/** * attempt to create an htaccess file * .htaccess creation only works for base_installations because of the $dirPrefix variable * This is for the rewrite_rule and TestResponse() which uses AbsoluteUrl() * * @access public * @static * @since 1.7 * * @param string $destination The root path of the installation * @param array $config Current installation configuration */ static function InstallHtaccess($destination, $config) { global $install_ftp_connection, $dirPrefix; //only proceed with save if we can test the results if (!\gp\tool\RemoteGet::Test()) { return; } $GLOBALS['config']['homepath'] = false; //to prevent a warning from absoluteUrl() $file = $destination . '/.htaccess'; $original_contents = null; if (file_exists($file)) { $original_contents = file_get_contents($file); } $contents = \gp\admin\Settings\Permalinks::Rewrite_Rules(true, $dirPrefix, $original_contents); if (!isset($config['useftp'])) { //echo 'not using ftp'; $fp = @fopen($file, 'wb'); if (!$fp) { return; } @fwrite($fp, $contents); fclose($fp); @chmod($file, 0666); //return .htaccess to original state if (!\gp\admin\Settings\Permalinks::TestResponse()) { if ($original_contents === false) { unlink($file); } else { $fp = @fopen($file, 'wb'); if ($fp) { @fwrite($fp, $original_contents); fclose($fp); } } } return; } //using ftp $file = $config['ftp_root'] . '/.htaccess'; $temp = tmpfile(); if (!$temp) { return false; } fwrite($temp, $contents); fseek($temp, 0); //Skip back to the start of the file being written to @ftp_fput($install_ftp_connection, $file, $temp, FTP_ASCII); fclose($temp); //return .htaccess to original state if (!\gp\admin\Settings\Permalinks::TestResponse()) { if ($original_contents === false) { @ftp_delete($install_ftp_connection, $file); } else { $temp = tmpfile(); fwrite($temp, $original_contents); fseek($temp, 0); @ftp_fput($install_ftp_connection, $file, $temp, FTP_ASCII); fclose($temp); } } }
/** * Download the source code * */ function DownloadSource() { global $langmessage, $dataDir; $this->msg('Downloading version ' . $this->core_package['version'] . ' from ' . CMS_READABLE_DOMAIN . '.'); /* for testing * $download = 'http://gpeasy.loc/x_gpEasy.zip'; */ $download = addon_browse_path . '/Special_gpEasy?cmd=download'; $contents = \gp\tool\RemoteGet::Get_Successful($download); if (!$contents || empty($contents)) { $this->msg($langmessage['download_failed'] . '(1)'); return false; } $this->msg($langmessage['package_downloaded']); $md5 = md5($contents); if ($md5 != $this->core_package['md5']) { $this->msg($langmessage['download_failed_md5'] . '<br/>Downloaded Checksum (' . $md5 . ') != Expected Checksum (' . $this->core_package['md5'] . ')'); return false; } $this->msg($langmessage['download_verified']); //save contents $temp_file = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/update', '.zip'); if (!\gp\tool\Files::Save($temp_file, $contents)) { $this->msg($langmessage['download_failed'] . ' (2)'); return false; } $this->core_package['file'] = $temp_file; return true; }
/** * Get the remote package * */ public function GetRemote() { global $langmessage, $dataDir; // check values if (empty($this->type) || empty($this->id) || !is_numeric($this->id)) { $this->message($langmessage['OOPS'] . ' (Invalid Request)'); return false; } // download url $download_url = \gp\admin\Tools::RemoteUrl($this->type); // allowed to remote install? if ($download_url === false) { $this->message($langmessage['OOPS'] . ' (Can\'t remote install ' . $this->type . ')'); return false; } $download_url .= '?cmd=install&id=' . rawurlencode($this->id); // purchase order id if (is_null($this->order)) { $this->order = $this->GetOrder($this->id); } if (!is_null($this->order)) { $download_url .= '&order=' . rawurlencode($this->order); } // able to remote install? if (!\gp\admin\Tools::CanRemoteInstall()) { $this->message($langmessage['OOPS'] . ' (Can\'t remote install)'); return false; } // get package from remote $full_result = \gp\tool\RemoteGet::Get($download_url); 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="' . self::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 = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/addon', '.zip'); if (!\gp\tool\Files::Save($tempfile, $result)) { $this->message($langmessage['download_failed'] . ' (Package not saved)'); return false; } $this->source = $this->TempFile(); $success = $this->ExtractArchive($tempfile); unlink($tempfile); return $success; }
/** * Determine if the installation should be allowed to process remote installations * */ public static function CanRemoteInstall() { static $bit; if (isset($bit)) { return $bit; } if (!gp_remote_themes && !gp_remote_plugins) { return $bit = 0; } if (!function_exists('gzinflate')) { return $bit = 0; } if (!\gp\tool\RemoteGet::Test()) { return $bit = 0; } if (gp_remote_themes) { $bit = 1; } if (gp_remote_plugins) { $bit += 2; } return $bit; }
/** * Determine if we will be able tot test the results * */ public function CanTestRules() { if (!\gp\tool\RemoteGet::Test()) { return false; } if (!$this->FileSystem || !$this->FileSystem->ConnectOrPrompt('Admin/Permalinks')) { return false; } return true; }
/** * Convert the response string to an array * Serialized or json (serialized data may be cached) * */ protected function ParseResponse($result) { //no response if (!$result) { echo '<p>' . \gp\tool\RemoteGet::Debug('Sorry, data not fetched') . '</p>'; return false; } $data = false; if (strpos($result, 'a:') === 0) { $data = unserialize($result); } elseif (strpos($result, '{') === 0) { $data = json_decode($result, true); } if (!is_array($data)) { $debug = array(); $debug['Two'] = substr($result, 0, 2); $debug['Twotr'] = substr(trim($result), 0, 2); echo '<p>' . \gp\tool\RemoteGet::Debug('Sorry, data not fetched', $debug) . '</p>'; } return $data; }