Esempio n. 1
0
 /**
  * Return response only if successful, otherwise return false
  *
  */
 static function Get_Successful($url, $args = array())
 {
     $result = gpRemoteGet::Get($url, $args);
     if ((int) $result['response']['code'] >= 200 && (int) $result['response']['code'] < 300) {
         return $result['body'];
     }
     return false;
 }
Esempio n. 2
0
 function RemoteInstall2()
 {
     global $langmessage, $addonBrowsePath;
     includeFile('tool/RemoteGet.php');
     if ($this->upgrade_key) {
         $this->install_folder_name = $this->upgrade_key;
         $this->temp_folder_name = $this->NewTempFolder();
         $copy_to = $this->addon_folder . '/' . $this->temp_folder_name;
     } else {
         $this->install_folder_name = $this->NewTempFolder();
         $copy_to = $this->addon_folder . '/' . $this->install_folder_name;
     }
     //download
     $download_link = $addonBrowsePath;
     if ($_POST['type'] == 'theme') {
         $download_link .= '/Special_Addon_Themes';
     } else {
         $download_link .= '/Special_Addon_Plugins';
     }
     $download_link .= '?cmd=install&id=' . rawurlencode($_POST['id']);
     if (isset($_POST['order'])) {
         $download_link .= '&order=' . rawurlencode($_POST['order']);
     } elseif (isset($this->config[$this->install_folder_name]['order'])) {
         $download_link .= '&order=' . rawurlencode($this->config[$this->install_folder_name]['order']);
     }
     $full_result = gpRemoteGet::Get($download_link);
     if ((int) $full_result['response']['code'] < 200 && (int) $full_result['response']['code'] >= 300) {
         message($langmessage['download_failed'] . ' (1)');
         return false;
     }
     //download failed and a message was sent
     if (isset($full_result['headers']['x-error'])) {
         echo '<p class="gp_notice">' . htmlspecialchars($full_result['headers']['x-error']) . '</p>';
         echo '<p>' . sprintf($langmessage['download_failed_xerror'], 'href="' . $this->DetailUrl($_POST) . '" name="remote"') . '</p>';
         return false;
     }
     $result = $full_result['body'];
     $md5 =& $full_result['headers']['x-md5'];
     //check md5
     if (md5($result) != $md5) {
         message($langmessage['OOPS'] . ' ' . $langmessage['Download_Unverified']);
         return false;
     }
     //save contents
     $tempfile = $this->tempfile();
     if (!gpFiles::Save($tempfile, $result)) {
         message($langmessage['download_failed'] . ' (2)');
         return false;
     }
     // Unzip uses a lot of memory, but not this much hopefully
     @ini_set('memory_limit', '256M');
     includeFile('thirdparty/pclzip-2-8-2/pclzip.lib.php');
     $archive = new PclZip($tempfile);
     $archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING);
     unlink($tempfile);
     if (!$this->write_package($copy_to, $archive_files)) {
         return false;
     }
     echo '<p>';
     echo $langmessage['copied_addon_files'];
     echo '</p>';
     if (!$this->Install_Ini($copy_to)) {
         return false;
     }
     if (!$this->Install_CheckIni()) {
         return false;
     }
     return $this->Install_CheckFile($copy_to);
 }
 /**
  * Get the remote package
  *
  */
 function GetRemote()
 {
     global $langmessage;
     includeFile('tool/RemoteGet.php');
     // check values
     if (empty($this->type) || empty($this->id) || !is_numeric($this->id)) {
         $this->message($langmessage['OOPS'] . ' (Invalid Request)');
         return false;
     }
     // allowed to remote install?
     switch ($this->type) {
         case 'plugin':
             if (!gp_remote_plugins) {
                 $this->message($langmessage['OOPS'] . ' (Can\'t remote install plugins)');
                 return false;
             }
             break;
         case 'theme':
             if (!gp_remote_themes) {
                 $this->message($langmessage['OOPS'] . ' (Can\'t remote install themes)');
                 return false;
             }
             break;
         default:
             $this->message($langmessage['OOPS'] . ' (Invalid Type)');
             return false;
     }
     // able to remote install?
     if (!admin_tools::CanRemoteInstall()) {
         $this->message($langmessage['OOPS'] . ' (Can\'t remote install)');
         return false;
     }
     // download
     $download_link = addon_browse_path;
     if ($this->type == 'theme') {
         $download_link .= '/Themes';
     } else {
         $download_link .= '/Plugins';
     }
     $download_link .= '?cmd=install&id=' . rawurlencode($this->id);
     // purchase order id
     if (!$this->order) {
         $this->order = $this->GetOrder($this->id);
     }
     if ($this->order) {
         $download_link .= '&order=' . rawurlencode($this->order);
     }
     // get package from remote
     $full_result = gpRemoteGet::Get($download_link);
     if ((int) $full_result['response']['code'] < 200 && (int) $full_result['response']['code'] >= 300) {
         $this->message($langmessage['download_failed'] . ' (1)');
         return false;
     }
     // download failed and a message was sent
     if (isset($full_result['headers']['x-error'])) {
         $this->message(htmlspecialchars($full_result['headers']['x-error']));
         $this->message(sprintf($langmessage['download_failed_xerror'], 'href="' . $this->DetailUrl($_POST['type'], $_POST['id']) . '" data-cmd="remote"'));
         return false;
     }
     $result = $full_result['body'];
     $md5 =& $full_result['headers']['x-md5'];
     //check md5
     $package_md5 = md5($result);
     if ($package_md5 != $md5) {
         $this->message($langmessage['download_failed_md5'] . ' <br/> (Package Checksum ' . $package_md5 . ' != Expected Checksum ' . $md5 . ')');
         return false;
     }
     //save contents
     $tempfile = $this->TempFile('.zip');
     if (!gpFiles::Save($tempfile, $result)) {
         $this->message($langmessage['download_failed'] . ' (Package not saved)');
         return false;
     }
     $this->source = $this->TempFile();
     $success = $this->ExtractArchive($this->source, $tempfile);
     unlink($tempfile);
     return $success;
 }
Esempio n. 4
0
 /**
  * Handle a redirect response
  *
  */
 function Redirect($headers, $r, $arrURL)
 {
     if ($r['redirection']-- < 0) {
         trigger_error('Too many redirects');
         return false;
     }
     //check location for releative value
     $location = $headers['headers']['location'];
     if ($location[0] == '/') {
         $location = $arrURL['scheme'] . '://' . $arrURL['host'] . $location;
     }
     return gpRemoteGet::Get($location, $r);
 }