Skip to content

Commit

Permalink
Merge pull request #14 from pd1acf/master
Browse files Browse the repository at this point in the history
added function to show only number of historic log files
  • Loading branch information
dg9vh committed Sep 5, 2018
2 parents 146b2d2 + 318c8bd commit 9319310
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -26,6 +26,11 @@ Installation

For detailled installation see `linux-step-by-step.md` within this repository.

Note
============
* You might need to implement a logrotate mechanism for the YSFReflector log files to prevent it to fill your filesystem. This directory is normally configured with 'FilePath=' in /etc/YSFReflector.ini


Contact
=======
Feel free to contact the author via email: dg9vh@darc.de
50 changes: 33 additions & 17 deletions include/functions.php
Expand Up @@ -68,28 +68,44 @@ function getYSFReflectorLog() {
}


function listdir_by_date($path){
$dir = opendir($path);
$list = array();
while($file = readdir($dir)){
if ($file != '.' and $file != '..'){
$ctime = filectime($data_path . $file) . ',' . $file;
$list[$ctime] = $file;
}
}
closedir($dir);
krsort($list);
return $list;
}


function getOldYSFReflectorLog() {
// first loop through the directory to find all log files for this year
$dir = YSFREFLECTORLOGPATH;
$files = scandir($dir, 1);
$dir = YSFREFLECTORLOGPATH;
$scanlogs = SHOWOLDMHEARD;
$oldlogLines = array();

$dir_files = listdir_by_date($dir);

foreach ($files as $file) {
foreach ($dir_files as $file) {
if ( $file != "." && $file != ".." ) {
if ( $scanlogs >= 0 ) {

if ($log = fopen(YSFREFLECTORLOGPATH."/".$file, 'r')) {
while ($oldlogLine = fgets($log)) {

if (strpos($oldlogLine, 'Received data from') !== false) {
array_push($oldlogLines, $oldlogLine);
}

// Open older Logfiles and copy loglines into oldLogLines-Array()
if ($log = fopen(YSFREFLECTORLOGPATH."/".$file, 'r')) {
while ($oldlogLine = fgets($log)) {

if (strpos($oldlogLine, 'Received data from') !== false) {
array_push($oldlogLines, $oldlogLine);
}

// if (startsWith($oldlogLine, "M:"))
// array_push($oldlogLines, $oldlogLine);
}
fclose($log);
}
}
fclose($log);
}
$scanlogs = $scanlogs - 1;
}
}
}
return $oldlogLines;
Expand Down
4 changes: 2 additions & 2 deletions setup.php
Expand Up @@ -151,8 +151,8 @@ function timezonechoice($selectedzone) {
<div class="panel-body"><input type="checkbox" <?php if (defined("SHOWPROGRESSBARS")) echo "checked" ?> name="SHOWPROGRESSBARS"></div>
</div>
<div class="input-group">
<span class="input-group-addon" id="SHOWOLDMHEARD" style="width: 300px">Show historic heard logs</span>
<div class="panel-body"><input type="checkbox" <?php if (defined("SHOWOLDMHEARD")) echo "checked" ?> name="SHOWOLDMHEARD"></div>
<span class="input-group-addon" id="SHOWOLDMHEARD" style="width: 300px">Show historic heard logs, in days</span>
<input type="text" value="<?php echo constant("SHOWOLDMHEARD") ?>" name="SHOWOLDMHEARD" class="form-control" placeholder="60" aria-describedby="SHOWOLDMHEARD" required data-fv-notempty-message="Value is required">
</div>
<div class="input-group">
<span class="input-group-addon" id="TEMPERATUREALERT" style="width: 300px">Enable CPU-temperature-warning</span>
Expand Down

0 comments on commit 9319310

Please sign in to comment.