Forum Moderators: coopster
<html><head>
<title>LogFile Search</title>
<style type="text/css"> <<irrelevant stuff removed>> </style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" language="javascript" src="js/UI.js"></script>
</head>
<body>
<h3 id="myh3">Log File Search</h3><h5>Version 1.0.1</h5>
<h4 id="myh4"><ul><li> <<irrelevant stuff removed>> </li></ul></h4>
<form method="post" name="LogFile_Search" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table id="mytable">
<tbody>
<tr>
<td id="mytd">Result(P|F|N): <input type="text" id="Result_PFN" name="Result_PFN" size="31"/></td>
<td id="mytd">Script Version: <input type="text" id="ScriptVersion" name="ScriptVersion" size="31"/></td>
</tr>
</tbody>
</table>
<br>
<input type="submit" value="Search" onclick="doForm();">
<input type="button" value="Reset" onclick="resetForm();">
</form>
<div id="searchResult">
<?php
/* Where the logs files are dropped by external process. */
$mydir = $_SERVER['DOCUMENT_ROOT'] . "/LogFile_Search/LogFiles";
/* Handle to directory. */
$dir = opendir($mydir);
/* Form variables. */
$Result_PFN = $_POST['Result_PFN'];
$ScriptVersion = $_POST['ScriptVersion'];
/* Test each field -- triggers JS alert if all are empty. */
if (!empty($Result_PFN)) {
doResult_PFN();
} elseif (!empty($ScriptVersion)) {
doScriptVersion();
}
/* Function for Search on Script version in logfile contents. */
function doScriptVersion() {
global $dir;
global $mydir;
global $ScriptVersion;
echo '<table id=\'mytable\'><tbody><tr><td id=\'mytd\'>Log File Name.</td></tr>';
//grabs all log files matching the script version number that's input in the form.
$cmd = "find " . $mydir . " -type f -print0 | xargs -0 grep -e 'Test_Version=" . $ScriptVersion . "'";
exec($cmd, $output);
//Sort the array using a case insensitive "natural order" algorithm.
natcasesort($output);
if (count($output) > 0) {
foreach ($output as $v) {
//Display file name without full path as URL.
echo '<tr><td><a href="' . basename($mydir) . '/'
. array_pop(explode("/", array_shift(explode(":", $v)))) . '" target="_blank">'
. array_pop(explode("/", array_shift(explode(":", $v)))) . '</a></td></tr>';
}
} else {
echo "<html><body style=\"background-color:#0080c0\">
<script type=\"text/javascript\" language=\"javascript\">alert(
'Nothing found'
+ '.');</script> </body></html>";
}
closedir($dir);
echo "</table></body>";
}
/* Function for Search on Result marker in file name. */
function doResult_PFN() {
global $dir;
global $mydir;
global $Result_PFN;
echo '<table id=\'mytable\'><tbody><tr><td id=\'mytd\'>Log File Name.</td></tr>';
if ($dir) {
//List files in directory
while (($file = readdir($dir)) !== false)
//Ignores OS stuff.
if ($file != "." && $file != "..") {
//Pattern match for result.
if (preg_match("/~(P|F|N)*" . $Result_PFN . "~/i", $file)) {
//Sort the array using a case insensitive "natural order" algorithm.
natcasesort($file);
echo '<tr><td><a href="' . basename($mydir) . '/' . $file . '" target="_blank">' . $file . '</a></td></tr>';
}
} else {
echo "<html><body style=\"background-color:#0080c0\">
<script type=\"text/javascript\" language=\"javascript\">alert(
'Nothing found'
+ '.');</script> </body></html>";
}
closedir($dir);
}
echo "</table></body>";
}
?>
</div>
</body>
</html>