Project

General

Profile

Download (10 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
require("guiconfig.inc");
30

    
31
function gentitle_pkg($pgname) {
32
	global $config;
33
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
34
}
35

    
36
function get_pkg_descr($package_name) {
37
	global $config;
38
	foreach($config['installedpackages']['package'] as $pkg) {
39
		if($pkg['name'] == $package_name)
40
			return $pkg['descr'];
41
	}
42
	return "Not available.";
43
}
44

    
45
if($_GET['mode'] == "restartservice" and $_GET['service']) {
46
	switch($_GET['service']) {
47
		case 'bsnmpd':
48
			services_snmpd_configure();
49
			break;
50
		case 'dnsmasq':
51
			services_dnsmasq_configure();
52
			break;
53
		case 'dhcpd':
54
			services_dhcpd_configure();
55
			break;
56
		case 'miniupnpd':
57
			upnp_action('restart');	
58
			break;
59
		case 'racoon':
60
			exec("killall -9 racoon");
61
			sleep(1);
62
			vpn_ipsec_force_reload();
63
			break;
64
		case 'openvpn':         
65
			$vpnmode = $_GET['vpnmode'];
66
			if (($vpnmode == "server") or ($vpnmode == "client")) {
67
				$id = $_GET['id'];
68
				if (is_numeric($id)) {
69
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
70
					killbypid($pidfile);
71
					sleep(1);
72
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
73
					mwexec_bg("openvpn --config $configfile");
74
				}
75
			}
76
			break;
77
		default:
78
			restart_service($_GET['service']);
79
			break;
80
	}
81
	$savemsg = "{$_GET['service']} has been restarted.";
82
	sleep(5);
83
}
84

    
85
if($_GET['mode'] == "startservice" and $_GET['service']) {
86
	switch($_GET['service']) {
87
		case 'bsnmpd':
88
			services_snmpd_configure();
89
			break;
90
		case 'dnsmasq':
91
			services_dnsmasq_configure();
92
			break;
93
		case 'dhcpd':
94
			services_dhcpd_configure();
95
			break;
96
		case 'miniupnpd':
97
			upnp_action('start');
98
			break;
99
		case 'racoon':
100
			exec("killall -9 racoon");
101
			sleep(1);
102
			vpn_ipsec_force_reload();
103
			break;
104
		case 'openvpn':
105
			$vpnmode = $_GET['vpnmode'];
106
			if (($vpnmode == "server") or ($vpnmode == "client")) {
107
				$id = $_GET['id'];
108
				if (is_numeric($id)) {
109
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
110
					mwexec_bg("openvpn --config $configfile");
111
				}
112
			}
113
			break;
114
		default:
115
			start_service($_GET['service']);
116
			break;
117
	}
118
	$savemsg = "{$_GET['service']} has been started.";
119
	sleep(5);
120
}
121

    
122
/* stop service */
123
if($_GET['mode'] == "stopservice" && $_GET['service']) {
124
	switch($_GET['service']) {
125
		case 'bsnmpd':
126
			killbypid("{$g['varrun_path']}/snmpd.pid");
127
			break;
128
		case 'choparp':
129
			killbyname("choparp");
130
			break;
131
		case 'dhcpd':
132
			killbyname("dhcpd");
133
			break;
134
		case 'dhcrelay':
135
			killbypid("{$g['varrun_path']}/dhcrelay.pid");
136
			break;
137
		case 'dnsmasq':
138
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
139
			break;
140
		case 'miniupnpd':
141
			upnp_action('stop');
142
			break;
143
		case 'ntpd':
144
			killbyname("ntpd");
145
			break;
146
		case 'sshd':
147
			killbyname("sshd");
148
			break;
149
		case 'racoon':
150
			exec("killall -9 racoon");
151
			break;
152
		case 'openvpn':         
153
			$vpnmode = $_GET['vpnmode'];
154
			if (($vpnmode == "server") or ($vpnmode == "client")) {
155
				$id = $_GET['id'];
156
				if (is_numeric($id)) {
157
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
158
					killbypid($pidfile);
159
				}
160
			}
161
			break;
162
		default:
163
			stop_service($_GET['service']);
164
			break;
165
	}
166
	$savemsg = "{$_GET['service']} " . gettext("has been stopped.");
167
	sleep(5);
168
}
169

    
170
/* batch mode, allow other scripts to call this script */
171
if($_GET['batch']) exit;
172

    
173
$pgtitle = array("Status","Services");
174
include("head.inc");
175

    
176
?>
177

    
178
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
179
<?php
180
include("fbegin.inc");
181
?>
182
<form action="status_services.php" method="post">
183
<?php if ($savemsg) print_info_box($savemsg); ?>
184

    
185
<p>
186

    
187
<div id="boxarea">
188
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
189
  <tr>
190
    <td>
191
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
192
	<tr>
193
	  <td class="listhdrr"><b><center>Service</center></b></td>
194
	  <td class="listhdrr"><b><center>Description</center></b></td>
195
	  <td class="listhdrr"><b><center>Status</center></b></td>
196
	</tr>
197

    
198
<?php
199

    
200
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
201
array_shift($psout);
202
foreach($psout as $line) {
203
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
204
}
205

    
206
$services = $config['installedpackages']['service'];
207

    
208
/*    Add services that are in the base.
209
 *
210
 */
211
if(isset($config['dnsmasq']['enable'])) {
212
	$pconfig['name'] = "dnsmasq";
213
	$pconfig['description'] = "DNS Forwarder";
214
	$services[] = $pconfig;
215
	unset($pconfig);
216
}
217

    
218
if(isset($config['captiveportal']['enable'])) {
219
	$pconfig['name'] = "lighttpd";
220
	$pconfig['description'] = "Captive Portal";
221
	$services[] = $pconfig;
222
	$pconfig = "";
223
	unset($pconfig);
224
}
225

    
226
$iflist = array();
227
$ifdescrs = get_configured_interface_list();
228
foreach ($ifdescrs as $if) {
229
	$oc = $config['interfaces'][$if];
230
	if ($oc['if'] && (!$oc['bridge']))
231
		$iflist[$if] = $if;
232
}
233
$show_dhcprelay = false;
234
foreach($iflist as $if) {
235
	if(isset($config['dhcrelay'][$if]['enable']))
236
		$show_dhcprelay = true;
237
}
238

    
239
if($show_dhcprelay == true) {
240
	$pconfig['name'] = "dhcrelay";
241
	$pconfig['description'] = "DHCP Relay";
242
	$services[] = $pconfig;
243
	unset($pconfig);
244
}
245

    
246
if(is_dhcp_server_enabled()) {
247
	$pconfig['name'] = "dhcpd";
248
	$pconfig['description'] = "DHCP Service";
249
	$services[] = $pconfig;
250
	unset($pconfig);
251
}
252

    
253
if(isset($config['snmpd']['enable'])) {
254
	$pconfig['name'] = "bsnmpd";
255
	$pconfig['description'] = "SNMP Service";
256
	$services[] = $pconfig;
257
	unset($pconfig);
258
}
259

    
260
if(isset($config['proxyarp']['proxyarpnet'])) {
261
	$pconfig['name'] = "choparp";
262
	$pconfig['description'] = "Proxy ARP";
263
	$services[] = $pconfig;
264
	unset($pconfig);
265
}
266

    
267
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
268
	$pconfig['name'] = "miniupnpd";
269
	$pconfig['description'] = gettext("UPnP Service");
270
	$services[] = $pconfig;
271
	unset($pconfig);
272
}
273

    
274
if (isset($config['ipsec']['enable'])) {
275
	$pconfig['name'] = "racoon";
276
	$pconfig['description'] = gettext("IPsec VPN");
277
	$services[] = $pconfig;
278
	unset($pconfig);
279
}
280

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

    
347
?>
348
</table>
349

    
350
</td>
351
</tr></table>
352
</div>
353

    
354
<?php include("fend.inc"); ?>
355
</body>
356
</html>
(146-146/200)