From 8305cee7ccb12b08ffbf557184190e142d1d3af5 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Thu, 30 Mar 2017 15:45:01 -0400 Subject: [PATCH 1/3] HOR-2917 --- workflow/engine/classes/class.patch.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/workflow/engine/classes/class.patch.php b/workflow/engine/classes/class.patch.php index 75b39fa10..efcd15065 100644 --- a/workflow/engine/classes/class.patch.php +++ b/workflow/engine/classes/class.patch.php @@ -26,19 +26,27 @@ class p11835 extends patch */ static public function isApplicable() { - if (! class_exists('System')) { + if (!class_exists('System')) { G::LoadClass("System"); } patch::$isPathchable = false; $con = Propel::getConnection("workflow"); - $stmt = $con->prepareStatement("describe TASK;"); + $stmt = $con->prepareStatement("SHOW TABLES LIKE 'TASK'"); $rs = $stmt->executeQuery(); $rs->next(); - while($row = $rs->getRow()) { + $row = $rs->getRow(); + if (empty($row) === true) { + return patch::$isPathchable; + } + + $stmt = $con->prepareStatement("DESCRIBE TASK"); + $rs = $stmt->executeQuery(); + $rs->next(); + while ($row = $rs->getRow()) { if ($row ['Field'] == "TAS_GROUP_VARIABLE") { - $version = System::getVersion (); - $version = explode('-',$version); + $version = System::getVersion(); + $version = explode('-', $version); if ($version[0] == '2.5.1') { echo "Version " . $version[0] . " Patch\n"; patch::$isPathchable = true; @@ -49,7 +57,7 @@ class p11835 extends patch } return patch::$isPathchable; } - + public static function pmVersion($version) { if (preg_match("/^\D*([\d\.]+)\D*$/", $version, $matches)) { From 5010993db4233a83f9121524ca2005d2504c4e9b Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Fri, 31 Mar 2017 14:20:23 -0400 Subject: [PATCH 2/3] HOR-2917 --- gulliver/system/class.dbMaintenance.php | 86 ++++++++++++++++++++----- workflow/engine/classes/class.patch.php | 18 ++---- 2 files changed, 76 insertions(+), 28 deletions(-) diff --git a/gulliver/system/class.dbMaintenance.php b/gulliver/system/class.dbMaintenance.php index 496fd6e1c..eb3f757de 100644 --- a/gulliver/system/class.dbMaintenance.php +++ b/gulliver/system/class.dbMaintenance.php @@ -399,32 +399,88 @@ class DataBaseMaintenance */ function backupDataBase ($outfile) { + $password = escapeshellarg($this->passwd); + + //On Windows, escapeshellarg() instead replaces percent signs, exclamation + //marks (delayed variable substitution) and double quotes with spaces and + //adds double quotes around the string. + //See: http://php.net/manual/en/function.escapeshellarg.php + if (PATH_SEP !== "/") { + $password = $this->escapeshellargCustom($this->passwd); + } $aHost = explode(':', $this->host); $dbHost = $aHost[0]; if (isset($aHost[1])) { $dbPort = $aHost[1]; $command = 'mysqldump' - . ' --user=' . $this->user - . ' --password=' . escapeshellarg($this->passwd) - . ' --host=' . $dbHost - . ' --port=' . $dbPort - . ' --opt' - . ' --skip-comments' - . ' ' . $this->dbName - . ' > ' . $outfile; + . ' --user=' . $this->user + . ' --password=' . $password + . ' --host=' . $dbHost + . ' --port=' . $dbPort + . ' --opt' + . ' --skip-comments' + . ' ' . $this->dbName + . ' > ' . $outfile; } else { $command = 'mysqldump' - . ' --host=' . $dbHost - . ' --user=' . $this->user - . ' --opt' - . ' --skip-comments' - . ' --password=' . escapeshellarg($this->passwd) - . ' ' . $this->dbName - . ' > ' . $outfile; + . ' --host=' . $dbHost + . ' --user=' . $this->user + . ' --opt' + . ' --skip-comments' + . ' --password=' . $password + . ' ' . $this->dbName + . ' > ' . $outfile; } shell_exec($command); } + /** + * string escapeshellargCustom ( string $arg , character $quotes) + * + * escapeshellarg() adds single quotes around a string and quotes/escapes any + * existing single quotes allowing you to pass a string directly to a shell + * function and having it be treated as a single safe argument. This function + * should be used to escape individual arguments to shell functions coming + * from user input. The shell functions include exec(), system() and the + * backtick operator. + * + * On Windows, escapeshellarg() instead replaces percent signs, exclamation + * marks (delayed variable substitution) and double quotes with spaces and + * adds double quotes around the string. + */ + private function escapeshellargCustom($string, $quotes = "") + { + if ($quotes === "") { + $quotes = PHP_OS == "WINNT" ? "\"" : "'"; + } + $n = strlen($string); + $especial = ["!", "%", "\""]; + $substring = ""; + $result1 = []; + $result2 = []; + for ($i = 0; $i < $n; $i++) { + if (in_array($string[$i], $especial, true)) { + $result2[] = $string[$i]; + $result1[] = $substring; + $substring = ""; + } else { + $substring = $substring . $string[$i]; + } + } + $result1[] = $substring; + //Rebuild the password string + $n = count($result1); + for ($i = 0; $i < $n; $i++) { + $result1[$i] = trim(escapeshellarg($result1[$i]), $quotes); + if (isset($result2[$i])) { + $result1[$i] = $result1[$i] . $result2[$i]; + } + } + //add simple quotes, see escapeshellarg function + $newString = $quotes . implode("", $result1) . $quotes; + return $newString; + } + /** * restoreFromSql * diff --git a/workflow/engine/classes/class.patch.php b/workflow/engine/classes/class.patch.php index efcd15065..f19d967e0 100644 --- a/workflow/engine/classes/class.patch.php +++ b/workflow/engine/classes/class.patch.php @@ -26,27 +26,19 @@ class p11835 extends patch */ static public function isApplicable() { - if (!class_exists('System')) { + if (! class_exists('System')) { G::LoadClass("System"); } patch::$isPathchable = false; $con = Propel::getConnection("workflow"); - $stmt = $con->prepareStatement("SHOW TABLES LIKE 'TASK'"); + $stmt = $con->prepareStatement("describe TASK;"); $rs = $stmt->executeQuery(); $rs->next(); - $row = $rs->getRow(); - if (empty($row) === true) { - return patch::$isPathchable; - } - - $stmt = $con->prepareStatement("DESCRIBE TASK"); - $rs = $stmt->executeQuery(); - $rs->next(); - while ($row = $rs->getRow()) { + while($row = $rs->getRow()) { if ($row ['Field'] == "TAS_GROUP_VARIABLE") { - $version = System::getVersion(); - $version = explode('-', $version); + $version = System::getVersion (); + $version = explode('-',$version); if ($version[0] == '2.5.1') { echo "Version " . $version[0] . " Patch\n"; patch::$isPathchable = true; From fc0edb47700b0860777fff57649f540498126530 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Fri, 31 Mar 2017 16:38:29 -0400 Subject: [PATCH 3/3] HOR-2917 --- gulliver/system/class.dbMaintenance.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gulliver/system/class.dbMaintenance.php b/gulliver/system/class.dbMaintenance.php index eb3f757de..b9b1c8664 100644 --- a/gulliver/system/class.dbMaintenance.php +++ b/gulliver/system/class.dbMaintenance.php @@ -49,6 +49,7 @@ class DataBaseMaintenance protected $tmpDir; protected $outfile; protected $infile; + protected $isWindows; /** * __construct @@ -64,7 +65,7 @@ class DataBaseMaintenance $this->tmpDir = './'; $this->link = null; $this->dbName = null; - + $this->isWindows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; if (isset( $host ) && isset( $user ) && isset( $passwd )) { $this->host = $host; $this->user = $user; @@ -405,7 +406,7 @@ class DataBaseMaintenance //marks (delayed variable substitution) and double quotes with spaces and //adds double quotes around the string. //See: http://php.net/manual/en/function.escapeshellarg.php - if (PATH_SEP !== "/") { + if ($this->isWindows) { $password = $this->escapeshellargCustom($this->passwd); } $aHost = explode(':', $this->host); @@ -451,15 +452,15 @@ class DataBaseMaintenance private function escapeshellargCustom($string, $quotes = "") { if ($quotes === "") { - $quotes = PHP_OS == "WINNT" ? "\"" : "'"; + $quotes = $this->isWindows ? "\"" : "'"; } $n = strlen($string); - $especial = ["!", "%", "\""]; + $special = ["!", "%", "\""]; $substring = ""; $result1 = []; $result2 = []; for ($i = 0; $i < $n; $i++) { - if (in_array($string[$i], $especial, true)) { + if (in_array($string[$i], $special, true)) { $result2[] = $string[$i]; $result1[] = $substring; $substring = "";