3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Admin;
24 use Friendica\Core\Addon;
25 use Friendica\Core\Config\Cache;
26 use Friendica\Core\Logger;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Update;
29 use Friendica\Database\DBA;
30 use Friendica\Database\DBStructure;
32 use Friendica\Model\Register;
33 use Friendica\Module\BaseAdmin;
34 use Friendica\Network\HTTPException\InternalServerErrorException;
35 use Friendica\Util\ConfigFileLoader;
36 use Friendica\Util\DateTimeFormat;
37 use Friendica\Util\Network;
39 class Summary extends BaseAdmin
41 public static function content(array $parameters = [])
43 parent::content($parameters);
47 // are there MyISAM tables in the DB? If so, trigger a warning message
49 if (DBA::count(['information_schema' => 'tables'], ['engine' => 'myisam', 'table_schema' => DBA::databaseName()])) {
50 $warningtext[] = DI::l10n()->t('Your DB still runs with MyISAM tables. You should change the engine type to InnoDB. As Friendica will use InnoDB only features in the future, you should change this! See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the command <tt>php bin/console.php dbstructure toinnodb</tt> of your Friendica installation for an automatic conversion.<br />', 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
53 // Check if github.com/friendica/master/VERSION is higher then
54 // the local version of Friendica. Check is opt-in, source may be master or devel branch
55 if (DI::config()->get('system', 'check_new_version_url', 'none') != 'none') {
56 $gitversion = DI::config()->get('system', 'git_friendica_version');
57 if (version_compare(FRIENDICA_VERSION, $gitversion) < 0) {
58 $warningtext[] = DI::l10n()->t('There is a new version of Friendica available for download. Your current version is %1$s, upstream version is %2$s', FRIENDICA_VERSION, $gitversion);
62 if (DI::config()->get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) {
63 DBStructure::update($a->getBasePath(), false, true);
66 if (DI::config()->get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) {
67 $warningtext[] = DI::l10n()->t('The database update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear.');
70 if (DI::config()->get('system', 'update') == Update::FAILED) {
71 $warningtext[] = DI::l10n()->t('The last update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear. (Some of the errors are possibly inside the logfile.)');
74 $last_worker_call = DI::config()->get('system', 'last_worker_execution', false);
75 if (!$last_worker_call) {
76 $warningtext[] = DI::l10n()->t('The worker was never executed. Please check your database structure!');
77 } elseif ((strtotime(DateTimeFormat::utcNow()) - strtotime($last_worker_call)) > 60 * 60) {
78 $warningtext[] = DI::l10n()->t('The last worker execution was on %s UTC. This is older than one hour. Please check your crontab settings.', $last_worker_call);
81 // Legacy config file warning
82 if (file_exists('.htconfig.php')) {
83 $warningtext[] = DI::l10n()->t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from <code>.htconfig.php</code>. See <a href="%s">the Config help page</a> for help with the transition.', DI::baseUrl()->get() . '/help/Config');
86 if (file_exists('config/local.ini.php')) {
87 $warningtext[] = DI::l10n()->t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from <code>config/local.ini.php</code>. See <a href="%s">the Config help page</a> for help with the transition.', DI::baseUrl()->get() . '/help/Config');
90 // Check server vitality
91 if (!self::checkSelfHostMeta()) {
92 $well_known = DI::baseUrl()->get() . '/.well-known/host-meta';
93 $warningtext[] = DI::l10n()->t('<a href="%s">%s</a> is not reachable on your system. This is a severe configuration issue that prevents server to server communication. See <a href="%s">the installation page</a> for help.',
94 $well_known, $well_known, DI::baseUrl()->get() . '/help/Install');
97 // Check logfile permission
98 if (DI::config()->get('system', 'debugging')) {
99 $file = DI::config()->get('system', 'logfile');
101 $fileSystem = DI::fs();
104 $stream = $fileSystem->createStream($file);
106 if (!isset($stream)) {
107 throw new InternalServerErrorException('Stream is null.');
110 } catch (\Throwable $exception) {
111 $warningtext[] = DI::l10n()->t('The logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
114 $file = DI::config()->get('system', 'dlogfile');
118 $stream = $fileSystem->createStream($file);
120 if (!isset($stream)) {
121 throw new InternalServerErrorException('Stream is null.');
125 } catch (\Throwable $exception) {
126 $warningtext[] = DI::l10n()->t('The debug logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
130 // check legacy basepath settings
131 $configLoader = new ConfigFileLoader($a->getBasePath());
132 $configCache = new Cache();
133 $configLoader->setupCache($configCache);
134 $confBasepath = $configCache->get('system', 'basepath');
135 $currBasepath = DI::config()->get('system', 'basepath');
136 if ($confBasepath !== $currBasepath || !is_dir($currBasepath)) {
137 if (is_dir($confBasepath) && DI::config()->set('system', 'basepath', $confBasepath)) {
138 DI::logger()->info('Friendica\'s system.basepath was updated successfully.', [
139 'from' => $currBasepath,
140 'to' => $confBasepath,
142 $warningtext[] = DI::l10n()->t('Friendica\'s system.basepath was updated from \'%s\' to \'%s\'. Please remove the system.basepath from your db to avoid differences.',
145 } elseif (!is_dir($currBasepath)) {
146 DI::logger()->alert('Friendica\'s system.basepath is wrong.', [
147 'from' => $currBasepath,
148 'to' => $confBasepath,
150 $warningtext[] = DI::l10n()->t('Friendica\'s current system.basepath \'%s\' is wrong and the config file \'%s\' isn\'t used.',
154 DI::logger()->alert('Friendica\'s system.basepath is wrong.', [
155 'from' => $currBasepath,
156 'to' => $confBasepath,
158 $warningtext[] = DI::l10n()->t('Friendica\'s current system.basepath \'%s\' is not equal to the config file \'%s\'. Please fix your configuration.',
165 [DI::l10n()->t('Normal Account'), 0],
166 [DI::l10n()->t('Automatic Follower Account'), 0],
167 [DI::l10n()->t('Public Forum Account'), 0],
168 [DI::l10n()->t('Automatic Friend Account'), 0],
169 [DI::l10n()->t('Blog Account'), 0],
170 [DI::l10n()->t('Private Forum Account'), 0]
174 $pageFlagsCountStmt = DBA::p('SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`');
175 while ($pageFlagsCount = DBA::fetch($pageFlagsCountStmt)) {
176 $accounts[$pageFlagsCount['page-flags']][1] = $pageFlagsCount['count'];
177 $users += $pageFlagsCount['count'];
179 DBA::close($pageFlagsCountStmt);
181 Logger::log('accounts: ' . print_r($accounts, true), Logger::DATA);
183 $pending = Register::getPendingCount();
185 $deferred = DBA::count('workerqueue', ['NOT `done` AND `retrial` > ?', 0]);
187 $workerqueue = DBA::count('workerqueue', ['NOT `done` AND `retrial` = ?', 0]);
189 // We can do better, but this is a quick queue status
190 $queues = ['label' => DI::l10n()->t('Message queues'), 'deferred' => $deferred, 'workerq' => $workerqueue];
192 $variables = DBA::toArray(DBA::p('SHOW variables LIKE "max_allowed_packet"'));
193 $max_allowed_packet = $variables ? $variables[0]['Value'] : 0;
196 'label' => DI::l10n()->t('Server Settings'),
198 'upload_max_filesize' => ini_get('upload_max_filesize'),
199 'post_max_size' => ini_get('post_max_size'),
200 'memory_limit' => ini_get('memory_limit')
203 'max_allowed_packet' => $max_allowed_packet
207 $t = Renderer::getMarkupTemplate('admin/summary.tpl');
208 return Renderer::replaceMacros($t, [
209 '$title' => DI::l10n()->t('Administration'),
210 '$page' => DI::l10n()->t('Summary'),
211 '$queues' => $queues,
212 '$users' => [DI::l10n()->t('Registered users'), $users],
213 '$accounts' => $accounts,
214 '$pending' => [DI::l10n()->t('Pending registrations'), $pending],
215 '$version' => [DI::l10n()->t('Version'), FRIENDICA_VERSION],
216 '$platform' => FRIENDICA_PLATFORM,
217 '$codename' => FRIENDICA_CODENAME,
218 '$build' => DI::config()->get('system', 'build'),
219 '$addons' => [DI::l10n()->t('Active addons'), Addon::getEnabledList()],
220 '$serversettings' => $server_settings,
221 '$warningtext' => $warningtext
225 private static function checkSelfHostMeta()
227 // Fetch the host-meta to check if this really is a vital server
228 return Network::curl(DI::baseUrl()->get() . '/.well-known/host-meta')->isSuccess();