New : allow to see and download logfile

This commit is contained in:
sparkyx 2026-02-27 11:47:46 +01:00
parent c18d75719b
commit bdefc955ab
4 changed files with 152 additions and 4 deletions

View file

@ -33,6 +33,7 @@ global $g_user,$cn,$g_parameter;
require_once NOALYSS_INCLUDE.'/class/database.class.php';
require_once NOALYSS_INCLUDE . '/class/noalyss_user.class.php';
require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
mb_internal_encoding("UTF-8");
//
// for loading javascripts or style-sheet, it is needed to know the user
@ -49,12 +50,47 @@ if (isset ($_REQUEST['loadjs']) && $_REQUEST['loadjs']=='message')
include_once NOALYSS_INCLUDE."/lib/message_javascript.php";
return;
}
//------------------------------------------------
// Export File from ADMINISTRATION MENU
//------------------------------------------------
$hi=new HttpInput();
if ($hi->request("admin","string",0)==1 ) {
$g_user=new Noalyss_user(new Database());
if ($g_user->admin != 1)
{
$g_user->audit('FAIL', "ADMIN: export admin".var_export($_REQUEST,true));
echo_warning(_("Accès interdit"));
exit();
}
if ( $hi->get("action")=="logfile") {
$directory=dir( NOALYSS_BASE.DIRECTORY_SEPARATOR."log");
$a_file=[];
while ( $file = $directory->read()) {
if (preg_match("/noalyss.*log/", $file)) {
$a_file[]=$file;
}
}
$file=$hi->get("file");
if (! in_array($file,$a_file ) )
{
echo_warning(sprintf("%s non trouvé",$file));
return;
}
header('Content-Type: application/x-download');
header('Content-Disposition: attachment; filename="'.$file.'"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
echo file_get_contents(NOALYSS_BASE.DIRECTORY_SEPARATOR."/log/{$file}");
}
return;
}
//------------------------------------------------
// Connect the user to the current folder and export file
//------------------------------------------------
$cn=Dossier::connect();
$g_user=new Noalyss_user($cn);
$gDossier=dossier::id();
$g_parameter=new Noalyss_Parameter_Folder($cn);
mb_internal_encoding("UTF-8");
$g_user->Check();
/**
* check if 2FA is completed
@ -62,9 +98,10 @@ $g_user->Check();
if ( ! $g_user->is_double_identified()) {
exit();
}
$gDossier=dossier::id();
$g_parameter=new Noalyss_Parameter_Folder($cn);
$action=$g_user->check_dossier($gDossier);
$hi=new HttpInput();
$action=$hi->get("act");
if ( $action=='X' || $g_user->check_print($action)==0 )

View file

@ -0,0 +1,93 @@
<?php
/*
* This file is part of NOALYSS.
*
* NOALYSS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* NOALYSS 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NOALYSS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Copyright Author Dany dany 27 févr. 2026
/*
*
*/
if (!defined('ALLOWED'))
die('Appel direct ne sont pas permis');
/**
* @file admin_logfile.inc
* @brief Show log file and download them
*/
if ( ! defined ('ALLOWED_ADMIN')) { die (_('Non autorisé'));}
print '<div class="content">';
print '<h2 class="h-section">';
print _("Fichiers trace");
print "</h2>";
//print p(_("Fichiers trace"),' class="text-muted"');
$directory=dir( NOALYSS_BASE.DIRECTORY_SEPARATOR."log");
$a_file=[];
while ( $file = $directory->read()) {
if (preg_match("/noalyss.*log/", $file)) {
$a_file[]=$file;
}
}
rsort($a_file);
$nb_file=count($a_file);
if ( $nb_file == 0) {
echo p(_("Aucune donnée"),' class="notice"');
return;
}
if ( $http->get("sa","string","x")=="dwn")
{
$file=$http->get("file");
if (! in_array($file,$a_file ) )
{
echo_warning(sprintf("%s non trouvé",$file));
record_log("admin_logfile : {$file} not found");
return;
}
print "<ul class=\"aligned-block\">";
print "<li>";
print \HtmlInput::button_anchor(_("Retour"), NOALYSS_URL."/admin-noalyss.php?action=logfile");
print "</li>";
print "<li>";
print \HtmlInput::button_anchor(_("Télécharger").'<i class="icon icon-download"></i>'
, NOALYSS_URL."/export.php?admin=1&action=logfile&file={$file}");
print "</li>";
print "</ul>";
echo '<pre>';
echo file_get_contents(NOALYSS_BASE.DIRECTORY_SEPARATOR."/log/{$file}");
echo '</pre>';
print "<ul class=\"aligned-block\">";
print "<li>";
print \HtmlInput::button_anchor(_("Retour"), NOALYSS_URL."/admin-noalyss.php?action=logfile");
print "</li>";
print "<li>";
print \HtmlInput::button_anchor(_("Télécharger").'<i class="icon icon-download"></i>'
, NOALYSS_URL."/export.php?admin=1&action=logfile&file={$file}");
print "</li>";
print "</ul>";
return;
}
echo '<ol>';
for ( $i=0;$i < $nb_file;$i++)
{
$url=sprintf("%s?%s", NOALYSS_URL."/admin-noalyss.php"
, http_build_query(["action"=>"logfile","sa"=>"dwn","file"=>$a_file[$i]]));
printf ("<li><a href=\"%s\">%s</a></li>",$url,$a_file[$i]);
}
print "</ol>";

View file

@ -47,6 +47,7 @@ if ($User->admin != 1)
{
$theme=(isset($User->theme))?$User->theme:"";
$User->audit('FAIL',"ADMIN : [$action]".var_export($_REQUEST,true));
record_log("Security alert [{$action}]".var_export($_REQUEST,true));
html_page_start($theme);
echo '<div class=content" style="padding:5%">';
echo "<h1 class=\"title\">";
@ -206,6 +207,12 @@ hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px; color: #0
echo $html->saveHTML();
}
if ($action== 'logfile')
{
/* List the connexion successfull and failed */
require_once NOALYSS_INCLUDE."/admin_logfile.inc.php";
}
//------------------------------------------------------------------------------
// Upgrade
//------------------------------------------------------------------------------

View file

@ -62,6 +62,9 @@ function MenuAdmin()
case 'info':
$def=6;
break;
case 'logfile':
$def=9;
break;
}
}
if (!defined("MULTI")||(defined("MULTI")&&MULTI==1))
@ -76,6 +79,10 @@ function MenuAdmin()
array("admin-noalyss.php?action=audit_log",_("Audit"),_("Utilisateurs qui se sont connectés"),4),
array("admin-noalyss.php?action=info",
_("Information système"),('Information à propos de votre installation'),6),
array("admin-noalyss.php?action=logfile"
,_("Trace")
,_("Fichiers erreurs")
,9),
array("login.php",_("Accueil"),"",7),
array("logout.php",_("Sortie"),"",8)
);
@ -96,6 +103,10 @@ function MenuAdmin()
array("admin-noalyss.php?action=audit_log",_("Audit"),_("Utilisateurs qui se sont connectés"),4),
array("admin-noalyss.php?action=info",
_("Information système"),('Information à propos de votre installation'),6),
array("admin-noalyss.php?action=logfile"
,_("Trace")
,_("Fichiers erreurs")
,9),
array("login.php",_("Accueil")),
array("logout.php",_("Sortie"))
);