2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
2017-02-15 16:26:02 +00:00
|
|
|
|
2020-04-09 17:45:04 -04:00
|
|
|
use Processmaker\Core\System;
|
2023-03-24 17:55:53 +00:00
|
|
|
use ProcessMaker\Exception\RBACException;
|
|
|
|
|
|
|
|
|
|
// Include global object RBAC
|
|
|
|
|
global $RBAC;
|
|
|
|
|
|
|
|
|
|
// Check if the current user have the correct permissions to access to this resource, if not throws a RBAC Exception with code 403
|
|
|
|
|
if ($RBAC->userCanAccess('PM_SETUP_ADVANCE') !== 1 || $RBAC->userCanAccess('PM_SETUP_CASES_LIST_CACHE_BUILDER') !== 1) {
|
|
|
|
|
throw new RBACException('ID_ACCESS_DENIED', 403);
|
|
|
|
|
}
|
2020-04-09 17:45:04 -04:00
|
|
|
|
2015-03-16 15:24:35 -04:00
|
|
|
$filter = new InputFilter();
|
|
|
|
|
$_POST = $filter->xssFilterHard($_POST);
|
|
|
|
|
$_GET = $filter->xssFilterHard($_GET);
|
2016-02-26 11:20:15 -04:00
|
|
|
$request = isset($_POST['request']) ? $_POST['request'] : (isset($_GET['request']) ? $_GET['request'] : null);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
switch ($request) {
|
2010-12-02 23:34:41 +00:00
|
|
|
//check if the APP_CACHE VIEW table and their triggers are installed
|
|
|
|
|
case 'info':
|
2012-10-17 15:40:37 -04:00
|
|
|
$result = new stdClass();
|
2017-12-04 13:25:35 +00:00
|
|
|
$result->info = [];
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
//check the language, if no info in config about language, the default is 'en'
|
|
|
|
|
$oConf = new Configurations();
|
2016-02-26 11:20:15 -04:00
|
|
|
$oConf->loadConfig($x, 'APP_CACHE_VIEW_ENGINE', '', '', '', '');
|
2012-10-17 15:40:37 -04:00
|
|
|
$appCacheViewEngine = $oConf->aConfig;
|
|
|
|
|
|
2016-02-26 11:20:15 -04:00
|
|
|
if (isset($appCacheViewEngine['LANG'])) {
|
2013-01-23 13:02:13 -04:00
|
|
|
$lang = (defined('SYS_LANG')) ? SYS_LANG : $appCacheViewEngine['LANG'];
|
2016-02-26 11:20:15 -04:00
|
|
|
$status = strtoupper($appCacheViewEngine['STATUS']);
|
2012-10-17 15:40:37 -04:00
|
|
|
} else {
|
2016-02-26 11:20:15 -04:00
|
|
|
$confParams = array('LANG' => (defined('SYS_LANG')) ? SYS_LANG : 'en', 'STATUS' => '');
|
2012-10-17 15:40:37 -04:00
|
|
|
$oConf->aConfig = $confParams;
|
2016-02-26 11:20:15 -04:00
|
|
|
$oConf->saveConfig('APP_CACHE_VIEW_ENGINE', '', '', '');
|
2013-01-23 13:02:13 -04:00
|
|
|
$lang = (defined('SYS_LANG')) ? SYS_LANG : 'en';
|
2012-10-17 15:40:37 -04:00
|
|
|
$status = '';
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-17 15:40:37 -04:00
|
|
|
//get user Root from hash
|
2017-12-04 13:25:35 +00:00
|
|
|
$result->info = [];
|
2012-10-17 15:40:37 -04:00
|
|
|
$result->error = false;
|
|
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
//setup the appcacheview object, and the path for the sql files
|
|
|
|
|
$appCache = new AppCacheView();
|
2016-02-26 11:20:15 -04:00
|
|
|
$appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
2013-03-20 17:12:15 -04:00
|
|
|
|
2012-10-17 15:40:37 -04:00
|
|
|
$res = $appCache->getMySQLVersion();
|
2013-03-14 15:15:04 -04:00
|
|
|
//load translations G::LoadTranslation
|
2016-02-26 11:20:15 -04:00
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_MYSQL_VERSION'), 'value' => $res);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->checkGrantsForUser(false);
|
2012-10-17 15:40:37 -04:00
|
|
|
$currentUser = $res['user'];
|
|
|
|
|
$currentUserIsSuper = $res['super'];
|
2016-02-26 11:20:15 -04:00
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_CURRENT_USER'), 'value' => $currentUser);
|
|
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_USER_SUPER_PRIVILEGE'), 'value' => $currentUserIsSuper);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
try {
|
2016-02-26 11:20:15 -04:00
|
|
|
PROPEL::Init(PATH_METHODS . 'dbConnections/rootDbConnections.php');
|
|
|
|
|
$con = Propel::getConnection("root");
|
2012-10-17 15:40:37 -04:00
|
|
|
} catch (Exception $e) {
|
2016-02-26 11:20:15 -04:00
|
|
|
$result->info[] = array('name' => 'Checking MySql Root user', 'value' => 'failed');
|
2012-10-17 15:40:37 -04:00
|
|
|
$result->error = true;
|
|
|
|
|
$result->errorMsg = $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if user does not have the SUPER privilege we need to use the root user and grant the SUPER priv. to normal user.
|
2016-02-26 11:20:15 -04:00
|
|
|
if (!$currentUserIsSuper && !$result->error) {
|
|
|
|
|
$res = $appCache->checkGrantsForUser(true);
|
|
|
|
|
if (!isset($res['error'])) {
|
|
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_ROOT_USER'), 'value' => $res['user']);
|
|
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_ROOT_USER_SUPER'), 'value' => $res['super']);
|
2012-10-17 15:40:37 -04:00
|
|
|
} else {
|
2016-02-26 11:20:15 -04:00
|
|
|
$result->info[] = array('name' => 'Error', 'value' => $res['msg']);
|
2012-10-17 15:40:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//now check if table APPCACHEVIEW exists, and it have correct number of fields, etc.
|
|
|
|
|
$res = $appCache->checkAppCacheView();
|
2016-02-26 11:20:15 -04:00
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_TABLE'), 'value' => $res['found']);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
2016-02-26 11:20:15 -04:00
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_ROWS'), 'value' => $res['count']);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
//now check if we have the triggers installed
|
|
|
|
|
//APP_DELEGATION INSERT
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->triggerAppDelegationInsert($lang, false);
|
|
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_TRIGGER_INSERT'), 'value' => $res);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
//APP_DELEGATION Update
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->triggerAppDelegationUpdate($lang, false);
|
|
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_TRIGGER_UPDATE'), 'value' => $res);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
//APPLICATION UPDATE
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->triggerApplicationUpdate($lang, false);
|
|
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_TRIGGER_APPLICATION_UPDATE'), 'value' => $res);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
//APPLICATION DELETE
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->triggerApplicationDelete($lang, false);
|
|
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_TRIGGER_APPLICATION_DELETE'), 'value' => $res);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
2013-09-25 17:24:04 -04:00
|
|
|
//SUB_APPLICATION INSERT
|
|
|
|
|
$res = $appCache->triggerSubApplicationInsert($lang, false);
|
|
|
|
|
|
2012-05-10 11:06:44 -04:00
|
|
|
//CONTENT UPDATE
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->triggerContentUpdate($lang, false);
|
|
|
|
|
$result->info[] = array("name" => G::LoadTranslation('ID_CACHE_BUILDER_TRIGGER_CONTENT_UPDATE'), "value" => $res);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
//show language
|
2016-02-26 11:20:15 -04:00
|
|
|
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_LANGUAGE'), 'value' => $lang);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
2016-02-26 11:20:15 -04:00
|
|
|
echo G::json_encode($result);
|
2012-10-17 15:40:37 -04:00
|
|
|
break;
|
|
|
|
|
case 'getLangList':
|
2016-02-26 11:20:15 -04:00
|
|
|
$Translations = G::getModel('Translation');
|
2012-10-17 15:40:37 -04:00
|
|
|
$result = new stdClass();
|
2017-12-04 13:25:35 +00:00
|
|
|
$result->rows = [];
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
$langs = $Translations->getTranslationEnvironments();
|
|
|
|
|
foreach ($langs as $lang) {
|
2016-02-26 11:20:15 -04:00
|
|
|
$result->rows[] = array('LAN_ID' => $lang['LOCALE'], 'LAN_NAME' => $lang['LANGUAGE']);
|
2012-10-17 15:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
print(G::json_encode($result));
|
2012-10-17 15:40:37 -04:00
|
|
|
break;
|
|
|
|
|
case 'build':
|
2017-12-04 13:25:35 +00:00
|
|
|
$sqlToExe = [];
|
2012-10-17 15:40:37 -04:00
|
|
|
$conf = new Configurations();
|
|
|
|
|
|
|
|
|
|
//DEPRECATED $lang = $_POST['lang'];
|
|
|
|
|
//there is no more support for other languages that english
|
2013-01-23 13:02:13 -04:00
|
|
|
$lang = (defined('SYS_LANG')) ? SYS_LANG : 'en';
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
//setup the appcacheview object, and the path for the sql files
|
|
|
|
|
$appCache = new AppCacheView();
|
2016-02-26 11:20:15 -04:00
|
|
|
$appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
2013-01-28 16:49:00 -04:00
|
|
|
//Update APP_DELEGATION.DEL_LAST_INDEX data
|
|
|
|
|
$res = $appCache->updateAppDelegationDelLastIndex($lang, true);
|
|
|
|
|
|
2012-10-17 15:40:37 -04:00
|
|
|
//APP_DELEGATION INSERT
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->triggerAppDelegationInsert($lang, true);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//APP_DELEGATION Update
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->triggerAppDelegationUpdate($lang, true);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//APPLICATION UPDATE
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->triggerApplicationUpdate($lang, true);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//APPLICATION DELETE
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->triggerApplicationDelete($lang, true);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
2013-09-25 17:24:04 -04:00
|
|
|
//SUB_APPLICATION INSERT
|
|
|
|
|
$res = $appCache->triggerSubApplicationInsert($lang, false);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
//CONTENT UPDATE
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->triggerContentUpdate($lang, true);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
//build using the method in AppCacheView Class
|
2016-02-26 11:20:15 -04:00
|
|
|
$res = $appCache->fillAppCacheView($lang);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
|
|
|
|
//set status in config table
|
2016-02-26 11:20:15 -04:00
|
|
|
$confParams = array('LANG' => $lang, 'STATUS' => 'active');
|
2012-10-17 15:40:37 -04:00
|
|
|
$conf->aConfig = $confParams;
|
2016-02-26 11:20:15 -04:00
|
|
|
$conf->saveConfig('APP_CACHE_VIEW_ENGINE', '', '', '');
|
2012-10-17 15:40:37 -04:00
|
|
|
|
2014-09-25 15:33:21 -04:00
|
|
|
$result = new StdClass();
|
2012-10-17 15:40:37 -04:00
|
|
|
$result->success = true;
|
2013-08-26 10:49:48 -04:00
|
|
|
$result->msg = G::LoadTranslation('ID_TITLE_COMPLETED');
|
2014-10-08 15:23:38 -04:00
|
|
|
G::auditLog("BuildCache");
|
2016-02-26 11:20:15 -04:00
|
|
|
echo G::json_encode($result);
|
2012-10-17 15:40:37 -04:00
|
|
|
} catch (Exception $e) {
|
2016-02-26 11:20:15 -04:00
|
|
|
$confParams = array('lang' => $lang, 'status' => 'failed');
|
|
|
|
|
$appCacheViewEngine = $oServerConf->setProperty('APP_CACHE_VIEW_ENGINE', $confParams);
|
2012-10-17 15:40:37 -04:00
|
|
|
|
2016-07-27 16:37:21 -04:00
|
|
|
$token = strtotime("now");
|
|
|
|
|
PMException::registerErrorLog($e, $token);
|
|
|
|
|
$varRes = '{success: false, msg:"' . G::LoadTranslation("ID_EXCEPTION_LOG_INTERFAZ", array($token)) . '"}';
|
2017-12-04 13:25:35 +00:00
|
|
|
G::outRes($varRes);
|
2012-10-17 15:40:37 -04:00
|
|
|
}
|
|
|
|
|
break;
|
2010-12-02 23:34:41 +00:00
|
|
|
case 'recreate-root':
|
2020-04-23 16:39:11 -04:00
|
|
|
// Get the post variables
|
|
|
|
|
$user = !empty($_POST['user']) ? $_POST['user'] : '';
|
|
|
|
|
$pass = !empty($_POST['password']) ? $_POST['password'] : '';
|
|
|
|
|
$server = !empty($_POST['host']) ? $_POST['host'] : '';
|
|
|
|
|
$code = !empty($_POST['codeCaptcha']) ? $_POST['codeCaptcha'] : '';
|
|
|
|
|
|
|
|
|
|
// Check if in the host was included the port
|
2020-04-09 17:45:04 -04:00
|
|
|
$server = explode(':', $server);
|
|
|
|
|
$serverName = $server[0];
|
|
|
|
|
$port = (count($server) > 1) ? $server[1] : '';
|
2020-04-23 16:39:11 -04:00
|
|
|
|
|
|
|
|
// Review if the captcha is not empty
|
|
|
|
|
if (empty($code)) {
|
|
|
|
|
echo G::loadTranslation('ID_CAPTCHA_CODE_INCORRECT');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Review if th captcha is incorrect
|
2016-02-26 11:20:15 -04:00
|
|
|
if ($code !== $_SESSION['securimage_code_disp']['default']) {
|
|
|
|
|
echo G::loadTranslation('ID_CAPTCHA_CODE_INCORRECT');
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-04-23 16:39:11 -04:00
|
|
|
// Define a message of failure
|
|
|
|
|
$message = G::loadTranslation('ID_MESSAGE_ROOT_CHANGE_FAILURE');
|
|
|
|
|
if (!empty($user) && !empty($pass) && !empty($serverName)) {
|
|
|
|
|
list($success, $message) = System::checkPermissionsDbUser(DB_ADAPTER, $serverName, $port, $user, $pass);
|
|
|
|
|
if ($success) {
|
|
|
|
|
$id = 'ID_MESSAGE_ROOT_CHANGE_FAILURE';
|
|
|
|
|
if (System::regenerateCredentiaslPathInstalled($serverName, $user, $pass)) {
|
|
|
|
|
$id = 'ID_MESSAGE_ROOT_CHANGE_SUCESS';
|
|
|
|
|
}
|
|
|
|
|
$message = G::loadTranslation($id);
|
2013-03-20 17:12:15 -04:00
|
|
|
}
|
2012-10-17 15:40:37 -04:00
|
|
|
}
|
2020-04-23 16:39:11 -04:00
|
|
|
|
2020-04-09 17:45:04 -04:00
|
|
|
echo $message;
|
2012-10-17 15:40:37 -04:00
|
|
|
break;
|
2016-02-26 11:20:15 -04:00
|
|
|
case 'captcha':
|
|
|
|
|
$img = new Securimage();
|
|
|
|
|
$img->show();
|
|
|
|
|
break;
|
2012-10-17 15:40:37 -04:00
|
|
|
}
|