Projet

Général

Profil

Télécharger (4,79 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / widgets / widgets / load_balancer_status.widget.php @ 56898132

1
<?php
2
/*
3
	Copyright 2010 Jim Pingle
4
	Portions copied from status_lb_pool.php, status_lb_vs.php, and vslb.inc:
5
	Copyright (C) 2010 Seth Mos <seth.mos@dds.nl>.
6
	Copyright (C) 2005-2008 Bill Marquette
7

    
8
	Part of pfSense widgets (https://www.pfsense.org)
9
	originally based on m0n0wall (http://m0n0.ch/wall)
10

    
11
	Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>, Manuel Kasper <mk@neon1.net>
12
	and Jonathan Watt <jwatt@jwatt.org>.
13
	All rights reserved.
14

    
15
	Redistribution and use in source and binary forms, with or without
16
	modification, are permitted provided that the following conditions are met:
17

    
18
	1. Redistributions of source code must retain the above copyright notice,
19
	   this list of conditions and the following disclaimer.
20

    
21
	2. Redistributions in binary form must reproduce the above copyright
22
	   notice, this list of conditions and the following disclaimer in the
23
	   documentation and/or other materials provided with the distribution.
24

    
25
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
26
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
29
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
	POSSIBILITY OF SUCH DAMAGE.
35
*/
36

    
37
$nocsrf = true;
38

    
39
require_once("guiconfig.inc");
40
require_once("pfsense-utils.inc");
41
require_once("functions.inc");
42
require_once("vslb.inc");
43

    
44
$now = time();
45
$year = date("Y");
46

    
47
if (!is_array($config['load_balancer']['lbpool'])) {
48
	$config['load_balancer']['lbpool'] = array();
49
}
50
if (!is_array($config['load_balancer']['virtual_server'])) {
51
	$config['load_balancer']['virtual_server'] = array();
52
}
53
$a_vs = &$config['load_balancer']['virtual_server'];
54
$a_pool = &$config['load_balancer']['lbpool'];
55
$rdr_a = get_lb_redirects();
56
$relay_hosts = get_lb_summary();
57

    
58
$lb_logfile = "{$g['varlog_path']}/relayd.log";
59
$nentries = $config['syslog']['nentries'];
60
if (!$nentries)
61
	$nentries = 50;
62

    
63
?>
64

    
65
<table bgcolor="#990000" width="100%" border="0" cellspacing="0" cellpadding="0" summary="load balancer">
66
	<tr>
67
		<td width="10%" class="listhdrr">Server</td>
68
		<td width="10%" class="listhdrr">Pool</td>
69
		<td width="30%" class="listhdr">Description</td>
70
	</tr>
71
	<?php $i = 0; foreach ($a_vs as $vsent): ?>
72
	<tr>
73
		<?php
74
		switch (trim($rdr_a[$vsent['name']]['status'])) {
75
			case 'active':
76
				$bgcolor = "#90EE90";  // lightgreen
77
				$rdr_a[$vsent['name']]['status'] = "Active";
78
				break;
79
			case 'down':
80
				$bgcolor = "#F08080";  // lightcoral
81
				$rdr_a[$vsent['name']]['status'] = "Down";
82
				break;
83
			default:
84
				$bgcolor = "#D3D3D3";  // lightgray
85
				 $rdr_a[$vsent['name']]['status'] = 'Unknown - relayd not running?';
86
		}
87
		?>
88
		<td class="listlr">
89
			<?=$vsent['name'];?><br />
90
			<span style="background-color: <?=$bgcolor?>; display: block"><i><?=$rdr_a[$vsent['name']]['status']?></i></span>
91
			<?=$vsent['ipaddr'].":".$vsent['port'];?><br />
92
		</td>
93
		<td class="listr" align="center" >
94
		<table border="0" cellpadding="0" cellspacing="2" summary="status">
95
		<?php
96
		foreach ($a_pool as $pool) {
97
			if ($pool['name'] == $vsent['poolname']) {
98
				$pool_hosts=array();
99
				foreach ((array) $pool['servers'] as $server) {
100
					$svr['ip']['addr']=$server;
101
					$svr['ip']['state']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['state'];
102
					$svr['ip']['avail']=$relay_hosts[$pool['name'].":".$pool['port']][$server]['avail'];
103
					$pool_hosts[]=$svr;
104
				}
105
				foreach ((array) $pool['serversdisabled'] as $server) {
106
					$svr['ip']['addr']="$server";
107
					$svr['ip']['state']='disabled';
108
					$svr['ip']['avail']='disabled';
109
					$pool_hosts[]=$svr;
110
				}
111
				asort($pool_hosts);
112
				foreach ((array) $pool_hosts as $server) {
113
					if($server['ip']['addr']!="") {
114
						switch ($server['ip']['state']) {
115
							case 'up':
116
								$bgcolor = "#90EE90";  // lightgreen
117
								$checked = "checked";
118
								break;
119
							case 'disabled':
120
								$bgcolor = "#FFFFFF";  // white
121
								$checked = "";
122
								break;
123
							default:
124
								$bgcolor = "#F08080";  // lightcoral
125
								$checked = "checked";
126
						}
127
						echo "<tr>";
128
						echo "<td bgcolor=\"{$bgcolor}\">&nbsp;{$server['ip']['addr']}:{$pool['port']}&nbsp;</td><td bgcolor=\"{$bgcolor}\">&nbsp;";
129
						if($server['ip']['avail'])
130
						  echo " ({$server['ip']['avail']}) ";
131
						echo "&nbsp;</td></tr>";
132
					}
133
				}
134
			}
135
		}
136
		?>
137
		</table>
138
		</td>
139
		<td class="listbg" >
140
			<font color="#FFFFFF"><?=$vsent['descr'];?></font>
141
		</td>
142
	</tr>
143
	<?php $i++; endforeach; ?>
144
</table>
(10-10/21)