I really don't recommend using this in production environments. There are potential issues with this script that could cause some damage.
Last active
July 5, 2018 20:00
-
-
Save blakethepatton/530d35a5b4b9a28d208069c134ec1aff to your computer and use it in GitHub Desktop.
A simple script that downloads and installs phpMyAdmin in its root location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL); | |
ini_set('max_execution_time', 300); | |
ini_set('display_errors', 1); | |
function delete_files($target) { | |
if(is_dir($target)){ | |
$files = glob( $target . '*', GLOB_MARK ); //GLOB_MARK adds a slash to directories returned | |
foreach( $files as $file ) | |
{ | |
delete_files( $file ); | |
} | |
@rmdir( $target ); | |
} elseif(is_file($target)) { | |
@unlink( $target ); | |
} | |
} | |
function recurse_move($src, $dst) { | |
$dir = opendir($src); | |
// sssssh. it'll be ok. | |
@mkdir($dst); | |
while( ( $file = readdir($dir) ) !== false ) { | |
if (( $file != '.' ) && ( $file != '..' )) { | |
if ( is_dir($src . '/' . $file) ) { | |
// ich bin ein directory | |
recurse_move($src . '/' . $file, $dst . '/' . $file); | |
} else { | |
copy($src . '/' . $file, $dst . '/' . $file); | |
unlink($src . '/' . $file); | |
} | |
} | |
} | |
closedir($dir); | |
// Your services are no longer required. | |
rmdir($src); | |
} | |
function tempdir() { | |
$tempfile=tempnam(sys_get_temp_dir(),''); | |
// you might want to reconsider this line when using this snippet. | |
// it "could" clash with an existing directory and this line will | |
// try to delete the existing one. Handle with caution. | |
if (file_exists($tempfile)) { unlink($tempfile); } | |
mkdir($tempfile); | |
if (is_dir($tempfile)) { return $tempfile; } | |
} | |
$tempPath = tempdir(); | |
$storage_path = $tempPath.'/pma'; | |
mkdir($storage_path); | |
if(!is_dir($storage_path)){ | |
header("HTTP/1.1 500 Internal Server Error"); | |
echo "Unable to create temp dir. "; | |
die(); | |
} | |
//echo $storage_path; | |
$latest = 'https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-english.tar.gz'; | |
$archive = $tempPath."/pma.tar.gz"; | |
file_put_contents($archive, fopen($latest, 'r')); | |
$phar = new \PharData($archive); | |
$phar->extractTo($storage_path, null, true); | |
$paths = glob($storage_path.'/phpMyAdmin*',GLOB_ONLYDIR); | |
if(count($paths)==1){ | |
recurse_move($paths[0], $_SERVER['DOCUMENT_ROOT']); | |
} else { | |
header("HTTP/1.1 500 Internal Server Error"); | |
echo "Couldn't find phpMyAdmin folder within archive. "; | |
delete_files($tempPath); | |
die(); | |
} | |
delete_files($tempPath); | |
header("Location: /"); | |
echo "Successfully updated. "; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment