Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+20 -6
View File
@@ -12,7 +12,7 @@
namespace IPS\nexus\Hosting;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -39,7 +39,20 @@ class _Account extends \IPS\Patterns\ActiveRecord
* @brief [ActiveRecord] ID Database Column
*/
public static $databaseColumnId = 'ps_id';
/**
* Account Types
*
* @return array
*/
public static function accountTypes()
{
return array(
'Cpanel' => 'IPS\nexus\Hosting\Cpanel\Account',
'None' => 'IPS\nexus\Hosting\None\Account',
);
}
/**
* Construct ActiveRecord from database row
*
@@ -50,7 +63,8 @@ class _Account extends \IPS\Patterns\ActiveRecord
public static function constructFromData( $data, $updateMultitonStoreIfExists = TRUE )
{
/* Initiate an object */
$classname = 'IPS\\nexus\Hosting\\' . mb_ucfirst( \IPS\nexus\Hosting\Server::load( $data['account_server'] )->type ) . '\\Account';
$availableTypes = static::accountTypes();
$classname = $availableTypes[ mb_ucfirst( \IPS\nexus\Hosting\Server::load( $data['account_server'] )->type ) ];
$obj = new $classname;
$obj->_new = FALSE;
@@ -85,9 +99,9 @@ class _Account extends \IPS\Patterns\ActiveRecord
{
$chr = rand( 33, 122 );
}
while ( in_array( $chr, array( 38, 43, 47, 64, 92, 93, 94 ) ) );
while ( \in_array( $chr, array( 38, 43, 47, 64, 92, 93, 94 ) ) );
$password .= chr( $chr );
$password .= \chr( $chr );
}
$this->password = $password;
@@ -187,7 +201,7 @@ class _Account extends \IPS\Patterns\ActiveRecord
*/
public function set_exists( $exists )
{
$this->_data['account_exists'] = intval( $exists );
$this->_data['account_exists'] = \intval( $exists );
}
/**
@@ -12,7 +12,7 @@
namespace IPS\nexus\Hosting\Cpanel;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -94,7 +94,7 @@ class _Account extends \IPS\nexus\Hosting\Account
{
$information = $this->summary();
return ( $information['disklimit'] === 'unlimited' ) ? NULL : ( intval( $information['disklimit'] ) * 1048576 );
return ( $information['disklimit'] === 'unlimited' ) ? NULL : ( \intval( $information['disklimit'] ) * 1048576 );
}
/**
@@ -106,7 +106,7 @@ class _Account extends \IPS\nexus\Hosting\Account
{
$information = $this->summary();
return intval( $information['diskused'] ) * 1048576;
return \intval( $information['diskused'] ) * 1048576;
}
/**
@@ -122,7 +122,7 @@ class _Account extends \IPS\nexus\Hosting\Account
/**
* Get bandwidth information
*
* @return array
* @return void
*/
protected function bandwidth()
{
@@ -268,7 +268,7 @@ class _Account extends \IPS\nexus\Hosting\Account
* 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)
* @param bool $park 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 )
@@ -12,7 +12,7 @@
namespace IPS\nexus\Hosting\Cpanel;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -31,7 +31,7 @@ class _Server extends \IPS\nexus\Hosting\Server
*/
public static function extraFormFields( \IPS\nexus\Hosting\Server $server )
{
$class = get_class();
$class = \get_class();
return array(
'server_cpanel_username' => new \IPS\Helpers\Form\Text( 'server_cpanel_username', $server->username ?: 'root', NULL, array(), function( $val )
{
@@ -116,7 +116,7 @@ class _Server extends \IPS\nexus\Hosting\Server
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' ) )
\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'
) {
@@ -145,8 +145,8 @@ class _Server extends \IPS\nexus\Hosting\Server
{
$return[ $account['user'] ] = array(
'domain' => $account['domain'],
'disklimit' => intval( str_replace( 'M', '', $account['disklimit'] ) ) * 1000000,
'diskused' => intval( str_replace( 'M', '', $account['diskused'] ) ) * 1000000,
'disklimit' => \intval( str_replace( 'M', '', $account['disklimit'] ) ) * 1000000,
'diskused' => \intval( str_replace( 'M', '', $account['diskused'] ) ) * 1000000,
'active' => !$account['suspended'],
);
}
+1 -1
View File
@@ -12,7 +12,7 @@
namespace IPS\nexus\Hosting;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -12,7 +12,7 @@
namespace IPS\nexus\Hosting;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -60,17 +60,14 @@ class _Exception extends \RuntimeException
* @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') ), \IPS\Email::TYPE_LIST )->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 )
) );
\IPS\core\AdminNotification::send( 'nexus', 'HostingError', NULL, TRUE, array( 'server' => $this->server, 'message' => $this->getMessage() ) );
}
}
@@ -12,7 +12,7 @@
namespace IPS\nexus\Hosting\None;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
+2 -2
View File
@@ -12,7 +12,7 @@
namespace IPS\nexus\Hosting;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -128,7 +128,7 @@ class _Queue extends \IPS\Node\Model
$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 )
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 )
{
+40 -22
View File
@@ -12,7 +12,7 @@
namespace IPS\nexus\Hosting;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,19 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _Server extends \IPS\Node\Model
{
/**
* Server Types
*
* @return array
*/
public static function serverTypes()
{
return array(
'Cpanel' => 'IPS\nexus\Hosting\Cpanel\Server',
'None' => 'IPS\nexus\Hosting\None\Server',
);
}
/* !ActiveRecord */
/**
@@ -60,7 +73,8 @@ class _Server extends \IPS\Node\Model
public static function constructFromData( $data, $updateMultitonStoreIfExists = TRUE )
{
/* Initiate an object */
$classname = 'IPS\\nexus\Hosting\\' . mb_ucfirst( $data['server_type'] ) . '\\Server';
$availableTypes = static::serverTypes();
$classname = $availableTypes[ mb_ucfirst( $data['server_type'] ) ];
$obj = new $classname;
$obj->_new = FALSE;
@@ -110,6 +124,16 @@ class _Server extends \IPS\Node\Model
{
$this->_data['extra'] = json_encode( $extra );
}
/**
* Get the server type
*
* @return string
*/
public function get_type()
{
return ( isset( $this->_data['type'] ) ) ? mb_ucfirst( $this->_data['type'] ) : '';
}
/* !Node */
@@ -151,16 +175,12 @@ class _Server extends \IPS\Node\Model
$types = array();
$extraFields = array();
$toggles = array();
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Hosting' ) as $file )
foreach ( static::serverTypes() as $key => $class )
{
if ( !$file->isDot() and mb_substr( $file, 0, 1 ) !== '.' and $file->isDir() )
{
$types[ mb_strtolower( $file ) ] = 'nexus_server_' . $file;
$class = 'IPS\nexus\Hosting\\' . mb_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 ) ) ] );
}
$types[ $key ] = 'nexus_server_' . $key;
$extraFields[ $key ] = $class::extraFormFields( $this );
$toggles[ $key ] = array_keys( $extraFields[ $key ] );
}
$form->addHeader( 'server_type' );
@@ -185,7 +205,7 @@ class _Server extends \IPS\Node\Model
$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\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' ) ) ) );
@@ -210,7 +230,7 @@ class _Server extends \IPS\Node\Model
{
if( isset( $values['server_queues'] ) )
{
$values['server_queues'] = is_array( $values['server_queues'] ) ? implode( ',', array_keys( $values['server_queues'] ) ) : NULL;
$values['server_queues'] = \is_array( $values['server_queues'] ) ? implode( ',', array_keys( $values['server_queues'] ) ) : NULL;
}
if( isset( $values['server_nameservers'] ) )
@@ -220,18 +240,16 @@ class _Server extends \IPS\Node\Model
unset( $values['server_nameservers_default'] );
unset( $values['server_monitor_on'] );
$values = call_user_func( array( 'IPS\nexus\Hosting\\' . mb_ucfirst( $values['server_type'] ) . '\Server', '_formatFormValues' ), $values );
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Hosting' ) as $file )
$availableTypes = static::serverTypes();
$serverClass = $availableTypes[ mb_ucfirst( $values['server_type'] ) ];
$values = $serverClass::_formatFormValues( $values );
foreach ( static::serverTypes() as $key => $class )
{
if ( !$file->isDot() and mb_substr( $file, 0, 1 ) !== '.' and $file->isDir() )
foreach ( array_keys( $class::extraFormFields( $this ) ) as $k )
{
$class = 'IPS\nexus\Hosting\\' . mb_ucfirst( $file ) . '\Server';
foreach ( array_keys( $class::extraFormFields( $this ) ) as $k )
{
unset( $values[ $k ] );
}
unset( $values[ $k ] );
}
}