1 |
<?php |
2 |
|
3 |
# Navigation for the i-scream reports. |
4 |
# pjm2@ukc.ac.uk |
5 |
# |
6 |
# CONFIGURABLE CONSTANTS: - |
7 |
|
8 |
include("latest_config.inc.php"); |
9 |
|
10 |
# |
11 |
# END CONFIGURATION |
12 |
|
13 |
include("iutils.inc.php"); |
14 |
|
15 |
function printLine($title) { |
16 |
echo "<hr style=\"color:#9999ff;\">"; |
17 |
echo "<b>$title</b>"; |
18 |
} |
19 |
|
20 |
|
21 |
function showStat($title, $value, $input) { |
22 |
|
23 |
$report = $value; |
24 |
|
25 |
$value = getPregMatch($value, $input); |
26 |
if (empty($value)) { |
27 |
$value = "<i><font color=\"#999999\">not sent</font></i>"; |
28 |
} |
29 |
?> |
30 |
<table border="0" width="100%"> |
31 |
<tr> |
32 |
<td width="50%" align="right" valign="top"> |
33 |
<b><?=$title?></b> |
34 |
</td> |
35 |
<td width="50%" align="left" valign="top"> |
36 |
<? if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) { |
37 |
linkToHistory($report); |
38 |
} ?> |
39 |
<?=$value?></td> |
40 |
</tr> |
41 |
</table> |
42 |
<? |
43 |
} |
44 |
|
45 |
|
46 |
function linkToHistory($report) { |
47 |
global $machine; |
48 |
$yesterday = date("Y-m-d", time() - 86400); |
49 |
echo <<<EOT |
50 |
<a href="browser.php?machine_name=$machine&report=$report&day=$yesterday&submit=Show"><img src="minichart.gif" alt="View yesterday's 24-hour chart" width="20" height="20" border="0"></a> |
51 |
EOT; |
52 |
} |
53 |
|
54 |
|
55 |
# show all disk information. |
56 |
function showDisks($diskRoot, $units, $input) { |
57 |
include("latest_config.inc.php"); |
58 |
|
59 |
$i = 0; |
60 |
while(1) { |
61 |
$name = getPregMatch("$diskRoot.p$i.attributes.name", $input); |
62 |
$mount = getPregMatch("$diskRoot.p$i.attributes.mount", $input); |
63 |
if ($name || $mount) { |
64 |
$used = "$diskRoot.p$i.attributes.used"; |
65 |
$kbytes = "$diskRoot.p$i.attributes.kbytes"; |
66 |
showBar("$name<br>($mount)", $used, $kbytes, $units, $input); |
67 |
} |
68 |
else { |
69 |
break; |
70 |
} |
71 |
$i++; |
72 |
} |
73 |
} |
74 |
|
75 |
# Return a preg_match result. |
76 |
function getPregMatch($value, $input) { |
77 |
preg_match("/$value=([^\,\}]*)[\,\}]/", $input, $matches); |
78 |
return $matches[1]; |
79 |
} |
80 |
|
81 |
|
82 |
# show a bar-represented value. |
83 |
function showBar($title, $value, $max, $units, $input, $arrange='normal') { |
84 |
|
85 |
include("latest_config.inc.php"); |
86 |
|
87 |
$report = $value; |
88 |
|
89 |
$value = getPregMatch($value, $input); |
90 |
if (!is_int($max)) { |
91 |
$max = getPregMatch($max, $input); |
92 |
} |
93 |
if (empty($value) || empty($max)) { |
94 |
return; |
95 |
} |
96 |
|
97 |
if ($arrange == 'swap') { |
98 |
$value = $max - $value; |
99 |
} |
100 |
|
101 |
$width = intval($max_width * $value / $max); |
102 |
|
103 |
?> |
104 |
<table border="0" cellpadding="0" cellspacing="0" align="center"> |
105 |
<tr> |
106 |
<td colspan="2"><? linkToHistory($report); ?> <b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td> |
107 |
</tr> |
108 |
<tr> |
109 |
<td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td> |
110 |
</tr> |
111 |
<tr> |
112 |
<td colspan="2"><img src="<?=$scaleImage?>" border="0" height="11" width="<?=$max_width?>"></td> |
113 |
</tr> |
114 |
<tr> |
115 |
<td align="left">0<?=$units?></td> |
116 |
<td align="right"><?=$max?><?=$units?></td> |
117 |
</tr> |
118 |
<tr> |
119 |
<td colspan="2"> </td> |
120 |
</tr> |
121 |
</table> |
122 |
<? |
123 |
} |
124 |
|
125 |
|
126 |
?> |
127 |
|
128 |
<? include($titleHTML); ?> |
129 |
|
130 |
<? printLine("Display the latest information received from a host"); ?> |
131 |
|
132 |
<form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>"> |
133 |
<? |
134 |
|
135 |
$file_array = getdirArray($latestDirectory,'asort'); |
136 |
print "<select size=\"1\" name=\"machine\">"; |
137 |
if ($machine) { ?> |
138 |
<option selected value="<? echo $machine ?>"><? echo $machine ?></option> |
139 |
<option value="">----------------</option> |
140 |
<? } |
141 |
foreach($file_array as $file_name) { |
142 |
#if (is_dir($file_name)) { |
143 |
print "<option value=\"$file_name\">$file_name</option>"; |
144 |
#} |
145 |
} |
146 |
print "</select>"; |
147 |
|
148 |
?> |
149 |
<input type="submit" name="submit" value="Display"> |
150 |
</form> |
151 |
|
152 |
<? if ($machine) { |
153 |
|
154 |
$last_modified = filemtime("$latestDirectory/$machine/$latestData"); |
155 |
clearstatcache(); |
156 |
$data_age = time() - $last_modified; |
157 |
|
158 |
$last_modified = date("l jS F - g:ia", $last_modified); |
159 |
|
160 |
if ($data_age > $warning_age) { |
161 |
$warning = <<<EOT |
162 |
<br> |
163 |
<font color="red"><b> |
164 |
Warning: |
165 |
</b></font> |
166 |
This realtime report is too old to be considered recent |
167 |
EOT; |
168 |
} |
169 |
|
170 |
echo <<<EOT |
171 |
<table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1"> |
172 |
<tr> |
173 |
<td bgcolor="#000066"> |
174 |
|
175 |
</td> |
176 |
<td bgcolor="#ffffcc"> |
177 |
<font face="arial,sans-serif" size="2"> |
178 |
<b>Receipt date:</b> $last_modified |
179 |
$warning |
180 |
</font> |
181 |
</td> |
182 |
</tr> |
183 |
</table> |
184 |
EOT; |
185 |
|
186 |
# Read the file. |
187 |
if (file_exists("$latestDirectory/$machine/$latestData")) { |
188 |
$input = file("$latestDirectory/$machine/$latestData"); |
189 |
# All we need is the first line if there is more than one line. |
190 |
$input = $input[0]; |
191 |
} |
192 |
|
193 |
if (empty($input)) { |
194 |
echo "<br><br>There are currently no latest details about <b>$machine</b>. Please notify your i-scream server administrator if you believe this to be incorrect."; |
195 |
} |
196 |
else { |
197 |
# Display the data specified in the display include. |
198 |
include("latest_display.inc.php"); |
199 |
} |
200 |
} |
201 |
|
202 |
?> |
203 |
|
204 |
<? printLine(""); ?> |
205 |
|
206 |
<? include($bottomHTML); ?> |