1 |
pjm2 |
1.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 |
|
|
|
14 |
|
|
# return an array of subdirectories from a directory. |
15 |
|
|
function getdirArray($dir='./',$sort='asort') { |
16 |
|
|
global $dir_file_count; |
17 |
|
|
if ( is_dir($dir) ) { |
18 |
|
|
$fd = @opendir($dir); |
19 |
|
|
while ( ($part = @readdir($fd)) == TRUE ) { |
20 |
|
|
clearstatcache(); |
21 |
|
|
if ($part != "." && $part != "..") { |
22 |
|
|
$dir_array[] = $part; |
23 |
|
|
} |
24 |
|
|
} |
25 |
|
|
if($fd == TRUE) { |
26 |
|
|
closedir($fd); |
27 |
|
|
} |
28 |
|
|
if (is_array($dir_array)) { |
29 |
|
|
$sort($dir_array); |
30 |
|
|
$dir_file_count = count($dir_array); |
31 |
|
|
Return $dir_array; |
32 |
|
|
} else { |
33 |
|
|
Return FALSE; |
34 |
|
|
} |
35 |
|
|
} else { |
36 |
|
|
Return FALSE; |
37 |
|
|
} |
38 |
|
|
} |
39 |
|
|
|
40 |
pjm2 |
1.9 |
function printLine($title) { |
41 |
pjm2 |
1.6 |
echo "<hr color=\"#9999ff\">"; |
42 |
pjm2 |
1.9 |
echo "<b>$title</b>"; |
43 |
pjm2 |
1.6 |
} |
44 |
|
|
|
45 |
pjm2 |
1.1 |
|
46 |
|
|
function showStat($title, $value, $input) { |
47 |
pjm2 |
1.7 |
preg_match("/$value=([^\,]*)[\,\}]/", $input, $matches); |
48 |
pjm2 |
1.1 |
$value = $matches[1]; |
49 |
|
|
if (empty($value)) { |
50 |
pjm2 |
1.8 |
$value = "<i><font color=\"#999999\">not sent</font></i>"; |
51 |
pjm2 |
1.1 |
} |
52 |
|
|
?> |
53 |
|
|
<table border="0" width="100%"> |
54 |
|
|
<tr> |
55 |
pjm2 |
1.12 |
<td width="50%" align="right" valign="top"><b><?=$title?></b></td> |
56 |
|
|
<td width="50%" align="left" valign="top"><?=$value?></td> |
57 |
pjm2 |
1.1 |
</tr> |
58 |
|
|
</table> |
59 |
|
|
<? |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
# show a bar-represented value. |
64 |
|
|
function showBar($title, $value, $max, $input) { |
65 |
|
|
|
66 |
|
|
include("latest_config.inc.php"); |
67 |
|
|
|
68 |
|
|
preg_match("/$value=([^\,]*)\,/", $input, $matches); |
69 |
|
|
$value = $matches[1]; |
70 |
|
|
if (!is_int($max)) { |
71 |
|
|
preg_match("/$max=([^\,]*)\,/", $input, $matches); |
72 |
|
|
$max = $matches[1]; |
73 |
|
|
} |
74 |
|
|
if (empty($value) || empty($max)) { |
75 |
|
|
return; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
$width = intval($max_width * $value / $max); |
79 |
|
|
|
80 |
|
|
?> |
81 |
pjm2 |
1.10 |
<table border="0" cellpadding="0" cellspacing="0" align="center"> |
82 |
pjm2 |
1.1 |
<tr> |
83 |
|
|
<td colspan="2"><b><?=$title?></b></td> |
84 |
|
|
</tr> |
85 |
|
|
<tr> |
86 |
|
|
<td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td> |
87 |
|
|
</tr> |
88 |
|
|
<tr> |
89 |
|
|
<td colspan="2"><img src="<?=$scaleImage?>" border="0" height="11" width="<?=$max_width?>"></td> |
90 |
|
|
</tr> |
91 |
|
|
<tr> |
92 |
|
|
<td align="left">0</td> |
93 |
|
|
<td align="right"><?=$max?></td> |
94 |
|
|
</tr> |
95 |
|
|
</table> |
96 |
|
|
<? |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
|
100 |
|
|
?> |
101 |
|
|
|
102 |
|
|
<? include($titleHTML); ?> |
103 |
|
|
|
104 |
pjm2 |
1.12 |
<? printLine("Display the latest information received from a host"); ?> |
105 |
pjm2 |
1.1 |
|
106 |
|
|
<form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>"> |
107 |
|
|
<? |
108 |
|
|
|
109 |
pjm2 |
1.5 |
$file_array = getdirArray($latestDirectory,'asort'); |
110 |
pjm2 |
1.1 |
print "<select size=\"1\" name=\"machine\">"; |
111 |
|
|
if ($machine) { ?> |
112 |
|
|
<option selected value="<? echo $machine ?>"><? echo $machine ?></option> |
113 |
|
|
<option value="">----------------</option> |
114 |
|
|
<? } |
115 |
|
|
foreach($file_array as $file_name) { |
116 |
pjm2 |
1.3 |
#if (is_dir($file_name)) { |
117 |
pjm2 |
1.1 |
print "<option value=\"$file_name\">$file_name</option>"; |
118 |
pjm2 |
1.3 |
#} |
119 |
pjm2 |
1.1 |
} |
120 |
|
|
print "</select>"; |
121 |
|
|
|
122 |
|
|
?> |
123 |
|
|
<input type="submit" name="submit" value="Display"> |
124 |
|
|
</form> |
125 |
|
|
|
126 |
pjm2 |
1.12 |
<hr weight="1" color="<? echo $lineColor ?>"> |
127 |
|
|
|
128 |
pjm2 |
1.1 |
<? if ($machine) { |
129 |
|
|
|
130 |
pjm2 |
1.12 |
$last_modified = filemtime("$latestDirectory/$machine/$latestData"); |
131 |
|
|
clearstatcache(); |
132 |
|
|
$data_age = time() - $last_modified; |
133 |
|
|
|
134 |
|
|
$last_modified = strftime("%a %d %b %Y at %T", $last_modified); |
135 |
|
|
|
136 |
|
|
if ($data_age > $warning_age) { |
137 |
|
|
$warning = <<<EOT |
138 |
|
|
<br> |
139 |
|
|
<font color="red"><b> |
140 |
|
|
Warning: |
141 |
|
|
</b></font> |
142 |
|
|
This realtime report is too old to be considered recent |
143 |
|
|
EOT; |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
echo <<<EOT |
147 |
|
|
<table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1" align="center"> |
148 |
|
|
<tr> |
149 |
|
|
<td bgcolor="#000066"> |
150 |
|
|
|
151 |
|
|
</td> |
152 |
|
|
<td bgcolor="#ffffcc"> |
153 |
|
|
<font face="arial,sans-serif" size="2"> |
154 |
|
|
<b>Recipt date:</b> $last_modified |
155 |
|
|
$warning |
156 |
|
|
</font> |
157 |
|
|
</td> |
158 |
|
|
</tr> |
159 |
|
|
</table> |
160 |
|
|
EOT; |
161 |
|
|
|
162 |
pjm2 |
1.1 |
# Read the file. |
163 |
|
|
#$input = "packet.attributes.machine_name=raptor.ukc.ac.uk,packet.memory.free=10,packet.memory.total=100,"; |
164 |
pjm2 |
1.2 |
$input = file("$latestDirectory/$machine/$latestData"); |
165 |
pjm2 |
1.1 |
# All we need is the first line if there is more than one line. |
166 |
|
|
$input = $input[0]; |
167 |
|
|
|
168 |
|
|
if (empty($input)) { |
169 |
|
|
echo "<br><br>There was an error reading from the latest packet received. Please notify your i-scream server administrator."; |
170 |
|
|
} |
171 |
|
|
else { |
172 |
|
|
# Display the data specified in the display include. |
173 |
|
|
include("latest_display.inc.php"); |
174 |
|
|
} |
175 |
pjm2 |
1.12 |
|
176 |
|
|
printLine(""); |
177 |
pjm2 |
1.9 |
} |
178 |
pjm2 |
1.12 |
|
179 |
pjm2 |
1.1 |
?> |
180 |
|
|
|
181 |
|
|
|
182 |
|
|
<? include($bottomHTML); ?> |