Revision 312d166b
Added by Jim Pingle over 15 years ago
usr/local/www/widgets/include/gmirror_status.inc | ||
---|---|---|
1 | 1 |
<?php |
2 |
function get_gmirror_status() { |
|
2 |
/* |
|
3 |
gmirror_status.widget.php |
|
4 |
Copyright (C) 2009-2010 Jim Pingle |
|
5 |
|
|
6 |
Redistribution and use in source and binary forms, with or without |
|
7 |
modification, are permitted provided that the following conditions are met: |
|
8 |
|
|
9 |
1. Redistributions of source code must retain the above copyright notice, |
|
10 |
this list of conditions and the following disclaimer. |
|
11 |
|
|
12 |
2. Redistributions in binary form must reproduce the above copyright |
|
13 |
notice, this list of conditions and the following disclaimer in the |
|
14 |
documentation and/or other materials provided with the distribution. |
|
15 |
|
|
16 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
17 |
INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
18 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
19 |
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
20 |
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
21 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
22 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
23 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
24 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
25 |
POSSIBILITY OF SUCH DAMAGE. |
|
26 |
*/ |
|
27 |
|
|
28 |
function gmirror_get_status() { |
|
3 | 29 |
$status = ""; |
4 | 30 |
exec("/sbin/gmirror status", $status); |
5 | 31 |
$mirrors = array(); |
... | ... | |
28 | 54 |
} |
29 | 55 |
/* Return an hash of mirrors and components */ |
30 | 56 |
return $mirrors; |
31 |
} ?> |
|
57 |
} |
|
58 |
|
|
59 |
function gmirror_html_status() { |
|
60 |
$mirrors = gmirror_get_status(); |
|
61 |
$output = ""; |
|
62 |
if (count($mirrors) > 0) { |
|
63 |
$output .= "<tr>\n"; |
|
64 |
$output .= "<td width=\"40%\" class=\"vncellt\">Name</td>\n"; |
|
65 |
$output .= "<td width=\"40%\" class=\"vncellt\">Status</td>\n"; |
|
66 |
$output .= "<td width=\"20%\" class=\"vncellt\">Component</td>\n"; |
|
67 |
$output .= "</tr>\n"; |
|
68 |
foreach ($mirrors as $mirror => $name) { |
|
69 |
$components = count($name["components"]); |
|
70 |
$output .= "<tr>\n"; |
|
71 |
$output .= "<td width=\"40%\" rowspan=\"{$components}\" class=\"listr\">{$name['name']}</td>\n"; |
|
72 |
$output .= "<td width=\"40%\" rowspan=\"{$components}\" class=\"listr\">{$name['status']}</td>\n"; |
|
73 |
$output .= "<td width=\"20%\" class=\"listr\">{$name['components'][0]}</td>\n"; |
|
74 |
$output .= "</tr>\n"; |
|
75 |
if (count($name["components"]) > 1) { |
|
76 |
$morecomponents = array_slice($name["components"], 1); |
|
77 |
foreach ($morecomponents as $component) { |
|
78 |
$output .= "<tr>\n"; |
|
79 |
$output .= "<td width=\"20%\" class=\"listr\">{$component}</td>\n"; |
|
80 |
$output .= "</tr>\n"; |
|
81 |
} |
|
82 |
} |
|
83 |
} |
|
84 |
} else { |
|
85 |
$output .= "<tr><td colspan=\"3\" class=\"listr\">No Mirrors Found</td></tr>\n"; |
|
86 |
} |
|
87 |
// $output .= "<tr><td colspan=\"3\" class=\"listr\">Updated at " . date("F j, Y, g:i:s a") . "</td></tr>\n"; |
|
88 |
return $output; |
|
89 |
} |
|
90 |
?> |
usr/local/www/widgets/widgets/gmirror_status.widget.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
/* |
3 | 3 |
gmirror_status.widget.php |
4 |
Copyright (C) 2009 Jim Pingle |
|
4 |
Copyright (C) 2009-2010 Jim Pingle
|
|
5 | 5 |
|
6 | 6 |
Redistribution and use in source and binary forms, with or without |
7 | 7 |
modification, are permitted provided that the following conditions are met: |
... | ... | |
27 | 27 |
|
28 | 28 |
require_once("/usr/local/www/widgets/include/gmirror_status.inc"); |
29 | 29 |
|
30 |
$mirrors = get_gmirror_status(); |
|
31 |
|
|
30 |
if ($_GET['textonly'] == "true") { |
|
31 |
header("Cache-Control: no-cache"); |
|
32 |
echo gmirror_html_status(); |
|
33 |
exit; |
|
34 |
} |
|
32 | 35 |
?> |
33 | 36 |
<table width="100%" border="0" cellspacing="0" cellpadding="0"> |
34 |
<tbody> |
|
35 |
<?php if (count($mirrors) > 0) { ?> |
|
36 |
<tr> |
|
37 |
<td width="40%" class="vncellt">Name</td> |
|
38 |
<td width="40%" class="vncellt">Status</td> |
|
39 |
<td width="20%" class="vncellt">Component</td> |
|
40 |
</tr> |
|
41 |
<?php foreach ($mirrors as $mirror => $name) { ?> |
|
42 |
<tr> |
|
43 |
<td width="40%" rowspan="<?= count($name["components"]) ?>" class="listr"><?= $name["name"] ?></td> |
|
44 |
<td width="40%" rowspan="<?= count($name["components"]) ?>" class="listr"><?= $name["status"] ?></td> |
|
45 |
<td width="20%" class="listr"><?= $name["components"][0] ?></td> |
|
46 |
</tr> |
|
47 |
<?php |
|
48 |
if (count($name["components"]) > 1) { |
|
49 |
$morecomponents = array_slice($name["components"], 1); |
|
50 |
foreach ($morecomponents as $component) { ?> |
|
51 |
<tr> |
|
52 |
<td width="20%" class="listr"><?= $component ?></td> |
|
53 |
</tr> |
|
54 |
<?php } |
|
55 |
} ?> |
|
56 |
<?php } ?> |
|
57 |
<?php } else { ?> |
|
58 |
<tr><td colspan="3" class="listr">No Mirrors Found</td></tr> |
|
59 |
<?php } ?> |
|
37 |
<tbody id="gmirror_status_table"> |
|
38 |
<?php echo gmirror_html_status(); ?> |
|
60 | 39 |
</tbody> |
61 | 40 |
</table> |
41 |
|
|
42 |
<script type="text/javascript" language="javascript"> |
|
43 |
// <![CDATA[ |
|
44 |
var gmirrorupdater = new Ajax.PeriodicalUpdater('gmirror_status_table', '/widgets/widgets/gmirror_status.widget.php?textonly=true', |
|
45 |
{ method: 'get', frequency: 5 } ); |
|
46 |
// ]]> |
|
47 |
</script> |
Also available in: Unified diff
AJAX-ify the gmirror status widget. Add license header while I'm here.