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
|
|
32
|
function gentitle_pkg($pgname) {
|
33
|
global $config;
|
34
|
return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
|
35
|
}
|
36
|
|
37
|
if($_GET['mode'] == "restartservice" and $_GET['service']) {
|
38
|
restart_service($_GET['service']);
|
39
|
$savemsg = "{$_GET['service']} has been restarted.";
|
40
|
}
|
41
|
|
42
|
if($_GET['mode'] == "startservice" and $_GET['service']) {
|
43
|
start_service($_GET['service']);
|
44
|
$savemsg = "{$_GET['service']} has been started.";
|
45
|
}
|
46
|
|
47
|
if($_GET['mode'] == "stopservice" and $_GET['service']) {
|
48
|
stop_service($_GET['service']);
|
49
|
$savemsg = "{$_GET['service']} has been stopped.";
|
50
|
}
|
51
|
|
52
|
/* batch mode, allow other scripts to call this script */
|
53
|
if($_GET['batch']) exit;
|
54
|
|
55
|
$pgtitle = "Status: Services";
|
56
|
include("head.inc");
|
57
|
|
58
|
?>
|
59
|
|
60
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
61
|
<?php
|
62
|
include("fbegin.inc");
|
63
|
?>
|
64
|
<p class="pgtitle"><?=$pgtitle?></p>
|
65
|
<form action="status_services.php" method="post">
|
66
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
67
|
|
68
|
<p>
|
69
|
|
70
|
<div id="boxarea">
|
71
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
72
|
<tr>
|
73
|
<td>
|
74
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
75
|
<tr>
|
76
|
<td class="listhdrr"><b><center>Service</center></b></td>
|
77
|
<td class="listhdrr"><b><center>Description</center></b></td>
|
78
|
<td class="listhdrr"><b><center>Status</center></b></td>
|
79
|
</tr>
|
80
|
|
81
|
<?php
|
82
|
|
83
|
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
|
84
|
array_shift($psout);
|
85
|
foreach($psout as $line) {
|
86
|
$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
|
87
|
}
|
88
|
|
89
|
$services = $config['installedpackages']['service'];
|
90
|
|
91
|
/* Add services that are in the base.
|
92
|
*
|
93
|
*/
|
94
|
if(isset($config['dnsmasq']['enable'])) {
|
95
|
$pconfig['name'] = "dnsmasq";
|
96
|
$pconfig['description'] = "DNS Forwarder";
|
97
|
$services[] = $pconfig;
|
98
|
unset($pconfig);
|
99
|
}
|
100
|
|
101
|
if(isset($config['captiveportal']['enable'])) {
|
102
|
$pconfig['name'] = "mini_httpd";
|
103
|
$pconfig['description'] = "Captive Portal";
|
104
|
$services[] = $pconfig;
|
105
|
$pconfig = "";
|
106
|
unset($pconfig);
|
107
|
}
|
108
|
|
109
|
if(isset($config['dnsmasq']['enable'])) {
|
110
|
$pconfig['name'] = "dhcprelay";
|
111
|
$pconfig['description'] = "DHCP Relay";
|
112
|
$services[] = $pconfig;
|
113
|
unset($pconfig);
|
114
|
}
|
115
|
|
116
|
if(isset($config['dhcpd']['enable'])) {
|
117
|
$pconfig['name'] = "dhcpd";
|
118
|
$pconfig['description'] = "DHCP Server";
|
119
|
$services[] = $pconfig;
|
120
|
unset($pconfig);
|
121
|
}
|
122
|
|
123
|
if(isset($config['snmpd']['enable'])) {
|
124
|
$pconfig['name'] = "bsnmpd";
|
125
|
$pconfig['description'] = "SNMP";
|
126
|
$services[] = $pconfig;
|
127
|
unset($pconfig);
|
128
|
}
|
129
|
|
130
|
if(isset($config['wol']['wolentry'])) {
|
131
|
$pconfig['name'] = "wol";
|
132
|
$pconfig['description'] = "Wake on lan";
|
133
|
$services[] = $pconfig;
|
134
|
unset($pconfig);
|
135
|
}
|
136
|
|
137
|
if(isset($config['proxyarp']['proxyarpnet'])) {
|
138
|
$pconfig['name'] = "choparp";
|
139
|
$pconfig['description'] = "Proxy Arp";
|
140
|
$services[] = $pconfig;
|
141
|
unset($pconfig);
|
142
|
}
|
143
|
|
144
|
if($services) {
|
145
|
foreach($services as $service) {
|
146
|
if(!$service['name']) continue;
|
147
|
if(!$service['description']) $service['description'] = "Unknown";
|
148
|
echo '<tr><td class="listlr">' . $service['name'] . '</td>';
|
149
|
echo '<td class="listlr">' . $service['description'] . '</td>';
|
150
|
if(is_service_running($service['name'], $ps) or is_process_running($service['name']) ) {
|
151
|
echo '<td class="listlr">Running</td><td><img src="/themes/';
|
152
|
echo $g["theme"] . '/images/icons/icon_pass.gif"></td>';
|
153
|
$running = true;
|
154
|
} else {
|
155
|
echo '<td class="listbg"><font color="white">Stopped</td><td><img src="/themes/';
|
156
|
echo $g["theme"] . '/images/icons/icon_block.gif"></td>';
|
157
|
$running = false;
|
158
|
}
|
159
|
echo '<td valign="middle" class="list" nowrap>';
|
160
|
if($running) {
|
161
|
echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
|
162
|
echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
|
163
|
echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'>";
|
164
|
echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
|
165
|
echo "</a>";
|
166
|
} else {
|
167
|
echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
|
168
|
echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
|
169
|
}
|
170
|
echo '</td>';
|
171
|
echo '</tr>';
|
172
|
}
|
173
|
} else {
|
174
|
echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
|
175
|
}
|
176
|
?>
|
177
|
</table>
|
178
|
|
179
|
</td>
|
180
|
</tr></table>
|
181
|
</div>
|
182
|
|
183
|
<?php include("fend.inc"); ?>
|
184
|
</body>
|
185
|
</html>
|
186
|
|