/** * */ function onAction() { global $application; CCacheFactory::clearAll(); modApiFunc("Tools", "clearBackupSession"); modApiFunc("Tools", "setDBStat", modApiFunc("Modules_Manager", "getTablesAndRecordsCount")); modApiFunc("Tools", "setCurrentBackupTable", 0); modApiFunc("Tools", "setCurrentBackupTableLimit", 0); modApiFunc("Tools", "setDBRecordsExported", 0); $request = $application->getInstance('Request'); $filename = $request->getValueByKey('BackupFile'); if ($filename) { modApiFunc("Tools", "setRestoreStatus", 'BACKUP'); modApiFunc("Tools", "setRestoreFile", $filename); $filename = modApiFunc("Tools", "getRestoreFile"); $full_filename = $application->getAppIni('PATH_BACKUP_DIR') . $filename . "/dump.sql"; $handle = @fopen($full_filename, "rb"); $backup_file_content = @fread($handle, 1024); @fclose($handle); $error = ""; $backup_info = @_parse_ini_file($application->getAppIni('PATH_BACKUP_DIR') . $filename . "/info/backup.ini"); if (!isset($backup_info["asc_version"]) || $backup_info["asc_version"] != PRODUCT_VERSION) { $error = "BCP_RESTORE_ERR_003"; } elseif (!$backup_file_content) { $error = "BCP_RESTORE_ERR_001"; } elseif (_ml_strpos($backup_file_content, "-- HASH: ") === false) { $error = "BCP_RESTORE_ERR_002"; } else { $hash = _byte_substr($backup_file_content, 9, 32); // $handle = fopen($full_filename, "rb"); $md5_temp = ''; // $begin = _byte_strpos($backup_file_content, "\n") + _byte_strlen("\n"); fseek($handle, $begin); while (!feof($handle)) { $contents = fread($handle, 1048576); $md5_temp .= md5($contents); } $counted_file_hash = md5($md5_temp); fclose($handle); // : if ($hash != $counted_file_hash) { $error = "BCP_RESTORE_ERR_002"; } } if ($error) { modApiFunc("Tools", "setRestoreError", $error); } else { modApiFunc("Tools", "setStringsCountInRestoreFile", $filename); } } modApiFunc("Tools", "saveState"); }
/** * see blowfish_ab_pad_text */ function blowfish_ab_unpad_text($text) { if (empty($text)) { //Perhaps it's a wrong situation. return ""; } // $pad_char = $text[_byte_strlen($text)-1]; $pad_char = _byte_substr($text, -1, 1); $i = _byte_strlen($text) - 1; for (; $i >= 0 && _byte_substr($text, $i, 1) == $pad_char; $i--) { } $new_len = $i + 1; $text = _byte_substr($text, 0, $new_len); return $text; }
function _byte_substr_replace($string, $replacement, $start, $length = NULL) { if ($length === NULL) { $length = _byte_strlen($string); } return substr_replace($string, $replacement, $start, $length); }
/** * Calculates bitwise or of $num1 and $num2, * starting from bit $start_pos for number $num1 * * @param string $num1 * @param string $num2 * @param int $start_pos * @return string * @access public */ function bitOr($num1, $num2, $start_pos) { // $num1 = new Math_BigInteger($num1, 10); $num2 = new Math_BigInteger($num2, 10); $start_byte = intval($start_pos / 8); $start_bit = $start_pos % 8; $tmp1 = $this->int2bin($num1); $num2 = $num2->multiply(new Math_BigInteger(1 << $start_bit)); $tmp2 = $this->int2bin($num2->toString()); if ($start_byte < _byte_strlen($tmp1)) { $tmp2 |= _byte_substr($tmp1, $start_byte); $tmp1 = _byte_substr($tmp1, 0, $start_byte) . $tmp2; } else { $tmp1 = str_pad($tmp1, $start_byte, "") . $tmp2; } return $this->bin2int($tmp1); }
function _httpsrequest($url, $URI, $http_method, $content_type = "", $body = "") { if ($this->passcookies && $this->_redirectaddr) { $this->setcookies(); } $headers = array(); $URI_PARTS = parse_url($URI); if (empty($url)) { $url = "/"; } // GET ... header not needed for curl //$headers[] = $http_method." ".$url." ".$this->_httpversion; if (!empty($this->agent)) { $headers[] = "User-Agent: " . $this->agent; } if (!empty($this->host)) { $headers[] = "Host: " . $this->host; } if (!empty($this->accept)) { $headers[] = "Accept: " . $this->accept; } if (!empty($this->referer)) { $headers[] = "Referer: " . $this->referer; } if (!empty($this->cookies)) { if (!is_array($this->cookies)) { $this->cookies = (array) $this->cookies; } reset($this->cookies); if (count($this->cookies) > 0) { $cookie_str = 'Cookie: '; foreach ($this->cookies as $cookieKey => $cookieVal) { $cookie_str .= $cookieKey . "=" . urlencode($cookieVal) . "; "; } $headers[] = _byte_substr($cookie_str, 0, -2); } } if (!empty($this->rawheaders)) { if (!is_array($this->rawheaders)) { $this->rawheaders = (array) $this->rawheaders; } while (list($headerKey, $headerVal) = each($this->rawheaders)) { $headers[] = $headerKey . ": " . $headerVal; } } if (!empty($content_type)) { if ($content_type == "multipart/form-data") { $headers[] = "Content-type: {$content_type}; boundary=" . $this->_mime_boundary; } else { $headers[] = "Content-type: {$content_type}"; } } if (!empty($body)) { $headers[] = "Content-length: " . _byte_strlen($body); } if (!empty($this->user) || !empty($this->pass)) { $headers[] = "Authorization: BASIC " . base64_encode($this->user . ":" . $this->pass); } for ($curr_header = 0; $curr_header < count($headers); $curr_header++) { $cmdline_params .= " -H \"" . $headers[$curr_header] . "\""; } if (!empty($body)) { $cmdline_params .= " -d \"{$body}\""; } if ($this->read_timeout > 0) { $cmdline_params .= " -m " . $this->read_timeout; } $headerfile = tempnam($temp_dir, "sno"); $safer_URI = strtr($URI, "\"", " "); // strip quotes from the URI to avoid shell access exec($this->curl_path . " -D \"{$headerfile}\"" . $cmdline_params . " \"" . $safer_URI . "\"", $results, $return); if ($return) { $this->error = "Error: cURL could not retrieve the document, error {$return}."; return false; } $results = implode("\r\n", $results); $file = new CFile($headerfile); $result_headers = $file->getLines(); $this->_redirectaddr = false; unset($this->headers); for ($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) { // if a header begins with Location: or URI:, set the redirect if (preg_match("/^(Location: |URI: )/i", $result_headers[$currentHeader])) { // get URL portion of the redirect preg_match("/^(Location: |URI:)\\s+(.*)/", chop($result_headers[$currentHeader]), $matches); // look for :// in the Location header to see if hostname is included if (!preg_match("|\\:\\/\\/|", $matches[2])) { // no host in the path, so prepend $this->_redirectaddr = $URI_PARTS["scheme"] . "://" . $this->host . ":" . $this->port; // eliminate double slash if (!preg_match("|^/|", $matches[2])) { $this->_redirectaddr .= "/" . $matches[2]; } else { $this->_redirectaddr .= $matches[2]; } } else { $this->_redirectaddr = $matches[2]; } } if (preg_match("|^HTTP/|", $result_headers[$currentHeader])) { $this->response_code = $result_headers[$currentHeader]; } $this->headers[] = $result_headers[$currentHeader]; } // check if there is a a redirect meta tag if (preg_match("'<meta[\\s]*http-equiv[^>]*?content[\\s]*=[\\s]*[\"\\']?\\d+;[\\s]+URL[\\s]*=[\\s]*([^\"\\']*?)[\"\\']?>'i", $results, $match)) { $this->_redirectaddr = $this->_expandlinks($match[1], $URI); } // have we hit our frame depth and is there frame src to fetch? if ($this->_framedepth < $this->maxframes && preg_match_all("'<frame\\s+.*src[\\s]*=[\\'\"]?([^\\'\"\\>]+)'i", $results, $match)) { $this->results[] = $results; for ($x = 0; $x < count($match[1]); $x++) { $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"] . "://" . $this->host); } } elseif (is_array($this->results)) { $this->results[] = $results; } else { $this->results = $results; } unlink("{$headerfile}"); return true; }
/** * */ function onAction() { global $application; $URL_correct = false; $request =& $application->getInstance('Request'); $HTTPSURL = $request->getValueByKey('HTTPSURL'); $SessionPost = array("URLS" => array("HTTPS_URL" => $HTTPSURL), "SECURE_SECTIONS" => array("AllAdminArea" => $request->getValueByKey('All') ? "true" : "", "SignIn_AdminMembers" => $request->getValueByKey('SignIn_AdminMembers') ? "true" : "", "Orders_Customers" => $request->getValueByKey('Orders_Customers') ? "true" : "", "Payment_Shipping" => $request->getValueByKey('Payment_Shipping') ? "true" : ""), "Message" => "", "FirstTimeSettings" => $request->getValueByKey('FirstTimeSettings')); if ($HTTPSURL) { $HTTPSURL = "https://" . $HTTPSURL; $parsedURL = @parse_url($HTTPSURL); if (isset($parsedURL["host"])) { if (isset($parsedURL["path"])) { $pos = _ml_strpos($parsedURL["path"], "/avactis-system"); if (!($pos === false)) { $parsedURL["path"] = _ml_substr($parsedURL["path"], 0, $pos + 1); } } $HTTPSURL = $parsedURL["host"]; $HTTPSURL .= isset($parsedURL["port"]) && $parsedURL["port"] != "" ? ":" . $parsedURL["port"] : ""; $HTTPSURL .= isset($parsedURL["path"]) && $parsedURL["path"] != "" ? $parsedURL["path"] : "/"; $HTTPSURL .= $HTTPSURL[_byte_strlen($HTTPSURL) - 1] != "/" ? "/" : ""; $SessionPost["URLS"]["HTTPS_URL"] = "https://" . $HTTPSURL; $URL_correct = $this->sendRequest("https://" . $HTTPSURL); /* if (!$URL_correct) { $HTTPSURL = $parsedURL["host"]; $HTTPSURL.= (isset($parsedURL["port"]) && $parsedURL["port"] != ""? ":".$parsedURL["port"]:""); $HTTPSURL.= "/".@parse_url($application->getAppIni('HTTP_URL'), PHP_URL_PATH); $HTTPSURL.= $HTTPSURL[_byte_strlen($HTTPSURL)-1] != "/"? "/":""; $URL_correct = $this->sendRequest("https://".$HTTPSURL); } */ if ($URL_correct || $request->getValueByKey('SSLAvailable') == "false") { $SessionPost["URLS"]["HTTPS_URL"] = "https://" . $HTTPSURL; #https_config.php file content $file_cotent = ";<?php exit(); >\n\n"; $file_cotent .= "[URLS]\n"; $file_cotent .= "HTTPS_URL = \"https://" . $HTTPSURL . "\"\n"; #if ($SessionPost["SECURE_SECTIONS"]["AllAdminArea"] == "true") #{ # $file_cotent.= "HTTP_URL = \"https://".$HTTPSURL."\"\n"; #} $file_cotent .= "\n[SECURE_SECTIONS]\n"; foreach ($SessionPost["SECURE_SECTIONS"] as $key => $val) { $file_cotent .= $key . " = " . $val . "\n"; } $file_name = $application->getAppIni("PATH_CONF_DIR") . "https_config.php"; $fp = @fopen($file_name, "w"); if ($fp) { @fwrite($fp, $file_cotent); @fclose($fp); if (!file_exists($file_name)) { #Can't create file $file_name $SessionPost["Message"] = "HTTPS_WRN_005"; } } else { #Can't write to the folder 'avactis-system' $SessionPost["Message"] = "HTTPS_WRN_004"; } } else { //Could't connect $SessionPost["Message"] = "HTTPS_WRN_003"; } } else { //Wrong URL syntax $SessionPost["Message"] = "HTTPS_WRN_002"; } } else { if ($SessionPost["FirstTimeSettings"] == "true") { //URL - isn't entered $SessionPost["Message"] = "HTTPS_WRN_001"; } elseif ($SessionPost["FirstTimeSettings"] == "false") { $SessionPost["Message"] = "HTTPS_WRN_006"; $SessionPost["FirstTimeSettings"] = ""; } else { $file_name = $application->getAppIni("PATH_CONF_DIR") . "https_config.php"; @unlink($file_name); if (file_exists($file_name)) { #Can't remove file $file_name $SessionPost["Message"] = "HTTPS_WRN_007"; } } } if ($SessionPost["Message"]) { modApiFunc('Session', 'set', 'SessionPost', $SessionPost); } else { // $SessionPost["hasCloseScript"] = "true"; modApiFunc('Session', 'set', 'SessionPost', $SessionPost); } if ($URL_correct) { // CZ : $layouts_from_bd = modApiFunc("Configuration", "getLayoutSettings"); foreach ($layouts_from_bd as $fname => $info) { $info =& $layouts_from_bd[$fname]; // , , : $k = 'layout_' . $info['id'] . '_res'; $res = $request->getValueByKey($k); if ($res === NULL) { $res = array(); } else { $res = explode('|', $res); } // Configuration : $sections = array_unique(array_values(modApiFunc("Configuration", "getLayoutSettingNameByCZLayoutSectionNameMap"))); foreach ($sections as $section) { if (in_array($section, $res)) { $info[$section] = DB_TRUE; } else { $info[$section] = DB_FALSE; } } unset($info); } modApiFunc("Session", "set", "ResultMessage", 'HTTPS_SETTINGS_SAVED'); modApiFunc("Configuration", "setLayoutSettings", $layouts_from_bd); $request = new Request(); $request->setView('HTTPSSettings'); $application->redirect($request); } }
function uploadImages(&$SessionPost) { global $application; // not to duplicate the code. $images = array('SmallImage', 'LargeImage'); foreach ($images as $image) { // if the file really exists. if (array_key_exists($image, $_FILES) && $_FILES[$image]['size'] > 0 && getimagesize($_FILES[$image]['tmp_name']) != FALSE) { // define an image type. It should be one of the allowed types. if ($application->isAllowedImageType($_FILES[$image])) { // define the image file extension $ext = $application->getImageTypeExtension($_FILES[$image]); if ($ext != false) { // upload a unique file name. $uploadfile = $application->getUploadImageName($_FILES[$image]['name']); // move the uploaded file to the general catalog. if (move_uploaded_file($_FILES[$image]['tmp_name'], $uploadfile)) { @chmod($uploadfile, 0644); // save the file to view it to the user. // $images_dir = $application->getAppIni('RELATIVE_PATH_IMAGES_DIR_ADMIN'); $SessionPost["ViewState"][$image] = basename($uploadfile); if ($image == 'LargeImage') { $large_image_path = $uploadfile; } } else { $SessionPost["ViewState"]["ErrorsArray"][$image] = new ActionMessage(array("PRDADD_006", $image)); } } else { $SessionPost["ViewState"]["ErrorsArray"][$image] = new ActionMessage(array("PRDADD_005", $image)); } } else { $SessionPost["ViewState"]["ErrorsArray"][$image] = new ActionMessage(array("PRDADD_005", $image)); } } else { if (array_key_exists($image, $_FILES) && $_FILES[$image]['size'] > 0) { $SessionPost["ViewState"]["ErrorsArray"][$image] = new ActionMessage(array("PRDADD_005", $image)); } } } // generate small image from the large image if (@$_FILES['SmallImage']['error'] == UPLOAD_ERR_NO_FILE && isset($SessionPost["ViewState"]['LargeImage']) && !isset($SessionPost["ViewState"]["ErrorsArray"]['LargeImage']) && isset($large_image_path)) { $pi_settings = modApiFunc('Product_Images', 'getSettings'); if ($pi_settings['AUTO_GEN_CAT_SMALL_IMAGE'] == 'Y' && function_exists('gd_info')) { $thumb_path = modApiFunc('Product_Images', 'genThumbnail', 0, $large_image_path, $pi_settings['CAT_IMAGE_SIDE']); $thumb_path_info = pathinfo($thumb_path); $large_image_path_parts = pathinfo($SessionPost["ViewState"]['LargeImage']); $large_image_basename = $large_image_path_parts['basename']; $large_image_ext = $large_image_path_parts['extension']; $large_image_basename_without_ext = _byte_substr($large_image_basename, 0, -1 * _byte_strlen("." . $large_image_ext)); $thumb_path_parts = pathinfo($thumb_path); $thumb_path_ext = $large_image_path_parts['extension']; $thumb_short_name = "thumb_" . $large_image_basename_without_ext . "." . $thumb_path_ext; $thumb_path_2 = $application->_img_path($thumb_short_name); if (@rename($thumb_path, $thumb_path_2)) { $SessionPost["ViewState"]['SmallImage'] = basename($thumb_path_2); } } } }
/** * quoteadPrintableEncode() * * Encodes data to quoted-printable standard. * * @param $input The data to encode * @param $line_max Optional max line length. Should * not be more than 76 chars * * @access private */ function _quotedPrintableEncode($input, $line_max = 76) { $lines = preg_split("/\r?\n/", $input); $eol = MAIL_MIMEPART_CRLF; $escape = '='; $output = ''; while (list(, $line) = each($lines)) { $linlen = _byte_strlen($line); $newline = ''; for ($i = 0; $i < $linlen; $i++) { $char = _byte_substr($line, $i, 1); $dec = _byte_ord($char); if ($dec == 32 and $i == $linlen - 1) { // convert space at eol only $char = '=20'; } elseif ($dec == 9) { // Do nothing if a tab. } elseif ($dec == 61 or $dec < 32 or $dec > 126) { $char = $escape . _ml_strtoupper(sprintf('%02s', dechex($dec))); } if (_byte_strlen($newline) + _byte_strlen($char) >= $line_max) { // MAIL_MIMEPART_CRLF is not counted $output .= $newline . $escape . $eol; // soft line break; " =\r\n" is okay $newline = ''; } $newline .= $char; } // end of for $output .= $newline . $eol; } $output = _byte_substr($output, 0, -1 * _byte_strlen($eol)); // Don't want last crlf return $output; }
/** * Prepares the query of type LOCK TABLES. * * @return a string, containing the SQL query 'LOCK TABLES' * @param DB_LockTables object $QueryData */ function PrepareLockTablesQuery($QueryData) { $SQL = ' LOCK TABLES '; $tables = $QueryData->getTablesToLock(); if (sizeof($tables) > 0) { foreach ($tables as $key => $info) { $SQL .= $key; if (!empty($info['alias'])) { $SQL .= ' AS ' . $info['alias']; } if (!empty($info['locking_mode'])) { $SQL .= ' ' . $info['locking_mode']; } $SQL .= ', '; } $SQL = _byte_substr($SQL, 0, _byte_strlen($SQL) - 2); } else { //Error - No Tables to Lock } return $SQL; }
/** * Converts the answer from the remote host to the array of headers, cookies * and body. * * @param $result answer from the remote host * @return array of headers, cookies and body */ function parseRequestResult($result) { $headers = array(); $cookies = array(); $body = ""; $dp = 4096; $delimiter = false; $dtrs = array("\n", "\r\n", "\n\r"); foreach ($dtrs as $v) { // trying to find a delimiter pair - headers/body border $tdp = _byte_strpos($result, $v . $v); if ($tdp != false && $dp > $tdp) { $dp = $tdp; $delimiter = $v; } } if ($delimiter == false) { CTrace::wrn('Failed to parse response, I cannot guess headers/body delimiter.'); return; } $headers = _byte_substr($result, 0, $dp); $hstr = explode($delimiter, $headers); foreach ($hstr as $key => $string) { if (preg_match("/^HTTP/", $string)) { continue; } if (trim($string) == "") { break; } $header_array = explode(": ", trim($string), 2); $header_array[0] = _ml_strtoupper($header_array[0]); $headers[$header_array[0]] = chop($header_array[1]); if ($header_array[0] == "SET-COOKIE") { array_push($cookies, $header_array[1]); } } $cookies = $this->parseCookies($cookies); $body = _byte_substr($result, $dp + _byte_strlen($delimiter) * 2); return array("headers" => $headers, "cookies" => $cookies, "body" => $body); }
/** * Converts the user inputed key into generic format (uppercase characters, no delimiters) * and applies the basic check (by length) * * @param string $key * @return string generic key representation * **/ function _prepareKey($key) { if ($key == null || _byte_strlen($key) == 0) { return KEY_BAD; } else { $_key = preg_replace("/[^0-9a-fA-F]/i", "", $key); if (_byte_strlen($_key) != KEY_LENGTH) { return KEY_BAD; } return _ml_strtoupper($_key); } }
/** * Sets the secret key * The key must be non-zero, and less than or equal to * 56 characters (bytes) in length. * * If you are making use of the PHP mcrypt extension, you must call this * method before each encrypt() and decrypt() call. * * @param string $key * @param string $iv 8-char initialization vector (required for CBC mode) * @return boolean|PEAR_Error Returns TRUE on success, PEAR_Error on failure * @access public * @ Fix the caching of the key */ function setKey($key, $iv = null) { if (!is_string($key)) { return PEAR::raiseError('Key must be a string', 2); } $len = _byte_strlen($key); if ($len > $this->_key_size || $len == 0) { return PEAR::raiseError('Key must be less than ' . $this->_key_size . ' characters (bytes) and non-zero. Supplied key length: ' . $len, 3); } if ($this->_iv_required) { if (_byte_strlen($iv) != $this->_iv_size) { return PEAR::raiseError('IV must be ' . $this->_iv_size . '-character (byte) long. Supplied IV length: ' . _byte_strlen($iv), 7); } $this->_iv = $iv; } // If same key passed, no need to re-initialize internal arrays. // @ This needs to be worked out better... if ($this->_keyHash == md5($key)) { return true; } $this->_init(); $k = 0; $data = 0; $datal = 0; $datar = 0; for ($i = 0; $i < 18; $i++) { $data = 0; for ($j = 4; $j > 0; $j--) { $data = $data << 8 | _byte_ord($key[$k]); $k = ($k + 1) % $len; } $this->_P[$i] ^= $data; } for ($i = 0; $i <= 16; $i += 2) { $this->_encipher($datal, $datar); $this->_P[$i] = $datal; $this->_P[$i + 1] = $datar; } for ($i = 0; $i < 256; $i += 2) { $this->_encipher($datal, $datar); $this->_S[0][$i] = $datal; $this->_S[0][$i + 1] = $datar; } for ($i = 0; $i < 256; $i += 2) { $this->_encipher($datal, $datar); $this->_S[1][$i] = $datal; $this->_S[1][$i + 1] = $datar; } for ($i = 0; $i < 256; $i += 2) { $this->_encipher($datal, $datar); $this->_S[2][$i] = $datal; $this->_S[2][$i + 1] = $datar; } for ($i = 0; $i < 256; $i += 2) { $this->_encipher($datal, $datar); $this->_S[3][$i] = $datal; $this->_S[3][$i + 1] = $datar; } $this->_keyHash = md5($key); return true; }
/** * Extracts from the template text only the part, which must be used for * mapping. * * @param string $text raw contents of the template file. * @return string template contents which contain between the seperators. */ function removeTemplateWrapper($text) { static $begin_tpl_tag_expr; static $end_tpl_tag_expr; // $begin_tpl_tag_expr = '/<hr>.*<!--.*BEGIN.*TPL.*\(DO.*NOT.*REMOVE!\).*-->/im'; $begin_tpl_tag_expr = '/<\\s*!\\s*-\\s*-\\s*B\\s*E\\s*G\\s*I\\s*N\\s*T\\s*P\\s*L\\s*\\(\\s*D\\s*O\\s*N\\s*O\\s*T\\s*R\\s*E\\s*M\\s*O\\s*V\\s*E\\s*!\\s*\\)\\s*-\\s*-\\s*>/im'; // $end_tpl_tag_expr = '/<hr>.*<!--.*END.*TPL.*\(DO NOT REMOVE!\).*-->/im'; $end_tpl_tag_expr = '/<\\s*!\\s*-\\s*-\\s*E\\s*N\\s*D\\s*T\\s*P\\s*L\\s*\\(\\s*D\\s*O\\s*N\\s*O\\s*T\\s*R\\s*E\\s*M\\s*O\\s*V\\s*E\\s*!\\s*\\)\\s*-\\s*-\\s*>/im'; if (preg_match($begin_tpl_tag_expr, $text, $begin, PREG_OFFSET_CAPTURE) != 1) { _fatal(array("CODE" => "CORE_046"), $this->CurrentTemplateFilename); } if (preg_match($end_tpl_tag_expr, $text, $end, PREG_OFFSET_CAPTURE) != 1) { _fatal(array("CODE" => "CORE_047"), $this->CurrentTemplateFilename); } $begin_pos = $begin[0][1] + _byte_strlen($begin[0][0]); $end_pos = $end[0][1]; if ($begin_pos > $end_pos) { _fatal(array("CODE" => "CORE_048"), $this->CurrentTemplateFilename); } return _byte_substr($text, $begin_pos, $end_pos - $begin_pos); }
/** * Sets the secret key * The key must be non-zero, and less than or equal to * 56 characters (bytes) in length. * * If you are making use of the PHP mcrypt extension, you must call this * method before each encrypt() and decrypt() call. * * @param string $key * @param string $iv 8-char initialization vector (required for CBC mode) * @return boolean|PEAR_Error Returns TRUE on success, PEAR_Error on failure * @access public */ function setKey($key, $iv = null) { if (!is_string($key)) { return PEAR::raiseError('Key must be a string', 2); } $len = _byte_strlen($key); if ($len > 56 || $len == 0) { return PEAR::raiseError('Key must be less than 56 characters (bytes) and non-zero. Supplied key length: ' . $len, 3); } if ($this->_iv_required) { if (_byte_strlen($iv) != 8) { return PEAR::raiseError('IV must be 8-character (byte) long. Supplied IV length: ' . _byte_strlen($iv), 7); } $this->_iv = $iv; } $return = mcrypt_generic_init($this->_td, $key, $this->_iv); if ($return < 0) { return PEAR::raiseError('Unknown PHP MCrypt library error', 4); } return true; }
/** * Decrypts $enc_data by the key $this->_dec_key or $key. * * @param string $enc_data encrypted data as binary string * @param object $key decryption key (object of RSA_Crypt_Key class) * @return mixed * decrypted data as string on success or false on error * * @access public */ function decryptBinary($enc_data, $key = null) { if (is_null($key)) { // use current decryption key $key = $this->_dec_key; } elseif (!Crypt_RSA_Key::isValid($key)) { $obj = PEAR::raiseError('invalid decryption key. It must be an object of Crypt_RSA_Key class', CRYPT_RSA_ERROR_WRONG_KEY); $this->pushError($obj); return false; } $exp = $this->_math_obj->bin2int($key->getExponent()); $modulus = $this->_math_obj->bin2int($key->getModulus()); $data_len = _byte_strlen($enc_data); $chunk_len = $key->getKeyLength() - 1; $block_len = (int) ceil($chunk_len / 8); $curr_pos = 0; $bit_pos = 0; $plain_data = $this->_math_obj->bin2int(""); while ($curr_pos < $data_len) { $tmp = $this->_math_obj->bin2int(_byte_substr($enc_data, $curr_pos, $block_len)); $tmp = $this->_math_obj->powmod($tmp, $exp, $modulus); $plain_data = $this->_math_obj->bitOr($plain_data, $tmp, $bit_pos); $bit_pos += $chunk_len; $curr_pos += $block_len; } $result = $this->_math_obj->int2bin($plain_data); // delete tail, containing of \x01 $tail = _byte_ord($result[_byte_strlen($result) - 1]); if ($tail != 1) { $obj = PEAR::raiseError("Error tail of decrypted text = {$tail}. Expected 1", CRYPT_RSA_ERROR_WRONG_TAIL); $this->pushError($obj); return false; } return _byte_substr($result, 0, -1); }
function return_bytes($val) { $val = trim($val); $last = _ml_strtolower($val[_byte_strlen($val) - 1]); switch ($last) { case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; }
function getDirectorySize($directory) { $total_size = 0; if ($directory[_byte_strlen($directory) - 1] != "/") { $directory .= "/"; } if ($dir = @dir($directory)) { while ($file = $dir->read()) { if (!is_dir($directory . $file)) { $total_size += filesize($directory . $file); } elseif ($file != "." && $file != "..") { $total_size += $this->getDirectorySize($directory . $file . "/"); } } $dir->close(); } return $total_size; }
function onAction() { global $application; $default_lng = modApiFunc('MultiLang', 'getDefaultLanguage'); $application->enterCriticalSection('ML_UpdateLabelData'); // getting the request data $request =& $application->getInstance('Request'); $lng = $request->getValueByKey('lng'); $label_data = $request->getValueByKey('label_data'); // flag if there is an error $error = ''; // checking the language if ($lng != $default_lng && !modApiFunc('MultiLang', 'checkLanguage', $lng, false)) { $error = 'ML_ERROR_INVALID_LANGUAGE'; $lng = modApiFunc('MultiLang', 'getDefaultLanguage'); } // checking the label id // and setting the label name for future use if ($label_data['id']) { $tmp = modApiFunc('MultiLang', 'searchLabels', array('label_id' => $label_data['id'], 'lng' => $lng)); if (!$tmp) { // label_id is incorrect $label_data['id'] = 0; $error = 'ML_ERROR_INVALID_LABEL'; $label_data['label'] = 'CUSTOM_'; $label_data['prefix'] = 'CZ'; } else { $label_data['label'] = $tmp[0]['label']; $label_data['prefix'] = $tmp[0]['prefix']; } // checking if the label is custom // while trying to change its name if (isset($label_data['custom_label']) && _ml_substr($tmp[0]['label'], 0, 7) != 'CUSTOM_') { $error = 'ML_ERROR_NOT_CUSTOM_LABEL'; } } else { $label_data['label'] = 'CUSTOM_'; $label_data['prefix'] = 'CZ'; } // checking the label name for custom labels if (!$error && (!$label_data['id'] || isset($label_data['custom_label'])) && !$label_data['custom_label']) { $error = 'ML_ERROR_EMPTY_CUSTOM_LABEL_NAME'; } // ckecking if custom_name contain invalid symbols if (!$error && !$label_data['id']) { for ($i = 0; $i < _byte_strlen($label_data['custom_label']); $i++) { $tmp = _byte_ord($label_data['custom_label'][$i]); if ($tmp < 48 || $tmp > 57 && $tmp < 65 || $tmp > 90 && $tmp != 95) { $error = 'ML_ERROR_INVALID_CUSTOM_LABEL_NAME'; break; } } } // checking if the label name is unique if (!$error && (!$label_data['id'] || isset($label_data['custom_label']))) { $tmp = modApiFunc('MultiLang', 'searchLabels', array('label' => array('exactly' => 'Y', 'value' => 'CUSTOM_' . $label_data['custom_label']), 'type' => 'CZ_CUSTOM', 'lng' => $lng)); if ($tmp && $tmp[0]['id'] != $label_data['id']) { $error = 'ML_ERROR_LABEL_EXISTS'; } } if (!$error) { // we are ready to save the changes if (!$label_data['id']) { // inserting a new label modApiFunc('Resources', 'addLabelToDB', 'CUSTOM_' . $label_data['custom_label'], $label_data['def_value']); $label_data['id'] = $application->db->DB_Insert_Id(); // saving the result message modApiFunc('Session', 'set', 'ResultMessage', 'ML_SUCCESS_LABEL_ADDED'); } else { // updating the label modApiFunc('Resources', 'updateLabelText', $label_data['id'], $label_data['def_value'], isset($label_data['custom_label']) ? 'CUSTOM_' . $label_data['custom_label'] : ''); modApiFunc('Session', 'set', 'ResultMessage', 'ML_SUCCESS_LABEL_UPDATED'); } // saving the multilang data if needed if ($lng != modApiFunc('MultiLang', 'getDefaultLanguage')) { $ml_label = modApiFunc('MultiLang', 'mapMLField', 'resource_labels', 'res_text', 'Resources'); modApiFunc('MultiLang', 'setMLValue', $ml_label, $label_data['id'], $label_data['value'], $lng); } modApiFunc('Session', 'set', 'ML_ReloadParentWindow', 'Y'); } else { // form contain an error, saving it to session modApiFunc('Session', 'set', 'SavedLabelData', $label_data); // saving the result modApiFunc('Session', 'set', 'ResultMessage', $error); } $application->leaveCriticalSection(); $req_to_redirect = new Request(); $req_to_redirect->setView('PopupWindow'); $req_to_redirect->setKey('page_view', 'LabelData'); $req_to_redirect->setKey('label_id', $label_data['id']); $req_to_redirect->setKey('lng', $lng); $application->redirect($req_to_redirect); }
/** * Decrypts an encrypted string * * The value was padded with NUL characters when encrypted. You may * need to trim the result or cast its type. * * @param string $cipherText * @return string|PEAR_Error Returns plain text on success, PEAR_Error on failure * @access public */ function decrypt($cipherText) { if (!is_string($cipherText)) { return PEAR::raiseError('Cipher text must be a string', 1); } if (empty($this->_P)) { return PEAR::raiseError('The key is not initialized.', 8); } $plainText = ''; $len = _byte_strlen($cipherText); $cipherText .= str_repeat(_byte_chr(0), (8 - $len % 8) % 8); for ($i = 0; $i < $len; $i += 8) { list(, $Xl, $Xr) = unpack('N2', _byte_substr($cipherText, $i, 8)); $this->_decipher($Xl, $Xr); $plainText .= pack('N2', $Xl, $Xr); } return $plainText; }
/** * Logical Right Shift * * Shifts binary strings $shift bits, essentially dividing by 2**$shift and returning the remainder. * * @param $x String * @param $shift Integer * @return String * @access private */ function _base256_rshift(&$x, $shift) { if ($shift == 0) { $x = ltrim($x, _byte_chr(0)); return ''; } $num_bytes = $shift >> 3; // eg. floor($shift/8) $shift &= 7; // eg. $shift % 8 $remainder = ''; if ($num_bytes) { $start = $num_bytes > _byte_strlen($x) ? -_byte_strlen($x) : -$num_bytes; $remainder = _byte_substr($x, $start); $x = _byte_substr($x, 0, -$num_bytes); } $carry = 0; $carry_shift = 8 - $shift; for ($i = 0; $i < _byte_strlen($x); $i++) { $temp = _byte_ord($x[$i]) >> $shift | $carry; $carry = _byte_ord($x[$i]) << $carry_shift & 0xff; $x[$i] = _byte_chr($temp); } $x = ltrim($x, _byte_chr(0)); $remainder = _byte_chr($carry >> $carry_shift) . $remainder; return ltrim($remainder, _byte_chr(0)); }
function __return_bytes($val) { $val = trim($val); $last = _ml_strtolower($val[_byte_strlen($val) - 1]); switch ($last) { // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; }
/** * CZ layout config . . */ function static_parse_layout_config_file($layout_file_path) { global $zone; global $application; $app_root_path = $application->getAppIni("PATH_ASC_ROOT"); $config = array(); $error = array(); # Use $layout_file_path If it exists and readable if (file_exists($layout_file_path) && is_readable($layout_file_path) && is_file($layout_file_path)) { $config['PATH_LAYOUTS_CONFIG_FILE'] = $layout_file_path; $config['PATH_LAYOUTS_CONFIG_FILE'] = strtr($config['PATH_LAYOUTS_CONFIG_FILE'], '\\', '/'); $isDefaultLayoutFileUsed = false; # Defining layout.ini directory location $config['DIR_LAYOUTS_CONFIG_FILE'] = dirname($config['PATH_LAYOUTS_CONFIG_FILE']) . '/'; $config['DIR_LAYOUTS_CONFIG_FILE'] = strtr($config['DIR_LAYOUTS_CONFIG_FILE'], '\\', '/'); } else { if ($zone != 'AdminZone') { $error = array("MAIN_ERROR_PARAMETERS" => array("CODE" => "CORE_056")); return $error; } } if (isset($config['DIR_LAYOUTS_CONFIG_FILE'])) { # Defining SITE_URL and SITE_PATH $layout_array = @_parse_cz_layout_ini_file($config['PATH_LAYOUTS_CONFIG_FILE'], true); # convert all array keys to upper case $layout_array = array_change_key_case($layout_array, CASE_UPPER); foreach ($layout_array as $layout_section => $layout_value) { $layout_array[$layout_section] = array_change_key_case($layout_value, CASE_UPPER); } # Read [Site] section from layout.ini if (isset($layout_array['SITE'])) { if (isset($layout_array['SITE']['SITEURL'])) { # Defining SITE_URL $config['SITE_URL'] = $layout_array['SITE']['SITEURL']; # check if SITE_URL is empty or ./ then set to current if ($config['SITE_URL'] == '' || $config['SITE_URL'] == './') { $config['SITE_URL'] = "http://" . $_SERVER['SERVER_NAME'] . _ml_substr($_SERVER['PHP_SELF'], 0, _ml_strrpos($_SERVER['PHP_SELF'], '/') + 1); } } else { $error = array("MAIN_ERROR_PARAMETERS" => array("CODE" => "CORE_032", "FILE" => $config['PATH_LAYOUTS_CONFIG_FILE'], "SECTION" => 'Site', "DIRECTIVE" => "SiteURL")); return $error; } if (isset($layout_array['SITE']['SITEPATH'])) { # Defining SITE_PATH $config['SITE_PATH'] = $layout_array['SITE']['SITEPATH']; $config['SITE_PATH'] = strtr($config['SITE_PATH'], '\\', '/'); } elseif (isset($application->appIni["PATH_ASC_ROOT"])) { # Defining SITE_PATH $config['SITE_PATH'] = $application->appIni["PATH_ASC_ROOT"]; $config['SITE_PATH'] = strtr($config['SITE_PATH'], '\\', '/'); } else { $error = array("MAIN_ERROR_PARAMETERS" => array("CODE" => "CORE_033", "FILE" => $config['PATH_LAYOUTS_CONFIG_FILE'], "SECTION" => 'Site', "DIRECTIVE" => "SitePATH")); return $error; } if (isset($layout_array['SITE']['SITEHTTPSURL'])) { $config['SITE_HTTPS_URL'] = $layout_array['SITE']['SITEHTTPSURL']; if ($config['SITE_HTTPS_URL'] == "" || $config['SITE_HTTPS_URL'] == "./") { $config['SITE_HTTPS_URL'] = "https://" . $_SERVER['SERVER_NAME'] . _ml_substr($_SERVER['PHP_SELF'], 0, _ml_strrpos($_SERVER['PHP_SELF'], '/') + 1); } $config['SITE_HTTPS_URL'] .= $config['SITE_HTTPS_URL'][_byte_strlen($config['SITE_HTTPS_URL']) - 1] != "/" ? "/" : ""; } /* else { $config['SITE_HTTPS_URL'] = $config['SITE_URL']; } */ } else { $error = array("MAIN_ERROR_PARAMETERS" => array("CODE" => "CORE_034", "FILE" => $config['PATH_LAYOUTS_CONFIG_FILE'], "SECTION" => 'Site')); return $error; } # Check if SITE_PATH and SITE_URL have '/' in the line end $config['SITE_PATH'] = _ml_substr($config['SITE_PATH'], -1, 1) != '/' ? $config['SITE_PATH'] . '/' : $config['SITE_PATH']; $config['SITE_URL'] = _ml_substr($config['SITE_URL'], -1, 1) != '/' ? $config['SITE_URL'] . '/' : $config['SITE_URL']; # Check if SITE_PATH exists if (!file_exists($config['SITE_PATH'])) { $error = array("MAIN_ERROR_PARAMETERS" => array("CODE" => "CORE_038", "FILE" => $config['PATH_LAYOUTS_CONFIG_FILE'], "SECTION" => 'Site', "DIRECTIVE" => "SitePath = " . $config['SITE_PATH'])); return $error; } # Define LAYOUT_TEMPLATE from layout.ini if (isset($layout_array['TEMPLATES']) && isset($layout_array['TEMPLATES']['TEMPLATEDIRECTORY'])) { # Defining LAYOUT_TEMPLATE $config['TEMPLATE_DIRECTORY_NAME'] = $layout_array['TEMPLATES']['TEMPLATEDIRECTORY']; # Check if there is '/' at the end of TEMPLATE_DIRECTORY_NAME path $config['TEMPLATE_DIRECTORY_NAME'] = _ml_substr($config['TEMPLATE_DIRECTORY_NAME'], -1, 1) != '/' ? $config['TEMPLATE_DIRECTORY_NAME'] . '/' : $config['TEMPLATE_DIRECTORY_NAME']; # Check template directory exists relative to SitePath directive if (file_exists($config['SITE_PATH'] . $config['TEMPLATE_DIRECTORY_NAME'])) { # Path to current templates directory, based on layout.ini directive $config['PATH_TEMPLATES'] = $config['SITE_PATH'] . $config['TEMPLATE_DIRECTORY_NAME']; $config['URL_TEMPLATES'] = $config['SITE_URL'] . $config['TEMPLATE_DIRECTORY_NAME']; $config['PATH_USERS_RESOURCES'] = $config['PATH_TEMPLATES'] . 'resources/'; if (isset($config['SITE_HTTPS_URL'])) { $config['HTTPS_URL_TEMPLATES'] = $config['SITE_HTTPS_URL'] . $config['TEMPLATE_DIRECTORY_NAME']; } } else { $error = array("MAIN_ERROR_PARAMETERS" => array("CODE" => "CORE_035", "FILE" => $config['PATH_LAYOUTS_CONFIG_FILE'], "SECTION" => 'Templates', "DIRECTIVE" => "TemplateDirectory = " . $config['TEMPLATE_DIRECTORY_NAME']), $config['TEMPLATE_DIRECTORY_NAME'], $config['SITE_PATH']); return $error; } } else { # If TEMPLATEDIRECTORY directive is undefined then use system templates $config['TEMPLATE_DIRECTORY_NAME'] = 'avactis-themes/system'; $config['PATH_TEMPLATES'] = $app_root_path . '/' . $config['TEMPLATE_DIRECTORY_NAME'] . '/'; $config['URL_TEMPLATES'] = $application->getAppIni('HTTP_URL') . $config['TEMPLATE_DIRECTORY_NAME'] . '/'; $config['PATH_USERS_RESOURCES'] = $config['PATH_TEMPLATES'] . 'resources/'; if (isset($config['SITE_HTTPS_URL'])) { $config['HTTPS_URL_TEMPLATES'] = $application->getAppIni('HTTPS_URL') . $config['TEMPLATE_DIRECTORY_NAME'] . '/'; } } # Hard-coding system templates $config['SYSTEM_TEMPLATE_DIRECTORY_NAME'] = 'avactis-themes/system'; $config['SYSTEM_PATH_TEMPLATES'] = str_replace('//', '/', $app_root_path . '/' . $config['SYSTEM_TEMPLATE_DIRECTORY_NAME'] . '/'); $config['SYSTEM_URL_TEMPLATES'] = $application->getAppIni('HTTP_URL') . $config['SYSTEM_TEMPLATE_DIRECTORY_NAME'] . '/'; $config['SYSTEM_PATH_USERS_RESOURCES'] = $config['SYSTEM_PATH_TEMPLATES'] . 'resources/'; if (isset($config['SITE_HTTPS_URL'])) { $config['SYSTEM_HTTPS_URL_TEMPLATES'] = $application->getAppIni('HTTPS_URL') . $config['SYSTEM_TEMPLATE_DIRECTORY_NAME'] . '/'; } } return $config; }
/** * Calculates bitwise or of $num1 and $num2, * starting from bit $start_pos for number $num1 * * @param gmp resource $num1 * @param gmp resource $num2 * @param int $start_pos * @return gmp resource * @access public */ function bitOr($num1, $num2, $start_pos) { $start_byte = intval($start_pos / 8); $start_bit = $start_pos % 8; $tmp1 = $this->int2bin($num1); $num2 = gmp_mul($num2, 1 << $start_bit); $tmp2 = $this->int2bin($num2); if ($start_byte < _byte_strlen($tmp1)) { $tmp2 |= _byte_substr($tmp1, $start_byte); $tmp1 = _byte_substr($tmp1, 0, $start_byte) . $tmp2; } else { $tmp1 = str_pad($tmp1, $start_byte, "") . $tmp2; } return $this->bin2int($tmp1); }
function writeLabel($Row, $Col, $Value) { $L = _byte_strlen($Value); $this->__content .= pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L); $this->__content .= $Value; }