Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+38 -27
View File
@@ -11,48 +11,59 @@
namespace IPS\core\modules\admin\system;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\core\modules\front\system\ajax as SystemAjax;
use IPS\Db;
use IPS\Member;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use function count;
use function defined;
use function file_put_contents;
use function is_array;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Core AJAX Responders
*/
class _ajax extends \IPS\core\modules\front\system\ajax
class ajax extends SystemAjax
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Save ACP Tabs
*
* @return void
*/
protected function saveTabs()
protected function saveTabs() : void
{
\IPS\Session::i()->csrfCheck();
if ( \is_array( \IPS\Request::i()->tabOrder ) )
{
$tabs = array();
Session::i()->csrfCheck();
foreach( \IPS\Request::i()->tabOrder as $topLevelTab )
$tabs = array();
if ( is_array( Request::i()->tabOrder ) )
{
foreach( Request::i()->tabOrder as $topLevelTab )
{
$tabs[ str_replace( "tab_", "", $topLevelTab ) ] = ( isset( \IPS\Request::i()->menuOrder[ $topLevelTab ] ) ) ? \IPS\Request::i()->menuOrder[ $topLevelTab ] : array();
$tabs[ str_replace( "tab_", "", $topLevelTab ) ] = ( isset( Request::i()->menuOrder[ $topLevelTab ] ) ) ? Request::i()->menuOrder[ $topLevelTab ] : array();
}
$tabs = json_encode( $tabs );
\IPS\Db::i()->insert( 'core_acp_tab_order', array( 'id' => \IPS\Member::loggedIn()->member_id, 'data' => $tabs ), TRUE );
Db::i()->insert( 'core_acp_tab_order', array( 'id' => Member::loggedIn()->member_id, 'data' => $tabs ), TRUE );
\IPS\Request::i()->setCookie( 'acpTabs', $tabs );
Request::i()->setCookie( 'acpTabs', $tabs );
}
\IPS\Output::i()->json( 'ok' );
Output::i()->json( ['message' =>'ok', 'tabs' => $tabs], 201 );
}
/**
@@ -60,38 +71,38 @@ class _ajax extends \IPS\core\modules\front\system\ajax
*
* @return void
*/
protected function searchKeywords()
protected function searchKeywords() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
if ( \IPS\IN_DEV )
{
$url = base64_decode( \IPS\Request::i()->url );
$url = base64_decode( Request::i()->url );
$qs = array();
parse_str( $url, $qs );
\IPS\Db::i()->delete( 'core_acp_search_index', array( 'url=?', $url ) );
Db::i()->delete( 'core_acp_search_index', array( 'url=?', $url ) );
$inserts = array();
foreach ( \IPS\Request::i()->keywords as $word )
foreach ( Request::i()->keywords as $word )
{
$inserts[] = array(
'url' => $url,
'keyword' => $word,
'app' => $qs['app'],
'lang_key' => \IPS\Request::i()->lang_key,
'restriction' => \IPS\Request::i()->restriction ?: NULL
'lang_key' => Request::i()->lang_key,
'restriction' => Request::i()->restriction ?: NULL
);
}
if( \count( $inserts ) )
if( count( $inserts ) )
{
\IPS\Db::i()->insert( 'core_acp_search_index', $inserts );
Db::i()->insert( 'core_acp_search_index', $inserts );
}
$keywords = array();
foreach ( \IPS\Db::i()->select( '*', 'core_acp_search_index', array( 'app=?', $qs['app'] ), 'url ASC, keyword ASC' ) as $word )
foreach ( Db::i()->select( '*', 'core_acp_search_index', array( 'app=?', $qs['app'] ), 'url ASC, keyword ASC' ) as $word )
{
$keywords[ $word['url'] ]['lang_key'] = $word['lang_key'];
$keywords[ $word['url'] ]['restriction'] = $word['restriction'];
@@ -104,9 +115,9 @@ class _ajax extends \IPS\core\modules\front\system\ajax
$keywords[ $url ]['keywords'] = array_unique( $entry['keywords'] );
}
\file_put_contents( \IPS\ROOT_PATH . "/applications/{$qs['app']}/data/acpsearch.json", json_encode( $keywords, JSON_PRETTY_PRINT ) );
file_put_contents( \IPS\ROOT_PATH . "/applications/{$qs['app']}/data/acpsearch.json", json_encode( $keywords, JSON_PRETTY_PRINT ) );
}
\IPS\Output::i()->json( 'ok' );
Output::i()->json( 'ok' );
}
}
@@ -11,32 +11,48 @@
namespace IPS\core\modules\admin\system;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Db;
use IPS\Dispatcher\Controller;
use IPS\Helpers\MultipleRedirect;
use IPS\Http\Url;
use IPS\Member;
use IPS\Output;
use IPS\Session;
use IPS\Task;
use IPS\Theme;
use UnderflowException;
use function defined;
use function intval;
use function is_array;
use const IPS\CIC;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Background processes 'Run Now'
*/
class _background extends \IPS\Dispatcher\Controller
class background extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
if ( \IPS\CIC )
if ( CIC )
{
\IPS\Output::i()->error( 'no_writes', '2C347/1', 403, '' );
Output::i()->error( 'no_writes', '2C347/1', 403, '' );
}
parent::execute();
@@ -47,10 +63,10 @@ class _background extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('background_process_run_title');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'system' )->backgroundProcessesRunNow();
Output::i()->title = Member::loggedIn()->language()->addToStack('background_process_run_title');
Output::i()->output = Theme::i()->getTemplate( 'system' )->backgroundProcessesRunNow();
}
/**
@@ -58,35 +74,35 @@ class _background extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function process()
protected function process() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
$self = $this;
$multiRedirect = new \IPS\Helpers\MultipleRedirect(
\IPS\Http\Url::internal('app=core&module=system&controller=background&do=process')->csrf(),
$multiRedirect = new MultipleRedirect(
Url::internal('app=core&module=system&controller=background&do=process')->csrf(),
function( $data ) use ( $self )
{
/* Make sure the task is locked */
$task = \IPS\Task::load('queue', 'key');
$task = Task::load('queue', 'key');
$task->running = TRUE;
$task->next_run = time() + 900;
$task->save();
if ( ! \is_array( $data ) )
if ( ! is_array( $data ) )
{
$count = $self->getCount();
return array( array( 'count' => $count, 'done' => 0 ), \IPS\Member::loggedIn()->language()->addToStack('background_process_starting') );
return array( array( 'count' => $count, 'done' => 0 ), Member::loggedIn()->language()->addToStack('background_process_starting') );
}
else
{
try
{
/* Run the next queue task, if any */
$queueData = \IPS\Task::runQueue();
$queueData = Task::runQueue();
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
/* If we're here it means there were no rows in core_queue and we are done */
return NULL;
@@ -113,7 +129,7 @@ class _background extends \IPS\Dispatcher\Controller
if ( isset( $json['count'] ) )
{
/* If the offset is larger than the count, then we should just show the count instead (to avoid situations where it will display 150 / 139, for example) */
$offset = \intval( $queueData['offset'] );
$offset = intval( $queueData['offset'] );
if ( $offset > $json['count'] )
{
$offset = $json['count'];
@@ -121,25 +137,25 @@ class _background extends \IPS\Dispatcher\Controller
$lang[] = " " . $offset . ' / ' . $json['count'];
}
return array( $data, \IPS\Member::loggedIn()->language()->addToStack('background_processes_processing', FALSE, array( 'sprintf' => array( implode( ' - ', $lang ) ) ) ), ( $data['count'] ) ? round( ( 100 / $data['count'] * $data['done'] ), 2 ) : 100 );
return array( $data, Member::loggedIn()->language()->addToStack('background_processes_processing', FALSE, array( 'sprintf' => array( implode( ' - ', $lang ) ) ) ), ( $data['count'] ) ? round( ( 100 / $data['count'] * $data['done'] ), 2 ) : 100 );
}
},
function()
{
/* Make sure the task is unlocked */
$task = \IPS\Task::load('queue', 'key');
$task = Task::load('queue', 'key');
$task->running = FALSE;
$task->next_run = time() + 60;
$task->save();
\IPS\Session::i()->log( 'acplog__background_tasks_ran' );
Session::i()->log( 'acplog__background_tasks_ran' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=overview&controller=dashboard'), 'completed' );
Output::i()->redirect( Url::internal('app=core&module=overview&controller=dashboard'), 'completed' );
}
);
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('background_process_run_title');
\IPS\Output::i()->output = $multiRedirect;
Output::i()->title = Member::loggedIn()->language()->addToStack('background_process_run_title');
Output::i()->output = $multiRedirect;
}
/**
@@ -147,10 +163,10 @@ class _background extends \IPS\Dispatcher\Controller
*
* @return int
*/
public function getCount()
public function getCount() : int
{
$count = 0;
foreach( \IPS\Db::i()->select( '*', 'core_queue' ) as $row )
foreach( Db::i()->select( '*', 'core_queue' ) as $row )
{
if ( ! empty( $row['data'] ) )
{
@@ -158,11 +174,11 @@ class _background extends \IPS\Dispatcher\Controller
if( isset( $data['realCount'] ) )
{
$count += \intval( $data['realCount'] );
$count += intval( $data['realCount'] );
}
elseif ( isset( $data['count'] ) )
{
$count += \intval( $data['count'] );
$count += intval( $data['count'] );
}
else
{
@@ -11,21 +11,25 @@
namespace IPS\core\modules\admin\system;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\core\modules\front\system\editor as SystemEditor;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Editor AJAX functions Controller
*/
class _editor extends \IPS\core\modules\front\system\editor
class editor extends SystemEditor
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
// This class only exists to extend the front-end controller
// so that within the ACP we can call this endpoint and the
@@ -11,28 +11,37 @@
namespace IPS\core\modules\admin\system;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Dispatcher\Controller;
use IPS\Http\Url;
use IPS\Member;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Language Changer
*/
class _language extends \IPS\Dispatcher\Controller
class language extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
parent::execute();
}
@@ -42,12 +51,12 @@ class _language extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
\IPS\Member::loggedIn()->acp_language = (int) \IPS\Request::i()->id;
\IPS\Member::loggedIn()->save();
\IPS\Output::i()->redirect( \IPS\Request::i()->referrer() ?: \IPS\Http\Url::internal( '' ) );
Member::loggedIn()->acp_language = (int) Request::i()->id;
Member::loggedIn()->save();
Output::i()->redirect( Request::i()->referrer() ?: Url::internal( '' ) );
}
}
@@ -11,30 +11,39 @@
namespace IPS\core\modules\admin\system;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Output;
use IPS\Request;
use OutOfRangeException;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Live Search
*/
class _livesearch extends \IPS\Dispatcher\Controller
class livesearch extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'livesearch_manage', 'core', 'livesearch' );
Dispatcher::i()->checkAcpPermission( 'livesearch_manage', 'core' );
parent::execute();
}
@@ -43,24 +52,24 @@ class _livesearch extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
$results = array();
try
{
$exploded = explode( '_', \IPS\Request::i()->search_key );
$app = \IPS\Application::load( $exploded[0] );
$exploded = explode( '_', Request::i()->search_key );
$app = Application::load( $exploded[0] );
foreach ( $app->extensions( 'core', 'LiveSearch' ) as $k => $extension )
{
if ( $k === $exploded[1] and method_exists( $extension, 'getResults' ) )
if ( $k === $exploded[1] )
{
$results = $extension->getResults( urldecode( \IPS\Request::i()->search_term ) );
$results = $extension->getResults( urldecode( Request::i()->search_term ) );
}
}
}
catch ( \OutOfRangeException $e ) { }
catch ( OutOfRangeException $e ) { }
\IPS\Output::i()->json( array_values( $results ) );
Output::i()->json( array_values( $results ) );
}
}
@@ -10,62 +10,82 @@
namespace IPS\core\modules\admin\system;
use IPS\Http\Url;
use IPS\Output;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Application;
use IPS\core\extensions\core\AdminNotifications\ConfigurationError;
use IPS\Db;
use IPS\Dispatcher\Controller;
use IPS\Http\Url;
use IPS\Login as LoginClass;
use IPS\Login\Exception;
use IPS\Member;
use IPS\MFA\MFAHandler;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Settings;
use IPS\Theme;
use function defined;
use function is_null;
use function substr;
use const IPS\CIC;
use const IPS\IN_DEV;
use const IPS\RECOVERY_MODE;
use const IPS\ROOT_PATH;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Admin CP Login
*/
class _login extends \IPS\Dispatcher\Controller
class login extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Log In
*
* @return void
*/
protected function manage()
protected function manage() : void
{
/* Do we have an unfinished upgrade? */
if ( !\IPS\IN_DEV and ( \IPS\RECOVERY_MODE !== TRUE OR !isset( \IPS\Request::i()->noWarning ) ) and \IPS\Settings::i()->setup_in_progress )
if ( !IN_DEV and ( !RECOVERY_MODE OR !isset( Request::i()->noWarning ) ) and Settings::i()->setup_in_progress )
{
/* Don't allow the upgrade in progress page to be cached, it will only be displayed for a very short period of time */
foreach( \IPS\Output::getNoCacheHeaders() as $headerKey => $headerValue )
foreach( Output::getNoCacheHeaders() as $headerKey => $headerValue )
{
header( "{$headerKey}: {$headerValue}" );
}
include( \IPS\ROOT_PATH . '/' . \IPS\CP_DIRECTORY . '/upgrade/upgradeStarted.php' );
include( ROOT_PATH . '/admin/upgrade/upgradeStarted.php' );
session_abort();
exit;
}
/* Do we have an upgrade available to install? */
if ( !\IPS\IN_DEV and !isset( \IPS\Request::i()->noWarning ) )
if ( !IN_DEV and !isset( Request::i()->noWarning ) )
{
if( \IPS\Application::load('core')->long_version < \IPS\Application::getAvailableVersion('core') and \IPS\Application::load('core')->version != \IPS\Application::getAvailableVersion( 'core', TRUE ) )
if( Application::load('core')->long_version < Application::getAvailableVersion('core') and Application::load('core')->version != Application::getAvailableVersion( 'core', TRUE ) )
{
/* Force no caching */
@header( "Cache-control: no-cache, no-store, must-revalidate, max-age=0, s-maxage=0" );
@header( "Expires: 0" );
if ( \IPS\CIC )
if ( CIC )
{
include( \IPS\ROOT_PATH . '/' . \IPS\CP_DIRECTORY . '/upgrade/upgradeAvailableCic.php' );
include( ROOT_PATH . '/admin/upgrade/upgradeAvailableCic.php' );
}
else
{
include( \IPS\ROOT_PATH . '/' . \IPS\CP_DIRECTORY . '/upgrade/upgradeAvailable.php' );
include( ROOT_PATH . '/admin/upgrade/upgradeAvailable.php' );
}
session_abort();
exit;
@@ -73,16 +93,16 @@ class _login extends \IPS\Dispatcher\Controller
}
/* Init login class */
$url = \IPS\Http\Url::internal( "app=core&module=system&controller=login", 'admin' );
if ( isset( \IPS\Request::i()->noWarning ) )
$url = Url::internal( "app=core&module=system&controller=login", 'admin' );
if ( isset( Request::i()->noWarning ) )
{
$url = $url->setQueryString( 'noWarning', 1 );
}
if ( isset( \IPS\Request::i()->ref ) )
if ( isset( Request::i()->ref ) )
{
$url = $url->setQueryString( 'ref', \IPS\Request::i()->ref );
$url = $url->setQueryString( 'ref', Request::i()->ref );
}
$login = new \IPS\Login( $url, \IPS\Login::LOGIN_ACP );
$login = new LoginClass( $url, LoginClass::LOGIN_ACP );
/* Authenticate */
$error = NULL;
@@ -99,16 +119,16 @@ class _login extends \IPS\Dispatcher\Controller
{
$_SESSION['processing2FA'] = array( 'memberId' => $success->member->member_id );
$url = \IPS\Http\Url::internal( 'app=core&module=system&controller=login&do=mfa', 'admin', 'login' );
if ( isset( \IPS\Request::i()->ref ) )
$url = Url::internal( 'app=core&module=system&controller=login&do=mfa', 'admin', 'login' );
if ( isset( Request::i()->ref ) )
{
$url = $url->setQueryString( 'ref', \IPS\Request::i()->ref );
$url = $url->setQueryString( 'ref', Request::i()->ref );
}
if ( isset( \IPS\Request::i()->auth ) )
if ( isset( Request::i()->auth ) )
{
$url = $url->setQueryString( 'auth', \IPS\Request::i()->auth );
$url = $url->setQueryString( 'auth', Request::i()->auth );
}
\IPS\Output::i()->redirect( $url );
Output::i()->redirect( $url );
}
$success->device->updateAfterAuthentication( FALSE, $success->handler, FALSE, FALSE );
@@ -123,136 +143,137 @@ class _login extends \IPS\Dispatcher\Controller
}
}
}
catch ( \IPS\Login\Exception $e )
catch ( Exception $e )
{
$error = $e->getMessage();
$this->_log( 'fail' );
}
/* Have we been sent here because of an IP address mismatch? */
if ( \is_null( $error ) AND isset( \IPS\Request::i()->error ) )
if ( is_null( $error ) AND isset( Request::i()->error ) )
{
switch( \IPS\Request::i()->error )
switch( Request::i()->error )
{
case 'BAD_IP':
$error = \IPS\Member::loggedIn()->language()->addToStack( 'cp_bad_ip' );
$error = Member::loggedIn()->language()->addToStack( 'cp_bad_ip' );
break;
case 'NO_ACPACCESS':
$error = \IPS\Member::loggedIn()->language()->addToStack( 'no_access_cp' );
$error = Member::loggedIn()->language()->addToStack( 'no_access_cp' );
break;
}
}
/* Display Login Form */
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_system.js', 'core', 'admin' ) );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'system/login.css', 'core', 'admin' ) );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'system' )->login( $login, $error, FALSE ) );
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_system.js', 'core', 'admin' ) );
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'system/login.css', 'core', 'admin' ) );
Output::i()->sendOutput( Theme::i()->getTemplate( 'system' )->login( $login, $error, FALSE ) );
}
/**
* MFA
*
* @param string $mfaOutput If coming from _doLogin, the existing MFA output
* @param string|null $mfaOutput If coming from _doLogin, the existing MFA output
* @return void
*/
protected function mfa( $mfaOutput=NULL )
protected function mfa( ?string $mfaOutput=NULL ) : void
{
/* Have we logged in? */
$member = NULL;
if ( isset( $_SESSION['processing2FA'] ) )
{
$member = \IPS\Member::load( $_SESSION['processing2FA']['memberId'] );
$member = Member::load( $_SESSION['processing2FA']['memberId'] );
}
if ( !$member AND !$member->member_id )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( '', 'admin' ) );
Output::i()->redirect( Url::internal( '', 'admin' ) );
}
/* Set the referer in the URL */
$url = \IPS\Http\Url::internal( 'app=core&module=system&controller=login&do=mfa', 'admin', 'login' );
if ( isset( \IPS\Request::i()->ref ) )
$url = Url::internal( 'app=core&module=system&controller=login&do=mfa', 'admin', 'login' );
if ( isset( Request::i()->ref ) )
{
$url = $url->setQueryString( 'ref', \IPS\Request::i()->ref );
$url = $url->setQueryString( 'ref', Request::i()->ref );
}
if ( isset( \IPS\Request::i()->auth ) )
if ( isset( Request::i()->auth ) )
{
$url = $url->setQueryString( 'auth', \IPS\Request::i()->auth );
$url = $url->setQueryString( 'auth', Request::i()->auth );
}
/* Have we already done 2FA? */
$output = $mfaOutput ?: \IPS\MFA\MFAHandler::accessToArea( 'core', 'AuthenticateAdmin', $url, $member );
$output = $mfaOutput ?: MFAHandler::accessToArea( 'core', 'AuthenticateAdmin', $url, $member );
if ( !$output )
{
$this->_doLogin( $member, TRUE );
}
/* Nope, displau the 2FA form over the login page */
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'system/login.css', 'core', 'admin' ) );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'system' )->mfaLogin( $output ) );
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'system/login.css', 'core', 'admin' ) );
Output::i()->sendOutput( Theme::i()->getTemplate( 'system' )->mfaLogin( $output ) );
}
/**
* Process log in
*
* @param \IPS\Member $member The member
* @param Member $member The member
* @param bool $bypass2FA If true, will not perform 2FA check
* @return void
*/
protected function _doLogin( $member, $bypass2FA = FALSE )
protected function _doLogin( Member $member, bool $bypass2FA = FALSE ) : void
{
/* Check if we need to send any ACP notifications */
\IPS\core\extensions\core\AdminNotifications\ConfigurationError::runChecksAndSendNotifications();
ConfigurationError::runChecksAndSendNotifications();
/* Set the referer in the URL */
$url = \IPS\Http\Url::internal( 'app=core&module=system&controller=login&do=mfa', 'admin', 'login' );
if ( isset( \IPS\Request::i()->ref ) )
$url = Url::internal( 'app=core&module=system&controller=login&do=mfa', 'admin', 'login' );
if ( isset( Request::i()->ref ) )
{
$url = $url->setQueryString( 'ref', \IPS\Request::i()->ref );
$url = $url->setQueryString( 'ref', Request::i()->ref );
}
if ( isset( \IPS\Request::i()->auth ) )
if ( isset( Request::i()->auth ) )
{
$url = $url->setQueryString( 'auth', \IPS\Request::i()->auth );
$url = $url->setQueryString( 'auth', Request::i()->auth );
}
/* Do we need to do 2FA? */
if ( !$bypass2FA and $output = \IPS\MFA\MFAHandler::accessToArea( 'core', 'AuthenticateAdmin', $url, $member ) )
if ( !$bypass2FA and $output = MFAHandler::accessToArea( 'core', 'AuthenticateAdmin', $url, $member ) )
{
$_SESSION['processing2FA'] = array( 'memberId' => $member->member_id );
return $this->mfa( $output );
$this->mfa( $output );
return;
}
/* Set the member */
\IPS\Session::i()->setMember( $member );
Session::i()->setMember( $member );
/* Log */
$this->_log( 'ok' );
/* Clean out any existing session ID in the URL */
$queryString = array();
if( isset( \IPS\Request::i()->ref ) )
if( isset( Request::i()->ref ) )
{
parse_str( base64_decode( \IPS\Request::i()->ref ), $queryString );
parse_str( base64_decode( Request::i()->ref ), $queryString );
}
/* Do we need to show the installation onboard screen? */
if( isset( \IPS\Settings::i()->onboard_complete ) AND ( \IPS\Settings::i()->onboard_complete == 0 OR ( \IPS\Settings::i()->onboard_complete != 1 AND \IPS\Settings::i()->onboard_complete < time() ) ) )
if( isset( Settings::i()->onboard_complete ) AND ( Settings::i()->onboard_complete == 0 OR ( Settings::i()->onboard_complete != 1 AND Settings::i()->onboard_complete < time() ) ) )
{
/* We flag that onboarding is complete now so that if the admin clicks away from the page they're not immediately taken back. This is supposed to be helpful, not a hindrance. */
\IPS\Settings::i()->changeValues( array( 'onboard_complete' => 1 ) );
Settings::i()->changeValues( array( 'onboard_complete' => 1 ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=overview&controller=onboard&do=initial", 'admin' )->csrf() );
Output::i()->redirect( Url::internal( "app=core&module=overview&controller=onboard&do=initial", 'admin' )->csrf() );
}
/* Boink - if we're in recovery mode, go there */
if ( \IPS\RECOVERY_MODE === TRUE )
if ( RECOVERY_MODE )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=support&controller=recovery" )->csrf(), '', 303 );
Output::i()->redirect( Url::internal( "app=core&module=support&controller=recovery" )->csrf(), '', 303 );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( http_build_query( $queryString, '', '&' ) ), '', 303 );
Output::i()->redirect( Url::internal( http_build_query( $queryString, '', '&' ) ), '', 303 );
}
}
@@ -261,12 +282,12 @@ class _login extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function logout()
protected function logout() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
session_destroy();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=system&controller=login&_fromLogout=1" ) );
Output::i()->redirect( Url::internal( "app=core&module=system&controller=login&_fromLogout=1" ) );
}
/**
@@ -275,10 +296,10 @@ class _login extends \IPS\Dispatcher\Controller
* @param string $status Status ['fail','ok']
* @return void
*/
protected function _log( $status )
protected function _log( string $status ) : void
{
/* Generate request details */
foreach( \IPS\Request::i() as $k => $v )
foreach( Request::i() as $k => $v )
{
if ( $k == 'password' AND mb_strlen( $v ) > 1 )
{
@@ -288,29 +309,26 @@ class _login extends \IPS\Dispatcher\Controller
}
$save = array(
'admin_ip_address' => \IPS\Request::i()->ipAddress(),
'admin_username' => \IPS\Request::i()->auth ? \substr( \IPS\Request::i()->auth, 0, 255 ) : '',
'admin_ip_address' => Request::i()->ipAddress(),
'admin_username' => Request::i()->auth ? substr( Request::i()->auth, 0, 255 ) : '',
'admin_time' => time(),
'admin_success' => ( $status == 'ok' ) ? 1 : 0,
'admin_request' => json_encode( $request ),
);
\IPS\Db::i()->insert( 'core_admin_login_logs', $save );
Db::i()->insert( 'core_admin_login_logs', $save );
}
/**
* Return current CSRF token
*
* @return string|null
* @return void
*/
public function getCsrfKey()
public function getCsrfKey() : void
{
/* Don't cache the CSRF key */
\IPS\Output::setCacheTime( false );
Output::i()->pageCaching = FALSE;
/* Restrict endpoint to our origin JS */
Output::i()->httpHeaders['Access-Control-Allow-Origin'] = Url::baseUrl()->data[ Url::COMPONENT_SCHEME ] . '://' . Url::baseUrl()->data[ Url::COMPONENT_HOST ];
\IPS\Output::i()->json( [ 'key' => \IPS\Session::i()->csrfKey ] );
Output::i()->json( [ 'key' => Session::i()->csrfKey ] );
}
}
File diff suppressed because it is too large. Load diff
@@ -11,21 +11,25 @@
namespace IPS\core\modules\admin\system;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\core\modules\front\system\vle as SystemVle;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Visual Language Editor
*/
class _vle extends \IPS\core\modules\front\system\vle
class vle extends SystemVle
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
// This class only exists to extend the front-end controller
// so that within the ACP we can call this endpoint and the