2012-08-21 18:25:56 +00:00
|
|
|
<?php
|
2015-09-25 15:42:00 +00:00
|
|
|
|
2012-08-21 18:25:56 +00:00
|
|
|
/*
|
2012-08-28 08:59:05 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
LICENSE
|
2015-09-25 15:42:00 +00:00
|
|
|
|
2012-08-28 08:59:05 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License (GPL)
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
2015-09-25 15:42:00 +00:00
|
|
|
|
2012-08-28 08:59:05 +00:00
|
|
|
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 General Public License for more details.
|
2015-09-25 15:42:00 +00:00
|
|
|
|
2012-08-28 08:59:05 +00:00
|
|
|
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
|
|
|
----------------------------------------------------------------------
|
2017-10-06 21:42:39 +00:00
|
|
|
*/
|
2012-08-28 08:59:05 +00:00
|
|
|
|
2012-08-21 18:25:56 +00:00
|
|
|
/**
|
2017-10-06 21:42:39 +00:00
|
|
|
* This class shows error or access logs of web server to the web panel
|
2017-10-08 17:31:34 +00:00
|
|
|
*
|
|
|
|
* @copyright AlternC-Team 2000-2017 https://alternc.com/
|
2015-09-25 15:42:00 +00:00
|
|
|
*/
|
2012-08-21 18:25:56 +00:00
|
|
|
class m_log {
|
|
|
|
|
2017-10-06 21:42:39 +00:00
|
|
|
/**
|
|
|
|
* List all logs files in a directory
|
|
|
|
*/
|
2015-09-25 15:42:00 +00:00
|
|
|
function list_logs_directory($dir) {
|
2017-08-17 01:32:18 +00:00
|
|
|
global $cuid, $msg;
|
|
|
|
$msg->log("log", "list_logs_directory");
|
2015-09-25 15:42:00 +00:00
|
|
|
|
|
|
|
$c = array();
|
|
|
|
foreach (glob("${dir}/*log*") as $absfile) {
|
|
|
|
$c[] = array("name" => basename($absfile),
|
2017-10-06 21:42:39 +00:00
|
|
|
"creation_date" => date("F d Y H:i:s", filectime($absfile)),
|
|
|
|
"mtime" => filemtime($absfile),
|
|
|
|
"filesize" => filesize($absfile),
|
|
|
|
"downlink" => urlencode(basename($absfile)),
|
2015-09-25 15:42:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
usort($c, "m_log::compare_logtime");
|
|
|
|
return $c;
|
|
|
|
}
|
|
|
|
|
2017-10-06 21:42:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used by list_logs_directory to sort
|
|
|
|
*/
|
2015-09-25 15:42:00 +00:00
|
|
|
private function compare_logname($a, $b) {
|
|
|
|
return strcmp($a['name'], $b['name']);
|
|
|
|
}
|
|
|
|
|
2017-10-06 21:42:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used by list_logs_directory to sort
|
|
|
|
*/
|
2015-09-25 15:42:00 +00:00
|
|
|
private function compare_logtime($a, $b) {
|
|
|
|
return $b['mtime'] - $a['mtime'];
|
2012-08-21 18:25:56 +00:00
|
|
|
}
|
2015-09-25 15:42:00 +00:00
|
|
|
|
2017-10-06 21:42:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* hook called by the menu class
|
|
|
|
* to add menu to the left panel
|
|
|
|
*/
|
2015-09-25 15:42:00 +00:00
|
|
|
function hook_menu() {
|
|
|
|
$obj = array(
|
|
|
|
'title' => _("Logs"),
|
|
|
|
'link' => 'logs_list.php',
|
|
|
|
'pos' => 130,
|
2017-10-06 21:42:39 +00:00
|
|
|
);
|
2015-09-25 15:42:00 +00:00
|
|
|
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
2017-10-06 21:42:39 +00:00
|
|
|
/**
|
|
|
|
* list all log files in all log directories
|
|
|
|
*/
|
2015-09-25 15:42:00 +00:00
|
|
|
function list_logs_directory_all($dirs) {
|
2017-08-17 01:32:18 +00:00
|
|
|
global $msg;
|
|
|
|
$msg->log("log", "get_logs_directory_all");
|
2015-09-25 15:42:00 +00:00
|
|
|
$c = array();
|
|
|
|
foreach ($dirs as $dir => $val) {
|
|
|
|
$c[$dir] = $this->list_logs_directory($val);
|
|
|
|
}
|
|
|
|
return $c;
|
|
|
|
}
|
|
|
|
|
2017-10-06 21:42:39 +00:00
|
|
|
|
2015-09-25 15:42:00 +00:00
|
|
|
function get_logs_directory() {
|
2017-08-17 01:32:18 +00:00
|
|
|
global $cuid, $mem, $msg;
|
|
|
|
$msg->log("log", "get_logs_directory");
|
2015-09-25 15:42:00 +00:00
|
|
|
// Return an array to allow multiple directory in the future
|
|
|
|
if (defined('ALTERNC_LOGS_ARCHIVE')) {
|
|
|
|
$c = array("dir" => ALTERNC_LOGS_ARCHIVE . "/" . $cuid . "-" . $mem->user["login"]);
|
|
|
|
} else {
|
|
|
|
$c = array("dir" => ALTERNC_LOGS . "/" . $cuid . "-" . $mem->user["login"]);
|
|
|
|
}
|
|
|
|
return $c;
|
2012-08-23 07:36:11 +00:00
|
|
|
}
|
2015-09-25 15:42:00 +00:00
|
|
|
|
2017-10-06 21:42:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* download a log file
|
|
|
|
*/
|
2015-09-25 15:42:00 +00:00
|
|
|
function download_link($file) {
|
2017-08-17 01:32:18 +00:00
|
|
|
global $msg;
|
|
|
|
$msg->log("log", "download_link");
|
2015-09-25 15:42:00 +00:00
|
|
|
header("Content-Disposition: attachment; filename=" . $file . "");
|
|
|
|
header("Content-Type: application/force-download");
|
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
$f = $this->get_logs_directory();
|
|
|
|
$ff = $f['dir'] . "/" . basename($file);
|
|
|
|
set_time_limit(0);
|
|
|
|
readfile($ff);
|
2013-04-24 15:26:09 +00:00
|
|
|
}
|
2012-08-21 18:25:56 +00:00
|
|
|
|
2017-10-06 21:42:39 +00:00
|
|
|
/**
|
|
|
|
* show the last lines of a file
|
|
|
|
*/
|
2015-09-25 15:42:00 +00:00
|
|
|
function tail($file, $lines = 20) {
|
2017-08-17 01:32:18 +00:00
|
|
|
global $msg;
|
|
|
|
$msg->log("log", "tail");
|
2015-09-25 15:42:00 +00:00
|
|
|
$lines = intval($lines);
|
|
|
|
if ($lines <= 0) {
|
|
|
|
$lines = 20;
|
|
|
|
}
|
|
|
|
$f = $this->get_logs_directory();
|
|
|
|
$ff = $f['dir'] . "/" . basename($file);
|
|
|
|
$out=array();
|
|
|
|
exec("tail -" . $lines . " " . escapeshellarg($ff), $out);
|
|
|
|
return implode("\n", $out);
|
|
|
|
}
|
|
|
|
|
2017-10-06 21:42:39 +00:00
|
|
|
} /* class m_log */
|