]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Logs/View.php
Fix security vulnerability in admin modules
[friendica.git] / src / Module / Admin / Logs / View.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Module\Admin\Logs;
23
24 use Friendica\Core\Renderer;
25 use Friendica\DI;
26 use Friendica\Module\BaseAdmin;
27 use Friendica\Util\Strings;
28
29 class View extends BaseAdmin
30 {
31         public static function content(array $parameters = [])
32         {
33                 parent::content($parameters);
34
35                 $t = Renderer::getMarkupTemplate('admin/logs/view.tpl');
36                 $f = DI::config()->get('system', 'logfile');
37                 $data = '';
38
39                 if (!file_exists($f)) {
40                         $data = DI::l10n()->t('Error trying to open <strong>%1$s</strong> log file.\r\n<br/>Check to see if file %1$s exist and is readable.', $f);
41                 } else {
42                         $fp = fopen($f, 'r');
43                         if (!$fp) {
44                                 $data = DI::l10n()->t('Couldn\'t open <strong>%1$s</strong> log file.\r\n<br/>Check to see if file %1$s is readable.', $f);
45                         } else {
46                                 $fstat = fstat($fp);
47                                 $size = $fstat['size'];
48                                 if ($size != 0) {
49                                         if ($size > 5000000 || $size < 0) {
50                                                 $size = 5000000;
51                                         }
52                                         $seek = fseek($fp, 0 - $size, SEEK_END);
53                                         if ($seek === 0) {
54                                                 $data = Strings::escapeHtml(fread($fp, $size));
55                                                 while (!feof($fp)) {
56                                                         $data .= Strings::escapeHtml(fread($fp, 4096));
57                                                 }
58                                         }
59                                 }
60                                 fclose($fp);
61                         }
62                 }
63                 return Renderer::replaceMacros($t, [
64                         '$title' => DI::l10n()->t('Administration'),
65                         '$page' => DI::l10n()->t('View Logs'),
66                         '$data' => $data,
67                         '$logname' => DI::config()->get('system', 'logfile')
68                 ]);
69         }
70 }