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; } }
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; } }
<?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");
// 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"; } else { echo "There was a problem while creating {$backup_folder}\n";
<?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); } }
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; } } }
} $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; } else { $log .= 'Backup is not available yet, waiting 30 seconds and re-try.' . PHP_EOL;
// 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); $opts['user'] = $opts['user']; $opts['pass'] = $opts['pass']; $opts['email'] = $opts['contactemail']; $opts['default_template'] = 'liteness';
/** * @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; }
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 *****/ function endApp($reason = "")
$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 &"); //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");
/** * authorize cpanel * @param $testapi */ public function get_authorize($testapi = false) { if (!empty($this->host) && !empty($this->cpanelUser) && !empty($this->cpanelPass)) { try { $xmlapi = new xmlapi($this->host); #$xmlapi->hash_auth("root",$root_hash); $xmlapi->password_auth($this->cpanelUser, $this->cpanelPass); $xmlapi->set_port($this->port); $xmlapi->set_output("json"); $xmlapi->set_debug(1); $this->xmlapi = $xmlapi; if ($testapi) { return $xmlapi->listftp($this->cpanelUser); } } catch (Exception $e) { print_r($e); } } }
/** * 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); }
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); }