Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. <?php
  2.  
  3. require("functions/dbconn.php");
  4.  
  5. $t = date("D");
  6. $select = "SELECT * FROM cpanel WHERE cron = '1' AND date != '".$t."' LIMIT 10";
  7. $results = mysql_query($select);
  8. $num_rows = mysql_num_rows($results);
  9. $r = mysql_fetch_row($results);
  10.  
  11. $id = $r[0];
  12.  
  13. $i = 1;
  14. $from = "failed@freeautobackup.com";
  15.  
  16. function sendEmail($to,$from,$subject,$message,$domain){
  17. $headers = "From:" . $from;
  18.  
  19. if ($message == 'nologin') {
  20. $message = "Hello! This is a email reminder to let you know that the backup for your cPanel account failed to connect for ".$domain."... Please double check your login information as we were unable
  21. to login! ID: "; echo $id;
  22. } elseif ($message=='noconnect') { $message = "Hello! This is a email reminder to let you know that the backup for your cPanel account failed to connect for ".$domain."... Please double check all
  23. of your connection settings! ID: $id";
  24. } else { $message = "I have no idea why I am emailing you"; }
  25.  
  26. mail($to,$subject,$message,$headers);
  27.  
  28. }
  29.  
  30.  
  31.  
  32. echo "Starting backups for <b>".$num_rows."</b> accounts!";
  33. echo "<br>";
  34.  
  35.  
  36. while ($row = mysql_fetch_array($results)){
  37.  
  38.  
  39. // Info required for cPanel access
  40. $cpuser = $row['cpuser']; // Username used to login to CPanel
  41. $cppass = $row['cppass']; // Password used to login to CPanel
  42. $domain = $row['domain']; // Domain name where CPanel is run
  43. $skin = $row['skin']; // Set to cPanel skin you use (script won't work if it doesn't match). Most people run the default x theme
  44.  
  45. // Info required for FTP host
  46. $ftpuser = $row['ftpuser']; // Username for FTP account
  47. $ftppass = $row['ftppass']; // Password for FTP account
  48. $ftphost = $row['ftphost']; // Full hostname or IP address for FTP host
  49. $ftpmode = $row['ftpmode']; // FTP mode ("ftp" for active, "passiveftp" for passive)
  50. $ftpport = $row['ftpport']; // FTP port
  51. $ftpdir = $row['ftpdir']; // FTP directory
  52.  
  53. // Notification information
  54. $notifyemail = $row['email']; // Email address to send results
  55.  
  56. // Secure or non-secure mode
  57. $secure = $row['secure']; // Set to 1 for SSL (requires SSL support), otherwise will use standard HTTP
  58.  
  59. // Set to 1 to have web page result appear in your cron log
  60. $debug = 1;
  61.  
  62. // *********** NO CONFIGURATION ITEMS BELOW THIS LINE *********
  63.  
  64.  
  65. if ($secure) {
  66. $url = "ssl://".$domain;
  67. $port = 2083;
  68. } else {
  69. $url = $domain;
  70. $port = 2082;
  71. }
  72.  
  73.  
  74. $socket = fsockopen($url,$port);
  75. if (!$socket) {
  76. echo "Failed to open socket connection... Bailing out!\n\nNotifying user!";
  77. sendEmail($notifyemail,$from,'Backup Failed','noconnect', $domain);
  78. //mysql_query("UPDATE cpanel SET date = '".$t."'") or die(mysql_error());
  79. continue;
  80. }
  81.  
  82. // Encode authentication string
  83. $authstr = $cpuser.":".$cppass;
  84. $pass = base64_encode($authstr);
  85.  
  86. //local with mail
  87. $m = "email=$notifyemail&submit=Generate Backup";
  88. //remote with mail
  89. $fm = "dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&port=$ftpport&rdir=$ftpdir&submit=Generate Backup";
  90. //remote with no mail
  91. $fnm = "dest=$ftpmode&server=$ftphost&user=$ftpuser&pass=$ftppass&port=$ftpport&rdir=$ftpdir&submit=Generate Backup";
  92.  
  93. $result = $nm;
  94.  
  95. if ($result == $nm) {
  96. $params = $nm;
  97. }
  98. elseif ($result == $m) {
  99. $params = $m;
  100. }
  101. elseif ($result == $fm) {
  102. $params = $fm;
  103. }
  104. elseif ($result == $fnm) {
  105. $params = $fnm;
  106. }
  107.  
  108. // Make POST to cPanel
  109. fputs($socket,"POST /frontend/".$skin."/backup/dofullbackup.html?".$params." HTTP/1.0\r\n");
  110. fputs($socket,"Host: $domain\r\n");
  111. fputs($socket,"Authorization: Basic $pass\r\n");
  112. fputs($socket,"Connection: Close\r\n");
  113. fputs($socket,"\r\n");
  114.  
  115. // Grab response even if we don't do anything with it.
  116. while (!feof($socket)) {
  117. $response = fgets($socket,4096);
  118. $loginfail = strpos($response, '401');
  119. if ($loginfail) {
  120. //login failed do code here:
  121. echo "Login Failed";
  122. sendEmail($notifyemail,$from,'Backup Failed!','nologin',$domain);
  123. break;
  124.  
  125. }
  126. if ($debug) echo $response;
  127. }
  128.  
  129. fclose($socket);
  130.  
  131.  
  132.  
  133. echo "<hr>";
  134. echo "".$i." Starting backup for user ".$cpuser." at ".$domain."";
  135. echo "<br>";
  136. $i++;
  137.  
  138. //mysql_query("UPDATE cpanel SET date = '".$t."'") or die(mysql_error());
  139.  
  140. }
  141.  
  142. echo "<hr>";
  143.  
  144. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement