Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+410 -190
View File
@@ -1,11 +1,11 @@
<?php
/**
* @brief Login Handlers
* @brief Login Methods
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 15 Mar 2013
* @since 12 May 2017
*/
namespace IPS\core\modules\admin\settings;
@@ -18,14 +18,19 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
}
/**
* Login Handlers
* Login Methods
*/
class _login extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = 'IPS\Login\LoginAbstract';
protected $nodeClass = 'IPS\Login\Handler';
/**
* Show the "add" button in the page root rather than the table root
*/
protected $_addButtonInRoot = FALSE;
/**
* Execute
@@ -34,54 +39,170 @@ class _login extends \IPS\Node\Controller
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'login_manage' );
\IPS\Dispatcher::i()->checkAcpPermission( 'login_access' );
return parent::execute();
}
/**
* Get Root Buttons
*
* @return array
*/
public function _getRootButtons()
{
$buttons = parent::_getRootButtons();
if ( isset( $buttons['add'] ) )
{
$buttons['add']['link'] = $buttons['add']['link']->setQueryString( '_new', 1 );
}
return $buttons;
}
/**
* Manage
*
* @return void
* @return void
*/
protected function manage()
{
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'login_settings',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=login&do=settings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('login_settings') )
),
'forcelogout' => array(
'title' => 'force_all_logout',
'icon' => 'lock',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=login&do=forceLogout' ),
'data' => array( 'confirm' => '' ),
),
);
/* Work out tabs */
$tabs = array();
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'login_manage' ) )
{
$tabs['handlers'] = 'login_handlers';
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'login_settings' ) )
{
$tabs['settings'] = 'login_settings';
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'registration_settings' ) )
{
$tabs['registration'] = 'registration_settings';
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'login_account_management' ) )
{
$tabs['accountsettings'] = 'account_management_settings';
}
/* Show IPS Connect "master" information */
$masterUrl = \IPS\Http\Url::internal( 'applications/core/interface/ipsconnect/ipsconnect.php', 'none' );
$masterKey = \IPS\CONNECT_MASTER_KEY ?: md5( md5( \IPS\Settings::i()->sql_user . \IPS\Settings::i()->sql_pass ) . \IPS\Settings::i()->board_start );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->message( \IPS\Member::loggedIn()->language()->addToStack( 'login_ipsconnect_info', FALSE, array( 'sprintf' => array( $masterUrl, $masterKey ) ) ), 'info', NULL, FALSE );
return parent::manage();
/* Get active tab */
if ( isset( \IPS\Request::i()->tab ) and isset( $tabs[ \IPS\Request::i()->tab ] ) )
{
$activeTab = \IPS\Request::i()->tab;
}
else
{
$_tabs = array_keys( $tabs ) ;
$activeTab = array_shift( $_tabs );
}
/* Get active tab contents */
$output = '';
switch ( $activeTab )
{
case 'handlers':
\IPS\Dispatcher::i()->checkAcpPermission( 'login_manage' );
parent::manage();
$output = \IPS\Output::i()->output;
break;
case 'settings':
$output = $this->_settings();
break;
case 'registration':
$output = $this->_registration();
break;
case 'accountsettings':
$output = $this->_accountsettings();
break;
}
/* Output */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_settings_login');
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->output = $output;
}
else
{
\IPS\Output::i()->sidebar['actions'] = array(
'forcelogout' => array(
'title' => 'force_all_logout',
'icon' => 'lock',
'link' => \IPS\Http\Url::internal( 'app=core&module=settings&controller=login&do=forceLogout' ),
'data' => array( 'confirm' => '' ),
),
);
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, $output, \IPS\Http\Url::internal( "app=core&module=settings&controller=login" ) );
}
}
/**
* Force all users to be logged out
* Add/Edit Form
*
* @return void
* @return void
*/
protected function forceLogout()
protected function form()
{
\IPS\Db::i()->update( 'core_members_known_devices', array( 'login_key' => NULL ) );
\IPS\Db::i()->delete( 'core_sessions' );
\IPS\Session::i()->log( 'acplogs__logout_force' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=login' ), 'logged_out_force' );
if ( \IPS\Request::i()->id )
{
return parent::form();
}
else
{
\IPS\Output::i()->output = new \IPS\Helpers\Wizard( array(
'login_handler' => function( $data )
{
$options = array();
foreach ( \IPS\Login\Handler::handlerClasses() as $class )
{
if ( !$class::$allowMultiple )
{
foreach ( \IPS\Login\Handler::roots() as $handler )
{
if ( $handler instanceof $class )
{
continue 2;
}
}
}
$options[ $class ] = $class::getTitle();
}
$form = new \IPS\Helpers\Form( 'login_handler_1', 'continue' );
$form->add( new \IPS\Helpers\Form\Radio( 'login_handler', TRUE, NULL, array( 'options' => $options ) ) );
if ( $values = $form->values() )
{
return array( 'handler' => $values['login_handler'] );
}
return $form;
},
'login_details' => function( $data )
{
$node = new $data['handler'];
$node->classname = $data['handler'];
$form = $this->_addEditForm( $node );
if ( $values = $form->values() )
{
try
{
$node->settings = array();
$node->order = \IPS\Db::i()->select( 'MAX(login_order)', $node::$databaseTable )->first() + 1;
$node->saveForm( $node->formatFormValues( $values ) );
\IPS\Session::i()->log( 'acplog__node_created', array( $this->title => TRUE, $node->titleForLog() => FALSE ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=settings&controller=login') );
}
catch ( \LogicException $e )
{
$form->error = $e->getMessage();
}
}
return $form;
}
), \IPS\Http\Url::internal('app=core&module=settings&controller=login&do=form') );
}
}
/**
@@ -92,48 +213,78 @@ class _login extends \IPS\Node\Controller
*/
protected function enableToggle()
{
$node = \IPS\Login\LoginAbstract::load( \IPS\Request::i()->id );
$loginMethod = \IPS\Login\Handler::load( \IPS\Request::i()->id );
if ( \IPS\Request::i()->status )
{
if ( method_exists( $node, 'testSettings' ) )
try
{
try
{
$node->testSettings();
}
catch ( \Exception $e )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=settings&controller=login&do=form&id={$node->key}" ) );
}
$loginMethod->testSettings();
}
catch ( \Exception $e )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=settings&controller=login&do=form&id={$loginMethod->id}" ) );
}
}
else
{
$others = \IPS\Db::i()->select( 'count(*)', 'core_login_handlers', array( 'login_enabled=? and login_key<>?', 1, $node->key ) )->first();
if( !$others )
{
\IPS\Output::i()->error( 'login_atleast_one', '1C166/3', 403, '' );
}
/* Allow the login handler to do stuff on-disable */
$node->onDisable();
$this->_disableCheck( $loginMethod );
}
/* Clear guest page caches */
/* Clear caches */
unset( \IPS\Data\Store::i()->loginMethods );
\IPS\Data\Cache::i()->clearAll();
/* Toggle */
return parent::enableToggle();
}
/**
* Settings
* Delete
*
* @return void
*/
protected function settings()
protected function delete()
{
/* Check it's okay */
$loginMethod = \IPS\Login\Handler::load( \IPS\Request::i()->id );
$this->_disableCheck( $loginMethod );
/* Do it */
parent::delete();
/* Clear caches */
unset( \IPS\Data\Store::i()->loginMethods );
\IPS\Data\Cache::i()->clearAll();
}
/**
* If a particular method is disabled/deleted - will we still be able to log in?
*
* @param \IPS\Login\Handler $methodToRemove Handler to be disabled/deleted
* @return void
*/
protected function _disableCheck( \IPS\Login\Handler $methodToRemove )
{
foreach ( \IPS\Login::methods() as $method )
{
if ( $method != $methodToRemove and $method->canProcess( \IPS\Member::loggedIn() ) and $method->acp )
{
return true;
}
}
\IPS\Output::i()->error( 'login_handler_cannot_disable', '1C166/5', 403, '' );
}
/**
* Login Settings
*
* @return string
*/
protected function _settings()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'login_settings' );
/* Build Form */
$form = new \IPS\Helpers\Form();
$form->addHeader( 'ipb_bruteforce_attempts' );
@@ -142,32 +293,6 @@ class _login extends \IPS\Node\Controller
$form->add( new \IPS\Helpers\Form\YesNo( 'ipb_bruteforce_unlock', \IPS\Settings::i()->ipb_bruteforce_unlock, FALSE, array(), NULL, NULL, NULL, 'ipb_bruteforce_unlock' ) );
$form->addHeader( 'login_settings' );
$form->add( new \IPS\Helpers\Form\YesNo( 'new_device_email', \IPS\Settings::i()->new_device_email, FALSE ) );
/* Check if the site works over HTTPS before we allow them to change that */
$httpsValue = \IPS\Settings::i()->logins_over_https;
$httpsDisabled = FALSE;
$toggles = array();
if ( mb_substr( \IPS\Settings::i()->base_url, 0, 8 ) === 'https://' )
{
$httpsValue = TRUE;
$httpsDisabled = TRUE;
\IPS\Member::loggedIn()->language()->words['logins_over_https_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'logins_over_https_enabled', FALSE );
}
else
{
try
{
$response = \IPS\Http\Url::external( 'https://' . mb_substr( \IPS\Settings::i()->base_url, 7 ) )->request()->get();
}
catch ( \IPS\Http\Request\Exception $e )
{
$httpsValue = FALSE;
$httpsDisabled = TRUE;
$toggles[] = 'form_logins_over_https_warning';
\IPS\Member::loggedIn()->language()->words['logins_over_https_desc'] = \IPS\Member::loggedIn()->language()->addToStack( 'logins_over_https_disabled', FALSE, array( 'sprintf' => array( $e->getMessage() ) ) );
}
}
$form->add( new \IPS\Helpers\Form\YesNo( 'logins_over_https', $httpsValue, FALSE, array( 'disabled' => $httpsDisabled, 'togglesOn' => $toggles ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'disable_anonymous', !\IPS\Settings::i()->disable_anonymous, FALSE, array(), NULL, NULL, NULL, 'disable_anonymous' ) );
/* Save */
@@ -189,125 +314,220 @@ class _login extends \IPS\Node\Controller
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), "`key`='unlockmembers'" );
}
/* Cache this for the later check */
$currentLoginSetting = \IPS\Settings::i()->logins_over_https;
$form->saveAsSettings( $values );
/* Reset datastore if https setting has changed */
if( $currentLoginSetting != $values['logins_over_https'] )
{
\IPS\Theme::deleteCompiledCss();
\IPS\Data\Store::i()->clearAll();
}
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplogs__login_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=login' ), 'saved' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=login&tab=settings' ), 'saved' );
}
/* Display */
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'login_settings', $form, FALSE );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'login_settings' );
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( 'login_settings' ) );
return (string) $form;
}
/**
* Manually reprocess IPS Connect requests that are queued
* HTTPS check
*
* @return null
*/
protected function httpsCheck()
{
try
{
$response = \IPS\Http\Url::external( 'https://' . mb_substr( \IPS\Settings::i()->base_url, 7 ) )->request()->get();
\IPS\Output::i()->output = $response;
}
catch ( \IPS\Http\Request\Exception $e )
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->message( $e->getMessage() ?: '500_error_title', 'error' );
}
}
/**
* Registration Settings
*
* @return string
*/
protected function _registration()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'registration_settings' );
/* Build Form */
$form = new \IPS\Helpers\Form();
$form->addHeader('registration_standard_settings');
$form->addMessage('registration_standard_settings_blurb');
$form->add( new \IPS\Helpers\Form\Radio( 'allow_reg', \IPS\Login::registrationType(), FALSE, array(
'options' => array(
'normal' => 'allow_reg_normal',
'full' => 'allow_reg_full',
'redirect' => 'allow_reg_redirect',
'disabled' => 'allow_reg_disabled'
),
'toggles' => array(
'full' => array( 'minimum_age', 'use_coppa' ),
'redirect' => array( 'allow_reg_target' )
),
'disabled' => \IPS\Login\Handler::findMethod( 'IPS\Login\Handler\Standard' ) ? array() : array( 'normal', 'full' )
) ) );
$form->add( new \IPS\Helpers\Form\Url( 'allow_reg_target', \IPS\Settings::i()->allow_reg_target, NULL, array(), function( $val )
{
if ( !$val and \IPS\Request::i()->allow_red === 'redirect' )
{
throw new \DomainException('form_required');
}
}, NULL, NULL, 'allow_reg_target' ) );
$form->add( new \IPS\Helpers\Form\Number( 'minimum_age', \IPS\Settings::i()->minimum_age, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'any_age' ), NULL, NULL, NULL, 'minimum_age' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'use_coppa', \IPS\Settings::i()->use_coppa, FALSE, array( 'togglesOn' => array( 'coppa_fax', 'coppa_address' ) ), NULL, NULL, NULL, 'use_coppa' ) );
$form->add( new \IPS\Helpers\Form\Tel( 'coppa_fax', \IPS\Settings::i()->coppa_fax, FALSE, array(), NULL, NULL, NULL, 'coppa_fax' ) );
$form->add( new \IPS\Helpers\Form\Address( 'coppa_address', \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->coppa_address ), FALSE, array(), NULL, NULL, NULL, 'coppa_address' ) );
$form->addHeader('registration_global_settings');
$form->addMessage('registration_global_settings_blurb');
$form->add( new \IPS\Helpers\Form\Radio( 'reg_auth_type', \IPS\Settings::i()->reg_auth_type, FALSE, array(
'options' => array( 'user' => 'reg_auth_type_user', 'admin' => 'reg_auth_type_admin', 'admin_user' => 'reg_auth_type_admin_user', 'none' => 'reg_auth_type_none' ),
'toggles' => array( 'user' => array( 'validate_day_prune' ), 'admin_user' => array( 'validate_day_prune' ) )
), NULL, NULL, NULL, 'reg_auth_type' ) );
$form->add( new \IPS\Helpers\Form\Number( 'validate_day_prune', \IPS\Settings::i()->validate_day_prune, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, \IPS\Member::loggedIn()->language()->addToStack('after'), \IPS\Member::loggedIn()->language()->addToStack('days'), 'validate_day_prune' ) );
$form->add( new \IPS\Helpers\Form\Stack( 'allowed_reg_email', explode( ',', \IPS\Settings::i()->allowed_reg_email ), FALSE, array( 'placeholder' => 'mycompany.com' ), function( $value ) {
if( isset( $value[0] ) AND mb_stripos( $value[0], '@' ) )
{
throw new \DomainException( 'allowed_reg_email_email_detected' );
}
}, NULL, NULL ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'new_reg_notify', \IPS\Settings::i()->new_reg_notify, FALSE, array(), NULL, NULL, NULL, 'new_reg_notify' ) );
$form->add( new \IPS\Helpers\Form\Radio( 'force_reg_terms', \IPS\Settings::i()->force_reg_terms, FALSE, array( 'options' => array(
'0' => 'force_reg_terms_0',
'1' => 'force_reg_terms_1',
) ) ) );
$form->add( new \IPS\Helpers\Form\Radio( 'updates_consent_default', \IPS\Settings::i()->updates_consent_default, FALSE, array(
'options' => array( 'enabled' => 'updates_consent_enabled', 'disabled' => 'updates_consent_disabled' ),
), NULL, NULL, NULL, 'updates_consent_default' ) );
/* Save */
if ( $values = $form->values() )
{
/* Save */
if ( isset( $values['allowed_reg_email'] ) and is_array( $values['allowed_reg_email'] ) )
{
$values['allowed_reg_email'] = implode( ',', $values['allowed_reg_email'] );
}
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__registration_settings' );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
/* Redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=login&tab=registration' ), 'saved' );
}
/* Display */
return (string) $form;
}
/**
* Account Management Settings
*
* @return string
*/
protected function _accountsettings()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'login_account_management' );
/* Build Form */
$form = new \IPS\Helpers\Form();
$form->addHeader( 'security_header_accounts' );
$form->add( new \IPS\Helpers\Form\YesNo( 'password_strength_meter', \IPS\Settings::i()->password_strength_meter, FALSE, array( 'togglesOn' => array( 'password_strength_meter_enforce' ) ), NULL, NULL, NULL, 'password_strength_meter' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'password_strength_meter_enforce', \IPS\Settings::i()->password_strength_meter_enforce, FALSE, array( 'togglesOn' => array( 'password_strength_option' ) ), NULL, NULL, NULL, 'password_strength_meter_enforce' ) );
$strengthOptions = array(
'3' => 'strength_3',
'4' => 'strength_4',
'5' => 'strength_5',
);
$form->add( new \IPS\Helpers\Form\Radio( 'password_strength_option', \IPS\Settings::i()->password_strength_option, FALSE, array( 'options' => $strengthOptions ), NULL, NULL, NULL, 'password_strength_option' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'device_management', \IPS\Settings::i()->device_management, FALSE ) );
$form->addHeader('account_management_email_pass');
$form->addMessage('account_management_email_pass_blurb');
$form->add( new \IPS\Helpers\Form\Radio( 'allow_email_changes', \IPS\Settings::i()->allow_email_changes, FALSE, array(
'options' => array(
'normal' => 'allow_email_changes_normal',
'redirect' => 'allow_email_changes_redirect',
'disabled' => 'allow_email_changes_disabled',
),
'toggles' => array(
'redirect' => array( 'allow_email_changes_target' )
)
) ) );
$form->add( new \IPS\Helpers\Form\Url( 'allow_email_changes_target', \IPS\Settings::i()->allow_email_changes_target, NULL, array(), function( $val )
{
if ( !$val and \IPS\Request::i()->allow_email_changes === 'redirect' )
{
throw new \DomainException('form_required');
}
}, NULL, NULL, 'allow_email_changes_target' ) );
$form->add( new \IPS\Helpers\Form\Radio( 'allow_password_changes', \IPS\Settings::i()->allow_password_changes, FALSE, array(
'options' => array(
'normal' => 'allow_password_changes_normal',
'redirect' => 'allow_password_changes_redirect',
'disabled' => 'allow_password_changes_disabled',
),
'toggles' => array(
'redirect' => array( 'allow_password_changes_target' )
)
) ) );
$form->add( new \IPS\Helpers\Form\Url( 'allow_password_changes_target', \IPS\Settings::i()->allow_password_changes_target, NULL, array(), function( $val )
{
if ( !$val and \IPS\Request::i()->allow_password_changes === 'redirect' )
{
throw new \DomainException('form_required');
}
}, NULL, NULL, 'allow_password_changes_target' ) );
$form->add( new \IPS\Helpers\Form\Radio( 'allow_forgot_password', \IPS\Settings::i()->allow_forgot_password, FALSE, array(
'options' => array(
'normal' => 'allow_forgot_password_normal',
'handler' => 'allow_forgot_password_handler',
'redirect' => 'allow_forgot_password_redirect',
'disabled' => 'allow_forgot_password_disabled',
),
'toggles' => array(
'redirect' => array( 'allow_forgot_password_target' )
)
) ) );
$form->add( new \IPS\Helpers\Form\Url( 'allow_forgot_password_target', \IPS\Settings::i()->allow_forgot_password_target, NULL, array(), function( $val )
{
if ( !$val and \IPS\Request::i()->allow_forgot_password === 'redirect' )
{
throw new \DomainException('form_required');
}
}, NULL, NULL, 'allow_forgot_password_target' ) );
/* Save */
if ( $values = $form->values() )
{
$values['password_strength_meter_enforce'] = $values['password_strength_meter'] ? $values['password_strength_meter_enforce'] : FALSE;
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__account_management_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=login&tab=accountsettings' ), 'saved' );
}
/* Display */
return (string) $form;
}
/**
* Force all users to be logged out
*
* @return void
*/
protected function retryConnect()
protected function forceLogout()
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('try_slave_request_again');
\IPS\Db::i()->update( 'core_members_known_devices', array( 'login_key' => NULL ) );
\IPS\Db::i()->delete( 'core_sessions' );
\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect(
\IPS\Http\Url::internal( "app=core&module=settings&controller=login&do=retryConnect&slave=" . \IPS\Request::i()->slave ),
function( $data )
{
/* On first cycle get data */
if ( !is_array( $data ) )
{
/* Get total number of failures to process for progress bar */
$data = array( 'done' => 0, 'total' => count( \IPS\Db::i()->select( 'id', 'core_ipsconnect_queue', array( 'slave_id=?', intval( \IPS\Request::i()->slave ) ) ) ) );
}
/* Get the next request */
try
{
$request = \IPS\Db::i()->select( 'q.*, s.*', array( 'core_ipsconnect_queue', 'q' ), array( 'q.slave_id=?', intval( \IPS\Request::i()->slave ) ), 'q.id asc', array( 0, 1 ) )
->join( array( 'core_ipsconnect_slaves', 's' ), "s.slave_id=q.slave_id" )
->first();
/* Try to process request again */
try
{
parse_str( $request['request_url'], $variables );
$response = \IPS\Http\Url::external( $request['slave_url'] )
->setQueryString( $variables )
->request()
->get();
if( $response->httpResponseCode !== NULL AND $response->httpResponseCode > 200 )
{
/* Update fail count */
\IPS\Db::i()->update( 'core_ipsconnect_queue', 'fail_count=fail_count+1', array( 'id=?', $request['id'] ) );
/* Show error message */
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'connect_failure_details', FALSE, array( 'sprintf' =>
array( \IPS\Member::loggedIn()->language()->addToStack('connect_slavefail_http', FALSE, array( 'sprintf' => array( $response->httpResponseCode ) ) ) )
) ), '4C166/1', 503, '' );
}
$response = $response->decodeJson();
/* If this is a registered slave but the slave is telling us Connect is disabled, remove it */
if( isset( $response['status'] ) AND $response['status'] == 'DISABLED' )
{
\IPS\Db::i()->update( 'core_ipsconnect_slaves', array( 'slave_enabled' => 0 ), array( 'slave_id=?', $request['slave_id'] ) );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => \IPS\Db::i()->select( 'COUNT(*)', 'core_ipsconnect_slaves', array( 'slave_enabled=?', 1 ) )->first() ), array( 'conf_key=?', 'connect_slaves' ) );
unset( \IPS\Data\Store::i()->settings );
}
else if( !isset( $response['status'] ) OR $response['status'] != 'SUCCESS' )
{
throw new \RuntimeException( $response['status'] );
}
/* If we are here, request succeeded - remove from queue */
\IPS\Db::i()->delete( 'core_ipsconnect_queue', array( 'id=?', $request['id'] ) );
}
catch( \RuntimeException $e )
{
/* Update fail count */
\IPS\Db::i()->update( 'core_ipsconnect_queue', 'fail_count=fail_count+1', array( 'id=?', $request['id'] ) );
/* The request failed - show the admin why */
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack('connect_failure_details', FALSE, array( 'sprintf' => array( $e->getMessage() ) ) ), '4C166/2', 503, '' );
}
$data['done']++;
/* Return null to indicate we are done */
return array( $data, 'connect_retry_success', round( $data['done'] / $data['total'] ) );
}
catch( \UnderflowException $e )
{
\IPS\Session::i()->log( 'acplog__connect_queue_cleared' );
/* Disable task */
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), "`key`='connect'" );
return NULL;
}
},
function()
{
/* And redirect back to the dashboard */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=overview&controller=dashboard' ), 'connect_queue_cleared' );
}
);
\IPS\Session::i()->log( 'acplogs__logout_force' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=settings&controller=login' ), 'logged_out_force' );
}
}