Code: Select all
/*
form fields:
`log_dir` = machine1, machine2 etc
`log_month` = 01, 02 etc
`log_option` = checked/unchecked
`log_string1` = custom search string 1
`log_string2` = custom search string 2
*/
// list files
$dir = '/home/user/public_html/logs/';
if(!$_POST['log_submit']) {
$log_dir = 'machine1';
$log_month = date('m');
$log_option = false;
$log_string1 = false;
$log_string2 = false;
} else {
$log_dir = $_POST['log_dir'];
$log_month = $_POST['log_month'];
if($_POST['log_option']) {
$log_option = 'error';
} else {
$log_option = false;
}
if(!empty($_POST['log_string1'])) {
$log_string1 = $_POST['log_string1'];
} else {
$log_string1 = false;
}
if(!empty($_POST['log_string2'])) {
$log_string2 = $_POST['log_string2'];
} else {
$log_string2 = false;
}
}
/*
* parse through all files from $dir.$log_dir that matches 'log_'.$log_month.'*.log
* (the logs are separated into log_<month>0001.log, log_<month>0002.log and so on)
* if(!$log_string1 || !$_POST['log_submit'])
* { list all files that starts with 'log_'.$log_month }
* elseif($_POST['log_submit'] && $log_string1 != false)
* if(number_of_files != 0)
* { list all files that matches the criterias ($log_option, $log_string1, $log_string2) that isn't falsed }
* else
* { echo 'No matching logs'; }
*/
// view log file
$badwords = array('word1', 'word2', 'word3');
if($_GET['view'] === 'true' && isset($_GET['month']) && isset($_GET['string1'])) {
/*
* show lines that matches the criterias:
* include word $_GET['string1']
* if($_GET['option'] == 1)
* { include word 'error' }
* if(isset($_GET['string2']))
* { include word $_GET['string2'] }
* exlude all lines that contains $badwords
* FROM all files from $dir.$log_dir that matches 'log_'.$log_month.'*.log
* if($matches != 0)
* { echo 'No matches.' }
*/
} else {
echo 'error - select a file.';
}