/** * Processing of replacing in content * * @param string $data * * @return string */ protected function process_replacing($data) { errors_off(); foreach ($this->Search as $i => $search) { $data = _preg_replace($search, $this->Replace[$i], $data) ?: str_replace($search, $this->Replace[$i], $data); } errors_on(); return $data; }
/** * Test connection to the DB * * @param array|string $data Array or string in JSON format of connection parameters * * @return bool */ function test($data) { $Core = Core::instance(); if (empty($data)) { return false; } elseif (is_array($data)) { $Config = Config::instance(); if (isset($data[1])) { $db = $Config->db[$data[0]]['mirrors'][$data[1]]; } elseif (isset($data[0])) { if ($data[0] == 0) { $db = ['type' => $Core->db_type, 'host' => $Core->db_host, 'name' => $Core->db_name, 'user' => $Core->db_user, 'password' => $Core->db_password, 'charset' => $Core->db_charset]; } else { $db = $Config->db[$data[0]]; } } else { return false; } } else { $db = _json_decode($data); } unset($data); if (is_array($db)) { errors_off(); $engine_class = '\\cs\\DB\\' . $db['type']; $test = new $engine_class($db['name'], $db['user'], $db['password'], $db['host'] ?: $Core->db_host, $db['charset'] ?: $Core->db_charset); errors_on(); return $test->connected(); } else { return false; } }
$query[] = sprintf("UPDATE person SET password = '******' WHERE personID = 1;", encrypt_password("alloc")); $query[] = sprintf("UPDATE config SET value = '%s' WHERE name = 'allocTimezone';", $timeZone); file_put_contents($_FORM["ATTACHMENTS_DIR"] . "db_config.sql", implode("\n", $query)); } if ($failed) { $TPL["img_install_result"] = IMG_CROSS; $TPL["msg_install_result"] = "The allocPSA installation has encountered errors."; $_GET["tab"] = 2; } else { define("INSTALL_SUCCESS", 1); $TPL["img_install_result"] = IMG_TICK; $_GET["tab"] = 3; } } if ($_POST["test_db"]) { errors_off(); $db = new db($_FORM["ALLOC_DB_USER"], $_FORM["ALLOC_DB_PASS"], $_FORM["ALLOC_DB_HOST"], $_FORM["ALLOC_DB_NAME"]); singleton("db", $db); // this makes db_esc() work as expected // Test supplied credentials if ($db->connect()) { $text_tab_3b[] = "Connected to MySQL database server as user '" . $_FORM["ALLOC_DB_USER"] . "'."; } else { $text_tab_3b[] = "<b>Unable to connect to MySQL database server! (" . $db->get_error() . ").</b>"; $failed = 1; } if (!$failed) { if ($db->select_db($_FORM["ALLOC_DB_NAME"])) { $text_tab_3b[] = "Connected to database '" . $_FORM["ALLOC_DB_NAME"] . "'."; } else { $text_tab_3b[] = "<b>Unable to select database '" . $_FORM["ALLOC_DB_NAME"] . "'. (" . $db->get_error() . ").</b>";
/** * Decryption of data * * @param string $data Data to be decrypted * @param bool|string $key Key, if not specified - system key will be used * * @return bool|mixed */ function decrypt($data, $key = false) { if (!$this->encrypt_support) { return $data; } if (!is_resource($this->td)) { $this->td = mcrypt_module_open(MCRYPT_BLOWFISH, '', 'cbc', ''); $this->key = mb_substr($this->key, 0, mcrypt_enc_get_key_size($this->td)); $this->iv = mb_substr(md5($this->iv), 0, mcrypt_enc_get_iv_size($this->td)); } if ($key === false) { $key = $this->key; } else { $key = mb_substr(md5($this->key) . md5($key), 0, mcrypt_enc_get_key_size($this->td)); } mcrypt_generic_init($this->td, $key, $this->iv); errors_off(); $decrypted = @unserialize(mdecrypt_generic($this->td, $data)); errors_on(); mcrypt_generic_deinit($this->td); if (is_array($decrypted) && $decrypted['key'] == $key) { return $decrypted['data']; } else { return false; } }