Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $auth = base64_encode("username:password"); //replace with your credentials. Make sure you don't publish them anywhere
- $domain = "cpanel.mydomain.com"; //replace with your domain
- $theme = "paper_lantern"; //replace with your theme
- $secure = false; //if no valid ssl certificate
- $ftp = true; //false if you don't want to backup to an FTP server
- $ftpserver = "ftp.mydomain.com"; //replace with your FTP server for backing up to FTP
- $ftpusername = "ftp username";
- $ftppassword = "ftp password";
- $ftpport = "21";
- $ftpdirectory = "/";
- if ($secure) {
- $url = "ssl://" . $domain;
- $port = 2083;
- } else {
- $url = $domain;
- $port = 80;
- }
- $socket = fsockopen($url, $port);
- if (!$socket) {
- exit("Failed to open socket connection.");
- }
- if ($ftp) {
- $params = "dest=ftp&server=$ftpserver&user=$ftpusername&pass=$ftppassword&port=$ftpport&rdir=$ftpdirectory&submit=Generate Backup";
- } else {
- $params = "submit=Generate Backup";
- }
- fputs($socket, "POST /frontend/" . $theme . "/backup/dofullbackup.html?" . $params . " HTTP/1.0rn");
- fputs($socket, "Host: $domainrn");
- fputs($socket, "Authorization: Basic $authrn");
- fputs($socket, "Connection: Closern");
- fputs($socket, "rn");
- while (!feof($socket)) {
- $response = fgets($socket, 4096);
- }
- fclose($socket);
- sleep(120);
- //laatste file
- $path = "/home/myusername/backups"; //backup store location
- $latest_ctime = 0;
- $latest_filename = '';
- $d = dir($path);
- while (false !== ($entry = $d->read())) {
- $filepath = "{$path}/{$entry}";
- if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
- $latest_ctime = filectime($filepath);
- $latest_filename = $entry;
- }
- }
- $file = "backups/" . $latest_filename;
- $email_to = "Somebody <me@example.com>";
- $email_from = "My Webserver <webserver@example.com>";
- $email_subject = "Created a backup";
- $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>";
- $fileatt = $file;
- $fileatt_type = "package/x-generic";
- $fileatt_name = $latest_filename;
- $file = fopen($fileatt,'rb');
- $data = fread($file,filesize($fileatt));
- fclose($file);
- $semi_rand = md5(time());
- $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
- $headers="From: " . $email_from;
- $headers .= "nMIME-Version: 1.0n" .
- "Content-Type: multipart/mixed;n" .
- " boundary="{$mime_boundary}"";
- $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;
- $email_message .= "nn";
- $data = chunk_split(base64_encode($data));
- $email_message .= "--{$mime_boundary}n" .
- "Content-Type: {$fileatt_type};n" .
- " name="{$fileatt_name}"n" .
- "Content-Transfer-Encoding: base64nn" .
- $data . "nn" .
- "--{$mime_boundary}--n";
- mail($email_to,$email_subject,$email_message,$headers);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement