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 |
function printLine() { |
41 |
echo "<hr color=\"#9999ff\">"; |
42 |
} |
43 |
|
44 |
|
45 |
function showStat($title, $value, $input) { |
46 |
preg_match("/$value=([^\,]*)[\,\}]/", $input, $matches); |
47 |
$value = $matches[1]; |
48 |
if (empty($value)) { |
49 |
$value = "<i><font color=\"#999999\">not sent</font></i>"; |
50 |
} |
51 |
?> |
52 |
<table border="0" width="100%"> |
53 |
<tr> |
54 |
<td width="50%" align="right" valign="top"><b><?=$title?></b></td> |
55 |
<td width="50%" align="left" valign="top"><?=$value?></td> |
56 |
</tr> |
57 |
</table> |
58 |
<? |
59 |
} |
60 |
|
61 |
|
62 |
# show a bar-represented value. |
63 |
function showBar($title, $value, $max, $input) { |
64 |
|
65 |
include("latest_config.inc.php"); |
66 |
|
67 |
preg_match("/$value=([^\,]*)\,/", $input, $matches); |
68 |
$value = $matches[1]; |
69 |
if (!is_int($max)) { |
70 |
preg_match("/$max=([^\,]*)\,/", $input, $matches); |
71 |
$max = $matches[1]; |
72 |
} |
73 |
if (empty($value) || empty($max)) { |
74 |
return; |
75 |
} |
76 |
|
77 |
$width = intval($max_width * $value / $max); |
78 |
|
79 |
?> |
80 |
<table border="0" cellpadding="0" cellspacing="0"> |
81 |
<tr> |
82 |
<td colspan="2"><b><?=$title?></b></td> |
83 |
</tr> |
84 |
<tr> |
85 |
<td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td> |
86 |
</tr> |
87 |
<tr> |
88 |
<td colspan="2"><img src="<?=$scaleImage?>" border="0" height="11" width="<?=$max_width?>"></td> |
89 |
</tr> |
90 |
<tr> |
91 |
<td align="left">0</td> |
92 |
<td align="right"><?=$max?></td> |
93 |
</tr> |
94 |
</table> |
95 |
<? |
96 |
} |
97 |
|
98 |
|
99 |
?> |
100 |
|
101 |
<? include($titleHTML); ?> |
102 |
|
103 |
<hr weight="1" color="<? echo $lineColor ?>"> |
104 |
|
105 |
<b>Display the latest information received from a host</b> |
106 |
<form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>"> |
107 |
<? |
108 |
|
109 |
$file_array = getdirArray($latestDirectory,'asort'); |
110 |
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 |
#if (is_dir($file_name)) { |
117 |
print "<option value=\"$file_name\">$file_name</option>"; |
118 |
#} |
119 |
} |
120 |
print "</select>"; |
121 |
|
122 |
?> |
123 |
<input type="submit" name="submit" value="Display"> |
124 |
</form> |
125 |
|
126 |
<hr weight="1" color="<? echo $lineColor ?>"> |
127 |
|
128 |
<? if ($machine) { |
129 |
|
130 |
# Read the file. |
131 |
#$input = "packet.attributes.machine_name=raptor.ukc.ac.uk,packet.memory.free=10,packet.memory.total=100,"; |
132 |
$input = file("$latestDirectory/$machine/$latestData"); |
133 |
# All we need is the first line if there is more than one line. |
134 |
$input = $input[0]; |
135 |
|
136 |
if (empty($input)) { |
137 |
echo "<br><br>There was an error reading from the latest packet received. Please notify your i-scream server administrator."; |
138 |
} |
139 |
else { |
140 |
# Display the data specified in the display include. |
141 |
include("latest_display.inc.php"); |
142 |
} |
143 |
} |
144 |
|
145 |
?> |
146 |
|
147 |
|
148 |
<? include($bottomHTML); ?> |