2019-05-02 04:01:43 +00:00
< ? php
2020-02-09 14:45:36 +00:00
/**
2021-03-29 06:40:20 +00:00
* @ copyright Copyright ( C ) 2010 - 2021 , the Friendica project
2020-02-09 14:45:36 +00:00
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*
*/
2019-05-02 04:01:43 +00:00
namespace Friendica\Module\Admin\Logs ;
use Friendica\Core\Renderer ;
2019-12-15 21:34:11 +00:00
use Friendica\DI ;
2020-01-23 04:14:14 +00:00
use Friendica\Module\BaseAdmin ;
2019-05-02 04:01:43 +00:00
use Friendica\Util\Strings ;
use Psr\Log\LogLevel ;
2020-01-23 04:14:14 +00:00
class Settings extends BaseAdmin
2019-05-02 04:01:43 +00:00
{
2021-11-14 22:13:47 +00:00
public function post ()
2019-05-02 04:01:43 +00:00
{
2020-09-08 14:44:27 +00:00
self :: checkAdminAccess ();
2019-05-02 04:01:43 +00:00
2020-09-08 14:42:25 +00:00
if ( empty ( $_POST [ 'page_logs' ])) {
return ;
}
2019-05-02 04:01:43 +00:00
2020-09-08 14:42:25 +00:00
self :: checkFormSecurityTokenRedirectOnError ( '/admin/logs' , 'admin_logs' );
2019-05-02 04:01:43 +00:00
2021-11-05 19:59:18 +00:00
$logfile = ( ! empty ( $_POST [ 'logfile' ]) ? trim ( $_POST [ 'logfile' ]) : '' );
2020-09-08 14:42:25 +00:00
$debugging = ! empty ( $_POST [ 'debugging' ]);
$loglevel = ( $_POST [ 'loglevel' ] ? ? '' ) ? : LogLevel :: ERROR ;
2019-05-26 12:33:09 +00:00
2020-09-08 14:42:25 +00:00
if ( is_file ( $logfile ) &&
! is_writeable ( $logfile )) {
notice ( DI :: l10n () -> t ( 'The logfile \'%s\' is not writable. No logging possible' , $logfile ));
return ;
2019-05-02 04:01:43 +00:00
}
2020-09-08 14:42:25 +00:00
DI :: config () -> set ( 'system' , 'logfile' , $logfile );
DI :: config () -> set ( 'system' , 'debugging' , $debugging );
DI :: config () -> set ( 'system' , 'loglevel' , $loglevel );
2019-12-15 23:28:31 +00:00
DI :: baseUrl () -> redirect ( 'admin/logs' );
2019-05-02 04:01:43 +00:00
}
2021-11-14 22:13:47 +00:00
public function content () : string
2019-05-02 04:01:43 +00:00
{
2021-11-14 19:46:25 +00:00
parent :: content ();
2019-05-02 04:01:43 +00:00
$log_choices = [
LogLevel :: ERROR => 'Error' ,
LogLevel :: WARNING => 'Warning' ,
LogLevel :: NOTICE => 'Notice' ,
LogLevel :: INFO => 'Info' ,
LogLevel :: DEBUG => 'Debug' ,
];
if ( ini_get ( 'log_errors' )) {
2020-01-18 19:52:34 +00:00
$phplogenabled = DI :: l10n () -> t ( 'PHP log currently enabled.' );
2019-05-02 04:01:43 +00:00
} else {
2020-01-18 19:52:34 +00:00
$phplogenabled = DI :: l10n () -> t ( 'PHP log currently disabled.' );
2019-05-02 04:01:43 +00:00
}
$t = Renderer :: getMarkupTemplate ( 'admin/logs/settings.tpl' );
return Renderer :: replaceMacros ( $t , [
2020-01-18 19:52:34 +00:00
'$title' => DI :: l10n () -> t ( 'Administration' ),
'$page' => DI :: l10n () -> t ( 'Logs' ),
'$submit' => DI :: l10n () -> t ( 'Save Settings' ),
'$clear' => DI :: l10n () -> t ( 'Clear' ),
2019-12-16 00:05:15 +00:00
'$baseurl' => DI :: baseUrl () -> get ( true ),
2020-01-19 20:21:13 +00:00
'$logname' => DI :: config () -> get ( 'system' , 'logfile' ),
2019-05-02 04:01:43 +00:00
// see /help/smarty3-templates#1_1 on any Friendica node
2020-01-19 20:21:13 +00:00
'$debugging' => [ 'debugging' , DI :: l10n () -> t ( " Enable Debugging " ), DI :: config () -> get ( 'system' , 'debugging' ), " " ],
'$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. " )],
'$loglevel' => [ 'loglevel' , DI :: l10n () -> t ( " Log level " ), DI :: config () -> get ( 'system' , 'loglevel' ), " " , $log_choices ],
2020-09-08 14:42:25 +00:00
'$form_security_token' => self :: getFormSecurityToken ( " admin_logs " ),
2020-01-18 19:52:34 +00:00
'$phpheader' => DI :: l10n () -> t ( " PHP logging " ),
'$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. " ),
2019-05-02 04:01:43 +00:00
'$phplogcode' => " error_reporting(E_ERROR | E_WARNING | E_PARSE); \n ini_set('error_log','php.out'); \n ini_set('log_errors','1'); \n ini_set('display_errors', '1'); " ,
'$phplogenabled' => $phplogenabled ,
]);
}
}