*/
include 'common.php';
$allowed_file[1]='/var/run/dmesg.boot';
$allowed_file[2]='/var/log/messages';
function tail($file,$tail_size) {
if(file_exists($file)) {
$file_contents = implode('',file($file));
$lines = explode("\n", $file_contents);
$line_count = count($lines) - 1;
if( $tail_size > $line_count ) {
$tail_size = $line_count;
}
for($i=($line_count-$tail_size);$i < $line_count;$i++) {
$tail_string .= "$i: $lines[$i]\n";
}
}
else {
$tail_string = 'couldn\'t find the log file';
}
return $tail_string;
}
function print_file($number,$tail) {
global $allowed_file;
print "
$allowed_file[$number] |
";
print "";
print tail($allowed_file[$number],$tail);
print " |
";
}
html_header("logfile");
print "\n";
parse_str($_SERVER['QUERY_STRING'], $output);
if ( (int)($output['tail']) > 0 ) {
$tail = $output['tail'];
}
else {
$tail = 10;
}
if ( (int)($output['file']) > 0 &&
(int)$output['file'] <= sizeof($allowed_file) ) {
print_file($output['file'], $tail);
}
elseif ( in_array($output['file'], $allowed_file) ) {
$number=array_search($output['file'], $allowed_file);
print_file($number, $tail);
}
else {
print "Allowed commands:\n";
print "";
for ($i = 1; $i <= sizeof($allowed_file); $i++ ) {
print "$i: $allowed_file[$i]\n";
}
print "
";
}
print "\n";
html_end();
?>