Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+28 -5
View File
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 6 Aug 2014
* @version SVN_VERSION_NUMBER
@@ -80,13 +80,13 @@ class _Account extends \IPS\Patterns\ActiveRecord
{
/* Set a random password */
$password = '';
foreach ( range( 1, 12 ) as $j )
foreach ( range( 1, 20 ) 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 ) ) );
while ( in_array( $chr, array( 38, 43, 47, 64, 92, 93, 94 ) ) );
$password .= chr( $chr );
}
@@ -125,7 +125,7 @@ class _Account extends \IPS\Patterns\ActiveRecord
*/
public function set_domain( $domain )
{
$this->_data['account_domain'] = $domain;
$this->_data['account_domain'] = mb_strtolower( $domain );
}
/**
@@ -367,6 +367,18 @@ class _Account extends \IPS\Patterns\ActiveRecord
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
}
/**
* Change Domain
*
* @param string $domain New Domain
* @param bool $keepOld If true, will park this domain, keeping the old domain as the main domain (rather than just changing the main domain)
* @return void
*/
public function changeDomain( $domain, $park=FALSE )
{
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
}
/**
* Edit Priviledges
*
@@ -402,6 +414,17 @@ class _Account extends \IPS\Patterns\ActiveRecord
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
}
/**
* Park a domain
*
* @param string $domain Domain to be parked
* @return void
*/
public function parkDomain( $domain )
{
throw new \IPS\nexus\Hosting\Exception( $this, 'DUMMY_SERVER' );
}
/**
* Suspend
*
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 6 Aug 2014
* @version SVN_VERSION_NUMBER
@@ -36,7 +36,7 @@ class _Account extends \IPS\nexus\Hosting\Account
$response = $this->server->api( 'createacct', array(
'username' => $this->username,
'domain' => $this->domain,
'quota' => ( $package->quota == -1 ) ? 'unlimited' : $package->quota,
'quota' => ( $package->quota == -1 ) ? 'unlimited' : floor( $package->quota * 1.024 ),
'password' => $this->password,
'ip' => $package->ip ? 'y' : 'n',
'cgi' => $package->cgi,
@@ -50,7 +50,7 @@ class _Account extends \IPS\nexus\Hosting\Account
'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,
'bwlimit' => ( $package->bwlimit == -1 ) ? 'unlimited' : floor( $package->bwlimit * 1.024 ),
) );
if ( !$response['result'][0]['status'] )
@@ -95,7 +95,7 @@ class _Account extends \IPS\nexus\Hosting\Account
{
$information = $this->summary();
return ( $information['disklimit'] === 'unlimited' ) ? NULL : ( intval( $information['disklimit'] ) * 1000000 );
return ( $information['disklimit'] === 'unlimited' ) ? NULL : ( intval( $information['disklimit'] ) * 1048576 );
}
/**
@@ -107,7 +107,7 @@ class _Account extends \IPS\nexus\Hosting\Account
{
$information = $this->summary();
return intval( $information['diskused'] ) * 1000000;
return intval( $information['diskused'] ) * 1048576;
}
/**
@@ -132,8 +132,8 @@ class _Account extends \IPS\nexus\Hosting\Account
{
if ( $data['user'] == $this->username )
{
$this->monthlyBandwidthAllowance = $data['limit'] / 1048576 * 1000000;
$this->bandwidthUsedThisMonth = $data['totalbytes'] / 1048576 * 1000000;
$this->monthlyBandwidthAllowance = $data['limit'];
$this->bandwidthUsedThisMonth = $data['totalbytes'];
break;
}
}
@@ -265,6 +265,29 @@ class _Account extends \IPS\nexus\Hosting\Account
return \IPS\Http\Url::external( 'https://' . $this->server->hostname . ':2083' );
}
/**
* Change Domain
*
* @param string $domain New Domain
* @param bool $keepOld If true, will park this domain, keeping the old domain as the main domain (rather than just changing the main domain)
* @return void
*/
public function changeDomain( $domain, $park=FALSE )
{
if ( $park )
{
return $this->parkDomain( $domain );
}
else
{
$response = $this->server->api( 'modifyacct', array( 'user' => $this->username, 'DNS' => $domain ) );
if( !$response['result'][0]['status'] )
{
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['result'][0]['statusmsg'] );
}
}
}
/**
* Edit Priviledges
*
@@ -274,63 +297,52 @@ class _Account extends \IPS\nexus\Hosting\Account
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'] )
);
$data = array( 'user' => $this->username );
/* Making quota or bandwidth unlimited? */
if ( $values['p_quota'] == -1 )
/* Set data */
foreach ( array( 'DNS' => 'account_domain', 'QUOTA' => 'p_quota', 'MAXFTP' => 'p_maxftp', 'MAXSQL' => 'p_maxsql', 'MAXPOP' => 'p_maxpop', 'MAXLST' => 'p_maxlst', 'MAXSUB' => 'p_maxsub', 'MAXPARK' => 'p_maxpark', 'MAXADDON' => 'p_maxaddon', 'HASSHELL' => 'p_hasshell' ) as $cpanelKey => $formKey )
{
$data['QUOTA'] = 'unlimited';
}
if ( $values['p_bwlimit'] == -1 )
{
$data['BWLIMIT'] = 'unlimited';
}
if ( isset( $values[ $formKey ] ) )
{
if ( $values[ $formKey ] == -1 )
{
$values[ $formKey ] = 'unlimited';
}
elseif ( $cpanelKey === 'QUOTA' )
{
$values[ $formKey ] = $values[ $formKey ] * 1048576 * 1.024;
}
$data[ $cpanelKey ] = $values[ $formKey ];
}
}
/* Has the username changed? */
if ( $values['account_username'] != $this->username )
if ( isset( $values['account_username'] ) AND $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 ) )
if ( isset( $values['p_bwlimit'] ) )
{
$this->changeBandwidthLimit( $values['p_bwlimit'] * 1000000, $values['account_username'] );
if ( ( $values['p_bwlimit'] == -1 and $this->monthlyBandwidthAllowance() !== NULL ) or ( $values['p_bwlimit'] != -1 and $values['p_bwlimit'] != ( $this->monthlyBandwidthAllowance() / 1048576 / 1.024 ) ) )
{
$this->changeBandwidthLimit( $values['p_bwlimit'] * 1048576 / 1.024, $values['account_username'] );
}
}
/* Change password? */
if ( $values['account_password'] != (string) $this->password )
if ( isset( $values['account_password'] ) and $values['account_password'] != (string) $this->password )
{
$this->changePassword( $values['account_password'], $values['account_username'] );
$this->changePassword( $values['account_password'], $this->username );
}
}
@@ -366,6 +378,27 @@ class _Account extends \IPS\nexus\Hosting\Account
}
}
/**
* Park a domain
*
* @param string $domain Domain to be parked
* @return void
*/
public function parkDomain( $domain )
{
$response = $this->server->api( 'cpanel', array(
'cpanel_jsonapi_user' => $this->username,
'cpanel_jsonapi_apiversion' => 2,
'cpanel_jsonapi_module' => 'Park',
'cpanel_jsonapi_func' => 'park',
'domain' => $domain
) );
if( !$response['cpanelresult']['data'][0]['result'] )
{
throw new \IPS\nexus\Hosting\Exception( $this->server, $response['cpanelresult']['data'][0]['reason'] );
}
}
/**
* Suspend
*
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 6 Aug 2014
* @version SVN_VERSION_NUMBER
+4 -4
View File
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 12 Sep 2014
* @version SVN_VERSION_NUMBER
@@ -73,7 +73,7 @@ class _EOM extends \IPS\Node\Model
*/
public function get__title()
{
return $this->url;
return (string) $this->url;
}
/**
@@ -115,6 +115,6 @@ class _EOM extends \IPS\Node\Model
*/
public function postSaveForm( $values )
{
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 1 ), "`key`='expectedOutputMonitoring'" );
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), "`key`='expectedOutputMonitoring'" );
}
}
@@ -2,9 +2,9 @@
/**
* @brief Hosting Exception
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 11 Aug 2014
* @version SVN_VERSION_NUMBER
@@ -64,7 +64,7 @@ class _Exception extends \RuntimeException
{
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\Email::buildFromTemplate( 'nexus', 'hostingError', array( $this->server, $this->getMessage(), \IPS\Http\Url::internal( '&app=nexus&module=hosting&controller=errors', 'admin' )->stripQueryString('adsess') ), \IPS\Email::TYPE_LIST )->send( explode( ',', \IPS\Settings::i()->nexus_hosting_error_emails ) );
}
\IPS\Db::i()->insert( 'nexus_hosting_errors', array(
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 6 Aug 2014
* @version SVN_VERSION_NUMBER
+22 -5
View File
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 6 Aug 2014
* @version SVN_VERSION_NUMBER
@@ -122,9 +122,26 @@ class _Queue extends \IPS\Node\Model
$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'] );
$serverLimits = iterator_to_array( \IPS\Db::i()->select( array( 'server_id', 'server_max_accounts' ), 'nexus_hosting_servers', $where )->setKeyField('server_id')->setValueField('server_max_accounts') );
$serverWithLeastAccounts = NULL;
foreach ( \IPS\Db::i()->select( 'nexus_hosting_servers.server_id, 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' ) as $serverData )
{
if ( !$serverWithLeastAccounts )
{
$serverWithLeastAccounts = $serverData['server_id'];
}
if ( !isset( $serverLimits[ $serverData['server_id'] ] ) or !$serverLimits[ $serverData['server_id'] ] or $serverLimits[ $serverData['server_id'] ] > $serverData['accounts'] )
{
return \IPS\nexus\Hosting\Server::load( $serverData['server_id'] );
}
}
return \IPS\nexus\Hosting\Server::constructFromData( $serverData );
if ( $serverWithLeastAccounts )
{
return \IPS\nexus\Hosting\Server::load( $serverWithLeastAccounts );
}
throw new \UnderflowException;
}
}
+13 -8
View File
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 6 Aug 2014
* @version SVN_VERSION_NUMBER
@@ -46,6 +46,11 @@ class _Server extends \IPS\Node\Model
*/
protected static $databaseIdFields = array( 'server_hostname', 'server_dedicated' );
/**
* @brief [ActiveRecord] Multiton Map
*/
protected static $multitonMap = array();
/**
* Construct ActiveRecord from database row
*
@@ -185,7 +190,7 @@ class _Server extends \IPS\Node\Model
$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 )
$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 )
{
@@ -272,7 +277,7 @@ class _Server extends \IPS\Node\Model
{
foreach ( explode( ',', \IPS\Settings::i()->monitoring_alert ) as $address )
{
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_online', array( $this, urlencode( $address ) ) );
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_online', array( $this, urlencode( $address ) ), \IPS\Email::TYPE_LIST );
$email->send( $address );
}
}
@@ -286,7 +291,7 @@ class _Server extends \IPS\Node\Model
{
foreach ( explode( ',', \IPS\Settings::i()->monitoring_alert ) as $address )
{
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_offline', array( $this, urlencode( $address ) ) );
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_offline', array( $this, urlencode( $address ) ), \IPS\Email::TYPE_LIST );
$email->send( $address );
}
}
@@ -300,7 +305,7 @@ class _Server extends \IPS\Node\Model
{
foreach ( explode( ',', \IPS\Settings::i()->monitoring_alert ) as $address )
{
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_panic', array( $this, urlencode( $address ) ) );
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_panic', array( $this, urlencode( $address ) ), \IPS\Email::TYPE_LIST );
$email->send( $address );
}
}
@@ -315,7 +320,7 @@ class _Server extends \IPS\Node\Model
{
foreach ( explode( ',', \IPS\Settings::i()->monitoring_alert ) as $address )
{
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_acknowledged', array( $this, urlencode( $address ), $by ) );
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_acknowledged', array( $this, urlencode( $address ), $by ), \IPS\Email::TYPE_LIST );
$email->send( $address );
}
}
@@ -330,7 +335,7 @@ class _Server extends \IPS\Node\Model
{
foreach ( explode( ',', \IPS\Settings::i()->monitoring_alert ) as $address )
{
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_reset', array( $this, urlencode( $address ), $by ) );
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_reset', array( $this, urlencode( $address ), $by ), \IPS\Email::TYPE_LIST );
$email->send( $address );
}
}