1 |
<?php |
2 |
|
3 |
# Navigation for the i-scream reports. |
4 |
# pjm2@ukc.ac.uk |
5 |
# |
6 |
# CONFIGURABLE CONSTANTS: - |
7 |
|
8 |
# The report directory, and the number of days to display. |
9 |
$reportDirectory = "/home/cut/pjm2/webpages/reports/historical"; |
10 |
$maxDaysShown = 7; |
11 |
|
12 |
# Page appearance. |
13 |
$scaleImage = "24hour.gif"; |
14 |
$lineColor = "#9999ff"; |
15 |
|
16 |
# Files to include |
17 |
$titleHTML = "title.inc"; |
18 |
$bottomHTML = "bottom.inc"; |
19 |
$machineNameHTML = "machine_name.inc"; |
20 |
$reportHTML = "report.inc"; |
21 |
|
22 |
# What are the names of the report files? |
23 |
$reportLimitsFile = "i-maxmin.txt"; |
24 |
$reportChartFile = "i-chart.gif"; |
25 |
$reportChartDataFile = "i-data.txt"; |
26 |
|
27 |
# Submission details. |
28 |
$formMethod = "GET"; |
29 |
$thisPage = "browser.php"; |
30 |
|
31 |
# Leave this alone unless you know what you're doing ;) |
32 |
$minFileSize = 33; |
33 |
|
34 |
# |
35 |
# END CONFIGURATION |
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
# Used to return whether or not a report data file is empty. |
42 |
function isReportEmpty($filename, $minFileSize) { |
43 |
if (filesize($filename) < $minFileSize) { |
44 |
return TRUE; |
45 |
} |
46 |
return FALSE; |
47 |
} |
48 |
|
49 |
|
50 |
# return an array of subdirectories in the current directory. |
51 |
function getdirArray($dir='./',$sort='asort') { |
52 |
global $dir_file_count; |
53 |
if ( is_dir($dir) ) { |
54 |
$fd = @opendir($dir); |
55 |
while ( ($part = @readdir($fd)) == TRUE ) { |
56 |
clearstatcache(); |
57 |
if ($part != "." && $part != "..") { |
58 |
if (preg_match("/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/", $part)) { |
59 |
$dir_array[] = $part; |
60 |
} |
61 |
} |
62 |
} |
63 |
if($fd == TRUE) { |
64 |
closedir($fd); |
65 |
} |
66 |
if (is_array($dir_array)) { |
67 |
$sort($dir_array); |
68 |
$dir_file_count = count($dir_array); |
69 |
Return $dir_array; |
70 |
} else { |
71 |
Return FALSE; |
72 |
} |
73 |
} else { |
74 |
Return FALSE; |
75 |
} |
76 |
} |
77 |
|
78 |
?> |
79 |
|
80 |
<? include($titleHTML); ?> |
81 |
|
82 |
<hr weight="1" color="<? echo $lineColor ?>"> |
83 |
|
84 |
<b>Most recent reports available</b> |
85 |
<form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>"> |
86 |
<? |
87 |
|
88 |
$file_array = getdirArray($reportDirectory,'rsort'); |
89 |
print "<select size=\"1\" name=\"day\">"; |
90 |
if ($day) { ?> |
91 |
<option selected value="<? echo $day ?>"><? echo $day ?></option> |
92 |
<option value="">----------------</option> |
93 |
<? } |
94 |
foreach($file_array as $file_name) { |
95 |
if (is_dir($file_name)) { |
96 |
$i++; |
97 |
print "<option value=\"$file_name\">$file_name</option>"; |
98 |
} |
99 |
if ($i >= $maxDaysShown) { |
100 |
break; |
101 |
} |
102 |
} |
103 |
print "</select>"; |
104 |
|
105 |
?> |
106 |
<input type="submit" name="submit" value="Go"> |
107 |
</form> |
108 |
|
109 |
<hr weight="1" color="<? echo $lineColor ?>"> |
110 |
|
111 |
<? if ($day) { ?> |
112 |
|
113 |
<b>Available reports for <? echo $day ?></b> |
114 |
|
115 |
<form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>"> |
116 |
<select size="1" name="machine_name"> |
117 |
<? if ($machine_name) { ?> |
118 |
<option selected value="<? echo $machine_name ?>"><? echo $machine_name ?></option> |
119 |
<option value="">----------------</option> |
120 |
<? } else { ?> |
121 |
<option selected value="">[select machine]</option> |
122 |
<? } ?> |
123 |
<? include("$day/$machineNameHTML"); ?> |
124 |
</select> |
125 |
|
126 |
<select size="1" name="report"> |
127 |
<? if ($report) { ?> |
128 |
<option selected value="<? echo $report ?>"><? echo $report ?></option> |
129 |
<option value="">----------------</option> |
130 |
<? } else { ?> |
131 |
<option selected value="">[select report]</option> |
132 |
<? } ?> |
133 |
<? include("$day/$reportHTML"); ?> |
134 |
</select> |
135 |
|
136 |
<input type="hidden" name="day" value="<? echo $day ?>"> |
137 |
<input type="submit" name="submit" value="Show"> |
138 |
</form> |
139 |
|
140 |
<hr weight="1" color="<? echo $lineColor ?>"> |
141 |
|
142 |
<? } ?> |
143 |
|
144 |
</p> |
145 |
|
146 |
|
147 |
<? |
148 |
if ($submit == "Show" && $machine_name && $report) { |
149 |
|
150 |
include("$day/$machine_name/$report/$reportLimitsFile"); |
151 |
|
152 |
$url = escapeshellcmd("$day/$machine_name/$report/$reportChartFile"); |
153 |
if (isReportEmpty("$day/$machine_name/$report/$reportChartDataFile", $minFileSize)) { |
154 |
echo "Host <b>$machine_name</b> did not send any information about <b>$report</b> on <b>$day</b>. Please select another report."; |
155 |
} |
156 |
else if (file_exists($url)) { ?> |
157 |
|
158 |
<center><b>[<? echo $machine_name; ?>] - <? echo $report; ?></b></center> |
159 |
|
160 |
<table border="0" cellpadding="0" cellspacing="0"> |
161 |
<tr> |
162 |
<td align="right" valign="top"> |
163 |
<font size="2"><? printf("%.1f", $max_value); ?></font> |
164 |
</td> |
165 |
<td rowspan="2"> |
166 |
<img src="<? echo $url; ?>" width="500" height="250"> |
167 |
</td> |
168 |
</tr> |
169 |
<tr> |
170 |
<td align="right" valign="bottom"> |
171 |
<font size="2"><? echo $min_value; ?></font> |
172 |
</td> |
173 |
</tr> |
174 |
<tr> |
175 |
<td> </td> |
176 |
<td><img src="<? echo $scaleImage ?>" width="500" height="39"></td> |
177 |
</tr> |
178 |
</table> |
179 |
|
180 |
<hr weigth="1" color="<? echo $lineColor ?>"> |
181 |
|
182 |
<b>Extra data</b> |
183 |
<p> |
184 |
<a href="<? echo "$day/$machine_name/$report/$reportChartDataFile" ?>">Raw plot data</a><br> |
185 |
<a href="<? echo "$day/$machine_name/$report/$reportChartFile" ?>">GIF chart</a><br> |
186 |
<a href="<? echo "$day/$machine_name/$report/$reportLimitsFile" ?>">PHP y-axis limits include</a> |
187 |
|
188 |
<? } |
189 |
else { |
190 |
echo "<p>The report could not be found. Somebody must have deleted it!</p>"; |
191 |
} |
192 |
echo "<hr weight=\"1\" color=\"$lineColor\">"; |
193 |
} |
194 |
|
195 |
?> |
196 |
|
197 |
<? include($bottomHTML); ?> |