Project

General

Profile

Bug #876 ยป status_gateway_groups.php

ivan primus, 09/20/2010 06:54 AM

 
1
<?php
2
/* $Id$ */
3
/*
4
	status_gateway_groups.php
5
	part of pfSense (http://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-gatewaygroups
37
##|*NAME=Status: Gateway Groups page
38
##|*DESCR=Allow access to the 'Status: Gateway Groups' page.
39
##|*MATCH=status_gateway_groups.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43

    
44
if (!is_array($config['gateways']['gateway_group']))
45
	$config['gateways']['gateway_group'] = array();
46

    
47
$a_gateway_groups = &$config['gateways']['gateway_group'];
48
$changedesc = gettext("Gateway Groups") . ": ";
49

    
50
$gateways_status = array();
51
$gateways_status = return_gateways_status(true);
52

    
53
$pgtitle = array(gettext("Status"),gettext("Gateway Groups"));
54
include("head.inc");
55

    
56
?>
57

    
58
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
59
<?php include("fbegin.inc"); ?>
60
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
61
		<tr>
62
		  <td>
63
<?php
64
			$tab_array = array();
65
			$tab_array[0] = array(gettext("Gateways"), false, "status_gateways.php");
66
			$tab_array[1] = array(gettext("Groups"), true, "status_gateway_groups.php");
67
			display_top_tabs($tab_array);
68
?>
69
</td></tr>
70
 <tr>
71
   <td>
72
	<div id="mainarea">
73
             <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
74
                <tr>
75
                  <td width="20%" class="listhdrr"><?=gettext("Group Name"); ?></td>
76
                  <td width="50%" class="listhdrr"><?=gettext("Gateways"); ?></td>
77
                  <td width="30%" class="listhdr"><?=gettext("Description"); ?></td>
78
		</tr>
79
			  <?php $i = 0; foreach ($a_gateway_groups as $gateway_group): ?>
80
                <tr>
81
                  <td class="listlr">
82
                    <?php
83
			echo $gateway_group['name'];
84
			?>
85
			
86
                  </td>
87
                  <td class="listr">
88
			<table border='0'>
89
                <?php
90
			/* process which priorities we have */
91
			$priorities = array();
92
			foreach($gateway_group['item'] as $item) {
93
				$itemsplit = explode("|", $item);
94
				$priorities[$itemsplit[1]] = true;
95
			}
96
			$priority_count = count($priorities);
97
			ksort($priorities);
98

    
99
			echo "<tr>";
100
			foreach($priorities as $number => $tier) {
101
				echo "<td width='120'>" . sprintf(gettext("Tier %s"), $number) . "</td>";
102
			}
103
			echo "</tr>\n";
104

    
105
			/* inverse gateway group to gateway priority */
106
			$priority_arr = array();
107
			foreach($gateway_group['item'] as $item) {
108
				$itemsplit = explode("|", $item);
109
				$priority_arr[$itemsplit[1]][] = $itemsplit[0];
110
			}
111
			ksort($priority_arr);
112
			$p = 1;
113
			foreach($priority_arr as $number => $tier) {
114
				/* for each priority process the gateways */
115
				foreach($tier as $member) {
116
					/* we always have $priority_count fields */
117
					echo "<tr>";
118
					$c = 1;
119
					while($c <= $priority_count) {
120
						if($p == $c) {
121
                                                   if ($gateways_status[$member]) {
122
						        $status = $gateways_status[$member];
123
							if (stristr($status['status'], "down")) {
124
                                        			$online = gettext("Offline");
125
                                        			$bgcolor = "lightcoral";
126
                                			} elseif (stristr($status['status'], "loss")) {
127
                                        			$online = gettext("Warning, Packetloss");
128
                                        			$bgcolor = "khaki";
129
                                			} elseif (stristr($status['status'], "delay")) {
130
                                        			$online = gettext("Warning, Latency");
131
                                        			$bgcolor = "khaki";
132
                                			} elseif ($status['status'] == "none") {
133
                                        			$online = gettext("Online");
134
                                        			$bgcolor = "lightgreen";
135
                                                        }
136

    
137
                                		  } else {
138
								$online = gettext("Gathering data");
139
								$bgcolor = "lightblue";
140
					          }
141
							echo "<td bgcolor='$bgcolor'>". htmlspecialchars($member) .", $online</td>";
142
						} else {
143
							echo "<td>&nbsp;</td>";
144
						}
145
						$c++;
146
					}
147
					echo "</tr>\n";
148
				}
149
				$p++;
150
			}
151
		    ?>
152
			</table>
153
                  </td>
154
                  <td class="listbg">
155
                    <?=htmlspecialchars($gateway_group['descr']);?>&nbsp;
156
                  </td>
157
		</tr>
158
			  <?php $i++; endforeach; ?>
159

    
160
	</table>
161
     </div>
162
    </td>
163
  </tr>
164
</table>
165
<?php include("fend.inc"); ?>
166
</body>
167
</html>
    (1-1/1)