1
|
<?php
|
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() {
|
29
|
$status = "";
|
30
|
exec("/sbin/gmirror status -s", $status);
|
31
|
$mirrors = array();
|
32
|
|
33
|
/* Empty output = no mirrors found */
|
34
|
if (count($status) > 0) {
|
35
|
/* Loop through gmirror status output. */
|
36
|
foreach ($status as $line) {
|
37
|
/* Split the line by whitespace */
|
38
|
$all = preg_split("/[\s\t]+/", trim($line), 3);
|
39
|
if (count($all) == 3) {
|
40
|
/* If there are three items on a line, it is mirror name, status, and component */
|
41
|
$currentmirror = $all[0];
|
42
|
$mirrors[$currentmirror]["name"] = $all[0];
|
43
|
$mirrors[$currentmirror]["status"] = $all[1];
|
44
|
if (!is_array($mirrors[$currentmirror]["components"]))
|
45
|
$mirrors[$currentmirror]["components"] = array();
|
46
|
$mirrors[$currentmirror]["components"][] = $all[2];
|
47
|
}
|
48
|
}
|
49
|
}
|
50
|
/* Return an hash of mirrors and components */
|
51
|
return $mirrors;
|
52
|
}
|
53
|
|
54
|
function gmirror_html_status() {
|
55
|
$mirrors = gmirror_get_status();
|
56
|
$output = "";
|
57
|
if (count($mirrors) > 0) {
|
58
|
$output .= "<tr>\n";
|
59
|
$output .= "<td width=\"40%\" class=\"vncellt\">Name</td>\n";
|
60
|
$output .= "<td width=\"40%\" class=\"vncellt\">Status</td>\n";
|
61
|
$output .= "<td width=\"20%\" class=\"vncellt\">Component</td>\n";
|
62
|
$output .= "</tr>\n";
|
63
|
foreach ($mirrors as $mirror => $name) {
|
64
|
$components = count($name["components"]);
|
65
|
$output .= "<tr>\n";
|
66
|
$output .= "<td width=\"40%\" rowspan=\"{$components}\" class=\"listr\">{$name['name']}</td>\n";
|
67
|
$output .= "<td width=\"40%\" rowspan=\"{$components}\" class=\"listr\">{$name['status']}</td>\n";
|
68
|
$output .= "<td width=\"20%\" class=\"listr\">{$name['components'][0]}</td>\n";
|
69
|
$output .= "</tr>\n";
|
70
|
if (count($name["components"]) > 1) {
|
71
|
$morecomponents = array_slice($name["components"], 1);
|
72
|
foreach ($morecomponents as $component) {
|
73
|
$output .= "<tr>\n";
|
74
|
$output .= "<td width=\"20%\" class=\"listr\">{$component}</td>\n";
|
75
|
$output .= "</tr>\n";
|
76
|
}
|
77
|
}
|
78
|
}
|
79
|
} else {
|
80
|
$output .= "<tr><td colspan=\"3\" class=\"listr\">No Mirrors Found</td></tr>\n";
|
81
|
}
|
82
|
// $output .= "<tr><td colspan=\"3\" class=\"listr\">Updated at " . date("F j, Y, g:i:s a") . "</td></tr>\n";
|
83
|
return $output;
|
84
|
}
|
85
|
?>
|