/** * Get the current server load for an active cPanel product * * @param Service $service The product being viewed * @return SimpleXMLElement|null */ function getLoadAverageFromService(Service $service) { // No need to do anything if the service is not active or suspended on the server. if (in_array($service->status, array('Pending', 'Terminated', 'Cancelled', 'Fraud'))) { return null; } // We only want to do this work on cPanel products, use other hooks for other modules. if ($service->product->module != 'cpanel') { return null; } // See http://docs.whmcs.com/Interacting_With_The_Database $server = Capsule::table('tblservers')->where('id', $service->serverId)->first(); // See https://github.com/CpanelInc/xmlapi-php $cpServer = new xmlapi($server->ipaddress, $server->username, decrypt($server->password)); // See https://documentation.cpanel.net/display/SDK/WHM+API+0+Functions+-+loadavg $loadAverage = $cpServer->loadavg(); return $loadAverage; }
function deletemail($pseudo) { $ip = '127.0.0.1'; $account_pass = '******'; // cpanel password $account = 'commerc1'; // cpanel username $email_account = $pseudo; // email account name without @mydomain.com $email_domain = 'commerce.gouv.td'; // domain associated with the email account $xmlapi = new xmlapi($ip); $xmlapi->password_auth($account, $account_pass); $xmlapi->set_port(2082); //$xmlapi->set_debug(1); // uncomment for debugging $args = array('domain' => $email_domain, 'email' => $email_account); if ($xmlapi->api2_query($account, 'Email', 'delpop', $args)) { return true; } else { return false; } }
public function __construct($param) { $this->ip = $param["ip"]; $this->user = $param["user"]; $this->pass = $param["pass"]; if (empty($this->ip)) { $this->ip = $_SERVER['SERVER_ADDR']; } parent::__construct($this->ip); if (!empty($this->user) && !empty($this->pass)) { $this->password_auth($this->user, $this->pass); } $this->set_output($param["output"]); $this->set_port($param["port"]); $this->set_debug($param["debug"]); }
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; } }
protected function getAllCpanelDatabases() { include_once dirname(__FILE__) . '/xmlapi-php/xmlapi.php'; $oXmlApi = new xmlapi($this->m_aConfig['CPANEL_SERVER_ADDRESS']); $oXmlApi->password_auth($this->m_aConfig['CPANEL_ADMIN_USERNAME'], $this->m_aConfig['CPANEL_ADMIN_PASSWORD']); $oXmlApi->set_port($this->m_aConfig['CPANEL_PORT_NUM']); $this->m_aDatabaseList = array(); $oResult = $oXmlApi->api2_query($this->m_aConfig['CPANEL_ADMIN_USERNAME'], 'MysqlFE', 'listdbs'); if (!isset($oResult->data[0])) { $this->m_aDatabaseList[] = (string) $oResult->data->db; } else { foreach ($oResult->data as $oDatabase) { $this->m_aDatabaseList[] = (string) $oDatabase->db; } } }
$pub_key = new GPG_Public_Key(file_get_contents($backupjob['encryptionkey'])); file_put_contents($config['path'] . '/files/' . $dirname . '-vzdump-' . $container . '.tgz', $gpg->encrypt(file_get_contents($config['path'] . '/files/' . $dirname . '-vzdump-' . $container . '.tgz'))); } $backups[count($backups)] = array('id' => $backupjob['id'], 'file' => $dirname . '-vzdump-' . $container . '.tgz', 'size' => filesize($config['path'] . '/files/' . $dirname . '-vzdump-' . $container . '.tgz'), 'time' => $vzstarttime); 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;
if (isset($opts["plan"])) { // ini_set('error_log', __DIR__ . DIRECTORY_SEPARATOR . 'my_file.log'); // folder for the microweber source // $opts['source_folder'] = '/usr/share/microweber-latest/'; // debug email // $opts['debug_email'] = '*****@*****.**'; // $opts['debug_email_subject'] = 'debug'; if (is_file('/home/cpanelscripthelpers/xmlapi.php')) { require '/home/cpanelscripthelpers/xmlapi.php'; } else { require __DIR__ . '/cpanelscripthelpers/xmlapi.php'; } $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);
# Copyright (c) 2009, cPanel, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted provided # 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 = "someuser"; $email_account = "randomemail"; $email_domain = "somedomain.com"; $xmlapi = new xmlapi($ip); $xmlapi->password_auth("root", $root_pass); $xmlapi->set_debug(1); print $xmlapi->api2_query($account, "Email", "getdiskusage", array(domain => $email_domain, login => $email_account));
/** * ControllerCpanelEmail::delete() * * @see Load * @see Document * @see Language * @see Session * @see Redirect * @see getList * @return void */ public function delete() { $this->load->library('cpxmlapi'); $cp = new xmlapi(CPANEL_HOST); if (isset($this->request->post['selected'])) { $cp->set_port(CPANEL_PORT); //set port number. cpanel client class allow you to access WHM as well using WHM port. $cp->password_auth(CPANEL_USER, CPANEL_PWD); // authorization with password. not as secure as hash. $cp->set_debug(0); //output to error file set to 1 to see error_log. foreach ($this->request->post['selected'] as $user) { // cpanel email addpop function Parameters $call = array('domain' => CPANEL_DOMAIN, 'email' => $user); $result = $cp->api2_query(CPANEL_USER, "Email", "delpop", $call); // making call to cpanel api } if ($result->data->result == 1) { $this->session->data['success'] = " La(s) cuenta(s) han sido eliminada(s) con éxito"; } else { $this->session->data['error'] = "No se pudo eliminar la cuenta de correo: " . $result->data->reason; } } $this->redirect(Url::createAdminUrl('cpanel/email') . $url); }
$accounts = array(); foreach ($listAccounts['acct'] as $account) { $accounts[] = $account['user']; //echo $account['user'] . "<br />"; //TEST - Enable to test storing accounts in an array } /***** 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 *****/
/** * @param \RainLoop\Model\Account $oAccount * @param string $sPrevPassword * @param string $sNewPassword * * @return bool */ public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) { if ($this->oLogger) { $this->oLogger->Write('Try to change password for ' . $oAccount->Email()); } if (!\class_exists('xmlapi')) { include_once __DIR__ . '/xmlapi.php'; } $bResult = false; if (!empty($this->sHost) && 0 < $this->iPost && 0 < \strlen($this->sUser) && 0 < \strlen($this->sPassword) && $oAccount && \class_exists('xmlapi')) { $sEmail = $oAccount->Email(); $sEmailUser = \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail); $sEmailDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail); $sHost = $this->sHost; $sHost = \str_replace('{user:domain}', $sEmailDomain, $sHost); $sUser = $this->sUser; $sUser = \str_replace('{user:email}', $sEmail, $sUser); $sUser = \str_replace('{user:login}', $sEmailUser, $sUser); $sPassword = $this->sPassword; $sPassword = \str_replace('{user:password}', $oAccount->Password(), $sPassword); try { $oXmlApi = new \xmlapi($sHost); $oXmlApi->set_port($this->iPost); $oXmlApi->set_protocol($this->bSsl ? 'https' : 'http'); $oXmlApi->set_debug(false); $oXmlApi->set_output('json'); // $oXmlApi->set_http_client('fopen'); $oXmlApi->set_http_client('curl'); $oXmlApi->password_auth($sUser, $sPassword); $aArgs = array('email' => $sEmailUser, 'domain' => $sEmailDomain, 'password' => $sNewPassword); $sResult = $oXmlApi->api2_query($sUser, 'Email', 'passwdpop', $aArgs); if ($sResult) { if ($this->oLogger) { $this->oLogger->Write('CPANEL: ' . $sResult, \MailSo\Log\Enumerations\Type::INFO); } $aResult = @\json_decode($sResult, true); $bResult = isset($aResult['cpanelresult']['data'][0]['result']) && !!$aResult['cpanelresult']['data'][0]['result']; } if (!$bResult && $this->oLogger) { $this->oLogger->Write('CPANEL: ' . $sResult, \MailSo\Log\Enumerations\Type::ERROR); } } catch (\Exception $oException) { if ($this->oLogger) { $this->oLogger->WriteException($oException); } } } else { if ($this->oLogger) { $this->oLogger->Write('CPANEL: Incorrent configuration data', \MailSo\Log\Enumerations\Type::ERROR); } } return $bResult; }
//exec("mysqldump --opt -h $dbhost -u $dbuser -p$dbpass $dbname > $local_basedir/$dbname.sql &"); $dsn = "mysql:host={$dbhost};dbname={$dbname};charset=utf8"; $opt = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC); try { $pdo = new PDO($dsn, $dbuser, $dbpass, $opt); fwrite($transfer_sh, "mysqldump --opt -h {$dbhost} -u {$dbuser} -p{$dbpass} {$dbname} > {$local_basedir}/{$dbname}.sql\n"); } catch (PDOException $e) { echo 'Нет соединения с удаленной базой данных'; } /** * 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 &");
<?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);
<?php # Copyright (c) 2009, cPanel, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted provided # 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 = "127.0.0.1"; $root_pass = "******"; $account = "someuser"; $xmlapi = new xmlapi($ip); $xmlapi->password_auth("root", $root_pass); $xmlapi->set_debug(1); print $xmlapi->api2_query($account, "Email", "listpopswithdisk");
/** * root access * @param $domain * @param $root_hash * @return xmlapi */ public static function authorize_root($domain, $root_hash) { self::$hashroot = $root_hash; //save hash try { $xmlapi = new xmlapi($domain); $xmlapi->hash_auth(HW_WHM_ROOT_USER, $root_hash); $xmlapi->set_output("json"); $xmlapi->set_debug(1); $inst = new self(); $inst->host = $domain; #$inst->cpanelUser = '******'; #$inst->cpanelPass = $root_hash; $inst->xmlapi = $xmlapi; return $inst; } catch (Exception $e) { print_r($e); } }
# Copyright (c) 2009, cPanel, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted provided # 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'); # The access has can be found on your server under WHM's "Setup remote access hash" section or at /root/.accesshash $root_hash = '__ROOT_HASH_GOES_HERE__'; $xmlapi = new xmlapi($ip); $xmlapi->hash_auth("root", $root_hash); $xmlapi->return_xml(1); $xmlapi->set_debug(1); print $xmlapi->listaccts();
<?php include "xmlapi.php.inc"; include "config.php.inc"; $xmlapi = new xmlapi($server); $xmlapi->password_auth($account, $password); $xmlapi->set_port(2083); $xmlapi->set_debug(0); $args = array('checkleaf' => '1', 'dir' => $backup_folder, 'filelist' => '0', 'filepath-*' => '', 'needmime' => '0', 'showdotfiles' => '0', 'types' => 'file'); $list = $xmlapi->api2_query($account, 'Fileman', 'listfiles', $args); $files = array(); foreach ($list->data as $item) { $files[] = array($item->file, $item->mtime, $item->ctime, $item->fullpath, $item->humansize); } foreach ($files as $file) { if ($file[1] < $retention) { $files = $backup_folder . '/' . $file[0]; $args = array('op' => 'unlink', 'sourcefiles' => $files, 'destfiles' => $backup_folder, 'doubledecode' => '0'); $xmlapi = new xmlapi($server); $xmlapi->password_auth($account, $password); $xmlapi->set_port(2083); return $xmlapi->api2_query($account, 'Fileman', 'fileop', $args); } }
# Redistribution and use in source and binary forms, with or without modification, are permitted provided # 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));
// FTP account $ftppass = isset($acc['cpanel_pass']) ? decrypt($acc['cpanel_pass']) : (isset($_POST['pass']) ? $_POST['pass'] : ""); // FTP password $email_notify = isset($acc['cpanel_email']) ? $acc['cpanel_email'] : (isset($_POST['email_notify']) ? $_POST['email_notify'] : "*****@*****.**"); // Email address for backup notification $backup_folder = '/public_html/hw_backups'; //validation if (empty($ftphost) || empty($ftpacct) || empty($ftppass)) { exit("Provide full credentials ?"); } #echo $ftphost,',',$ftpacct,',',$ftppass; /** * create cpanel instance */ include_once 'libs/xmlapi.php'; $xmlapi = new xmlapi($ftphost); #$xmlapi->hash_auth("root",$root_hash); $xmlapi->password_auth($ftpacct, $ftppass); $xmlapi->set_port(2083); $xmlapi->set_output("json"); /** * delete old backup file */ # 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";
# Copyright (c) 2009, cPanel, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted provided # 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'); $domain = "somedns.com"; $xmlapi = new xmlapi($ip); $xmlapi->password_auth("root", $root_pass); $xmlapi->set_http_client('curl'); $xmlapi->set_port(2086); $xmlapi->set_debug(1); print $xmlapi->adddns($domain, $ip);
<?php # Copyright (c) 2009, cPanel, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted provided # 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'); $domain = "somedns.com"; $xmlapi = new xmlapi($ip); $xmlapi->password_auth("root", $root_pass); $xmlapi->set_debug(1); print $xmlapi->killdns($domain);
function googleapps_show($vars) { global $smarty; $lang_arr = $smarty->get_template_vars('LANG'); $module = $vars['modulename']; $cpuser = $vars['username']; $srv_host = $vars['serverip']; $srv_user = $vars['serverusername']; $srv_pass = $vars['serverpassword']; $srv_hash = $vars['serveraccesshash']; $srv_secure = $vars['serversecure']; $status = $vars['rawstatus']; if ($module != 'cpanel' || $status != 'active') { $isvalid = 0; } else { $isvalid = 1; } if ($isvalid) { // Setup API connection $xmlapi = new xmlapi($srv_host); if ($srv_secure) { $srv_port = 2087; } else { $srv_port = 2086; } if (!$srv_hash) { $xmlapi->password_auth($srv_user, $srv_pass); } else { $xmlapi->hash_auth($srv_user, preg_replace("'(\r|\n)'", "", $srv_hash)); } $xmlapi->set_port($srv_port); $accounts = array(); $accounts[] = $cpuser; $domains = ga_getUserDomains($xmlapi, $cpuser); // Check if reseller $reseller = $xmlapi->resellerstats($cpuser); if (isset($reseller->result->accts)) { // This is a reseller foreach ($reseller->result->accts as $key => $val) { if ($val->user != $cpuser) { $accounts[] = (string) $val->user; } } } // handle event to populate domain select if (isset($_REQUEST['domlookup'])) { $curcpuser = $_REQUEST['user']; $res = ga_getUserDomains($xmlapi, $curcpuser); print json_encode($res); exit(1); } // handle event to change mode between local and google if (isset($_REQUEST['googleit'])) { $errorcount = 0; $config = $_REQUEST['config']; $cur_cpuser = $_REQUEST['user']; $cur_domain = $_REQUEST['domain']; $cur_domain_dot = $cur_domain . "."; $doms_for_user = ga_getUserDomains($xmlapi, $cur_cpuser); // check if user actually owns domain, and user if (in_array($cur_domain, $doms_for_user) && in_array($cur_cpuser, $accounts)) { $rmRec = array(); $zdata = $xmlapi->dumpzone($cur_domain); // step through zone records and find MX, google CNAMEs, mail. CNAME, and SPF record foreach ($zdata->result->record as $key => $val) { if ($val->type == 'MX') { $rmRec[] = array('line' => (string) $val->Line, 'name' => (string) $val->exchange); } elseif ($val->type == 'CNAME' && ($val->name == 'mail.' . $cur_domain_dot || $val->name == 'calendar.' . $cur_domain_dot || $val->name == 'start.' . $cur_domain_dot || $val->name == 'sites.' . $cur_domain_dot || $val->name == 'docs.' . $cur_domain_dot)) { $rmRec[] = array('line' => (string) $val->Line, 'name' => (string) $val->name); } elseif ($val->type == 'TXT' && preg_match('/v=spf/', (string) $val->txtdata)) { $rmRec[] = array('line' => (string) $val->Line, 'name' => (string) $val->name); } } // we must reverse sort them so the line numbers do not when they are removed rsort($rmRec); $gmail_smtp = array('aspmx.l.google.com' => '0', 'alt1.aspmx.l.google.com' => '10', 'alt2.aspmx.l.google.com' => '10', 'aspmx2.googlemail.com' => '20', 'aspmx3.googlemail.com' => '20', 'aspmx4.googlemail.com' => '20', 'aspmx5.googlemail.com' => '20'); $ghshost = "ghs.google.com"; $cnlist = array("calendar", "start", "sites", "docs"); // delete lines in zone file found in previous statements foreach ($rmRec as $del) { $rmline = $del['line']; $rmname = $del['name']; $rmdata = $xmlapi->removezonerecord($cur_domain, $rmline); if ($rmdata->result->status == 0) { $errorcount++; $error .= "Removal of {$rmname} failed. -- " . $rmdata->result->statusmsg . "<br />"; } } $mxname = "mail.{$cur_domain}."; if ($config == 'google') { $cname = $ghshost; } else { $cname = $cur_domain; } $cnameArr = array('name' => $mxname, 'type' => 'CNAME', 'cname' => $cname); // Add main "mail." CNAME record back as google or local $cnamedata = $xmlapi->addzonerecord($cur_domain, $cnameArr); if ($cnamedata->result->status == 0) { $errorcount++; $error .= "Failed to add {$mxname}. -- " . $cnamedata->result->statusmsg . "<br />"; } if ($config == 'google') { // Add google specific CNAME's foreach ($cnlist as $cur_cname) { $cn = $cur_cname . '.' . $cur_domain . '.'; $addArr = array('name' => $cn, 'type' => 'CNAME', 'cname' => $ghshost); $adddata = $xmlapi->addzonerecord($cur_domain, $addArr); if ($adddata->result->status == 0) { $errorcount++; $error .= "Failed to add {$cn} -- " . $adddata->result->statusmsg . "<br />"; } } // Add google SPF $txtdata = '"v=spf1 include:' . $cur_domain . ' include:_spf.google.com ~all"'; $spfArr = array('name' => $cur_domain_dot, 'type' => 'TXT', 'txtdata' => $txtdata); $spfdata = $xmlapi->addzonerecord($cur_domain, $spfArr); if ($spfdata->result->status == 0) { $errorcount++; $error .= "Failed to add SPF record -- " . $spfdata->result->statusmsg . "<br />"; } } if ($config == 'google') { $mx = $gmail_smtp; } else { $mx = array($cur_domain => 0); } // Add MX records foreach ($mx as $key => $val) { $exchange = $key; $pref = $val; $addArr = array('name' => $cur_domain_dot, 'type' => 'MX', 'exchange' => $exchange, 'preference' => $pref); $adddata = $xmlapi->addzonerecord($cur_domain, $addArr); if ($adddata->result->status == 0) { $errorcount++; $error .= "Failed to add {$exchange} MX record -- " . $adddata->result->statusmsg . "<br />"; } } if ($config == 'google') { $mxcheck = 'remote'; } else { $mxcheck = 'local'; } // Set mxcheck to local or remote $sdataArr = array('domain' => $cur_domain, 'mxcheck' => $mxcheck); $sdata = $xmlapi->api2_query($cpuser, 'Email', 'setalwaysaccept', $sdataArr); if ($sdata->data->status == 0) { $errorcount++; $error .= "Could not set MX accept status to {$mxcheck} -- " . $sdata->data->statusmsg . "<br />"; } if (!$errorcount) { $fullmsg = $lang_arr['googleapps_noerror'] . '<br />'; } else { $fullmsg = $lang_arr['googleapps_error'] . '<br />'; } } else { $fullmsg = $lang_arr['googleapps_error'] . '<br />'; $error .= $lang_arr['googleapps_notowned'] . '<br />'; } $resultsArr = array('msg' => $fullmsg, 'error' => $error); print json_encode($resultsArr); exit(1); } } $smarty->assign('googleapps_isvalid', $isvalid); $smarty->assign('googleapps_domains', $domains); $smarty->assign('googleapps_users', $accounts); }
<?php # Copyright (c) 2009, cPanel, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted provided # 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'); $xmlapi = new xmlapi($ip); $xmlapi->password_auth("root", $root_pass); $xmlapi->set_debug(1); print $xmlapi->listips();
<?php # Copyright (c) 2009, cPanel, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted provided # 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 = "127.0.0.1"; $root_pass = "******"; $xmlapi = new xmlapi($ip); $xmlapi->password_auth("root", $root_pass); $xmlapi->set_debug(1); $acct = array(username => "someuser", password => "pass123", domain => "thisdomain.com"); print $xmlapi->createacct($acct);
<?php # Copyright (c) 2009, cPanel, Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, are permitted provided # 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 = "10.1.5.169"; $root_pass = "******"; $xmlapi = new xmlapi($ip); $xmlapi->password_auth("root", $root_pass); $xmlapi->set_debug(1); print $xmlapi->addip("127.0.0.3", "255.255.255.0");
/** * Adds the service to the remote server. Sets Input errors on failure, * preventing the service from being added. * * @param stdClass $package A stdClass object representing the selected package * @param array $vars An array of user supplied info to satisfy the request * @param stdClass $parent_package A stdClass object representing the parent service's selected package (if the current service is an addon service) * @param stdClass $parent_service A stdClass object representing the parent service of the service being added (if the current service is an addon service service and parent service has already been provisioned) * @param string $status The status of the service being added. These include: * - active * - canceled * - pending * - suspended * @return array A numerically indexed array of meta fields to be stored for this service containing: * - key The key for this meta field * - value The value for this key * - encrypted Whether or not this field should be encrypted (default 0, not encrypted) * @see Module::getModule() * @see Module::getModuleRow() */ public function addService($package, array $vars = null, $parent_package = null, $parent_service = null, $status = "pending") { $row = $this->getModuleRow(); $api = $this->getApiByMeta($row->meta); // If no username given, generate a username if (!$this->getFromVars($vars, 'cpanel_username') and $this->getFromVars($vars, 'cpanel_domain')) { $vars['cpanel_username'] = $this->generateUsername($vars['cpanel_domain']); } $params = $this->getInputFieldsToCreate((array) $vars, $package); $this->validateService($package, $vars); if ($this->Input->errors()) { return; } // Generate Password if the Field is Hidden if ($package->meta->passwordfield != 'true') { $params['password'] = $this->generatePassword(); } // Only provision the service if 'use_module' is true if ($vars['use_module'] == "true") { $masked_params = $params; $masked_params['password'] = "******"; $this->log($row->meta->host_name . "|createacct", serialize($masked_params), "input", true); unset($masked_params); $result = $api->createacct($params); $this->parseResponse($result->getCleanResponse()); if ($this->Input->errors()) { return; } // If reseller and we have an ACL set, update the reseller's ACL if ($package->meta->type == "reseller") { if ($package->meta->acl != "") { $api->setacls(array('reseller' => $params['username'], 'acllist' => $package->meta->acl)); } // Set Space Limit for Resellers if (!empty($package->meta->diskreseller) && !empty($package->meta->bandreseller)) { Loader::load(dirname(__FILE__) . DS . "api" . DS . "xmlapi.php"); $xmlapi = new xmlapi($row->meta->host_name, $row->meta->user_name, $row->meta->password); $params = array('user' => $vars['cpanel_username'], 'enable_resource_limits' => 1, 'diskspace_limit' => $package->meta->diskreseller, 'bandwidth_limit' => $package->meta->bandreseller); $this->log($row->meta->host_name . "|setresellerlimits", serialize($params), "input", true); $response = $xmlapi->setresellerlimits($params); } } } // Return service fields return array(array('key' => "cpanel_domain", 'value' => $params['domain'], 'encrypted' => 0), array('key' => "cpanel_username", 'value' => $params['username'], 'encrypted' => 0), array('key' => "cpanel_password", 'value' => $params['password'], 'encrypted' => 1), array('key' => "cpanel_confirm_password", 'value' => $params['password'], 'encrypted' => 1)); }