]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Summary.php
Remove duplicate $baseurl template variable
[friendica.git] / src / Module / Admin / Summary.php
1 <?php\r
2 \r
3 namespace Friendica\Module\Admin;\r
4 \r
5 use Friendica\Core\Addon;\r
6 use Friendica\Core\Config;\r
7 use Friendica\Core\L10n;\r
8 use Friendica\Core\Logger;\r
9 use Friendica\Core\Renderer;\r
10 use Friendica\Core\Update;\r
11 use Friendica\Database\DBA;\r
12 use Friendica\Database\DBStructure;\r
13 use Friendica\Model\Register;\r
14 use Friendica\Module\BaseAdminModule;\r
15 use Friendica\Util\DateTimeFormat;\r
16 use Friendica\Util\Network;\r
17 \r
18 class Summary extends BaseAdminModule\r
19 {\r
20         public static function content()\r
21         {\r
22                 parent::content();\r
23 \r
24                 $a = self::getApp();\r
25 \r
26                 // are there MyISAM tables in the DB? If so, trigger a warning message\r
27                 $warningtext = [];\r
28                 if (DBA::count('`information_schema`.`tables`', ['engine' => 'myisam', 'table_schema' => DBA::databaseName()])) {\r
29                         $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');\r
30                 }\r
31 \r
32                 // Check if github.com/friendica/master/VERSION is higher then\r
33                 // the local version of Friendica. Check is opt-in, source may be master or devel branch\r
34                 if (Config::get('system', 'check_new_version_url', 'none') != 'none') {\r
35                         $gitversion = Config::get('system', 'git_friendica_version');\r
36                         if (version_compare(FRIENDICA_VERSION, $gitversion) < 0) {\r
37                                 $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);\r
38                         }\r
39                 }\r
40 \r
41                 if (Config::get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) {\r
42                         DBStructure::update($a->getBasePath(), false, true);\r
43                 }\r
44 \r
45                 if (Config::get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) {\r
46                         $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.');\r
47                 }\r
48 \r
49                 if (Config::get('system', 'update') == Update::FAILED) {\r
50                         $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.)');\r
51                 }\r
52 \r
53                 $last_worker_call = Config::get('system', 'last_worker_execution', false);\r
54                 if (!$last_worker_call) {\r
55                         $warningtext[] = L10n::t('The worker was never executed. Please check your database structure!');\r
56                 } elseif ((strtotime(DateTimeFormat::utcNow()) - strtotime($last_worker_call)) > 60 * 60) {\r
57                         $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);\r
58                 }\r
59 \r
60                 // Legacy config file warning\r
61                 if (file_exists('.htconfig.php')) {\r
62                         $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');\r
63                 }\r
64 \r
65                 if (file_exists('config/local.ini.php')) {\r
66                         $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');\r
67                 }\r
68 \r
69                 // Check server vitality\r
70                 if (!self::checkSelfHostMeta()) {\r
71                         $well_known = $a->getBaseURL() . '/.well-known/host-meta';\r
72                         $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.',\r
73                                 $well_known, $well_known, $a->getBaseURL() . '/help/Install');\r
74                 }\r
75 \r
76                 $accounts = [\r
77                         [L10n::t('Normal Account'), 0],\r
78                         [L10n::t('Automatic Follower Account'), 0],\r
79                         [L10n::t('Public Forum Account'), 0],\r
80                         [L10n::t('Automatic Friend Account'), 0],\r
81                         [L10n::t('Blog Account'), 0],\r
82                         [L10n::t('Private Forum Account'), 0]\r
83                 ];\r
84 \r
85                 $users = 0;\r
86                 $pageFlagsCountStmt = DBA::p('SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`');\r
87                 while ($pageFlagsCount = DBA::fetch($pageFlagsCountStmt)) {\r
88                         $accounts[$pageFlagsCount['page-flags']][1] = $pageFlagsCount['count'];\r
89                         $users += $pageFlagsCount['count'];\r
90                 }\r
91                 DBA::close($pageFlagsCountStmt);\r
92 \r
93                 Logger::log('accounts: ' . print_r($accounts, true), Logger::DATA);\r
94 \r
95                 $pending = Register::getPendingCount();\r
96 \r
97                 $queue = DBA::count('queue', []);\r
98 \r
99                 $deferred = DBA::count('workerqueue', ['`executed` <= ? AND NOT `done` AND `next_try` > ?',\r
100                         DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);\r
101 \r
102                 $workerqueue = DBA::count('workerqueue', ['`executed` <= ? AND NOT `done` AND `next_try` < ?',\r
103                         DBA::NULL_DATETIME, DateTimeFormat::utcNow()]);\r
104 \r
105                 // We can do better, but this is a quick queue status\r
106                 $queues = ['label' => L10n::t('Message queues'), 'queue' => $queue, 'deferred' => $deferred, 'workerq' => $workerqueue];\r
107 \r
108                 $variables = DBA::toArray(DBA::p('SHOW variables LIKE "max_allowed_packet"'));\r
109                 $max_allowed_packet = $variables ? $variables[0]['Value'] : 0;\r
110 \r
111                 $server_settings = [\r
112                         'label' => L10n::t('Server Settings'),\r
113                         'php' => [\r
114                                 'upload_max_filesize' => ini_get('upload_max_filesize'),\r
115                                 'post_max_size' => ini_get('post_max_size'),\r
116                                 'memory_limit' => ini_get('memory_limit')\r
117                         ],\r
118                         'mysql' => [\r
119                                 'max_allowed_packet' => $max_allowed_packet\r
120                         ]\r
121                 ];\r
122 \r
123                 $t = Renderer::getMarkupTemplate('admin/summary.tpl');\r
124                 return Renderer::replaceMacros($t, [\r
125                         '$title' => L10n::t('Administration'),\r
126                         '$page' => L10n::t('Summary'),\r
127                         '$queues' => $queues,\r
128                         '$users' => [L10n::t('Registered users'), $users],\r
129                         '$accounts' => $accounts,\r
130                         '$pending' => [L10n::t('Pending registrations'), $pending],\r
131                         '$version' => [L10n::t('Version'), FRIENDICA_VERSION],\r
132                         '$platform' => FRIENDICA_PLATFORM,\r
133                         '$codename' => FRIENDICA_CODENAME,\r
134                         '$build' => Config::get('system', 'build'),\r
135                         '$addons' => [L10n::t('Active addons'), Addon::getEnabledList()],\r
136                         '$serversettings' => $server_settings,\r
137                         '$warningtext' => $warningtext\r
138                 ]);\r
139         }\r
140 \r
141         private static function checkSelfHostMeta()\r
142         {\r
143                 // Fetch the host-meta to check if this really is a vital server\r
144                 return Network::curl(self::getApp()->getBaseURL() . '/.well-known/host-meta')->isSuccess();\r
145         }\r
146 \r
147 }