Project

General

Profile

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

    
7
	Copyright (C) 2007 Seth Mos <seth.mos@xs4all.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
##|+PRIV
33
##|*IDENT=page-status-loadbalancer-virtualserver
34
##|*NAME=Status: Load Balancer: Virtual Server page
35
##|*DESCR=Allow access to the 'Status: Load Balancer: Virtual Server' page.
36
##|*MATCH=status_slbd_vs.php*
37
##|-PRIV
38

    
39

    
40
require("guiconfig.inc");
41

    
42
if (!is_array($config['load_balancer']['lbpool'])) {
43
	$config['load_balancer']['lbpool'] = array();
44
}
45
if (!is_array($config['load_balancer']['virtual_server'])) {
46
	$config['load_balancer']['virtual_server'] = array();
47
}
48
$a_vs = &$config['load_balancer']['virtual_server'];
49
$a_pool = &$config['load_balancer']['lbpool'];
50

    
51

    
52

    
53
// # relayctl show summary
54
// Id   Type      Name                      Avlblty Status
55
// 1    redirect  testvs2                           active
56
// 5    table     test2:80                          active (3 hosts up)
57
// 11   host      192.168.1.2               91.55%  up
58
// 10   host      192.168.1.3               100.00% up
59
// 9    host      192.168.1.4               88.73%  up
60
// 3    table     test:80                           active (1 hosts up)
61
// 7    host      192.168.1.2               66.20%  down
62
// 6    host      192.168.1.3               97.18%  up
63
// 0    redirect  testvs                            active
64
// 3    table     test:80                           active (1 hosts up)
65
// 7    host      192.168.1.2               66.20%  down
66
// 6    host      192.168.1.3               97.18%  up
67
// 4    table     testvs-sitedown:80                active (1 hosts up)
68
// 8    host      192.168.1.4               84.51%  up
69
// # relayctl show redirects
70
// Id   Type      Name                      Avlblty Status
71
// 1    redirect  testvs2                           active
72
// 0    redirect  testvs                            active
73
// # relayctl show redirects
74
// Id   Type      Name                      Avlblty Status
75
// 1    redirect  testvs2                           active
76
//            total: 2 sessions
77
//            last: 2/60s 2/h 2/d sessions
78
//            average: 1/60s 0/h 0/d sessions
79
// 0    redirect  testvs                            active
80

    
81
$redirects_a = exec_command_and_return_text_array('/usr/local/sbin/relayctl show redirects');
82
$summary_a = exec_command_and_return_text_array('/usr/local/sbin/relayctl show summary');
83
$rdr_a = parse_redirects($redirects_a);
84
//$server_a = parse_summary($summary_a, parse_redirects($redirects_a));
85

    
86
function parse_redirects($rdr_a) {
87
  $vs = array();
88
  for ($i = 0; isset($rdr_a[$i]); $i++) {
89
    $line = $rdr_a[$i];
90
    if (preg_match("/^[0-9]+/", $line)) {
91
      $regs = array();
92
      if($x = preg_match("/^[0-9]+\s+redirect\s+([0-9a-zA-Z]+)\s+([a-z]+)/", $line, $regs)) {
93
        $vs[$regs[1]] = array();
94
        $vs[$regs[1]]['status'] = $regs[2];
95
      }
96
    }
97
  }
98
  return $vs;
99
}
100

    
101
function parse_summary($summary, $rdrs_a) {
102
  $server_a = array();
103
  return $server_a;
104
}
105

    
106
$pgtitle = array("Status","Load Balancer","Virtual Server");
107
include("head.inc");
108

    
109
?>
110
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
111
<?php include("fbegin.inc"); ?>
112
<table width="100%" border="0" cellpadding="0" cellspacing="0">
113
  <tr><td class="tabnavtbl">
114
  <?php
115
        /* active tabs */
116
        $tab_array = array();
117
        $tab_array[] = array("Pools", false, "status_slbd_pool.php");
118
        $tab_array[] = array("Virtual Servers", true, "status_slbd_vs.php");
119
        display_top_tabs($tab_array);
120
  ?>
121
  </td></tr>
122
  <tr>
123
    <td>
124
	<div id="mainarea">
125
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
126
                <tr>
127
                  <td width="10%" class="listhdrr">Name</td>
128
		  <td width="10%" class="listhdrr">Port</td>
129
                  <td width="10%" class="listhdrr">Servers</td>
130
                  <td width="30%" class="listhdrr">Status</td>
131
                  <td width="30%" class="listhdr">Description</td>
132
				</tr>
133
			  <?php $i = 0; foreach ($a_vs as $vsent): ?>
134
                <tr>
135
                  <td class="listlr">
136
				<?=$vsent['name'];?>
137
                  </td>
138
                  <td class="listr" align="center" >
139
                                <?=$vsent['port'];?>
140
                                <br />
141
                  </td>
142
                  <td class="listr" align="center" >
143
			<table border="0" cellpadding="0" cellspacing="2">
144
                        <?php
145
			foreach ($a_pool as $vipent) {
146
				if ($vipent['name'] == $vsent['pool']) {
147
					foreach ((array) $vipent['servers'] as $server) {
148
						print "<tr><td> {$server} </td></tr>";
149
					}
150
				}
151
			}
152
			?>
153
			</table>
154
                  </td>
155
                  <?php
156
                  switch ($rdr_a[$vsent['name']]['status']) {
157
                    case 'active':
158
                      $bgcolor = "lightgreen";
159
                      break;
160
                    default:
161
                      $bgcolor = "lightcoral";
162
                  }
163
                  ?>
164
                  <td class="listr" bgcolor="<?=$bgcolor?>">
165
                  <?=$rdr_a[$vsent['name']]['status']?>
166
                  </td>
167
                  <td class="listbg" >
168
				<font color="#FFFFFF"><?=$vipent['desc'];?></font>
169
                  </td>
170
                </tr>
171
		<?php $i++; endforeach; ?>
172
             </table>
173
	   </div>
174
	</table>
175

    
176
<?php include("fend.inc"); ?>
177
</body>
178
</html>
(161-161/211)