Project

General

Profile

Download (8.26 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 'ntpd':
48
			system_ntp_configure();
49
			break;		
50
		case 'bsnmpd':
51
			services_snmpd_configure();
52
			break;
53
		case 'dnsmasq':
54
			services_dnsmasq_configure();
55
			break;
56
		case 'dhcpd':
57
			services_dhcpd_configure();
58
			break;
59
		case 'miniupnpd':
60
			upnp_action('restart');
61
			break;
62
        case 'racoon':
63
        	exec("killall -9 racoon");
64
        	sleep(1);
65
        	vpn_ipsec_force_reload();
66
        	break;
67
		default:
68
			restart_service($_GET['service']);
69
			break;
70
	}
71
	$savemsg = "{$_GET['service']} has been restarted.";
72
	sleep(5);
73
}
74

    
75
if($_GET['mode'] == "startservice" and $_GET['service']) {
76
	switch($_GET['service']) {
77
		case 'ntpd':
78
			system_ntp_configure();
79
			break;
80
		case 'bsnmpd':
81
			services_snmpd_configure();
82
			break;
83
		case 'dnsmasq':
84
			services_dnsmasq_configure();
85
			break;
86
		case 'dhcpd':
87
			services_dhcpd_configure();
88
			break;
89
		case 'miniupnpd':
90
			upnp_action('start');
91
			break;
92
        case 'racoon':
93
        	exec("killall -9 racoon");
94
        	sleep(1);
95
        	vpn_ipsec_force_reload();
96
        	break;
97
		default:
98
			start_service($_GET['service']);
99
			break;
100
	}
101
    $savemsg = "{$_GET['service']} has been started.";
102
	sleep(5);
103
}
104

    
105
/* stop service */
106
if($_GET['mode'] == "stopservice" && $_GET['service']) {
107
	switch($_GET['service']) {
108
		case 'ntpd':
109
			killbyname("ntpd");
110
			break;		
111
		case 'bsnmpd':
112
			killbypid("{$g['varrun_path']}/snmpd.pid");
113
			break;
114
		case 'choparp':
115
			killbyname("choparp");
116
			break;
117
        case 'dhcpd':
118
			killbyname("dhcpd");
119
            break;
120
        case 'dhcrelay':
121
            killbypid("{$g['varrun_path']}/dhcrelay.pid");
122
            break;
123
        case 'dnsmasq':
124
			killbypid("{$g['varrun_path']}/dnsmasq.pid");
125
			break;
126
		case 'miniupnpd':
127
			upnp_action('stop');
128
			break;
129
		case 'openntpd':
130
			killbyname("openntpd");
131
            break;
132
        case 'sshd':
133
			killbyname("sshd");
134
            break;
135
        case 'racoon':
136
        	exec("killall -9 racoon");
137
		default:
138
		    stop_service($_GET['service']);
139
			break;
140
	}
141
    $savemsg = "{$_GET['service']} " . gettext("has been stopped.");
142
    sleep(5);
143
}
144

    
145
/* batch mode, allow other scripts to call this script */
146
if($_GET['batch']) exit;
147

    
148
$pgtitle = "Status: Services";
149
include("head.inc");
150

    
151
?>
152

    
153
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
154
<?php
155
include("fbegin.inc");
156
?>
157
<p class="pgtitle"><?=$pgtitle?></p>
158
<form action="status_services.php" method="post">
159
<?php if ($savemsg) print_info_box($savemsg); ?>
160

    
161
<p>
162

    
163
<div id="boxarea">
164
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
165
  <tr>
166
    <td>
167
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
168
	<tr>
169
	  <td class="listhdrr"><b><center>Service</center></b></td>
170
	  <td class="listhdrr"><b><center>Description</center></b></td>
171
	  <td class="listhdrr"><b><center>Status</center></b></td>
172
	</tr>
173

    
174
<?php
175

    
176
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
177
array_shift($psout);
178
foreach($psout as $line) {
179
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
180
}
181

    
182
$services = $config['installedpackages']['service'];
183

    
184
/*    Add services that are in the base.
185
 *
186
 */
187
if(isset($config['dnsmasq']['enable'])) {
188
	$pconfig['name'] = "dnsmasq";
189
	$pconfig['description'] = "DNS Forwarder";
190
	$services[] = $pconfig;
191
	unset($pconfig);
192
}
193

    
194
$pconfig['name'] = "ntpd";
195
$pconfig['description'] = "NTP clock sync";
196
$services[] = $pconfig;
197
unset($pconfig);
198

    
199
if(isset($config['captiveportal']['enable'])) {
200
	$pconfig['name'] = "lighttpd";
201
	$pconfig['description'] = "Captive Portal";
202
	$services[] = $pconfig;
203
	$pconfig = "";
204
	unset($pconfig);
205
}
206

    
207
$iflist = array("lan" => "LAN");
208
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
209
	$oc = $config['interfaces']['opt' . $i];
210
	if (isset($oc['enable']) && $oc['if'] && (!$oc['bridge']))
211
		$iflist['opt' . $i] = "opt{$i}";
212
}
213
$show_dhcprelay = false;
214
foreach($iflist as $if) {
215
	if(isset($config['dhcrelay'][$if]['enable']))
216
		$show_dhcprelay = true;
217
}
218

    
219
if($show_dhcprelay == true) {
220
	$pconfig['name'] = "dhcrelay";
221
	$pconfig['description'] = "DHCP Relay";
222
	$services[] = $pconfig;
223
	unset($pconfig);
224
}
225

    
226
if(is_dhcp_server_enabled()) {
227
	$pconfig['name'] = "dhcpd";
228
	$pconfig['description'] = "DHCP Service";
229
	$services[] = $pconfig;
230
	unset($pconfig);
231
}
232

    
233
if(isset($config['snmpd']['enable'])) {
234
	$pconfig['name'] = "bsnmpd";
235
	$pconfig['description'] = "SNMP Service";
236
	$services[] = $pconfig;
237
	unset($pconfig);
238
}
239

    
240
if(isset($config['proxyarp']['proxyarpnet'])) {
241
	$pconfig['name'] = "choparp";
242
	$pconfig['description'] = "Proxy ARP";
243
	$services[] = $pconfig;
244
	unset($pconfig);
245
}
246

    
247
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
248
    $pconfig['name'] = "miniupnpd";
249
    $pconfig['description'] = gettext("UPnP Service");
250
    $services[] = $pconfig;
251
    unset($pconfig);
252
}
253

    
254
if (isset($config['ipsec']['enable'])) {
255
    $pconfig['name'] = "racoon";
256
    $pconfig['description'] = gettext("IPsec VPN");
257
    $services[] = $pconfig;
258
    unset($pconfig);
259
}
260

    
261
if($services) {
262
	foreach($services as $service) {
263
		if(!$service['name']) continue;
264
		if(!$service['description']) $service['description'] = get_pkg_descr($service['name']);
265
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
266
		echo '<td class="listr">' . $service['description'] . '</td>';
267
		if(is_service_running($service['name'], $ps) or is_process_running($service['name']) ) {
268
			echo '<td class="listr"><center>';
269
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
270
			$running = true;
271
		} else {
272
			echo '<td class="listbg"><center>';
273
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
274
			$running = false;
275
		}
276
		echo '<td valign="middle" class="list" nowrap>';
277
		if($running) {
278
			echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
279
			echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
280
			echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'>";
281
			echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
282
			echo "</a>";
283
		} else {
284
			echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
285
			echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
286
		}
287
		echo '</td>';
288
		echo '</tr>';
289
	}
290
} else {
291
	echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
292
}
293
?>
294
</table>
295

    
296
</td>
297
</tr></table>
298
</div>
299

    
300
<?php include("fend.inc"); ?>
301
</body>
302
</html>
(132-132/174)