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,435 @@
|
||||
<?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;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Account Account Model
|
||||
*/
|
||||
class _Account extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
/* !ActiveRecord */
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_hosting_accounts';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'ps_id';
|
||||
|
||||
/**
|
||||
* Construct ActiveRecord from database row
|
||||
*
|
||||
* @param array $data Row from database table
|
||||
* @param bool $updateMultitonStoreIfExists Replace current object in multiton store if it already exists there?
|
||||
* @return static
|
||||
*/
|
||||
public static function constructFromData( $data, $updateMultitonStoreIfExists = TRUE )
|
||||
{
|
||||
/* Initiate an object */
|
||||
$classname = 'IPS\\nexus\Hosting\\' . ucfirst( \IPS\nexus\Hosting\Server::load( $data['account_server'] )->type ) . '\\Account';
|
||||
$obj = new $classname;
|
||||
$obj->_new = FALSE;
|
||||
|
||||
/* Import data */
|
||||
foreach ( $data as $k => $v )
|
||||
{
|
||||
if( static::$databasePrefix )
|
||||
{
|
||||
$k = \substr( $k, \strlen( static::$databasePrefix ) );
|
||||
}
|
||||
|
||||
$obj->_data[ $k ] = $v;
|
||||
}
|
||||
$obj->changed = array();
|
||||
|
||||
/* Return */
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Default Values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
{
|
||||
/* Set a random password */
|
||||
$password = '';
|
||||
foreach ( range( 1, 12 ) as $j )
|
||||
{
|
||||
do
|
||||
{
|
||||
$chr = rand( 33, 122 );
|
||||
}
|
||||
while ( in_array( $chr, array( 34, 37, 38, 39, 44, 46, 47, 58, 59, 60, 61, 62, 64, 91, 92, 93, 94, 96 ) ) );
|
||||
|
||||
$password .= chr( $chr );
|
||||
}
|
||||
$this->password = $password;
|
||||
|
||||
/* By default the account exists */
|
||||
$this->exists = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Server
|
||||
*
|
||||
* @param \IPS\nexus\Hosting\Server $server The server
|
||||
* @return void
|
||||
*/
|
||||
public function set_server( \IPS\nexus\Hosting\Server $server )
|
||||
{
|
||||
$this->_data['account_server'] = $server->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Server
|
||||
*
|
||||
* @return \IPS\nexus\Hosting\Server
|
||||
*/
|
||||
public function get_server()
|
||||
{
|
||||
return \IPS\nexus\Hosting\Server::load( $this->_data['account_server'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Domain
|
||||
*
|
||||
* @param string $domain The domain
|
||||
* @return void
|
||||
*/
|
||||
public function set_domain( $domain )
|
||||
{
|
||||
$this->_data['account_domain'] = $domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Domain
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_domain()
|
||||
{
|
||||
return $this->_data['account_domain'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Username
|
||||
*
|
||||
* @param string $username The username
|
||||
* @return void
|
||||
*/
|
||||
public function set_username( $username )
|
||||
{
|
||||
$this->_data['account_username'] = $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Username
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_username()
|
||||
{
|
||||
return $this->_data['account_username'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Password
|
||||
*
|
||||
* @param string $password The password
|
||||
* @return void
|
||||
*/
|
||||
public function set_password( $password )
|
||||
{
|
||||
$this->_data['account_password'] = \IPS\Text\Encrypt::fromPlaintext( $password )->tag();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Password
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_password()
|
||||
{
|
||||
return \IPS\Text\Encrypt::fromTag( $this->_data['account_password'] )->decrypt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set If Account Exists
|
||||
*
|
||||
* @param bool $exists If the account exists
|
||||
* @return void
|
||||
*/
|
||||
public function set_exists( $exists )
|
||||
{
|
||||
$this->_data['account_exists'] = intval( $exists );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get If Account Exists
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function get_exists()
|
||||
{
|
||||
return (bool) $this->_data['account_exists'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Purchase
|
||||
*
|
||||
* @return \IPS\nexus\Purchase
|
||||
*/
|
||||
public function purchase()
|
||||
{
|
||||
return \IPS\nexus\Purchase::load( $this->_data['ps_id'] );
|
||||
}
|
||||
|
||||
/* !Account */
|
||||
|
||||
/**
|
||||
* Get FTP Link
|
||||
*
|
||||
* @return \IPS\Http\Url
|
||||
*/
|
||||
public function ftpLink()
|
||||
{
|
||||
return \IPS\Http\Url::external( 'ftp://' . $this->username . ':' . urlencode( $this->password ) . '@' . $this->server->hostname );
|
||||
}
|
||||
|
||||
/* !abstract */
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get diskspace allowance (in bytes)
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function diskspaceAllowance()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get diskspace currently in use (in bytes)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function diskspaceInUse()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get monthly bandwidth allowance (in bytes)
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function monthlyBandwidthAllowance()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bandwidth used this month (in bytes)
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function bandwidthUsedThisMonth()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max FTP accounts
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxFtpAccounts()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max databases
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxDatabases()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max email accounts
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxEmailAccounts()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max mailing lists
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxMailingLists()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max subdomains
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxSubdomains()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max parked domains
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxParkedDomains()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max addon domains
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function maxAddonDomains()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Has SSH access?
|
||||
*
|
||||
* @return int|NULL
|
||||
*/
|
||||
public function hasSSHAccess()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Control Panel Link
|
||||
*
|
||||
* @return \IPS\Http\Url
|
||||
*/
|
||||
public function controlPanelLink()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit Priviledges
|
||||
*
|
||||
* @param array $values Values from form
|
||||
* @return void
|
||||
*/
|
||||
public function edit( $values )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function suspend()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsuspend
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsuspend()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function terminate()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Expected Output Monitoring Rule
|
||||
* @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 12 Sep 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Hosting;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expected Output Monitoring Rule
|
||||
*/
|
||||
class _EOM extends \IPS\Node\Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_eom';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'eom_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'expected_output_monitoring';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
* @code
|
||||
array(
|
||||
'app' => 'core', // The application key which holds the restrictrions
|
||||
'module' => 'foo', // The module key which holds the restrictions
|
||||
'map' => array( // [Optional] The key for each restriction - can alternatively use "prefix"
|
||||
'add' => 'foo_add',
|
||||
'edit' => 'foo_edit',
|
||||
'permissions' => 'foo_perms',
|
||||
'delete' => 'foo_delete'
|
||||
),
|
||||
'all' => 'foo_manage', // [Optional] The key to use for any restriction not provided in the map (only needed if not providing all 4)
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
'app' => 'nexus',
|
||||
'module' => 'hosting',
|
||||
'prefix' => 'monitoring_eom_'
|
||||
);
|
||||
|
||||
/**
|
||||
* Get title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get__title()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'eom_url', $this->url, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'eom_type', $this->type, TRUE, array( 'options' => array( 'c' => 'eom_type_c', 'e' => 'eom_type_e', 'n' => 'eom_type_n' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\TextArea( 'eom_value', $this->value, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'eom_notify', json_decode( $this->notify, TRUE ), TRUE ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
{
|
||||
if( isset( $values['eom_notify'] ) )
|
||||
{
|
||||
$values['eom_notify'] = json_encode( $values['eom_notify'] );
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Perform actions after saving the form
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return void
|
||||
*/
|
||||
public function postSaveForm( $values )
|
||||
{
|
||||
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 1 ), "`key`='expectedOutputMonitoring'" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Hosting Exception
|
||||
* @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 11 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\Hosting;
|
||||
|
||||
/* 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 Exception
|
||||
*/
|
||||
class _Exception extends \RuntimeException
|
||||
{
|
||||
/**
|
||||
* @brief Time
|
||||
*/
|
||||
protected $time;
|
||||
|
||||
/**
|
||||
* @brief Server
|
||||
*/
|
||||
protected $server;
|
||||
|
||||
/**
|
||||
* @brief Details
|
||||
*/
|
||||
protected $details;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \IPS\nexus\Hosting\Server $server Server
|
||||
* @param string $message Message
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( \IPS\nexus\Hosting\Server $server, $message )
|
||||
{
|
||||
$this->time = new \IPS\DateTime;
|
||||
$this->server = $server;
|
||||
$this->details = $server->lastCallData;
|
||||
|
||||
return parent::__construct( $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Log
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function log()
|
||||
{
|
||||
if ( \IPS\Settings::i()->nexus_hosting_error_emails )
|
||||
{
|
||||
\IPS\Email::buildFromTemplate( 'nexus', 'hostingError', array( $this->server, $this->getMessage(), \IPS\Http\Url::internal( '&app=nexus&module=hosting&controller=errors', 'admin' )->stripQueryString('adsess') ) )->send( explode( ',', \IPS\Settings::i()->nexus_hosting_error_emails ) );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'nexus_hosting_errors', array(
|
||||
'e_time' => $this->time->getTimestamp(),
|
||||
'e_server' => $this->server->id,
|
||||
'e_message' => $this->getMessage(),
|
||||
'e_extra' => json_encode( $this->details )
|
||||
) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Dummy 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\None;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy Server Model
|
||||
*/
|
||||
class _Server extends \IPS\nexus\Hosting\Server
|
||||
{
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Hosting Queue 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;
|
||||
|
||||
/* 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 Queue Model
|
||||
*/
|
||||
class _Queue extends \IPS\Node\Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_hosting_queues';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'queue_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'name';
|
||||
|
||||
/**
|
||||
* @brief [Node] Sortable?
|
||||
*/
|
||||
public static $nodeSortable = FALSE;
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'menu__nexus_hosting_queues';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
* @code
|
||||
array(
|
||||
'app' => 'core', // The application key which holds the restrictrions
|
||||
'module' => 'foo', // The module key which holds the restrictions
|
||||
'map' => array( // [Optional] The key for each restriction - can alternatively use "prefix"
|
||||
'add' => 'foo_add',
|
||||
'edit' => 'foo_edit',
|
||||
'permissions' => 'foo_perms',
|
||||
'delete' => 'foo_delete'
|
||||
),
|
||||
'all' => 'foo_manage', // [Optional] The key to use for any restriction not provided in the map (only needed if not providing all 4)
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
'app' => 'nexus',
|
||||
'module' => 'hosting',
|
||||
'prefix' => 'queues_'
|
||||
);
|
||||
|
||||
/**
|
||||
* Get all queues
|
||||
*
|
||||
* @return \IPS\Patterns\ActiveRecordIterator
|
||||
*/
|
||||
public static function queues()
|
||||
{
|
||||
return new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_hosting_queues', NULL, 'queue_name' ), 'IPS\nexus\Hosting\Queue' );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'queue_name', $this->name, TRUE ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get__title()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Active Server
|
||||
*
|
||||
* @return \IPS\nexus\Hosting\Server
|
||||
* @throws \UnderflowException
|
||||
*/
|
||||
public function activeServer()
|
||||
{
|
||||
$where = array();
|
||||
$where[] = array( \IPS\Db::i()->findInSet( 'server_queues', array( $this->id ) ) );
|
||||
if ( !\IPS\IN_DEV )
|
||||
{
|
||||
$where[] = array( 'server_type<>?', 'none' );
|
||||
}
|
||||
|
||||
$serverData = \IPS\Db::i()->select( 'nexus_hosting_servers.*, COUNT(nexus_hosting_accounts.ps_id) AS accounts', 'nexus_hosting_servers', $where, 'accounts ASC', NULL, 'server_id' )->join( 'nexus_hosting_accounts', 'account_server=server_id AND account_exists=1' )->first();
|
||||
unset( $serverData['accounts'] );
|
||||
|
||||
return \IPS\nexus\Hosting\Server::constructFromData( $serverData );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Hosting 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;
|
||||
|
||||
/* 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 Server Model
|
||||
*/
|
||||
class _Server extends \IPS\Node\Model
|
||||
{
|
||||
/* !ActiveRecord */
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_hosting_servers';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'server_';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Fields
|
||||
*/
|
||||
protected static $databaseIdFields = array( 'server_hostname', 'server_dedicated' );
|
||||
|
||||
/**
|
||||
* Construct ActiveRecord from database row
|
||||
*
|
||||
* @param array $data Row from database table
|
||||
* @param bool $updateMultitonStoreIfExists Replace current object in multiton store if it already exists there?
|
||||
* @return static
|
||||
*/
|
||||
public static function constructFromData( $data, $updateMultitonStoreIfExists = TRUE )
|
||||
{
|
||||
/* Initiate an object */
|
||||
$classname = 'IPS\\nexus\Hosting\\' . ucfirst( $data['server_type'] ) . '\\Server';
|
||||
$obj = new $classname;
|
||||
$obj->_new = FALSE;
|
||||
|
||||
/* Import data */
|
||||
foreach ( $data as $k => $v )
|
||||
{
|
||||
if( static::$databasePrefix )
|
||||
{
|
||||
$k = \substr( $k, \strlen( static::$databasePrefix ) );
|
||||
}
|
||||
|
||||
$obj->_data[ $k ] = $v;
|
||||
}
|
||||
$obj->changed = array();
|
||||
|
||||
/* Return */
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get__title()
|
||||
{
|
||||
return $this->hostname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extra information
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_extra()
|
||||
{
|
||||
return isset( $this->_data['extra'] ) ? json_decode( $this->_data['extra'], TRUE ) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set extra information
|
||||
*
|
||||
* @param mixed $extra The data
|
||||
* @return void
|
||||
*/
|
||||
public function set_extra( $extra )
|
||||
{
|
||||
$this->_data['extra'] = json_encode( $extra );
|
||||
}
|
||||
|
||||
/* !Node */
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'menu__nexus_hosting_servers';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
* @code
|
||||
array(
|
||||
'app' => 'core', // The application key which holds the restrictrions
|
||||
'module' => 'foo', // The module key which holds the restrictions
|
||||
'map' => array( // [Optional] The key for each restriction - can alternatively use "prefix"
|
||||
'add' => 'foo_add',
|
||||
'edit' => 'foo_edit',
|
||||
'permissions' => 'foo_perms',
|
||||
'delete' => 'foo_delete'
|
||||
),
|
||||
'all' => 'foo_manage', // [Optional] The key to use for any restriction not provided in the map (only needed if not providing all 4)
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
'app' => 'nexus',
|
||||
'module' => 'hosting',
|
||||
'prefix' => 'servers_'
|
||||
);
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
{
|
||||
$types = array();
|
||||
$extraFields = array();
|
||||
$toggles = array();
|
||||
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Hosting' ) as $file )
|
||||
{
|
||||
if ( !$file->isDot() and mb_substr( $file, 0, 1 ) !== '.' and $file->isDir() )
|
||||
{
|
||||
$types[ mb_strtolower( $file ) ] = 'nexus_server_' . $file;
|
||||
|
||||
$class = 'IPS\nexus\Hosting\\' . ucfirst( $file ) . '\Server';
|
||||
$extraFields[ mb_strtolower( mb_substr( $file, 0, -4 ) ) ] = $class::extraFormFields( $this );
|
||||
$toggles[ mb_strtolower( $file ) ] = array_keys( $extraFields[ mb_strtolower( mb_substr( $file, 0, -4 ) ) ] );
|
||||
}
|
||||
}
|
||||
|
||||
$form->addHeader( 'server_type' );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'server_type', $this->type, TRUE, array( 'options' => $types, 'toggles' => $toggles ) ) );
|
||||
foreach ( $extraFields as $type => $fields )
|
||||
{
|
||||
foreach ( $fields as $id => $field )
|
||||
{
|
||||
$form->add( $field );
|
||||
}
|
||||
}
|
||||
$form->addHeader( 'server_network_information' );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'server_hostname', $this->hostname, TRUE, array( 'placeholder' => 'server.example.net' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'server_ip', $this->ip, TRUE, array( 'placeholder' => '123.456.789.000' ), function( $val )
|
||||
{
|
||||
if ( !filter_var( $val, FILTER_VALIDATE_IP ) )
|
||||
{
|
||||
throw new \DomainException('form_bad_value');
|
||||
}
|
||||
} ) );
|
||||
$form->addHeader( 'server_accounts' );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'server_queues', explode( ',', $this->queues ), FALSE, array( 'class' => 'IPS\nexus\Hosting\Queue', 'multiple' => TRUE ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'server_max_accounts', $this->id ? $this->max_accounts : 0, FALSE, array( 'unlimited' => 0 ) ) );
|
||||
$nameservers = $this->nameservers ? explode( ',', $this->nameservers ) : array();
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'server_nameservers_default', count( $nameservers ) ? 0 : 1, FALSE, array( 'options' => array( 1 => 'server_nameservers_default_yes', 0 => 'server_nameservers_default_no' ), 'toggles' => array( 0 => array( 'server_nameservers' ) ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'server_nameservers', $nameservers, NULL, array( 'placeholder' => 'ns.example.net' ), NULL, NULL, NULL, 'server_nameservers' ) );
|
||||
$form->addHeader( 'server_reporting' );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'server_monitor_on', \IPS\Settings::i()->monitoring_script and $this->monitor, FALSE, array( 'disabled' => !\IPS\Settings::i()->monitoring_script, 'togglesOn' => array( 'server_monitor' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'server_monitor', $this->monitor, NULL, array( 'placeholder' => 'http://server.example.net/monitor_remote.php' ), function( $val )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->sever_monitor_on )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, NULL, 'server_monitor' ) );
|
||||
$currencies = \IPS\nexus\Money::currencies();
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'server_cost', $this->cost, FALSE, array(), NULL, NULL, array_shift( $currencies ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
{
|
||||
if( isset( $values['server_queues'] ) )
|
||||
{
|
||||
$values['server_queues'] = is_array( $values['server_queues'] ) ? implode( ',', array_keys( $values['server_queues'] ) ) : NULL;
|
||||
}
|
||||
|
||||
if( isset( $values['server_nameservers'] ) )
|
||||
{
|
||||
$values['server_nameservers'] = implode( ',', $values['server_nameservers'] );
|
||||
}
|
||||
|
||||
unset( $values['server_nameservers_default'] );
|
||||
unset( $values['server_monitor_on'] );
|
||||
|
||||
$values = call_user_func( array( 'IPS\nexus\Hosting\\' . ucfirst( $values['server_type'] ) . '\Server', '_formatFormValues' ), $values );
|
||||
|
||||
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Hosting' ) as $file )
|
||||
{
|
||||
if ( !$file->isDot() and mb_substr( $file, 0, 1 ) !== '.' and $file->isDir() )
|
||||
{
|
||||
$class = 'IPS\nexus\Hosting\\' . ucfirst( $file ) . '\Server';
|
||||
foreach ( array_keys( $class::extraFormFields( $this ) ) as $k )
|
||||
{
|
||||
unset( $values[ $k ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public static function _formatFormValues( $values )
|
||||
{
|
||||
return $values;
|
||||
}
|
||||
|
||||
/* !Server */
|
||||
|
||||
/**
|
||||
* Last API call data
|
||||
*/
|
||||
public $lastCallData;
|
||||
|
||||
/**
|
||||
* Get nameservers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function nameservers()
|
||||
{
|
||||
return explode( ',', $this->nameservers ?: \IPS\Settings::i()->nexus_hosting_nameservers );
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitoring: Server Online
|
||||
*
|
||||
* @param mixed $version Version number returned from script
|
||||
* @return void
|
||||
*/
|
||||
public function monitoringOnline( $version )
|
||||
{
|
||||
foreach ( explode( ',', \IPS\Settings::i()->monitoring_alert ) as $address )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_online', array( $this, urlencode( $address ) ) );
|
||||
$email->send( $address );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitoring: Server Offline
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function monitoringOffline()
|
||||
{
|
||||
foreach ( explode( ',', \IPS\Settings::i()->monitoring_alert ) as $address )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_offline', array( $this, urlencode( $address ) ) );
|
||||
$email->send( $address );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitoring: Server Offline - Second Notification
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function monitoringPanic()
|
||||
{
|
||||
foreach ( explode( ',', \IPS\Settings::i()->monitoring_alert ) as $address )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_panic', array( $this, urlencode( $address ) ) );
|
||||
$email->send( $address );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitoring: Server Reset
|
||||
*
|
||||
* @param string $by Email address
|
||||
* @return void
|
||||
*/
|
||||
public function monitoringAcknowledged( $by )
|
||||
{
|
||||
foreach ( explode( ',', \IPS\Settings::i()->monitoring_alert ) as $address )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_acknowledged', array( $this, urlencode( $address ), $by ) );
|
||||
$email->send( $address );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitoring: Server Reset
|
||||
*
|
||||
* @param string $by Email address
|
||||
* @return void
|
||||
*/
|
||||
public function monitoringReset( $by )
|
||||
{
|
||||
foreach ( explode( ',', \IPS\Settings::i()->monitoring_alert ) as $address )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_reset', array( $this, urlencode( $address ), $by ) );
|
||||
$email->send( $address );
|
||||
}
|
||||
}
|
||||
|
||||
/* !abstract */
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if username is acceptable
|
||||
*
|
||||
* @param string $username The username to check
|
||||
* @return bool
|
||||
*/
|
||||
public function checkUsername( $username )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* List Accounts
|
||||
*
|
||||
* @return array 'username' => array( 'domain' => 'example.com', 'disklimit' => 100000, 'diskused' => 50000, 'active' => TRUE )
|
||||
*/
|
||||
public function listAccounts()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Reboot Server
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reboot()
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry Error
|
||||
*
|
||||
* @param array $details Details
|
||||
* @return void
|
||||
*/
|
||||
public function retryError( $details )
|
||||
{
|
||||
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user