Project

General

Profile

Download (10.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
    services_status.php
4
    Copyright (C) 2004, 2005 Scott Ullrich
5
    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
    INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
    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
##|+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
require("guiconfig.inc");
38

    
39
function gentitle_pkg($pgname) {
40
	global $config;
41
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
42
}
43

    
44
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
if($_GET['mode'] == "restartservice" and $_GET['service']) {
54
	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
			break;
64
		case 'miniupnpd':
65
			upnp_action('restart');	
66
			break;
67
		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
		default:
86
			restart_service($_GET['service']);
87
			break;
88
	}
89
	$savemsg = "{$_GET['service']} has been restarted.";
90
	sleep(5);
91
}
92

    
93
if($_GET['mode'] == "startservice" and $_GET['service']) {
94
	switch($_GET['service']) {
95
		case 'bsnmpd':
96
			services_snmpd_configure();
97
			break;
98
		case 'dnsmasq':
99
			services_dnsmasq_configure();
100
			break;
101
		case 'dhcpd':
102
			services_dhcpd_configure();
103
			break;
104
		case 'miniupnpd':
105
			upnp_action('start');
106
			break;
107
		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
		default:
123
			start_service($_GET['service']);
124
			break;
125
	}
126
	$savemsg = "{$_GET['service']} has been started.";
127
	sleep(5);
128
}
129

    
130
/* stop service */
131
if($_GET['mode'] == "stopservice" && $_GET['service']) {
132
	switch($_GET['service']) {
133
		case 'bsnmpd':
134
			killbypid("{$g['varrun_path']}/snmpd.pid");
135
			break;
136
		case 'choparp':
137
			killbyname("choparp");
138
			break;
139
		case 'dhcpd':
140
			killbyname("dhcpd");
141
			break;
142
		case 'dhcrelay':
143
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
144
			break;
145
		case 'dnsmasq':
146
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
147
			break;
148
		case 'miniupnpd':
149
			upnp_action('stop');
150
			break;
151
		case 'openntpd':
152
			killbyname("openntpd");
153
			break;
154
		case 'sshd':
155
			killbyname("sshd");
156
			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
		default:
171
			stop_service($_GET['service']);
172
			break;
173
	}
174
	$savemsg = "{$_GET['service']} " . gettext("has been stopped.");
175
	sleep(5);
176
}
177

    
178
/* batch mode, allow other scripts to call this script */
179
if($_GET['batch']) exit;
180

    
181
$pgtitle = array("Status","Services");
182
include("head.inc");
183

    
184
?>
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
<div id="boxarea">
196
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
197
  <tr>
198
    <td>
199
    <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
<?php
207

    
208
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
209
array_shift($psout);
210
foreach($psout as $line) {
211
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
212
}
213

    
214
$services = $config['installedpackages']['service'];
215

    
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
	unset($pconfig);
224
}
225

    
226
$pconfig['name'] = "ntpd";
227
$pconfig['description'] = "NTP clock sync";
228
$services[] = $pconfig;
229
unset($pconfig);
230

    
231
if(isset($config['captiveportal']['enable'])) {
232
	$pconfig['name'] = "lighttpd";
233
	$pconfig['description'] = "Captive Portal";
234
	$services[] = $pconfig;
235
	$pconfig = "";
236
	unset($pconfig);
237
}
238

    
239
$iflist = array();
240
$ifdescrs = get_configured_interface_list();
241
foreach ($ifdescrs as $if) {
242
	$oc = $config['interfaces'][$if];
243
	if ($oc['if'] && (!link_interface_to_bridge($if)))
244
		$iflist[$if] = $if;
245
}
246
$show_dhcprelay = false;
247
foreach($iflist as $if) {
248
	if(isset($config['dhcrelay'][$if]['enable']))
249
		$show_dhcprelay = true;
250
}
251

    
252
if($show_dhcprelay == true) {
253
	$pconfig['name'] = "dhcrelay";
254
	$pconfig['description'] = "DHCP Relay";
255
	$services[] = $pconfig;
256
	unset($pconfig);
257
}
258

    
259
if(is_dhcp_server_enabled()) {
260
	$pconfig['name'] = "dhcpd";
261
	$pconfig['description'] = "DHCP Service";
262
	$services[] = $pconfig;
263
	unset($pconfig);
264
}
265

    
266
if(isset($config['snmpd']['enable'])) {
267
	$pconfig['name'] = "bsnmpd";
268
	$pconfig['description'] = "SNMP Service";
269
	$services[] = $pconfig;
270
	unset($pconfig);
271
}
272

    
273
if(isset($config['proxyarp']['proxyarpnet'])) {
274
	$pconfig['name'] = "choparp";
275
	$pconfig['description'] = "Proxy ARP";
276
	$services[] = $pconfig;
277
	unset($pconfig);
278
}
279

    
280
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
281
	$pconfig['name'] = "miniupnpd";
282
	$pconfig['description'] = gettext("UPnP Service");
283
	$services[] = $pconfig;
284
	unset($pconfig);
285
}
286

    
287
if (isset($config['ipsec']['enable'])) {
288
	$pconfig['name'] = "racoon";
289
	$pconfig['description'] = gettext("IPsec VPN");
290
	$services[] = $pconfig;
291
	unset($pconfig);
292
}
293

    
294
foreach (array('server', 'client') as $mode) {
295
	if (is_array($config['installedpackages']["openvpn$mode"]['config'])) {
296
		foreach ($config['installedpackages']["openvpn$mode"]['config'] as $id => $settings) {
297
			$setting = $config['installedpackages']["openvpn$mode"]['config'][$id];
298
			if (!$setting['disable']) {
299
				$pconfig['name'] = "openvpn";
300
				$pconfig['mode'] = $mode;
301
				$pconfig['id'] = $id;
302
				$pconfig['description'] = "OpenVPN ".$mode.": ".htmlspecialchars($setting['description']);
303
				$services[] = $pconfig;
304
				unset($pconfig);
305
			}
306
		}
307
	}
308
}
309
 
310
 
311
if($services) {
312
	foreach($services as $service) {
313
		if(!$service['name']) continue;
314
		if(!$service['description']) $service['description'] = get_pkg_descr($service['name']);
315
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
316
		echo '<td class="listr">' . $service['description'] . '</td>';
317
		if ($service['name'] == "openvpn") {
318
			$running =  (is_pid_running($g['varrun_path'] . "/openvpn_{$service['mode']}{$service['id']}.pid") );
319
		} else {
320
			$running = (is_service_running($service['name'], $ps) or is_process_running($service['name']) );
321
		}
322
		if($running) {
323
			echo '<td class="listr"><center>';
324
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
325
		} else {
326
			echo '<td class="listbg"><center>';
327
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
328
		}
329
		echo '<td valign="middle" class="list" nowrap>';
330
		if($running) {
331
			if ($service['name'] == "openvpn") {
332
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
333
			} else {
334
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
335
			}
336
			echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
337
			if ($service['name'] == "openvpn") {
338
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
339
			} else {
340
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'> ";
341
			}
342
			echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
343
			echo "</a>";
344
		} else {
345
			if ($service['name'] == "openvpn") {
346
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
347
			} else { 
348
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
349
			}
350
			
351
			echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
352
		}
353
		echo '</td>';
354
		echo '</tr>';
355
	}
356
} else {
357
	echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
358
}
359

    
360
?>
361
</table>
362

    
363
</td>
364
</tr></table>
365
</div>
366

    
367
<?php include("fend.inc"); ?>
368
</body>
369
</html>
(161-161/214)