Project

General

Profile

Download (7.99 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
		default:
65
			restart_service($_GET['service']);
66
			break;
67
	}
68
	$savemsg = "{$_GET['service']} has been restarted.";
69
	sleep(5);
70
}
71

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

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

    
136
/* batch mode, allow other scripts to call this script */
137
if($_GET['batch']) exit;
138

    
139
$pgtitle = "Status: Services";
140
include("head.inc");
141

    
142
?>
143

    
144
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
145
<?php
146
include("fbegin.inc");
147
?>
148
<p class="pgtitle"><?=$pgtitle?></p>
149
<form action="status_services.php" method="post">
150
<?php if ($savemsg) print_info_box($savemsg); ?>
151

    
152
<p>
153

    
154
<div id="boxarea">
155
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
156
  <tr>
157
    <td>
158
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
159
	<tr>
160
	  <td class="listhdrr"><b><center>Service</center></b></td>
161
	  <td class="listhdrr"><b><center>Description</center></b></td>
162
	  <td class="listhdrr"><b><center>Status</center></b></td>
163
	</tr>
164

    
165
<?php
166

    
167
exec("/bin/ps ax | awk '{ print $5 }'", $psout);
168
array_shift($psout);
169
foreach($psout as $line) {
170
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
171
}
172

    
173
$services = $config['installedpackages']['service'];
174

    
175
/*    Add services that are in the base.
176
 *
177
 */
178
if(isset($config['dnsmasq']['enable'])) {
179
	$pconfig['name'] = "dnsmasq";
180
	$pconfig['description'] = "DNS Forwarder";
181
	$services[] = $pconfig;
182
	unset($pconfig);
183
}
184

    
185
if(isset($config['captiveportal']['enable'])) {
186
	$pconfig['name'] = "lighttpd";
187
	$pconfig['description'] = "Captive Portal";
188
	$services[] = $pconfig;
189
	$pconfig = "";
190
	unset($pconfig);
191
}
192

    
193
$iflist = array("lan" => "LAN");
194
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
195
	$oc = $config['interfaces']['opt' . $i];
196
	if (isset($oc['enable']) && $oc['if'] && (!$oc['bridge']))
197
		$iflist['opt' . $i] = "opt{$i}";
198
}
199
$show_dhcprelay = false;
200
foreach($iflist as $if) {
201
	if(isset($config['dhcrelay'][$if]['enable']))
202
		$show_dhcprelay = true;
203
}
204

    
205
if($show_dhcprelay == true) {
206
	$pconfig['name'] = "dhcrelay";
207
	$pconfig['description'] = "DHCP Relay";
208
	$services[] = $pconfig;
209
	unset($pconfig);
210
}
211

    
212
if(is_dhcp_server_enabled()) {
213
	$pconfig['name'] = "dhcpd";
214
	$pconfig['description'] = "DHCP Service";
215
	$services[] = $pconfig;
216
	unset($pconfig);
217
}
218

    
219
if(isset($config['snmpd']['enable'])) {
220
	$pconfig['name'] = "bsnmpd";
221
	$pconfig['description'] = "SNMP Service";
222
	$services[] = $pconfig;
223
	unset($pconfig);
224
}
225

    
226
if(isset($config['proxyarp']['proxyarpnet'])) {
227
	$pconfig['name'] = "choparp";
228
	$pconfig['description'] = "Proxy Arp";
229
	$services[] = $pconfig;
230
	unset($pconfig);
231
}
232

    
233
if($config['installedpackages']['miniupnpd']['config'][0]['enable']) {
234
    $pconfig['name'] = "miniupnpd";
235
    $pconfig['description'] = gettext("UPnP Service");
236
    $services[] = $pconfig;
237
    unset($pconfig);
238
}
239

    
240
if (isset($config['ipsec']['enable'])) {
241
    $pconfig['name'] = "racoon";
242
    $pconfig['description'] = gettext("IPSEC VPN");
243
    $services[] = $pconfig;
244
    unset($pconfig);
245
}
246

    
247
if($services) {
248
	foreach($services as $service) {
249
		if(!$service['name']) continue;
250
		if(!$service['description']) $service['description'] = get_pkg_descr($service['name']);
251
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
252
		echo '<td class="listr">' . $service['description'] . '</td>';
253
		if(is_service_running($service['name'], $ps) or is_process_running($service['name']) ) {
254
			echo '<td class="listr"><center>';
255
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
256
			$running = true;
257
		} else {
258
			echo '<td class="listbg"><center>';
259
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
260
			$running = false;
261
		}
262
		echo '<td valign="middle" class="list" nowrap>';
263
		if($running) {
264
			echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
265
			echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
266
			echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'>";
267
			echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
268
			echo "</a>";
269
		} else {
270
			echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
271
			echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
272
		}
273
		echo '</td>';
274
		echo '</tr>';
275
	}
276
} else {
277
	echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
278
}
279
?>
280
</table>
281

    
282
</td>
283
</tr></table>
284
</div>
285

    
286
<?php include("fend.inc"); ?>
287
</body>
288
</html>
(131-131/173)