1 |
6b6a76f9
|
Scott Ullrich
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
477dcf13
|
Chris Buechler
|
status_lb_pool.php
|
5 |
6b6a76f9
|
Scott Ullrich
|
part of pfSense (http://www.pfsense.com/)
|
6 |
|
|
|
7 |
6216690b
|
smos
|
Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
|
8 |
6b6a76f9
|
Scott Ullrich
|
All rights reserved.
|
9 |
|
|
|
10 |
|
|
Redistribution and use in source and binary forms, with or without
|
11 |
|
|
modification, are permitted provided that the following conditions are met:
|
12 |
|
|
|
13 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
this list of conditions and the following disclaimer.
|
15 |
|
|
|
16 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
17 |
|
|
notice, this list of conditions and the following disclaimer in the
|
18 |
|
|
documentation and/or other materials provided with the distribution.
|
19 |
|
|
|
20 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
30 |
|
|
*/
|
31 |
1d333258
|
Scott Ullrich
|
/*
|
32 |
|
|
pfSense_MODULE: routing
|
33 |
|
|
*/
|
34 |
6b6a76f9
|
Scott Ullrich
|
|
35 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
36 |
|
|
##|*IDENT=page-status-loadbalancer-pool
|
37 |
|
|
##|*NAME=Status: Load Balancer: Pool page
|
38 |
|
|
##|*DESCR=Allow access to the 'Status: Load Balancer: Pool' page.
|
39 |
477dcf13
|
Chris Buechler
|
##|*MATCH=status_lb_pool.php*
|
40 |
6b07c15a
|
Matthew Grooms
|
##|-PRIV
|
41 |
|
|
|
42 |
6b6a76f9
|
Scott Ullrich
|
require("guiconfig.inc");
|
43 |
|
|
|
44 |
|
|
if (!is_array($config['load_balancer']['lbpool'])) {
|
45 |
|
|
$config['load_balancer']['lbpool'] = array();
|
46 |
|
|
}
|
47 |
|
|
$a_pool = &$config['load_balancer']['lbpool'];
|
48 |
|
|
|
49 |
087a89f8
|
Chris Buechler
|
$lb_logfile = "{$g['varlog_path']}/relayd.log";
|
50 |
6b6a76f9
|
Scott Ullrich
|
|
51 |
|
|
$nentries = $config['syslog']['nentries'];
|
52 |
|
|
if (!$nentries)
|
53 |
|
|
$nentries = 50;
|
54 |
|
|
|
55 |
|
|
$now = time();
|
56 |
|
|
$year = date("Y");
|
57 |
|
|
|
58 |
bbaba7e6
|
Rafael Lucas
|
$pgtitle = array(gettext("Status"),gettext("Load Balancer"),gettext("Pool"));
|
59 |
6b6a76f9
|
Scott Ullrich
|
include("head.inc");
|
60 |
|
|
|
61 |
8c29490e
|
Chris Buechler
|
$relayctl=split("\n", shell_exec("/usr/local/sbin/relayctl show summary"));
|
62 |
|
|
$relay_hosts=Array();
|
63 |
|
|
foreach( (array) $relayctl as $line) {
|
64 |
|
|
$t=split("\t", $line);
|
65 |
|
|
switch (trim($t[1])) {
|
66 |
|
|
case "table":
|
67 |
|
|
$curpool=trim($t[2]);
|
68 |
|
|
break;
|
69 |
|
|
case "host":
|
70 |
|
|
$curhost=trim($t[2]);
|
71 |
|
|
$relay_hosts[$curpool][$curhost]['state']=trim($t[4]);
|
72 |
|
|
break;
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
|
76 |
6b6a76f9
|
Scott Ullrich
|
?>
|
77 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
78 |
ff9d6728
|
Scott Ullrich
|
<script src="/javascript/sorttable.js"></script>
|
79 |
6b6a76f9
|
Scott Ullrich
|
<?php include("fbegin.inc"); ?>
|
80 |
|
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
81 |
f852d17b
|
Seth Mos
|
<tr><td class="tabnavtbl">
|
82 |
|
|
<?php
|
83 |
|
|
/* active tabs */
|
84 |
|
|
$tab_array = array();
|
85 |
bbaba7e6
|
Rafael Lucas
|
$tab_array[] = array(gettext("Pools"), true, "status_lb_pool.php");
|
86 |
|
|
$tab_array[] = array(gettext("Virtual Servers"), false, "status_lb_vs.php");
|
87 |
f852d17b
|
Seth Mos
|
display_top_tabs($tab_array);
|
88 |
|
|
?>
|
89 |
|
|
</td></tr>
|
90 |
6b6a76f9
|
Scott Ullrich
|
<tr>
|
91 |
|
|
<td>
|
92 |
|
|
<div id="mainarea">
|
93 |
3473bb6a
|
Scott Ullrich
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable" name="sortabletable" id="sortabletable">
|
94 |
6b6a76f9
|
Scott Ullrich
|
<tr>
|
95 |
a9d5bf0c
|
Renato Botelho
|
<td width="10%" class="listhdrr"><?=gettext("Name");?></td>
|
96 |
|
|
<td width="10%" class="listhdrr"><?=gettext("Mode");?></td>
|
97 |
|
|
<td width="10%" class="listhdrr"><?=gettext("Servers");?></td>
|
98 |
|
|
<td width="10%" class="listhdrr"><?=gettext("Monitor");?></td>
|
99 |
|
|
<td width="30%" class="listhdr"><?=gettext("Description");?></td>
|
100 |
6b6a76f9
|
Scott Ullrich
|
</tr>
|
101 |
c3da9072
|
Seth Mos
|
<?php $i = 0; foreach ($a_pool as $vipent):
|
102 |
|
|
?>
|
103 |
6b6a76f9
|
Scott Ullrich
|
<tr>
|
104 |
|
|
<td class="listlr">
|
105 |
|
|
<?=$vipent['name'];?>
|
106 |
|
|
</td>
|
107 |
4190956e
|
Seth Mos
|
<td class="listr" align="center" >
|
108 |
8c29490e
|
Chris Buechler
|
<?php
|
109 |
|
|
switch($vipent['mode']) {
|
110 |
|
|
case "loadbalance":
|
111 |
|
|
echo "Load balancing";
|
112 |
|
|
break;
|
113 |
|
|
case "failover":
|
114 |
|
|
echo "Manual failover";
|
115 |
|
|
break;
|
116 |
|
|
default:
|
117 |
|
|
echo "(default)";
|
118 |
|
|
}
|
119 |
|
|
?>
|
120 |
4190956e
|
Seth Mos
|
</td>
|
121 |
6b6a76f9
|
Scott Ullrich
|
<td class="listr" align="center" >
|
122 |
|
|
<table border="0" cellpadding="0" cellspacing="2">
|
123 |
|
|
<?php
|
124 |
|
|
foreach ((array) $vipent['servers'] as $server) {
|
125 |
|
|
$svr = split("\|", $server);
|
126 |
8c29490e
|
Chris Buechler
|
if($svr[0]!="") {
|
127 |
|
|
switch ($relay_hosts[$vipent['name'].":".$vipent['port']][$svr[0]]['state']) {
|
128 |
|
|
case 'up':
|
129 |
|
|
$bgcolor = "lightgreen";
|
130 |
|
|
break;
|
131 |
|
|
default:
|
132 |
|
|
$bgcolor = "lightcoral";
|
133 |
|
|
}
|
134 |
|
|
PRINT "<tr>";
|
135 |
|
|
switch ($vipent['mode']) {
|
136 |
|
|
case 'loadbalance':
|
137 |
cdad3139
|
Eirik Oeverby
|
if($svr[0]!="") PRINT "<td><input type='checkbox' name='".$vipent['name']."_".$svr[0]."' checked></td>";
|
138 |
8c29490e
|
Chris Buechler
|
break;
|
139 |
|
|
case 'failover':
|
140 |
cdad3139
|
Eirik Oeverby
|
if($svr[0]!="") PRINT "<td><input type='radio' name='".$vipent['name']."' checked></td>";
|
141 |
8c29490e
|
Chris Buechler
|
break;
|
142 |
|
|
}
|
143 |
|
|
PRINT "<td bgcolor=".$bgcolor."> {$svr[0]}:{$vipent['port']} </td></tr>";
|
144 |
|
|
}
|
145 |
6b6a76f9
|
Scott Ullrich
|
}
|
146 |
8c29490e
|
Chris Buechler
|
foreach ((array) $vipent['serversdisabled'] as $server) {
|
147 |
|
|
$svr = split("\|", $server);
|
148 |
cdad3139
|
Eirik Oeverby
|
|
149 |
|
|
PRINT "<tr>";
|
150 |
|
|
switch ($vipent['mode']) {
|
151 |
|
|
case 'loadbalance':
|
152 |
|
|
if($svr[0]!="") PRINT "<td><input type='checkbox' name='".$vipent['name']."_".$svr[0]."'></td>";
|
153 |
|
|
break;
|
154 |
|
|
case 'failover':
|
155 |
|
|
if($svr[0]!="") PRINT "<td><input type='radio' name='".$vipent['name']."'></td>";
|
156 |
|
|
break;
|
157 |
|
|
}
|
158 |
|
|
PRINT "<td> {$svr[0]}:{$vipent['port']} </td></tr>";
|
159 |
8c29490e
|
Chris Buechler
|
}
|
160 |
6b6a76f9
|
Scott Ullrich
|
?>
|
161 |
|
|
</table>
|
162 |
|
|
</td>
|
163 |
|
|
<td class="listr" >
|
164 |
|
|
<table border="0" cellpadding="0" cellspacing="2">
|
165 |
|
|
<?php
|
166 |
|
|
if ($vipent['type'] == "gateway") {
|
167 |
|
|
$poolfile = "{$g['tmp_path']}/{$vipent['name']}.pool";
|
168 |
|
|
if(file_exists("$poolfile")) {
|
169 |
|
|
$poolstatus = file_get_contents("$poolfile");
|
170 |
|
|
}
|
171 |
|
|
foreach ((array) $vipent['servers'] as $server) {
|
172 |
|
|
$lastchange = "";
|
173 |
|
|
$svr = split("\|", $server);
|
174 |
|
|
$monitorip = $svr[1];
|
175 |
087a89f8
|
Chris Buechler
|
$logstates = return_clog($lb_logfile, $nentries, true, array("$monitorip", "marking"), "", true);
|
176 |
43e7c36c
|
Bill Marquette
|
|
177 |
d269563b
|
Scott Ullrich
|
$logstates = $logstates[0];
|
178 |
6b6a76f9
|
Scott Ullrich
|
|
179 |
d269563b
|
Scott Ullrich
|
if(stristr($logstates, $monitorip)) {
|
180 |
|
|
$date = preg_split("/[ ]+/" , $logstates);
|
181 |
6b6a76f9
|
Scott Ullrich
|
$lastchange = "$date[0] $date[1] $year $date[2]";
|
182 |
|
|
}
|
183 |
|
|
if(stristr($poolstatus, $monitorip)) {
|
184 |
bbaba7e6
|
Rafael Lucas
|
$online = gettext("Online");
|
185 |
6b6a76f9
|
Scott Ullrich
|
$bgcolor = "lightgreen";
|
186 |
|
|
$change = $now - strtotime("$lastchange");
|
187 |
|
|
if($change < 300) {
|
188 |
|
|
$bgcolor = "khaki";
|
189 |
|
|
}
|
190 |
|
|
} else {
|
191 |
bbaba7e6
|
Rafael Lucas
|
$online = gettext("Offline");
|
192 |
6b6a76f9
|
Scott Ullrich
|
$bgcolor = "lightcoral";
|
193 |
|
|
}
|
194 |
d269563b
|
Scott Ullrich
|
PRINT "<tr><td bgcolor=\"$bgcolor\" > $online </td><td>";
|
195 |
|
|
if($lastchange <> "") {
|
196 |
bbaba7e6
|
Rafael Lucas
|
PRINTF(gettext("Last change %s"),$lastchange);
|
197 |
d269563b
|
Scott Ullrich
|
} else {
|
198 |
bbaba7e6
|
Rafael Lucas
|
PRINT(gettext("No changes found in logfile"));
|
199 |
d269563b
|
Scott Ullrich
|
}
|
200 |
|
|
PRINT "</td></tr>";
|
201 |
6b6a76f9
|
Scott Ullrich
|
}
|
202 |
|
|
} else {
|
203 |
|
|
PRINT "<tr><td> {$vipent['monitor']} </td></tr>";
|
204 |
|
|
}
|
205 |
|
|
?>
|
206 |
|
|
</table>
|
207 |
|
|
</td>
|
208 |
|
|
<td class="listbg" >
|
209 |
d514a16b
|
Scott Ullrich
|
<?=$vipent['desc'];?>
|
210 |
6b6a76f9
|
Scott Ullrich
|
</td>
|
211 |
|
|
</tr>
|
212 |
c3da9072
|
Seth Mos
|
<?php
|
213 |
|
|
$i++;
|
214 |
|
|
endforeach;
|
215 |
|
|
?>
|
216 |
6b6a76f9
|
Scott Ullrich
|
</table>
|
217 |
|
|
</div>
|
218 |
|
|
</table>
|
219 |
591fe019
|
Scott Ullrich
|
|
220 |
6b6a76f9
|
Scott Ullrich
|
<?php include("fend.inc"); ?>
|
221 |
|
|
</body>
|
222 |
|
|
</html>
|