From a39d4b18c4e8c40e316876ca28177f16342f8808 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@users.sourceforge.net> Date: Tue, 30 Jun 2009 01:06:10 +0000 Subject: [PATCH] New: Can delete the log file from the tool menu --- htdocs/admin/tools/purge.php | 67 +++++++++++++++++++++++++++-------- htdocs/langs/en_US/admin.lang | 3 +- htdocs/langs/fr_FR/admin.lang | 1 + htdocs/lib/files.lib.php | 8 +++-- htdocs/lib/functions.lib.php | 7 ++-- 5 files changed, 64 insertions(+), 22 deletions(-) diff --git a/htdocs/admin/tools/purge.php b/htdocs/admin/tools/purge.php index 691b7e495da..946f0ff6c95 100644 --- a/htdocs/admin/tools/purge.php +++ b/htdocs/admin/tools/purge.php @@ -1,5 +1,5 @@ <?php -/* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net> +/* Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,10 +17,10 @@ */ /** - \file htdocs/admin/tools/purge.php - \brief Page de purge des fichiers temporaires - \version $Id$ -*/ + * \file htdocs/admin/tools/purge.php + * \brief Page to purge files (temporary or not) + * \version $Id$ + */ require("./pre.inc.php"); include_once(DOL_DOCUMENT_ROOT."/lib/databases/".$conf->db->type.".lib.php"); @@ -29,19 +29,27 @@ include_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php'); $langs->load("admin"); if (! $user->admin) - accessforbidden(); +accessforbidden(); if ($_GET["msg"]) $message='<div class="error">'.$_GET["msg"].'</div>'; +// Define filelog to discard it from purge +$filelog=''; +if ($conf->syslog->enabled) +{ + $filelog=SYSLOG_FILE; + $filelog=eregi_replace('DOL_DATA_ROOT',DOL_DATA_ROOT,$filelog); +} + /* -* Actions -*/ + * Actions + */ if ($_POST["action"]=='purge') { $filesarray=array(); - + if ($_POST["choice"]=='tempfiles') { // Delete temporary files @@ -60,15 +68,32 @@ if ($_POST["action"]=='purge') } } + if ($_POST["choice"]=='logfile') + { + $filesarray[]=array('fullname'=>$filelog,'type'=>'file'); + } + $count=0; if (sizeof($filesarray)) { + foreach($filesarray as $key => $value) { //print "x ".$filesarray[$key]['fullname']."<br>\n"; - $count+=dol_delete_dir_recursive($filesarray[$key]['fullname']); + if ($filesarray[$key]['type'] == 'dir') + { + $count+=dol_delete_dir_recursive($filesarray[$key]['fullname']); + } + elseif ($filesarray[$key]['type'] == 'file') + { + // If (file that is not logfile) or (if logfile with option logfile) + if ($filesarray[$key]['fullname'] != $filelog || $_POST["choice"]=='logfile') + { + $count+=dol_delete_file($filesarray[$key]['fullname']); + } + } } - + // Update cachenbofdoc if ($conf->ecm->enabled && $_POST["choice"]=='allfiles') { @@ -85,8 +110,8 @@ if ($_POST["action"]=='purge') /* -* Affichage page -*/ + * View + */ llxHeader(); @@ -98,7 +123,7 @@ print '<br>'; print $langs->trans("PurgeAreaDesc",$dolibarr_main_data_root).'<br>'; print '<br>'; -if ($message) +if ($message) { print $message.'<br>'; print "\n"; @@ -109,13 +134,25 @@ print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="action" value="purge">'; -print '<table class="border" width="100%"><tr><td>'; +print '<table class="border" width="100%">'; + +print '<tr><td>'; + print '<input type="radio" name="choice" value="tempfiles"'; print (! $_POST["choice"] || $_POST["choice"]=='tempfiles') ? ' checked="true"' : ''; print '> '.$langs->trans("PurgeDeleteTemporaryFiles").'<br>'; + print '<input type="radio" name="choice" value="allfiles"'; print ($_POST["choice"] && $_POST["choice"]=='allfiles') ? ' checked="true"' : ''; print '> '.$langs->trans("PurgeDeleteAllFilesInDocumentsDir",$dolibarr_main_data_root).'<br>'; + +if ($conf->syslog->enabled) +{ + print '<input type="radio" name="choice" value="logfile"'; + print ($_POST["choice"] && $_POST["choice"]=='logfile') ? ' checked="true"' : ''; + print '> '.$langs->trans("PurgeDeleteLogFile",$filelog).'<br>'; +} + print '</td></tr></table>'; print '<br>'; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 52e64fdfffd..58b54cbe143 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -108,6 +108,7 @@ SystemToolsAreaDesc=This area provides administration features. Use the menu to PurgeAreaDesc=This page allows you to delete all files built or stored by Dolibarr (temporary files or all files in <b>%s</b> directory). Using this feature is not necessary. It is provided for users whose Dolibarr is hosted by a provider that does not offer permissions to delete files built by the web server. PurgeDeleteTemporaryFiles=Delete all temporary files (no risk to loose data) PurgeDeleteAllFilesInDocumentsDir=Delete all files in directory <b>%s</b>. Temporary files but also files attached to elements (third parties, invoices, ...) and uploaded into the ECM module will be deleted. +PurgeDeleteLogFile=Delete log file <b>%s</b> defined for Syslog module. PurgeRunNow=Purge now PurgeNothingToDelete=no directory to delete. PurgeNDirectoriesDeleted=<b>%s</b> files or directories deleted. @@ -684,7 +685,7 @@ NoEventOrNoAuditSetup=No security event has been recorded yet. This can be norma NoEventFoundWithCriteria=No security event has been found for such search criterias. SeeLocalSendMailSetup=See your local sendmail setup BackupDesc=To make a complete backup of Dolibarr, you must: -BackupDesc2=* Save content of documents directory (<b>%s</b>) that contains all uplaoded and generated files (you can make a zip for exeample). +BackupDesc2=* Save content of documents directory (<b>%s</b>) that contains all uploaded and generated files (you can make a zip for exeample). BackupDesc3=* Save content of your database with a dump. for this, you can use following assistant. BackupDescX=Archived directory should be stored in a secure place. BackupDescY=The generated dump file should be stored in a secure place. diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 951291efc74..960bcbf540d 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -108,6 +108,7 @@ SystemToolsAreaDesc = Cet espace offre des fonctions d'administration diverses. PurgeAreaDesc = Cette page vous permet d'effacer tous les fichiers construits ou stockés par Dolibarr (fichiers temporaires ou tous les fichiers du répertoire <b>%s</b>). L'utilisation de cette fonction n'est pas nécessaire. Elle est fournie pour les utilisateurs qui héberge Dolibarr chez un hébergeur qui n'offre pas les permissions de supprimer les fichiers sauvegardés par le serveur Web. PurgeDeleteTemporaryFiles = Effacer tous les fichiers temporaires (pas de risque de perte de données) PurgeDeleteAllFilesInDocumentsDir = Effacer tous les fichiers du répertoire <b>%s</b>. Les fichiers temporaires mais aussi les fichiers joints aux éléments (tiers, factures, ...) ou dans le module GED seront effacées. +PurgeDeleteLogFile = Effacer le fichier log <b>%s</b> défini pour le module Syslog. PurgeRunNow = Lancer la purge maintenant PurgeNothingToDelete = Aucun répertoire à supprimer. PurgeNDirectoriesDeleted = <b>%s</b> fichiers ou répertoires supprimés. diff --git a/htdocs/lib/files.lib.php b/htdocs/lib/files.lib.php index 6acd9d97825..6ea2d4c2055 100644 --- a/htdocs/lib/files.lib.php +++ b/htdocs/lib/files.lib.php @@ -33,7 +33,7 @@ * \param $sortcriteria Sort criteria ("name","date","size") * \param $sortorder Sort order (SORT_ASC, SORT_DESC) * \param $mode 0=Return array with only keys needed, 1=Force all keys to be loaded - * \return array Array of array('name'=>xxx,'date'=>yyy,'size'=>zzz) + * \return array Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file') */ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter="", $sortcriteria="name", $sortorder=SORT_ASC, $mode=0) { @@ -73,7 +73,8 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil "name" => $file, "fullname" => $path.'/'.$file, "date" => $filedate, - "size" => $filesize + "size" => $filesize, + "type" => 'dir' ); } @@ -94,7 +95,8 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil "name" => $file, "fullname" => $path.'/'.$file, "date" => $filedate, - "size" => $filesize + "size" => $filesize, + "type" => 'file' ); } } diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 4ce047ebc64..ef7f960cce1 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -2017,9 +2017,9 @@ function print_fleche_navigation($page,$file,$options='',$nextpage,$betweenarrow /** - * \brief Effacement d'un fichier - * \param file Fichier a effacer ou masque de fichier a effacer - * \param boolean true if file deleted, false if error + * \brief Remove a file + * \param file Fichier a effacer ou masque de fichier a effacer + * \param boolean true if file deleted, false if error */ function dol_delete_file($file) { @@ -2052,6 +2052,7 @@ function dol_delete_dir($dir) */ function dol_delete_dir_recursive($dir,$count=0) { + //dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG); if ($handle = opendir("$dir")) { while (false !== ($item = readdir($handle))) -- GitLab