3 use wcf\acp\form\MasterPasswordForm
;
4 use wcf\acp\form\MasterPasswordInitForm
;
5 use wcf\data\menu\Menu
;
6 use wcf\data\menu\MenuCache
;
7 use wcf\system\application\ApplicationHandler
;
8 use wcf\system\cache\builder\ACPSearchProviderCacheBuilder
;
9 use wcf\system\event\EventHandler
;
10 use wcf\system\exception\AJAXException
;
11 use wcf\system\exception\PermissionDeniedException
;
12 use wcf\system\exception\SystemException
;
13 use wcf\system\request\LinkHandler
;
14 use wcf\system\request\RouteHandler
;
15 use wcf\system\session\ACPSessionFactory
;
16 use wcf\system\session\SessionHandler
;
17 use wcf\system\template\ACPTemplateEngine
;
18 use wcf\util\FileUtil
;
19 use wcf\util\HeaderUtil
;
22 * Extends WCF class with functions for the ACP.
25 * @copyright 2001-2018 WoltLab GmbH
26 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
27 * @package WoltLabSuite\Core\System
29 class WCFACP
extends WCF
{
34 protected static $inRescueMode;
37 * URL to WCF within rescue mode
40 protected static $rescueModePageURL;
42 /** @noinspection PhpMissingParentConstructorInspection */
44 * Calls all init functions of the WCF and the WCFACP class.
46 public function __construct() {
47 // add autoload directory
48 self
::$autoloadDirectories['wcf'] = WCF_DIR
. 'lib/';
50 // define tmp directory
51 if (!defined('TMP_DIR')) define('TMP_DIR', FileUtil
::getTempFolder());
53 // start initialization
58 $this->initLanguage();
60 $this->initCronjobs();
61 $this->initCoreObjects();
63 // prevent application loading during setup
65 $this->initApplications();
68 $this->initBlacklist();
71 EventHandler
::getInstance()->fireAction($this, 'initialized');
75 * Returns the main menu object.
77 * @return Menu|null menu object
80 public function getFrontendMenu() {
81 return MenuCache
::getInstance()->getMainMenu();
85 * Returns true if ACP is currently in rescue mode.
89 public static function inRescueMode() {
90 if (self
::$inRescueMode === null) {
91 self
::$inRescueMode = false;
93 if (PACKAGE_ID
&& isset($_SERVER['HTTP_HOST'])) {
94 self
::$inRescueMode = true;
96 foreach (ApplicationHandler
::getInstance()->getApplications() as $application) {
97 if ($application->domainName
=== $_SERVER['HTTP_HOST']) {
98 self
::$inRescueMode = false;
103 if (self
::$inRescueMode) {
104 self
::$rescueModePageURL = RouteHandler
::getProtocol() . $_SERVER['HTTP_HOST'] . RouteHandler
::getPath(['acp']);
109 return self
::$inRescueMode;
113 * Returns URL for rescue mode page.
117 public static function getRescueModePageURL() {
118 if (self
::inRescueMode()) {
119 return self
::$rescueModePageURL;
126 * Does the user authentication.
128 protected function initAuth() {
129 // this is a work-around since neither RequestHandler
130 // nor RouteHandler are populated right now
131 $pathInfo = RouteHandler
::getPathInfo();
133 if (self
::inRescueMode()) {
134 if (!preg_match('~^/?rescue-mode/~', $pathInfo)) {
135 $redirectURI = self
::$rescueModePageURL . 'acp/index.php?rescue-mode/';
137 HeaderUtil
::redirect($redirectURI);
141 else if (empty($pathInfo) ||
!preg_match('~^/?(acp-?captcha|login|logout)/~i', $pathInfo)) {
142 if (WCF
::getUser()->userID
== 0) {
143 // work-around for AJAX-requests within ACP
144 if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
145 throw new AJAXException(WCF
::getLanguage()->getDynamicVariable('wcf.ajax.error.sessionExpired'), AJAXException
::SESSION_EXPIRED
, '');
148 // build redirect path
149 $application = ApplicationHandler
::getInstance()->getActiveApplication();
150 if ($application === null) {
151 throw new SystemException("You have aborted the installation, therefore this installation is unusable. You are required to reinstall the software.");
154 HeaderUtil
::redirect(
155 LinkHandler
::getInstance()->getLink('Login', [
156 'url' => RouteHandler
::getProtocol() . $_SERVER['HTTP_HOST'] . WCF
::getSession()->requestURI
162 // work-around for AJAX-requests within ACP
163 if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
165 WCF
::getSession()->checkPermissions(['admin.general.canUseAcp']);
167 catch (PermissionDeniedException
$e) {
168 throw new AJAXException(self
::getLanguage()->getDynamicVariable('wcf.ajax.error.permissionDenied'), AJAXException
::INSUFFICIENT_PERMISSIONS
, $e->getTraceAsString());
172 WCF
::getSession()->checkPermissions(['admin.general.canUseAcp']);
175 // force debug mode if in ACP and authenticated
176 self
::$overrideDebugMode = true;
184 protected function initSession() {
185 self
::$sessionObj = SessionHandler
::getInstance();
186 self
::$sessionObj->setCookieSuffix('_acp');
188 $factory = new ACPSessionFactory();
191 self
::$sessionObj->setHasValidCookie($factory->hasValidCookie());
197 protected function initTPL() {
198 self
::$tplObj = ACPTemplateEngine
::getInstance();
199 self
::getTPL()->setLanguageID(self
::getLanguage()->languageID
);
200 $this->assignDefaultTemplateVariables();
206 protected function assignDefaultTemplateVariables() {
207 parent
::assignDefaultTemplateVariables();
209 // base tag is determined on runtime
210 $host = RouteHandler
::getHost();
211 $path = RouteHandler
::getPath();
213 // available acp search providers
214 $availableAcpSearchProviders = [];
215 foreach (ACPSearchProviderCacheBuilder
::getInstance()->getData() as $searchProvider) {
216 $availableAcpSearchProviders[$searchProvider->providerName
] = self
::getLanguage()->get('wcf.acp.search.provider.'.$searchProvider->providerName
);
218 asort($availableAcpSearchProviders);
220 self
::getTPL()->assign([
221 'baseHref' => $host . $path,
222 'availableAcpSearchProviders' => $availableAcpSearchProviders
227 * Initializes the active package.
229 protected function initPackage() {
230 // define active package id
231 if (!defined('PACKAGE_ID')) {
232 define('PACKAGE_ID', 1);
237 * Checks whether the active user has entered the valid master password.
239 public static function checkMasterPassword() {
240 if (defined('MODULE_MASTER_PASSWORD') && MODULE_MASTER_PASSWORD
== 1 && !WCF
::getSession()->getVar('masterPassword')) {
241 if (file_exists(WCF_DIR
.'acp/masterPassword.inc.php')) {
242 require_once(WCF_DIR
.'acp/masterPassword.inc.php');
244 if (defined('MASTER_PASSWORD')) {
245 $form = new MasterPasswordForm();
250 $form = new MasterPasswordInitForm();