]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Allow dollar character in bconsole commands (used for paths)
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 25 Jul 2019 06:47:37 +0000 (08:47 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 14 Dec 2019 14:55:26 +0000 (15:55 +0100)
gui/baculum/protected/API/Class/Bconsole.php
gui/baculum/protected/Common/Class/Miscellaneous.php

index eb2ffffed55130802c2b47a1959be5c779360cff..ad698d704b59b47bd37947d370e107cd92a027a1 100644 (file)
@@ -230,6 +230,7 @@ class Bconsole extends APIModule {
 
        private function getCommand($pattern, $sudo, $director, $bconsole_command) {
                $command = array('cmd' => null, 'out_id' => null);
+               $misc = $this->getModule('misc');
                if ($pattern === self::BCONSOLE_BG_COMMAND_PATTERN || $pattern === self::BCONSOLE_CONFIRM_YES_BG_COMMAND_PATTERN) {
                        $file = $this->prepareOutputFile();
                        $cmd = sprintf(
@@ -241,7 +242,7 @@ class Bconsole extends APIModule {
                                $director,
                                $file
                        );
-                       $command['cmd'] = $cmd;
+                       $command['cmd'] = $misc->escapeCharsToConsole($cmd);
                        $command['out_id'] = preg_replace('/^[\s\S]+\/output_/', '', $file);
                } else {
                        $cmd = sprintf(
@@ -252,7 +253,7 @@ class Bconsole extends APIModule {
                                $director,
                                $bconsole_command
                        );
-                       $command['cmd'] = $cmd;
+                       $command['cmd'] = $misc->escapeCharsToConsole($cmd);
                        $command['out_id'] = '';
                }
                return $command;
@@ -278,6 +279,7 @@ class Bconsole extends APIModule {
                        self::getCmdPath(),
                        self::getCfgPath()
                );
+               $cmd = $this->getModule('misc')->escapeCharsToConsole($cmd);
                exec($cmd, $output, $exitcode);
                if($exitcode != 0) {
                        $emsg = ' Output=>' . implode("\n", $output) . ', Exitcode=>' . $exitcode;
index f2465681bafd1010447575d3fab35759e8ea7be4..fb4731786ecb8d30311a5b7c968de9f5769b0e70 100644 (file)
@@ -220,7 +220,7 @@ class Miscellaneous extends TModule {
        }
 
        public function isValidPath($path) {
-               return (preg_match('/^[\p{L}\p{N}\p{Z}\[\]\(\)\-\+\/\\\:\.#~_,{}!\']{0,10000}$/u', $path) === 1);
+               return (preg_match('/^[\p{L}\p{N}\p{Z}\[\]\-\'\/\\(){}:.#~_,+!$]{0,10000}$/u', $path) === 1);
        }
 
        public function isValidReplace($replace) {
@@ -247,6 +247,10 @@ class Miscellaneous extends TModule {
                return (preg_match('/^[a-zA-Z0-9]+$/', $str) === 1);
        }
 
+       public function escapeCharsToConsole($path) {
+               return preg_replace('/([$])/', '\\\${1}', $path);
+       }
+
 
        /**
         * Writing INI-style configuration file.