Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("config.php");
- $pass = strip_tags($_GET['pass']);
- $pass = nl2br($pass);
- $pass = htmlspecialchars($pass);
- if($pass == "$password" && $pass != NULL) {
- $date = date('d-M-y H:i:s');
- $logquery = "INSERT INTO log (date) VALUES ('$date')";
- $logresult = mysql_query($logquery);
- $notification1 = "SELECT * FROM config";
- $notificationresult = mysql_query($notification1);
- while ($rownot = mysql_fetch_array($notificationresult, MYSQL_ASSOC)){
- $from = $rownot['fromemail'];
- $subject = "Demo Manager";
- $message = "Hello! This email is letting you know that your demo was reinstalled at ".$date."";
- $headers = "From: $from";
- if ($rownot['notifications']=="yes"){
- mail($rownot['email'],$subject,$message,$headers);
- echo "Mail Sent...";
- echo "<br>";
- }
- else {
- echo "No email being sent...";
- echo "<br>";
- }
- }
- $query = "SELECT * FROM demo";
- $result = mysql_query($query);
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
- //Declarations
- $demoname = $row['name'];
- $fileroot = $row['fileroot'];
- $demoroot = $row['demoroot'];
- $sqlfile = $row['sqlfile'];
- $zipfile = $row['zipfile'];
- $demo = $row['demofolder'];
- $drop = $row['drop'];
- $dbhost = $row['hostname'];
- $dbname = $row['dbname'];
- $dbuser = $row['dbuser'];
- $dbpass = $row['dbpass'];
- $sqlpath = "$fileroot"."$sqlfile";
- $zippath = "$fileroot"."$zipfile";
- $demopath = "$demoroot"."$demo";
- // Connect to demo's
- mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
- mysql_select_db($dbname);
- // Start
- echo "Reinstallation of ". $demoname ." Started...<br />";
- // Drop
- if ($drop=="no"){
- echo "Dropping Database...";
- echo "<br>";
- // Query all tables
- $sql = "SHOW TABLES FROM $dbname";
- if($result2 = mysql_query($sql)){
- $number_tables=mysql_num_rows($result2);
- /* add table name to array */
- while($row2 = mysql_fetch_row($result2)){
- $found_tables[]=$row2[0];
- }
- }
- else{
- die("Error, could not list tables. MySQL Error: " . mysql_error());
- }
- if($number_tables)
- {
- // Loop through and drop each table
- foreach($found_tables as $table_name){
- $sql = "DROP TABLE $table_name";
- if($result2 = mysql_query($sql)){
- echo "Success - $table_name deleted.<br />";
- }
- else{
- echo "Error deleting $table_name. MySQL Error: " . mysql_error() . "";
- }
- }
- }
- echo "<br />";
- }
- else {
- echo "Allowing sql file to drop...";
- echo "<br>";
- }
- // Import sql file
- $import = "mysql -u ".$dbuser." -p".$dbpass." ".$dbname." < ".$sqlpath."";
- system($import);
- echo "Database Imported Again!";
- echo "<br />";
- // Remove demo folder
- echo "<br />";
- echo "Removing Files...";
- echo "<br />";
- if(!function_exists('remove_dir')){
- function remove_dir($dir)
- {
- $handle = opendir($dir);
- while (false!==($item = readdir($handle)))
- {
- if($item != '.' && $item != '..')
- {
- if(is_dir($dir.'/'.$item))
- {
- remove_dir($dir.'/'.$item);
- echo $item;
- echo "<br>";
- }else{
- unlink($dir.'/'.$item);
- echo $item;
- echo "<br>";
- }
- }
- }
- closedir($handle);
- if(rmdir($dir))
- {
- $success = true;
- }
- return $success;
- }
- }
- remove_dir("$demopath");
- echo "<br />";
- // Unzip demo zip contents
- $zip = new ZipArchive() ;
- // Open zip
- if ($zip->open("$fileroot"."$zipfile") !== TRUE) {
- die ("Unable to open zip file");
- }
- // Extract contents to destination directory
- $zip->extractTo("$demoroot");
- // Unzip Completed
- $zip->close();
- echo "Zip file extracted to ";
- echo $demo;
- // Done
- echo "<br />";
- echo "Reinstallation of ". $demoname ." Completed...<br />";
- echo "<br />";
- echo "<br />";
- //end
- }
- }
- else { echo $wrongPW; }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement