| 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($title) { | 
 
 
 
 
 | 41 | echo "<hr color=\"#9999ff\">"; | 
 
 
 
 
 | 42 | echo "<b>$title</b>"; | 
 
 
 
 
 | 43 | } | 
 
 
 
 
 | 44 |  | 
 
 
 
 
 | 45 |  | 
 
 
 
 
 | 46 | function showStat($title, $value, $input) { | 
 
 
 
 
 | 47 | preg_match("/$value=([^\,]*)[\,\}]/", $input, $matches); | 
 
 
 
 
 | 48 | $value = $matches[1]; | 
 
 
 
 
 | 49 | if (empty($value)) { | 
 
 
 
 
 | 50 | $value = "<i><font color=\"#999999\">not sent</font></i>"; | 
 
 
 
 
 | 51 | } | 
 
 
 
 
 | 52 | ?> | 
 
 
 
 
 | 53 | <table border="0" width="100%"> | 
 
 
 
 
 | 54 | <tr> | 
 
 
 
 
 | 55 | <td width="50%" align="right" valign="top"><b><?=$title?></b></td> | 
 
 
 
 
 | 56 | <td width="50%" align="left" valign="top"><?=$value?></td> | 
 
 
 
 
 | 57 | </tr> | 
 
 
 
 
 | 58 | </table> | 
 
 
 
 
 | 59 | <? | 
 
 
 
 
 | 60 | } | 
 
 
 
 
 | 61 |  | 
 
 
 
 
 | 62 |  | 
 
 
 
 
 | 63 | # show a bar-represented value. | 
 
 
 
 
 | 64 | function showBar($title, $value, $max, $units, $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 | <table border="0" cellpadding="0" cellspacing="0" align="center"> | 
 
 
 
 
 | 82 | <tr> | 
 
 
 
 
 | 83 | <td colspan="2"><b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></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<?=$units?></td> | 
 
 
 
 
 | 93 | <td align="right"><?=$max?><?=$units?></td> | 
 
 
 
 
 | 94 | </tr> | 
 
 
 
 
 | 95 | <tr> | 
 
 
 
 
 | 96 | <td colspan="2"> </td> | 
 
 
 
 
 | 97 | </tr> | 
 
 
 
 
 | 98 | </table> | 
 
 
 
 
 | 99 | <? | 
 
 
 
 
 | 100 | } | 
 
 
 
 
 | 101 |  | 
 
 
 
 
 | 102 |  | 
 
 
 
 
 | 103 | ?> | 
 
 
 
 
 | 104 |  | 
 
 
 
 
 | 105 | <? include($titleHTML); ?> | 
 
 
 
 
 | 106 |  | 
 
 
 
 
 | 107 | <? printLine("Display the latest information received from a host"); ?> | 
 
 
 
 
 | 108 |  | 
 
 
 
 
 | 109 | <form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>"> | 
 
 
 
 
 | 110 | <? | 
 
 
 
 
 | 111 |  | 
 
 
 
 
 | 112 | $file_array = getdirArray($latestDirectory,'asort'); | 
 
 
 
 
 | 113 | print "<select size=\"1\" name=\"machine\">"; | 
 
 
 
 
 | 114 | if ($machine) { ?> | 
 
 
 
 
 | 115 | <option selected value="<? echo $machine ?>"><? echo $machine ?></option> | 
 
 
 
 
 | 116 | <option value="">----------------</option> | 
 
 
 
 
 | 117 | <? } | 
 
 
 
 
 | 118 | foreach($file_array as $file_name) { | 
 
 
 
 
 | 119 | #if (is_dir($file_name)) { | 
 
 
 
 
 | 120 | print "<option value=\"$file_name\">$file_name</option>"; | 
 
 
 
 
 | 121 | #} | 
 
 
 
 
 | 122 | } | 
 
 
 
 
 | 123 | print "</select>"; | 
 
 
 
 
 | 124 |  | 
 
 
 
 
 | 125 | ?> | 
 
 
 
 
 | 126 | <input type="submit" name="submit" value="Display"> | 
 
 
 
 
 | 127 | </form> | 
 
 
 
 
 | 128 |  | 
 
 
 
 
 | 129 | <? if ($machine) { | 
 
 
 
 
 | 130 |  | 
 
 
 
 
 | 131 | $last_modified = filemtime("$latestDirectory/$machine/$latestData"); | 
 
 
 
 
 | 132 | clearstatcache(); | 
 
 
 
 
 | 133 | $data_age = time() - $last_modified; | 
 
 
 
 
 | 134 |  | 
 
 
 
 
 | 135 | $last_modified = date("l jS F - g:ia", $last_modified); | 
 
 
 
 
 | 136 |  | 
 
 
 
 
 | 137 | if ($data_age > $warning_age) { | 
 
 
 
 
 | 138 | $warning = <<<EOT | 
 
 
 
 
 | 139 | <br> | 
 
 
 
 
 | 140 | <font color="red"><b> | 
 
 
 
 
 | 141 | Warning: | 
 
 
 
 
 | 142 | </b></font> | 
 
 
 
 
 | 143 | This realtime report is too old to be considered recent | 
 
 
 
 
 | 144 | EOT; | 
 
 
 
 
 | 145 | } | 
 
 
 
 
 | 146 |  | 
 
 
 
 
 | 147 | echo <<<EOT | 
 
 
 
 
 | 148 | <table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1"> | 
 
 
 
 
 | 149 | <tr> | 
 
 
 
 
 | 150 | <td bgcolor="#000066"> | 
 
 
 
 
 | 151 |   | 
 
 
 
 
 | 152 | </td> | 
 
 
 
 
 | 153 | <td bgcolor="#ffffcc"> | 
 
 
 
 
 | 154 | <font face="arial,sans-serif" size="2"> | 
 
 
 
 
 | 155 | <b>Recipt date:</b> $last_modified | 
 
 
 
 
 | 156 | $warning | 
 
 
 
 
 | 157 | </font> | 
 
 
 
 
 | 158 | </td> | 
 
 
 
 
 | 159 | </tr> | 
 
 
 
 
 | 160 | </table> | 
 
 
 
 
 | 161 | EOT; | 
 
 
 
 
 | 162 |  | 
 
 
 
 
 | 163 | # Read the file. | 
 
 
 
 
 | 164 | #$input = "packet.attributes.machine_name=raptor.ukc.ac.uk,packet.memory.free=10,packet.memory.total=100,"; | 
 
 
 
 
 | 165 | $input = file("$latestDirectory/$machine/$latestData"); | 
 
 
 
 
 | 166 | # All we need is the first line if there is more than one line. | 
 
 
 
 
 | 167 | $input = $input[0]; | 
 
 
 
 
 | 168 |  | 
 
 
 
 
 | 169 | if (empty($input)) { | 
 
 
 
 
 | 170 | echo "<br><br>There was an error reading from the latest packet received.  Please notify your i-scream server administrator."; | 
 
 
 
 
 | 171 | } | 
 
 
 
 
 | 172 | else { | 
 
 
 
 
 | 173 | # Display the data specified in the display include. | 
 
 
 
 
 | 174 | include("latest_display.inc.php"); | 
 
 
 
 
 | 175 | } | 
 
 
 
 
 | 176 | } | 
 
 
 
 
 | 177 |  | 
 
 
 
 
 | 178 | ?> | 
 
 
 
 
 | 179 |  | 
 
 
 
 
 | 180 | <? printLine(""); ?> | 
 
 
 
 
 | 181 |  | 
 
 
 
 
 | 182 | <? include($bottomHTML); ?> |