3 namespace Friendica\Module\Admin;
5 use Friendica\Core\Addon;
6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Logger;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\Update;
11 use Friendica\Database\DBA;
12 use Friendica\Database\DBStructure;
13 use Friendica\Model\Register;
14 use Friendica\Module\BaseAdminModule;
15 use Friendica\Util\Config\ConfigFileLoader;
16 use Friendica\Util\DateTimeFormat;
17 use Friendica\Util\Network;
19 class Summary extends BaseAdminModule
21 public static function content()
27 // are there MyISAM tables in the DB? If so, trigger a warning message
29 if (DBA::count(['information_schema' => 'tables'], ['engine' => 'myisam', 'table_schema' => DBA::databaseName()])) {
30 $warningtext[] = 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');
33 // Check if github.com/friendica/master/VERSION is higher then
34 // the local version of Friendica. Check is opt-in, source may be master or devel branch
35 if (Config::get('system', 'check_new_version_url', 'none') != 'none') {
36 $gitversion = Config::get('system', 'git_friendica_version');
37 if (version_compare(FRIENDICA_VERSION, $gitversion) < 0) {
38 $warningtext[] = 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);
42 if (Config::get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) {
43 DBStructure::update($a->getBasePath(), false, true);
46 if (Config::get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) {
47 $warningtext[] = 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.');
50 if (Config::get('system', 'update') == Update::FAILED) {
51 $warningtext[] = 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.)');
54 $last_worker_call = Config::get('system', 'last_worker_execution', false);
55 if (!$last_worker_call) {
56 $warningtext[] = L10n::t('The worker was never executed. Please check your database structure!');
57 } elseif ((strtotime(DateTimeFormat::utcNow()) - strtotime($last_worker_call)) > 60 * 60) {
58 $warningtext[] = L10n::t('The last worker execution was on %s UTC. This is older than one hour. Please check your crontab settings.', $last_worker_call);
61 // Legacy config file warning
62 if (file_exists('.htconfig.php')) {
63 $warningtext[] = 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.', $a->getBaseURL() . '/help/Config');
66 if (file_exists('config/local.ini.php')) {
67 $warningtext[] = 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.', $a->getBaseURL() . '/help/Config');
70 // Check server vitality
71 if (!self::checkSelfHostMeta()) {
72 $well_known = $a->getBaseURL() . '/.well-known/host-meta';
73 $warningtext[] = 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.',
74 $well_known, $well_known, $a->getBaseURL() . '/help/Install');
77 // check legacy basepath settings
78 $configLoader = new ConfigFileLoader($a->getBasePath(), $a->getMode());
79 $configCache = new Config\Cache\ConfigCache();
80 $configLoader->setupCache($configCache);
81 $confBasepath = $configCache->get('system', 'basepath');
82 $currBasepath = $a->getConfig()->get('system', 'basepath');
83 if ($confBasepath !== $currBasepath || !is_dir($currBasepath)) {
84 if (is_dir($confBasepath) && Config::set('system', 'basepath', $confBasepath)) {
85 $a->getLogger()->info('Friendica\'s system.basepath was updated successfully.', [
86 'from' => $currBasepath,
87 'to' => $confBasepath,
89 $warningtext[] = L10n::t('Friendica\'s system.basepath was updated from \'%s\' to \'%s\'. Please remove the system.basepath from your db to avoid differences.',
92 } elseif (!is_dir($currBasepath)) {
93 $a->getLogger()->alert('Friendica\'s system.basepath is wrong.', [
94 'from' => $currBasepath,
95 'to' => $confBasepath,
97 $warningtext[] = L10n::t('Friendica\'s current system.basepath \'%s\' is wrong and the config file \'%s\' isn\'t used.',
101 $a->getLogger()->alert('Friendica\'s system.basepath is wrong.', [
102 'from' => $currBasepath,
103 'to' => $confBasepath,
105 $warningtext[] = L10n::t('Friendica\'s current system.basepath \'%s\' is not equal to the config file \'%s\'. Please fix your configuration.',
112 [L10n::t('Normal Account'), 0],
113 [L10n::t('Automatic Follower Account'), 0],
114 [L10n::t('Public Forum Account'), 0],
115 [L10n::t('Automatic Friend Account'), 0],
116 [L10n::t('Blog Account'), 0],
117 [L10n::t('Private Forum Account'), 0]
121 $pageFlagsCountStmt = DBA::p('SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`');
122 while ($pageFlagsCount = DBA::fetch($pageFlagsCountStmt)) {
123 $accounts[$pageFlagsCount['page-flags']][1] = $pageFlagsCount['count'];
124 $users += $pageFlagsCount['count'];
126 DBA::close($pageFlagsCountStmt);
128 Logger::log('accounts: ' . print_r($accounts, true), Logger::DATA);
130 $pending = Register::getPendingCount();
132 $queue = DBA::count('queue', []);
134 $deferred = DBA::count('workerqueue', ['`executed` <= ? AND NOT `done` AND `next_try` > ?',
135 DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);
137 $workerqueue = DBA::count('workerqueue', ['`executed` <= ? AND NOT `done` AND `next_try` < ?',
138 DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);
140 // We can do better, but this is a quick queue status
141 $queues = ['label' => L10n::t('Message queues'), 'queue' => $queue, 'deferred' => $deferred, 'workerq' => $workerqueue];
143 $variables = DBA::toArray(DBA::p('SHOW variables LIKE "max_allowed_packet"'));
144 $max_allowed_packet = $variables ? $variables[0]['Value'] : 0;
147 'label' => L10n::t('Server Settings'),
149 'upload_max_filesize' => ini_get('upload_max_filesize'),
150 'post_max_size' => ini_get('post_max_size'),
151 'memory_limit' => ini_get('memory_limit')
154 'max_allowed_packet' => $max_allowed_packet
158 $t = Renderer::getMarkupTemplate('admin/summary.tpl');
159 return Renderer::replaceMacros($t, [
160 '$title' => L10n::t('Administration'),
161 '$page' => L10n::t('Summary'),
162 '$queues' => $queues,
163 '$users' => [L10n::t('Registered users'), $users],
164 '$accounts' => $accounts,
165 '$pending' => [L10n::t('Pending registrations'), $pending],
166 '$version' => [L10n::t('Version'), FRIENDICA_VERSION],
167 '$platform' => FRIENDICA_PLATFORM,
168 '$codename' => FRIENDICA_CODENAME,
169 '$build' => Config::get('system', 'build'),
170 '$addons' => [L10n::t('Active addons'), Addon::getEnabledList()],
171 '$serversettings' => $server_settings,
172 '$warningtext' => $warningtext
176 private static function checkSelfHostMeta()
178 // Fetch the host-meta to check if this really is a vital server
179 return Network::curl(self::getApp()->getBaseURL() . '/.well-known/host-meta')->isSuccess();