1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
services_status.php
|
5
|
Copyright (C) 2004, 2005 Scott Ullrich
|
6
|
All rights reserved.
|
7
|
|
8
|
Redistribution and use in source and binary forms, with or without
|
9
|
modification, are permitted provided that the following conditions are met:
|
10
|
|
11
|
1. Redistributions of source code must retain the above copyright notice,
|
12
|
this list of conditions and the following disclaimer.
|
13
|
|
14
|
2. Redistributions in binary form must reproduce the above copyright
|
15
|
notice, this list of conditions and the following disclaimer in the
|
16
|
documentation and/or other materials provided with the distribution.
|
17
|
|
18
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
19
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
20
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
21
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
22
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27
|
POSSIBILITY OF SUCH DAMAGE.
|
28
|
*/
|
29
|
|
30
|
require("guiconfig.inc");
|
31
|
require("xmlparse_pkg.inc");
|
32
|
|
33
|
function gentitle_pkg($pgname) {
|
34
|
global $config;
|
35
|
return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
|
36
|
}
|
37
|
|
38
|
function find_package_description($package) {
|
39
|
global $g, $config;
|
40
|
if(!file_exists("{$g['tmp_path']}/pkg_config.xml"))
|
41
|
fetch_latest_pkg_config();
|
42
|
$pkg_config = parse_xml_config_pkg("{$g['tmp_path']}/pkg_config.xml", "pfsensepkgs");
|
43
|
foreach($pkg_config['packages']['package'] as $index) {
|
44
|
if($index['name'] == $package)
|
45
|
return $index['descr'];
|
46
|
}
|
47
|
return;
|
48
|
}
|
49
|
|
50
|
function get_package_rcd_details($extd) {
|
51
|
global $package_name, $executable_name, $description, $raw_name;
|
52
|
$raw_name = str_replace(".sh","",$extd);
|
53
|
$package_name = "";
|
54
|
$executable_name = "";
|
55
|
/* XXX: needs a get_pkg_description($packagename) function */
|
56
|
$description = "";
|
57
|
$file_contents = return_filename_as_string("/usr/local/etc/rc.d/{$extd}");
|
58
|
if (preg_match_all("/\# PACKAGE\: (.*)\n/",$file_contents,$match_array))
|
59
|
$package_name = $match_array[1][0];
|
60
|
if (preg_match_all("/\# EXECUTABLE\: (.*)\n/",$file_contents,$match_array))
|
61
|
$executable_name = $match_array[1][0];
|
62
|
/* if we cannot locate it atleast return what they passed us */
|
63
|
if($package_name == "")
|
64
|
$package_name = str_replace(".sh","",$extd);
|
65
|
if($executable_name == "")
|
66
|
$executable_name = str_replace(".sh","",$extd);
|
67
|
$description = find_package_description($raw_name);
|
68
|
if($description == "")
|
69
|
$description = " ";
|
70
|
}
|
71
|
|
72
|
if($_GET['service'] <> "")
|
73
|
get_package_rcd_details($_GET['service'] . ".sh");
|
74
|
|
75
|
if($_GET['restartservice'] == "true") {
|
76
|
mwexec("/sbin/killall $executable_name");
|
77
|
mwexec("/bin/sh /usr/local/etc/rc.d/{$raw_name}.sh start");
|
78
|
$status = is_service_running($executable_name);
|
79
|
if($status == 1) {
|
80
|
$savemsg = "{$package_name} has been restarted.";
|
81
|
} else {
|
82
|
$error_message = exec_command("/bin/sh /usr/local/etc/rc.d/{$raw_name}.sh");
|
83
|
$savemsg = "There was a error restarting {$package_name}.<p>{$error_message}";
|
84
|
}
|
85
|
}
|
86
|
|
87
|
if($_GET['stopservice'] == "true") {
|
88
|
mwexec("/sbin/killall $executable_name");
|
89
|
$savemsg = "{$package_name} has been stopped.";
|
90
|
}
|
91
|
|
92
|
if($_GET['startservice'] == "true") {
|
93
|
mwexec("/bin/sh /usr/local/etc/rc.d/{$raw_name}.sh start");
|
94
|
if($status == 1) {
|
95
|
$savemsg = "{$package_name} has been started.";
|
96
|
} else {
|
97
|
$error_message = exec_command("/bin/sh /usr/local/etc/rc.d/{$raw_name}.sh");
|
98
|
$savemsg = "There was a error restarting {$package_name}.<p>{$error_message}";
|
99
|
}
|
100
|
|
101
|
}
|
102
|
|
103
|
/* batch mode, allow other scripts to call this script */
|
104
|
if($_GET['batch'] <> "") exit;
|
105
|
|
106
|
?>
|
107
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
108
|
<html>
|
109
|
<head>
|
110
|
<?php $title = "Status: Services"; ?>
|
111
|
<title><?=gentitle_pkg($title);?></title>
|
112
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
113
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
114
|
</head>
|
115
|
|
116
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
117
|
<?php
|
118
|
include("fbegin.inc");
|
119
|
?>
|
120
|
<p class="pgtitle"><?=$title?></p>
|
121
|
<form action="status_services.php" method="post">
|
122
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
123
|
|
124
|
<p>
|
125
|
|
126
|
|
127
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
128
|
<tr>
|
129
|
<td class="tabcont">
|
130
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
131
|
<tr>
|
132
|
<td class="listhdrr"><b><center>Service</center></b></td>
|
133
|
<td class="listhdrr"><b><center>Description</center></b></td>
|
134
|
<td class="listhdrr"><b><center>Status</center></b></td>
|
135
|
<td class="listhdrr"><b><center>Maintenance</center></b></td>
|
136
|
</tr>
|
137
|
|
138
|
<?php
|
139
|
|
140
|
$dh = @opendir("/usr/local/etc/rc.d/");
|
141
|
if ($dh)
|
142
|
while (($extd = readdir($dh)) !== false) {
|
143
|
if (($extd == ".") || ($extd == ".."))
|
144
|
continue;
|
145
|
get_package_rcd_details($extd);
|
146
|
if($executable_name == "")
|
147
|
continue;
|
148
|
if($package_name == "")
|
149
|
continue;
|
150
|
if(get_pkg_id($package_name) == -1)
|
151
|
continue;
|
152
|
$status = is_service_running($executable_name);
|
153
|
if($status == 1)
|
154
|
$status_txt = "<font color='green'>Running</font>";
|
155
|
else
|
156
|
$status_txt = "<font color='red'>Stopped</font>";
|
157
|
echo "<tr><td class=\"listlr\">{$package_name}</td>";
|
158
|
echo "<td class=\"listlr\">{$description}</td>";
|
159
|
echo "<td class=\"listlr\">{$status_txt}</td>";
|
160
|
echo "<td class=\"listlr\"><center>";
|
161
|
if($status == 1) {
|
162
|
echo "<a href='status_services.php?restartservice=true&service={$raw_name}'>";
|
163
|
echo "<img title='Restart Service' border='0' src='/service_restart.gif'></a> ";
|
164
|
echo "<a href='status_services.php?stopservice=true&service={$raw_name}'>";
|
165
|
echo "<img title='Stop Service' border='0' src='/service_stop.gif'> ";
|
166
|
echo "</a> ";
|
167
|
} else {
|
168
|
echo "<a href='status_services.php?startservice=true&service={$raw_name}'> ";
|
169
|
echo "<img title='Start Service' border='0' src='/service_start.gif'></a> ";
|
170
|
}
|
171
|
echo "</center></td>";
|
172
|
echo "</tr>";
|
173
|
$counter++;
|
174
|
}
|
175
|
|
176
|
if($counter == 0)
|
177
|
echo "<tr><td colspan=5><center>Could not locate any services.</td></tr>";
|
178
|
|
179
|
?>
|
180
|
<tr><td>
|
181
|
</td></tr>
|
182
|
</table>
|
183
|
|
184
|
</td>
|
185
|
</tr></table>
|
186
|
|
187
|
<?php include("fend.inc"); ?>
|
188
|
</body>
|
189
|
</html>
|