$return_path = 'admin';
if ($a->argc > 1) {
switch ($a->argv[1]) {
- case 'logs':
- admin_page_logs_post($a);
- break;
case 'deleteitem':
admin_page_deleteitem_post($a);
break;
// urls
if ($a->argc > 1) {
switch ($a->argv[1]) {
- case 'logs':
- $o = admin_page_logs($a);
- break;
- case 'viewlogs':
- $o = admin_page_viewlogs($a);
- break;
case 'dbsync':
$o = admin_page_dbsync($a);
break;
return $o;
}
-/**
- * @brief Prosesses data send by Logs admin page
- *
- * @param App $a
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
-function admin_page_logs_post(App $a)
-{
- if (!empty($_POST['page_logs'])) {
- BaseModule::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');
-
- $logfile = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');
- $debugging = !empty($_POST['debugging']);
- $loglevel = defaults($_POST, 'loglevel', LogLevel::ERROR);
-
- Config::set('system', 'logfile', $logfile);
- Config::set('system', 'debugging', $debugging);
- Config::set('system', 'loglevel', $loglevel);
- }
-
- info(L10n::t("Log settings updated."));
- $a->internalRedirect('admin/logs');
- return; // NOTREACHED
-}
-
-/**
- * @brief Generates admin panel subpage for configuration of the logs
- *
- * This function take the view/templates/admin_logs.tpl file and generates a
- * page where admin can configure the logging of friendica.
- *
- * Displaying the log is separated from the log config as the logfile can get
- * big depending on the settings and changing settings regarding the logs can
- * thus waste bandwidth.
- *
- * The string returned contains the content of the template file with replaced
- * macros.
- *
- * @param App $a
- * @return string
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
-function admin_page_logs(App $a)
-{
- $log_choices = [
- LogLevel::ERROR => 'Error',
- LogLevel::WARNING => 'Warning',
- LogLevel::NOTICE => 'Notice',
- LogLevel::INFO => 'Info',
- LogLevel::DEBUG => 'Debug',
- ];
-
- if (ini_get('log_errors')) {
- $phplogenabled = L10n::t('PHP log currently enabled.');
- } else {
- $phplogenabled = L10n::t('PHP log currently disabled.');
- }
-
- $t = Renderer::getMarkupTemplate('admin/logs.tpl');
-
- return Renderer::replaceMacros($t, [
- '$title' => L10n::t('Administration'),
- '$page' => L10n::t('Logs'),
- '$submit' => L10n::t('Save Settings'),
- '$clear' => L10n::t('Clear'),
- '$baseurl' => System::baseUrl(true),
- '$logname' => Config::get('system', 'logfile'),
- // name, label, value, help string, extra data...
- '$debugging' => ['debugging', L10n::t("Enable Debugging"), Config::get('system', 'debugging'), ""],
- '$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.")],
- '$loglevel' => ['loglevel', L10n::t("Log level"), Config::get('system', 'loglevel'), "", $log_choices],
- '$form_security_token' => BaseModule::getFormSecurityToken("admin_logs"),
- '$phpheader' => L10n::t("PHP logging"),
- '$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."),
- '$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');",
- '$phplogenabled' => $phplogenabled,
- ]);
-}
-
-/**
- * @brief Generates admin panel subpage to view the Friendica log
- *
- * This function loads the template view/templates/admin_viewlogs.tpl to
- * display the systemlog content. The filename for the systemlog of friendica
- * is relative to the base directory and taken from the config entry 'logfile'
- * in the 'system' category.
- *
- * Displaying the log is separated from the log config as the logfile can get
- * big depending on the settings and changing settings regarding the logs can
- * thus waste bandwidth.
- *
- * The string returned contains the content of the template file with replaced
- * macros.
- *
- * @param App $a
- * @return string
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
-function admin_page_viewlogs(App $a)
-{
- $t = Renderer::getMarkupTemplate('admin/viewlogs.tpl');
- $f = Config::get('system', 'logfile');
- $data = '';
-
- if (!file_exists($f)) {
- $data = 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);
- } else {
- $fp = fopen($f, 'r');
- if (!$fp) {
- $data = L10n::t('Couldn\'t open <strong>%1$s</strong> log file.\r\n<br/>Check to see if file %1$s is readable.', $f);
- } else {
- $fstat = fstat($fp);
- $size = $fstat['size'];
- if ($size != 0) {
- if ($size > 5000000 || $size < 0) {
- $size = 5000000;
- }
- $seek = fseek($fp, 0 - $size, SEEK_END);
- if ($seek === 0) {
- $data = Strings::escapeHtml(fread($fp, $size));
- while (!feof($fp)) {
- $data .= Strings::escapeHtml(fread($fp, 4096));
- }
- }
- }
- fclose($fp);
- }
- }
- return Renderer::replaceMacros($t, [
- '$title' => L10n::t('Administration'),
- '$page' => L10n::t('View Logs'),
- '$data' => $data,
- '$logname' => Config::get('system', 'logfile')
- ]);
-}
-
function admin_page_server_vital()
{
// Fetch the host-meta to check if this really is a vital server
$collector->addRoute(['GET', 'POST'], '/features' , Module\Admin\Features::class);
$collector->addRoute(['GET'] , '/federation' , Module\Admin\Federation::class);
+ $collector->addRoute(['GET'] , '/logs/view' , Module\Admin\Logs\View::class);
+ $collector->addRoute(['GET', 'POST'], '/logs' , Module\Admin\Logs\Settings::class);
+
$collector->addRoute(['GET'] , '/queue[/deferred]' , Module\Admin\Queue::class);
$collector->addRoute(['GET', 'POST'], '/site' , Module\Admin\Site::class);
--- /dev/null
+<?php\r
+\r
+namespace Friendica\Module\Admin\Logs;\r
+\r
+use Friendica\Core\Config;\r
+use Friendica\Core\L10n;\r
+use Friendica\Core\Renderer;\r
+use Friendica\Core\System;\r
+use Friendica\Module\BaseAdminModule;\r
+use Friendica\Util\Strings;\r
+use Psr\Log\LogLevel;\r
+\r
+class Settings extends BaseAdminModule\r
+{\r
+ public static function post()\r
+ {\r
+ parent::post();\r
+\r
+ if (!empty($_POST['page_logs'])) {\r
+ parent::checkFormSecurityTokenRedirectOnError('/admin/logs', 'admin_logs');\r
+\r
+ $logfile = (!empty($_POST['logfile']) ? Strings::escapeTags(trim($_POST['logfile'])) : '');\r
+ $debugging = !empty($_POST['debugging']);\r
+ $loglevel = defaults($_POST, 'loglevel', LogLevel::ERROR);\r
+\r
+ Config::set('system', 'logfile', $logfile);\r
+ Config::set('system', 'debugging', $debugging);\r
+ Config::set('system', 'loglevel', $loglevel);\r
+ }\r
+\r
+ info(L10n::t("Log settings updated."));\r
+ self::getApp()->internalRedirect('admin/logs');\r
+ }\r
+\r
+ public static function content()\r
+ {\r
+ parent::content();\r
+\r
+ $log_choices = [\r
+ LogLevel::ERROR => 'Error',\r
+ LogLevel::WARNING => 'Warning',\r
+ LogLevel::NOTICE => 'Notice',\r
+ LogLevel::INFO => 'Info',\r
+ LogLevel::DEBUG => 'Debug',\r
+ ];\r
+\r
+ if (ini_get('log_errors')) {\r
+ $phplogenabled = L10n::t('PHP log currently enabled.');\r
+ } else {\r
+ $phplogenabled = L10n::t('PHP log currently disabled.');\r
+ }\r
+\r
+ $t = Renderer::getMarkupTemplate('admin/logs/settings.tpl');\r
+\r
+ return Renderer::replaceMacros($t, [\r
+ '$title' => L10n::t('Administration'),\r
+ '$page' => L10n::t('Logs'),\r
+ '$submit' => L10n::t('Save Settings'),\r
+ '$clear' => L10n::t('Clear'),\r
+ '$baseurl' => System::baseUrl(true),\r
+ '$logname' => Config::get('system', 'logfile'),\r
+ // name, label, value, help string, extra data...\r
+ '$debugging' => ['debugging', L10n::t("Enable Debugging"), Config::get('system', 'debugging'), ""],\r
+ '$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.")],\r
+ '$loglevel' => ['loglevel', L10n::t("Log level"), Config::get('system', 'loglevel'), "", $log_choices],\r
+ '$form_security_token' => parent::getFormSecurityToken("admin_logs"),\r
+ '$phpheader' => L10n::t("PHP logging"),\r
+ '$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."),\r
+ '$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');",\r
+ '$phplogenabled' => $phplogenabled,\r
+ ]);\r
+ }\r
+}\r
--- /dev/null
+<?php\r
+\r
+namespace Friendica\Module\Admin\Logs;\r
+\r
+use Friendica\Core\Config;\r
+use Friendica\Core\L10n;\r
+use Friendica\Core\Renderer;\r
+use Friendica\Module\BaseAdminModule;\r
+use Friendica\Util\Strings;\r
+\r
+class View extends BaseAdminModule\r
+{\r
+ public static function content()\r
+ {\r
+ parent::content();\r
+\r
+ $t = Renderer::getMarkupTemplate('admin/logs/view.tpl');\r
+ $f = Config::get('system', 'logfile');\r
+ $data = '';\r
+\r
+ if (!file_exists($f)) {\r
+ $data = 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);\r
+ } else {\r
+ $fp = fopen($f, 'r');\r
+ if (!$fp) {\r
+ $data = L10n::t('Couldn\'t open <strong>%1$s</strong> log file.\r\n<br/>Check to see if file %1$s is readable.', $f);\r
+ } else {\r
+ $fstat = fstat($fp);\r
+ $size = $fstat['size'];\r
+ if ($size != 0) {\r
+ if ($size > 5000000 || $size < 0) {\r
+ $size = 5000000;\r
+ }\r
+ $seek = fseek($fp, 0 - $size, SEEK_END);\r
+ if ($seek === 0) {\r
+ $data = Strings::escapeHtml(fread($fp, $size));\r
+ while (!feof($fp)) {\r
+ $data .= Strings::escapeHtml(fread($fp, 4096));\r
+ }\r
+ }\r
+ }\r
+ fclose($fp);\r
+ }\r
+ }\r
+ return Renderer::replaceMacros($t, [\r
+ '$title' => L10n::t('Administration'),\r
+ '$page' => L10n::t('View Logs'),\r
+ '$data' => $data,\r
+ '$logname' => Config::get('system', 'logfile')\r
+ ]);\r
+ }\r
+}\r
'contactblock' => ['admin/blocklist/contact', L10n::t('Contact Blocklist') , 'contactblock'],\r
'blocklist' => ['admin/blocklist/server' , L10n::t('Server Blocklist') , 'blocklist'],\r
]],\r
+ 'logs' => [L10n::t('Logs'), [\r
+ 'logsconfig' => ['admin/logs/', L10n::t('Logs') , 'logs'],\r
+ 'logsview' => ['admin/logs/view' , L10n::t('View Logs') , 'viewlogs'],\r
+ ]],\r
];\r
\r
$addons_admin = [];\r
+++ /dev/null
-<div id='adminpage'>
- <h1>{{$title}} - {{$page}}</h1>
-
- <form action="{{$baseurl}}/admin/logs" method="post">
- <input type='hidden' name='form_security_token' value="{{$form_security_token}}">
-
- {{include file="field_checkbox.tpl" field=$debugging}}
- {{include file="field_input.tpl" field=$logfile}}
- {{include file="field_select.tpl" field=$loglevel}}
-
- <div class="submit"><input type="submit" name="page_logs" value="{{$submit}}" /></div>
-
- </form>
-
- <h2>{{$phpheader}}</h2>
- <div>
- <p>{{$phplogenabled}}<p>
- <p>{{$phphint}}</p>
- <pre>{{$phplogcode}}</pre>
- </div>
-
-</div>
--- /dev/null
+<div id='adminpage'>
+ <h1>{{$title}} - {{$page}}</h1>
+
+ <form action="{{$baseurl}}/admin/logs/settings" method="post">
+ <input type='hidden' name='form_security_token' value="{{$form_security_token}}">
+
+ {{include file="field_checkbox.tpl" field=$debugging}}
+ {{include file="field_input.tpl" field=$logfile}}
+ {{include file="field_select.tpl" field=$loglevel}}
+
+ <div class="submit"><input type="submit" name="page_logs" value="{{$submit}}" /></div>
+
+ </form>
+
+ <h2>{{$phpheader}}</h2>
+ <div>
+ <p>{{$phplogenabled}}<p>
+ <p>{{$phphint}}</p>
+ <pre>{{$phplogcode}}</pre>
+ </div>
+
+</div>
--- /dev/null
+<div id="adminpage">
+ <h1>{{$title}} - {{$page}}</h1>
+
+ <h3>{{$logname}}</h3>
+ <div style="width:100%; height:400px; overflow: auto; "><pre>{{$data}}</pre></div>
+</div>
+++ /dev/null
-<div id='adminpage'>
- <h1>{{$title}} - {{$page}}</h1>
-
- <h3>{{$logname}}</h3>
- <div style="width:100%; height:400px; overflow: auto; "><pre>{{$data}}</pre></div>
-</div>