Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,410 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Hosting Account Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 6 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Hosting\Cpanel;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hosting Account Model
|
||||
*/
|
||||
class _Account extends \IPS\nexus\Hosting\Account
|
||||
{
|
||||
/**
|
||||
* Create
|
||||
*
|
||||
* @param \IPS\nexus\Package\Hosting $package The package
|
||||
* @param \IPS\nexus\Customer $customer The customer
|
||||
* @return void
|
||||
*/
|
||||
public function create( \IPS\nexus\Package\Hosting $package, \IPS\nexus\Customer $customer )
|
||||
{
|
||||
$response = $this->server->api( 'createacct', array(
|
||||
'username' => $this->username,
|
||||
'domain' => $this->domain,
|
||||
'quota' => ( $package->quota == -1 ) ? 'unlimited' : $package->quota,
|
||||
'password' => $this->password,
|
||||
'ip' => $package->ip ? 'y' : 'n',
|
||||
'cgi' => $package->cgi,
|
||||
'frontpage' => $package->frontpage,
|
||||
'hasshell' => $package->hasshell,
|
||||
'contactemail' => $customer->email,
|
||||
'maxftp' => ( $package->maxftp == -1 ) ? 'unlimited' : $package->maxftp,
|
||||
'maxsql' => ( $package->maxsql == -1 ) ? 'unlimited' : $package->maxsql,
|
||||
'maxpop' => ( $package->maxpop == -1 ) ? 'unlimited' : $package->maxpop,
|
||||
'maxlst' => ( $package->maxlst == -1 ) ? 'unlimited' : $package->maxlst,
|
||||
'maxsub' => ( $package->maxsub == -1 ) ? 'unlimited' : $package->maxsub,
|
||||
'maxpark' => ( $package->maxpark == -1 ) ? 'unlimited' : $package->maxpark,
|
||||
'maxaddon' => ( $package->maxaddon == -1 ) ? 'unlimited' : $package->maxaddon,
|
||||
'bwlimit' => ( $package->bwlimit == -1 ) ? 'unlimited' : $package->bwlimit,
|
||||
) );
|
||||
|
||||
if ( !$response['result'][0]['status'] )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['result'][0]['statusmsg'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Account Summary
|
||||
*/
|
||||
protected $summary;
|
||||
|
||||
/**
|
||||
* Get Information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function summary()
|
||||
{
|
||||
if ( $this->summary === NULL )
|
||||
{
|
||||
$response = $this->server->api( 'accountsummary', array( 'user' => $this->username ), 15 );
|
||||
|
||||
if ( !$response['status'] )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['statusmsg'] );
|
||||
}
|
||||
|
||||
$this->summary = $response['acct'][0];
|
||||
}
|
||||
|
||||
return $this->summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get diskspace allowance (in bytes)
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function diskspaceAllowance()
|
||||
{
|
||||
$information = $this->summary();
|
||||
|
||||
return ( $information['disklimit'] === 'unlimited' ) ? NULL : ( intval( $information['disklimit'] ) * 1000000 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get diskspace currently in use (in bytes)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function diskspaceInUse()
|
||||
{
|
||||
$information = $this->summary();
|
||||
|
||||
return intval( $information['diskused'] ) * 1000000;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Bandwidth used this month
|
||||
*/
|
||||
protected $monthlyBandwidthAllowance;
|
||||
|
||||
/**
|
||||
* @brief Bandwidth used this month
|
||||
*/
|
||||
protected $bandwidthUsedThisMonth;
|
||||
|
||||
/**
|
||||
* Get bandwidth information
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function bandwidth()
|
||||
{
|
||||
$response = $this->server->api( 'showbw' );
|
||||
foreach( $response['bandwidth'][0]['acct'] as $data )
|
||||
{
|
||||
if ( $data['user'] == $this->username )
|
||||
{
|
||||
$this->monthlyBandwidthAllowance = $data['limit'] / 1048576 * 1000000;
|
||||
$this->bandwidthUsedThisMonth = $data['totalbytes'] / 1048576 * 1000000;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get monthly bandwidth allowance (in bytes)
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function monthlyBandwidthAllowance()
|
||||
{
|
||||
if ( $this->monthlyBandwidthAllowance === NULL )
|
||||
{
|
||||
$this->bandwidth();
|
||||
}
|
||||
return ( $this->monthlyBandwidthAllowance === 'unlimited' ) ? NULL : $this->monthlyBandwidthAllowance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bandwidth used this month (in bytes)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function bandwidthUsedThisMonth()
|
||||
{
|
||||
if ( $this->bandwidthUsedThisMonth === NULL )
|
||||
{
|
||||
$this->bandwidth();
|
||||
}
|
||||
return $this->bandwidthUsedThisMonth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max FTP accounts
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxFtpAccounts()
|
||||
{
|
||||
$information = $this->summary();
|
||||
return ( $information['maxftp'] === 'unlimited' ) ? NULL : $information['maxftp'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max databases
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxDatabases()
|
||||
{
|
||||
$information = $this->summary();
|
||||
return ( $information['maxsql'] === 'unlimited' ) ? NULL : $information['maxsql'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max email accounts
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxEmailAccounts()
|
||||
{
|
||||
$information = $this->summary();
|
||||
return ( $information['maxpop'] === 'unlimited' ) ? NULL : $information['maxpop'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max mailing lists
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxMailingLists()
|
||||
{
|
||||
$information = $this->summary();
|
||||
return ( $information['maxlst'] === 'unlimited' ) ? NULL : $information['maxlst'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max subdomains
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxSubdomains()
|
||||
{
|
||||
$information = $this->summary();
|
||||
return ( $information['maxsub'] === 'unlimited' ) ? NULL : $information['maxsub'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max parked domains
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxParkedDomains()
|
||||
{
|
||||
$information = $this->summary();
|
||||
return ( $information['maxparked'] === 'unlimited' ) ? NULL : $information['maxparked'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max addon domains
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxAddonDomains()
|
||||
{
|
||||
$information = $this->summary();
|
||||
return ( $information['maxaddons'] === 'unlimited' ) ? NULL : $information['maxaddons'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Has SSH access?
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function hasSSHAccess()
|
||||
{
|
||||
$information = $this->summary();
|
||||
return ( mb_substr( $information['shell'], -7 ) != 'noshell' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Control Panel Link
|
||||
*
|
||||
* @return \IPS\Http\Url
|
||||
*/
|
||||
public function controlPanelLink()
|
||||
{
|
||||
return \IPS\Http\Url::external( 'https://' . $this->server->hostname . ':2083' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Priviledges
|
||||
*
|
||||
* @param array $values Values from form
|
||||
* @return void
|
||||
*/
|
||||
public function edit( $values )
|
||||
{
|
||||
/* Init */
|
||||
$data = array(
|
||||
'user' => $this->username,
|
||||
'DNS' => $values['account_domain'],
|
||||
'QUOTA' => ( $values['p_quota'] != -1 ) ? ( $values['p_quota'] * 1000000 ) : 'unlimited',
|
||||
'MAXFTP' => ( $values['p_maxftp'] != -1 ) ? ( $values['p_maxftp'] ) : 'unlimited',
|
||||
'MAXSQL' => ( $values['p_maxsql'] != -1 ) ? ( $values['p_maxsql'] ) : 'unlimited',
|
||||
'MAXPOP' => ( $values['p_maxpop'] != -1 ) ? ( $values['p_maxpop'] ) : 'unlimited',
|
||||
'MAXLST' => ( $values['p_maxlst'] != -1 ) ? ( $values['p_maxlst'] ) : 'unlimited',
|
||||
'MAXSUB' => ( $values['p_maxsub'] != -1 ) ? ( $values['p_maxsub'] ) : 'unlimited',
|
||||
'MAXPARK' => ( $values['p_maxpark'] != -1 ) ? ( $values['p_maxpark'] ) : 'unlimited',
|
||||
'MAXADDON' => ( $values['p_maxaddon'] != -1 ) ? ( $values['p_maxaddon'] ) : 'unlimited',
|
||||
'HASSHELL' => intval( $values['p_hasshell'] )
|
||||
);
|
||||
|
||||
/* Making quota or bandwidth unlimited? */
|
||||
if ( $values['p_quota'] == -1 )
|
||||
{
|
||||
$data['QUOTA'] = 'unlimited';
|
||||
}
|
||||
if ( $values['p_bwlimit'] == -1 )
|
||||
{
|
||||
$data['BWLIMIT'] = 'unlimited';
|
||||
}
|
||||
|
||||
/* Has the username changed? */
|
||||
if ( $values['account_username'] != $this->username )
|
||||
{
|
||||
$data['newuser'] = $values['account_username'];
|
||||
}
|
||||
|
||||
/* Send */
|
||||
$response = $this->server->api( 'modifyacct', $data );
|
||||
if( !$response['result'][0]['status'] )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['result'][0]['statusmsg'] );
|
||||
}
|
||||
|
||||
/* Change quota? */
|
||||
if ( $values['p_quota'] != -1 and ( $this->diskspaceAllowance() === NULL or $values['p_quota'] * 1000000 != $this->diskspaceAllowance() ) )
|
||||
{
|
||||
$response = $this->server->api( 'editquota', array( 'user' => $values['account_username'], 'quota' => $values['p_quota'] ) );
|
||||
if( !$response['result'][0]['status'] )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['result'][0]['statusmsg'] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Change bandwidth limit? */
|
||||
if ( ( $values['p_bwlimit'] != -1 and ( $this->monthlyBandwidthAllowance() === NULL or $values['p_bwlimit'] * 1000000 != $this->monthlyBandwidthAllowance() ) ) or ( $values['p_bwlimit'] != -1 and $this->monthlyBandwidthAllowance() !== NULL ) )
|
||||
{
|
||||
$this->changeBandwidthLimit( $values['p_bwlimit'] * 1000000, $values['account_username'] );
|
||||
}
|
||||
|
||||
/* Change password? */
|
||||
if ( $values['account_password'] != (string) $this->password )
|
||||
{
|
||||
$this->changePassword( $values['account_password'], $values['account_username'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change bandwidth limit
|
||||
*
|
||||
* @param float $newLimit New Limit (in bytes)
|
||||
* @param string|NULL $username Username. Only needed if has been changed on server but not locally
|
||||
* @return void
|
||||
*/
|
||||
public function changeBandwidthLimit( $newLimit, $username = NULL )
|
||||
{
|
||||
$response = $this->server->api( 'limitbw', array( 'user' => $username ?: $this->username, 'bwlimit' => floor( $newLimit / 1000000 ) ) );
|
||||
if( !$response['result'][0]['status'] )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['result'][0]['statusmsg'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Password
|
||||
*
|
||||
* @param string $newPassword New Password
|
||||
* @param string|NULL $username Username. Only needed if has been changed on server but not locally
|
||||
* @return void
|
||||
*/
|
||||
public function changePassword( $newPassword, $username = NULL )
|
||||
{
|
||||
$response = $this->server->api( 'passwd', array( 'user' => $username ?: $this->username, 'pass' => $newPassword ) );
|
||||
if( !$response['passwd'][0]['status'] )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['passwd'][0]['statusmsg'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function suspend()
|
||||
{
|
||||
$response = $this->server->api( 'suspendacct', array( 'user' => $this->username ) );
|
||||
if( !$response['result'][0]['status'] )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['result'][0]['statusmsg'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsuspend
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsuspend()
|
||||
{
|
||||
$response = $this->server->api( 'unsuspendacct', array( 'user' => $this->username ) );
|
||||
if( !$response['result'][0]['status'] )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['result'][0]['statusmsg'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function terminate()
|
||||
{
|
||||
$response = $this->server->api( 'removeacct', array( 'user' => $this->username ) );
|
||||
if( !$response['result'][0]['status'] )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['result'][0]['statusmsg'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief CPanel/WHM Server Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage Nexus
|
||||
* @since 6 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Hosting\Cpanel;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* CPanel/WHM Server Model
|
||||
*/
|
||||
class _Server extends \IPS\nexus\Hosting\Server
|
||||
{
|
||||
/**
|
||||
* Additional fields for the server form
|
||||
*
|
||||
* @param \IPS\nexus\Hosting\Server $server The server bring edited
|
||||
* @return array
|
||||
*/
|
||||
public static function extraFormFields( \IPS\nexus\Hosting\Server $server )
|
||||
{
|
||||
$class = get_class();
|
||||
return array(
|
||||
'server_cpanel_username' => new \IPS\Helpers\Form\Text( 'server_cpanel_username', $server->username ?: 'root', NULL, array(), function( $val )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->server_type == 'cpanel' )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, NULL, 'server_cpanel_username' ),
|
||||
'server_cpanel_key' => new \IPS\Helpers\Form\TextArea( 'server_cpanel_key', $server->access, NULL, array( 'rows' => 20 ), function( $val ) use ( $class )
|
||||
{
|
||||
if ( \IPS\Request::i()->server_type == 'cpanel' )
|
||||
{
|
||||
if ( !$val )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
else
|
||||
{
|
||||
$server = new $class;
|
||||
$server->hostname = \IPS\Request::i()->server_hostname;
|
||||
$server->ip = \IPS\Request::i()->server_ip;
|
||||
$server->username = \IPS\Request::i()->server_cpanel_username;
|
||||
$server->access = $val;
|
||||
$server->extra = array( 'call' => \IPS\Request::i()->server_cpanel_call );
|
||||
|
||||
try
|
||||
{
|
||||
$response = $server->api( 'gethostname' );
|
||||
}
|
||||
catch ( \IPS\nexus\Hosting\Exception $e )
|
||||
{
|
||||
throw new \DomainException( $e->getMessage() );
|
||||
}
|
||||
|
||||
if ( $response['hostname'] !== $server->hostname )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'server_cpanel_key_hostname_err', FALSE, array( 'sprintf' => array( $response['hostname'] ) ) ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}, NULL, NULL, 'server_cpanel_key' ),
|
||||
'server_cpanel_call' => new \IPS\Helpers\Form\Radio( 'server_cpanel_call', isset( $server->extra['call'] ) ? $server->extra['call'] : 'hostname', NULL, array( 'options' => array( 'hostname' => 'server_hostname', 'ip' => 'server_ip' ) ), NULL, NULL, NULL, 'server_cpanel_call' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public static function _formatFormValues( $values )
|
||||
{
|
||||
if( isset( $values['server_cpanel_username'] ) )
|
||||
{
|
||||
$values['server_username'] = $values['server_cpanel_username'];
|
||||
unset( $values['server_cpanel_username'] );
|
||||
}
|
||||
|
||||
if( isset( $values['server_cpanel_key'] ) )
|
||||
{
|
||||
$values['server_access'] = trim( $values['server_cpanel_key'] );
|
||||
unset( $values['server_cpanel_key'] );
|
||||
}
|
||||
|
||||
if( isset( $values['server_cpanel_call'] ) )
|
||||
{
|
||||
$values['extra'] = array( 'call' => $values['server_cpanel_call'] );
|
||||
unset( $values['server_cpanel_call'] );
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if username is acceptable
|
||||
*
|
||||
* @param string $username The username to check
|
||||
* @return bool
|
||||
*/
|
||||
public function checkUsername( $username )
|
||||
{
|
||||
if (
|
||||
in_array( $username, array( 'root', 'virtfs', 'roundcube', 'horde', 'spamassassin', 'eximstats', 'cphulkd', 'modsec', 'all', 'dovecot', 'tomcat', 'postgres', 'mailman', 'proftpd', 'cpbackup', 'files', 'dirs', 'tmp', 'toor', 'munin' ) )
|
||||
OR mb_substr( $username, 0, 4 ) == 'test'
|
||||
OR mb_substr( $username, -7 ) == 'assword'
|
||||
) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* List Accounts
|
||||
*
|
||||
* @return array 'username' => array( 'domain' => 'example.com', 'disklimit' => 100000, 'diskused' => 50000, 'active' => TRUE )
|
||||
*/
|
||||
public function listAccounts()
|
||||
{
|
||||
$return = array();
|
||||
|
||||
$response = $this->api( 'listaccts' );
|
||||
if( !$response['status'] )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['statusmsg'] );
|
||||
}
|
||||
|
||||
foreach ( $response['acct'] as $account )
|
||||
{
|
||||
$return[ $account['user'] ] = array(
|
||||
'domain' => $account['domain'],
|
||||
'disklimit' => intval( str_replace( 'M', '', $account['disklimit'] ) ) * 1000000,
|
||||
'diskused' => intval( str_replace( 'M', '', $account['diskused'] ) ) * 1000000,
|
||||
'active' => !$account['suspended'],
|
||||
);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reboot Server
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reboot()
|
||||
{
|
||||
$this->api( 'reboot' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry Error
|
||||
*
|
||||
* @param array $details Details
|
||||
* @return void
|
||||
*/
|
||||
public function retryError( $details )
|
||||
{
|
||||
$response = $this->api( $details['function'], $details['params'] );
|
||||
|
||||
if ( isset( $response['result'][0] ) and !$response['result'][0]['status'] )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, $response['result'][0]['statusmsg'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API Call
|
||||
*
|
||||
* @param string $function Function Name
|
||||
* @param array $params Parameters to send
|
||||
* @param int $timeout Timeout limit
|
||||
* @return void
|
||||
*/
|
||||
public function api( $function, $params=array(), $timeout=90 )
|
||||
{
|
||||
$this->lastCallData = array( 'function' => $function, 'params' => $params );
|
||||
|
||||
$apiCall = isset( $this->extra['call'] ) ? str_replace( 'server_', '', $this->extra['call'] ) : 'ip';
|
||||
|
||||
try
|
||||
{
|
||||
$response = \IPS\Http\Url::external( 'https://' . $this->$apiCall . ':2087/json-api/' . $function )
|
||||
->setQueryString( $params )
|
||||
->request( $timeout )
|
||||
->setHeaders( array( 'Authorization' => "WHM {$this->username}:" . preg_replace( "'(\r|\n)'", '', $this->access ) ) )
|
||||
->get()
|
||||
->decodeJson();
|
||||
|
||||
if ( isset( $response['error'] ) )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, $response['error'] );
|
||||
}
|
||||
elseif ( isset( $response['cpanelresult']['error'] ) )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, $response['cpanelresult']['error'] );
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, $e->getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user