The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Backup using Cron and a backup script fails on Security Token

Discussion in 'Data Protection' started by caylean, Jan 15, 2015.

  1. caylean

    caylean Member

    Joined:
    Jul 2, 2013
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello together,
    I have for my personal sites a small shared hosting and no access to the WHM Backup Config. But I still want to have my personal Backup files on a seperate Backup VPS Server.
    The VPS was easily configured and is right now used with SFTP Access (Maybe also already a Problem, but couldn't figure that out so far, as i would plainly install vsftpd and i would be good to go.

    I have created on for my Accounts a Cronjob as seen below

    0 0 * * 0 php -f /home/ACCOUNT/public_html/backup/backup.php
    The Path i was given by my Hoster as i had asked him directly the ecact Path i would need to use in order to get the script running.

    where i use the Script i have created using the Guide here:
    /http://www.ericzhang.me/howto-cpanel-automatic-backups/

    Code:
    <?php
    
    $auth = base64_encode("ACCOUNTNAME:PASSWORD);
    $domain = "name.hostname.com";
    $theme = "x3";
    $secure = true;
    $ftp = true;
    $ftpserver = "123.456.789.012";
    $ftpusername = "VPSUSERNAME";
    $ftppassword = "VPSUSERPW";
    $ftpport = "VPS_SSH_PORT";
    $ftpdirectory = "/home/VPSUSERNAME/Backupfolder";
    
    if ($secure) {
    	$url = "ssl://" . $domain;
    	$port = 2083;
    } else {
    	$url = $domain;
    	$port = 2082;
    }
    
    $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.0\r\n");
    fputs($socket, "Host: $domain\r\n");
    fputs($socket, "Authorization: Basic $auth\r\n");
    fputs($socket, "Connection: Close\r\n");
    fputs($socket, "\r\n");
    
    while (!feof($socket)) {
    	$response = fgets($socket, 4096);
    	echo $response;
    }
    
    fclose($socket);
    
    ?>
    
    For testing purpose i had ran the Cron every 2 minutes and send the result by mail to see if it was successful..... Well, it was not.

    Code:
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    HTTP/1.1 401 Access Denied
    Set-Cookie: cprelogin=no; HttpOnly; path=/; port=2083; secure
    Set-Cookie: cpsession=%3aO_zJdMMvTcG3s2w[.Shortened.]8a2949637881e80; HttpOnly; path=/; port=2083; secure
    Server: cpsrvd/11.46.2.0
    Content-type: text/html; charset="utf-8"
    Connection: close
    Date: Fri, 16 Jan 2015 05:02:02 GMT
    Content-Length: 21107
    
    
    <!DOCTYPE html>
    <html dir="ltr">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="google" content="notranslate" />
        <title>cPanel Login</title>
        <link rel="shortcut icon" href="/cPanel_magic_revision_1372453550/unprotected/cpanel/favicon.ico" />
    
        <!-- EXTERNAL CSS -->
        <link href="/cPanel_magic_revision_1372453527/unprotected/cpanel/style_v2_optimized.css" rel="stylesheet" type="text/css" />
    
        <!--[if IE 6]>
        <style type="text/css">
            img {
                behavior: url(/cPanel_magic_revision_1372453485/unprotected/cp_pngbehavior_login.htc);
            }
        </style>
        <![endif]-->
    
        <script>
        window.DOM = { get: function(id) { return document.getElementById(id) } };
        </script>
    </head>
    <body>
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    Properbly it is the Security Token (cpsess) that gets generated each time you login.

    Is there any other Script that would help me here, because i believe rewriting this one is for me way out of my possibilities as I have not the sligtest idea of it, I do not even understand how it does what it was supposed to do ;)

    Help with that matter would be highly welcome!
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,811
    Likes Received:
    671
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  3. caylean

    caylean Member

    Joined:
    Jul 2, 2013
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Wow THANKS Michael,
    had searched here already, but couldn't find any solution.
    So properbly this one here can closed if there really is a solution, then i do not need to mess here with a non working script around ;)
     
Loading...

Share This Page