Hey there, i'm currently using VestaCP with BoxBilling, and I can't find a way to automate sales for it. If somebody could update this php for free i'll give ya a vouch. First one to finish and it has to work. Of course, don't try and pull off anything.
Convert from (old, base it off of this):
Convert Into (edit this):
WHMCS VestaCP Module (for reference):
Convert from (old, base it off of this):
PHP:
<?php
/**
* BoxBilling
*
* LICENSE
*
* This source file is subject to the license that is bundled
* with this package in the file LICENSE.txt
* It is also available through the world-wide-web at this URL:
* http://www.boxbilling.com/LICENSE.txt
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @copyright Copyright (c) 2010-2012 BoxBilling (http://www.boxbilling.com)
* @license http://www.boxbilling.com/LICENSE.txt
* @version $Id$
*/
class Server_Manager_Vesta extends Server_Manager
{
/**
* Method is called just after obejct contruct is complete.
* Add required parameters checks here.
*/
public function init()
{
}
/**
* Return server manager parameters.
* @return type
*/
public static function getForm()
{
return array(
'label' => 'Vesta Server Manager V2',
);
}
/**
* Returns link to account management page
*
* @return string
*/
public function getLoginUrl()
{
$host = 'http';
if ($this->_config['secure']) {
$host .= 's';
}
$host .= '://' . $this->_config['host'] . ':'.$this->_config['port'].'/';
return $host;
}
/**
* Returns link to reseller account management
* @return string
*/
public function getResellerLoginUrl()
{
return 'http://www.google.com?q=whm';
}
private function _makeRequest($params)
{
$host = 'http';
if ($this->_config['secure']) {
$host .= 's';
}
$host .= '://' . $this->_config['host'] . ':'.$this->_config['port'].'/api/';
// Server credentials
$params['user'] = $this->_config['username'];
$params['password'] = $this->_config['password'];
// Send POST query via cURL
$postdata = http_build_query($params);
$curl = curl_init();
$timeout = 5;
curl_setopt($curl, CURLOPT_URL, $host);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
$result = curl_exec($curl);
curl_close($curl);
if(strpos($result, 'Error')!== false){
throw new Server_Exception('Connection to server failed '.$result);
}
return $result;
}
private function _getPackageName(Server_Package $package)
{
$name = $package->getName();
return $name;
}
/**
* This method is called to check if configuration is correct
* and class can connect to server
*
* @return boolean
*/
public function testConnection()
{
// Server credentials
$vst_command = 'v-check-user-password';
$vst_returncode = 'yes';
// Prepare POST query
$postvars = array(
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $this->_config['username'],
'arg2' => $this->_config['password'],
);
// Make request and check sys info
$result = $this->_makeRequest($postvars);
if(strpos($result, 'Error')!== false){
throw new Server_Exception('Connection to server failed '.$result);
}
else {
if ($result == 0) {
return true;
} else {
throw new Server_Exception('Connection to server failed '.$result);
}
}
return true;
}
/**
* MEthods retrieves information from server, assignes new values to
* cloned Server_Account object and returns it.
* @param Server_Account $a
* @return Server_Account
*/
public function synchronizeAccount(Server_Account $a)
{
$this->getLog()->info('Synchronizing account with server '.$a->getUsername());
$new = clone $a;
//@example - retrieve username from server and set it to cloned object
//$new->setUsername('newusername');
return $new;
}
/**
* Create new account on server
*
* @param Server_Account $a
*/
public function createAccount(Server_Account $a)
{
$p = $a->getPackage();
$packname = $this->_getPackageName($p);
$client = $a->getClient();
// Server credentials
$vst_command = 'v-add-user';
$vst_returncode = 'yes';
$parts = explode(" ", $client->getFullName());
$lastname = array_pop($parts);
$firstname = implode(" ", $parts);
// Prepare POST query
$postvars = array(
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $a->getUsername(),
'arg2' => $a->getPassword(),
'arg3' => $client->getEmail(),
'arg4' => $packname,
'arg5' => $firstname,
'arg6' => $lastname
);
// Make request and create user
$result = $this->_makeRequest($postvars);
if($result == 0)
{
// Create Domain Prepare POST query
$postvars2 = array(
'returncode' => 'yes',
'cmd' => 'v-add-domain',
'arg1' => $a->getUsername(),
'arg2' => $a->getDomain()
);
$result2 = $this->_makeRequest($postvars2);
}
else {
}
if($result2 != '0'){
throw new Server_Exception('Server Manager Vesta CP Error: Create Domain failure '.$result2);
}
return true;
}
/**
* Suspend account on server
* @param Server_Account $a
*/
public function suspendAccount(Server_Account $a)
{
$user = $a->getUsername();
// Prepare POST query
$postvars = array(
'returncode' => 'yes',
'cmd' => 'v-suspend-user',
'arg1' => $a->getUsername(),
'arg2' => 'no'
);
// Make request and suspend user
$result = $this->_makeRequest($postvars);
// Check if error 6 the account is suspended on server
if($result == '6'){
return true;
}
if($result != '0'){
throw new Server_Exception('Server Manager Vesta CP Error: Suspend Account Error '.$result.$suspended);
}
return true;
}
/**
* Unsuspend account on server
* @param Server_Account $a
*/
public function unsuspendAccount(Server_Account $a)
{
// Server credentials
$vst_command = 'v-unsuspend-user';
$vst_returncode = 'yes';
// Prepare POST query
$postvars = array(
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $a->getUsername(),
'arg2' => 'no',
'arg3' =>'',
'arg4' =>'',
'arg5' =>'',
'arg6' =>'',
'arg7' =>'',
'arg8' =>'',
'arg9' =>''
);
$result = $this->_makeRequest($postvars);
if($result != '0'){
throw new Server_Exception('Server Manager Vesta CP Error: unSuspend Account Error '.$result);
}
return true;
}
/**
* Cancel account on server
* @param Server_Account $a
*/
public function cancelAccount(Server_Account $a)
{
// Server credentials
$vst_username = $this->_config['username'];
$vst_password = $this->_config['password'];
$vst_command = 'v-delete-user';
$vst_returncode = 'yes';
// Prepare POST query
$postvars = array(
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $a->getUsername(),
'arg2' => 'no'
);
// Make request and delete user
$result = $this->_makeRequest($postvars);
if($result == '3'){
return true;
}
else {if($result != '0'){
throw new Server_Exception('Server Manager Vesta CP Error: Cancel Account Error '.$result);
}}
return true;
}
/**
* Change account package on server
* @param Server_Account $a
* @param Server_Package $p
*/
public function changeAccountPackage(Server_Account $a, Server_Package $p)
{
$package = $a->getPackage()->getName();
// Server credentials
$vst_username = $this->_config['username'];
$vst_password = $this->_config['password'];
$vst_command = 'v-change-user-package';
$vst_returncode = 'yes';
// Prepare POST query
$postvars = array(
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $a->getUsername(),
'arg2' => $this->_getPackageName($p),
'arg3' => 'no'
);
// Make request and change package
$result = $this->_makeRequest($postvars);
if($result != '0'){
throw new Server_Exception('Server Manager Vesta CP Error: Change User package Account Error '.$result);
}
return true;
}
/**
* Change account username on server
* @param Server_Account $a
* @param type $new - new account username
*/
public function changeAccountUsername(Server_Account $a, $new)
{
{
throw new Server_Exception('Server Manager Vesta CP Error: Not Supported');
}
}
/**
* Change account domain on server
* @param Server_Account $a
* @param type $new - new domain name
*/
public function changeAccountDomain(Server_Account $a, $new)
{
{
throw new Server_Exception('Server Manager Vesta CP Error: Not Supported');
}
}
/**
* Change account password on server
* @param Server_Account $a
* @param type $new - new password
*/
public function changeAccountPassword(Server_Account $a, $new)
{
// Server credentials
$vst_username = $this->_config['username'];
$vst_password = $this->_config['password'];
$vst_command = 'v-change-user-password';
$vst_returncode = 'yes';
// Prepare POST query
$postvars = array(
'returncode' => $vst_returncode,
'cmd' => $vst_command,
'arg1' => $a->getUsername(),
'arg2' => $new
);
// Make request and change password
$result = $this->_makeRequest($postvars);
if($result != '0'){
throw new Server_Exception('Server Manager Vesta CP Error: Change Password Account Error '.$result);
}
return true;
}
/**
* Change account IP on server
* @param Server_Account $a
* @param type $new - account IP
*/
public function changeAccountIp(Server_Account $a, $new)
{
{
throw new Server_Exception('Server Manager Vesta CP Error: Not Supported');
}
}
}
PHP:
<?php
class Server_Manager_Custom extends Server_Manager
{
public static function getForm()
{
return array(
'label' => 'VestaCP',
);
}
public function getLoginUrl()
{
return 'http://www.google.com?q=cpanel';
}
public function getResellerLoginUrl()
{
return 'http://www.google.com?q=whm';
}
public function testConnection()
{
return TRUE;
}
public function synchronizeAccount(Server_Account $a)
{
$this->getLog()->info('Synchronizing account with server '.$a->getUsername());
return $a;
}
public function createAccount(Server_Account $a)
{
if($a->getReseller()) {
$this->getLog()->info('Creating reseller hosting account');
} else {
$this->getLog()->info('Creating shared hosting account');
}
}
public function suspendAccount(Server_Account $a)
{
if($a->getReseller()) {
$this->getLog()->info('Suspending reseller hosting account');
} else {
$this->getLog()->info('Suspending shared hosting account');
}
}
public function unsuspendAccount(Server_Account $a)
{
if($a->getReseller()) {
$this->getLog()->info('Unsuspending reseller hosting account');
} else {
$this->getLog()->info('Unsuspending shared hosting account');
}
}
public function cancelAccount(Server_Account $a)
{
if($a->getReseller()) {
$this->getLog()->info('Canceling reseller hosting account');
} else {
$this->getLog()->info('Canceling shared hosting account');
}
}
public function changeAccountPackage(Server_Account $a, Server_Package $p)
{
if($a->getReseller()) {
$this->getLog()->info('Updating reseller hosting account');
} else {
$this->getLog()->info('Updating shared hosting account');
}
$p->getName();
$p->getQuota();
$p->getBandwidth();
$p->getMaxSubdomains();
$p->getMaxParkedDomains();
$p->getMaxDomains();
$p->getMaxFtp();
$p->getMaxSql();
$p->getMaxPop();
$p->getCustomValue('param_name');
}
public function changeAccountUsername(Server_Account $a, $new)
{
if($a->getReseller()) {
$this->getLog()->info('Changing reseller hosting account username');
} else {
$this->getLog()->info('Changing shared hosting account username');
}
}
public function changeAccountDomain(Server_Account $a, $new)
{
if($a->getReseller()) {
$this->getLog()->info('Changing reseller hosting account domain');
} else {
$this->getLog()->info('Changing shared hosting account domain');
}
}
public function changeAccountPassword(Server_Account $a, $new)
{
if($a->getReseller()) {
$this->getLog()->info('Changing reseller hosting account password');
} else {
$this->getLog()->info('Changing shared hosting account password');
}
}
public function changeAccountIp(Server_Account $a, $new)
{
if($a->getReseller()) {
$this->getLog()->info('Changing reseller hosting account ip');
} else {
$this->getLog()->info('Changing shared hosting account ip');
}
}
}
PHP:
<?php
// This module sponsered by our good friends from wexcloud.com
function vesta_ConfigOptions() {
$configarray = array(
"Package Name" => array( "Type" => "text", "Default" => "default"),
"SSH Access" => array( "Type" => "yesno", "Description" => "Tick to grant access", ),
"IP Address (optional)" => array( "Type" => "text" ),
);
return $configarray;
}
function vesta_CreateAccount($params) {
// Execute only if there is assigned server
if ($params["server"] == 1) {
// Prepare variables
$postvars = array(
'user' => $params["serverusername"],
'password' => $params["serverpassword"],
'hash' => $params["serveraccesshash"],
'cmd' => 'v-add-user',
'arg1' => $params["username"],
'arg2' => $params["password"],
'arg3' => $params["clientsdetails"]["email"],
'arg4' => $params["configoption1"],
'arg5' => $params["clientsdetails"]["firstname"],
'arg6' => $params["clientsdetails"]["lastname"],
);
$postdata = http_build_query($postvars);
// Create user account
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
logModuleCall('vesta','CreateAccount_UserAccount','https://'.$params["serverhostname"].':8083/api/'.$postdata,$answer);
// Enable ssh access
if(($answer == 'OK') && ($params["configoption2"] == 'on')) {
$postvars = array(
'user' => $params["serverusername"],
'password' => $params["serverpassword"],
'hash' => $params["serveraccesshash"],
'cmd' => 'v-change-user-shell',
'arg1' => $params["username"],
'arg2' => 'bash'
);
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
logModuleCall('vesta','CreateAccount_EnableSSH','https://'.$params["serverhostname"].':8083/api/'.$postdata,$answer);
}
// Add domain
if(($answer == 'OK') && (!empty($params["domain"]))) {
$postvars = array(
'user' => $params["serverusername"],
'password' => $params["serverpassword"],
'hash' => $params["serveraccesshash"],
'cmd' => 'v-add-domain',
'arg1' => $params["username"],
'arg2' => $params["domain"],
'arg3' => $params["configoption3"],
);
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
logModuleCall('vesta','CreateAccount_AddDomain','https://'.$params["serverhostname"].':8083/api/'.$postdata,$answer);
}
}
if($answer == 'OK') {
$result = "success";
} else {
$result = $answer;
}
return $result;
}
function vesta_TerminateAccount($params) {
// Execute only if there is assigned server
if ($params["server"] == 1) {
// Prepare variables
$postvars = array(
'user' => $params["serverusername"],
'password' => $params["serverpassword"],
'hash' => $params["serveraccesshash"],
'cmd' => 'v-delete-user',
'arg1' => $params["username"]
);
$postdata = http_build_query($postvars);
// Delete user account
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
}
logModuleCall('vesta','TerminateAccount','https://'.$params["serverhostname"].':8083/api/'.$postdata,$answer);
if($answer == 'OK') {
$result = "success";
} else {
$result = $answer;
}
return $result;
}
function vesta_SuspendAccount($params) {
// Execute only if there is assigned server
if ($params["server"] == 1) {
// Prepare variables
$postvars = array(
'user' => $params["serverusername"],
'password' => $params["serverpassword"],
'hash' => $params["serveraccesshash"],
'cmd' => 'v-suspend-user',
'arg1' => $params["username"]
);
$postdata = http_build_query($postvars);
// Susupend user account
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
}
logModuleCall('vesta','SuspendAccount','https://'.$params["serverhostname"].':8083/api/'.$postdata,$answer);
if($answer == 'OK') {
$result = "success";
} else {
$result = $answer;
}
return $result;
}
function vesta_UnsuspendAccount($params) {
// Execute only if there is assigned server
if ($params["server"] == 1) {
// Prepare variables
$postvars = array(
'user' => $params["serverusername"],
'password' => $params["serverpassword"],
'hash' => $params["serveraccesshash"],
'cmd' => 'v-unsuspend-user',
'arg1' => $params["username"]
);
$postdata = http_build_query($postvars);
// Unsusupend user account
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
}
logModuleCall('vesta','UnsuspendAccount','https://'.$params["serverhostname"].':8083/api/'.$postdata,$answer);
if($answer == 'OK') {
$result = "success";
} else {
$result = $answer;
}
return $result;
}
function vesta_ChangePassword($params) {
// Execute only if there is assigned server
if ($params["server"] == 1) {
// Prepare variables
$postvars = array(
'user' => $params["serverusername"],
'password' => $params["serverpassword"],
'hash' => $params["serveraccesshash"],
'cmd' => 'v-change-user-password',
'arg1' => $params["username"],
'arg2' => $params["password"]
);
$postdata = http_build_query($postvars);
// Change user package
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
}
logModuleCall('vesta','ChangePassword','https://'.$params["serverhostname"].':8083/api/'.$postdata,$answer);
if($answer == 'OK') {
$result = "success";
} else {
$result = $answer;
}
return $result;
}
function vesta_ChangePackage($params) {
// Execute only if there is assigned server
if ($params["server"] == 1) {
// Prepare variables
$postvars = array(
'user' => $params["serverusername"],
'password' => $params["serverpassword"],
'hash' => $params["serveraccesshash"],
'cmd' => 'v-change-user-package',
'arg1' => $params["username"],
'arg2' => $params["configoption1"]
);
$postdata = http_build_query($postvars);
// Change user package
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
}
logModuleCall('vesta','ChangePackage','https://'.$params["serverhostname"].':8083/api/'.$postdata,$answer);
if($answer == 'OK') {
$result = "success";
} else {
$result = $answer;
}
return $result;
}
function vesta_ClientArea($params) {
$code = '<form action="https://'.$params["serverhostname"].':8083/login/" method="post" target="_blank">
<input type="hidden" name="user" value="'.$params["username"].'" />
<input type="hidden" name="password" value="'.$params["password"].'" />
<input type="submit" value="Login to Control Panel" />
<input type="button" value="Login to Webmail" onClick="window.open(\'http://'.$serverhostname.'/webmail\')" />
</form>';
return $code;
}
function vesta_AdminLink($params) {
$code = '<form action="https://'.$params["serverhostname"].':8083/login/" method="post" target="_blank">
<input type="hidden" name="user" value="'.$params["serverusername"].'" />
<input type="hidden" name="password" value="'.$params["serverpassword"].'" />
<input type="submit" value="Login to Control Panel" />
</form>';
return $code;
}
function vesta_LoginLink($params) {
echo "<a href=\"https://".$params["serverhostname"].":8083/login/\" target=\"_blank\" style=\"color:#cc0000\">control panel</a>";
}
function vesta_UsageUpdate($params) {
// Prepare variables
$postvars = array(
'user' => $params["serverusername"],
'password' => $params["serverpassword"],
'hash' => $params["serveraccesshash"],
'cmd' => 'v-list-users',
'arg1' => 'json'
);
$postdata = http_build_query($postvars);
// Get user stats
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);
// Decode json data
$results = json_decode($answer, true);
// Loop through results and update DB
foreach ($results AS $user=>$values) {
update_query("tblhosting",array(
"diskusage"=>$values['U_DISK'],
"disklimit"=>$values['DISK_QUOTA'],
"bwusage"=>$values['U_BANDWIDTH'],
"bwlimit"=>$values['BANDWIDTH'],
"lastupdate"=>"now()",
),array("server"=>$params['serverid'], "username"=>$user));
}
}
?>
