]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Logs/Settings.php
Some removed escapeTags calls
[friendica.git] / src / Module / Admin / Logs / Settings.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
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 use Psr\Log\LogLevel;
29
30 class Settings extends BaseAdmin
31 {
32         public static function post(array $parameters = [])
33         {
34                 self::checkAdminAccess();
35
36                 if (empty($_POST['page_logs'])) {
37                         return;
38                 }
39
40                 self::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
41
42                 $logfile   = (!empty($_POST['logfile']) ? trim($_POST['logfile']) : '');
43                 $debugging = !empty($_POST['debugging']);
44                 $loglevel  = ($_POST['loglevel'] ?? '') ?: LogLevel::ERROR;
45
46                 if (is_file($logfile) &&
47                 !is_writeable($logfile)) {
48                         notice(DI::l10n()->t('The logfile \'%s\' is not writable. No logging possible', $logfile));
49                         return;
50                 }
51
52                 DI::config()->set('system', 'logfile', $logfile);
53                 DI::config()->set('system', 'debugging', $debugging);
54                 DI::config()->set('system', 'loglevel', $loglevel);
55
56                 DI::baseUrl()->redirect('admin/logs');
57         }
58
59         public static function content(array $parameters = [])
60         {
61                 parent::content($parameters);
62
63                 $log_choices = [
64                         LogLevel::ERROR   => 'Error',
65                         LogLevel::WARNING => 'Warning',
66                         LogLevel::NOTICE  => 'Notice',
67                         LogLevel::INFO    => 'Info',
68                         LogLevel::DEBUG   => 'Debug',
69                 ];
70
71                 if (ini_get('log_errors')) {
72                         $phplogenabled = DI::l10n()->t('PHP log currently enabled.');
73                 } else {
74                         $phplogenabled = DI::l10n()->t('PHP log currently disabled.');
75                 }
76
77                 $t = Renderer::getMarkupTemplate('admin/logs/settings.tpl');
78
79                 return Renderer::replaceMacros($t, [
80                         '$title' => DI::l10n()->t('Administration'),
81                         '$page' => DI::l10n()->t('Logs'),
82                         '$submit' => DI::l10n()->t('Save Settings'),
83                         '$clear' => DI::l10n()->t('Clear'),
84                         '$baseurl' => DI::baseUrl()->get(true),
85                         '$logname' => DI::config()->get('system', 'logfile'),
86                         // see /help/smarty3-templates#1_1 on any Friendica node
87                         '$debugging' => ['debugging', DI::l10n()->t("Enable Debugging"), DI::config()->get('system', 'debugging'), ""],
88                         '$logfile' => ['logfile', DI::l10n()->t("Log file"), DI::config()->get('system', 'logfile'), DI::l10n()->t("Must be writable by web server. Relative to your Friendica top-level directory.")],
89                         '$loglevel' => ['loglevel', DI::l10n()->t("Log level"), DI::config()->get('system', 'loglevel'), "", $log_choices],
90                         '$form_security_token' => self::getFormSecurityToken("admin_logs"),
91                         '$phpheader' => DI::l10n()->t("PHP logging"),
92                         '$phphint' => DI::l10n()->t("To temporarily enable logging of PHP errors and warnings you can prepend the following to the index.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."),
93                         '$phplogcode' => "error_reporting(E_ERROR | E_WARNING | E_PARSE);\nini_set('error_log','php.out');\nini_set('log_errors','1');\nini_set('display_errors', '1');",
94                         '$phplogenabled' => $phplogenabled,
95                 ]);
96         }
97 }