Projet

Général

Profil

Télécharger (13,2 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / system_gateway_groups_edit.php @ fab1cd2f

1
<?php 
2
/* $Id$ */
3
/*
4
	system_gateway_groups_edit.php
5
	part of pfSense (https://www.pfsense.org)
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-system-gateways-editgatewaygroups
37
##|*NAME=System: Gateways: Edit Gateway Groups page
38
##|*DESCR=Allow access to the 'System: Gateways: Edit Gateway Groups' page.
39
##|*MATCH=system_gateway_groups_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require_once("ipsec.inc");
44
require_once("vpn.inc");
45

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

    
49
$a_gateway_groups = &$config['gateways']['gateway_group'];
50
$a_gateways = return_gateways_array();
51
$carplist = get_configured_carp_interface_list();
52

    
53
$categories = array('down' => gettext("Member Down"),
54
                    'downloss' => gettext("Packet Loss"),
55
                    'downlatency' => gettext("High Latency"),
56
                    'downlosslatency' => gettext("Packet Loss or High Latency"));
57

    
58
if (is_numericint($_GET['id']))
59
	$id = $_GET['id'];
60
if (isset($_POST['id']) && is_numericint($_POST['id']))
61
	$id = $_POST['id'];
62

    
63
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
64
	$id = $_GET['dup'];
65

    
66
if (isset($id) && $a_gateway_groups[$id]) {
67
	$pconfig['name'] = $a_gateway_groups[$id]['name'];
68
	$pconfig['item'] = &$a_gateway_groups[$id]['item'];
69
	$pconfig['descr'] = $a_gateway_groups[$id]['descr'];
70
	$pconfig['trigger'] = $a_gateway_groups[$id]['trigger'];
71
}
72

    
73
if (isset($_GET['dup']) && is_numericint($_GET['dup']))
74
	unset($id);
75

    
76
if ($_POST) {
77

    
78
	unset($input_errors);
79
	$pconfig = $_POST;
80

    
81
	/* input validation */
82
	$reqdfields = explode(" ", "name");
83
	$reqdfieldsn = explode(",", "Name");
84
	
85
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
86
	
87
	if (! isset($_POST['name'])) {
88
		$input_errors[] = gettext("A valid gateway group name must be specified.");
89
	}
90
	if (! is_validaliasname($_POST['name'])) {
91
		$input_errors[] = gettext("The gateway name must not contain invalid characters.");
92
	}
93

    
94
	if (isset($_POST['name'])) {
95
		/* check for overlaps */
96
		if(is_array($a_gateway_groups)) {
97
			foreach ($a_gateway_groups as $gateway_group) {
98
				if (isset($id) && ($a_gateway_groups[$id]) && ($a_gateway_groups[$id] === $gateway_group)) {
99
					if ($gateway_group['name'] != $_POST['name'])
100
						$input_errors[] = gettext("Changing name on a gateway group is not allowed.");
101
					continue;
102
				}
103

    
104
				if ($gateway_group['name'] == $_POST['name']) {
105
					$input_errors[] = sprintf(gettext('A gateway group with this name "%s" already exists.'), $_POST['name']);
106
					break;
107
				}
108
			}
109
		}
110
	}
111

    
112
	/* Build list of items in group with priority */
113
	$pconfig['item'] = array();
114
	foreach($a_gateways as $gwname => $gateway) {
115
		if($_POST[$gwname] > 0) {
116
			$vipname = "{$gwname}_vip";
117
			/* we have a priority above 0 (disabled), add item to list */
118
			$pconfig['item'][] = "{$gwname}|{$_POST[$gwname]}|{$_POST[$vipname]}";
119
		}
120
		/* check for overlaps */
121
		if ($_POST['name'] == $gwname)
122
			$input_errors[] = sprintf(gettext('A gateway group cannot have the same name with a gateway "%s" please choose another name.'), $_POST['name']);
123

    
124
	}
125
	if(count($pconfig['item']) == 0)
126
		$input_errors[] = gettext("No gateway(s) have been selected to be used in this group");
127

    
128
	if (!$input_errors) {
129
		$gateway_group = array();
130
		$gateway_group['name'] = $_POST['name'];
131
		$gateway_group['item'] = $pconfig['item'];
132
		$gateway_group['trigger'] = $_POST['trigger'];
133
		$gateway_group['descr'] = $_POST['descr'];
134

    
135
		if (isset($id) && $a_gateway_groups[$id])
136
			$a_gateway_groups[$id] = $gateway_group;
137
		else
138
			$a_gateway_groups[] = $gateway_group;
139
		
140
		mark_subsystem_dirty('staticroutes');
141
		mark_subsystem_dirty('gwgroup.' . $gateway_group['name']);
142
		
143
		write_config();
144
		
145
		header("Location: system_gateway_groups.php");
146
		exit;
147
	}
148
}
149

    
150
$pgtitle = array(gettext("System"),gettext("Gateways"),gettext("Edit gateway group"));
151
$shortcut_section = "gateway-groups";
152

    
153
function build_gateway_protocol_map (&$a_gateways) {
154
	$result = array();
155
	foreach ($a_gateways as $gwname => $gateway) {
156
		$result[$gwname] = $gateway['ipprotocol'];
157
	}
158
	return $result;
159
}
160

    
161
include("head.inc");
162

    
163
?>
164

    
165
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
166

    
167
<?php
168
$gateway_protocol = build_gateway_protocol_map($a_gateways);
169
$gateway_array    = array_keys($a_gateways);
170
$protocol_array   = array_values($gateway_protocol);
171
$protocol_array   = array_values(array_unique($gateway_protocol));
172
?>
173
<script type="text/javascript">
174
//<![CDATA[
175
jQuery(function ($) {
176
	var gateway_protocol = <?= json_encode($gateway_protocol) ?>;
177
	var gateways         = <?= json_encode($gateway_array) ?>;
178
	var protocols        = <?= json_encode($protocol_array) ?>;
179
	if (protocols.length <= 1) { return; }
180

    
181
	var update_gateway_visibilities = function () {
182
		var which_protocol_to_show = undefined;
183
		$.each(gateways, function (i, gateway) {
184
			var $select = $("#" + gateway);
185
			var value = $select.val();
186
			var protocol = gateway_protocol[gateway];
187
			if (value !== '0' /* i.e., an option is selected */) {
188
				if (which_protocol_to_show === undefined) {
189
					which_protocol_to_show = protocol;
190
				}
191
				else if (which_protocol_to_show !== protocol) {
192
					which_protocol_to_show = 'ALL OF THEM'; // this shouldn't happen
193
				}
194
			}
195
		});
196
		if (which_protocol_to_show !== undefined && which_protocol_to_show !== 'ALL OF THEM') {
197
			$.each(gateways, function (i, gateway) {
198
				var protocol = gateway_protocol[gateway];
199
				var $row = $("tr.gateway_row#" + gateway + "_row");
200
				if (protocol === which_protocol_to_show) {
201
					if ($row.is(":hidden")) {
202
						$row.fadeIn('slow');
203
					}
204
				} else {
205
					if (!$row.is(":hidden")) {
206
						$row.fadeOut('slow');
207
					}
208
				}
209
			});
210
		} else {
211
			$("tr.gateway_row").each(function () {
212
				if ($(this).is(":hidden")) {
213
					$(this).fadeIn('slow');
214
				}
215
			});
216
		}
217
	};
218
	$("select.gateway_tier_selector").change(update_gateway_visibilities);
219
	update_gateway_visibilities();
220
});
221
//]]>
222
</script>
223

    
224
<?php include("fbegin.inc"); ?>
225
<?php if ($input_errors) print_input_errors($input_errors); ?>
226
            <form action="system_gateway_groups_edit.php" method="post" name="iform" id="iform">
227
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="system groups edit">
228
		<tr>
229
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit gateway group entry"); ?></td>
230
		</tr>	
231
                <tr>
232
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Group Name"); ?></td>
233
                  <td width="78%" class="vtable"> 
234
                    <input name="name" type="text" class="formfld unknown" id="name" size="20" value="<?=htmlspecialchars($pconfig['name']);?>" />
235
                    <br /> <span class="vexpl"><?=gettext("Group Name"); ?></span></td>
236
                </tr>
237
		<tr>
238
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway Priority"); ?></td>
239
                  <td width="78%" class="vtable">
240
			<table border="0" cellpadding="6" cellspacing="0" summary="gateway priority">
241
			<tr>
242
				<td class="listhdrr">Gateway</td>
243
				<td class="listhdrr">Tier</td>
244
				<td class="listhdrr">Virtual IP</td>
245
				<td class="listhdrr">Description</td>
246
			</tr>
247
		<?php
248
			foreach($a_gateways as $gwname => $gateway) {
249
				if(!empty($pconfig['item'])) {
250
					$af = explode("|", $pconfig['item'][0]);
251
					$family = $a_gateways[$af[0]]['ipprotocol'];
252
					if($gateway['ipprotocol'] != $family)
253
						continue;
254
				}
255
				$interface = $gateway['friendlyiface'];
256
				$selected = array();
257
				foreach((array)$pconfig['item'] as $item) {
258
					$itemsplit = explode("|", $item);
259
					if($itemsplit[0] == $gwname) {
260
						$selected[$itemsplit[1]] = "selected=\"selected\"";
261
						break;
262
					} else {
263
						$selected[0] = "selected=\"selected\"";
264
					}
265
				}
266
				$tr_id = $gwname . "_row";
267
				echo "<tr class='gateway_row' id='{$tr_id}'>\n";
268
				echo "<td class='listlr'>";
269
				echo "<strong>{$gateway['name']} </strong>";
270
				echo "</td><td class='listr'>";
271
				echo "<select name='{$gwname}' class='gateway_tier_selector formfldselect' id='{$gwname}'>\n";
272
				echo "<option value='0' $selected[0] >" . gettext("Never") . "</option>\n";
273
				echo "<option value='1' $selected[1] >" . gettext("Tier 1") . "</option>\n";
274
				echo "<option value='2' $selected[2] >" . gettext("Tier 2") . "</option>\n";
275
				echo "<option value='3' $selected[3] >" . gettext("Tier 3") . "</option>\n";
276
				echo "<option value='4' $selected[4] >" . gettext("Tier 4") . "</option>\n";
277
				echo "<option value='5' $selected[5] >" . gettext("Tier 5") . "</option>\n";
278
				echo "</select>\n";
279
				echo "</td>";
280

    
281
				$selected = array();
282
				foreach((array)$pconfig['item'] as $item) {
283
					$itemsplit = explode("|", $item);
284
					if($itemsplit[0] == $gwname) {
285
						$selected[$itemsplit[2]] = "selected=\"selected\"";
286
						break;
287
					} else {
288
						$selected['address'] = "selected=\"selected\"";
289
					}
290
				}
291
				echo "<td class='listr'>";
292
				echo "<select name='{$gwname}_vip' class='gateway_vip_selector formfldselect' id='{$gwname}_vip'>\n";
293
				echo "<option value='address' {$selected['address']} >" . gettext("Interface Address") . "</option>\n";
294
				foreach($carplist as $vip => $address) {
295
					echo "<!-- $vip - $address - $interface -->\n";
296
					if(!preg_match("/^{$interface}_/i", $vip))
297
						continue;
298
					if(($gateway['ipprotocol'] == "inet") && (!is_ipaddrv4($address)))
299
						continue;
300
					if(($gateway['ipprotocol'] == "inet6") && (!is_ipaddrv6($address)))
301
						continue;
302
					echo "<option value='{$vip}' $selected[$vip] >$vip - $address</option>\n";
303
				}
304
				echo "</select></td>";
305
				echo "<td class='listr'><strong>{$gateway['descr']}&nbsp;</strong>";
306
				echo "</td></tr>";
307
		 	}
308
		?>
309
			</table>
310
			<br /><span class="vexpl">
311
			<strong><?=gettext("Link Priority"); ?></strong> <br />
312
			<?=gettext("The priority selected here defines in what order failover and balancing of links will be done. " .
313
			"Multiple links of the same priority will balance connections until all links in the priority will be exhausted. " .
314
			"If all links in a priority level are exhausted we will use the next available link(s) in the next priority level.") ?>
315
			<br />
316
			<strong><?=gettext("Virtual IP"); ?></strong> <br />
317
			<?=gettext("The virtual IP field selects what (virtual) IP should be used when this group applies to a local Dynamic DNS, IPsec or OpenVPN endpoint") ?>
318
			</span><br />
319
		   </td>
320
                </tr>
321
                <tr>
322
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Trigger Level"); ?></td>
323
                  <td width="78%" class="vtable">
324
			<select name='trigger' class='formfldselect trigger_level_selector' id='trigger'>
325
			<?php
326
				foreach ($categories as $category => $categoryd) {
327
				        echo "<option value=\"$category\"";
328
				        if ($category == $pconfig['trigger']) echo " selected=\"selected\"";
329
					echo ">" . htmlspecialchars($categoryd) . "</option>\n";
330
				}
331
			?>
332
			</select>
333
                    <br /> <span class="vexpl"><?=gettext("When to trigger exclusion of a member"); ?></span></td>
334
                </tr>
335
		<tr>
336
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
337
                  <td width="78%" class="vtable"> 
338
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
339
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed)."); ?></span></td>
340
                </tr>
341
                <tr>
342
                  <td width="22%" valign="top">&nbsp;</td>
343
                  <td width="78%"> 
344
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> <input type="button" value="<?=gettext("Cancel"); ?>" class="formbtn"  onclick="history.back()" />
345
                    <?php if (isset($id) && $a_gateway_groups[$id]): ?>
346
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
347
                    <?php endif; ?>
348
                  </td>
349
                </tr>
350
              </table>
351
</form>
352
<?php include("fend.inc"); ?>
353
</body>
354
</html>
(220-220/255)