From c5a63873b4e2d31d4cddb9e20abb19b9948c6b7c Mon Sep 17 00:00:00 2001 From: hjonathan Date: Mon, 7 Aug 2017 08:51:02 -0400 Subject: [PATCH 1/7] HOR-2933 HOR-2933-B update --- framework/src/Maveriks/Util/Common.php | 37 ++++++++++++++++--- gulliver/system/class.g.php | 28 ++++++++++---- .../methods/processes/processes_Export.php | 2 +- .../Migrator/GranularExporter.php | 2 +- .../src/ProcessMaker/Importer/Importer.php | 2 +- .../src/ProcessMaker/Services/Api/Project.php | 2 +- 6 files changed, 56 insertions(+), 17 deletions(-) diff --git a/framework/src/Maveriks/Util/Common.php b/framework/src/Maveriks/Util/Common.php index 2ccbd9c28..9ad136593 100644 --- a/framework/src/Maveriks/Util/Common.php +++ b/framework/src/Maveriks/Util/Common.php @@ -52,16 +52,18 @@ class Common } $files = glob("$path/$singlePattern", $flags); - $dirs = glob("$path/*", GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT); + $dirs = glob("$path/*", GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT); - if(is_array($dirs)){ + if (is_array($dirs)) { foreach ($dirs as $dir) { $files = array_merge($files, self::rglob("$dir/$singlePattern", $flags)); } } if ($onlyFiles) { - $files = array_filter($files, function($v) { return is_dir($v) ? false : true;}); + $files = array_filter($files, function ($v) { + return is_dir($v) ? false : true; + }); } return $files; @@ -96,7 +98,7 @@ class Common foreach ($files as $file) { $filename = basename($file); - if (preg_match('/'.$pattern.'/', $filename, $match)) { + if (preg_match('/' . $pattern . '/', $filename, $match)) { if ($maxVersion < $match[1]) { $maxVersion = $match[1]; @@ -107,6 +109,29 @@ class Common return $maxVersion; } + /** + * This method get the last version of file when exists a special characters + * @param $pattern + * @param $extension + * @param int $flag + * @return int + */ + public static function getLastVersionSpecialCharacters($dir, $pattern, $extension, $flag = 0) + { + $files = glob($dir . quotemeta($pattern) . "-*." . $extension, $flag); + $maxVersion = 0; + $pattern = preg_quote(basename($pattern)) . '-([0-9\.]+)pmx'; + foreach ($files as $file) { + $filename = basename($file); + if (preg_match('/' . $pattern . '/', $filename, $match)) { + if ($maxVersion < $match[1]) { + $maxVersion = $match[1]; + } + } + } + return $maxVersion; + } + public static function parseIniFile($filename) { $data = @parse_ini_file($filename, true); @@ -141,8 +166,8 @@ class Common } while ($parent_folder_path = array_pop($folder_path)) { - if (! @is_dir($parent_folder_path)) { - if (! @mkdir($parent_folder_path, $rights)) { + if (!@is_dir($parent_folder_path)) { + if (!@mkdir($parent_folder_path, $rights)) { umask($oldumask); } } diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index 4332c12fa..e628699c6 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -3221,20 +3221,34 @@ class G * @param (array) additional characteres map * */ - public function inflect ($string, $replacement = '_', $map = array()) + public function inflect($string, $replacement = '_', $map = array()) { - if (is_array( $replacement )) { + if (is_array($replacement)) { $map = $replacement; $replacement = '_'; } - $quotedReplacement = preg_quote( $replacement, '/' ); + $quotedReplacement = preg_quote($replacement, '/'); - $default = array ('/à|á|å|â/' => 'a','/è|é|ê|ẽ|ë/' => 'e','/ì|í|î/' => 'i','/ò|ó|ô|ø/' => 'o','/ù|ú|ů|û/' => 'u','/ç/' => 'c','/ñ/' => 'n','/ä|æ/' => 'ae','/ö/' => 'oe','/ü/' => 'ue','/Ä/' => 'Ae','/Ü/' => 'Ue','/Ö/' => 'Oe','/ß/' => 'ss','/\.|\,|\:|\-|\\|\//' => " ",'/\\s+/' => $replacement - ); + $default = array('/à|á|å|â/' => 'a', + '/è|é|ê|ẽ|ë/' => 'e', + '/ì|í|î/' => 'i', + '/ò|ó|ô|ø/' => 'o', + '/ù|ú|ů|û/' => 'u', + '/ç/' => 'c', + '/ñ/' => 'n', + '/ä|æ/' => 'ae', + '/ö/' => 'oe', + '/ü/' => 'ue', + '/Ä/' => 'Ae', + '/Ü/' => 'Ue', + '/Ö/' => 'Oe', + '/ß/' => 'ss', + '/[\.|\,|\+|\"|\:|\;|\-|\\|\/]/' => " ", + '/\\s+/' => $replacement); - $map = array_merge( $default, $map ); - return preg_replace( array_keys( $map ), array_values( $map ), $string ); + $map = array_merge($default, $map); + return preg_replace(array_keys($map), array_values($map), $string); } /** diff --git a/workflow/engine/methods/processes/processes_Export.php b/workflow/engine/methods/processes/processes_Export.php index 524bbe49a..5d4f4c803 100644 --- a/workflow/engine/methods/processes/processes_Export.php +++ b/workflow/engine/methods/processes/processes_Export.php @@ -42,7 +42,7 @@ try { $projectName = $exporter->getProjectName(); $getProjectName = $exporter->truncateName($projectName, false); - $version = ProcessMaker\Util\Common::getLastVersion($outputDir . $getProjectName . "-*.pmx") + 1; + $version = ProcessMaker\Util\Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; $outputFilename = sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx"); $outputFilename = $exporter->saveExport($outputDir . $outputFilename); /*----------------------------------********---------------------------------*/ diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php index 461f17e3d..60afe6e34 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php @@ -64,7 +64,7 @@ class GranularExporter $this->prjName = $projectData['PRJ_NAME']; $getProjectName = $this->publisher->truncateName($projectData['PRJ_NAME'], false); $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP; - $version = \ProcessMaker\Util\Common::getLastVersion($outputDir . $getProjectName . "-*.pmx2") + 1; + $version = \ProcessMaker\Util\Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx2") + 1; $outputFilename = $outputDir . sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx2"); $bpnmDefinition = array( diff --git a/workflow/engine/src/ProcessMaker/Importer/Importer.php b/workflow/engine/src/ProcessMaker/Importer/Importer.php index 1e89f110f..94c4a3167 100644 --- a/workflow/engine/src/ProcessMaker/Importer/Importer.php +++ b/workflow/engine/src/ProcessMaker/Importer/Importer.php @@ -771,7 +771,7 @@ abstract class Importer $getProjectName = $exporter->truncateName($exporter->getProjectName(), false); $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP; - $version = \ProcessMaker\Util\Common::getLastVersion($outputDir . $getProjectName . "-*.pmx") + 1; + $version = \ProcessMaker\Util\Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; $outputFilename = $outputDir . sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx"); $exporter->setMetadata("export_version", $version); diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Project.php b/workflow/engine/src/ProcessMaker/Services/Api/Project.php index 0496db5b0..0b57f33e2 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Project.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Project.php @@ -182,7 +182,7 @@ class Project extends Api $getProjectName = $exporter->truncateName($exporter->getProjectName(), false); $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP; - $version = \ProcessMaker\Util\Common::getLastVersion($outputDir . $getProjectName . "-*.pmx") + 1; + $version = \ProcessMaker\Util\Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; $outputFilename = $outputDir . sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx"); $exporter->setMetadata("export_version", $version); From 04a8b6561af03b1a27f7006fdfa8d71e7ae45ae7 Mon Sep 17 00:00:00 2001 From: Ronald Quenta Date: Mon, 7 Aug 2017 16:33:49 -0400 Subject: [PATCH 2/7] HOR-3467 --- gulliver/system/class.rbac.php | 11 ++++++++++- .../processCategory/processCategoryList.php | 7 +++++-- .../processCategory/processCategory_Ajax.php | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/gulliver/system/class.rbac.php b/gulliver/system/class.rbac.php index c4749221e..3d6f99282 100644 --- a/gulliver/system/class.rbac.php +++ b/gulliver/system/class.rbac.php @@ -147,8 +147,17 @@ class RBAC ), 'newSite.php' => array( 'newSite.php' => array('PM_SETUP_ADVANCE') + ), + 'processCategory_Ajax.php' => array( + 'processCategoryList' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), + 'updatePageSize' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), + 'checkCategoryName' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), + 'saveNewCategory' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), + 'checkEditCategoryName' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), + 'updateCategory' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), + 'canDeleteCategory' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), + 'deleteCategory' => array('PM_SETUP', 'PM_SETUP_ADVANCE') ) - ); } diff --git a/workflow/engine/methods/processCategory/processCategoryList.php b/workflow/engine/methods/processCategory/processCategoryList.php index 3c819b354..148286a39 100644 --- a/workflow/engine/methods/processCategory/processCategoryList.php +++ b/workflow/engine/methods/processCategory/processCategoryList.php @@ -21,9 +21,12 @@ * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. */ +use ProcessMaker\Exception\RBACException; + +/** @var RBAC $RBAC */ +global $RBAC; if ($RBAC->userCanAccess( 'PM_SETUP' ) != 1 && $RBAC->userCanAccess( 'PM_SETUP_ADVANCE' ) != 1) { - G::SendTemporalMessage( 'krlos', 'error', 'labels' ); - die(); + throw new RBACException('ID_USER_HAVENT_RIGHTS_PAGE', -1); } $c = new Configurations(); diff --git a/workflow/engine/methods/processCategory/processCategory_Ajax.php b/workflow/engine/methods/processCategory/processCategory_Ajax.php index 74d529ede..d1c1d73f2 100644 --- a/workflow/engine/methods/processCategory/processCategory_Ajax.php +++ b/workflow/engine/methods/processCategory/processCategory_Ajax.php @@ -22,6 +22,20 @@ * Coral Gables, FL, 33134, USA, or email info@colosa.com. */ +use ProcessMaker\Exception\RBACException; + +/** @var RBAC $RBAC */ +global $RBAC; +switch ($RBAC->userCanAccess('PM_LOGIN')) { + case -2: + throw new RBACException('ID_USER_HAVENT_RIGHTS_SYSTEM', -2); + break; + case -1: + throw new RBACException('ID_USER_HAVENT_RIGHTS_PAGE', -1); + break; +} +$RBAC->allows(basename(__FILE__), $_REQUEST['action']); + if (isset( $_REQUEST['action'] )) { switch ($_REQUEST['action']) { case 'processCategoryList': From a43e3687cb4b0406310fdba1bfafa214e92014e6 Mon Sep 17 00:00:00 2001 From: hjonathan Date: Tue, 8 Aug 2017 10:16:02 -0400 Subject: [PATCH 3/7] remove the getLastVersion method --- framework/src/Maveriks/Util/Common.php | 40 -------------------------- 1 file changed, 40 deletions(-) diff --git a/framework/src/Maveriks/Util/Common.php b/framework/src/Maveriks/Util/Common.php index 9ad136593..afe8a6b75 100644 --- a/framework/src/Maveriks/Util/Common.php +++ b/framework/src/Maveriks/Util/Common.php @@ -69,46 +69,6 @@ class Common return $files; } - /** - * Returns the last version given a pattern of file name - * - * @param string $pattern a valid pattern for glob(...) native function - * @param int $flag php flags for glob(...) native function - * @return int|string - * - * Example: - * - Given the following files inside a directory: - * /example/path/myApplication-v1.tar - * /example/path/myApplication-v2.tar - * /example/path/myApplication-v3.tar - * /example/path/myApplication-v5.tar - * /example/path/myApplication-v7.tar - * - * $lastVer = ProcessMaker\Util\Common::getLastVersion("/example/path/myApplication-*.tar"); - * - * It will returns: 7 - */ - public static function getLastVersion($pattern, $flag = 0) - { - $files = glob($pattern, $flag); - $maxVersion = 0; - - $pattern = str_replace("*", '([0-9\.]+)', basename($pattern)); - - foreach ($files as $file) { - $filename = basename($file); - - if (preg_match('/' . $pattern . '/', $filename, $match)) { - - if ($maxVersion < $match[1]) { - $maxVersion = $match[1]; - } - } - } - - return $maxVersion; - } - /** * This method get the last version of file when exists a special characters * @param $pattern From 61f9f9f7c4319bd3e736011c337f490a595aecf2 Mon Sep 17 00:00:00 2001 From: Ronald Quenta Date: Tue, 8 Aug 2017 14:46:01 -0400 Subject: [PATCH 4/7] add validation for sort and up observations --- gulliver/system/class.g.php | 4 +- gulliver/system/class.pmException.php | 2 +- gulliver/system/class.rbac.php | 16 +-- .../processCategory/processCategoryList.php | 19 +-- .../processCategory/processCategory_Ajax.php | 135 +++++++++--------- 5 files changed, 88 insertions(+), 88 deletions(-) diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index 4332c12fa..6589db737 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -638,7 +638,7 @@ class G * @param string $strSkin * @return void */ - public function RenderPage ($strTemplate = "default", $strSkin = SYS_SKIN, $objContent = null, $layout = '') + public static function RenderPage ($strTemplate = "default", $strSkin = SYS_SKIN, $objContent = null, $layout = '') { global $G_CONTENT; global $G_TEMPLATE; @@ -5701,7 +5701,7 @@ class G * * @return showRes($string) */ - public function outRes ($sInfVar) + public static function outRes ($sInfVar) { echo $sInfVar; } diff --git a/gulliver/system/class.pmException.php b/gulliver/system/class.pmException.php index 273529b47..e428cec9f 100644 --- a/gulliver/system/class.pmException.php +++ b/gulliver/system/class.pmException.php @@ -20,7 +20,7 @@ class PMException extends Exception return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; } - public function registerErrorLog($error, $token){ + public static function registerErrorLog($error, $token){ $ws = (defined("SYS_SYS"))? SYS_SYS : "Wokspace Undefined"; Bootstrap::registerMonolog('ExceptionCron', 400, $error->getMessage(), array('token'=>$token), $ws, 'processmaker.log'); } diff --git a/gulliver/system/class.rbac.php b/gulliver/system/class.rbac.php index 3d6f99282..98b2a810d 100644 --- a/gulliver/system/class.rbac.php +++ b/gulliver/system/class.rbac.php @@ -149,14 +149,14 @@ class RBAC 'newSite.php' => array('PM_SETUP_ADVANCE') ), 'processCategory_Ajax.php' => array( - 'processCategoryList' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), - 'updatePageSize' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), - 'checkCategoryName' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), - 'saveNewCategory' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), - 'checkEditCategoryName' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), - 'updateCategory' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), - 'canDeleteCategory' => array('PM_SETUP', 'PM_SETUP_ADVANCE'), - 'deleteCategory' => array('PM_SETUP', 'PM_SETUP_ADVANCE') + 'processCategoryList' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES'), + 'updatePageSize' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES'), + 'checkCategoryName' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES'), + 'saveNewCategory' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES'), + 'checkEditCategoryName' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES'), + 'updateCategory' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES'), + 'canDeleteCategory' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES'), + 'deleteCategory' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES') ) ); } diff --git a/workflow/engine/methods/processCategory/processCategoryList.php b/workflow/engine/methods/processCategory/processCategoryList.php index 148286a39..496f1ca21 100644 --- a/workflow/engine/methods/processCategory/processCategoryList.php +++ b/workflow/engine/methods/processCategory/processCategoryList.php @@ -21,17 +21,18 @@ * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. */ + use ProcessMaker\Exception\RBACException; /** @var RBAC $RBAC */ global $RBAC; -if ($RBAC->userCanAccess( 'PM_SETUP' ) != 1 && $RBAC->userCanAccess( 'PM_SETUP_ADVANCE' ) != 1) { +if ($RBAC->userCanAccess('PM_SETUP') != 1 && $RBAC->userCanAccess('PM_SETUP_PROCESS_CATEGORIES') != 1) { throw new RBACException('ID_USER_HAVENT_RIGHTS_PAGE', -1); } $c = new Configurations(); -$configPage = $c->getConfiguration( 'processCategoryList', 'pageSize', '', $_SESSION['USER_LOGGED'] ); -$Config['pageSize'] = isset( $configPage['pageSize'] ) ? $configPage['pageSize'] : 20; +$configPage = $c->getConfiguration('processCategoryList', 'pageSize', '', $_SESSION['USER_LOGGED']); +$Config['pageSize'] = isset($configPage['pageSize']) ? $configPage['pageSize'] : 20; $G_MAIN_MENU = 'workflow'; $G_SUB_MENU = 'processCategory'; @@ -40,9 +41,9 @@ $G_ID_SUB_MENU_SELECTED = ''; $G_PUBLISH = new Publisher(); -$oHeadPublisher = & headPublisher::getSingleton(); -$oHeadPublisher->addExtJsScript( 'processCategory/processCategoryList', false ); //adding a javascript file .js -$oHeadPublisher->addContent( 'processCategory/processCategoryList' ); //adding a html file .html. -$oHeadPublisher->assign( 'FORMATS', $c->getFormats() ); -$oHeadPublisher->assign( 'CONFIG', $Config ); -G::RenderPage( 'publish', 'extJs' ); \ No newline at end of file +$oHeadPublisher = &headPublisher::getSingleton(); +$oHeadPublisher->addExtJsScript('processCategory/processCategoryList', false); //adding a javascript file .js +$oHeadPublisher->addContent('processCategory/processCategoryList'); //adding a html file .html. +$oHeadPublisher->assign('FORMATS', $c->getFormats()); +$oHeadPublisher->assign('CONFIG', $Config); +G::RenderPage('publish', 'extJs'); \ No newline at end of file diff --git a/workflow/engine/methods/processCategory/processCategory_Ajax.php b/workflow/engine/methods/processCategory/processCategory_Ajax.php index d1c1d73f2..398cd036a 100644 --- a/workflow/engine/methods/processCategory/processCategory_Ajax.php +++ b/workflow/engine/methods/processCategory/processCategory_Ajax.php @@ -36,158 +36,157 @@ switch ($RBAC->userCanAccess('PM_LOGIN')) { } $RBAC->allows(basename(__FILE__), $_REQUEST['action']); -if (isset( $_REQUEST['action'] )) { +if (isset($_REQUEST['action'])) { switch ($_REQUEST['action']) { case 'processCategoryList': $co = new Configurations(); - $config = $co->getConfiguration( 'processCategoryList', 'pageSize', '', $_SESSION['USER_LOGGED'] ); - $limit_size = isset( $config['pageSize'] ) ? $config['pageSize'] : 20; + $config = $co->getConfiguration('processCategoryList', 'pageSize', '', $_SESSION['USER_LOGGED']); + $limit_size = isset($config['pageSize']) ? $config['pageSize'] : 20; - $start = isset( $_POST['start'] ) ? $_POST['start'] : 0; - $limit = isset( $_POST['limit'] ) ? $_POST['limit'] : $limit_size; - $filter = isset( $_REQUEST['textFilter'] ) ? $_REQUEST['textFilter'] : ''; - $dir = isset( $_POST['dir'] ) ? $_POST['dir'] : 'ASC'; - $sort = isset( $_POST['sort'] ) ? $_POST['sort'] : 'CATEGORY_NAME'; + $start = isset($_POST['start']) ? $_POST['start'] : 0; + $limit = isset($_POST['limit']) ? $_POST['limit'] : $limit_size; + $filter = isset($_REQUEST['textFilter']) ? $_REQUEST['textFilter'] : ''; + $dir = isset($_POST['dir']) ? $_POST['dir'] : 'ASC'; + $sort = isset($_POST['sort']) ? $_POST['sort'] : 'CATEGORY_NAME'; - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->addSelectColumn( 'COUNT(*) AS CNT' ); - $oCriteria->add( ProcessCategoryPeer::CATEGORY_UID, '', Criteria::NOT_EQUAL ); + $oCriteria = new Criteria('workflow'); + $oCriteria->addSelectColumn('COUNT(*) AS CNT'); + $oCriteria->add(ProcessCategoryPeer::CATEGORY_UID, '', Criteria::NOT_EQUAL); if ($filter != '') { - $oCriteria->add( ProcessCategoryPeer::CATEGORY_NAME, '%' . $filter . '%', Criteria::LIKE ); + $oCriteria->add(ProcessCategoryPeer::CATEGORY_NAME, '%' . $filter . '%', Criteria::LIKE); } - $oDat = ProcessCategoryPeer::doSelectRS( $oCriteria ); - $oDat->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oDat = ProcessCategoryPeer::doSelectRS($oCriteria); + $oDat->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDat->next(); $row = $oDat->getRow(); $total_categories = $row['CNT']; $oCriteria->clear(); - $oCriteria->addSelectColumn( ProcessCategoryPeer::CATEGORY_UID ); - $oCriteria->addSelectColumn( ProcessCategoryPeer::CATEGORY_NAME ); - $oCriteria->add( ProcessCategoryPeer::CATEGORY_UID, '', Criteria::NOT_EQUAL ); + $oCriteria->addSelectColumn(ProcessCategoryPeer::CATEGORY_UID); + $oCriteria->addSelectColumn(ProcessCategoryPeer::CATEGORY_NAME); + $oCriteria->add(ProcessCategoryPeer::CATEGORY_UID, '', Criteria::NOT_EQUAL); if ($filter != '') { - $oCriteria->add( ProcessCategoryPeer::CATEGORY_NAME, '%' . $filter . '%', Criteria::LIKE ); + $oCriteria->add(ProcessCategoryPeer::CATEGORY_NAME, '%' . $filter . '%', Criteria::LIKE); } - + + //SQL Injection via 'sort' parameter + if (!in_array($sort, array_merge(ProcessCategoryPeer::getFieldNames(BasePeer::TYPE_FIELDNAME), ['TOTAL_PROCESSES']))) { + throw new Exception(G::LoadTranslation('ID_INVALID_VALUE_FOR', array('$sort'))); + } + if ($dir == "DESC") { $oCriteria->addDescendingOrderByColumn($sort); } else { $oCriteria->addAscendingOrderByColumn($sort); } - $oCriteria->setLimit( $limit ); - $oCriteria->setOffset( $start ); - $oDataset = ProcessCategoryPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oCriteria->setLimit($limit); + $oCriteria->setOffset($start); + $oDataset = ProcessCategoryPeer::doSelectRS($oCriteria); + $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $proc = new Process(); $aProcess = $proc->getAllProcessesByCategory(); - $result = ""; - $aCat = array (); + $result = []; + $aCat = array(); while ($oDataset->next()) { $aCat[] = $oDataset->getRow(); - $index = sizeof( $aCat ) - 1; - $aCat[$index]['TOTAL_PROCESSES'] = isset( $aProcess[$aCat[$index]['CATEGORY_UID']] ) ? $aProcess[$aCat[$index]['CATEGORY_UID']] : 0; + $index = sizeof($aCat) - 1; + $aCat[$index]['TOTAL_PROCESSES'] = isset($aProcess[$aCat[$index]['CATEGORY_UID']]) ? $aProcess[$aCat[$index]['CATEGORY_UID']] : 0; } $result['data'] = $aCat; $result['totalCount'] = $total_categories; - echo G::json_encode( $result ); + echo G::json_encode($result); break; case 'updatePageSize': $c = new Configurations(); $arr['pageSize'] = $_REQUEST['size']; - $arr['dateSave'] = date( 'Y-m-d H:i:s' ); - $config = Array (); + $arr['dateSave'] = date('Y-m-d H:i:s'); + $config = Array(); $config[] = $arr; $c->aConfig = $config; - $c->saveConfig( 'processCategoryList', 'pageSize', '', $_SESSION['USER_LOGGED'] ); + $c->saveConfig('processCategoryList', 'pageSize', '', $_SESSION['USER_LOGGED']); echo '{success: true}'; break; case 'checkCategoryName': - require_once 'classes/model/ProcessCategory.php'; $catName = $_REQUEST['cat_name']; - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->addSelectColumn( ProcessCategoryPeer::CATEGORY_NAME ); - $oCriteria->add( ProcessCategoryPeer::CATEGORY_NAME, $catName ); - $oDataset = ProcessCategoryPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oCriteria = new Criteria('workflow'); + $oCriteria->addSelectColumn(ProcessCategoryPeer::CATEGORY_NAME); + $oCriteria->add(ProcessCategoryPeer::CATEGORY_NAME, $catName); + $oDataset = ProcessCategoryPeer::doSelectRS($oCriteria); + $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); $row = $oDataset->getRow(); - $response = isset( $row['CATEGORY_NAME'] ) ? 'false' : 'true'; + $response = isset($row['CATEGORY_NAME']) ? 'false' : 'true'; echo $response; break; case 'saveNewCategory': try { - require_once 'classes/model/ProcessCategory.php'; - $catName = trim( $_REQUEST['category'] ); + $catName = trim($_REQUEST['category']); $pcat = new ProcessCategory(); - $pcat->setNew( true ); - $pcat->setCategoryUid( G::GenerateUniqueID() ); - $pcat->setCategoryName( $catName ); + $pcat->setNew(true); + $pcat->setCategoryUid(G::GenerateUniqueID()); + $pcat->setCategoryName($catName); $pcat->save(); - G::auditLog("CreateCategory", "Category Name: ".$catName); + G::auditLog("CreateCategory", "Category Name: " . $catName); echo '{success: true}'; } catch (Exception $ex) { $varEcho = '{success: false, error: ' . $ex->getMessage() . '}'; - G::outRes( $varEcho ); + G::outRes($varEcho); } break; case 'checkEditCategoryName': - require_once 'classes/model/ProcessCategory.php'; $catUID = $_REQUEST['cat_uid']; $catName = $_REQUEST['cat_name']; - $oCriteria = new Criteria( 'workflow' ); - $oCriteria->addSelectColumn( ProcessCategoryPeer::CATEGORY_NAME ); - $oCriteria->add( ProcessCategoryPeer::CATEGORY_NAME, $catName ); - $oCriteria->add( ProcessCategoryPeer::CATEGORY_UID, $catUID, Criteria::NOT_EQUAL ); - $oDataset = ProcessCategoryPeer::doSelectRS( $oCriteria ); - $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oCriteria = new Criteria('workflow'); + $oCriteria->addSelectColumn(ProcessCategoryPeer::CATEGORY_NAME); + $oCriteria->add(ProcessCategoryPeer::CATEGORY_NAME, $catName); + $oCriteria->add(ProcessCategoryPeer::CATEGORY_UID, $catUID, Criteria::NOT_EQUAL); + $oDataset = ProcessCategoryPeer::doSelectRS($oCriteria); + $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); $row = $oDataset->getRow(); - $response = isset( $row['CATEGORY_NAME'] ) ? 'false' : 'true'; + $response = isset($row['CATEGORY_NAME']) ? 'false' : 'true'; echo $response; break; case 'updateCategory': try { - require_once 'classes/model/ProcessCategory.php'; $catUID = $_REQUEST['cat_uid']; - $catName = trim( $_REQUEST['category'] ); + $catName = trim($_REQUEST['category']); $pcat = new ProcessCategory(); - $pcat->setNew( false ); - $pcat->setCategoryUid( $catUID ); - $pcat->setCategoryName( $catName ); + $pcat->setNew(false); + $pcat->setCategoryUid($catUID); + $pcat->setCategoryName($catName); $pcat->save(); - g::auditLog("UpdateCategory", "Category Name: ".$catName." Category ID: (".$catUID.") "); + g::auditLog("UpdateCategory", "Category Name: " . $catName . " Category ID: (" . $catUID . ") "); echo '{success: true}'; } catch (Exception $ex) { $varEcho = '{success: false, error: ' . $ex->getMessage() . '}'; - G::outRes( $varEcho ); + G::outRes($varEcho); } break; case 'canDeleteCategory': - require_once 'classes/model/Process.php'; $proc = new Process(); $aProcess = $proc->getAllProcessesByCategory(); $catUID = $_REQUEST['CAT_UID']; - $response = isset( $aProcess[$catUID] ) ? 'false' : 'true'; + $response = isset($aProcess[$catUID]) ? 'false' : 'true'; echo $response; break; case 'deleteCategory': try { - require_once 'classes/model/ProcessCategory.php'; $catUID = $_REQUEST['cat_uid']; $cat = new ProcessCategory(); - $cat->setCategoryUid( $catUID ); - $catName = $cat->loadByCategoryId( $catUID ); + $cat->setCategoryUid($catUID); + $catName = $cat->loadByCategoryId($catUID); $cat->delete(); - G::auditLog("DeleteCategory", "Category Name: ".$catName." Category ID: (".$catUID.") "); + G::auditLog("DeleteCategory", "Category Name: " . $catName . " Category ID: (" . $catUID . ") "); $varEcho = '{success: true}'; - G::outRes( $varEcho ); + G::outRes($varEcho); } catch (Exception $ex) { $token = strtotime("now"); PMException::registerErrorLog($ex, $token); $resJson = '{success: false, error: ' . G::LoadTranslation("ID_EXCEPTION_LOG_INTERFAZ", array($token)) . '}'; - G::outRes( $resJson ); + G::outRes($resJson); } break; default: From 9dd07338c192d147bf98b49d74e5e09997fe5a29 Mon Sep 17 00:00:00 2001 From: hjonathan Date: Tue, 8 Aug 2017 17:28:35 -0400 Subject: [PATCH 5/7] add use library --- workflow/engine/methods/processes/processes_Export.php | 3 ++- .../ProcessMaker/BusinessModel/Migrator/GranularExporter.php | 3 ++- workflow/engine/src/ProcessMaker/Importer/Importer.php | 3 ++- workflow/engine/src/ProcessMaker/Services/Api/Project.php | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/workflow/engine/methods/processes/processes_Export.php b/workflow/engine/methods/processes/processes_Export.php index 5d4f4c803..99c248bfc 100644 --- a/workflow/engine/methods/processes/processes_Export.php +++ b/workflow/engine/methods/processes/processes_Export.php @@ -21,6 +21,7 @@ * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. */ +use ProcessMaker\Util\Common; $response = new StdClass(); $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP; @@ -42,7 +43,7 @@ try { $projectName = $exporter->getProjectName(); $getProjectName = $exporter->truncateName($projectName, false); - $version = ProcessMaker\Util\Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; + $version = Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; $outputFilename = sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx"); $outputFilename = $exporter->saveExport($outputDir . $outputFilename); /*----------------------------------********---------------------------------*/ diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php index 60afe6e34..09b5308f1 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Migrator/GranularExporter.php @@ -3,6 +3,7 @@ namespace ProcessMaker\BusinessModel\Migrator; use ProcessMaker\Project; +use ProcessMaker\Util\Common; class GranularExporter { @@ -64,7 +65,7 @@ class GranularExporter $this->prjName = $projectData['PRJ_NAME']; $getProjectName = $this->publisher->truncateName($projectData['PRJ_NAME'], false); $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP; - $version = \ProcessMaker\Util\Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx2") + 1; + $version = Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx2") + 1; $outputFilename = $outputDir . sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx2"); $bpnmDefinition = array( diff --git a/workflow/engine/src/ProcessMaker/Importer/Importer.php b/workflow/engine/src/ProcessMaker/Importer/Importer.php index 94c4a3167..fecb7e164 100644 --- a/workflow/engine/src/ProcessMaker/Importer/Importer.php +++ b/workflow/engine/src/ProcessMaker/Importer/Importer.php @@ -6,6 +6,7 @@ use ProcessMaker\Project; use ProcessMaker\Project\Adapter; use ProcessMaker\BusinessModel\Migrator; use ProcessMaker\BusinessModel\Migrator\ImportException; +use ProcessMaker\Util\Common; abstract class Importer { @@ -771,7 +772,7 @@ abstract class Importer $getProjectName = $exporter->truncateName($exporter->getProjectName(), false); $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP; - $version = \ProcessMaker\Util\Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; + $version = Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; $outputFilename = $outputDir . sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx"); $exporter->setMetadata("export_version", $version); diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Project.php b/workflow/engine/src/ProcessMaker/Services/Api/Project.php index 0b57f33e2..cc38f31a2 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Project.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Project.php @@ -10,6 +10,7 @@ use \ProcessMaker\BusinessModel\Validator; use \ProcessMaker\BusinessModel\Migrator\GranularExporter; use \ProcessMaker\BusinessModel\Migrator\ExportObjects; use \ProcessMaker\Util\IO\HttpStream; +use \ProcessMaker\Util\Common; /** * Class Project @@ -182,7 +183,7 @@ class Project extends Api $getProjectName = $exporter->truncateName($exporter->getProjectName(), false); $outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP; - $version = \ProcessMaker\Util\Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; + $version = Common::getLastVersionSpecialCharacters($outputDir, $getProjectName, "pmx") + 1; $outputFilename = $outputDir . sprintf("%s-%s.%s", str_replace(" ", "_", $getProjectName), $version, "pmx"); $exporter->setMetadata("export_version", $version); From deb4999537050972d8743974f3501470d31fcde4 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Wed, 9 Aug 2017 12:03:25 -0400 Subject: [PATCH 6/7] HOR-2949 --- gulliver/system/class.rbac.php | 7 + .../methods/emailServer/emailServerAjax.php | 2 +- .../BusinessModel/EmailServer.php | 293 +++++++++++++----- 3 files changed, 222 insertions(+), 80 deletions(-) diff --git a/gulliver/system/class.rbac.php b/gulliver/system/class.rbac.php index af9c6b321..253ff34b8 100644 --- a/gulliver/system/class.rbac.php +++ b/gulliver/system/class.rbac.php @@ -165,6 +165,13 @@ class RBAC 'updateCategory' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES'), 'canDeleteCategory' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES'), 'deleteCategory' => array('PM_SETUP', 'PM_SETUP_PROCESS_CATEGORIES') + ), + 'emailServerAjax.php' => array( + 'INS' => array('PM_SETUP'), + 'UPD' => array('PM_SETUP'), + 'DEL' => array('PM_SETUP'), + 'LST' => array('PM_SETUP'), + 'TEST' => array('PM_SETUP') ) ); } diff --git a/workflow/engine/methods/emailServer/emailServerAjax.php b/workflow/engine/methods/emailServer/emailServerAjax.php index 78dc6c652..6f3c246e3 100644 --- a/workflow/engine/methods/emailServer/emailServerAjax.php +++ b/workflow/engine/methods/emailServer/emailServerAjax.php @@ -1,8 +1,8 @@ allows(basename(__FILE__), $option); switch ($option) { case "INS": $arrayData = array(); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php b/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php index b3e6d261b..0946e163d 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php @@ -1,5 +1,8 @@ array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "emailServerDefault") ); + private $contextLog = array(); + private $formatFieldNameInUppercase = true; private $arrayFieldNameForException = array( @@ -37,17 +42,51 @@ class EmailServer foreach ($this->arrayFieldDefinition as $key => $value) { $this->arrayFieldNameForException[$value["fieldNameAux"]] = $key; } - } catch (\Exception $e) { + + //Define the variables for the logging + global $RBAC; + $currentUser = $RBAC->aUserInfo['USER_INFO']; + $info = array( + 'ip' => G::getIpAddress(), + 'workspace' => (defined("SYS_SYS"))? SYS_SYS : "Workspace undefined", + 'usrUid' => $currentUser['USR_UID'] + ); + $this->setContextLog($info); + + + } catch (Exception $e) { throw $e; } } + /** + * Get the $contextLog value. + * + * @return string + */ + public function getContextLog() + { + return $this->contextLog; + } + + /** + * Set the value of $contextLog. + * + * @param array $k + * @return void + */ + public function setContextLog($k) + { + $this->contextLog = array_merge($this->contextLog, $k); + } + /** * Set the format of the fields name (uppercase, lowercase) * * @param bool $flag Value that set the format * - * return void + * @return void + * @throws Exception */ public function setFormatFieldNameInUppercase($flag) { @@ -55,7 +94,7 @@ class EmailServer $this->formatFieldNameInUppercase = $flag; $this->setArrayFieldNameForException($this->arrayFieldNameForException); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -65,7 +104,8 @@ class EmailServer * * @param array $arrayData Data with the fields * - * return void + * @return void + * @throws Exception */ public function setArrayFieldNameForException(array $arrayData) { @@ -73,7 +113,7 @@ class EmailServer foreach ($arrayData as $key => $value) { $this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value); } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -83,13 +123,14 @@ class EmailServer * * @param string $fieldName Field name * - * return string Return the field name according the format + * @return string, return the field name according the format + * @throws Exception */ public function getFieldNameByFormatFieldName($fieldName) { try { return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -99,7 +140,8 @@ class EmailServer * * @param array $arrayData Data * - * return array Return array with result of send test mail + * @return array, return array with result of send test mail + * @throws Exception */ public function sendTestMail(array $arrayData) { @@ -117,20 +159,20 @@ class EmailServer "SMTPSecure" => (isset($arrayData["SMTPSecure"]))? $arrayData["SMTPSecure"] : "none" ); - $sFrom = \G::buildFrom($aConfiguration); + $sFrom = G::buildFrom($aConfiguration); - $sSubject = \G::LoadTranslation("ID_MESS_TEST_SUBJECT"); - $msg = \G::LoadTranslation("ID_MESS_TEST_BODY"); + $sSubject = G::LoadTranslation("ID_MESS_TEST_SUBJECT"); + $msg = G::LoadTranslation("ID_MESS_TEST_BODY"); switch ($arrayData["MESS_ENGINE"]) { case "MAIL": - $engine = \G::LoadTranslation("ID_MESS_ENGINE_TYPE_1"); + $engine = G::LoadTranslation("ID_MESS_ENGINE_TYPE_1"); break; case "PHPMAILER": - $engine = \G::LoadTranslation("ID_MESS_ENGINE_TYPE_2"); + $engine = G::LoadTranslation("ID_MESS_ENGINE_TYPE_2"); break; case "OPENMAIL": - $engine = \G::LoadTranslation("ID_MESS_ENGINE_TYPE_3"); + $engine = G::LoadTranslation("ID_MESS_ENGINE_TYPE_3"); break; } @@ -175,7 +217,7 @@ class EmailServer if ($oSpool->status == "sent") { $arrayTestMailResult["status"] = true; $arrayTestMailResult["success"] = true; - $arrayTestMailResult["msg"] = \G::LoadTranslation("ID_MAIL_TEST_SUCCESS"); + $arrayTestMailResult["msg"] = G::LoadTranslation("ID_MAIL_TEST_SUCCESS"); } else { $arrayTestMailResult["status"] = false; $arrayTestMailResult["success"] = false; @@ -183,7 +225,7 @@ class EmailServer } return $arrayTestMailResult; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -194,7 +236,8 @@ class EmailServer * @param array $arrayData Data * @param int $step Step * - * return array Return array with result of test connection by step + * @return array, return array with result of test connection by step + * @throws Exception */ public function testConnectionByStep(array $arrayData, $step = 0) { @@ -208,7 +251,7 @@ class EmailServer $eregMail = "/^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*@[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3}$/"; $arrayDataMail["FROM_EMAIL"] = ($arrayData["MESS_FROM_MAIL"] != "" && preg_match($eregMail, $arrayData["MESS_FROM_MAIL"]))? $arrayData["MESS_FROM_MAIL"] : ""; - $arrayDataMail["FROM_NAME"] = ($arrayData["MESS_FROM_NAME"] != "")? $arrayData["MESS_FROM_NAME"] : \G::LoadTranslation("ID_MESS_TEST_BODY"); + $arrayDataMail["FROM_NAME"] = ($arrayData["MESS_FROM_NAME"] != "")? $arrayData["MESS_FROM_NAME"] : G::LoadTranslation("ID_MESS_TEST_BODY"); $arrayDataMail["MESS_ENGINE"] = "MAIL"; $arrayDataMail["MESS_SERVER"] = "localhost"; $arrayDataMail["MESS_PORT"] = 25; @@ -233,7 +276,7 @@ class EmailServer ); if ($arrayTestMailResult["status"] == false) { - $arrayResult["message"] = \G::LoadTranslation("ID_SENDMAIL_NOT_INSTALLED"); + $arrayResult["message"] = G::LoadTranslation("ID_SENDMAIL_NOT_INSTALLED"); } //Return @@ -252,7 +295,7 @@ class EmailServer $passwdHide = ""; } - $passwdDec = \G::decrypt($passwd,"EMAILENCRYPT"); + $passwdDec = G::decrypt($passwd,"EMAILENCRYPT"); $auxPass = explode("hash:", $passwdDec); if (count($auxPass) > 1) { @@ -378,7 +421,7 @@ class EmailServer $eregMail = "/^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*@[0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3}$/"; $arrayDataPhpMailer["FROM_EMAIL"] = ($fromMail != "" && preg_match($eregMail, $fromMail))? $fromMail : ""; - $arrayDataPhpMailer["FROM_NAME"] = $arrayData["MESS_FROM_NAME"] != "" ? $arrayData["MESS_FROM_NAME"] : \G::LoadTranslation("ID_MESS_TEST_BODY"); + $arrayDataPhpMailer["FROM_NAME"] = $arrayData["MESS_FROM_NAME"] != "" ? $arrayData["MESS_FROM_NAME"] : G::LoadTranslation("ID_MESS_TEST_BODY"); $arrayDataPhpMailer["MESS_ENGINE"] = "PHPMAILER"; $arrayDataPhpMailer["MESS_SERVER"] = $server; $arrayDataPhpMailer["MESS_PORT"] = $port; @@ -421,7 +464,7 @@ class EmailServer //Return return $arrayResult; - } catch (\Exception $e) { + } catch (Exception $e) { $arrayResult = array(); $arrayResult["result"] = false; @@ -437,7 +480,8 @@ class EmailServer * * @param array $arrayData Data * - * return array Return array with result of test connection + * @return array, return array with result of test connection + * @throws Exception */ public function testConnection(array $arrayData) { @@ -467,11 +511,11 @@ class EmailServer $arrayDataAux["MAIL_TO"] = "admin@processmaker.com"; $arrayResult[$arrayMailTestName[1]] = $this->testConnectionByStep($arrayDataAux); - $arrayResult[$arrayMailTestName[1]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_VERIFYING_MAIL"); + $arrayResult[$arrayMailTestName[1]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_VERIFYING_MAIL"); if ((int)($arrayData["MESS_TRY_SEND_INMEDIATLY"]) == 1 && $arrayData['MAIL_TO'] != '') { $arrayResult[$arrayMailTestName[2]] = $this->testConnectionByStep($arrayData); - $arrayResult[$arrayMailTestName[2]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_SENDING_EMAIL", array($arrayData["MAIL_TO"])); + $arrayResult[$arrayMailTestName[2]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_SENDING_EMAIL", array($arrayData["MAIL_TO"])); } break; case "PHPMAILER": @@ -482,19 +526,19 @@ class EmailServer switch ($step) { case 1: - $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_RESOLVING_NAME", array($arrayData["MESS_SERVER"])); + $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_RESOLVING_NAME", array($arrayData["MESS_SERVER"])); break; case 2: - $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_CHECK_PORT", array($arrayData["MESS_PORT"])); + $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_CHECK_PORT", array($arrayData["MESS_PORT"])); break; case 3: - $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_ESTABLISHING_CON_HOST", array($arrayData["MESS_SERVER"] . ":" . $arrayData["MESS_PORT"])); + $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_ESTABLISHING_CON_HOST", array($arrayData["MESS_SERVER"] . ":" . $arrayData["MESS_PORT"])); break; case 4: - $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_LOGIN", array($arrayData["MESS_ACCOUNT"], $arrayData["MESS_SERVER"])); + $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_LOGIN", array($arrayData["MESS_ACCOUNT"], $arrayData["MESS_SERVER"])); break; case 5: - $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = \G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_SENDING_EMAIL", array($arrayData["MAIL_TO"])); + $arrayResult[$arrayPhpMailerTestName[$step]]["title"] = G::LoadTranslation("ID_EMAIL_SERVER_TEST_CONNECTION_SENDING_EMAIL", array($arrayData["MAIL_TO"])); break; } } @@ -503,7 +547,7 @@ class EmailServer //Result return $arrayResult; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -513,7 +557,8 @@ class EmailServer * * @param string $emailServerUid Unique id of Email Server * - * return bool Return true if is default Email Server, false otherwise + * @return bool, return true if is default Email Server, false otherwise + * @throws Exception */ public function checkIfIsDefault($emailServerUid) { @@ -530,7 +575,7 @@ class EmailServer } else { return false; } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -541,7 +586,8 @@ class EmailServer * @param string $emailServerUid Unique id of Email Server * @param array $arrayData Data * - * return void Throw exception if data has an invalid value + * @return void Throw exception if data has an invalid value + * @throws Exception */ public function throwExceptionIfDataIsInvalid($emailServerUid, array $arrayData) { @@ -609,10 +655,10 @@ class EmailServer } if ($msg != "") { - throw new \Exception($msg); + throw new Exception($msg); } } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -623,7 +669,8 @@ class EmailServer * @param string $emailServerUid Unique id of Email Server * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if does not exist the Email Server in table EMAIL_SERVER + * @return void Throw exception if does not exist the Email Server in table EMAIL_SERVER + * @throws Exception */ public function throwExceptionIfNotExistsEmailServer($emailServerUid, $fieldNameForException) { @@ -631,9 +678,9 @@ class EmailServer $obj = \EmailServerPeer::retrieveByPK($emailServerUid); if (is_null($obj)) { - throw new \Exception(\G::LoadTranslation("ID_EMAIL_SERVER_DOES_NOT_EXIST", array($fieldNameForException, $emailServerUid))); + throw new Exception(G::LoadTranslation("ID_EMAIL_SERVER_DOES_NOT_EXIST", array($fieldNameForException, $emailServerUid))); } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -644,15 +691,16 @@ class EmailServer * @param string $emailServerUid Unique id of Email Server * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if is default Email Server + * @return void Throw exception if is default Email Server + * @throws Exception */ public function throwExceptionIfIsDefault($emailServerUid, $fieldNameForException) { try { if ($this->checkIfIsDefault($emailServerUid)) { - throw new \Exception(\G::LoadTranslation("ID_EMAIL_SERVER_IS_DEFAULT", array($fieldNameForException, $emailServerUid))); + throw new Exception(G::LoadTranslation("ID_EMAIL_SERVER_IS_DEFAULT", array($fieldNameForException, $emailServerUid))); } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -662,7 +710,8 @@ class EmailServer * * @param string $emailServerUid Unique id of Email Server * - * return void + * @return void + * @throws Exception */ public function setEmailServerDefaultByUid($emailServerUid) { @@ -703,7 +752,8 @@ class EmailServer * * @param array $arrayData Data * - * return array Return data of the new Email Server created + * @return array, data of the new Email Server created + * @throws Exception */ public function create(array $arrayData) { @@ -729,7 +779,7 @@ class EmailServer $emailServer = new \EmailServer(); $passwd = $arrayData["MESS_PASSWORD"]; - $passwdDec = \G::decrypt($passwd, "EMAILENCRYPT"); + $passwdDec = G::decrypt($passwd, "EMAILENCRYPT"); $auxPass = explode("hash:", $passwdDec); if (count($auxPass) > 1) { @@ -745,7 +795,7 @@ class EmailServer if ($arrayData["MESS_PASSWORD"] != "") { $arrayData["MESS_PASSWORD"] = "hash:" . $arrayData["MESS_PASSWORD"]; - $arrayData["MESS_PASSWORD"] = \G::encrypt($arrayData["MESS_PASSWORD"], "EMAILENCRYPT"); + $arrayData["MESS_PASSWORD"] = G::encrypt($arrayData["MESS_PASSWORD"], "EMAILENCRYPT"); } $emailServer->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME); @@ -765,7 +815,28 @@ class EmailServer $this->setEmailServerDefaultByUid($emailServerUid); } - //Return + //Logging the create action + $info = array( + 'action' => 'Create email server', + 'messUid'=> $emailServerUid, + 'engine'=> $arrayData["MESS_ENGINE"], + 'server' => $arrayData["MESS_SERVER"], + 'port' => $arrayData["MESS_PORT"], + 'requireAuthentication' => $arrayData["MESS_RAUTH"], + 'account' => $arrayData["MESS_ACCOUNT"], + 'senderEmail' => $arrayData["MESS_FROM_MAIL"], + 'senderName' => $arrayData["MESS_FROM_NAME"], + 'useSecureConnection' => $arrayData["SMTPSECURE"], + 'sendTestEmail' => $arrayData["MESS_TRY_SEND_INMEDIATLY"], + 'setAsDefaultConfiguration' => $arrayData["MESS_DEFAULT"] + ); + $this->setContextLog($info); + $this->syslog( + 'CreateEmailServer', + 200, + 'New email server was created', + $this->getContextLog() + ); return $this->getEmailServer($emailServerUid); } else { $msg = ""; @@ -774,14 +845,14 @@ class EmailServer $msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage(); } - throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); + throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); } - } catch (\Exception $e) { + } catch (Exception $e) { $cnn->rollback(); throw $e; } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -791,7 +862,8 @@ class EmailServer * * @param array $arrayData Data * - * return array Return data of the new Email Server created + * @return array, return data of the new Email Server created + * @throws Exception */ public function create2(array $arrayData) { @@ -828,14 +900,14 @@ class EmailServer $msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage(); } - throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); + throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); } - } catch (\Exception $e) { + } catch (Exception $e) { $cnn->rollback(); throw $e; } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -846,7 +918,8 @@ class EmailServer * @param string $emailServerUid Unique id of Group * @param array $arrayData Data * - * return array Return data of the Email Server updated + * @return array Return data of the Email Server updated + * @throws Exception */ public function update($emailServerUid, $arrayData) { @@ -874,7 +947,7 @@ class EmailServer if (isset($arrayData['MESS_PASSWORD'])) { $passwd = $arrayData['MESS_PASSWORD']; - $passwdDec = \G::decrypt($passwd, 'EMAILENCRYPT'); + $passwdDec = G::decrypt($passwd, 'EMAILENCRYPT'); $auxPass = explode('hash:', $passwdDec); if (count($auxPass) > 1) { @@ -890,7 +963,7 @@ class EmailServer if ($arrayData['MESS_PASSWORD'] != '') { $arrayData['MESS_PASSWORD'] = 'hash:' . $arrayData['MESS_PASSWORD']; - $arrayData['MESS_PASSWORD'] = \G::encrypt($arrayData['MESS_PASSWORD'], 'EMAILENCRYPT'); + $arrayData['MESS_PASSWORD'] = G::encrypt($arrayData['MESS_PASSWORD'], 'EMAILENCRYPT'); } } @@ -912,6 +985,29 @@ class EmailServer $arrayData = array_change_key_case($arrayData, CASE_LOWER); } + //Logging the update action + $info = array( + 'action' => 'Update email server', + 'messUid' => $emailServerUid, + 'engine' => $arrayData["MESS_ENGINE"], + 'server' => $arrayData["MESS_SERVER"], + 'port' => $arrayData["MESS_PORT"], + 'requireAuthentication' => $arrayData["MESS_RAUTH"], + 'account' => $arrayData["MESS_ACCOUNT"], + 'senderEmail' => $arrayData["MESS_FROM_MAIL"], + 'senderName' => $arrayData["MESS_FROM_NAME"], + 'useSecureConnection' => $arrayData["SMTPSECURE"], + 'sendTestEmail' => $arrayData["MESS_TRY_SEND_INMEDIATLY"], + 'setAsDefaultConfiguration' => $arrayData["MESS_DEFAULT"] + ); + $this->setContextLog($info); + $this->syslog( + 'UpdateEmailServer', + 200, + 'The email server was updated', + $this->getContextLog() + ); + return $arrayData; } else { $msg = ""; @@ -920,14 +1016,14 @@ class EmailServer $msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage(); } - throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); + throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : "")); } - } catch (\Exception $e) { + } catch (Exception $e) { $cnn->rollback(); throw $e; } - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -937,22 +1033,32 @@ class EmailServer * * @param string $emailServerUid Unique id of Email Server * - * return void + * @return void + * @throws Exception */ public function delete($emailServerUid) { try { //Verify data $this->throwExceptionIfNotExistsEmailServer($emailServerUid, $this->arrayFieldNameForException["emailServerUid"]); - $this->throwExceptionIfIsDefault($emailServerUid, $this->arrayFieldNameForException["emailServerUid"]); - $criteria = $this->getEmailServerCriteria(); - $criteria->add(\EmailServerPeer::MESS_UID, $emailServerUid, \Criteria::EQUAL); - \EmailServerPeer::doDelete($criteria); - } catch (\Exception $e) { + + //Logging the delete action + $info = array( + 'action' => 'Delete email server', + 'messUid' => $emailServerUid + ); + $this->setContextLog($info); + $this->syslog( + 'DeleteEmailServer', + 200, + 'The email server was deleted', + $this->getContextLog() + ); + } catch (Exception $e) { throw $e; } } @@ -982,7 +1088,7 @@ class EmailServer $criteria->addSelectColumn(\EmailServerPeer::MESS_DEFAULT); return $criteria; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -992,7 +1098,8 @@ class EmailServer * * @param array $record Record * - * return array Return an array with data Email Server + * @return array, return an array with data Email Server + * @throws Exception */ public function getEmailServerDataFromRecord(array $record) { @@ -1016,7 +1123,7 @@ class EmailServer $this->getFieldNameByFormatFieldName("MESS_EXECUTE_EVERY") => '', $this->getFieldNameByFormatFieldName("MESS_SEND_MAX") => '' ); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -1064,7 +1171,7 @@ class EmailServer //Return return $arrayData; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -1078,7 +1185,8 @@ class EmailServer * @param int $start Start * @param int $limit Limit * - * return array Return an array with all Email Servers + * @return array, return an array with all Email Servers + * @throws Exception */ public function getEmailServers($arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null) { @@ -1101,10 +1209,10 @@ class EmailServer if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") { $criteria->add( $criteria->getNewCriterion(\EmailServerPeer::MESS_ENGINE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr( - $criteria->getNewCriterion(\EmailServerPeer::MESS_SERVER, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( - $criteria->getNewCriterion(\EmailServerPeer::MESS_ACCOUNT, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( - $criteria->getNewCriterion(\EmailServerPeer::MESS_FROM_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( - $criteria->getNewCriterion(\EmailServerPeer::SMTPSECURE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)) + $criteria->getNewCriterion(\EmailServerPeer::MESS_SERVER, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( + $criteria->getNewCriterion(\EmailServerPeer::MESS_ACCOUNT, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( + $criteria->getNewCriterion(\EmailServerPeer::MESS_FROM_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))->addOr( + $criteria->getNewCriterion(\EmailServerPeer::SMTPSECURE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)) ); } @@ -1156,7 +1264,7 @@ class EmailServer $row = $rsCriteria->getRow(); $passwd = $row["MESS_PASSWORD"]; - $passwdDec = \G::decrypt($passwd, "EMAILENCRYPT"); + $passwdDec = G::decrypt($passwd, "EMAILENCRYPT"); $auxPass = explode("hash:", $passwdDec); if (count($auxPass) > 1) { @@ -1181,7 +1289,7 @@ class EmailServer "filter" => (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]))? $arrayFilterData["filter"] : "", "data" => $arrayEmailServer ); - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -1192,7 +1300,8 @@ class EmailServer * @param string $emailServerUid Unique id of Email Server * @param bool $flagGetRecord Value that set the getting * - * return array Return an array with data of a Email Server + * @return array, return an array with data of a Email Server + * @throws Exception */ public function getEmailServer($emailServerUid, $flagGetRecord = false) { @@ -1224,7 +1333,7 @@ class EmailServer //Return return (!$flagGetRecord)? $this->getEmailServerDataFromRecord($row) : $row; - } catch (\Exception $e) { + } catch (Exception $e) { throw $e; } } @@ -1246,5 +1355,31 @@ class EmailServer $rsCriteria->next(); return $rsCriteria->getRow(); } + + /** + * Logging information related to the email server + * When the user create, update, delete the email server + * + * @param string $channel + * @param string $level + * @param string $message + * @param array $context + * + * @return void + * @throws Exception + */ + private function syslog( + $channel, + $level, + $message, + $context = array() + ) + { + try { + Bootstrap::registerMonolog($channel, $level, $message, $context, $context['workspace'], 'processmaker.log'); + } catch (Exception $e) { + throw $e; + } + } } From 062df2b52736bfc3adf94166fa88852d722b390d Mon Sep 17 00:00:00 2001 From: davidcallizaya Date: Wed, 9 Aug 2017 16:00:49 -0400 Subject: [PATCH 7/7] HOR-3646 Restored requires needed --- gulliver/bin/gulliver.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gulliver/bin/gulliver.php b/gulliver/bin/gulliver.php index 99a5443c9..8ed17edf8 100644 --- a/gulliver/bin/gulliver.php +++ b/gulliver/bin/gulliver.php @@ -35,6 +35,8 @@ /** * require_once pakeFunction.php */ + require_once( PATH_THIRDPARTY . 'pake' . PATH_SEP . 'pakeFunction.php'); + require_once( PATH_THIRDPARTY . 'pake' . PATH_SEP . 'pakeGetopt.class.php'); require_once( PATH_CORE . 'config' . PATH_SEP . 'environments.php'); // trap -V before pake