Project

General

Profile

Download (10.8 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
require_once("service-utils.inc");
39

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

    
45
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
if($_GET['mode'] == "restartservice" and $_GET['service']) {
55
	switch($_GET['service']) {
56
		case 'ntpd':
57
			system_ntp_configure();
58
			break;
59
		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
			break;
68
		case 'igmpproxy':
69
			services_igmpproxy_configure();
70
			break;
71
		case 'miniupnpd':
72
			upnp_action('restart');	
73
			break;
74
		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
		default:
93
			restart_service($_GET['service']);
94
			break;
95
	}
96
	$savemsg = "{$_GET['service']} has been restarted.";
97
	sleep(5);
98
}
99

    
100
if($_GET['mode'] == "startservice" and $_GET['service']) {
101
	switch($_GET['service']) {
102
		case 'ntpd':
103
			system_ntp_configure();
104
			break;		
105
		case 'bsnmpd':
106
			services_snmpd_configure();
107
			break;
108
		case 'dnsmasq':
109
			services_dnsmasq_configure();
110
			break;
111
		case 'dhcpd':
112
			services_dhcpd_configure();
113
			break;
114
		case 'igmpproxy':
115
			services_igmpproxy_configure();
116
			break;
117
		case 'miniupnpd':
118
			upnp_action('start');
119
			break;
120
		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
		default:
136
			start_service($_GET['service']);
137
			break;
138
	}
139
	$savemsg = "{$_GET['service']} has been started.";
140
	sleep(5);
141
}
142

    
143
/* stop service */
144
if($_GET['mode'] == "stopservice" && $_GET['service']) {
145
	switch($_GET['service']) {
146
		case 'ntpd':
147
			killbyname("ntpd");
148
			break;		
149
		case 'bsnmpd':
150
			killbypid("{$g['varrun_path']}/snmpd.pid");
151
			break;
152
		case 'choparp':
153
			killbyname("choparp");
154
			break;
155
		case 'dhcpd':
156
			killbyname("dhcpd");
157
			break;
158
		case 'dhcrelay':
159
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
160
			break;
161
		case 'dnsmasq':
162
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
163
			break;
164
		case 'igmpproxy':
165
			killbyname("igmpproxy");
166
			break;
167
		case 'miniupnpd':
168
			upnp_action('stop');
169
			break;
170
		case 'openntpd':
171
			killbyname("openntpd");
172
			break;
173
		case 'sshd':
174
			killbyname("sshd");
175
			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
		default:
190
			stop_service($_GET['service']);
191
			break;
192
	}
193
	$savemsg = "{$_GET['service']} " . gettext("has been stopped.");
194
	sleep(5);
195
}
196

    
197
/* batch mode, allow other scripts to call this script */
198
if($_GET['batch']) exit;
199

    
200
$pgtitle = array("Status","Services");
201
include("head.inc");
202

    
203
?>
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
<div id="boxarea">
215
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
216
  <tr>
217
    <td>
218
    <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
<?php
226

    
227
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
228
array_shift($psout);
229
foreach($psout as $line) {
230
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
231
}
232

    
233
$services = $config['installedpackages']['service'];
234

    
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
	unset($pconfig);
243
}
244

    
245
$pconfig['name'] = "ntpd";
246
$pconfig['description'] = "NTP clock sync";
247
$services[] = $pconfig;
248
unset($pconfig);
249

    
250
if(isset($config['captiveportal']['enable'])) {
251
	$pconfig['name'] = "lighttpd";
252
	$pconfig['description'] = "Captive Portal";
253
	$services[] = $pconfig;
254
	$pconfig = "";
255
	unset($pconfig);
256
}
257

    
258
$iflist = array();
259
$ifdescrs = get_configured_interface_list();
260
foreach ($ifdescrs as $if) {
261
	$oc = $config['interfaces'][$if];
262
	if ($oc['if'] && (!link_interface_to_bridge($if)))
263
		$iflist[$if] = $if;
264
}
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
	$pconfig['name'] = "dhcrelay";
273
	$pconfig['description'] = "DHCP Relay";
274
	$services[] = $pconfig;
275
	unset($pconfig);
276
}
277

    
278
if(is_dhcp_server_enabled()) {
279
	$pconfig['name'] = "dhcpd";
280
	$pconfig['description'] = "DHCP Service";
281
	$services[] = $pconfig;
282
	unset($pconfig);
283
}
284

    
285
if(isset($config['snmpd']['enable'])) {
286
	$pconfig['name'] = "bsnmpd";
287
	$pconfig['description'] = "SNMP Service";
288
	$services[] = $pconfig;
289
	unset($pconfig);
290
}
291

    
292
if(isset($config['proxyarp']['proxyarpnet'])) {
293
	$pconfig['name'] = "choparp";
294
	$pconfig['description'] = "Proxy ARP";
295
	$services[] = $pconfig;
296
	unset($pconfig);
297
}
298

    
299
if (count($config['igmpproxy']['igmpentry']) > 0) {
300
	$pconfig['name'] = "igmpproxy";
301
	$pconfig['descritption'] = "IGMP proxy";
302
	$services[] = $pconfig;
303
	unset($pconfig);
304
}
305

    
306
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
307
	$pconfig['name'] = "miniupnpd";
308
	$pconfig['description'] = gettext("UPnP Service");
309
	$services[] = $pconfig;
310
	unset($pconfig);
311
}
312

    
313
if (isset($config['ipsec']['enable'])) {
314
	$pconfig['name'] = "racoon";
315
	$pconfig['description'] = gettext("IPsec VPN");
316
	$services[] = $pconfig;
317
	unset($pconfig);
318
}
319

    
320
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
if($services) {
338
	foreach($services as $service) {
339
		if(!$service['name']) continue;
340
		if(!$service['description']) $service['description'] = get_pkg_descr($service['name']);
341
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
342
		echo '<td class="listr">' . $service['description'] . '</td>';
343
		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
			echo '<td class="listr"><center>';
350
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
351
		} else {
352
			echo '<td class="listbg"><center>';
353
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
354
		}
355
		echo '<td valign="middle" class="list" nowrap>';
356
		if($running) {
357
			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
			echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
363
			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
			echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
369
			echo "</a>";
370
		} else {
371
			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
			echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
378
		}
379
		echo '</td>';
380
		echo '</tr>';
381
	}
382
} else {
383
	echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
384
}
385

    
386
?>
387
</table>
388

    
389
</td>
390
</tr></table>
391
</div>
392

    
393
<?php include("fend.inc"); ?>
394
</body>
395
</html>
(164-164/218)