From 616306ecc633c5d9cb184f918f66c22ccfa60189 Mon Sep 17 00:00:00 2001 From: Benjamin Sonntag Date: Wed, 11 Feb 2015 11:28:15 +0100 Subject: [PATCH] adding tail log view + order by DATE last files before in logs --- bureau/admin/logs_list.php | 6 +- bureau/admin/logs_tail.php | 98 ++++++++++++++++++++++++ bureau/class/m_log.php | 25 +++++- etc/alternc/templates/apache2/vhost.conf | 5 ++ 4 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 bureau/admin/logs_tail.php diff --git a/bureau/admin/logs_list.php b/bureau/admin/logs_list.php index 1a94ccd9..ab7ffa1b 100644 --- a/bureau/admin/logs_list.php +++ b/bureau/admin/logs_list.php @@ -62,7 +62,11 @@ while (list($key,$val)=each($list)){ - "._("Download")."";?> + "._("Download").""; + if ((time()-14400)<$v['mtime']) { + echo "   "._("Follow").""; + } +?> array ("request", "string", ""), + "autoreload" => array ("request", "integer", "1"), + "lines" => array ("request", "integer", "20"), +); +getFields($fields); + +if (empty($file)) { +$error=""; +} + +include_once("head.php"); + +$string=$log->tail($file,$lines); +if (!$string) { + $file=_("unknown"); +} +?> +

+

%s"),$file); ?>

+
+ + + +" onclick="document.location='logs_tail.php?file=&autoreload=0'"/> + +" onclick="document.location='logs_tail.php?file='"/> + + +  +"._("Download").""; ?> + +
+
+$error

"; +} + + +?> +
+
+
+ + + diff --git a/bureau/class/m_log.php b/bureau/class/m_log.php index a4b5dafa..6c2bedaa 100644 --- a/bureau/class/m_log.php +++ b/bureau/class/m_log.php @@ -38,12 +38,13 @@ class m_log { $c=array(); foreach( glob("${dir}/*log*") as $absfile) { $c[]=array("name"=>basename($absfile), - "creation_date"=>date("F d Y H:i:s.", filectime($absfile)), + "creation_date"=>date("F d Y H:i:s", filectime($absfile)), + "mtime" => filemtime($absfile), "filesize"=>filesize($absfile), - "downlink"=>"logs_download.php?file=".urlencode(basename($absfile)), + "downlink"=>urlencode(basename($absfile)), ); } - usort($c,"m_log::compare_logname"); + usort($c,"m_log::compare_logtime"); return $c; }//list_logs @@ -53,6 +54,11 @@ class m_log { return strcmp($a['name'],$b['name']); } + // Used by list_logs_directory to sort + private function compare_logtime($a, $b) { + return $b['mtime']-$a['mtime']; + } + function hook_menu() { $obj = array( @@ -91,7 +97,7 @@ class m_log { function download_link($file){ global $err,$mem; $err->log("log","download_link"); - header("Content-Disposition: attachment; filename=".$file); + header("Content-Disposition: attachment; filename=".$file.""); header("Content-Type: application/force-download"); header("Content-Transfer-Encoding: binary"); $f=$this->get_logs_directory(); @@ -100,6 +106,17 @@ class m_log { readfile($ff); } + function tail($file,$lines=20) { + global $err,$mem; + $err->log("log","tail"); + $lines=intval($lines); if ($lines<=0) $lines=20; + $f=$this->get_logs_directory(); + $ff=$f['dir']."/".basename($file); + unset($out); + exec("tail -".$lines." ".escapeshellarg($ff),$out); + return implode("\n",$out); + } + } // end class diff --git a/etc/alternc/templates/apache2/vhost.conf b/etc/alternc/templates/apache2/vhost.conf index 9c78d037..77f5e038 100644 --- a/etc/alternc/templates/apache2/vhost.conf +++ b/etc/alternc/templates/apache2/vhost.conf @@ -13,5 +13,10 @@ AllowOverride AuthConfig FileInfo Limit Options Indexes +# If you want to log the errors also in /var/log/alternc/sites/ +# WARNING: this WILL FORK a vlogger for EACH VHOST havingg this !!! the load on the machine may be high +# on hosting with many vhosts. as a consequence, this is disabled by default +# ErrorLog "|| /usr/sbin/vlogger -e -u alterncpanel -g alterncpanel -s error.log -t \"error-%Y%m%d.log\" /var/log/alternc/sites/%%UID%%-%%LOGIN%%/" +