Project

General

Profile

Download (10.5 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
			if(file_exists('/usr/local/etc/rc.d/miniupnpd.sh'))
58
				mwexec('/usr/local/etc/rc.d/miniupnpd.sh restart');
59
			break;
60
		case 'racoon':
61
			exec("killall -9 racoon");
62
			sleep(1);
63
			vpn_ipsec_force_reload();
64
			break;
65
		case 'openvpn':         
66
			$vpnmode = $_GET['vpnmode'];
67
			if (($vpnmode == "server") or ($vpnmode == "client")) {
68
				$id = $_GET['id'];
69
				if (is_numeric($id)) {
70
					$pidfile = $g['varrun_path'] . "/openvpn_{$vpnmode}{$id}.pid";
71
					killbypid($pidfile);
72
					sleep(1);
73
					$configfile = $g['varetc_path'] . "/openvpn_{$vpnmode}{$id}.conf";
74
					mwexec_bg("openvpn --config $configfile");
75
				}
76
			}
77
			break;
78
		default:
79
			restart_service($_GET['service']);
80
			break;
81
	}
82
	$savemsg = "{$_GET['service']} has been restarted.";
83
	sleep(5);
84
}
85

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

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

    
174
/* batch mode, allow other scripts to call this script */
175
if($_GET['batch']) exit;
176

    
177
$pgtitle = "Status: Services";
178
include("head.inc");
179

    
180
?>
181

    
182
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
183
<?php
184
include("fbegin.inc");
185
?>
186
<p class="pgtitle"><?=$pgtitle?></p>
187
<form action="status_services.php" method="post">
188
<?php if ($savemsg) print_info_box($savemsg); ?>
189

    
190
<p>
191

    
192
<div id="boxarea">
193
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
194
  <tr>
195
    <td>
196
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
197
	<tr>
198
	  <td class="listhdrr"><b><center>Service</center></b></td>
199
	  <td class="listhdrr"><b><center>Description</center></b></td>
200
	  <td class="listhdrr"><b><center>Status</center></b></td>
201
	</tr>
202

    
203
<?php
204

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

    
211
$services = $config['installedpackages']['service'];
212

    
213
/*    Add services that are in the base.
214
 *
215
 */
216
if(isset($config['dnsmasq']['enable'])) {
217
	$pconfig['name'] = "dnsmasq";
218
	$pconfig['description'] = "DNS Forwarder";
219
	$services[] = $pconfig;
220
	unset($pconfig);
221
}
222

    
223
if(isset($config['captiveportal']['enable'])) {
224
	$pconfig['name'] = "lighttpd";
225
	$pconfig['description'] = "Captive Portal";
226
	$services[] = $pconfig;
227
	$pconfig = "";
228
	unset($pconfig);
229
}
230

    
231
$iflist = array("lan" => "LAN");
232
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
233
	$oc = $config['interfaces']['opt' . $i];
234
	if (isset($oc['enable']) && $oc['if'] && (!$oc['bridge']))
235
		$iflist['opt' . $i] = "opt{$i}";
236
}
237
$show_dhcprelay = false;
238
foreach($iflist as $if) {
239
	if(isset($config['dhcrelay'][$if]['enable']))
240
		$show_dhcprelay = true;
241
}
242

    
243
if($show_dhcprelay == true) {
244
	$pconfig['name'] = "dhcrelay";
245
	$pconfig['description'] = "DHCP Relay";
246
	$services[] = $pconfig;
247
	unset($pconfig);
248
}
249

    
250
if(is_dhcp_server_enabled()) {
251
	$pconfig['name'] = "dhcpd";
252
	$pconfig['description'] = "DHCP Service";
253
	$services[] = $pconfig;
254
	unset($pconfig);
255
}
256

    
257
if(isset($config['snmpd']['enable'])) {
258
	$pconfig['name'] = "bsnmpd";
259
	$pconfig['description'] = "SNMP Service";
260
	$services[] = $pconfig;
261
	unset($pconfig);
262
}
263

    
264
if(isset($config['proxyarp']['proxyarpnet'])) {
265
	$pconfig['name'] = "choparp";
266
	$pconfig['description'] = "Proxy Arp";
267
	$services[] = $pconfig;
268
	unset($pconfig);
269
}
270

    
271
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
272
	$pconfig['name'] = "miniupnpd";
273
	$pconfig['description'] = gettext("UPnP Service");
274
	$services[] = $pconfig;
275
	unset($pconfig);
276
}
277

    
278
if (isset($config['ipsec']['enable'])) {
279
	$pconfig['name'] = "racoon";
280
	$pconfig['description'] = gettext("IPSEC VPN");
281
	$services[] = $pconfig;
282
	unset($pconfig);
283
}
284

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

    
351
?>
352
</table>
353

    
354
</td>
355
</tr></table>
356
</div>
357

    
358
<meta http-equiv="refresh" content="120;url=<?php echo $_SERVER['SCRIPT_NAME']; ?>">
359

    
360
<?php include("fend.inc"); ?>
361
</body>
362
</html>
(136-136/181)