Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
+89
-48
@@ -11,38 +11,62 @@
|
||||
namespace IPS\Dispatcher;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Data\Cache;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Http\Url;
|
||||
use IPS\IPS;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Group;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
use const IPS\COOKIE_BYPASS_SSLONLY;
|
||||
use const IPS\COOKIE_DOMAIN;
|
||||
use const IPS\COOKIE_PATH;
|
||||
use const IPS\COOKIE_PREFIX;
|
||||
use const IPS\SITE_FILES_PATH;
|
||||
use const IPS\STORE_CONFIG;
|
||||
use const IPS\STORE_METHOD;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Installer/Upgrader Dispatcher
|
||||
*/
|
||||
class _Setup extends \IPS\Dispatcher
|
||||
class Setup extends Dispatcher
|
||||
{
|
||||
/**
|
||||
* @brief Controller Location
|
||||
*/
|
||||
public $controllerLocation = 'setup';
|
||||
public string $controllerLocation = 'setup';
|
||||
|
||||
/**
|
||||
* @brief Install or upgrade
|
||||
*/
|
||||
public $setupLocation = 'install';
|
||||
public string $setupLocation = 'install';
|
||||
|
||||
/**
|
||||
* @brief Step
|
||||
*/
|
||||
public $step = 1;
|
||||
public int $step = 1;
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
public function init() : void
|
||||
{
|
||||
}
|
||||
|
||||
@@ -51,7 +75,7 @@ class _Setup extends \IPS\Dispatcher
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function returnSteps()
|
||||
protected function returnSteps(): array
|
||||
{
|
||||
if( $this->setupLocation == 'upgrade' )
|
||||
{
|
||||
@@ -83,14 +107,31 @@ class _Setup extends \IPS\Dispatcher
|
||||
/**
|
||||
* Set location (install or upgrade)
|
||||
*
|
||||
* @param string $location 'install' or 'upgrade'
|
||||
* @return \IPS\Dispatcher\Setup
|
||||
* @param string $location 'install' or 'upgrade'
|
||||
* @return Setup
|
||||
*/
|
||||
public function setLocation( $location )
|
||||
public function setLocation(string $location ): Setup
|
||||
{
|
||||
$this->setupLocation = $location;
|
||||
$steps = $this->returnSteps();
|
||||
$this->classname = 'IPS\core\modules\setup\\' . $location . '\\' . ( isset( \IPS\Request::i()->controller ) ? \IPS\Request::i()->controller : $steps[1] );
|
||||
$currentStep = ( isset( Request::i()->controller ) ? Request::i()->controller : $steps[1] );
|
||||
$this->classname = 'IPS\core\modules\setup\\' . $location . '\\' . $currentStep;
|
||||
|
||||
/* If we are upgrading and just starting, check the current version.
|
||||
If we are upgrading from a version prior to v5, disable all non-1st party apps. */
|
||||
if( $location == 'upgrade' and $currentStep == 'login' )
|
||||
{
|
||||
$currentBaseVersion = Db::i()->select( 'app_long_version', 'core_applications', [ 'app_directory=?', 'core' ] )->first();
|
||||
|
||||
/* If we are upgrading from a version earlier than v5, disable and lock anything that isn't 1st party */
|
||||
if( $currentBaseVersion < 5000016 )
|
||||
{
|
||||
Db::i()->update( 'core_applications', [ 'app_enabled' => 0, 'app_requires_manual_intervention' => 1 ], Db::i()->in( 'app_directory', IPS::$ipsApps, true ) );
|
||||
Cache::i()->clearAll();
|
||||
Store::i()->clearAll();
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -99,7 +140,7 @@ class _Setup extends \IPS\Dispatcher
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
public function run() : void
|
||||
{
|
||||
/* Installer checks */
|
||||
if( $this->setupLocation == 'install' )
|
||||
@@ -110,7 +151,7 @@ class _Setup extends \IPS\Dispatcher
|
||||
{
|
||||
rename( \IPS\ROOT_PATH . '/conf_global.dist.php', \IPS\ROOT_PATH . '/conf_global.php' );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
catch ( Exception $e ) { }
|
||||
|
||||
if ( !file_exists( \IPS\ROOT_PATH . '/conf_global.php' ) )
|
||||
{
|
||||
@@ -118,115 +159,115 @@ class _Setup extends \IPS\Dispatcher
|
||||
{
|
||||
file_put_contents( \IPS\ROOT_PATH. '/conf_global.php', '' );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
catch ( Exception $e ) { }
|
||||
}
|
||||
|
||||
if ( !file_exists( \IPS\ROOT_PATH . '/conf_global.php' ) )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Member::loggedIn()->language()->addToStack( 'installation_error' ), '', true, \IPS\ROOT_PATH ), 500, 'text/html', array(), FALSE, FALSE, FALSE );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( Member::loggedIn()->language()->addToStack( 'installation_error' ), '', true, \IPS\ROOT_PATH ), 500, 'text/html', array(), FALSE, FALSE, FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
require \IPS\ROOT_PATH . '/conf_global.php';
|
||||
if ( isset( $INFO ) and isset( $INFO['installed'] ) )
|
||||
{
|
||||
$upgradeUrl = new \IPS\Http\Url( \IPS\Settings::i()->base_url . \IPS\CP_DIRECTORY . '/upgrade/' );
|
||||
\IPS\Output::i()->redirect( $upgradeUrl );
|
||||
$upgradeUrl = new Url( Settings::i()->base_url . 'admin/upgrade/' );
|
||||
Output::i()->redirect( $upgradeUrl );
|
||||
}
|
||||
}
|
||||
/* Upgrader Checks */
|
||||
else
|
||||
{
|
||||
if ( !file_exists( \IPS\SITE_FILES_PATH . '/conf_global.php' ) )
|
||||
if ( !file_exists( SITE_FILES_PATH . '/conf_global.php' ) )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Member::loggedIn()->language()->addToStack('upgrade_error'), '', \IPS\Member::loggedIn()->language()->addToStack('no_conf_global'), \IPS\ROOT_PATH ), 200, 'text/html', array(), FALSE );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( Member::loggedIn()->language()->addToStack('upgrade_error'), '', Member::loggedIn()->language()->addToStack('no_conf_global'), \IPS\ROOT_PATH ), 200, 'text/html', array(), FALSE );
|
||||
}
|
||||
|
||||
if ( \IPS\STORE_METHOD === 'FileSystem' )
|
||||
if ( STORE_METHOD === 'FileSystem' )
|
||||
{
|
||||
$config = json_decode( \IPS\STORE_CONFIG, TRUE );
|
||||
$config = json_decode( STORE_CONFIG, TRUE );
|
||||
$path = str_replace( '{root}', \IPS\ROOT_PATH, $config['path'] );
|
||||
if ( !is_dir( $path ) or !is_writable( $path ) )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Member::loggedIn()->language()->addToStack('upgrade_error'), '', \IPS\Member::loggedIn()->language()->addToStack( 'create_conf_global', FALSE, array( 'sprintf' => array( $path ) ) ), \IPS\ROOT_PATH ), 200, 'text/html', array(), FALSE );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( Member::loggedIn()->language()->addToStack('upgrade_error'), '', Member::loggedIn()->language()->addToStack( 'create_conf_global', FALSE, array( 'sprintf' => array( $path ) ) ), \IPS\ROOT_PATH ), 200, 'text/html', array(), FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
require \IPS\SITE_FILES_PATH . '/conf_global.php';
|
||||
require SITE_FILES_PATH . '/conf_global.php';
|
||||
if ( !isset( $INFO ) )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Member::loggedIn()->language()->addToStack('upgrade_error'), '', \IPS\Member::loggedIn()->language()->addToStack('bad_conf_global'), \IPS\ROOT_PATH ), 200, 'text/html', array(), FALSE );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( Member::loggedIn()->language()->addToStack('upgrade_error'), '', Member::loggedIn()->language()->addToStack('bad_conf_global'), \IPS\ROOT_PATH ), 200, 'text/html', array(), FALSE );
|
||||
}
|
||||
|
||||
/* Fix languages if necessary */
|
||||
if( \IPS\Db::i()->checkForTable( 'core_sys_lang' ) AND !\IPS\Db::i()->checkForColumn( 'core_sys_lang', 'lang_order' ) )
|
||||
if( Db::i()->checkForTable( 'core_sys_lang' ) AND !Db::i()->checkForColumn( 'core_sys_lang', 'lang_order' ) )
|
||||
{
|
||||
\IPS\Lang::languages( \IPS\Db::i()->select( '*', 'core_sys_lang' ) );
|
||||
Lang::languages( Db::i()->select( '*', 'core_sys_lang' ) );
|
||||
}
|
||||
|
||||
/* Fix members if necessary */
|
||||
if( !\IPS\Db::i()->checkForTable( 'core_members' ) )
|
||||
if( !Db::i()->checkForTable( 'core_members' ) )
|
||||
{
|
||||
\IPS\Member::$databaseTable = 'members';
|
||||
Member::$databaseTable = 'members';
|
||||
|
||||
if ( !\IPS\Db::i()->checkForTable( 'core_groups' ) )
|
||||
if ( !Db::i()->checkForTable( 'core_groups' ) )
|
||||
{
|
||||
\IPS\Member\Group::$databaseTable = 'groups';
|
||||
Group::$databaseTable = 'groups';
|
||||
}
|
||||
|
||||
/* re-arrange 3.x mapping to 4.x code */
|
||||
$bits = \IPS\Member::$bitOptions;
|
||||
$bits = Member::$bitOptions;
|
||||
unset( $bits['members_bitoptions']['members_bitoptions2'] );
|
||||
\IPS\Member::$bitOptions = $bits;
|
||||
Member::$bitOptions = $bits;
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Settings::i()->base_url = ( \IPS\Request::i()->isSecure() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . mb_substr( $_SERVER['SCRIPT_NAME'], 0, -mb_strlen( \IPS\CP_DIRECTORY . '/' . $this->setupLocation . '/index.php' ) );
|
||||
Settings::i()->base_url = ( Request::i()->isSecure() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . mb_substr( $_SERVER['SCRIPT_NAME'], 0, -mb_strlen( 'admin/' . $this->setupLocation . '/index.php' ) );
|
||||
|
||||
$this->step = array_search( \IPS\Request::i()->controller, $this->returnSteps() );
|
||||
$this->step = array_search( Request::i()->controller, $this->returnSteps() );
|
||||
|
||||
session_name( ( \IPS\COOKIE_PREFIX !== NULL ) ? \IPS\COOKIE_PREFIX . 'IPSSessionSetup' : 'IPSSessionSetup' );
|
||||
session_name( ( COOKIE_PREFIX !== NULL ) ? COOKIE_PREFIX . 'IPSSessionSetup' : 'IPSSessionSetup' );
|
||||
$currentCookieParams = session_get_cookie_params();
|
||||
session_set_cookie_params(
|
||||
86400 * 14,
|
||||
( \IPS\COOKIE_PATH !== NULL ) ? \IPS\COOKIE_PATH : $currentCookieParams['path'],
|
||||
( \IPS\COOKIE_DOMAIN !== NULL ) ? \IPS\COOKIE_DOMAIN : $currentCookieParams['domain'],
|
||||
( \IPS\COOKIE_BYPASS_SSLONLY !== TRUE ) ? ( mb_substr( \IPS\Settings::i()->base_url, 0, 5 ) == 'https' ) : $currentCookieParams['secure'],
|
||||
( COOKIE_PATH !== NULL ) ? COOKIE_PATH : $currentCookieParams['path'],
|
||||
( COOKIE_DOMAIN !== NULL ) ? COOKIE_DOMAIN : $currentCookieParams['domain'],
|
||||
( !COOKIE_BYPASS_SSLONLY ) ? ( mb_substr( Settings::i()->base_url, 0, 5 ) == 'https' ) : $currentCookieParams['secure'],
|
||||
TRUE
|
||||
);
|
||||
|
||||
if( !@session_start() )
|
||||
{
|
||||
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'session_no_good', FALSE, array( 'sprintf' => array( \IPS\IPS::$lastError ? \IPS\IPS::$lastError->getMessage() : NULL ) ) ), '4S109/5', 500, '' );
|
||||
Output::i()->error( Member::loggedIn()->language()->addToStack( 'session_no_good', FALSE, array( 'sprintf' => array( IPS::$lastError?->getMessage() ) ) ), '4S109/5', 500, '' );
|
||||
}
|
||||
|
||||
if( $this->classname != 'IPS\core\modules\setup\upgrade\done' and $this->setupLocation != 'install' and $this->step > 1 AND ( !isset( $_SESSION['uniqueKey'] ) OR $_SESSION['uniqueKey'] != \IPS\Request::i()->key ) )
|
||||
if( $this->classname != 'IPS\core\modules\setup\upgrade\done' and $this->setupLocation != 'install' and $this->step > 1 AND ( !isset( $_SESSION['uniqueKey'] ) OR $_SESSION['uniqueKey'] != Request::i()->key ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'upgrade_session_error', '3S109/4', 403, '' );
|
||||
Output::i()->error( 'upgrade_session_error', '3S109/4', 403, '' );
|
||||
}
|
||||
|
||||
/* Init class */
|
||||
if( !class_exists( $this->classname ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'page_doesnt_exist', '2S100/1', 404 );
|
||||
Output::i()->error( 'page_doesnt_exist', '2S100/1', 404 );
|
||||
}
|
||||
$controller = new $this->classname;
|
||||
if( !( $controller instanceof \IPS\Dispatcher\Controller ) )
|
||||
if( !( $controller instanceof Controller) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'page_not_found', '5S100/3', 500, '' );
|
||||
Output::i()->error( 'page_not_found', '5S100/3', 500, '' );
|
||||
}
|
||||
|
||||
/* Execute */
|
||||
$controller->execute();
|
||||
|
||||
/* If we're still here - output */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( \IPS\Output::i()->output ), 200, 'text/html', array(), FALSE, FALSE, TRUE, FALSE );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( Output::i()->output ), 200, 'text/html', array(), FALSE, FALSE, TRUE, FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output ), 200, 'text/html', array(), FALSE, FALSE, TRUE, FALSE );
|
||||
Output::i()->sendOutput( Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( Output::i()->title, Output::i()->output ), 200, 'text/html', array(), FALSE, FALSE, TRUE, FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user