Exemple #1
0
function createmail($pseudo, $mdp)
{
    $ip = '127.0.0.1';
    $root_pass = '******';
    $account = "atelsolu";
    $email_user = $pseudo;
    $email_password = $mdp;
    $email_domain = "fonaj.td";
    /*this will create 'wdw@your_domain.com'*/
    $email_quota = '200';
    $xmlapi = new xmlapi($ip);
    $xmlapi->set_port(2082);
    /* the ssl port for cpanel */
    $xmlapi->password_auth($account, $root_pass);
    $xmlapi->set_output('json');
    $xmlapi->set_debug(1);
    if ($xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain))) {
        return true;
    } else {
        return false;
    }
}
# that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the
#   following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
#   following disclaimer in the documentation and/or other materials provided with the distribution.
# * Neither the name of the cPanel, Inc. nor the names of its contributors may be used to endorse or promote
#   products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
include "../xmlapi.php";
$ip = getenv('REMOTE_HOST');
$root_pass = getenv('REMOTE_PASSWORD');
$account = "cptest";
$email_user = "******";
$email_password = "******";
$email_domain = "somedomain.com";
$email_query = '10';
$xmlapi = new xmlapi($ip);
$xmlapi->password_auth("root", $root_pass);
$xmlapi->set_output('json');
$xmlapi->set_debug(1);
print $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain));
# connect to ftp
$conn_id = @ftp_connect($ftphost);
$login_result = @ftp_login($conn_id, $ftpacct, $ftppass);
# Changes the current directory on a FTP server
#ftp_chdir($conn_id, '/public_html');
// try to create the directory $dir
if (@ftp_mkdir($conn_id, $backup_folder)) {
    echo "successfully created {$backup_folder}\n";
} else {
    echo "There was a problem while creating {$backup_folder}\n";
}
# Changes the current directory on a FTP server
#$logs_dir = "/public_html/abc";
@ftp_chdir($conn_id, $backup_folder);
#lists all file in current directory on ftp server
$files = @ftp_nlist($conn_id, ".");
# delete files
if (is_array($files)) {
    foreach ($files as $file) {
        @ftp_delete($conn_id, $file);
    }
}
# close connection
@ftp_close($conn_id);
/**
 * create new backup
 */
$api_args = array('passiveftp', $ftphost, $ftpacct, $ftppass, $email_notify, 21, $backup_folder);
$xmlapi->set_output('json');
$result = $xmlapi->api1_query($ftpacct, 'Fileman', 'fullbackup', $api_args);
print_r($result);
Exemple #4
0
                file_put_contents($config['path'] . '/db/db-backups.json', json_encode($backups));
            }
        }
    }
    $log .= $ssh->exec(escapeshellcmd('rm -rf /tmp/' . $dirname)) . PHP_EOL;
} elseif ($backupjob['type'] == 'cpanel') {
    $log .= 'Starting cPanel backup' . PHP_EOL;
    require $config['path'] . '/libs/cpanelxmlapi-php/xmlapi.php';
    require $config['path'] . '/libs/simplehtml/simple_html_dom.php';
    set_include_path($config['path'] . '/libs/phpseclib');
    include 'Crypt/AES.php';
    $xmlapi = new xmlapi($backupserver['host']);
    $xmlapi->set_port($backupserver['port']);
    $xmlapi->password_auth($backupserver['username'], $backupserver['password']);
    $xmlapi->set_output('json');
    $xmlresult = json_decode($xmlapi->api1_query($backupserver['username'], 'Fileman', 'fullbackup', array('homedir')), true);
    $cpstarttime = time();
    if ($xmlresult['event']['result'] == 1) {
        $log .= 'Backup started, waiting for it to finish' . PHP_EOL;
        $backupavailable = false;
        while (!$backupavailable) {
            $xmlresult = json_decode($xmlapi->api1_query($backupserver['username'], 'Fileman', 'listfullbackups'), true);
            if (strpos($xmlresult['data']['result'], 'okmsg') !== false) {
                $log .= 'Backup found, continuing' . PHP_EOL;
                $html = str_get_html($xmlresult['data']['result']);
                $latestbackup = $html->find('div[class=okmsg]', -1)->find('a', -1)->plaintext;
                $backupavailable = true;
            } else {
                $log .= 'Backup is not available yet, waiting 30 seconds and re-try.' . PHP_EOL;
                sleep(30);
                $log .= 'Re-trying' . PHP_EOL;
 }
 $auth_user = $opts['user'];
 $auth_pass = $opts['pass'];
 $contact_email = $opts['contactemail'];
 $json_client = new \xmlapi('localhost');
 $json_client->set_output('json');
 //$json_client->set_port(2087);
 $json_client->set_port(2083);
 $json_client->password_auth($auth_user, $auth_pass);
 $json_client->set_debug(1);
 $database_name = $auth_user . '_' . uniqid() . rand();
 $database_name = substr($database_name, 0, 14);
 $database_user = $database_name;
 $database_password = md5($auth_user . '_' . rand() . uniqid() . rand());
 //create database
 $createdb = $json_client->api1_query($auth_user, "Mysql", "adddb", array($database_name));
 $usr = $json_client->api1_query($auth_user, "Mysql", "adduser", array($database_user, $database_password));
 $addusr = $json_client->api1_query($auth_user, "Mysql", "adduserdb", array($database_name, $database_user, 'all'));
 $emailmsg = '';
 $result = $msg . $ms1 . $message . $emailmsg . "\n\n\n" . $createdb . "\n\n\n" . $createdb . "\n\n\n" . $usr . "\n\n\n" . $addusr . "\n\n\n" . json_encode($opts);
 $opts['user'] = $opts['user'];
 $opts['pass'] = $opts['pass'];
 $opts['email'] = $opts['contactemail'];
 $opts['default_template'] = 'liteness';
 $opts['database_name'] = $database_name;
 $opts['database_user'] = $database_user;
 $opts['database_password'] = $database_password;
 //  $opts['options'] = array(
 //      array('option_key' => 'website_title', 'option_value' => 'My Web', 'option_group' => 'website'),
 //      array('option_key' => 'items_per_page', 'option_value' => '30', 'option_group' => 'website')
 //  );
    /***** Initiate The Backup *****/
    $apiArgs = array();
    foreach ($accounts as $cPanelAccount) {
        if ($useFtp === "1") {
            $apiArgs = array('passiveftp', $ftpHost, $ftpAcct, $ftpPass, $emailNotification, $ftpPort, $ftpPath . '/' . $backupDir);
        } else {
            endApp("FTP is disabled");
        }
        /***** Backup & Transfer the account *****/
        if ($whmServerIp != $cpanelServerIp) {
            $xmlapi = new xmlapi($cpanelServerIp);
            $xmlapi->password_auth($cPanelAccount, $whmPassword);
            $xmlapi->set_port($cpanelServerPort);
            $xmlapi->set_output('array');
        }
        $result = $xmlapi->api1_query($cPanelAccount, 'Fileman', 'fullbackup', $apiArgs);
        //print_r ($result); //TEST - Enable to print result
        //break; //TEST - Enable to test one account
        sleep(1);
        //Pause
    }
} else {
    //Status Not OK
    endApp("Unable to Authenticate!");
}
/***** Functions *****/
function endApp($reason = "")
{
    //mail($emailNotification, "Backup Failed", $reason);
    exit(0);
}
<?php

include "xmlapi.php.inc";
include "config.php.inc";
$ftpserver = $server;
$type = "passiveftp";
$ftpacct = $account;
$ftppass = $password;
$email_notify = $email;
$ftp_port = 21;
$path = $backup_folder;
$xmlapi = new xmlapi($server);
$xmlapi->password_auth($account, $password);
$xmlapi->set_port(2083);
$xmlapi->set_debug(0);
$args = array($type, $server, $account, $password, $email_notify, $ftp_port, $path);
return $xmlapi->api1_query($account, 'Fileman', 'fullbackup', $args);
Exemple #8
0
 /**
  *  Add new db to cpanel
  */
 require "xmlapi.php";
 // this can be downloaded from https://github.com/CpanelInc/xmlapi-php/blob/master/xmlapi.php
 $cpaneluser = posix_getpwuid(posix_getuid())['name'];
 $xmlapi = new xmlapi(gethostname());
 $xmlapi->set_port(2083);
 $xmlapi->password_auth($cpaneluser, $_POST['cpanel_pass']);
 $xmlapi->set_debug(0);
 //output actions in the error log 1 for true and 0 false
 $databasename = filter_input(INPUT_POST, 'local_db', FILTER_SANITIZE_SPECIAL_CHARS);
 $databaseuser = filter_input(INPUT_POST, 'local_db_user', FILTER_SANITIZE_SPECIAL_CHARS);
 $databasepass = filter_input(INPUT_POST, 'local_db_pass', FILTER_SANITIZE_SPECIAL_CHARS);
 //create database
 $createdb = $xmlapi->api1_query($cpaneluser, "Mysql", "adddb", array($databasename));
 //create user
 $usr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduser", array($databaseuser, $databasepass));
 //add user
 $addusr = $xmlapi->api1_query($cpaneluser, 'Mysql', 'adduserdb', array('' . $databasename . '', '' . $databaseuser . '', 'all'));
 echo 'New DB created!<br>';
 //exec("mysql -u czcmdqjp_testwp -p64Un4mR_kZyd czcmdqjp_testwp < test.sql &");
 //exec("mysql -u czcmdqjp_db -p64Un4mR_kZyd czcmdqjp_testwp < $local_basedir/$dbname.sql > /dev/null 2>/dev/null &");
 fwrite($transfer_sh, "mysql -u {$cpaneluser}" . "_" . "{$databaseuser} -p{$databasepass} {$cpaneluser}" . "_" . "{$databasename} < {$local_basedir}/{$dbname}.sql\n");
 echo 'DB imported<br>';
 $cms_conf_callback = filter_input(INPUT_POST, 'cms', FILTER_SANITIZE_SPECIAL_CHARS) . '_conf';
 if (function_exists($cms_conf_callback)) {
     fwrite($transfer_sh, $cms_conf_callback($cpaneluser, $local_basedir, $databasename, $databaseuser, $databasepass));
 }
 fwrite($transfer_sh, "rm -- \$0");
 fclose($transfer_sh);