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