Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reliance on linux / unix tail command. #581

Merged
merged 1 commit into from Oct 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 39 additions & 1 deletion Modules/admin/admin_controller.php
Expand Up @@ -59,7 +59,45 @@ function admin_controller()
$route->format = "text";
if ($log_enabled) {
ob_start();
passthru("tail -25 " . $log_filename);
// PHP replacement for tail starts here
// full path to text file
define("TEXT_FILE", $log_filename);
// number of lines to read from the end of file
define("LINES_COUNT", 25);

function read_file($file, $lines) {
//global $fsize;
$handle = fopen($file, "r");
$linecounter = $lines;
$pos = -2;
$beginning = false;
$text = array();
while ($linecounter > 0) {
$t = " ";
while ($t != "\n") {
if(fseek($handle, $pos, SEEK_END) == -1) {
$beginning = true;
break;
}
$t = fgetc($handle);
$pos --;
}
$linecounter --;
if ($beginning) {
rewind($handle);
}
$text[$lines-$linecounter-1] = fgets($handle);
if ($beginning) break;
}
fclose ($handle);
return array_reverse($text);
}

$fsize = round(filesize(TEXT_FILE)/1024/1024,2);
$lines = read_file(TEXT_FILE, LINES_COUNT);
foreach ($lines as $line) {
echo $line;
} //End PHP replacement for Tail
$result = trim(ob_get_clean());
} else {
$result = "Log is disabled.";
Expand Down