Project

General

Profile

Download (10.8 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 44173def Ermal Lu?i
require_once("service-utils.inc");
39 a0e4cea2 Scott Ullrich
40
function gentitle_pkg($pgname) {
41
	global $config;
42
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
43
}
44
45 5d8bcb27 Scott Ullrich
function get_pkg_descr($package_name) {
46
	global $config;
47
	foreach($config['installedpackages']['package'] as $pkg) {
48
		if($pkg['name'] == $package_name)
49
			return $pkg['descr'];
50
	}
51
	return "Not available.";
52
}
53
54 b9eadc0c Colin Smith
if($_GET['mode'] == "restartservice" and $_GET['service']) {
55 6c3e2b19 Scott Ullrich
	switch($_GET['service']) {
56 96155ce4 Scott Ullrich
		case 'ntpd':
57
			system_ntp_configure();
58
			break;
59 6c3e2b19 Scott Ullrich
		case 'bsnmpd':
60
			services_snmpd_configure();
61
			break;
62
		case 'dnsmasq':
63
			services_dnsmasq_configure();
64
			break;
65
		case 'dhcpd':
66
			services_dhcpd_configure();
67 422e039b Scott Ullrich
			break;
68 41997fbb Ermal Luci
		case 'igmpproxy':
69
			services_igmpproxy_configure();
70
			break;
71 422e039b Scott Ullrich
		case 'miniupnpd':
72 431484c8 Ryan Wagoner
			upnp_action('restart');	
73 6c3e2b19 Scott Ullrich
			break;
74 cd72ded3 Timo Boettcher
		case 'racoon':
75
			exec("killall -9 racoon");
76
			sleep(1);
77
			vpn_ipsec_force_reload();
78
			break;
79
		case 'openvpn':         
80
			$vpnmode = $_GET['vpnmode'];
81
			if (($vpnmode == "server") or ($vpnmode == "client")) {
82
				$id = $_GET['id'];
83
				if (is_numeric($id)) {
84
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
85
					killbypid($pidfile);
86
					sleep(1);
87
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
88
					mwexec_bg("openvpn --config $configfile");
89
				}
90
			}
91
			break;
92 6c3e2b19 Scott Ullrich
		default:
93
			restart_service($_GET['service']);
94
			break;
95
	}
96 b9eadc0c Colin Smith
	$savemsg = "{$_GET['service']} has been restarted.";
97 422e039b Scott Ullrich
	sleep(5);
98 a0e4cea2 Scott Ullrich
}
99
100 b9eadc0c Colin Smith
if($_GET['mode'] == "startservice" and $_GET['service']) {
101 3e32a807 Scott Ullrich
	switch($_GET['service']) {
102 96155ce4 Scott Ullrich
		case 'ntpd':
103
			system_ntp_configure();
104
			break;		
105 3e32a807 Scott Ullrich
		case 'bsnmpd':
106 3af54e48 Scott Ullrich
			services_snmpd_configure();
107 3e32a807 Scott Ullrich
			break;
108
		case 'dnsmasq':
109
			services_dnsmasq_configure();
110
			break;
111
		case 'dhcpd':
112
			services_dhcpd_configure();
113 422e039b Scott Ullrich
			break;
114 41997fbb Ermal Luci
		case 'igmpproxy':
115
			services_igmpproxy_configure();
116
			break;
117 422e039b Scott Ullrich
		case 'miniupnpd':
118 431484c8 Ryan Wagoner
			upnp_action('start');
119 3e32a807 Scott Ullrich
			break;
120 cd72ded3 Timo Boettcher
		case 'racoon':
121
			exec("killall -9 racoon");
122
			sleep(1);
123
			vpn_ipsec_force_reload();
124
			break;
125
		case 'openvpn':
126
			$vpnmode = $_GET['vpnmode'];
127
			if (($vpnmode == "server") or ($vpnmode == "client")) {
128
				$id = $_GET['id'];
129
				if (is_numeric($id)) {
130
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
131
					mwexec_bg("openvpn --config $configfile");
132
				}
133
			}
134
			break;
135 3e32a807 Scott Ullrich
		default:
136
			start_service($_GET['service']);
137
			break;
138
	}
139 cd72ded3 Timo Boettcher
	$savemsg = "{$_GET['service']} has been started.";
140 422e039b Scott Ullrich
	sleep(5);
141 a0e4cea2 Scott Ullrich
}
142
143 25b66ec5 Scott Ullrich
/* stop service */
144
if($_GET['mode'] == "stopservice" && $_GET['service']) {
145 422e039b Scott Ullrich
	switch($_GET['service']) {
146 96155ce4 Scott Ullrich
		case 'ntpd':
147
			killbyname("ntpd");
148
			break;		
149 25b66ec5 Scott Ullrich
		case 'bsnmpd':
150
			killbypid("{$g['varrun_path']}/snmpd.pid");
151
			break;
152
		case 'choparp':
153
			killbyname("choparp");
154
			break;
155 cd72ded3 Timo Boettcher
		case 'dhcpd':
156 25b66ec5 Scott Ullrich
			killbyname("dhcpd");
157 cd72ded3 Timo Boettcher
			break;
158
		case 'dhcrelay':
159
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
160
			break;
161
		case 'dnsmasq':
162 25b66ec5 Scott Ullrich
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
163
			break;
164 41997fbb Ermal Luci
		case 'igmpproxy':
165
			killbyname("igmpproxy");
166
			break;
167 422e039b Scott Ullrich
		case 'miniupnpd':
168 431484c8 Ryan Wagoner
			upnp_action('stop');
169 25b66ec5 Scott Ullrich
			break;
170 9e226d16 Scott Ullrich
		case 'openntpd':
171
			killbyname("openntpd");
172 cd72ded3 Timo Boettcher
			break;
173
		case 'sshd':
174 25b66ec5 Scott Ullrich
			killbyname("sshd");
175 cd72ded3 Timo Boettcher
			break;
176
		case 'racoon':
177
			exec("killall -9 racoon");
178
			break;
179
		case 'openvpn':         
180
			$vpnmode = $_GET['vpnmode'];
181
			if (($vpnmode == "server") or ($vpnmode == "client")) {
182
				$id = $_GET['id'];
183
				if (is_numeric($id)) {
184
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
185
					killbypid($pidfile);
186
				}
187
			}
188
			break;
189 422e039b Scott Ullrich
		default:
190 cd72ded3 Timo Boettcher
			stop_service($_GET['service']);
191 422e039b Scott Ullrich
			break;
192
	}
193 cd72ded3 Timo Boettcher
	$savemsg = "{$_GET['service']} " . gettext("has been stopped.");
194
	sleep(5);
195 a0e4cea2 Scott Ullrich
}
196
197
/* batch mode, allow other scripts to call this script */
198 b9eadc0c Colin Smith
if($_GET['batch']) exit;
199
200 d88c6a9f Scott Ullrich
$pgtitle = array("Status","Services");
201 4df96eff Scott Ullrich
include("head.inc");
202
203 a0e4cea2 Scott Ullrich
?>
204
205
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
206
<?php
207
include("fbegin.inc");
208
?>
209
<form action="status_services.php" method="post">
210
<?php if ($savemsg) print_info_box($savemsg); ?>
211
212
<p>
213
214 0f10aee4 Bill Marquette
<div id="boxarea">
215
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
216 a9bc3b82 Scott Ullrich
  <tr>
217 0f10aee4 Bill Marquette
    <td>
218 a9bc3b82 Scott Ullrich
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
219
	<tr>
220
	  <td class="listhdrr"><b><center>Service</center></b></td>
221
	  <td class="listhdrr"><b><center>Description</center></b></td>
222
	  <td class="listhdrr"><b><center>Status</center></b></td>
223
	</tr>
224
225 a0e4cea2 Scott Ullrich
<?php
226
227 3af54e48 Scott Ullrich
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
228 ef09107d Colin Smith
array_shift($psout);
229
foreach($psout as $line) {
230
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
231
}
232
233 7670e4d2 Scott Ullrich
$services = $config['installedpackages']['service'];
234 25d3fbd5 Scott Ullrich
235
/*    Add services that are in the base.
236
 *
237
 */
238
if(isset($config['dnsmasq']['enable'])) {
239
	$pconfig['name'] = "dnsmasq";
240
	$pconfig['description'] = "DNS Forwarder";
241
	$services[] = $pconfig;
242 7670e4d2 Scott Ullrich
	unset($pconfig);
243 25d3fbd5 Scott Ullrich
}
244
245 f4c155cd Scott Ullrich
$pconfig['name'] = "ntpd";
246 9e226d16 Scott Ullrich
$pconfig['description'] = "NTP clock sync";
247
$services[] = $pconfig;
248
unset($pconfig);
249
250 25d3fbd5 Scott Ullrich
if(isset($config['captiveportal']['enable'])) {
251 a17d277c Scott Ullrich
	$pconfig['name'] = "lighttpd";
252 25d3fbd5 Scott Ullrich
	$pconfig['description'] = "Captive Portal";
253
	$services[] = $pconfig;
254 7670e4d2 Scott Ullrich
	$pconfig = "";
255
	unset($pconfig);
256 25d3fbd5 Scott Ullrich
}
257
258 3e321df2 Ermal Luçi
$iflist = array();
259
$ifdescrs = get_configured_interface_list();
260
foreach ($ifdescrs as $if) {
261
	$oc = $config['interfaces'][$if];
262 7ec05d27 Ermal Luçi
	if ($oc['if'] && (!link_interface_to_bridge($if)))
263 3e321df2 Ermal Luçi
		$iflist[$if] = $if;
264 51bb9b94 Scott Ullrich
}
265
$show_dhcprelay = false;
266
foreach($iflist as $if) {
267
	if(isset($config['dhcrelay'][$if]['enable']))
268
		$show_dhcprelay = true;
269
}
270
271
if($show_dhcprelay == true) {
272 c214e575 Scott Ullrich
	$pconfig['name'] = "dhcrelay";
273 25d3fbd5 Scott Ullrich
	$pconfig['description'] = "DHCP Relay";
274
	$services[] = $pconfig;
275 7670e4d2 Scott Ullrich
	unset($pconfig);
276 25d3fbd5 Scott Ullrich
}
277
278 3af54e48 Scott Ullrich
if(is_dhcp_server_enabled()) {
279 25d3fbd5 Scott Ullrich
	$pconfig['name'] = "dhcpd";
280 967fcdd0 Scott Ullrich
	$pconfig['description'] = "DHCP Service";
281 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
282 7670e4d2 Scott Ullrich
	unset($pconfig);
283 25d3fbd5 Scott Ullrich
}
284
285
if(isset($config['snmpd']['enable'])) {
286
	$pconfig['name'] = "bsnmpd";
287 967fcdd0 Scott Ullrich
	$pconfig['description'] = "SNMP Service";
288 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
289 7670e4d2 Scott Ullrich
	unset($pconfig);
290 25d3fbd5 Scott Ullrich
}
291
292
if(isset($config['proxyarp']['proxyarpnet'])) {
293 1e055202 Scott Ullrich
	$pconfig['name'] = "choparp";
294 e8616013 Chris Buechler
	$pconfig['description'] = "Proxy ARP";
295 25d3fbd5 Scott Ullrich
	$services[] = $pconfig;
296 7670e4d2 Scott Ullrich
	unset($pconfig);
297 25d3fbd5 Scott Ullrich
}
298
299 41997fbb Ermal Luci
if (count($config['igmpproxy']['igmpentry']) > 0) {
300
	$pconfig['name'] = "igmpproxy";
301
	$pconfig['descritption'] = "IGMP proxy";
302
	$services[] = $pconfig;
303
	unset($pconfig);
304
}
305
306 422e039b Scott Ullrich
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
307 cd72ded3 Timo Boettcher
	$pconfig['name'] = "miniupnpd";
308
	$pconfig['description'] = gettext("UPnP Service");
309
	$services[] = $pconfig;
310
	unset($pconfig);
311 422e039b Scott Ullrich
}
312
313 25b66ec5 Scott Ullrich
if (isset($config['ipsec']['enable'])) {
314 cd72ded3 Timo Boettcher
	$pconfig['name'] = "racoon";
315 0f266b2e Chris Buechler
	$pconfig['description'] = gettext("IPsec VPN");
316 cd72ded3 Timo Boettcher
	$services[] = $pconfig;
317
	unset($pconfig);
318 25b66ec5 Scott Ullrich
}
319
320 cd72ded3 Timo Boettcher
foreach (array('server', 'client') as $mode) {
321
	if (is_array($config['installedpackages']["openvpn$mode"]['config'])) {
322
		foreach ($config['installedpackages']["openvpn$mode"]['config'] as $id => $settings) {
323
			$setting = $config['installedpackages']["openvpn$mode"]['config'][$id];
324
			if (!$setting['disable']) {
325
				$pconfig['name'] = "openvpn";
326
				$pconfig['mode'] = $mode;
327
				$pconfig['id'] = $id;
328
				$pconfig['description'] = "OpenVPN ".$mode.": ".htmlspecialchars($setting['description']);
329
				$services[] = $pconfig;
330
				unset($pconfig);
331
			}
332
		}
333
	}
334
}
335
 
336
 
337 25d3fbd5 Scott Ullrich
if($services) {
338
	foreach($services as $service) {
339 b9eadc0c Colin Smith
		if(!$service['name']) continue;
340 5d8bcb27 Scott Ullrich
		if(!$service['description']) $service['description'] = get_pkg_descr($service['name']);
341 b9eadc0c Colin Smith
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
342 271b638f Scott Ullrich
		echo '<td class="listr">' . $service['description'] . '</td>';
343 cd72ded3 Timo Boettcher
		if ($service['name'] == "openvpn") {
344
			$running =  (is_pid_running($g['varrun_path'] . "/openvpn_{$service['mode']}{$service['id']}.pid") );
345
		} else {
346
			$running = (is_service_running($service['name'], $ps) or is_process_running($service['name']) );
347
		}
348
		if($running) {
349 4fd12c25 Scott Ullrich
			echo '<td class="listr"><center>';
350
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
351 b9eadc0c Colin Smith
		} else {
352 4fd12c25 Scott Ullrich
			echo '<td class="listbg"><center>';
353
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
354 b9eadc0c Colin Smith
		}
355 ef09107d Colin Smith
		echo '<td valign="middle" class="list" nowrap>';
356 b9eadc0c Colin Smith
		if($running) {
357 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
358
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
359
			} else {
360
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
361
			}
362 677c0869 Erik Kristensen
			echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
363 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
364
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
365
			} else {
366
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'> ";
367
			}
368 677c0869 Erik Kristensen
			echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
369 b9eadc0c Colin Smith
			echo "</a>";
370 a0e4cea2 Scott Ullrich
		} else {
371 cd72ded3 Timo Boettcher
			if ($service['name'] == "openvpn") {
372
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
373
			} else { 
374
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
375
			}
376
			
377 677c0869 Erik Kristensen
			echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
378 a0e4cea2 Scott Ullrich
		}
379 ef09107d Colin Smith
		echo '</td>';
380 b9eadc0c Colin Smith
		echo '</tr>';
381 a0e4cea2 Scott Ullrich
	}
382 b9eadc0c Colin Smith
} else {
383
	echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
384
}
385 cd72ded3 Timo Boettcher
386 a0e4cea2 Scott Ullrich
?>
387
</table>
388
389 a9bc3b82 Scott Ullrich
</td>
390
</tr></table>
391 12af52d9 Scott Ullrich
</div>
392 a9bc3b82 Scott Ullrich
393 a0e4cea2 Scott Ullrich
<?php include("fend.inc"); ?>
394
</body>
395
</html>