Project

General

Profile

Download (6.22 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
require("guiconfig.inc");
33

    
34
if (!is_array($config['load_balancer']['lbpool'])) {
35
	$config['load_balancer']['lbpool'] = array();
36
}
37
if (!is_array($config['load_balancer']['virtual_server'])) {
38
	$config['load_balancer']['virtual_server'] = array();
39
}
40
$a_vs = &$config['load_balancer']['virtual_server'];
41
$a_pool = &$config['load_balancer']['lbpool'];
42

    
43

    
44

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

    
73
$redirects_a = exec_command_and_return_text_array('/usr/local/sbin/relayctl show redirects');
74
$summary_a = exec_command_and_return_text_array('/usr/local/sbin/relayctl show summary');
75
$rdr_a = parse_redirects($redirects_a);
76
//$server_a = parse_summary($summary_a, parse_redirects($redirects_a));
77

    
78
function parse_redirects($rdr_a) {
79
  $vs = array();
80
  for ($i = 0; isset($rdr_a[$i]); $i++) {
81
    $line = $rdr_a[$i];
82
    if (preg_match("/^[0-9]+/", $line)) {
83
      $regs = array();
84
      if($x = preg_match("/^[0-9]+\s+redirect\s+([0-9a-zA-Z]+)\s+([a-z]+)/", $line, $regs)) {
85
        $vs[$regs[1]] = array();
86
        $vs[$regs[1]]['status'] = $regs[2];
87
      }
88
    }
89
  }
90
  return $vs;
91
}
92

    
93
function parse_summary($summary, $rdrs_a) {
94
  $server_a = array();
95
  return $server_a;
96
}
97

    
98
$pgtitle = array("Status","Load Balancer","Virtual Server");
99
include("head.inc");
100

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

    
168
<?php include("fend.inc"); ?>
169
</body>
170
</html>
(148-148/200)