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

    
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 'ntpd':
56
			system_ntp_configure();
57
			break;
58
		case 'bsnmpd':
59
			services_snmpd_configure();
60
			break;
61
		case 'dnsmasq':
62
			services_dnsmasq_configure();
63
			break;
64
		case 'dhcpd':
65
			services_dhcpd_configure();
66
			break;
67
		case 'igmpproxy':
68
			services_igmpproxy_configure();
69
			break;
70
		case 'miniupnpd':
71
			upnp_action('restart');	
72
			break;
73
		case 'racoon':
74
			exec("killall -9 racoon");
75
			sleep(1);
76
			vpn_ipsec_force_reload();
77
			break;
78
		case 'openvpn':         
79
			$vpnmode = $_GET['vpnmode'];
80
			if (($vpnmode == "server") or ($vpnmode == "client")) {
81
				$id = $_GET['id'];
82
				if (is_numeric($id)) {
83
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
84
					killbypid($pidfile);
85
					sleep(1);
86
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
87
					mwexec_bg("openvpn --config $configfile");
88
				}
89
			}
90
			break;
91
		default:
92
			restart_service($_GET['service']);
93
			break;
94
	}
95
	$savemsg = "{$_GET['service']} has been restarted.";
96
	sleep(5);
97
}
98

    
99
if($_GET['mode'] == "startservice" and $_GET['service']) {
100
	switch($_GET['service']) {
101
		case 'ntpd':
102
			system_ntp_configure();
103
			break;		
104
		case 'bsnmpd':
105
			services_snmpd_configure();
106
			break;
107
		case 'dnsmasq':
108
			services_dnsmasq_configure();
109
			break;
110
		case 'dhcpd':
111
			services_dhcpd_configure();
112
			break;
113
		case 'igmpproxy':
114
			services_igmpproxy_configure();
115
			break;
116
		case 'miniupnpd':
117
			upnp_action('start');
118
			break;
119
		case 'racoon':
120
			exec("killall -9 racoon");
121
			sleep(1);
122
			vpn_ipsec_force_reload();
123
			break;
124
		case 'openvpn':
125
			$vpnmode = $_GET['vpnmode'];
126
			if (($vpnmode == "server") or ($vpnmode == "client")) {
127
				$id = $_GET['id'];
128
				if (is_numeric($id)) {
129
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
130
					mwexec_bg("openvpn --config $configfile");
131
				}
132
			}
133
			break;
134
		default:
135
			start_service($_GET['service']);
136
			break;
137
	}
138
	$savemsg = "{$_GET['service']} has been started.";
139
	sleep(5);
140
}
141

    
142
/* stop service */
143
if($_GET['mode'] == "stopservice" && $_GET['service']) {
144
	switch($_GET['service']) {
145
		case 'ntpd':
146
			killbyname("ntpd");
147
			break;		
148
		case 'bsnmpd':
149
			killbypid("{$g['varrun_path']}/snmpd.pid");
150
			break;
151
		case 'choparp':
152
			killbyname("choparp");
153
			break;
154
		case 'dhcpd':
155
			killbyname("dhcpd");
156
			break;
157
		case 'dhcrelay':
158
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
159
			break;
160
		case 'dnsmasq':
161
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
162
			break;
163
		case 'igmpproxy':
164
			killbyname("igmpproxy");
165
			break;
166
		case 'miniupnpd':
167
			upnp_action('stop');
168
			break;
169
		case 'openntpd':
170
			killbyname("openntpd");
171
			break;
172
		case 'sshd':
173
			killbyname("sshd");
174
			break;
175
		case 'racoon':
176
			exec("killall -9 racoon");
177
			break;
178
		case 'openvpn':         
179
			$vpnmode = $_GET['vpnmode'];
180
			if (($vpnmode == "server") or ($vpnmode == "client")) {
181
				$id = $_GET['id'];
182
				if (is_numeric($id)) {
183
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
184
					killbypid($pidfile);
185
				}
186
			}
187
			break;
188
		default:
189
			stop_service($_GET['service']);
190
			break;
191
	}
192
	$savemsg = "{$_GET['service']} " . gettext("has been stopped.");
193
	sleep(5);
194
}
195

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

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

    
202
?>
203

    
204
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
205
<?php
206
include("fbegin.inc");
207
?>
208
<form action="status_services.php" method="post">
209
<?php if ($savemsg) print_info_box($savemsg); ?>
210

    
211
<p>
212

    
213
<div id="boxarea">
214
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
215
  <tr>
216
    <td>
217
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
218
	<tr>
219
	  <td class="listhdrr"><b><center>Service</center></b></td>
220
	  <td class="listhdrr"><b><center>Description</center></b></td>
221
	  <td class="listhdrr"><b><center>Status</center></b></td>
222
	</tr>
223

    
224
<?php
225

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

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

    
234
/*    Add services that are in the base.
235
 *
236
 */
237
if(isset($config['dnsmasq']['enable'])) {
238
	$pconfig['name'] = "dnsmasq";
239
	$pconfig['description'] = "DNS Forwarder";
240
	$services[] = $pconfig;
241
	unset($pconfig);
242
}
243

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

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

    
257
$iflist = array();
258
$ifdescrs = get_configured_interface_list();
259
foreach ($ifdescrs as $if) {
260
	$oc = $config['interfaces'][$if];
261
	if ($oc['if'] && (!link_interface_to_bridge($if)))
262
		$iflist[$if] = $if;
263
}
264
$show_dhcprelay = false;
265
foreach($iflist as $if) {
266
	if(isset($config['dhcrelay'][$if]['enable']))
267
		$show_dhcprelay = true;
268
}
269

    
270
if($show_dhcprelay == true) {
271
	$pconfig['name'] = "dhcrelay";
272
	$pconfig['description'] = "DHCP Relay";
273
	$services[] = $pconfig;
274
	unset($pconfig);
275
}
276

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

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

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

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

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

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

    
319
foreach (array('server', 'client') as $mode) {
320
	if (is_array($config['installedpackages']["openvpn$mode"]['config'])) {
321
		foreach ($config['installedpackages']["openvpn$mode"]['config'] as $id => $settings) {
322
			$setting = $config['installedpackages']["openvpn$mode"]['config'][$id];
323
			if (!$setting['disable']) {
324
				$pconfig['name'] = "openvpn";
325
				$pconfig['mode'] = $mode;
326
				$pconfig['id'] = $id;
327
				$pconfig['description'] = "OpenVPN ".$mode.": ".htmlspecialchars($setting['description']);
328
				$services[] = $pconfig;
329
				unset($pconfig);
330
			}
331
		}
332
	}
333
}
334
 
335
 
336
if($services) {
337
	foreach($services as $service) {
338
		if(!$service['name']) continue;
339
		if(!$service['description']) $service['description'] = get_pkg_descr($service['name']);
340
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
341
		echo '<td class="listr">' . $service['description'] . '</td>';
342
		if ($service['name'] == "openvpn") {
343
			$running =  (is_pid_running($g['varrun_path'] . "/openvpn_{$service['mode']}{$service['id']}.pid") );
344
		} else {
345
			$running = (is_service_running($service['name'], $ps) or is_process_running($service['name']) );
346
		}
347
		if($running) {
348
			echo '<td class="listr"><center>';
349
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
350
		} else {
351
			echo '<td class="listbg"><center>';
352
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
353
		}
354
		echo '<td valign="middle" class="list" nowrap>';
355
		if($running) {
356
			if ($service['name'] == "openvpn") {
357
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
358
			} else {
359
				echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
360
			}
361
			echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
362
			if ($service['name'] == "openvpn") {
363
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
364
			} else {
365
				echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'> ";
366
			}
367
			echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
368
			echo "</a>";
369
		} else {
370
			if ($service['name'] == "openvpn") {
371
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}&vpnmode={$service['mode']}&id={$service['id']}'>";
372
			} else { 
373
				echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
374
			}
375
			
376
			echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
377
		}
378
		echo '</td>';
379
		echo '</tr>';
380
	}
381
} else {
382
	echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
383
}
384

    
385
?>
386
</table>
387

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

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