Ejemplo n.º 1
0
 /**
  *
  */
 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");
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  * Logical Not
  *
  * Although integers can be converted to and from various bases with relative ease, there is one piece
  * of information that is lost during such conversions.  The number of leading zeros that number had
  * or should have in any given base.  Per that, if you convert 1 from decimal to binary, there's no
  * way to know just how many leading zero's there should be.  In truth, there could be any number.
  *
  * Normally, the number of leading zero's is unimportant.  When doing "not", however, it is.  The "not"
  * of 1 on an 8-bit representation of 1 is 1111 1110.  The "not" of 1 on a 16-bit representation of 1 is
  * 1111 1111 1111 1110.  When doing it on a number that's preceeded by an infinite number of zero's, it's
  * infinite.
  *
  * This function assumes that there are no leading zero's - that the bit-representation being used is
  * equal to the minimum number of required bits, unless otherwise specified in the optional parameter,
  * where the optional parameter represents the bit-representation being used.  If the specified
  * bit-representation is smaller than the minimum number of bits required to represent the number, the
  * latter will be used as the bit-representation.
  *
  * @param $bits Integer
  * @access public
  * @internal Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
  * @return Math_BigInteger
  */
 function bitwise_not($bits = -1)
 {
     // calculuate "not" without regard to $bits
     $temp = ~$this->toBytes();
     $msb = decbin(_byte_ord($temp[0]));
     $msb = _byte_substr($msb, _byte_strpos($msb, '0'));
     $temp[0] = _byte_chr(bindec($msb));
     // see if we need to add extra leading 1's
     $current_bits = _byte_strlen($msb) + 8 * _byte_strlen($temp) - 8;
     $new_bits = $bits - $current_bits;
     if ($new_bits <= 0) {
         return new Math_BigInteger($temp, 256);
     }
     // generate as many leading 1's as we need to.
     $leading_ones = _byte_chr((1 << ($new_bits & 0x7)) - 1) . str_repeat(_byte_chr(0xff), $new_bits >> 3);
     $this->_base256_lshift($leading_ones, $current_bits);
     $temp = str_pad($temp, ceil($bits / 8), _byte_chr(0), STR_PAD_LEFT);
     return new Math_BigInteger($leading_ones | $temp, 256);
 }
Ejemplo n.º 4
0
 function submit($URI, $formvars = "", $formfiles = "")
 {
     unset($postdata);
     $postdata = $this->_prepare_post_body($formvars, $formfiles);
     $URI_PARTS = parse_url($URI);
     if (!empty($URI_PARTS["user"])) {
         $this->user = $URI_PARTS["user"];
     }
     if (!empty($URI_PARTS["pass"])) {
         $this->pass = $URI_PARTS["pass"];
     }
     if (empty($URI_PARTS["query"])) {
         $URI_PARTS["query"] = '';
     }
     switch ($URI_PARTS["scheme"]) {
         case "http":
             $this->host = $URI_PARTS["host"];
             if (!empty($URI_PARTS["port"])) {
                 $this->port = $URI_PARTS["port"];
             }
             if ($this->_connect($fp)) {
                 if ($this->_isproxy) {
                     // using proxy, send entire URI
                     $this->_httprequest($URI, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata);
                 } else {
                     $path = $URI_PARTS["path"] . ($URI_PARTS["query"] ? "?" . $URI_PARTS["query"] : "");
                     // no proxy, send only the path
                     $this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata);
                 }
                 $this->_disconnect($fp);
                 if ($this->_redirectaddr) {
                     /* url was redirected, check if we've hit the max depth */
                     if ($this->maxredirs > $this->_redirectdepth) {
                         if (!preg_match("|^" . $URI_PARTS["scheme"] . "://|", $this->_redirectaddr)) {
                             $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"] . "://" . $URI_PARTS["host"]);
                         }
                         // only follow redirect if it's on this site, or offsiteok is true
                         if (preg_match("|^http://" . preg_quote($this->host) . "|i", $this->_redirectaddr) || $this->offsiteok) {
                             /* follow the redirect */
                             $this->_redirectdepth++;
                             $this->lastredirectaddr = $this->_redirectaddr;
                             if (_byte_strpos($this->_redirectaddr, "?") > 0) {
                                 $this->fetch($this->_redirectaddr);
                             } else {
                                 $this->submit($this->_redirectaddr, $formvars, $formfiles);
                             }
                         }
                     }
                 }
                 if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) {
                     $frameurls = $this->_frameurls;
                     $this->_frameurls = array();
                     while (list(, $frameurl) = each($frameurls)) {
                         if ($this->_framedepth < $this->maxframes) {
                             $this->fetch($frameurl);
                             $this->_framedepth++;
                         } else {
                             break;
                         }
                     }
                 }
             } else {
                 return false;
             }
             return true;
             break;
         case "https":
             if (!$this->curl_path) {
                 return false;
             }
             if (function_exists("is_executable")) {
                 if (!is_executable($this->curl_path)) {
                     return false;
                 }
             }
             $this->host = $URI_PARTS["host"];
             if (!empty($URI_PARTS["port"])) {
                 $this->port = $URI_PARTS["port"];
             }
             if ($this->_isproxy) {
                 // using proxy, send entire URI
                 $this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata);
             } else {
                 $path = $URI_PARTS["path"] . ($URI_PARTS["query"] ? "?" . $URI_PARTS["query"] : "");
                 // no proxy, send only the path
                 $this->_httpsrequest($path, $URI, $this->_submit_method, $this->_submit_type, $postdata);
             }
             if ($this->_redirectaddr) {
                 /* url was redirected, check if we've hit the max depth */
                 if ($this->maxredirs > $this->_redirectdepth) {
                     if (!preg_match("|^" . $URI_PARTS["scheme"] . "://|", $this->_redirectaddr)) {
                         $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"] . "://" . $URI_PARTS["host"]);
                     }
                     // only follow redirect if it's on this site, or offsiteok is true
                     if (preg_match("|^http://" . preg_quote($this->host) . "|i", $this->_redirectaddr) || $this->offsiteok) {
                         /* follow the redirect */
                         $this->_redirectdepth++;
                         $this->lastredirectaddr = $this->_redirectaddr;
                         if (_byte_strpos($this->_redirectaddr, "?") > 0) {
                             $this->fetch($this->_redirectaddr);
                         } else {
                             $this->submit($this->_redirectaddr, $formvars, $formfiles);
                         }
                     }
                 }
             }
             if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) {
                 $frameurls = $this->_frameurls;
                 $this->_frameurls = array();
                 while (list(, $frameurl) = each($frameurls)) {
                     if ($this->_framedepth < $this->maxframes) {
                         $this->fetch($frameurl);
                         $this->_framedepth++;
                     } else {
                         break;
                     }
                 }
             }
             return true;
             break;
         default:
             // not a valid protocol
             $this->error = 'Invalid protocol "' . $URI_PARTS["scheme"] . '"\\n';
             return false;
             break;
     }
     return true;
 }