Project

General

Profile

Download (5.94 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
        start_service($_GET['service']);
43
        $savemsg = "{$_GET['service']} has been started.";
44
}
45

    
46
if($_GET['mode'] == "stopservice" and $_GET['service']) {
47
        stop_service($_GET['service']);
48
        $savemsg = "{$_GET['service']} has been stopped.";
49
}
50

    
51
/* batch mode, allow other scripts to call this script */
52
if($_GET['batch']) exit;
53

    
54
$pgtitle = "Status: Services";
55
include("head.inc");
56

    
57
?>
58

    
59
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
60
<?php
61
include("fbegin.inc");
62
?>
63
<p class="pgtitle"><?=$pgtitle?></p>
64
<form action="status_services.php" method="post">
65
<?php if ($savemsg) print_info_box($savemsg); ?>
66

    
67
<p>
68

    
69
<div id="boxarea">
70
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
71
  <tr>
72
    <td>
73
    <table width="100%" border="0" cellpadding="6" cellspacing="0">
74
	<tr>
75
	  <td class="listhdrr"><b><center>Service</center></b></td>
76
	  <td class="listhdrr"><b><center>Description</center></b></td>
77
	  <td class="listhdrr"><b><center>Status</center></b></td>
78
	</tr>
79

    
80
<?php
81

    
82
exec("/bin/ps ax | awk '{ print $5 }'", $psout); 
83
array_shift($psout);
84
foreach($psout as $line) {
85
	$ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
86
}
87

    
88
$services = $config['installedpackages']['service'];
89

    
90
/*    Add services that are in the base.
91
 *
92
 */
93
if(isset($config['dnsmasq']['enable'])) {
94
	$pconfig['name'] = "dnsmasq";
95
	$pconfig['description'] = "DNS Forwarder";
96
	$services[] = $pconfig;
97
	unset($pconfig);
98
}
99

    
100
if(isset($config['captiveportal']['enable'])) {
101
	$pconfig['name'] = "lighttpd";
102
	$pconfig['description'] = "Captive Portal";
103
	$services[] = $pconfig;
104
	$pconfig = "";
105
	unset($pconfig);
106
}
107

    
108
$iflist = array("lan" => "LAN");
109
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
110
	$oc = $config['interfaces']['opt' . $i];
111
	if (isset($oc['enable']) && $oc['if'] && (!$oc['bridge'])) 
112
		$iflist['opt' . $i] = "opt{$i}";	
113
}
114
$show_dhcprelay = false;
115
foreach($iflist as $if) {
116
	if(isset($config['dhcrelay'][$if]['enable']))
117
		$show_dhcprelay = true;
118
}
119

    
120
if($show_dhcprelay == true) {
121
	$pconfig['name'] = "dhcprelay";
122
	$pconfig['description'] = "DHCP Relay";
123
	$services[] = $pconfig;
124
	unset($pconfig);
125
}
126

    
127
if(isset($config['dhcpd']['enable'])) {
128
	$pconfig['name'] = "dhcpd";
129
	$pconfig['description'] = "DHCP Server";
130
	$services[] = $pconfig;
131
	unset($pconfig);
132
}
133

    
134
if(isset($config['snmpd']['enable'])) {
135
	$pconfig['name'] = "bsnmpd";
136
	$pconfig['description'] = "SNMP";
137
	$services[] = $pconfig;
138
	unset($pconfig);
139
}
140

    
141
if(isset($config['proxyarp']['proxyarpnet'])) {
142
	$pconfig['name'] = "choparp";
143
	$pconfig['description'] = "Proxy Arp";
144
	$services[] = $pconfig;
145
	unset($pconfig);
146
}
147

    
148
if($services) {
149
	foreach($services as $service) {
150
		if(!$service['name']) continue;
151
		if(!$service['description']) $service['description'] = "Unknown";
152
		echo '<tr><td class="listlr">' . $service['name'] . '</td>';
153
		echo '<td class="listr">' . $service['description'] . '</td>';
154
		if(is_service_running($service['name'], $ps) or is_process_running($service['name']) ) {
155
			echo '<td class="listr">Running</td><td><img src="/themes/';
156
			echo $g["theme"] . '/images/icons/icon_pass.gif"></td>';
157
			$running = true;
158
		} else {
159
			echo '<td class="listbg"><font color="white">Stopped</td><td><img src="/themes/';
160
			echo $g["theme"] . '/images/icons/icon_block.gif"></td>';
161
			$running = false;
162
		}
163
		echo '<td valign="middle" class="list" nowrap>';
164
		if($running) {
165
			echo "<a href='status_services.php?mode=restartservice&service={$service['name']}'>";
166
			echo "<img title='Restart Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_restart.gif'></a> ";
167
			echo "<a href='status_services.php?mode=stopservice&service={$service['name']}'>";
168
			echo "<img title='Stop Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_stop.gif'> ";
169
			echo "</a>";
170
		} else {
171
			echo "<a href='status_services.php?mode=startservice&service={$service['name']}'> ";
172
			echo "<img title='Start Service' border='0' src='./themes/".$g['theme']."/images/icons/icon_service_start.gif'></a> ";
173
		}
174
		echo '</td>';
175
		echo '</tr>';
176
	}
177
} else {
178
	echo "<tr><td colspan=\"3\"><center>No services found.</td></tr>";
179
}
180
?>
181
</table>
182

    
183
</td>
184
</tr></table>
185
</div>
186

    
187
<meta http-equiv="refresh" content="120;url=<?php print $_SERVER['PHP_SELF']; ?>">
188

    
189
<?php include("fend.inc"); ?>
190
</body>
191
</html>
192

    
(117-117/155)