Advertisement
Guest User

Untitled

a guest
Dec 30th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. $auth = base64_encode("username:password"); //replace with your credentials. Make sure you don't publish them anywhere
  2. $domain = "cpanel.mydomain.com"; //replace with your domain
  3. $theme = "paper_lantern"; //replace with your theme
  4. $secure = false; //if no valid ssl certificate
  5. $ftp = true; //false if you don't want to backup to an FTP server
  6. $ftpserver = "ftp.mydomain.com"; //replace with your FTP server for backing up to FTP
  7. $ftpusername = "ftp username";
  8. $ftppassword = "ftp password";
  9. $ftpport = "21";
  10. $ftpdirectory = "/";
  11.  
  12. if ($secure) {
  13. $url = "ssl://" . $domain;
  14. $port = 2083;
  15. } else {
  16. $url = $domain;
  17. $port = 80;
  18. }
  19.  
  20. $socket = fsockopen($url, $port);
  21. if (!$socket) {
  22. exit("Failed to open socket connection.");
  23. }
  24.  
  25. if ($ftp) {
  26. $params = "dest=ftp&server=$ftpserver&user=$ftpusername&pass=$ftppassword&port=$ftpport&rdir=$ftpdirectory&submit=Generate Backup";
  27. } else {
  28. $params = "submit=Generate Backup";
  29. }
  30.  
  31. fputs($socket, "POST /frontend/" . $theme . "/backup/dofullbackup.html?" . $params . " HTTP/1.0rn");
  32. fputs($socket, "Host: $domainrn");
  33. fputs($socket, "Authorization: Basic $authrn");
  34. fputs($socket, "Connection: Closern");
  35. fputs($socket, "rn");
  36.  
  37.  
  38. while (!feof($socket)) {
  39. $response = fgets($socket, 4096);
  40. }
  41.  
  42. fclose($socket);
  43.  
  44. sleep(120);
  45.  
  46. //laatste file
  47. $path = "/home/myusername/backups"; //backup store location
  48.  
  49. $latest_ctime = 0;
  50. $latest_filename = '';
  51.  
  52. $d = dir($path);
  53. while (false !== ($entry = $d->read())) {
  54. $filepath = "{$path}/{$entry}";
  55. if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
  56. $latest_ctime = filectime($filepath);
  57. $latest_filename = $entry;
  58. }
  59. }
  60. $file = "backups/" . $latest_filename;
  61.  
  62.  
  63. $email_to = "Somebody <me@example.com>";
  64. $email_from = "My Webserver <webserver@example.com>";
  65. $email_subject = "Created a backup";
  66. $email_txt = "<html><body>n" . "Backup created on " . date('d/m/Y') . " at " . date("h:i:sa") . " (" . date_default_timezone_get() . "). Backup saved as " . $latest_filename . " <br>Backup is created every day." . "<br><hr><br> This mail was automatically generated. Please don't answer." . "</body></html>";
  67. $fileatt = $file;
  68. $fileatt_type = "package/x-generic";
  69. $fileatt_name = $latest_filename;
  70. $file = fopen($fileatt,'rb');
  71. $data = fread($file,filesize($fileatt));
  72. fclose($file);
  73. $semi_rand = md5(time());
  74. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  75. $headers="From: " . $email_from;
  76. $headers .= "nMIME-Version: 1.0n" .
  77. "Content-Type: multipart/mixed;n" .
  78. " boundary="{$mime_boundary}"";
  79. $email_message .= "This is a multi-part message in MIME format.nn" . "--{$mime_boundary}n" . "Content-Type:text/html; charset="iso-8859-1"n" . "Content-Transfer-Encoding: 7bitnn" . $email_txt;
  80. $email_message .= "nn";
  81. $data = chunk_split(base64_encode($data));
  82. $email_message .= "--{$mime_boundary}n" .
  83. "Content-Type: {$fileatt_type};n" .
  84. " name="{$fileatt_name}"n" .
  85. "Content-Transfer-Encoding: base64nn" .
  86. $data . "nn" .
  87. "--{$mime_boundary}--n";
  88.  
  89. mail($email_to,$email_subject,$email_message,$headers);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement