]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Logs/Settings.php
Remove deprecated App::query_string - replace with DI::args()->getQueryString()
[friendica.git] / src / Module / Admin / Logs / Settings.php
1 <?php
2
3 namespace Friendica\Module\Admin\Logs;
4
5 use Friendica\Core\Config;
6 use Friendica\Core\L10n;
7 use Friendica\Core\Renderer;
8 use Friendica\DI;
9 use Friendica\Module\BaseAdminModule;
10 use Friendica\Util\Strings;
11 use Psr\Log\LogLevel;
12
13 class Settings extends BaseAdminModule
14 {
15         public static function post(array $parameters = [])
16         {
17                 parent::post($parameters);
18
19                 if (!empty($_POST['page_logs'])) {
20                         parent::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
21
22                         $logfile   = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');
23                         $debugging = !empty($_POST['debugging']);
24                         $loglevel  = ($_POST['loglevel'] ?? '') ?: LogLevel::ERROR;
25
26                         if (is_file($logfile) &&
27                         !is_writeable($logfile)) {
28                                 notice(L10n::t('The logfile \'%s\' is not writable. No logging possible', $logfile));
29                                 return;
30                         }
31
32                         Config::set('system', 'logfile', $logfile);
33                         Config::set('system', 'debugging', $debugging);
34                         Config::set('system', 'loglevel', $loglevel);
35                 }
36
37                 info(L10n::t("Log settings updated."));
38                 DI::baseUrl()->redirect('admin/logs');
39         }
40
41         public static function content(array $parameters = [])
42         {
43                 parent::content($parameters);
44
45                 $log_choices = [
46                         LogLevel::ERROR   => 'Error',
47                         LogLevel::WARNING => 'Warning',
48                         LogLevel::NOTICE  => 'Notice',
49                         LogLevel::INFO    => 'Info',
50                         LogLevel::DEBUG   => 'Debug',
51                 ];
52
53                 if (ini_get('log_errors')) {
54                         $phplogenabled = L10n::t('PHP log currently enabled.');
55                 } else {
56                         $phplogenabled = L10n::t('PHP log currently disabled.');
57                 }
58
59                 $t = Renderer::getMarkupTemplate('admin/logs/settings.tpl');
60
61                 return Renderer::replaceMacros($t, [
62                         '$title' => L10n::t('Administration'),
63                         '$page' => L10n::t('Logs'),
64                         '$submit' => L10n::t('Save Settings'),
65                         '$clear' => L10n::t('Clear'),
66                         '$baseurl' => DI::baseUrl()->get(true),
67                         '$logname' => Config::get('system', 'logfile'),
68                         // see /help/smarty3-templates#1_1 on any Friendica node
69                         '$debugging' => ['debugging', L10n::t("Enable Debugging"), Config::get('system', 'debugging'), ""],
70                         '$logfile' => ['logfile', L10n::t("Log file"), Config::get('system', 'logfile'), L10n::t("Must be writable by web server. Relative to your Friendica top-level directory.")],
71                         '$loglevel' => ['loglevel', L10n::t("Log level"), Config::get('system', 'loglevel'), "", $log_choices],
72                         '$form_security_token' => parent::getFormSecurityToken("admin_logs"),
73                         '$phpheader' => L10n::t("PHP logging"),
74                         '$phphint' => 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."),
75                         '$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');",
76                         '$phplogenabled' => $phplogenabled,
77                 ]);
78         }
79 }