Version 4.0.13.1

This commit is contained in:
Neo committed 2025-12-19 04:57:54 -08:00
1 parent f9e857d255
commit c6a86f0d9b
7517 files changed
+597400 -668041

No files matched your search

@@ -0,0 +1,235 @@
<?php
/**
* @brief Hosting Server Errors
* @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 Aug 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\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 Errors
*/
class _errors extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'errors_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'nexus_hosting_errors', \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=errors' ) );
$table->include = array( 'e_time', 'e_server', 'e_account', 'e_function', 'e_message' );
$table->langPrefix = 'hosting_';
if ( !$table->sortBy )
{
$table->sortBy = 'e_time';
$table->sortDirection = 'asc';
}
/* Parsers */
$table->parsers = array(
'e_time' => function( $val )
{
return \IPS\DateTime::ts( $val );
},
'e_server' => function( $val )
{
try
{
return \IPS\nexus\Hosting\Server::load( $val )->hostname;
}
catch ( \OutOfRangeException $e )
{
return '';
}
},
'e_function' => function ( $val, $row )
{
$details = json_decode( $row['e_extra'], TRUE );
if ( isset( $details['function'] ) )
{
return $details['function'];
}
return '';
},
'e_account' => function ( $val, $row )
{
$details = json_decode( $row['e_extra'], TRUE );
$username = NULL;
if ( isset( $details['params']['user'] ) )
{
$username = $details['params']['user'];
}
if ( isset( $details['params']['username'] ) )
{
$username = $details['params']['username'];
}
if ( $username )
{
return \IPS\Theme::i()->getTemplate('hosting')->accountLink( $username );
}
return '';
},
'e_message' => function( $val )
{
if ( \IPS\Member::loggedIn()->language()->checkKeyExists( 'hosting_ex_' . $val ) )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'hosting_ex_' . $val );
}
else
{
return $val;
}
}
);
/* Buttons */
$table->rowButtons = function( $row )
{
return array(
'view' => array(
'icon' => 'search',
'title' => 'view',
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=errors&do=view&id=' . $row['e_id'] ),
'data' => array( 'ipsDialog' => '' )
),
'retry' => array(
'icon' => 'refresh',
'title' => 'retry',
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=errors&do=retry&id=' . $row['e_id'] )
),
'delete'=> array(
'icon' => 'times-circle',
'title' => 'delete',
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=errors&do=delete&id=' . $row['e_id'] ),
'data' => array( 'delete' => '' )
)
);
};
/* Display */
\IPS\Output::i()->sidebar['actions'][] = array(
'icon' => 'envelope',
'title' => 'notifications',
'link' => \IPS\Http\Url::internal( "app=nexus&module=hosting&controller=errors&do=settings" ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('notifications') )
);
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_hosting_errors');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'hosting_errors_blurb' ) . (string) $table;
}
/**
* View
*
* @return void
*/
public function view()
{
try
{
$log = \IPS\Db::i()->select( '*', 'nexus_hosting_errors', array( 'e_id=?', \IPS\Request::i()->id ) )->first();
}
catch ( \UnderflowException $e )
{
\IPS\Output::i()->error( 'node_error', '2X244/2', 404, '' );
}
$details = json_decode( $log['e_extra'], TRUE );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->definitionTable( $details['params'], NULL, FALSE );
}
/**
* Retry
*
* @return void
*/
public function retry()
{
try
{
$log = \IPS\Db::i()->select( '*', 'nexus_hosting_errors', array( 'e_id=?', \IPS\Request::i()->id ) )->first();
}
catch ( \UnderflowException $e )
{
\IPS\Output::i()->error( 'node_error', '2X244/3', 404, '' );
}
try
{
\IPS\nexus\Hosting\Server::load( $log['e_server'] )->retryError( json_decode( $log['e_extra'], TRUE ) );
\IPS\Db::i()->delete( 'nexus_hosting_errors', array( 'e_id=?', \IPS\Request::i()->id ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=hosting&controller=errors'), 'hosrting_error_retry_done' );
}
catch ( \UnderflowException $e )
{
\IPS\Output::i()->error( $e->getMessage(), '3X244/4', 500, '' );
}
catch ( \IPS\nexus\Hosting\Exception $e )
{
$message = $e->getMessage();
if ( \IPS\Member::loggedIn()->language()->checkKeyExists( 'hosting_ex_' . $message ) )
{
$message = \IPS\Member::loggedIn()->language()->addToStack( 'hosting_ex_' . $message );
}
\IPS\Output::i()->error( $message, '1X244/1', 503, '' );
}
}
/**
* Delete
*
* @return void
*/
public function delete()
{
\IPS\Db::i()->delete( 'nexus_hosting_errors', array( 'e_id=?', \IPS\Request::i()->id ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=hosting&controller=errors'), 'deleted' );
}
/**
* Settings
*
* @return void
*/
public function settings()
{
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Stack( 'nexus_hosting_error_emails', explode( ',', \IPS\Settings::i()->nexus_hosting_error_emails ), FALSE, array( 'stackFieldType' => 'Email' ) ) );
if ( $values = $form->values() )
{
$values['nexus_hosting_error_emails'] = implode( ',', $values['nexus_hosting_error_emails'] );
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__host_err_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=hosting&controller=errors'), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_hosting_errors');
\IPS\Output::i()->output = $form;
}
}
Whitespace-only changes.
@@ -0,0 +1,145 @@
<?php
/**
* @brief Monitoring Settings
* @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 07 Aug 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\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;
}
/**
* Monitoring Settings
*/
class _monitoring extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = 'IPS\nexus\Hosting\EOM';
/**
* Manage
*
* @return void
*/
protected function manage()
{
/* Init Tabs */
$tabs = array();
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'monitoring_settings' ) )
{
$tabs['settings'] = 'settings';
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'monitoring_eom_view' ) )
{
$tabs['eom'] = 'expected_output_monitoring';
}
$keys = array_keys( $tabs );
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : array_shift( $keys );
/* Work out contents */
$activeTabContents = NULL;
switch ( $activeTab )
{
/* Settings */
case 'settings':
/* Build Form */
$form = new \IPS\Helpers\Form;
$form->addHeader('monitoring_header');
$form->addMessage('monitoring_blurb');
$form->add( new \IPS\Helpers\Form\YesNo( 'monitoring_on', \IPS\Settings::i()->monitoring_script, FALSE, array( 'togglesOn' => array( 'monitoring_script', 'monitoring_alert', 'monitoring_from', 'monitoring_backup', 'monitoring_allowed_fails', 'monitoring_panic', 'form_header_network_status_header', 'network_status' ) ) ) );
$form->add( new \IPS\Helpers\Form\Url( 'monitoring_script', \IPS\Settings::i()->monitoring_script, NULL, array( 'placeholder' => 'http://www.example.com/monitor_master.php' ), NULL, NULL, NULL, 'monitoring_script' ) );
$form->add( new \IPS\Helpers\Form\Url( 'monitoring_backup', \IPS\Settings::i()->monitoring_backup, FALSE, array( 'placeholder' => 'http://backup.example.com/monitor_master.php' ), NULL, NULL, NULL, 'monitoring_backup' ) );
$form->add( new \IPS\Helpers\Form\Stack( 'monitoring_alert', explode( ',', \IPS\Settings::i()->monitoring_alert ), NULL, array(), NULL, NULL, NULL, 'monitoring_alert' ) );
$form->add( new \IPS\Helpers\Form\Email( 'monitoring_from', \IPS\Settings::i()->monitoring_from ?: \IPS\Settings::i()->email_out, NULL, array(), NULL, NULL, NULL, 'monitoring_from' ) );
$form->add( new \IPS\Helpers\Form\Number( 'monitoring_allowed_fails', \IPS\Settings::i()->monitoring_allowed_fails, FALSE, array(), NULL, NULL, NULL, 'monitoring_allowed_fails' ) );
$form->add( new \IPS\Helpers\Form\Number( 'monitoring_panic', \IPS\Settings::i()->monitoring_panic, FALSE, array(), NULL, NULL, NULL, 'monitoring_panic' ) );
$form->addHeader('network_status_header');
$form->add( new \IPS\Helpers\Form\Radio( 'network_status', \IPS\Settings::i()->network_status, FALSE, array( 'options' => array( 2 => 'network_status_2', 1 => 'network_status_1', 0 => 'network_status_0' ), 'toggles' => array( 2 => array( 'network_status_text' ), 1 => array( 'network_status_text' ) ) ), NULL, NULL, NULL, 'network_status' ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'network_status_text', NULL, FALSE, array( 'app' => 'nexus', 'key' => 'network_status_text_val', 'editor' => array( 'app' => 'nexus', 'key' => 'Admin', 'autoSaveKey' => 'network_status_text', 'attachIds' => array( NULL, NULL, 'network_status_text' ) ) ), NULL, NULL, NULL, 'network_status_text' ) );
/* Handle submissions */
if ( $values = $form->values() )
{
if ( !$values['monitoring_on'] )
{
$values['monitoring_script'] = '';
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 0 ), "`key`='monitor'" );
}
else
{
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 1 ), "`key`='monitor'" );
}
unset( $values['monitoring_on'] );
$values['monitoring_alert'] = implode( ',', $values['monitoring_alert'] );
\IPS\Lang::saveCustom( 'nexus', 'network_status_text_val', $values['network_status_text'] );
unset( $values['network_status_text'] );
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__host_mon_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=monitoring&tab=settings' ), 'saved' );
}
/* Display */
$activeTabContents = (string) $form;
break;
/* EOM */
case 'eom':
parent::manage();
$activeTabContents = \IPS\Theme::i()->getTemplate('forms', 'core')->blurb( 'eom_blurb', TRUE, TRUE ) . \IPS\Output::i()->output;
break;
}
/* Display */
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->output = $activeTabContents;
return;
}
else
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_hosting_monitoring');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, $activeTabContents, \IPS\Http\Url::internal( "app=nexus&module=hosting&controller=monitoring" ) );
}
}
/**
* Download Master Monitoring Script
*
* @return void
*/
public function downloadMaster()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'monitoring_settings' );
\IPS\Output::i()->sendOutput( file_get_contents( \IPS\ROOT_PATH . '/applications/nexus/data/monitoring/master.txt' ), 200, 'text/plain', array( 'Content-Disposition' => 'attachment; filename=monitor_master.php' ) );
}
/**
* Download Remote Monitoring Script
*
* @return void
*/
public function downloadRemote()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'monitoring_settings' );
\IPS\Output::i()->sendOutput( file_get_contents( \IPS\ROOT_PATH . '/applications/nexus/data/monitoring/remote.txt' ), 200, 'text/plain', array( 'Content-Disposition' => 'attachment; filename=monitor_remote.php' ) );
}
}
@@ -0,0 +1,53 @@
<?php
/**
* @brief Hosting Queues
* @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 06 Aug 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\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 Queues
*/
class _queues extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = 'IPS\nexus\Hosting\Queue';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'queues_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
public function manage()
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'hosting_queues_blurb' );
return parent::manage();
}
}
@@ -0,0 +1,476 @@
<?php
/**
* @brief Hosting Servers
* @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 06 Aug 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\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 Servers
*/
class _servers extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = 'IPS\nexus\Hosting\Server';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'servers_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
public function manage()
{
/* Initiate the table */
$table = new \IPS\Helpers\Table\Db( 'nexus_hosting_servers', \IPS\Http\Url::internal('app=nexus&module=hosting&controller=servers') );
if ( \IPS\Settings::i()->monitoring_script )
{
$table->include = array( 'server_monitor_icon', 'server_hostname', 'server_ip', 'server_num_accounts', 'server_cost', 'server_income' );
$table->widths = array( 'server_monitor_icon' => 5 );
$table->noSort = array( 'server_monitor_icon' );
}
else
{
$table->include = array( 'server_hostname', 'server_ip', 'server_num_accounts', 'server_cost', 'server_income' );
}
$table->sortBy = $table->sortBy ?: 'server_hostname';
$table->quickSearch = 'server_hostname';
/* Buttons */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'servers_add' ) )
{
$table->rootButtons = array(
'add' => array(
'title' => 'add',
'icon' => 'plus',
'link' => \IPS\Http\Url::internal('app=nexus&module=hosting&controller=servers&do=form')
)
);
}
$table->rowButtons = function( $row )
{
$return = array();
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'servers_audit' ) )
{
$return['list'] = array(
'title' => 'view_accounts',
'icon' => 'search',
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=servers&do=view&id=' . $row['server_id'] )
);
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'servers_edit' ) )
{
$return['edit'] = array(
'title' => 'edit',
'icon' => 'pencil',
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=servers&do=form&id=' . $row['server_id'] )
);
}
if ( !$row['server_dedicated'] and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'servers_reboot' ) )
{
$return['reboot'] = array(
'title' => 'reboot',
'icon' => 'refresh',
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=servers&do=reboot&id=' . $row['server_id'] )
);
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'hosting', 'servers_delete' ) )
{
$return['delete'] = array(
'title' => 'delete',
'icon' => 'times-circle',
'link' => \IPS\Http\Url::internal( 'app=nexus&module=hosting&controller=servers&do=delete&id=' . $row['server_id'] ),
'data' => array( 'delete' => '' )
);
}
return $return;
};
/* Work out the monthly income for each server */
$serverIncomes = array();
foreach ( array(
'd' => ( 365 / 12 ),
'w' => ( 365 / 12 / 7 ),
'm' => 1,
'y' => ( 1 / 12 ),
) as $key => $multiplier )
{
foreach (
\IPS\Db::i()->select(
'account_server, ps_renewal_currency, SUM( ps_renewal_price / ps_renewals ) * ' . $multiplier . ' AS amount',
'nexus_hosting_accounts',
array( 'account_exists=1 AND ps_renewal_unit=?', $key ),
NULL,
NULL,
array( 'account_server', 'ps_renewal_currency' )
)->join( 'nexus_purchases', 'nexus_hosting_accounts.ps_id=nexus_purchases.ps_id' )
as $row
)
{
if ( !isset( $serverIncomes[ $row['account_server'] ][ $row['ps_renewal_currency'] ] ) )
{
$serverIncomes[ $row['account_server'] ][ $row['ps_renewal_currency'] ] = 0;
}
$serverIncomes[ $row['account_server'] ][ $row['ps_renewal_currency'] ] += $row['amount'];
}
}
/* Parse the columns */
$currencies = \IPS\nexus\Money::currencies();
$costCurrency = array_shift( $currencies );
$table->parsers = array(
'server_monitor_icon' => function( $val, $row )
{
return \IPS\Theme::i()->getTemplate('hosting')->serverStatus( $row );
},
'server_num_accounts' => function( $val, $row )
{
if ( $row['server_dedicated'] )
{
try
{
return \IPS\Theme::i()->getTemplate('purchases')->link( \IPS\nexus\Purchase::load( $row['server_dedicated'] ) );
}
catch ( \OutOfRangeException $e )
{
return '-';
}
}
else
{
return \IPS\Db::i()->select( 'COUNT(*)', 'nexus_hosting_accounts', array( 'account_server=? AND account_exists=1', $row['server_id'] ) )->first() . ( $row['server_max_accounts'] ? ( ' / ' . $row['server_max_accounts'] ) : '' );
}
},
'server_cost' => function ( $val ) use ( $costCurrency )
{
return new \IPS\nexus\Money( $val, $costCurrency );
},
'server_income' => function( $val, $row ) use ( $serverIncomes, $costCurrency )
{
if ( $row['server_dedicated'] )
{
try
{
$purchase = \IPS\nexus\Purchase::load( $row['server_dedicated'] );
$months = 0;
$months += ( $purchase->renewals->interval->y / 12 );
$months += ( $purchase->renewals->interval->m );
$months += ( $purchase->renewals->interval->d * ( 365 / 12 ) );
return new \IPS\nexus\Money( $purchase->renewals->cost->amount * $months, $purchase->renewals->cost->currency );
}
catch ( \OutOfRangeException $e )
{
return '-';
}
}
else
{
$return = array();
if ( isset( $serverIncomes[ $row['server_id'] ] ) )
{
foreach ( $serverIncomes[ $row['server_id'] ] as $currency => $amount )
{
$return[] = new \IPS\nexus\Money( $amount, $currency );
}
}
else
{
return new \IPS\nexus\Money( 0, $costCurrency );
}
return implode( '<br>', $return );
}
}
);
/* Add filters for the queues */
foreach ( \IPS\nexus\Hosting\Queue::queues() as $queue )
{
$table->filters[ $queue->name ] = \IPS\Db::i()->findInSet( 'server_queues', array( $queue->id ) );
}
/* Display */
\IPS\Output::i()->sidebar['actions'][] = array(
'icon' => 'check-circle',
'title' => 'hserv_audit',
'link' => \IPS\Http\Url::internal( "app=nexus&module=hosting&controller=servers&do=audit" ),
);
\IPS\Output::i()->output = (string) $table;
}
/**
* View accounts
*
* @return void
*/
protected function view()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'servers_audit' );
try
{
$server = \IPS\nexus\Hosting\Server::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X243/3', 403, '' );
}
\IPS\Output::i()->title = $server->hostname;
\IPS\Output::i()->output = call_user_func_array( array( \IPS\Theme::i()->getTemplate( 'hosting' ), 'viewAccounts' ), $this->_audit( $server ) );
}
/**
* Reboot a server
*
* @return void
*/
protected function reboot()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'servers_reboot' );
try
{
\IPS\nexus\Hosting\Server::load( \IPS\Request::i()->id )->reboot();
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X243/1', 404, '' );
}
catch ( \IPS\nexus\Hosting\Exception $e )
{
\IPS\Output::i()->error( $e->getMessage(), '3X243/2', 500, '' );
}
\IPS\Session::i()->log( 'acplogs__server_reboot', array( $server->hostname => FALSE ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=hosting&controller=servers'), 'rebooting' );
}
/**
* Audit all servers
*
* @return void
*/
protected function audit()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'servers_audit' );
$self = $this;
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
\IPS\Http\Url::internal('app=nexus&module=hosting&controller=servers&do=audit'),
function( $data ) use ( $self )
{
if ( $data === 0 )
{
$_SESSION['serverAudit'] = array();
$data = array( 'offset' => 0, 'bad' => array() );
}
try
{
$select = \IPS\Db::i()->select( '*', 'nexus_hosting_servers', array(), 'server_hostname', array( $data['offset'], 1 ) );
$server = \IPS\nexus\Hosting\Server::constructFromData( $select->first() );
$results = $self->_audit( $server );
foreach ( array( 1, 2, 3, 6, 7, 8 ) as $i )
{
if ( !empty( $results[ $i ] ) )
{
$data['bad'][ $server->id ] = $server->hostname;
break;
}
}
$data['offset']++;
return array( $data, \IPS\Member::loggedIn()->language()->get('hserv_audit_running'), 100 / $select->count(TRUE) * $data['offset'] );
}
catch ( \UnderflowException $e )
{
$_SESSION['serverAudit'] = $data['bad'];
return NULL;
}
},
function()
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=hosting&controller=servers&do=auditResults') );
}
);
}
/**
* Audit all servers
*
* @return void
*/
protected function auditResults()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'servers_audit' );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'hosting' )->audit( $_SESSION['serverAudit'] );
}
/**
* Audit a server
*
* @param \IPS\nexus\Hosting\Server $server
* @return array
*/
protected function _audit( \IPS\nexus\Hosting\Server $server )
{
/* Get accounts from server */
try
{
$serverAccounts = $server->listAccounts();
}
catch ( \IPS\nexus\Hosting\Exception $e )
{
\IPS\Output::i()->error( $e->getMessage(), '3X243/4', 403, '' );
}
/* Init */
$notPresentOnServer = array();
$notPresentInDb = array();
$domainsDontMatch = array();
$expiredButnotSuspended = array();
$diskSpaceAllocated = 0;
$diskSpaceInUse = 0;
$accounts = array();
$suspendedButNotExpired = array();
$doesNotResolveCorrectly= array();
/* Get accounts in the database */
foreach ( \IPS\Db::i()->select( 'nexus_hosting_accounts.*, nexus_purchases.ps_active', 'nexus_hosting_accounts', array( 'account_server=?', $server->id ), 'account_username' )->join( 'nexus_purchases', 'nexus_hosting_accounts.ps_id=nexus_purchases.ps_id' ) as $row )
{
/* If we don't think it exists, check if it does */
if ( !$row['account_exists'] )
{
if ( isset( $serverAccounts[ $row['account_username'] ] ) )
{
$row['account_exists'] = 1;
\IPS\Db::i()->update( 'nexus_hosting_accounts', array( 'account_exists' => 1 ), "ps_id={$row['ps_id']}" );
}
}
// Now check it
if ( $row['account_exists'] )
{
// Is it in there?
if ( isset( $serverAccounts[ $row['account_username'] ] ) )
{
$accounts[] = array_merge( $row, $serverAccounts[ $row['account_username'] ] );
// Does the domain match?
if ( $serverAccounts[ $row['account_username'] ]['domain'] != $row['account_domain'] )
{
$row['domain'] = $serverAccounts[ $row['account_username'] ]['domain'];
$domainsDontMatch[] = $row;
}
// Does the status match?
if ( $row['ps_active'] and !$serverAccounts[ $row['account_username'] ]['active'] )
{
$suspendedButNotExpired[] = $row;
}
elseif ( !$row['ps_active'] and $serverAccounts[ $row['account_username'] ]['active'] )
{
$expiredButnotSuspended[] = $row;
}
// Does it resolve correctly? */
if ( gethostbyname( $row['account_domain'] ) !== $server->ip )
{
$doesNotResolveCorrectly[] = $row;
}
// Get disk use
if( $diskSpaceAllocated == -1 or $serverAccounts[ $row['account_username'] ]['disklimit'] == 'unlimited' )
{
$diskSpaceAllocated = -1;
}
else
{
$diskSpaceAllocated += $serverAccounts[ $row['account_username'] ]['disklimit'];
}
$diskSpaceInUse += $serverAccounts[ $row['account_username'] ]['diskused'];
// Note that we have it
unset( $serverAccounts[ $row['account_username'] ] );
}
else
{
if ( !$row['ps_active'] )
{
\IPS\Db::i()->update( 'nexus_hosting_accounts', array( 'account_exists' => 0 ), "ps_id={$row['ps_id']}" );
}
else
{
$notPresentOnServer[] = $row;
}
}
}
}
$notPresentInDb = $serverAccounts;
/* Return */
return array( $server, $notPresentOnServer, $notPresentInDb, $domainsDontMatch, $diskSpaceAllocated, $diskSpaceInUse, $expiredButnotSuspended, $suspendedButNotExpired, $doesNotResolveCorrectly, $accounts );
}
/**
* Add/Edit Form
*
* @return void
*/
protected function form()
{
$availableTypes = 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())
{
$availableTypes[] = (string) $file;
}
}
if( isset( \IPS\Request::i()->server_type ) and in_array( \IPS\Request::i()->server_type, $availableTypes ) )
{
$this->nodeClass = "IPS\\nexus\\Hosting\\" . ucfirst( \IPS\Request::i()->server_type ) . "\\Server";
}
parent::form();
}
}
@@ -0,0 +1,178 @@
<?php
/**
* @brief Hosting Settings
* @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 08 Aug 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\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 Settings
*/
class _settings extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'settings_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
/* Init */
$form = new \IPS\Helpers\Form;
/* Account Management */
$form->addTab('hosting_account_management');
$form->add( new \IPS\Helpers\Form\Number( 'nexus_hosting_terminate', \IPS\Settings::i()->nexus_hosting_terminate, TRUE, array( 'unlimited' => -1, 'unlimitedLang' => 'forever' ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('days') ) );
/* Domains */
$form->addTab('hosting_settings_domains');
$form->addHeader('domain_options');
$optionsVal = array();
$domainPrices = array();
if ( \IPS\Settings::i()->nexus_enom_un and $domainPrices = json_decode( \IPS\Settings::i()->nexus_domain_prices, TRUE ) and count( $domainPrices ) )
{
$optionsVal[] = 'enom';
}
if ( \IPS\Settings::i()->nexus_hosting_subdomains )
{
$optionsVal[] = 'sub';
}
if ( \IPS\Settings::i()->nexus_hosting_allow_own_domain )
{
$optionsVal[] = 'own';
}
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'domain_options', $optionsVal, FALSE, array(
'options' => array(
'enom' => 'domain_options_enom',
'sub' =>'domain_options_sub',
'own' => 'domain_options_own'
),
'toggles' => array(
'enom' => array( 'form_header_nexus_domain_prices', 'nexus_domain_prices', 'nexus_domain_tax' ),
'sub' => array( 'form_header_nexus_hosting_sub', 'nexus_hosting_subdomains' ),
'own' => array()
),
'disabled' => \IPS\Settings::i()->nexus_enom_un ? array() : array( 'enom' )
) ) );
$form->add( new \IPS\Helpers\Form\Stack( 'nexus_hosting_nameservers', explode( ',', \IPS\Settings::i()->nexus_hosting_nameservers ), FALSE, array(), NULL, NULL, NULL, 'nexus_hosting_nameservers' ) );
$form->add( new \IPS\Helpers\Form\Stack( 'nexus_hosting_subdomains', explode( ',', \IPS\Settings::i()->nexus_hosting_subdomains ), FALSE, array(), NULL, NULL, NULL, 'nexus_hosting_subdomains' ) );
$form->addHeader('nexus_domain_prices');
$matrix = new \IPS\Helpers\Form\Matrix;
$matrix->columns = array(
'domain_tld' => array( 'Text' ),
'domain_price' => function( $key, $value, $data )
{
return new \IPS\nexus\Form\Money( $key, $value, FALSE, array() );
},
);
if ( count( $domainPrices ) )
{
foreach ( $domainPrices as $tld => $prices )
{
$matrix->rows[] = array( 'domain_tld' => $tld, 'domain_price' => $prices );
}
}
else
{
$matrix->rows = array( array( 'domain_tld' => 'com', 'domain_price' => NULL ) );
}
$form->addMatrix( 'nexus_domain_prices', $matrix );
$form->add( new \IPS\Helpers\Form\Node( 'nexus_domain_tax', \IPS\Settings::i()->nexus_domain_tax, FALSE, array( 'class' => 'IPS\nexus\Tax', 'zeroVal' => 'do_not_tax' ), NULL, NULL, NULL, 'nexus_domain_tax' ) );
/* Badwidth */
$form->addTab('nexus_hosting_bandwidth');
$form->addMessage( 'nexus_hosting_bandwidth_blurb' );
$bandwidthMatrix = new \IPS\Helpers\Form\Matrix;
$bandwidthMatrix->columns = array(
'bandwidth_amount' => array( 'Number' ),
'bandwidth_price' => function( $key, $value, $data )
{
return new \IPS\nexus\Form\Money( $key, $value, FALSE, array() );
},
);
$bandwidthPrices = json_decode( \IPS\Settings::i()->nexus_hosting_bandwidth, TRUE );
if ( count( $bandwidthPrices ) )
{
foreach ( $bandwidthPrices as $amount => $prices )
{
$bandwidthMatrix->rows[] = array( 'bandwidth_amount' => $amount, 'bandwidth_price' => $prices );
}
}
else
{
$bandwidthMatrix->rows = array();
}
$form->addMatrix( 'nexus_hosting_bandwidth', $bandwidthMatrix );
/* Handle Submissions */
if ( $values = $form->values() )
{
$domainPrices = array();
if ( in_array( 'enom', $values['domain_options'] ) )
{
foreach ( $values['nexus_domain_prices'] as $option )
{
if ( $option['domain_tld'] )
{
$domainPrices[ $option['domain_tld'] ] = $option['domain_price'];
}
}
}
$values['nexus_domain_prices'] = json_encode( $domainPrices );
$values['nexus_hosting_allow_own_domain'] = in_array( 'own', $values['domain_options'] );
$values['nexus_hosting_nameservers'] = implode( ',', $values['nexus_hosting_nameservers'] );
$values['nexus_hosting_subdomains'] = in_array( 'sub', $values['domain_options'] ) ? implode( ',', $values['nexus_hosting_subdomains'] ) : '';
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => (bool) $values['nexus_hosting_terminate'] ), "`key`='terminateHosting'" );
$bandwidthPrices = array();
foreach ( $values['nexus_hosting_bandwidth'] as $option )
{
if ( $option['bandwidth_amount'] )
{
$bandwidthPrices[ $option['bandwidth_amount'] ] = $option['bandwidth_price'];
}
}
$values['nexus_hosting_bandwidth'] = json_encode( $bandwidthPrices );
unset( $values['domain_options'] );
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__hosting_settings' );
}
/* Display */
if ( !\IPS\Settings::i()->nexus_enom_un )
{
\IPS\Member::loggedIn()->language()->words['domain_options_enom_desc'] = \IPS\Member::loggedIn()->language()->get( 'domain_options_enom_dis' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('hosting_settings');
\IPS\Output::i()->output = $form;
}
}