Project

General

Profile

Download (15.5 KB) Statistics
| Branch: | Tag: | Revision:
1 d173230c Seth Mos
<?php
2
/*
3 c5d81585 Renato Botelho
 * system_gateways.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2019 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * Copyright (c) 2010 Seth Mos <seth.mos@dds.nl>
10
 * All rights reserved.
11
 *
12 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15 c5d81585 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
17 c5d81585 Renato Botelho
 *
18 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23 6ff05704 Stephen Beaver
 */
24 d173230c Seth Mos
25 6b07c15a Matthew Grooms
##|+PRIV
26
##|*IDENT=page-system-gateways
27 5230f468 jim-p
##|*NAME=System: Gateways
28 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'System: Gateways' page.
29
##|*MATCH=system_gateways.php*
30
##|-PRIV
31
32 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
33 7a927e67 Scott Ullrich
require_once("functions.inc");
34
require_once("filter.inc");
35
require_once("shaper.inc");
36 43a9b03d PiBa-NL
require_once("gwlb.inc");
37
38
$simplefields = array('defaultgw4', 'defaultgw6');
39 d173230c Seth Mos
40 c6c398c6 jim-p
init_config_arr(array('gateways', 'gateway_item'));
41 616e1956 Seth Mos
$a_gateway_item = &$config['gateways']['gateway_item'];
42
43 4611e283 Steve Beaver
$pconfig = $_REQUEST;
44 d173230c Seth Mos
45 e311cb79 PiBa-NL
if ($_POST['order-store']) {
46
	// Include the rules of this (the selected) interface.
47
	// If a rule is not in POST[rule], it has been deleted by the user
48
	$a_gateway_item_new = array();
49
	//print "<pre>";
50
	foreach ($_POST['row'] as $id) {
51
		//print " $id";
52
		$a_gateway_item_new[] = $a_gateway_item[$id];
53
	}
54
	//print_r($a_gateway_item);
55
	//print_r($a_gateway_item_new);
56
	//print "</pre>";
57
	$a_gateway_item = $a_gateway_item_new;
58
	//mark_subsystem_dirty('staticroutes');
59
	write_config("System - Gateways: save default gateway");
60
} else if ($_POST['save']) {
61 43a9b03d PiBa-NL
	unset($input_errors);
62
	$pconfig = $_POST;
63
	foreach($simplefields as $field) {
64
		$config['gateways'][$field] = $pconfig[$field];
65
	}
66
	mark_subsystem_dirty('staticroutes');
67
	write_config("System - Gateways: save default gateway");
68
}
69
70 4611e283 Steve Beaver
if ($_POST['apply']) {
71 d173230c Seth Mos
72 4611e283 Steve Beaver
	$retval = 0;
73 d173230c Seth Mos
74 4611e283 Steve Beaver
	$retval |= system_routing_configure();
75
	$retval |= system_resolvconf_generate();
76
	$retval |= filter_configure();
77
	/* reconfigure our gateway monitor */
78
	setup_gateways_monitor();
79
	/* Dynamic DNS on gw groups may have changed */
80
	send_event("service reload dyndnsall");
81 d173230c Seth Mos
82 4611e283 Steve Beaver
	if ($retval == 0) {
83
		clear_subsystem_dirty('staticroutes');
84 d173230c Seth Mos
	}
85
}
86
87 3cd21b4e PiBa-NL
$a_gateways = return_gateways_array(true, false, true, true);
88 4611e283 Steve Beaver
89 028ff8f8 Phil Davis
function can_delete_disable_gateway_item($id, $disable = false) {
90 e97df865 Renato Botelho
	global $config, $input_errors, $a_gateways;
91 d251a8d4 Renato Botelho
92 e0c7b2fe Phil Davis
	if (!isset($a_gateways[$id])) {
93 e97df865 Renato Botelho
		return false;
94 e0c7b2fe Phil Davis
	}
95 e97df865 Renato Botelho
96
	if (is_array($config['gateways']['gateway_group'])) {
97
		foreach ($config['gateways']['gateway_group'] as $group) {
98
			foreach ($group['item'] as $item) {
99
				$items = explode("|", $item);
100
				if ($items[0] == $a_gateways[$id]['name']) {
101 205178aa Phil Davis
					if (!$disable) {
102 762faef5 Phil Davis
						$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be deleted because it is in use on Gateway Group "%2$s"'), $a_gateways[$id]['name'], $group['name']);
103 205178aa Phil Davis
					} else {
104 762faef5 Phil Davis
						$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be disabled because it is in use on Gateway Group "%2$s"'), $a_gateways[$id]['name'], $group['name']);
105 028ff8f8 Phil Davis
					}
106 f78302e8 Ermal
				}
107
			}
108
		}
109 e97df865 Renato Botelho
	}
110
111
	if (is_array($config['staticroutes']['route'])) {
112
		foreach ($config['staticroutes']['route'] as $route) {
113
			if ($route['gateway'] == $a_gateways[$id]['name']) {
114 205178aa Phil Davis
				if (!$disable) {
115 028ff8f8 Phil Davis
					// The user wants to delete this gateway, but there is a static route (enabled or disabled) that refers to the gateway.
116 762faef5 Phil Davis
					$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be deleted because it is in use on Static Route "%2$s"'), $a_gateways[$id]['name'], $route['network']);
117 205178aa Phil Davis
				} else if (!isset($route['disabled'])) {
118
					// The user wants to disable this gateway.
119
					// But there is a static route that uses this gateway and is enabled (not disabled).
120 762faef5 Phil Davis
					$input_errors[] = sprintf(gettext('Gateway "%1$s" cannot be disabled because it is in use on Static Route "%2$s"'), $a_gateways[$id]['name'], $route['network']);
121 028ff8f8 Phil Davis
				}
122 f78302e8 Ermal
			}
123
		}
124 e97df865 Renato Botelho
	}
125
126 e0c7b2fe Phil Davis
	if (isset($input_errors)) {
127 e97df865 Renato Botelho
		return false;
128 e0c7b2fe Phil Davis
	}
129 e97df865 Renato Botelho
130
	return true;
131
}
132
133
function delete_gateway_item($id) {
134 dde20226 Renato Botelho
	global $config, $a_gateways;
135
136 e0c7b2fe Phil Davis
	if (!isset($a_gateways[$id])) {
137 e97df865 Renato Botelho
		return;
138 e0c7b2fe Phil Davis
	}
139 32a9eb18 Ermal
140 1be1b87b jim-p
	/* If the removed gateway was the default route, remove the default route */
141
	if (!empty($a_gateways[$id]) && is_ipaddr($a_gateways[$id]['gateway']) &&
142
	    !isset($a_gateways[$id]['disabled']) &&
143 43a9b03d PiBa-NL
	    isset($a_gateways[$id]['isdefaultgw'])) {
144 1be1b87b jim-p
		$inet = (!is_ipaddrv4($a_gateways[$id]['gateway']) ? '-inet6' : '-inet');
145 43a9b03d PiBa-NL
		file_put_contents("/dev/console", "\n[".getmypid()."] DEL_GW, route= delete {$inet} default");
146 5a24d994 Viktor Gurov
		mwexec("/sbin/route delete {$inet} default " . escapeshellarg($a_gateways[$id]['gateway']));
147 1be1b87b jim-p
	}
148
149 e75f0e7d PiBa-NL
	/* NOTE: Cleanup static routes for the interface route if any */
150 d61309a0 Phil Davis
	if (!empty($a_gateways[$id]) && is_ipaddr($a_gateways[$id]['gateway']) &&
151
	    $gateway['gateway'] != $a_gateways[$id]['gateway'] &&
152
	    isset($a_gateways[$id]["nonlocalgateway"])) {
153 e75f0e7d PiBa-NL
		$realif = get_real_interface($a_gateways[$id]['interface']);
154
		$inet = (!is_ipaddrv4($a_gateways[$id]['gateway']) ? "-inet6" : "-inet");
155 988e6c59 Viktor Gurov
		$rgateway = $a_gateways[$id]['gateway'];
156 43a9b03d PiBa-NL
		file_put_contents("/dev/console", "\n[".getmypid()."] DEL_GW, route= $inet " . escapeshellarg($a_gateways[$id]['gateway']) . " -iface " . escapeshellarg($realif));
157 988e6c59 Viktor Gurov
		$cmd = "/sbin/route delete $inet " . escapeshellarg($a_gateways[$id]['gateway']) . " -iface " . escapeshellarg($realif) . " " . escapeshellarg($rgateway);
158 e75f0e7d PiBa-NL
		mwexec($cmd);
159
	}
160 e97df865 Renato Botelho
	/* NOTE: Cleanup static routes for the monitor ip if any */
161
	if (!empty($a_gateways[$id]['monitor']) &&
162 d61309a0 Phil Davis
	    $a_gateways[$id]['monitor'] != "dynamic" &&
163
	    is_ipaddr($a_gateways[$id]['monitor']) &&
164
	    $a_gateways[$id]['gateway'] != $a_gateways[$id]['monitor']) {
165 988e6c59 Viktor Gurov
		$rgateway = $a_gateways[$id]['gateway'];
166 e0c7b2fe Phil Davis
		if (is_ipaddrv4($a_gateways[$id]['monitor'])) {
167 988e6c59 Viktor Gurov
			mwexec("/sbin/route delete " . escapeshellarg($a_gateways[$id]['monitor']) . " " . escapeshellarg($rgateway));
168 e0c7b2fe Phil Davis
		} else {
169 988e6c59 Viktor Gurov
			mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateways[$id]['monitor']) . " " . escapeshellarg($rgateway)));
170 e0c7b2fe Phil Davis
		}
171 e97df865 Renato Botelho
	}
172
173 e0c7b2fe Phil Davis
	if ($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway'] == $a_gateways[$id]['name']) {
174 e97df865 Renato Botelho
		unset($config['interfaces'][$a_gateways[$id]['friendlyiface']]['gateway']);
175 e0c7b2fe Phil Davis
	}
176 e97df865 Renato Botelho
	unset($config['gateways']['gateway_item'][$a_gateways[$id]['attribute']]);
177
}
178
179
unset($input_errors);
180 4611e283 Steve Beaver
if ($_REQUEST['act'] == "del") {
181
	if (can_delete_disable_gateway_item($_REQUEST['id'])) {
182
		$realid = $a_gateways[$_REQUEST['id']]['attribute'];
183
		delete_gateway_item($_REQUEST['id']);
184 e97df865 Renato Botelho
		write_config("Gateways: removed gateway {$realid}");
185
		mark_subsystem_dirty('staticroutes');
186
		header("Location: system_gateways.php");
187
		exit;
188
	}
189
}
190
191 4611e283 Steve Beaver
if (isset($_REQUEST['del_x'])) {
192 e97df865 Renato Botelho
	/* delete selected items */
193 4611e283 Steve Beaver
	if (is_array($_REQUEST['rule']) && count($_REQUEST['rule'])) {
194
		foreach ($_REQUEST['rule'] as $rulei) {
195 028ff8f8 Phil Davis
			if (!can_delete_disable_gateway_item($rulei)) {
196 e97df865 Renato Botelho
				break;
197 e0c7b2fe Phil Davis
			}
198
		}
199 e97df865 Renato Botelho
200
		if (!isset($input_errors)) {
201
			$items_deleted = "";
202 4611e283 Steve Beaver
			foreach ($_REQUEST['rule'] as $rulei) {
203 e97df865 Renato Botelho
				delete_gateway_item($rulei);
204
				$items_deleted .= "{$rulei} ";
205
			}
206
			if (!empty($items_deleted)) {
207 762faef5 Phil Davis
				write_config(sprintf(gettext("Gateways: removed gateways %s", $items_deleted)));
208 e97df865 Renato Botelho
				mark_subsystem_dirty('staticroutes');
209
			}
210 f78302e8 Ermal
			header("Location: system_gateways.php");
211
			exit;
212
		}
213 d173230c Seth Mos
	}
214
215 4611e283 Steve Beaver
} else if ($_REQUEST['act'] == "toggle" && $a_gateways[$_REQUEST['id']]) {
216
	$realid = $a_gateways[$_REQUEST['id']]['attribute'];
217 028ff8f8 Phil Davis
	$disable_gw = !isset($a_gateway_item[$realid]['disabled']);
218
	if ($disable_gw) {
219
		// The user wants to disable the gateway, so check if that is OK.
220 4611e283 Steve Beaver
		$ok_to_toggle = can_delete_disable_gateway_item($_REQUEST['id'], $disable_gw);
221 e0c7b2fe Phil Davis
	} else {
222 028ff8f8 Phil Davis
		// The user wants to enable the gateway. That is always OK.
223
		$ok_to_toggle = true;
224 e0c7b2fe Phil Davis
	}
225 028ff8f8 Phil Davis
	if ($ok_to_toggle) {
226 43a9b03d PiBa-NL
		gateway_set_enabled($a_gateway_item[$realid]['name'], !$disable_gw);
227 e97df865 Renato Botelho
228 028ff8f8 Phil Davis
		if (write_config("Gateways: enable/disable")) {
229
			mark_subsystem_dirty('staticroutes');
230
		}
231 e97df865 Renato Botelho
232 028ff8f8 Phil Davis
		header("Location: system_gateways.php");
233
		exit;
234
	}
235 e97df865 Renato Botelho
}
236 124aee67 Chris Buechler
237 43a9b03d PiBa-NL
foreach($simplefields as $field) {
238
	$pconfig[$field] = $config['gateways'][$field];
239
}
240
241
function gateway_displaygwtiername($gwname) {
242
	global $config;
243
	$gw = lookup_gateway_or_group_by_name($gwname);
244
	if ($config['gateways']['defaultgw4'] == $gwname || $config['gateways']['defaultgw6'] == $gwname) {
245
		$result = "Default";
246
	} else {
247
		if ($gw['ipprotocol'] == 'inet') {
248
			$defgw = lookup_gateway_or_group_by_name($config['gateways']['defaultgw4']);
249
		} else {
250
			$defgw = lookup_gateway_or_group_by_name($config['gateways']['defaultgw6']);
251
		}
252
		if ($defgw['type'] == "gatewaygroup") {
253
			$detail = gateway_is_gwgroup_member($gwname, true);
254
			foreach($detail as $gwitem) {
255
				if ($gwitem['name'] == $defgw['name']) {
256
					if (isset($gwitem['tier'])) {
257
						$result = "Tier " . $gwitem['tier'];
258
						break;
259
					}
260
				}
261
			}
262
		}
263
	}
264
	if (!empty($result)) {
265 e311cb79 PiBa-NL
		if ($gw['ipprotocol'] == "inet") {
266
			$result .= " (IPv4)";
267
		} elseif ($gw['ipprotocol'] == "inet6") {
268
			$result .= " (IPv6)";
269
		}
270 43a9b03d PiBa-NL
	}
271
	return $result;
272
}
273
274 d036bc07 Stephen Beaver
$pgtitle = array(gettext("System"), gettext("Routing"), gettext("Gateways"));
275 edcd7535 Phil Davis
$pglinks = array("", "@self", "@self");
276 b32dd0a6 jim-p
$shortcut_section = "gateways";
277 02ca24c9 jim-p
278 d173230c Seth Mos
include("head.inc");
279
280 d61309a0 Phil Davis
if ($input_errors) {
281 c3c692a9 Sjon Hortensius
	print_input_errors($input_errors);
282 d61309a0 Phil Davis
}
283 44c42356 Phil Davis
284
if ($_POST['apply']) {
285
	print_apply_result_box($retval);
286 d61309a0 Phil Davis
}
287 f74457df Stephen Beaver
288 d61309a0 Phil Davis
if (is_subsystem_dirty('staticroutes')) {
289 7fdca5ff NOYB
	print_apply_box(gettext("The gateway configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
290 d61309a0 Phil Davis
}
291 c3c692a9 Sjon Hortensius
292
$tab_array = array();
293
$tab_array[0] = array(gettext("Gateways"), true, "system_gateways.php");
294 80b4d0c5 heper
$tab_array[1] = array(gettext("Static Routes"), false, "system_routes.php");
295
$tab_array[2] = array(gettext("Gateway Groups"), false, "system_gateway_groups.php");
296 c3c692a9 Sjon Hortensius
display_top_tabs($tab_array);
297 d173230c Seth Mos
298 d251a8d4 Renato Botelho
?>
299 e311cb79 PiBa-NL
<form method="post">
300 060ed238 Stephen Beaver
<div class="panel panel-default">
301
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Gateways')?></h2></div>
302
	<div class="panel-body">
303
		<div class="table-responsive">
304 e311cb79 PiBa-NL
			<table id="gateways" class="table table-striped table-hover table-condensed table-rowdblclickedit">
305 060ed238 Stephen Beaver
				<thead>
306
					<tr>
307 e311cb79 PiBa-NL
						<th></th>
308 060ed238 Stephen Beaver
						<th></th>
309
						<th><?=gettext("Name")?></th>
310 43a9b03d PiBa-NL
						<th><?=gettext("Default")?></th>
311 060ed238 Stephen Beaver
						<th><?=gettext("Interface")?></th>
312
						<th><?=gettext("Gateway")?></th>
313
						<th><?=gettext("Monitor IP")?></th>
314
						<th><?=gettext("Description")?></th>
315
						<th><?=gettext("Actions")?></th>
316
					</tr>
317
				</thead>
318
				<tbody>
319 e97df865 Renato Botelho
<?php
320 c3c692a9 Sjon Hortensius
foreach ($a_gateways as $i => $gateway):
321 d61309a0 Phil Davis
	if (isset($gateway['inactive'])) {
322 1b7379f9 Jared Dillard
		$icon = 'fa-times-circle-o';
323 d61309a0 Phil Davis
	} elseif (isset($gateway['disabled'])) {
324 1b7379f9 Jared Dillard
		$icon = 'fa-ban';
325 d61309a0 Phil Davis
	} else {
326 1b7379f9 Jared Dillard
		$icon = 'fa-check-circle-o';
327 d61309a0 Phil Davis
	}
328 c3c692a9 Sjon Hortensius
329 d61309a0 Phil Davis
	if (isset($gateway['inactive'])) {
330 c3c692a9 Sjon Hortensius
		$title = gettext("This gateway is inactive because interface is missing");
331 d61309a0 Phil Davis
	} else {
332 c3c692a9 Sjon Hortensius
		$title = '';
333 d61309a0 Phil Davis
	}
334 e311cb79 PiBa-NL
	$id = $gateway['attribute'];
335 e97df865 Renato Botelho
?>
336 e311cb79 PiBa-NL
				<tr<?=($icon != 'fa-check-circle-o')? ' class="disabled"' : ''?> onClick="fr_toggle(<?=$id;?>)" id="fr<?=$id;?>">
337
					<td style="white-space: nowrap;">
338
						<?php 
339
						if (is_numeric($id)) :?>
340
							<input type='checkbox' id='frc<?=$id?>' onClick='fr_toggle(<?=$id?>)' name='row[]' value='<?=$id?>'/>
341
							<a class='fa fa-anchor' id='Xmove_<?=$id?>' title='"<?=gettext("Move checked entries to here")?>"'></a>
342
						<?php endif; ?>
343
					</td>
344 060ed238 Stephen Beaver
					<td title="<?=$title?>"><i class="fa <?=$icon?>"></i></td>
345
					<td>
346
						<?=htmlspecialchars($gateway['name'])?>
347 e97df865 Renato Botelho
<?php
348 43a9b03d PiBa-NL
						if (isset($gateway['isdefaultgw'])) {
349 3cd21b4e PiBa-NL
							echo ' <i class="fa fa-globe"></i>';
350 43a9b03d PiBa-NL
						}
351 e97df865 Renato Botelho
?>
352 060ed238 Stephen Beaver
						</td>
353 43a9b03d PiBa-NL
						<td>
354
							<?=gateway_displaygwtiername($gateway['name'])?>
355
						</td>
356 060ed238 Stephen Beaver
						<td>
357
							<?=htmlspecialchars(convert_friendly_interface_to_friendly_descr($gateway['friendlyiface']))?>
358
						</td>
359
						<td>
360
							<?=htmlspecialchars($gateway['gateway'])?>
361
						</td>
362
						<td>
363
							<?=htmlspecialchars($gateway['monitor'])?>
364
						</td>
365
						<td>
366
							<?=htmlspecialchars($gateway['descr'])?>
367
						</td>
368 e311cb79 PiBa-NL
						<td style="white-space: nowrap;">
369 4611e283 Steve Beaver
							<a href="system_gateways_edit.php?id=<?=$i?>" class="fa fa-pencil" title="<?=gettext('Edit gateway');?>"></a>
370
							<a href="system_gateways_edit.php?dup=<?=$i?>" class="fa fa-clone" title="<?=gettext('Copy gateway')?>"></a>
371 f74457df Stephen Beaver
372 fa172bc5 NewEraCracker
<?php if (is_numeric($gateway['attribute'])): ?>
373 1629e8ea heper
	<?php if (isset($gateway['disabled'])) {
374 f74457df Stephen Beaver
	?>
375 a04f6658 Steve Beaver
							<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-check-square-o" title="<?=gettext('Enable gateway')?>" usepost></a>
376 1629e8ea heper
	<?php } else {
377
	?>
378 a04f6658 Steve Beaver
							<a href="?act=toggle&amp;id=<?=$i?>" class="fa fa-ban" title="<?=gettext('Disable gateway')?>" usepost></a>
379 1629e8ea heper
	<?php }
380 f74457df Stephen Beaver
	?>
381 a04f6658 Steve Beaver
							<a href="system_gateways.php?act=del&amp;id=<?=$i?>" class="fa fa-trash" title="<?=gettext('Delete gateway')?>" usepost></a>
382 f74457df Stephen Beaver
383 fa172bc5 NewEraCracker
<?php endif; ?>
384 060ed238 Stephen Beaver
						</td>
385
					</tr>
386 fa172bc5 NewEraCracker
<?php endforeach; ?>
387 060ed238 Stephen Beaver
				</tbody>
388
			</table>
389
		</div>
390
	</div>
391
</div>
392 c3c692a9 Sjon Hortensius
393 c10cb196 Stephen Beaver
<nav class="action-buttons">
394 e311cb79 PiBa-NL
	<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
395
		<i class="fa fa-save icon-embed-btn"></i>
396
		<?=gettext("Save")?>
397
	</button>
398 4611e283 Steve Beaver
	<a href="system_gateways_edit.php" role="button" class="btn btn-success">
399 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
400 f74457df Stephen Beaver
		<?=gettext("Add");?>
401 c3c692a9 Sjon Hortensius
	</a>
402
</nav>
403 e311cb79 PiBa-NL
</form>
404 e97df865 Renato Botelho
<?php
405 c3c692a9 Sjon Hortensius
406 43a9b03d PiBa-NL
$form = new Form;
407
$section = new Form_Section('Default gateway');
408
409
$items4 = array();
410
$items6 = array();
411 e311cb79 PiBa-NL
$items4[''] = "Automatic";
412
$items6[''] = "Automatic";
413 43a9b03d PiBa-NL
foreach($a_gateways as $gw) {
414
	$gwn = $gw['name'];
415
	if ($gw['ipprotocol'] == "inet6") {
416
		$items6[$gwn] = $gwn;
417
	} else {
418
		$items4[$gwn] = $gwn;
419
	}
420
}
421
$groups = return_gateway_groups_array();
422
foreach ($groups as $key => $group) {
423
	$gwn = $group['descr'];
424
	if ($group['ipprotocol'] == "inet6") {
425
		$items6[$key] = "$key ($gwn)";
426
	} else {
427
		$items4[$key] = "$key ($gwn)";
428
	}
429
}
430 e311cb79 PiBa-NL
$items4['-'] = "None";
431
$items6['-'] = "None";
432 43a9b03d PiBa-NL
433
$section->addInput(new Form_Select(
434
	'defaultgw4',
435
	'Default gateway IPv4',
436
	$pconfig['defaultgw4'],
437
	$items4
438
))->setHelp('Select the gateway or gatewaygroup to use as the default gateway.');
439
440
$section->addInput(new Form_Select(
441
	'defaultgw6',
442
	'Default gateway IPv6',
443
	$pconfig['defaultgw6'],
444
	$items6
445
))->setHelp('Select the gateway or gatewaygroup to use as the default gateway.');
446
447
$form->add($section);
448
print $form;
449
450 e311cb79 PiBa-NL
?>
451 3cd21b4e PiBa-NL
<div class="infoblock">
452
<?php
453
print_info_box(
454
	sprintf(gettext('%1$s%2$s%3$s is the current default route as present in the current routing table of the operating system'), '<strong>', '<i class="fa fa-globe"></i>', '</strong>')
455
	);
456
?>
457
</div>
458 e311cb79 PiBa-NL
<script type="text/javascript">
459
//<![CDATA[
460
events.push(function() {
461
	$('#order-store').click(function () {
462
		// Check all of the rule checkboxes so that their values are posted
463
	   $('[id^=frc]').prop('checked', true);
464
	});
465
466
	$('[id^=Xmove_]').click(function (event) {
467
		// anchor click to move gateways around..
468
		moveRowUpAboveAnchor(event.target.id.slice(6),"gateways");
469
		return false;
470
	});
471
	$('[id^=Xmove_]').css('cursor', 'pointer');
472
});
473
	function moveRowUpAboveAnchor(rowId, tableId) {
474
		var table = $('#'+tableId);
475
		var viewcheckboxes = $('[id^=frc]input:checked', table);
476
		var rowview = $("#fr" + rowId, table);
477
		var moveabove = rowview;
478
		//var parent = moveabove[0].parentNode;
479
		
480
		viewcheckboxes.each(function( index ) {
481
			var moveid = this.value;
482
			console.log( index + ": " + this.id );
483
484
			var prevrowview = $("#fr" + moveid, table);
485
			prevrowview.insertBefore(moveabove);
486
			$('#order-store').removeAttr('disabled');
487
		});
488
	}
489
//]]>
490
</script>
491
492
<?php include("foot.inc");