]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Summary.php
cfd9aa984041edc7e2d7ed389601f9be3e27eeef
[friendica.git] / src / Module / Admin / Summary.php
1 <?php
2
3 namespace Friendica\Module\Admin;
4
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\Network\HTTPException\InternalServerErrorException;
16 use Friendica\Util\ConfigFileLoader;
17 use Friendica\Util\DateTimeFormat;
18 use Friendica\Util\FileSystem;
19 use Friendica\Util\Network;
20
21 class Summary extends BaseAdminModule
22 {
23         public static function content()
24         {
25                 parent::content();
26
27                 $a = self::getApp();
28
29                 // are there MyISAM tables in the DB? If so, trigger a warning message
30                 $warningtext = [];
31                 if (DBA::count(['information_schema' => 'tables'], ['engine' => 'myisam', 'table_schema' => DBA::databaseName()])) {
32                         $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                 }
34
35                 // Check if github.com/friendica/master/VERSION is higher then
36                 // the local version of Friendica. Check is opt-in, source may be master or devel branch
37                 if (Config::get('system', 'check_new_version_url', 'none') != 'none') {
38                         $gitversion = Config::get('system', 'git_friendica_version');
39                         if (version_compare(FRIENDICA_VERSION, $gitversion) < 0) {
40                                 $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);
41                         }
42                 }
43
44                 if (Config::get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) {
45                         DBStructure::update($a->getBasePath(), false, true);
46                 }
47
48                 if (Config::get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) {
49                         $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                 }
51
52                 if (Config::get('system', 'update') == Update::FAILED) {
53                         $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                 }
55
56                 $last_worker_call = Config::get('system', 'last_worker_execution', false);
57                 if (!$last_worker_call) {
58                         $warningtext[] = L10n::t('The worker was never executed. Please check your database structure!');
59                 } elseif ((strtotime(DateTimeFormat::utcNow()) - strtotime($last_worker_call)) > 60 * 60) {
60                         $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                 }
62
63                 // Legacy config file warning
64                 if (file_exists('.htconfig.php')) {
65                         $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                 }
67
68                 if (file_exists('config/local.ini.php')) {
69                         $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                 }
71
72                 // Check server vitality
73                 if (!self::checkSelfHostMeta()) {
74                         $well_known = $a->getBaseURL() . '/.well-known/host-meta';
75                         $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.',
76                                 $well_known, $well_known, $a->getBaseURL() . '/help/Install');
77                 }
78
79                 // Check logfile permission
80                 if (Config::get('system', 'debugging')) {
81                         $file = Config::get('system', 'logfile');
82
83                         /** @var FileSystem $fileSystem */
84                         $fileSystem = self::getClass(FileSystem::class);
85
86                         try {
87                                 $stream = $fileSystem->createStream($file);
88
89                                 if (!isset($stream)) {
90                                         throw new InternalServerErrorException('Stream is null.');
91                                 }
92
93                         } catch (\Throwable $exception) {
94                                 $warningtext[] = L10n::t('The logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
95                         }
96
97                         $file = Config::get('system', 'dlogfile');
98
99                         try {
100                                 if (!empty($file)) {
101                                         $stream = $fileSystem->createStream($file);
102
103                                         if (!isset($stream)) {
104                                                 throw new InternalServerErrorException('Stream is null.');
105                                         }
106                                 }
107
108                         } catch (\Throwable $exception) {
109                                 $warningtext[] = L10n::t('The debug logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
110                         }
111                 }
112
113                 // check legacy basepath settings
114                 $configLoader = new ConfigFileLoader($a->getBasePath(), $a->getMode());
115                 $configCache = new Config\Cache\ConfigCache();
116                 $configLoader->setupCache($configCache);
117                 $confBasepath = $configCache->get('system', 'basepath');
118                 $currBasepath = $a->getConfig()->get('system', 'basepath');
119                 if ($confBasepath !== $currBasepath || !is_dir($currBasepath)) {
120                         if (is_dir($confBasepath) && Config::set('system', 'basepath', $confBasepath)) {
121                                 $a->getLogger()->info('Friendica\'s system.basepath was updated successfully.', [
122                                         'from' => $currBasepath,
123                                         'to'   => $confBasepath,
124                                 ]);
125                                 $warningtext[] = L10n::t('Friendica\'s system.basepath was updated from \'%s\' to \'%s\'. Please remove the system.basepath from your db to avoid differences.',
126                                         $currBasepath,
127                                         $confBasepath);
128                         } elseif (!is_dir($currBasepath)) {
129                                 $a->getLogger()->alert('Friendica\'s system.basepath is wrong.', [
130                                         'from' => $currBasepath,
131                                         'to'   => $confBasepath,
132                                 ]);
133                                 $warningtext[] = L10n::t('Friendica\'s current system.basepath \'%s\' is wrong and the config file \'%s\' isn\'t used.',
134                                         $currBasepath,
135                                         $confBasepath);
136                         } else {
137                                 $a->getLogger()->alert('Friendica\'s system.basepath is wrong.', [
138                                         'from' => $currBasepath,
139                                         'to'   => $confBasepath,
140                                 ]);
141                                 $warningtext[] = L10n::t('Friendica\'s current system.basepath \'%s\' is not equal to the config file \'%s\'. Please fix your configuration.',
142                                         $currBasepath,
143                                         $confBasepath);
144                         }
145                 }
146
147                 $accounts = [
148                         [L10n::t('Normal Account'), 0],
149                         [L10n::t('Automatic Follower Account'), 0],
150                         [L10n::t('Public Forum Account'), 0],
151                         [L10n::t('Automatic Friend Account'), 0],
152                         [L10n::t('Blog Account'), 0],
153                         [L10n::t('Private Forum Account'), 0]
154                 ];
155
156                 $users = 0;
157                 $pageFlagsCountStmt = DBA::p('SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`');
158                 while ($pageFlagsCount = DBA::fetch($pageFlagsCountStmt)) {
159                         $accounts[$pageFlagsCount['page-flags']][1] = $pageFlagsCount['count'];
160                         $users += $pageFlagsCount['count'];
161                 }
162                 DBA::close($pageFlagsCountStmt);
163
164                 Logger::log('accounts: ' . print_r($accounts, true), Logger::DATA);
165
166                 $pending = Register::getPendingCount();
167
168                 $deferred = DBA::count('workerqueue', ['NOT `done` AND `retrial` > ?', 0]);
169
170                 $workerqueue = DBA::count('workerqueue', ['NOT `done` AND `retrial` = ?', 0]);
171
172                 // We can do better, but this is a quick queue status
173                 $queues = ['label' => L10n::t('Message queues'), 'deferred' => $deferred, 'workerq' => $workerqueue];
174
175                 $variables = DBA::toArray(DBA::p('SHOW variables LIKE "max_allowed_packet"'));
176                 $max_allowed_packet = $variables ? $variables[0]['Value'] : 0;
177
178                 $server_settings = [
179                         'label' => L10n::t('Server Settings'),
180                         'php' => [
181                                 'upload_max_filesize' => ini_get('upload_max_filesize'),
182                                 'post_max_size' => ini_get('post_max_size'),
183                                 'memory_limit' => ini_get('memory_limit')
184                         ],
185                         'mysql' => [
186                                 'max_allowed_packet' => $max_allowed_packet
187                         ]
188                 ];
189
190                 $t = Renderer::getMarkupTemplate('admin/summary.tpl');
191                 return Renderer::replaceMacros($t, [
192                         '$title' => L10n::t('Administration'),
193                         '$page' => L10n::t('Summary'),
194                         '$queues' => $queues,
195                         '$users' => [L10n::t('Registered users'), $users],
196                         '$accounts' => $accounts,
197                         '$pending' => [L10n::t('Pending registrations'), $pending],
198                         '$version' => [L10n::t('Version'), FRIENDICA_VERSION],
199                         '$platform' => FRIENDICA_PLATFORM,
200                         '$codename' => FRIENDICA_CODENAME,
201                         '$build' => Config::get('system', 'build'),
202                         '$addons' => [L10n::t('Active addons'), Addon::getEnabledList()],
203                         '$serversettings' => $server_settings,
204                         '$warningtext' => $warningtext
205                 ]);
206         }
207
208         private static function checkSelfHostMeta()
209         {
210                 // Fetch the host-meta to check if this really is a vital server
211                 return Network::curl(self::getApp()->getBaseURL() . '/.well-known/host-meta')->isSuccess();
212         }
213
214 }