示例#1
0
 private function package_system_upgrade()
 {
     if ((int) $this->check_access() < 10) {
         $this->response(null, null, 401);
     }
     $file_contents = file_get_contents($this->upgrade_url);
     if (empty($file_contents)) {
         $this->response(null, null, 404);
     }
     if (!RazorFileTools::write_file_contents("{$this->package_path}/system_upgrade.zip", $file_contents)) {
         throw new Exception("Could not write upgrade file to storage/tmp/package.");
     }
     $this->response("success", "json");
 }
示例#2
0
 public function post($data)
 {
     if ((int) $this->check_access() < 10) {
         $this->response(null, null, 401);
     }
     if (empty($data) || !isset($data["type"]) || !isset($data["handle"]) || !isset($data["extension"])) {
         $this->response(null, null, 400);
     }
     // fetch cleaned data
     $category = preg_replace('/[^a-zA-Z0-9-_]/', '', $data["type"]);
     $handle = preg_replace('/[^a-zA-Z0-9-_]/', '', $data["handle"]);
     $name = preg_replace('/[^a-zA-Z0-9-_]/', '', $data["extension"]);
     // fetch details
     $package_url = $this->package_url . "{$category}/{$handle}/{$name}/{$name}.zip";
     $headers = @get_headers($package_url);
     if (strpos($headers[0], "404") === false) {
         $ctx = stream_context_create(array('http' => array('timeout' => 60)));
         // copy package to temp location
         $package_contents = @file_get_contents($package_url, false, $ctx);
         if (!empty($package_contents)) {
             if (!RazorFileTools::write_file_contents("{$this->tmp_package_path}/{$name}.zip", $package_contents)) {
                 throw new Exception("Could not write upgrade file to storage/tmp/package.");
             }
         }
         // extract to file system
         if (!is_file("{$this->tmp_package_path}/{$name}.zip")) {
             throw new exception("Extension file not found.");
         }
         // open extension package
         $zip = new RazorZip();
         $zip->open("{$this->tmp_package_path}/{$name}.zip");
         // extract
         $zip->extractTo(RAZOR_BASE_PATH);
         $zip->close();
         // cleanup
         RazorFileTools::delete_directory($this->tmp_path);
         // send back not found if no details
         $this->response("success", "json");
     }
     // send back not found if no details
     $this->response(null, null, 404);
 }
 /**
  * Log Error
  * Log the error to log file
  *
  * @param array $error Error data array
  * @param string $log_book The log book to write to
  * @return bool False on fail
  */
 private function log_error($error, $log_book = 'razor-error-log')
 {
     if (empty($error)) {
         return false;
     }
     // get file contents
     $log = array();
     if (is_file(RAZOR_BASE_PATH . "storage/log/{$log_book}.php")) {
         $log = RazorFileTools::read_file_contents(RAZOR_BASE_PATH . "storage/log/{$log_book}.php", 'array');
     }
     // set date time
     $date_time = @date('d m Y - h:i:s', time());
     $entry = "<?php /* [{$date_time}] [{$error['error']}]";
     $entry .= isset($error['type']) ? " [type: {$error['type']}]" : "";
     $entry .= isset($error['file']) ? " [file: {$error['file']}]" : "";
     $entry .= isset($error['line']) ? " [line: {$error['line']}]" : "";
     $entry .= " [message: {$error['string']}] */ ?>\n\r";
     $log[] = $entry;
     if (count($log) > 100) {
         array_shift($log);
     }
     $log_string = implode('', $log);
     if (!is_dir(RAZOR_BASE_PATH . 'storage/log')) {
         mkdir(RAZOR_BASE_PATH . 'storage/log');
     }
     RazorFileTools::write_file_contents(RAZOR_BASE_PATH . "storage/log/{$log_book}.php", $log_string);
 }