Spaces:
Sleeping
Sleeping
File size: 15,145 Bytes
07c3cdd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | <?php
$filter = new InputFilter();
$_POST = $filter->xssFilterHard($_POST);
$_GET = $filter->xssFilterHard($_GET);
$request = isset($_POST['request']) ? $_POST['request'] : (isset($_GET['request']) ? $_GET['request'] : null);
function testConnection($type, $server, $user, $passwd, $port = 'none', $dbName = "")
{
if (($port == 'none') || ($port == '') || ($port == 0)) {
//setting defaults ports
switch ($type) {
case 'mysql':
$port = 3306;
break;
case 'pgsql':
$port = 5432;
break;
case 'mssql':
$port = 1433;
break;
case 'oracle':
$port = 1521;
break;
}
}
$Server = new Net($server);
$filter = new InputFilter();
if ($Server->getErrno() == 0) {
$Server->scannPort($port);
if ($Server->getErrno() == 0) {
$Server->loginDbServer($user, $passwd);
$Server->setDataBase($dbName, $port);
if ($Server->errno == 0) {
$response = $Server->tryConnectServer($type);
if ($response->status == 'SUCCESS') {
if ($Server->errno == 0) {
$message = "";
$response = $Server->tryConnectServer($type);
$server = $filter->validateInput($server);
$user = $filter->validateInput($user);
$passwd = $filter->validateInput($passwd);
$connDatabase = @mysql_connect($server, $user, $passwd);
$dbNameTest = "PROCESSMAKERTESTDC";
$dbNameTest = $filter->validateInput($dbNameTest, 'nosql');
$query = "CREATE DATABASE %s";
$query = $filter->preventSqlInjection($query, array($dbNameTest), $connDatabase);
$db = @mysql_query($query, $connDatabase);
$success = false;
if (!$db) {
$message = mysql_error();;
} else {
$usrTest = "wfrbtest";
$chkG = "GRANT ALL PRIVILEGES ON `%s`.* TO %s@'%%' IDENTIFIED BY 'sample' WITH GRANT OPTION";
$chkG = $filter->preventSqlInjection($chkG, array($dbNameTest, $usrTest), $connDatabase);
$ch = @mysql_query($chkG, $connDatabase);
if (!$ch) {
$message = mysql_error();
} else {
$sqlCreateUser = "CREATE USER '%s'@'%%' IDENTIFIED BY '%s'";
$user = $filter->validateInput($user, 'nosql');
$sqlCreateUser = $filter->preventSqlInjection($sqlCreateUser, array($user . "_usertest", "sample"), $connDatabase);
$result = @mysql_query($sqlCreateUser, $connDatabase);
if (!$result) {
$message = mysql_error();
} else {
$success = true;
$message = G::LoadTranslation('ID_SUCCESSFUL_CONNECTION');
}
$sqlDropUser = "DROP USER '%s'@'%%'";
$user = $filter->validateInput($user, 'nosql');
$sqlDropUser = $filter->preventSqlInjection($sqlDropUser, array($user . "_usertest"), $connDatabase);
@mysql_query($sqlDropUser, $connDatabase);
$sqlDropUser = "DROP USER %s@'%%'";
$usrTest = $filter->validateInput($usrTest, 'nosql');
$sqlDropUser = $filter->preventSqlInjection($sqlDropUser, array($usrTest), $connDatabase);
@mysql_query($sqlDropUser, $connDatabase);
}
$sqlDropDb = "DROP DATABASE %s";
$dbNameTest = $filter->validateInput($dbNameTest, 'nosql');
$sqlDropDb = $filter->preventSqlInjection($sqlDropDb, array($dbNameTest), $connDatabase);
@mysql_query($sqlDropDb, $connDatabase);
}
return array($success, ($message != "") ? $message : $Server->error);
} else {
return array(false, $Server->error);
}
} else {
return array(false, $Server->error);
}
} else {
return array(false, $Server->error);
}
} else {
return array(false, $Server->error);
}
} else {
return array(false, $Server->error);
}
}
switch ($request) {
//check if the APP_CACHE VIEW table and their triggers are installed
case 'info':
$result = new stdClass();
$result->info = array();
//check the language, if no info in config about language, the default is 'en'
$oConf = new Configurations();
$oConf->loadConfig($x, 'APP_CACHE_VIEW_ENGINE', '', '', '', '');
$appCacheViewEngine = $oConf->aConfig;
if (isset($appCacheViewEngine['LANG'])) {
$lang = (defined('SYS_LANG')) ? SYS_LANG : $appCacheViewEngine['LANG'];
$status = strtoupper($appCacheViewEngine['STATUS']);
} else {
$confParams = array('LANG' => (defined('SYS_LANG')) ? SYS_LANG : 'en', 'STATUS' => '');
$oConf->aConfig = $confParams;
$oConf->saveConfig('APP_CACHE_VIEW_ENGINE', '', '', '');
$lang = (defined('SYS_LANG')) ? SYS_LANG : 'en';
$status = '';
}
//get user Root from hash
$result->info = array();
$result->error = false;
//setup the appcacheview object, and the path for the sql files
$appCache = new AppCacheView();
$appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
$res = $appCache->getMySQLVersion();
//load translations G::LoadTranslation
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_MYSQL_VERSION'), 'value' => $res);
$res = $appCache->checkGrantsForUser(false);
$currentUser = $res['user'];
$currentUserIsSuper = $res['super'];
$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);
try {
PROPEL::Init(PATH_METHODS . 'dbConnections/rootDbConnections.php');
$con = Propel::getConnection("root");
} catch (Exception $e) {
$result->info[] = array('name' => 'Checking MySql Root user', 'value' => 'failed');
$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.
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']);
} else {
$result->info[] = array('name' => 'Error', 'value' => $res['msg']);
}
}
//now check if table APPCACHEVIEW exists, and it have correct number of fields, etc.
$res = $appCache->checkAppCacheView();
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_TABLE'), 'value' => $res['found']);
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_ROWS'), 'value' => $res['count']);
//now check if we have the triggers installed
//APP_DELEGATION INSERT
$res = $appCache->triggerAppDelegationInsert($lang, false);
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_TRIGGER_INSERT'), 'value' => $res);
//APP_DELEGATION Update
$res = $appCache->triggerAppDelegationUpdate($lang, false);
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_TRIGGER_UPDATE'), 'value' => $res);
//APPLICATION UPDATE
$res = $appCache->triggerApplicationUpdate($lang, false);
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_TRIGGER_APPLICATION_UPDATE'), 'value' => $res);
//APPLICATION DELETE
$res = $appCache->triggerApplicationDelete($lang, false);
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_TRIGGER_APPLICATION_DELETE'), 'value' => $res);
//SUB_APPLICATION INSERT
$res = $appCache->triggerSubApplicationInsert($lang, false);
//CONTENT UPDATE
$res = $appCache->triggerContentUpdate($lang, false);
$result->info[] = array("name" => G::LoadTranslation('ID_CACHE_BUILDER_TRIGGER_CONTENT_UPDATE'), "value" => $res);
//show language
$result->info[] = array('name' => G::LoadTranslation('ID_CACHE_BUILDER_LANGUAGE'), 'value' => $lang);
echo G::json_encode($result);
break;
case 'getLangList':
$Translations = G::getModel('Translation');
$result = new stdClass();
$result->rows = array();
$langs = $Translations->getTranslationEnvironments();
foreach ($langs as $lang) {
$result->rows[] = array('LAN_ID' => $lang['LOCALE'], 'LAN_NAME' => $lang['LANGUAGE']);
}
print (G::json_encode($result));
break;
case 'build':
$sqlToExe = array();
$conf = new Configurations();
//DEPRECATED $lang = $_POST['lang'];
//there is no more support for other languages that english
$lang = (defined('SYS_LANG')) ? SYS_LANG : 'en';
try {
//setup the appcacheview object, and the path for the sql files
$appCache = new AppCacheView();
$appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup' . PATH_SEP . 'setupSchemas' . PATH_SEP);
//Update APP_DELEGATION.DEL_LAST_INDEX data
$res = $appCache->updateAppDelegationDelLastIndex($lang, true);
//$result->info[] = array("name" => "update APP_DELEGATION.DEL_LAST_INDEX", "value" => $res);
//APP_DELEGATION INSERT
$res = $appCache->triggerAppDelegationInsert($lang, true);
//$result->info[] = array ('name' => 'Trigger APP_DELEGATION INSERT', 'value'=> $res);
//APP_DELEGATION Update
$res = $appCache->triggerAppDelegationUpdate($lang, true);
//$result->info[] = array ('name' => 'Trigger APP_DELEGATION UPDATE', 'value'=> $res);
//APPLICATION UPDATE
$res = $appCache->triggerApplicationUpdate($lang, true);
//$result->info[] = array ('name' => 'Trigger APPLICATION UPDATE', 'value'=> $res);
//APPLICATION DELETE
$res = $appCache->triggerApplicationDelete($lang, true);
//$result->info[] = array ('name' => 'Trigger APPLICATION DELETE', 'value'=> $res);
//SUB_APPLICATION INSERT
$res = $appCache->triggerSubApplicationInsert($lang, false);
//CONTENT UPDATE
$res = $appCache->triggerContentUpdate($lang, true);
//$result->info[] = array("name" => "Trigger CONTENT UPDATE", "value" => $res);
//build using the method in AppCacheView Class
$res = $appCache->fillAppCacheView($lang);
//$result->info[] = array ('name' => 'build APP_CACHE_VIEW', 'value'=> $res);
//set status in config table
$confParams = array('LANG' => $lang, 'STATUS' => 'active');
$conf->aConfig = $confParams;
$conf->saveConfig('APP_CACHE_VIEW_ENGINE', '', '', '');
$result = new StdClass();
$result->success = true;
$result->msg = G::LoadTranslation('ID_TITLE_COMPLETED');
G::auditLog("BuildCache");
echo G::json_encode($result);
} catch (Exception $e) {
$confParams = array('lang' => $lang, 'status' => 'failed');
$appCacheViewEngine = $oServerConf->setProperty('APP_CACHE_VIEW_ENGINE', $confParams);
$token = strtotime("now");
PMException::registerErrorLog($e, $token);
$varRes = '{success: false, msg:"' . G::LoadTranslation("ID_EXCEPTION_LOG_INTERFAZ", array($token)) . '"}';
G::outRes( $varRes );
}
break;
case 'recreate-root':
$user = $_POST['user'];
$passwd = $_POST['password'];
$server = $_POST['host'];
$code = $_POST['codeCaptcha'];
$aServer = explode(':', $server);
$serverName = $aServer[0];
$port = (count($aServer) > 1) ? $aServer[1] : "none";
if ($code !== $_SESSION['securimage_code_disp']['default']) {
echo G::loadTranslation('ID_CAPTCHA_CODE_INCORRECT');
break;
}
list($sucess, $msgErr) = testConnection(DB_ADAPTER, $serverName, $user, $passwd, $port);
if ($sucess) {
$sh = G::encryptOld(filemtime(PATH_GULLIVER . "/class.g.php"));
$h = G::encrypt($_POST['host'] . $sh . $_POST['user'] . $sh . $_POST['password'] . $sh . (1), $sh);
$insertStatements = "define ( 'HASH_INSTALLATION','{$h}' ); \ndefine ( 'SYSTEM_HASH', '{$sh}' ); \n";
$lines = array();
$content = '';
$filename = PATH_HOME . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'paths_installed.php';
$lines = file($filename);
$count = 1;
foreach ($lines as $line_num => $line) {
$pos = strpos($line, "define");
if ($pos !== false && $count < 3) {
$content = $content . $line;
$count++;
}
}
$content = "<?php \n" . $content . "\n" . $insertStatements . "\n";
if (file_put_contents($filename, $content) != false) {
echo G::loadTranslation('ID_MESSAGE_ROOT_CHANGE_SUCESS');
} else {
echo G::loadTranslation('ID_MESSAGE_ROOT_CHANGE_FAILURE');
}
} else {
echo $msgErr;
}
break;
case 'captcha':
require_once PATH_TRUNK . 'vendor/dapphp/securimage/securimage.php';
$img = new Securimage();
$img->show();
break;
}
|