diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..424829c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +nbproject \ No newline at end of file diff --git a/README.md b/README.md index b53a123..0cb6642 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,4 @@ A php script to prepare installation of selected Wordpress release. - Click on `Install` # How it works -Script downloads selected release, unpacks, creates `.htaccess` file, removes itself and redirects you to installation process. +Script downloads selected release, unpacks, removes itself and redirects you to installation process. diff --git a/index.php b/index.php new file mode 100644 index 0000000..cf04ad9 --- /dev/null +++ b/index.php @@ -0,0 +1,405 @@ +prepareConnection($url); + + // Return response + $buffer = curl_exec ($this->connection); + + } else { + $options = $file_get_contents_options = array( + 'ssl' => array( + "verify_peer" => false, + "verify_peer_name" => false + ), + 'http' => array( + 'user_agent' => $_SERVER['HTTP_USER_AGENT'] + ) + ); + + $buffer = file_get_contents( + $url, false, + stream_context_create($options) + ); + } + + return $buffer; + } + + /** + * Prepare CURL connection. + * + * @param String $url URL to be used in connection. + * @param String $handle File handle to be used in connection. + */ + protected function prepareConnection($url = null, $handle = null){ + + // Connection needs to be created + if( !is_resource($this->connection) ) { + + // Initialise connection + $this->connection = curl_init(); + + // Configure CURL + curl_setopt($this->connection, CURLOPT_RETURNTRANSFER, true); + curl_setopt($this->connection, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($this->connection, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); + } + + // Set URL + if( !is_null($url) ) { + curl_setopt($this->connection, CURLOPT_URL, $url); + } + + // Set File Handle + if( !is_null($handle) ) { + curl_setopt($this->connection, CURLOPT_TIMEOUT, 100); + curl_setopt($this->connection, CURLOPT_FILE, $handle); + curl_setopt($this->connection, CURLOPT_FOLLOWLOCATION, true); + } + } + + /** + * Download a file to local filesystem. + * + * @param type $url + * @param type $path + * + * @throws Exception + */ + protected function downloadFile($url, $path) { + + if( function_exists('curl_init') ) { + + // Create file handle + $handle = fopen ($path, 'w+'); + + // Prepare CURL connection + $this->prepareConnection($url, $handle); + + // Run CURL + curl_exec($this->connection); + $error = curl_error($this->connection); + if( !empty($error) ) { + throw new Exception('(Curl) '.$error, 502); + } + + // Close file handle + fclose($handle); + + // Close CURL connection + curl_close($this->connection); + + } else { + + $options = $file_get_contents_options = array( + 'ssl' => array( + "verify_peer" => false, + "verify_peer_name" => false + ), + 'http' => array( + 'user_agent' => $_SERVER['HTTP_USER_AGENT'] + ) + ); + + file_put_contents( + $path, + file_get_contents( + $url, false, + stream_context_create($options) + ) + ); + } + } + + /** + * Downloads a selected installation packaged. + * + * @param String $url_zip Download the installation package. + */ + public function downloadTask($url_zip) { + if( file_exists(__DIR__.'/wordpress.zip') ) { + return true; + } + // Download zip + $this->downloadFile($url_zip, __DIR__.'/wordpress.zip'); + } + + /** + * Download package, unpack it, install and redirect to + * Wordpress installation page. + * + * @throws Exception + */ + public function prepareTask(){ + + // Remove this script + unlink(__FILE__); + + // Unpack + $package = new ZipArchive; + if ($package->open(__DIR__.'/wordpress.zip') === TRUE) { + // Extract files to created directory + for( $i=1, $ic=$package->numFiles; $i<$ic; $i++ ){ + + // Get path + $path = $package->getNameIndex($i); + $info = pathinfo($path); + + // Create directory + if( stripos($info['dirname'], '/') ) { + $parts = explode('/',$info['dirname']); + if( empty($info['extension']) ) { + $dirname = __DIR__.'/'.implode('/', array_slice($parts, 1)).'/'.$info['basename']; + } else { + $dirname = __DIR__.'/'.implode('/', array_slice($parts, 1)); + } + + } else { + $dirname = __DIR__; + } + + // If we need to create this directory + if ( !is_dir($dirname) ) { + mkdir($dirname, 0755, true); + } + if( empty($info['extension']) ) { + continue; + } else { + $buff = $package->getFromIndex($i); + file_put_contents($dirname.'/'.$info['basename'], $buff); + } + } + $package->close(); + + // Remove package + unlink(__DIR__.'/wordpress.zip'); + } else { + throw new Exception('Cannot extract wordpress.zip', 502); + } + } + + /** + * Check Class requirements + * + * @throws Exception + */ + public function checkRequirements(){ + + // Check if PHP can get remote contect + if( !ini_get('allow_url_fopen') OR !function_exists('curl_init') ) { + throw new Exception('This class requires CURL or allow_url_fopen to be enabled in PHP configuration.', 502); + } + + // Check if server allow to extract zip files + if( !class_exists('ZipArchive')) { + throw new Exception('Class ZipArchive is not available in current PHP configuration.', 502); + } + + } +} + +// Create new Installer instance +$installer = new Installer; + +// Run tasks +try { + + // First check if server meets requirements + $installer->checkRequirements(); + + // If this is install task + if (isset($_GET['install'])) { + $installer->downloadTask($_GET['install']); + } + if (isset($_GET['prepare'])) { + $installer->prepareTask(); + } + +} catch (Exception $e) { + die('ERROR: '.$e->getMessage()); +} + +if( isset($_GET['install']) OR isset($_GET['prepare'])) { + die('OK.'); +} + +?> + + + + + + + + + + GetWordpress + + + + + + + + + + + + + + + + + +
+
+

GetWordpress v1.0.0

+

Just a crazy fast script to download and prepare Wordpress installation.

+
+
+ + + + +
+
+
+ +
+
+

How it works

+

This script downloads selected release from Wordpress Github repository, unpacks it, creates .htaccess, removes itself and then redirects you to Wordpress installation. In short: just select version and click install to run Wordpress installer.

+
+ +
+

Warning

+

This script is free for everyone. Im not responsible for any damage it can make. Remember to always have a copy of files you have on this server.

+ +

License

+

This script is released under GNU/GPL 3.0 license. Free for commercial and non-commercial usage.

+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Loading versions list
+
+ +