Project

General

Profile

Download (6.2 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
if($_GET['mode'] == "restartservice" and $_GET['service']) {
37
	restart_service($_GET['service']);
38
	$savemsg = "{$_GET['service']} has been restarted.";
39
}
40

    
41
if($_GET['mode'] == "startservice" and $_GET['service']) {
42
	switch($_GET['service']) {
43
		case 'bsnmpd':
44
			services_snmpd_configure();	
45
			break;
46
		case 'dnsmasq':
47
			services_dnsmasq_configure();
48
			break;
49
		case 'dhcpd':
50
			services_dhcpd_configure();
51
			break;
52
		default:
53
			start_service($_GET['service']);
54
			break;
55
	}
56
	start_service($_GET['service']);
57
    $savemsg = "{$_GET['service']} has been started.";
58
}
59

    
60
if($_GET['mode'] == "stopservice" and $_GET['service']) {
61
    stop_service($_GET['service']);
62
    $savemsg = "{$_GET['service']} has been stopped.";
63
}
64

    
65
/* batch mode, allow other scripts to call this script */
66
if($_GET['batch']) exit;
67

    
68
$pgtitle = "Status: Services";
69
include("head.inc");
70

    
71
?>
72

    
73
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
74
<?php
75
include("fbegin.inc");
76
?>
77
<p class="pgtitle"><?=$pgtitle?></p>
78
<form action="status_services.php" method="post">
79
<?php if ($savemsg) print_info_box($savemsg); ?>
80

    
81
<p>
82

    
83
<div id="boxarea">
84
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
85
  <tr>
86
    <td>
87
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
88
	<tr>
89
	  <td class="listhdrr"><b><center>Service</center></b></td>
90
	  <td class="listhdrr"><b><center>Description</center></b></td>
91
	  <td class="listhdrr"><b><center>Status</center></b></td>
92
	</tr>
93

    
94
<?php
95

    
96
exec("/bin/ps ax | awk '{ print $5 }'", $psout); 
97
array_shift($psout);
98
foreach($psout as $line) {
99
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
100
}
101

    
102
$services = $config['installedpackages']['service'];
103

    
104
/*    Add services that are in the base.
105
 *
106
 */
107
if(isset($config['dnsmasq']['enable'])) {
108
	$pconfig['name'] = "dnsmasq";
109
	$pconfig['description'] = "DNS Forwarder";
110
	$services[] = $pconfig;
111
	unset($pconfig);
112
}
113

    
114
if(isset($config['captiveportal']['enable'])) {
115
	$pconfig['name'] = "lighttpd";
116
	$pconfig['description'] = "Captive Portal";
117
	$services[] = $pconfig;
118
	$pconfig = "";
119
	unset($pconfig);
120
}
121

    
122
$iflist = array("lan" => "LAN");
123
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
124
	$oc = $config['interfaces']['opt' . $i];
125
	if (isset($oc['enable']) && $oc['if'] && (!$oc['bridge'])) 
126
		$iflist['opt' . $i] = "opt{$i}";	
127
}
128
$show_dhcprelay = false;
129
foreach($iflist as $if) {
130
	if(isset($config['dhcrelay'][$if]['enable']))
131
		$show_dhcprelay = true;
132
}
133

    
134
if($show_dhcprelay == true) {
135
	$pconfig['name'] = "dhcprelay";
136
	$pconfig['description'] = "DHCP Relay";
137
	$services[] = $pconfig;
138
	unset($pconfig);
139
}
140

    
141
if(isset($config['dhcpd']['enable'])) {
142
	$pconfig['name'] = "dhcpd";
143
	$pconfig['description'] = "DHCP Server";
144
	$services[] = $pconfig;
145
	unset($pconfig);
146
}
147

    
148
if(isset($config['snmpd']['enable'])) {
149
	$pconfig['name'] = "bsnmpd";
150
	$pconfig['description'] = "SNMP";
151
	$services[] = $pconfig;
152
	unset($pconfig);
153
}
154

    
155
if(isset($config['proxyarp']['proxyarpnet'])) {
156
	$pconfig['name'] = "choparp";
157
	$pconfig['description'] = "Proxy Arp";
158
	$services[] = $pconfig;
159
	unset($pconfig);
160
}
161

    
162
if($services) {
163
	foreach($services as $service) {
164
		if(!$service['name']) continue;
165
		if(!$service['description']) $service['description'] = "Unknown";
166
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
167
		echo '<td class="listr">' . $service['description'] . '</td>';
168
		if(is_service_running($service['name'], $ps) or is_process_running($service['name']) ) {
169
			echo '<td class="listr"><center>';
170
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_pass.gif\"> Running</td>";
171
			$running = true;
172
		} else {
173
			echo '<td class="listbg"><center>';
174
			echo "<img src=\"/themes/" . $g["theme"] . "/images/icons/icon_block.gif\"> <font color=\"white\">Stopped</td>";
175
			$running = false;
176
		}
177
		echo '<td valign="middle" class="list" nowrap>';
178
		if($running) {
179
			echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
180
			echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
181
			echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'>";
182
			echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
183
			echo "</a>";
184
		} else {
185
			echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
186
			echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
187
		}
188
		echo '</td>';
189
		echo '</tr>';
190
	}
191
} else {
192
	echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
193
}
194
?>
195
</table>
196

    
197
</td>
198
</tr></table>
199
</div>
200

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

    
203
<?php include("fend.inc"); ?>
204
</body>
205
</html>
206

    
(124-124/164)