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("lan" => "LAN");
227
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
228
	$oc = $config['interfaces']['opt' . $i];
229
	if (isset($oc['enable']) && $oc['if'] && (!$oc['bridge']))
230
		$iflist['opt' . $i] = "opt{$i}";
231
}
232
$show_dhcprelay = false;
233
foreach($iflist as $if) {
234
	if(isset($config['dhcrelay'][$if]['enable']))
235
		$show_dhcprelay = true;
236
}
237

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

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

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

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

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

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

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

    
346
?>
347
</table>
348

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

    
353
<?php include("fend.inc"); ?>
354
</body>
355
</html>
(137-137/187)