Project

General

Profile

Download (7.22 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_lb_pool.php
5
	part of pfSense (http://www.pfsense.com/)
6

    
7
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
8
	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
/*	
32
	pfSense_MODULE:	routing
33
*/
34

    
35
##|+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
##|*MATCH=status_lb_pool.php*
40
##|-PRIV
41

    
42
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
$lb_logfile = "{$g['varlog_path']}/relayd.log";
50

    
51
$nentries = $config['syslog']['nentries'];
52
if (!$nentries)
53
        $nentries = 50;
54

    
55
$now = time();
56
$year = date("Y");
57

    
58
$pgtitle = array(gettext("Status"),gettext("Load Balancer"),gettext("Pool"));
59
include("head.inc");
60

    
61
$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
?>
77
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
78
<script src="/javascript/sorttable.js"></script>
79
<?php include("fbegin.inc"); ?>
80
<table width="100%" border="0" cellpadding="0" cellspacing="0">
81
  <tr><td class="tabnavtbl">
82
  <?php
83
        /* active tabs */
84
        $tab_array = array();
85
        $tab_array[] = array(gettext("Pools"), true, "status_lb_pool.php");
86
        $tab_array[] = array(gettext("Virtual Servers"), false, "status_lb_vs.php");
87
        display_top_tabs($tab_array);
88
  ?>
89
  </td></tr>
90
  <tr>
91
    <td>
92
	<div id="mainarea">
93
              <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont sortable" name="sortabletable" id="sortabletable">
94
                <tr>
95
		  <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
				</tr>
101
			  <?php $i = 0; foreach ($a_pool as $vipent):
102
			  ?>
103
                <tr>
104
                  <td class="listlr">
105
				<?=$vipent['name'];?>
106
                  </td>
107
                  <td class="listr" align="center" >
108
			<?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
                  </td>
121
                  <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
					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
							if($svr[0]!="") PRINT "<td><input type='checkbox' name='".$vipent['name']."_".$svr[0]."' checked></td>";
138
							break;
139
						  case 'failover':
140
							if($svr[0]!="") PRINT "<td><input type='radio' name='".$vipent['name']."' checked></td>";
141
							break;
142
						}
143
						PRINT "<td bgcolor=".$bgcolor."> {$svr[0]}:{$vipent['port']} </td></tr>";
144
					}
145
                                }
146
				foreach ((array) $vipent['serversdisabled'] as $server) {
147
                                       	$svr = split("\|", $server);
148

    
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
				}
160
                        ?>
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
						$logstates = return_clog($lb_logfile, $nentries, true, array("$monitorip", "marking"), "", true);
176

    
177
						$logstates = $logstates[0];
178

    
179
						if(stristr($logstates, $monitorip)) {
180
							$date = preg_split("/[ ]+/" , $logstates);
181
							$lastchange = "$date[0] $date[1] $year $date[2]";
182
						}
183
						if(stristr($poolstatus, $monitorip)) {
184
							$online = gettext("Online");
185
							$bgcolor = "lightgreen";
186
							$change = $now - strtotime("$lastchange");
187
							if($change < 300) {
188
								$bgcolor = "khaki";
189
							}
190
						} else {
191
							$online = gettext("Offline");
192
							$bgcolor = "lightcoral";
193
						}
194
						PRINT "<tr><td bgcolor=\"$bgcolor\" > $online </td><td>";
195
						if($lastchange <> "") {
196
							PRINTF(gettext("Last change %s"),$lastchange);
197
						} else {
198
							PRINT(gettext("No changes found in logfile"));
199
						}
200
						PRINT "</td></tr>";
201
                                        }
202
                                } else {
203
					PRINT "<tr><td> {$vipent['monitor']} </td></tr>";
204
                                }
205
                        ?>
206
			</table>
207
                  </td>
208
                  <td class="listbg" >
209
					<?=$vipent['desc'];?>
210
                  </td>
211
                </tr>
212
		<?php
213
			$i++;
214
		 endforeach;
215
		 ?>
216
              </table>
217
	   </div>
218
	</table>
219

    
220
<?php include("fend.inc"); ?>
221
</body>
222
</html>
(162-162/222)