Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. <?php
  2.  
  3. include("config.php");
  4.  
  5. $pass = strip_tags($_GET['pass']);
  6. $pass = nl2br($pass);
  7. $pass = htmlspecialchars($pass);
  8. if($pass == "$password" && $pass != NULL) {
  9.  
  10. $date = date('d-M-y H:i:s');
  11. $logquery = "INSERT INTO log (date) VALUES ('$date')";
  12. $logresult = mysql_query($logquery);
  13.  
  14. $notification1 = "SELECT * FROM config";
  15. $notificationresult = mysql_query($notification1);
  16.  
  17. while ($rownot = mysql_fetch_array($notificationresult, MYSQL_ASSOC)){
  18.  
  19. $from = $rownot['fromemail'];
  20. $subject = "Demo Manager";
  21. $message = "Hello! This email is letting you know that your demo was reinstalled at ".$date."";
  22. $headers = "From: $from";
  23.  
  24. if ($rownot['notifications']=="yes"){
  25. mail($rownot['email'],$subject,$message,$headers);
  26. echo "Mail Sent...";
  27. echo "<br>";
  28. }
  29. else {
  30. echo "No email being sent...";
  31. echo "<br>";
  32. }
  33.  
  34. }
  35.  
  36. $query = "SELECT * FROM demo";
  37. $result = mysql_query($query);
  38.  
  39. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  40.  
  41. //Declarations
  42.  
  43. $demoname = $row['name'];
  44. $fileroot = $row['fileroot'];
  45. $demoroot = $row['demoroot'];
  46. $sqlfile = $row['sqlfile'];
  47. $zipfile = $row['zipfile'];
  48. $demo = $row['demofolder'];
  49. $drop = $row['drop'];
  50.  
  51. $dbhost = $row['hostname'];
  52. $dbname = $row['dbname'];
  53. $dbuser = $row['dbuser'];
  54. $dbpass = $row['dbpass'];
  55.  
  56. $sqlpath = "$fileroot"."$sqlfile";
  57. $zippath = "$fileroot"."$zipfile";
  58. $demopath = "$demoroot"."$demo";
  59.  
  60. // Connect to demo's
  61. mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
  62. mysql_select_db($dbname);
  63.  
  64.  
  65. // Start
  66. echo "Reinstallation of ". $demoname ." Started...<br />";
  67.  
  68. // Drop
  69. if ($drop=="no"){
  70. echo "Dropping Database...";
  71. echo "<br>";
  72. // Query all tables
  73. $sql = "SHOW TABLES FROM $dbname";
  74. if($result2 = mysql_query($sql)){
  75. $number_tables=mysql_num_rows($result2);
  76. /* add table name to array */
  77. while($row2 = mysql_fetch_row($result2)){
  78. $found_tables[]=$row2[0];
  79. }
  80. }
  81. else{
  82. die("Error, could not list tables. MySQL Error: " . mysql_error());
  83. }
  84. if($number_tables)
  85. {
  86. // Loop through and drop each table
  87. foreach($found_tables as $table_name){
  88. $sql = "DROP TABLE $table_name";
  89. if($result2 = mysql_query($sql)){
  90. echo "Success - $table_name deleted.<br />";
  91. }
  92. else{
  93. echo "Error deleting $table_name. MySQL Error: " . mysql_error() . "";
  94. }
  95. }
  96. }
  97. echo "<br />";
  98. }
  99. else {
  100. echo "Allowing sql file to drop...";
  101. echo "<br>";
  102. }
  103.  
  104.  
  105. // Import sql file
  106. $import = "mysql -u ".$dbuser." -p".$dbpass." ".$dbname." < ".$sqlpath."";
  107. system($import);
  108. echo "Database Imported Again!";
  109. echo "<br />";
  110.  
  111. // Remove demo folder
  112. echo "<br />";
  113. echo "Removing Files...";
  114. echo "<br />";
  115.  
  116. if(!function_exists('remove_dir')){
  117.  
  118. function remove_dir($dir)
  119. {
  120. $handle = opendir($dir);
  121. while (false!==($item = readdir($handle)))
  122. {
  123. if($item != '.' && $item != '..')
  124. {
  125. if(is_dir($dir.'/'.$item))
  126. {
  127. remove_dir($dir.'/'.$item);
  128. echo $item;
  129. echo "<br>";
  130. }else{
  131. unlink($dir.'/'.$item);
  132. echo $item;
  133. echo "<br>";
  134. }
  135. }
  136. }
  137. closedir($handle);
  138. if(rmdir($dir))
  139. {
  140. $success = true;
  141. }
  142. return $success;
  143. }
  144.  
  145. }
  146.  
  147.  
  148. remove_dir("$demopath");
  149. echo "<br />";
  150.  
  151. // Unzip demo zip contents
  152. $zip = new ZipArchive() ;
  153.  
  154. // Open zip
  155. if ($zip->open("$fileroot"."$zipfile") !== TRUE) {
  156. die ("Unable to open zip file");
  157. }
  158. // Extract contents to destination directory
  159. $zip->extractTo("$demoroot");
  160.  
  161. // Unzip Completed
  162. $zip->close();
  163. echo "Zip file extracted to ";
  164. echo $demo;
  165.  
  166. // Done
  167. echo "<br />";
  168. echo "Reinstallation of ". $demoname ." Completed...<br />";
  169. echo "<br />";
  170. echo "<br />";
  171.  
  172.  
  173. //end
  174. }
  175.  
  176. }
  177.  
  178. else { echo $wrongPW; }
  179.  
  180. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement