Merge branch '5.2' into 5.3
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / page / IndexPage.class.php
1 <?php
2 namespace wcf\acp\page;
3 use wcf\data\user\User;
4 use wcf\data\devtools\missing\language\item\DevtoolsMissingLanguageItemList;
5 use wcf\page\AbstractPage;
6 use wcf\system\application\ApplicationHandler;
7 use wcf\system\cache\builder\OptionCacheBuilder;
8 use wcf\system\database\util\PreparedStatementConditionBuilder;
9 use wcf\system\io\RemoteFile;
10 use wcf\system\package\PackageInstallationDispatcher;
11 use wcf\system\request\LinkHandler;
12 use wcf\system\WCF;
13
14 /**
15 * Shows the welcome page in admin control panel.
16 *
17 * @author Marcel Werk
18 * @copyright 2001-2020 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package WoltLabSuite\Core\Acp\Page
21 */
22 class IndexPage extends AbstractPage {
23 /**
24 * server information
25 * @var string[]
26 */
27 public $server = [];
28
29 /**
30 * @inheritDoc
31 */
32 public function readData() {
33 parent::readData();
34
35 $sql = "SHOW VARIABLES LIKE 'innodb_flush_log_at_trx_commit'";
36 $statement = WCF::getDB()->prepareStatement($sql);
37 $statement->execute();
38 $row = $statement->fetchArray();
39 $innodbFlushLogAtTrxCommit = false;
40 if ($row !== false) {
41 $innodbFlushLogAtTrxCommit = $row['Value'];
42 }
43
44 $this->server = [
45 'os' => PHP_OS,
46 'webserver' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '',
47 'mySQLVersion' => WCF::getDB()->getVersion(),
48 'load' => '',
49 'memoryLimit' => @ini_get('memory_limit'),
50 'upload_max_filesize' => @ini_get('upload_max_filesize'),
51 'postMaxSize' => @ini_get('post_max_size'),
52 'sslSupport' => RemoteFile::supportsSSL(),
53 'innodbFlushLogAtTrxCommit' => $innodbFlushLogAtTrxCommit,
54 ];
55
56 // get load
57 if (function_exists('sys_getloadavg')) {
58 $load = sys_getloadavg();
59 if (is_array($load) && count($load) == 3) {
60 $this->server['load'] = implode(', ', $load);
61 }
62 }
63 }
64
65 /**
66 * @inheritDoc
67 */
68 public function assignVariables() {
69 parent::assignVariables();
70
71 $usersAwaitingApproval = 0;
72 if (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_ADMIN) {
73 $conditionBuilder = new PreparedStatementConditionBuilder();
74 $conditionBuilder->add('activationCode <> ?', [0]);
75 if (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER) {
76 $conditionBuilder->add('emailConfirmed IS NULL');
77 }
78
79 $sql = "SELECT COUNT(*)
80 FROM wcf".WCF_N."_user ".
81 $conditionBuilder;
82 $statement = WCF::getDB()->prepareStatement($sql);
83 $statement->execute($conditionBuilder->getParameters());
84 $usersAwaitingApproval = $statement->fetchSingleColumn();
85 }
86
87 $recaptchaWithoutKey = false;
88 $recaptchaKeyLink = '';
89 if (CAPTCHA_TYPE == 'com.woltlab.wcf.recaptcha' && (!RECAPTCHA_PUBLICKEY || !RECAPTCHA_PRIVATEKEY)) {
90 $recaptchaWithoutKey = true;
91
92 $optionCategories = OptionCacheBuilder::getInstance()->getData([], 'categories');
93 $categorySecurity = $optionCategories['security'];
94 $recaptchaKeyLink = LinkHandler::getInstance()->getLink(
95 'Option',
96 [
97 'id' => $categorySecurity->categoryID,
98 'optionName' => 'recaptcha_publickey'
99 ], '#category_security.antispam'
100 );
101 }
102
103 $evaluationExpired = $evaluationPending = [];
104 foreach (ApplicationHandler::getInstance()->getApplications() as $application) {
105 if ($application->isTainted) {
106 continue;
107 }
108
109 if ($application->getPackage()->package === 'com.woltlab.wcf') {
110 continue;
111 }
112
113 $app = WCF::getApplicationObject($application);
114 $endDate = $app->getEvaluationEndDate();
115 if ($endDate) {
116 if ($endDate < TIME_NOW) {
117 $pluginStoreFileID = $app->getEvaluationPluginStoreID();
118 $isWoltLab = false;
119 if ($pluginStoreFileID === 0 && strpos($application->getPackage()->package, 'com.woltlab.') === 0) {
120 $isWoltLab = true;
121 }
122
123 $evaluationExpired[] = [
124 'packageName' => $application->getPackage()->getName(),
125 'isWoltLab' => $isWoltLab,
126 'pluginStoreFileID' => $pluginStoreFileID
127 ];
128 }
129 else {
130 if (!isset($evaluationPending[$endDate])) {
131 $evaluationPending[$endDate] = [];
132 }
133
134 $evaluationPending[$endDate][] = $application->getPackage()->getName();
135 }
136 }
137 }
138
139 $missingLanguageItemsMTime = 0;
140 if (ENABLE_DEBUG_MODE && ENABLE_DEVELOPER_TOOLS) {
141 $logList = new DevtoolsMissingLanguageItemList();
142 $logList->sqlOrderBy = 'lastTime DESC';
143 $logList->sqlLimit = 1;
144 $logList->readObjects();
145 $logEntry = $logList->getSingleObject();
146
147 if ($logEntry !== null) {
148 $missingLanguageItemsMTime = $logEntry->lastTime;
149 }
150 }
151
152 WCF::getTPL()->assign([
153 'recaptchaWithoutKey' => $recaptchaWithoutKey,
154 'recaptchaKeyLink' => $recaptchaKeyLink,
155 'server' => $this->server,
156 'usersAwaitingApproval' => $usersAwaitingApproval,
157 'evaluationExpired' => $evaluationExpired,
158 'evaluationPending' => $evaluationPending,
159 'missingLanguageItemsMTime' => $missingLanguageItemsMTime
160 ]);
161 }
162
163 /**
164 * @inheritDoc
165 */
166 public function show() {
167 // check package installation queue
168 if ($this->action == 'WCFSetup') {
169 $queueID = PackageInstallationDispatcher::checkPackageInstallationQueue();
170
171 if ($queueID) {
172 WCF::getTPL()->assign(['queueID' => $queueID]);
173 WCF::getTPL()->display('packageInstallationSetup');
174 exit;
175 }
176 }
177
178 // show page
179 parent::show();
180 }
181 }