Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
1 a0e4cea2 Scott Ullrich
<?php
2
/*
3 ef09107d Colin Smith
    services_status.php
4
    Copyright (C) 2004, 2005 Scott Ullrich
5 a0e4cea2 Scott Ullrich
    All rights reserved.
6
7
    Redistribution and use in source and binary forms, with or without
8
    modification, are permitted provided that the following conditions are met:
9
10
    1. Redistributions of source code must retain the above copyright notice,
11
       this list of conditions and the following disclaimer.
12
13
    2. Redistributions in binary form must reproduce the above copyright
14
       notice, this list of conditions and the following disclaimer in the
15
       documentation and/or other materials provided with the distribution.
16
17
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 ef09107d Colin Smith
    INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19 a0e4cea2 Scott Ullrich
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
    POSSIBILITY OF SUCH DAMAGE.
27
*/
28
29 6b07c15a Matthew Grooms
##|+PRIV
30
##|*IDENT=page-status-services
31
##|*NAME=Status: Services page
32
##|*DESCR=Allow access to the 'Status: Services' page.
33
##|*MATCH=status_services.php*
34
##|-PRIV
35
36
37 bc2e6100 Colin Smith
require("guiconfig.inc");
38 a0e4cea2 Scott Ullrich
39
function gentitle_pkg($pgname) {
40
	global $config;
41
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
42
}
43
44 5d8bcb27 Scott Ullrich
function get_pkg_descr($package_name) {
45
	global $config;
46
	foreach($config['installedpackages']['package'] as $pkg) {
47
		if($pkg['name'] == $package_name)
48
			return $pkg['descr'];
49
	}
50
	return "Not available.";
51
}
52
53 b9eadc0c Colin Smith
if($_GET['mode'] == "restartservice" and $_GET['service']) {
54 6c3e2b19 Scott Ullrich
	switch($_GET['service']) {
55
		case 'bsnmpd':
56
			services_snmpd_configure();
57
			break;
58
		case 'dnsmasq':
59
			services_dnsmasq_configure();
60
			break;
61
		case 'dhcpd':
62
			services_dhcpd_configure();
63 422e039b Scott Ullrich
			break;
64
		case 'miniupnpd':
65 431484c8 Ryan Wagoner
			upnp_action('restart');	
66 6c3e2b19 Scott Ullrich
			break;
67 cd72ded3 Timo Boettcher
		case 'racoon':
68
			exec("killall -9 racoon");
69
			sleep(1);
70
			vpn_ipsec_force_reload();
71
			break;
72
		case 'openvpn':         
73
			$vpnmode = $_GET['vpnmode'];
74
			if (($vpnmode == "server") or ($vpnmode == "client")) {
75
				$id = $_GET['id'];
76
				if (is_numeric($id)) {
77
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
78
					killbypid($pidfile);
79
					sleep(1);
80
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
81
					mwexec_bg("openvpn --config $configfile");
82
				}
83
			}
84
			break;
85 6c3e2b19 Scott Ullrich
		default:
86
			restart_service($_GET['service']);
87
			break;
88
	}
89 b9eadc0c Colin Smith
	$savemsg = "{$_GET['service']} has been restarted.";
90 422e039b Scott Ullrich
	sleep(5);
91 a0e4cea2 Scott Ullrich
}
92
93 b9eadc0c Colin Smith
if($_GET['mode'] == "startservice" and $_GET['service']) {
94 3e32a807 Scott Ullrich
	switch($_GET['service']) {
95
		case 'bsnmpd':
96 3af54e48 Scott Ullrich
			services_snmpd_configure();
97 3e32a807 Scott Ullrich
			break;
98
		case 'dnsmasq':
99
			services_dnsmasq_configure();
100
			break;
101
		case 'dhcpd':
102
			services_dhcpd_configure();
103 422e039b Scott Ullrich
			break;
104
		case 'miniupnpd':
105 431484c8 Ryan Wagoner
			upnp_action('start');
106 3e32a807 Scott Ullrich
			break;
107 cd72ded3 Timo Boettcher
		case 'racoon':
108
			exec("killall -9 racoon");
109
			sleep(1);
110
			vpn_ipsec_force_reload();
111
			break;
112
		case 'openvpn':
113
			$vpnmode = $_GET['vpnmode'];
114
			if (($vpnmode == "server") or ($vpnmode == "client")) {
115
				$id = $_GET['id'];
116
				if (is_numeric($id)) {
117
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
118
					mwexec_bg("openvpn --config $configfile");
119
				}
120
			}
121
			break;
122 3e32a807 Scott Ullrich
		default:
123
			start_service($_GET['service']);
124
			break;
125
	}
126 cd72ded3 Timo Boettcher
	$savemsg = "{$_GET['service']} has been started.";
127 422e039b Scott Ullrich
	sleep(5);
128 a0e4cea2 Scott Ullrich
}
129
130 25b66ec5 Scott Ullrich
/* stop service */
131
if($_GET['mode'] == "stopservice" && $_GET['service']) {
132 422e039b Scott Ullrich
	switch($_GET['service']) {
133 25b66ec5 Scott Ullrich
		case 'bsnmpd':
134
			killbypid("{$g['varrun_path']}/snmpd.pid");
135
			break;
136
		case 'choparp':
137
			killbyname("choparp");
138
			break;
139 cd72ded3 Timo Boettcher
		case 'dhcpd':
140 25b66ec5 Scott Ullrich
			killbyname("dhcpd");
141 cd72ded3 Timo Boettcher
			break;
142
		case 'dhcrelay':
143
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
144
			break;
145
		case 'dnsmasq':
146 25b66ec5 Scott Ullrich
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
147
			break;
148 422e039b Scott Ullrich
		case 'miniupnpd':
149 431484c8 Ryan Wagoner
			upnp_action('stop');
150 25b66ec5 Scott Ullrich
			break;
151
		case 'ntpd':
152
			killbyname("ntpd");
153 cd72ded3 Timo Boettcher
			break;
154
		case 'sshd':
155 25b66ec5 Scott Ullrich
			killbyname("sshd");
156 cd72ded3 Timo Boettcher
			break;
157
		case 'racoon':
158
			exec("killall -9 racoon");
159
			break;
160
		case 'openvpn':         
161
			$vpnmode = $_GET['vpnmode'];
162
			if (($vpnmode == "server") or ($vpnmode == "client")) {
163
				$id = $_GET['id'];
164
				if (is_numeric($id)) {
165
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
166
					killbypid($pidfile);
167
				}
168
			}
169
			break;
170 422e039b Scott Ullrich
		default:
171 cd72ded3 Timo Boettcher
			stop_service($_GET['service']);
172 422e039b Scott Ullrich
			break;
173
	}
174 cd72ded3 Timo Boettcher
	$savemsg = "{$_GET['service']} " . gettext("has been stopped.");
175
	sleep(5);
176 a0e4cea2 Scott Ullrich
}
177
178
/* batch mode, allow other scripts to call this script */
179 b9eadc0c Colin Smith
if($_GET['batch']) exit;
180
181 d88c6a9f Scott Ullrich
$pgtitle = array("Status","Services");
182 4df96eff Scott Ullrich
include("head.inc");
183
184 a0e4cea2 Scott Ullrich
?>
185
186
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
187
<?php
188
include("fbegin.inc");
189
?>
190
<form action="status_services.php" method="post">
191
<?php if ($savemsg) print_info_box($savemsg); ?>
192
193
<p>
194
195 0f10aee4 Bill Marquette
<div id="boxarea">
196
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
197 a9bc3b82 Scott Ullrich
  <tr>
198 0f10aee4 Bill Marquette
    <td>
199 a9bc3b82 Scott Ullrich
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
200
	<tr>
201
	  <td class="listhdrr"><b><center>Service</center></b></td>
202
	  <td class="listhdrr"><b><center>Description</center></b></td>
203
	  <td class="listhdrr"><b><center>Status</center></b></td>
204
	</tr>
205
206 a0e4cea2 Scott Ullrich
<?php
207
208 3af54e48 Scott Ullrich
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
209 ef09107d Colin Smith
array_shift($psout);
210
foreach($psout as $line) {
211
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
212
}
213
214 7670e4d2 Scott Ullrich
$services = $config['installedpackages']['service'];
215 25d3fbd5 Scott Ullrich
216
/*    Add services that are in the base.
217
 *
218
 */
219
if(isset($config['dnsmasq']['enable'])) {
220
	$pconfig['name'] = "dnsmasq";
221
	$pconfig['description'] = "DNS Forwarder";
222
	$services[] = $pconfig;
223 7670e4d2 Scott Ullrich
	unset($pconfig);
224 25d3fbd5 Scott Ullrich
}
225
226
if(isset($config['captiveportal']['enable'])) {
227 a17d277c Scott Ullrich
	$pconfig['name'] = "lighttpd";
228 25d3fbd5 Scott Ullrich
	$pconfig['description'] = "Captive Portal";
229
	$services[] = $pconfig;
230 7670e4d2 Scott Ullrich
	$pconfig = "";
231
	unset($pconfig);
232 25d3fbd5 Scott Ullrich
}
233
234 3e321df2 Ermal Luçi
$iflist = array();
235
$ifdescrs = get_configured_interface_list();
236
foreach ($ifdescrs as $if) {
237
	$oc = $config['interfaces'][$if];
238
	if ($oc['if'] && (!$oc['bridge']))
239
		$iflist[$if] = $if;
240 51bb9b94 Scott Ullrich
}
241
$show_dhcprelay = false;
242
foreach($iflist as $if) {
243
	if(isset($config['dhcrelay'][$if]['enable']))
244
		$show_dhcprelay = true;
245
}
246
247
if($show_dhcprelay == true) {
248 c214e575 Scott Ullrich
	$pconfig['name'] = "dhcrelay";
249 25d3fbd5 Scott Ullrich
	$pconfig['description'] = "DHCP Relay";
250
	$services[] = $pconfig;
251 7670e4d2 Scott Ullrich
	unset($pconfig);
252 25d3fbd5 Scott Ullrich
}
253
254 3af54e48 Scott Ullrich
if(is_dhcp_server_enabled()) {
255 25d3fbd5 Scott Ullrich
	$pconfig['name'] = "dhcpd";
256 967fcdd0 Scott Ullrich
	$pconfig['description'] = "DHCP Service";
257 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
258 7670e4d2 Scott Ullrich
	unset($pconfig);
259 25d3fbd5 Scott Ullrich
}
260
261
if(isset($config['snmpd']['enable'])) {
262
	$pconfig['name'] = "bsnmpd";
263 967fcdd0 Scott Ullrich
	$pconfig['description'] = "SNMP Service";
264 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
265 7670e4d2 Scott Ullrich
	unset($pconfig);
266 25d3fbd5 Scott Ullrich
}
267
268
if(isset($config['proxyarp']['proxyarpnet'])) {
269 1e055202 Scott Ullrich
	$pconfig['name'] = "choparp";
270 e8616013 Chris Buechler
	$pconfig['description'] = "Proxy ARP";
271 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
272 7670e4d2 Scott Ullrich
	unset($pconfig);
273 25d3fbd5 Scott Ullrich
}
274
275 422e039b Scott Ullrich
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
276 cd72ded3 Timo Boettcher
	$pconfig['name'] = "miniupnpd";
277
	$pconfig['description'] = gettext("UPnP Service");
278
	$services[] = $pconfig;
279
	unset($pconfig);
280 422e039b Scott Ullrich
}
281
282 25b66ec5 Scott Ullrich
if (isset($config['ipsec']['enable'])) {
283 cd72ded3 Timo Boettcher
	$pconfig['name'] = "racoon";
284 0f266b2e Chris Buechler
	$pconfig['description'] = gettext("IPsec VPN");
285 cd72ded3 Timo Boettcher
	$services[] = $pconfig;
286
	unset($pconfig);
287 25b66ec5 Scott Ullrich
}
288
289 cd72ded3 Timo Boettcher
foreach (array('server', 'client') as $mode) {
290
	if (is_array($config['installedpackages']["openvpn$mode"]['config'])) {
291
		foreach ($config['installedpackages']["openvpn$mode"]['config'] as $id => $settings) {
292
			$setting = $config['installedpackages']["openvpn$mode"]['config'][$id];
293
			if (!$setting['disable']) {
294
				$pconfig['name'] = "openvpn";
295
				$pconfig['mode'] = $mode;
296
				$pconfig['id'] = $id;
297
				$pconfig['description'] = "OpenVPN ".$mode.": ".htmlspecialchars($setting['description']);
298
				$services[] = $pconfig;
299
				unset($pconfig);
300
			}
301
		}
302
	}
303
}
304
 
305
 
306 25d3fbd5 Scott Ullrich
if($services) {
307
	foreach($services as $service) {
308 b9eadc0c Colin Smith
		if(!$service['name']) continue;
309 5d8bcb27 Scott Ullrich
		if(!$service['description']) $service['description'] = get_pkg_descr($service['name']);
310 b9eadc0c Colin Smith
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
311 271b638f Scott Ullrich
		echo '<td class="listr">' . $service['description'] . '</td>';
312 cd72ded3 Timo Boettcher
		if ($service['name'] == "openvpn") {
313
			$running =  (is_pid_running($g['varrun_path'] . "/openvpn_{$service['mode']}{$service['id']}.pid") );
314
		} else {
315
			$running = (is_service_running($service['name'], $ps) or is_process_running($service['name']) );
316
		}
317
		if($running) {
318 4fd12c25 Scott Ullrich
			echo '<td class="listr"><center>';
319
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
320 b9eadc0c Colin Smith
		} else {
321 4fd12c25 Scott Ullrich
			echo '<td class="listbg"><center>';
322
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
323 b9eadc0c Colin Smith
		}
324 ef09107d Colin Smith
		echo '<td valign="middle" class="list" nowrap>';
325 b9eadc0c Colin Smith
		if($running) {
326 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
327
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
328
			} else {
329
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
330
			}
331 677c0869 Erik Kristensen
			echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
332 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
333
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
334
			} else {
335
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'> ";
336
			}
337 677c0869 Erik Kristensen
			echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
338 b9eadc0c Colin Smith
			echo "</a>";
339 a0e4cea2 Scott Ullrich
		} else {
340 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
341
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
342
			} else { 
343
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
344
			}
345
			
346 677c0869 Erik Kristensen
			echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
347 a0e4cea2 Scott Ullrich
		}
348 ef09107d Colin Smith
		echo '</td>';
349 b9eadc0c Colin Smith
		echo '</tr>';
350 a0e4cea2 Scott Ullrich
	}
351 b9eadc0c Colin Smith
} else {
352
	echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
353
}
354 cd72ded3 Timo Boettcher
355 a0e4cea2 Scott Ullrich
?>
356
</table>
357
358 a9bc3b82 Scott Ullrich
</td>
359
</tr></table>
360 12af52d9 Scott Ullrich
</div>
361 a9bc3b82 Scott Ullrich
362 a0e4cea2 Scott Ullrich
<?php include("fend.inc"); ?>
363
</body>
364
</html>