Project

General

Profile

Download (122 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces.php
5
	Copyright (C) 2004-2008 Scott Ullrich
6
	Copyright (C) 2006 Daniel S. Haischt.
7
	Copyright (C) 2008-2010 Ermal Lu?i
8
	All rights reserved.
9

    
10
	originally part of m0n0wall (http://m0n0.ch/wall)
11
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
	All rights reserved.
13

    
14
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16

    
17
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19

    
20
	2. Redistributions in binary form must reproduce the above copyright
21
	   notice, this list of conditions and the following disclaimer in the
22
	   documentation and/or other materials provided with the distribution.
23

    
24
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
	POSSIBILITY OF SUCH DAMAGE.
34
*/
35
/*
36
	pfSense_BUILDER_BINARIES:	/usr/sbin/arp
37
	pfSense_MODULE:	interfaces
38
*/
39

    
40
##|+PRIV
41
##|*IDENT=page-interfaces
42
##|*NAME=Interfaces: WAN page
43
##|*DESCR=Allow access to the 'Interfaces' page.
44
##|*MATCH=interfaces.php*
45
##|-PRIV
46

    
47
require_once("guiconfig.inc");
48
require_once("ipsec.inc");
49
require_once("functions.inc");
50
require_once("captiveportal.inc");
51
require_once("filter.inc");
52
require_once("shaper.inc");
53
require_once("rrd.inc");
54
require_once("vpn.inc");
55
require_once("xmlparse_attr.inc");
56

    
57
// Get configured interface list
58
$ifdescrs = get_configured_interface_with_descr(false, true);
59

    
60
$if = "wan";
61
if ($_REQUEST['if'])
62
	$if = $_REQUEST['if'];
63

    
64
if (empty($ifdescrs[$if])) {
65
	Header("Location: interfaces.php");
66
	exit;
67
}
68

    
69
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
70
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
71
define("CRON_DAILY_PATTERN", "0 0 * * *");
72
define("CRON_HOURLY_PATTERN", "0 * * * *");
73

    
74
if (!is_array($config['ppps']['ppp']))
75
	$config['ppps']['ppp'] = array();
76

    
77
$a_ppps = &$config['ppps']['ppp'];
78

    
79
function remove_bad_chars($string) {
80
	return preg_replace('/[^a-z_0-9]/i','',$string);
81
}
82

    
83
if (!is_array($config['gateways']['gateway_item']))
84
	$config['gateways']['gateway_item'] = array();
85
$a_gateways = &$config['gateways']['gateway_item'];
86

    
87
$wancfg = &$config['interfaces'][$if];
88
$old_wancfg = $wancfg;
89
// Populate page descr if it does not exist.
90
if ($if == "wan" && !$wancfg['descr'])
91
	$wancfg['descr'] = "WAN";
92
else if ($if == "lan" && !$wancfg['descr'])
93
	$wancfg['descr'] = "LAN";
94

    
95

    
96
foreach ($a_ppps as $pppid => $ppp) {
97
	if ($wancfg['if'] == $ppp['if'])
98
		break;
99
}
100

    
101
if ($wancfg['if'] == $a_ppps[$pppid]['if']) {
102
	$pconfig['pppid'] = $pppid;
103
	$pconfig['ptpid'] = $a_ppps[$pppid]['ptpid'];
104
	$pconfig['port'] = $a_ppps[$pppid]['ports'];
105
	if ($a_ppps[$pppid]['type'] == "ppp"){
106
		$pconfig['username'] = $a_ppps[$pppid]['username'];
107
		$pconfig['password'] = base64_decode($a_ppps[$pppid]['password']);
108

    
109
		$pconfig['phone'] = $a_ppps[$pppid]['phone'];
110
		$pconfig['apn'] = $a_ppps[$pppid]['apn'];
111
	}
112

    
113
	if ($a_ppps[$pppid]['type'] == "pppoe"){
114
		$pconfig['pppoe_username'] = $a_ppps[$pppid]['username'];
115
		$pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']);
116
		$pconfig['provider'] = $a_ppps[$pppid]['provider'];
117
		$pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
118
		$pconfig['pppoe_idletimeout'] = $a_ppps[$pppid]['idletimeout'];
119

    
120
		/* ================================================ */
121
		/* = force a connection reset at a specific time? = */
122
		/* ================================================ */
123

    
124
		if (isset($a_ppps[$pppid]['pppoe-reset-type'])) {
125
			$pconfig['pppoe-reset-type'] = $a_ppps[$pppid]['pppoe-reset-type'];
126
			$itemhash = getMPDCRONSettings($a_ppps[$pppid]['if']);
127
			$cronitem = $itemhash['ITEM'];
128
			if (isset($cronitem)) {
129
				$resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}";
130
			} else {
131
				$resetTime = NULL;
132
			}
133
			log_error("ResetTime:".$resetTime);
134
			if ($a_ppps[$pppid]['pppoe-reset-type'] == "custom") {
135
				$resetTime_a = explode(" ", $resetTime);
136
				$pconfig['pppoe_pr_custom'] = true;
137
				$pconfig['pppoe_resetminute'] = $resetTime_a[0];
138
				$pconfig['pppoe_resethour'] = $resetTime_a[1];
139
				/*  just initialize $pconfig['pppoe_resetdate'] if the
140
				 *  coresponding item contains appropriate numeric values.
141
				 */
142
				if ($resetTime_a[2] <> "*" && $resetTime_a[3] <> "*")
143
					$pconfig['pppoe_resetdate'] = "{$resetTime_a[3]}/{$resetTime_a[2]}/" . date("Y");
144
			} else if ($a_ppps[$pppid]['pppoe-reset-type'] == "preset") {
145
				$pconfig['pppoe_pr_preset'] = true;
146
				switch ($resetTime) {
147
					case CRON_MONTHLY_PATTERN:
148
						$pconfig['pppoe_monthly'] = true;
149
						break;
150
					case CRON_WEEKLY_PATTERN:
151
						$pconfig['pppoe_weekly'] = true;
152
						break;
153
					case CRON_DAILY_PATTERN:
154
						$pconfig['pppoe_daily'] = true;
155
						break;
156
					case CRON_HOURLY_PATTERN:
157
						$pconfig['pppoe_hourly'] = true;
158
						break;
159
				}
160
			}
161
		}// End force pppoe reset at specific time
162
	}// End if type == pppoe
163
	else if ($a_ppps[$pppid]['type'] == "pptp" || $a_ppps[$pppid]['type'] == "l2tp"){
164
		$pconfig['pptp_username'] = $a_ppps[$pppid]['username'];
165
		$pconfig['pptp_password'] = base64_decode($a_ppps[$pppid]['password']);
166
		$pconfig['pptp_local'] = explode(",",$a_ppps[$pppid]['localip']);
167
		$pconfig['pptp_subnet'] = explode(",",$a_ppps[$pppid]['subnet']);
168
		$pconfig['pptp_remote'] = explode(",",$a_ppps[$pppid]['gateway']);
169
		$pconfig['pptp_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
170
		$pconfig['pptp_idletimeout'] = $a_ppps[$pppid]['timeout'];
171
	}
172
} else {
173
	$pconfig['ptpid'] = interfaces_ptpid_next();
174
	$pppid = count($a_ppps);
175
}
176
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
177
$pconfig['alias-address'] = $wancfg['alias-address'];
178
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
179
$pconfig['dhcp_plus'] = isset($wancfg['dhcp_plus']);
180
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
181
$pconfig['enable'] = isset($wancfg['enable']);
182

    
183
if (is_array($config['aliases']['alias'])) {
184
	foreach($config['aliases']['alias'] as $alias) {
185
		if($alias['name'] == $wancfg['descr']) {
186
			$input_errors[] = sprintf(gettext("Sorry, an alias with the name %s already exists."),$wancfg['descr']);
187
		}
188
	}
189
}
190

    
191
switch($wancfg['ipaddr']) {
192
	case "dhcp":
193
		$pconfig['type'] = "dhcp";
194
		break;
195
	case "carpdev-dhcp":
196
		$pconfig['ipaddr'] = "";
197
		break;
198
	case "pppoe":
199
	case "pptp":
200
	case "l2tp":
201
	case "ppp":
202
		$pconfig['type'] = $wancfg['ipaddr'];
203
		break;
204
	default:
205
		if(is_ipaddr($wancfg['ipaddr'])) {
206
			$pconfig['type'] = "staticv4";
207
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
208
			$pconfig['subnet'] = $wancfg['subnet'];
209
			$pconfig['gateway'] = $wancfg['gateway'];
210
		} else
211
			$pconfig['type'] = "none";
212
		break;
213
}
214

    
215
switch($wancfg['ipaddrv6']) {
216
	case "dhcp6":
217
		$pconfig['dhcp6-duid'] = $wancfg['dhcp6-duid'];
218
		if($wancfg['dhcp6-ia-pd-len'] == "")
219
			$wancfg['dhcp6-ia-pd-len'] = "none";
220
		$pconfig['dhcp6-ia-pd-len'] = $wancfg['dhcp6-ia-pd-len'];
221
		$pconfig['type6'] = "dhcp6";
222
		break;
223
	case "6rd":
224
		$pconfig['prefix-6rd'] = $wancfg['prefix-6rd'];
225
		if($wancfg['prefix-6rd-v4plen'] == "")
226
			$wancfg['prefix-6rd-v4plen'] = "0";
227
		$pconfig['prefix-6rd-v4plen'] = $wancfg['prefix-6rd-v4plen'];
228
		$pconfig['type6'] = "6rd";
229
		$pconfig['gateway-6rd'] = $wancfg['gateway-6rd'];
230
		break;
231
	default:
232
		if(is_ipaddr($wancfg['ipaddrv6'])) {
233
			$pconfig['type6'] = "staticv6";
234
			$pconfig['ipaddrv6'] = $wancfg['ipaddrv6'];
235
			$pconfig['subnetv6'] = $wancfg['subnetv6'];
236
			$pconfig['gatewayv6'] = $wancfg['gatewayv6'];
237
			$pconfig['dhcp6-pd-sla-id'] = $wancfg['dhcp6-pd-sla-id'];
238
			$pconfig['prefix-6rd-id'] = $wancfg['prefix-6rd-id'];
239
		} else
240
			$pconfig['type6'] = "none";
241
		break;
242
}
243

    
244
// print_r($pconfig);
245

    
246
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
247
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
248
$pconfig['spoofmac'] = $wancfg['spoofmac'];
249
$pconfig['mtu'] = $wancfg['mtu'];
250
$pconfig['mss'] = $wancfg['mss'];
251

    
252
/* Wireless interface? */
253
if (isset($wancfg['wireless'])) {
254
	/* Sync first to be sure it displays the actual settings that will be used */
255
	interface_sync_wireless_clones($wancfg, false);
256
	/* Get wireless modes */
257
	$wlanif = get_real_interface($if);
258
	if (!does_interface_exist($wlanif))
259
		interface_wireless_clone($wlanif, $wancfg);
260
	$wlanbaseif = interface_get_wireless_base($wancfg['if']);
261
	preg_match("/^(.*?)([0-9]*)$/", $wlanbaseif, $wlanbaseif_split);
262
	$wl_modes = get_wireless_modes($if);
263
	$wl_chaninfo = get_wireless_channel_info($if);
264
	$wl_sysctl_prefix = 'dev.' . $wlanbaseif_split[1] . '.' . $wlanbaseif_split[2];
265
	$wl_sysctl = get_sysctl(array("{$wl_sysctl_prefix}.diversity", "{$wl_sysctl_prefix}.txantenna", "{$wl_sysctl_prefix}.rxantenna",
266
	                              "{$wl_sysctl_prefix}.slottime", "{$wl_sysctl_prefix}.acktimeout", "{$wl_sysctl_prefix}.ctstimeout"));
267
	$wl_regdomain_xml_attr = array();
268
	$wl_regdomain_xml = parse_xml_regdomain($wl_regdomain_xml_attr);
269
	$wl_regdomains = &$wl_regdomain_xml['regulatory-domains']['rd'];
270
	$wl_regdomains_attr = &$wl_regdomain_xml_attr['regulatory-domains']['rd'];
271
	$wl_countries = &$wl_regdomain_xml['country-codes']['country'];
272
	$wl_countries_attr = &$wl_regdomain_xml_attr['country-codes']['country'];
273
	$pconfig['persistcommonwireless'] = isset($config['wireless']['interfaces'][$wlanbaseif]);
274
	$pconfig['standard'] = $wancfg['wireless']['standard'];
275
	$pconfig['mode'] = $wancfg['wireless']['mode'];
276
	$pconfig['protmode'] = $wancfg['wireless']['protmode'];
277
	$pconfig['ssid'] = $wancfg['wireless']['ssid'];
278
	$pconfig['channel'] = $wancfg['wireless']['channel'];
279
	$pconfig['txpower'] = $wancfg['wireless']['txpower'];
280
	$pconfig['diversity'] = $wancfg['wireless']['diversity'];
281
	$pconfig['txantenna'] = $wancfg['wireless']['txantenna'];
282
	$pconfig['rxantenna'] = $wancfg['wireless']['rxantenna'];
283
	$pconfig['distance'] = $wancfg['wireless']['distance'];
284
	$pconfig['regdomain'] = $wancfg['wireless']['regdomain'];
285
	$pconfig['regcountry'] = $wancfg['wireless']['regcountry'];
286
	$pconfig['reglocation'] = $wancfg['wireless']['reglocation'];
287
	$pconfig['wme_enable'] = isset($wancfg['wireless']['wme']['enable']);
288
	if (isset($wancfg['wireless']['puren']['enable']))
289
		$pconfig['puremode'] = '11n';
290
	else if (isset($wancfg['wireless']['pureg']['enable']))
291
		$pconfig['puremode'] = '11g';
292
	else
293
		$pconfig['puremode'] = 'any';
294
	$pconfig['apbridge_enable'] = isset($wancfg['wireless']['apbridge']['enable']);
295
	$pconfig['authmode'] = $wancfg['wireless']['authmode'];
296
	$pconfig['hidessid_enable'] = isset($wancfg['wireless']['hidessid']['enable']);
297
	$pconfig['auth_server_addr'] = $wancfg['wireless']['auth_server_addr'];
298
	$pconfig['auth_server_port'] = $wancfg['wireless']['auth_server_port'];
299
	$pconfig['auth_server_shared_secret'] = $wancfg['wireless']['auth_server_shared_secret'];
300
	$pconfig['auth_server_addr2'] = $wancfg['wireless']['auth_server_addr2'];
301
	$pconfig['auth_server_port2'] = $wancfg['wireless']['auth_server_port2'];
302
	$pconfig['auth_server_shared_secret2'] = $wancfg['wireless']['auth_server_shared_secret2'];
303
	if (is_array($wancfg['wireless']['wpa'])) {
304
		$pconfig['debug_mode'] = $wancfg['wireless']['wpa']['debug_mode'];
305
		$pconfig['macaddr_acl'] = $wancfg['wireless']['wpa']['macaddr_acl'];
306
		$pconfig['mac_acl_enable'] = isset($wancfg['wireless']['wpa']['mac_acl_enable']);
307
		$pconfig['auth_algs'] = $wancfg['wireless']['wpa']['auth_algs'];
308
		$pconfig['wpa_mode'] = $wancfg['wireless']['wpa']['wpa_mode'];
309
		$pconfig['wpa_key_mgmt'] = $wancfg['wireless']['wpa']['wpa_key_mgmt'];
310
		$pconfig['wpa_pairwise'] = $wancfg['wireless']['wpa']['wpa_pairwise'];
311
		$pconfig['wpa_group_rekey'] = $wancfg['wireless']['wpa']['wpa_group_rekey'];
312
		$pconfig['wpa_gmk_rekey'] = $wancfg['wireless']['wpa']['wpa_gmk_rekey'];
313
		$pconfig['wpa_strict_rekey'] = isset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
314
		$pconfig['passphrase'] = $wancfg['wireless']['wpa']['passphrase'];
315
		$pconfig['ieee8021x'] = isset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
316
		$pconfig['rsn_preauth'] = isset($wancfg['wireless']['wpa']['rsn_preauth']);
317
		$pconfig['ext_wpa_sw'] = $wancfg['wireless']['wpa']['ext_wpa_sw'];
318
		$pconfig['wpa_enable'] = isset($wancfg['wireless']['wpa']['enable']);
319
	}
320
	$pconfig['wep_enable'] = isset($wancfg['wireless']['wep']['enable']);
321
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
322
	if (is_array($wancfg['wireless']['wep']) && is_array($wancfg['wireless']['wep']['key'])) {
323
		$i = 1;
324
		foreach ($wancfg['wireless']['wep']['key'] as $wepkey) {
325
			$pconfig['key' . $i] = $wepkey['value'];
326
			if (isset($wepkey['txkey']))
327
				$pconfig['txkey'] = $i;
328
			$i++;
329
		}
330
		if (!isset($wepkey['txkey']))
331
			$pconfig['txkey'] = 1;
332
	}
333
}
334

    
335
if ($_POST['apply']) {
336
	unset($input_errors);
337
	if (!is_subsystem_dirty('interfaces'))
338
		$intput_errors[] = gettext("You have already applied your settings!");
339
	else {
340
		unlink_if_exists("{$g['tmp_path']}/config.cache");
341
		clear_subsystem_dirty('interfaces');
342

    
343
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
344
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
345
			foreach ($toapplylist as $ifapply => $values) {
346
				if (isset($config['interfaces'][$ifapply]['enable'])) {
347
					/* check if any old addresses need purging */
348
					if(is_ipaddrv6($values['ipaddrv6'])) {
349
						$realif = get_real_interface("$ifapply");
350
						log_error("removing old v6 address {$values['ipaddrv6']} on {$realif}");
351
						mwexec("/sbin/ifconfig {$realif} inet6 {$values['ipaddrv6']} -alias");
352
					}
353
					interface_reconfigure($ifapply, true);
354
				} else {
355

    
356
					interface_bring_down($ifapply);
357
				}
358
			}
359
		}
360
		/* restart snmp so that it binds to correct address */
361
		services_snmpd_configure();
362

    
363
		/* sync filter configuration */
364
		setup_gateways_monitor();
365

    
366
		clear_subsystem_dirty('staticroutes');
367

    
368
		filter_configure();
369

    
370
		enable_rrd_graphing();
371
	}
372
	@unlink("{$g['tmp_path']}/.interfaces.apply");
373
	header("Location: interfaces.php?if={$if}");
374
	exit;
375
} else if ($_POST && $_POST['enable'] != "yes") {
376
	unset($wancfg['enable']);
377
	if (isset($wancfg['wireless']))
378
		interface_sync_wireless_clones($wancfg, false);
379
	write_config("Interface {$_POST['descr']}({$if}) is now disabled.");
380
	mark_subsystem_dirty('interfaces');
381
	if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
382
		$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
383
	} else {
384
		$toapplylist = array();
385
	}
386
	$toapplylist[$if] = array();
387
	/* we need to be able remove IP aliases for IPv6 */
388
	if(($old_wancfg['ipaddrv6'] != $wancfg['ipaddrv6']) && (is_ipaddrv6($old_wancfg['ipaddrv6']))) {
389
		$toapplylist[$if]['ipaddrv6'] = "{$old_wancfg['ipaddrv6']}";
390
	}
391
	file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
392
	header("Location: interfaces.php?if={$if}");
393
	exit;
394
} else if ($_POST) {
395

    
396
	unset($input_errors);
397
	$pconfig = $_POST;
398
	conf_mount_rw();
399

    
400
	/* filter out spaces from descriptions  */
401
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
402

    
403
	/* okay first of all, cause we are just hiding the PPPoE HTML
404
	 * fields releated to PPPoE resets, we are going to unset $_POST
405
	 * vars, if the reset feature should not be used. Otherwise the
406
	 * data validation procedure below, may trigger a false error
407
	 * message.
408
	 */
409
	if (empty($_POST['pppoe-reset-type'])) {
410
		unset($_POST['pppoe_pr_type']);
411
		unset($_POST['pppoe_resethour']);
412
		unset($_POST['pppoe_resetminute']);
413
		unset($_POST['pppoe_resetdate']);
414
		unset($_POST['pppoe_pr_preset_val']);
415
	}
416
	/* description unique? */
417
	foreach ($ifdescrs as $ifent => $ifdescr) {
418
		if ($if != $ifent && $ifdescr == $_POST['descr']) {
419
			$input_errors[] = gettext("An interface with the specified description already exists.");
420
			break;
421
		}
422
	}
423
	/* input validation */
424
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && (! preg_match("/^staticv4/", $_POST['type'])))
425
		$input_errors[] = gettext("The DHCP Server is active on this interface and it can be used only with a static IP configuration. Please disable the DHCP Server service on this interface first, then change the interface configuration.");
426
	if (isset($config['dhcpd6']) && isset($config['dhcpd6'][$if]['enable']) && (! preg_match("/^staticv6/", $_POST['type6'])))
427
		$input_errors[] = gettext("The DHCP6 Server is active on this interface and it can be used only with a static IPv6 configuration. Please disable the DHCPv6 Server service on this interface first, then change the interface configuration.");
428

    
429
	switch(strtolower($_POST['type'])) {
430
		case "staticv4":
431
			$reqdfields = explode(" ", "ipaddr subnet gateway");
432
			$reqdfieldsn = array(gettext("IPv4 address"),gettext("Subnet bit count"),gettext("Gateway"));
433
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
434
			break;
435
		case "none":
436
			if(is_array($config['virtualip']['vip'])) {
437
				foreach ($config['virtualip']['vip'] as $vip) {
438
					if (is_ipaddrv4($vip['subnet']) && $vip['interface'] == $if)
439
						$input_errors[] = gettext("This interface is referenced by IPv4 VIPs. Please delete those before setting the interface to 'none' configuration.");
440
				}
441
			}
442
		case "dhcp":
443
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp")))
444
				$input_errors[] = sprintf(gettext("You have to reassign the interface to be able to configure as %s."),$_POST['type']);
445
			break;
446
		case "ppp":
447
			$reqdfields = explode(" ", "port phone");
448
			$reqdfieldsn = array(gettext("Modem Port"),gettext("Phone Number"));
449
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
450
			break;
451
		case "pppoe":
452
			if ($_POST['pppoe_dialondemand']) {
453
				$reqdfields = explode(" ", "pppoe_username pppoe_password pppoe_dialondemand pppoe_idletimeout");
454
				$reqdfieldsn = array(gettext("PPPoE username"),gettext("PPPoE password"),gettext("Dial on demand"),gettext("Idle timeout value"));
455
			} else {
456
				$reqdfields = explode(" ", "pppoe_username pppoe_password");
457
				$reqdfieldsn = array(gettext("PPPoE username"),gettext("PPPoE password"));
458
			}
459
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
460
			break;
461
		case "pptp":
462
			if ($_POST['pptp_dialondemand']) {
463
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote pptp_dialondemand pptp_idletimeout");
464
				$reqdfieldsn = array(gettext("PPTP username"),gettext("PPTP password"),gettext("PPTP local IP address"),gettext("PPTP subnet"),gettext("PPTP remote IP address"),gettext("Dial on demand"),gettext("Idle timeout value"));
465
			} else {
466
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote");
467
				$reqdfieldsn = array(gettext("PPTP username"),gettext("PPTP password"),gettext("PPTP local IP address"),gettext("PPTP subnet"),gettext("PPTP remote IP address"));
468
			}
469
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
470
			break;
471
		case "l2tp":
472
			if ($_POST['pptp_dialondemand']) {
473
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_remote pptp_dialondemand pptp_idletimeout");
474
				$reqdfieldsn = array(gettext("L2TP username"),gettext("L2TP password"),gettext("L2TP remote IP address"),gettext("Dial on demand"),gettext("Idle timeout value"));
475
			} else {
476
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_remote");
477
				$reqdfieldsn = array(gettext("L2TP username"),gettext("L2TP password"),gettext("L2TP remote IP address"));
478
			}
479
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
480
			break;
481
	}
482
	switch(strtolower($_POST['type6'])) {
483
		case "staticv6":
484
			$reqdfields = explode(" ", "ipaddrv6 subnetv6 gatewayv6");
485
			$reqdfieldsn = array(gettext("IPv6 address"),gettext("Subnet bit count"),gettext("Gateway"));
486
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
487
			break;
488
		case "none":
489
			if(is_array($config['virtualip']['vip'])) {
490
				foreach ($config['virtualip']['vip'] as $vip) {
491
					if (is_ipaddrv6($vip['subnet']) && $vip['interface'] == $if)
492
						$input_errors[] = gettext("This interface is referenced by IPv6 VIPs. Please delete those before setting the interface to 'none' configuration.");
493
				}
494
			}
495
		case "dhcp6":
496
			if (in_array($wancfg['ipaddrv6'], array()))
497
				$input_errors[] = sprintf(gettext("You have to reassign the interface to be able to configure as %s."),$_POST['type']);
498
			break;
499
		case "6rd":
500
			if (in_array($wancfg['ipaddrv6'], array()))
501
				$input_errors[] = sprintf(gettext("You have to reassign the interface to be able to configure as %s."),$_POST['type']);
502
			break;
503
	}
504

    
505
	
506
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
507
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
508
	if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr'])))
509
		$input_errors[] = gettext("A valid IPv4 address must be specified.");
510
	if (($_POST['ipaddrv6'] && !is_ipaddr($_POST['ipaddrv6'])))
511
		$input_errors[] = gettext("A valid IPv6 address must be specified.");
512
	if (($_POST['subnet'] && !is_numeric($_POST['subnet'])))
513
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
514
	if (($_POST['subnetv6'] && !is_numeric($_POST['subnetv6'])))
515
		$input_errors[] = gettext("A valid subnet bit count must be specified.");
516
	if (($_POST['alias-address'] && !is_ipaddr($_POST['alias-address'])))
517
		$input_errors[] = gettext("A valid alias IP address must be specified.");
518
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet'])))
519
		$input_errors[] = gettext("A valid alias subnet bit count must be specified.");
520
	if (($_POST['gateway'] != "none") || ($_POST['gatewayv6'] != "none")) {
521
		$match = false;
522
		foreach($a_gateways as $gateway) {
523
			if(in_array($_POST['gateway'], $gateway)) {
524
				$match = true;
525
			}
526
		}
527
		foreach($a_gateways as $gateway) {
528
			if(in_array($_POST['gatewayv6'], $gateway)) {
529
				$match = true;
530
			}
531
		}
532
		if(!$match) {
533
			$input_errors[] = gettext("A valid gateway must be specified.");
534
		}
535
	}
536
	if (($_POST['provider'] && !is_domain($_POST['provider'])))
537
		$input_errors[] = gettext("The service name contains invalid characters.");
538
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout']))
539
		$input_errors[] = gettext("The idle timeout value must be an integer.");
540
	if ($_POST['pppoe_resethour'] <> "" && !is_numericint($_POST['pppoe_resethour']) &&
541
		$_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23)
542
			$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
543
	if ($_POST['pppoe_resetminute'] <> "" && !is_numericint($_POST['pppoe_resetminute']) &&
544
		$_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59)
545
			$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
546
	if ($_POST['pppoe_resetdate'] <> "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate'])))
547
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
548
	if (($_POST['pptp_local'] && !is_ipaddr($_POST['pptp_local'])))
549
		$input_errors[] = gettext("A valid PPTP local IP address must be specified.");
550
	if (($_POST['pptp_subnet'] && !is_numeric($_POST['pptp_subnet'])))
551
		$input_errors[] = gettext("A valid PPTP subnet bit count must be specified.");
552
	if (($_POST['pptp_remote'] && !is_ipaddr($_POST['pptp_remote']) && !is_hostname($_POST['gateway'][$iface])))
553
		$input_errors[] = gettext("A valid PPTP remote IP address must be specified.");
554
	if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout']))
555
		$input_errors[] = gettext("The idle timeout value must be an integer.");
556
	if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac'])))
557
		$input_errors[] = gettext("A valid MAC address must be specified.");
558
	if ($_POST['mtu'] && ($_POST['mtu'] < 576))
559
		$input_errors[] = gettext("The MTU must be greater than 576 bytes.");
560
	if ($_POST['mss'] && ($_POST['mss'] < 576))
561
		$input_errors[] = gettext("The MSS must be greater than 576 bytes.");
562
	/* Wireless interface? */
563
	if (isset($wancfg['wireless'])) {
564
		$reqdfields = array("mode");
565
		$reqdfieldsn = array(gettext("Mode"));
566
		if ($_POST['mode'] == 'hostap') {
567
			$reqdfields[] = "ssid";
568
			$reqdfieldsn[] = gettext("SSID");
569
		}
570
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
571
		check_wireless_mode();
572
		/* loop through keys and enforce size */
573
		for ($i = 1; $i <= 4; $i++) {
574
			if ($_POST['key' . $i]) {
575
				/* 64 bit */
576
				if (strlen($_POST['key' . $i]) == 5)
577
					continue;
578
				if (strlen($_POST['key' . $i]) == 10) {
579
					/* hex key */
580
					if (stristr($_POST['key' . $i], "0x") == false) {
581
						$_POST['key' . $i] = "0x" . $_POST['key' . $i];
582
					}
583
					continue;
584
				}
585
				if (strlen($_POST['key' . $i]) == 12) {
586
					/* hex key */
587
					if(stristr($_POST['key' . $i], "0x") == false) {
588
					$_POST['key' . $i] = "0x" . $_POST['key' . $i];
589
					}
590
					continue;
591
				}
592
				/* 128 bit */
593
				if (strlen($_POST['key' . $i]) == 13)
594
					continue;
595
				if (strlen($_POST['key' . $i]) == 26) {
596
					/* hex key */
597
					if (stristr($_POST['key' . $i], "0x") == false)
598
						$_POST['key' . $i] = "0x" . $_POST['key' . $i];
599
					continue;
600
				}
601
				if(strlen($_POST['key' . $i]) == 28)
602
					continue;
603
				$input_errors[] =  gettext("Invalid WEP key size.   Sizes should be 40 (64) bit keys or 104 (128) bit.");
604
				break;
605
			}
606
		}
607

    
608
		if ($_POST['passphrase']) {
609
                	$passlen = strlen($_POST['passphrase']);
610
                	if ($passlen < 8 || $passlen > 64)
611
                        	$input_errors[] = gettext("The length of the passphrase should be between 8 and 63 characters.");
612
		}
613
	}
614
	if (!$input_errors) {
615
		if ($wancfg['ipaddr'] != $_POST['type']) {
616
			if (in_array($wancfg['ipaddr'], array("ppp", "pppoe", "pptp", "l2tp"))) {
617
				$wancfg['if'] = $a_ppps[$pppid]['ports'];
618
				unset($a_ppps[$pppid]);
619
			} else if ($wancfg['ipaddrv6'] == "dhcp6") {
620
				$pid = find_dhcp6c_process($realif);
621
				if($pid)
622
					posix_kill($pid, SIGTERM);
623
			} else if ($wancfg['ipaddr'] == "dhcp") {
624
				$pid = find_dhclient_process($realif);
625
				if($pid)
626
					posix_kill($pid, SIGTERM);
627
			}
628
				
629
		}
630
		$ppp = array();
631
		if ($wancfg['ipaddr'] != "ppp")
632
			unset($wancfg['ipaddr']);
633
		if ($wancfg['ipaddrv6'] != "ppp")
634
			unset($wancfg['ipaddrv6']);
635
		unset($wancfg['subnet']);
636
		unset($wancfg['gateway']);
637
		unset($wancfg['subnetv6']);
638
		unset($wancfg['gatewayv6']);
639
		unset($wancfg['dhcphostname']);
640
		unset($wancfg['dhcp6-pd-sla-id']);
641
		unset($wancfg['dhcp6-duid']);
642
		unset($wancfg['dhcp6-ia-pd-len']);
643
		unset($wancfg['prefix-6rd']);
644
		unset($wancfg['prefix-6rd-v4plen']);
645
		unset($wancfg['gateway-6rd']);
646
		unset($wancfg['prefix-6rd-id']);
647
		unset($wancfg['pppoe_password']);
648
		unset($wancfg['pptp_username']);
649
		unset($wancfg['pptp_password']);
650
		unset($wancfg['provider']);
651
		unset($wancfg['ondemand']);
652
		unset($wancfg['timeout']);
653
		if (isset($wancfg['pppoe']['pppoe-reset-type']))
654
			unset($wancfg['pppoe']['pppoe-reset-type']);
655
		unset($wancfg['local']);
656
		
657
		unset($wancfg['remote']);
658
		unset($a_ppps[$pppid]['apn']);
659
		unset($a_ppps[$pppid]['phone']);
660
		unset($a_ppps[$pppid]['localip']);
661
		unset($a_ppps[$pppid]['subnet']);
662
		unset($a_ppps[$pppid]['gateway']);
663
		unset($a_ppps[$pppid]['pppoe-reset-type']);
664
		unset($a_ppps[$pppid]['provider']);
665

    
666
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
667
		$wancfg['enable'] =  $_POST['enable']  == "yes" ? true : false;
668

    
669
		/* for dynamic interfaces we tack a gateway item onto the array to prevent system
670
		 * log messages from appearing. They can also manually add these items */
671
		/* 1st added gateway gets a default bit */
672
		if(!empty($a_gateways)) {
673
			$gateway_item = array();
674
			/* check for duplicates */
675
			$skip = false;
676
			foreach($a_gateways as $item) {
677
				if(($item['interface'] == "$if") && (preg_match("/dynamic/", $item['gateway']))) {
678
					$skip = true;
679
				}
680
			}
681
			if($skip == false) {
682
				$gateway_item['gateway'] = "dynamic";
683
				$gateway_item['descr'] = sprintf(gettext("Interface %s dynamic gateway"),$if);
684
				$gateway_item['name'] = "GW_" . strtoupper($if);
685
				$gateway_item['interface'] = "{$if}";
686
			} else {
687
				unset($gateway_item);
688
			}
689
		}
690

    
691
		switch($_POST['type']) {
692
			case "staticv4":
693
				$wancfg['ipaddr'] = $_POST['ipaddr'];
694
				$wancfg['subnet'] = $_POST['subnet'];
695
				if ($_POST['gateway'] != "none") {
696
					$wancfg['gateway'] = $_POST['gateway'];
697
				}
698
				break;
699
			case "dhcp":
700
				$wancfg['ipaddr'] = "dhcp";
701
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
702
				$wancfg['alias-address'] = $_POST['alias-address'];
703
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
704
				$wancfg['dhcp_plus'] = $_POST['dhcp_plus'] == "yes" ? true : false;
705
				if($gateway_item) {
706
					$a_gateways[] = $gateway_item;
707
				}
708
				break;
709
			case "carpdev-dhcp":
710
				$wancfg['ipaddr'] = "carpdev-dhcp";
711
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
712
				$wancfg['alias-address'] = $_POST['alias-address'];
713
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
714
				if($gateway_item) {
715
					$a_gateways[] = $gateway_item;
716
				}
717
				break;
718
			case "ppp":
719
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
720
				$a_ppps[$pppid]['type'] = $_POST['type'];
721
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
722
				$a_ppps[$pppid]['ports'] = $_POST['port'];
723
				$a_ppps[$pppid]['username'] = $_POST['username'];
724
				$a_ppps[$pppid]['password'] = base64_encode($_POST['password']);
725
				$a_ppps[$pppid]['phone'] = $_POST['phone'];
726
				$a_ppps[$pppid]['apn'] = $_POST['apn'];
727
				$wancfg['if'] = $_POST['type'] . $_POST['ptpid'];
728
				$wancfg['ipaddr'] = $_POST['type'];
729
				unset($a_ppps[$pppid]['ondemand']);
730
				unset($a_ppps[$pppid]['idletimeout']);
731
				break;
732

    
733
			case "pppoe":
734
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
735
				$a_ppps[$pppid]['type'] = $_POST['type'];
736
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
737
				if (isset($_POST['ppp_port']))
738
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
739
				else
740
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
741
				$a_ppps[$pppid]['username'] = $_POST['pppoe_username'];
742
				$a_ppps[$pppid]['password'] = base64_encode($_POST['pppoe_password']);
743
				if (!empty($_POST['provider']))
744
					$a_ppps[$pppid]['provider'] = $_POST['provider'];
745
				else
746
					$a_ppps[$pppid]['provider'] = true;
747
				$a_ppps[$pppid]['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
748
				if (!empty($_POST['idletimeout']))
749
					$a_ppps[$pppid]['idletimeout'] = $_POST['pppoe_idletimeout'];
750
				else
751
					unset($a_ppps[$pppid]['idletimeout']);
752

    
753
				if (!empty($_POST['pppoe-reset-type']))
754
					$a_ppps[$pppid]['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
755
				else
756
					unset($a_ppps[$pppid]['pppoe-reset-type']);
757
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
758
				$wancfg['ipaddr'] = $_POST['type'];
759
				if($gateway_item) {
760
					$a_gateways[] = $gateway_item;
761
				}
762

    
763
				break;
764
			case "pptp":
765
			case "l2tp":
766
				$a_ppps[$pppid]['ptpid'] = $_POST['ptpid'];
767
				$a_ppps[$pppid]['type'] = $_POST['type'];
768
				$a_ppps[$pppid]['if'] = $_POST['type'].$_POST['ptpid'];
769
				if (isset($_POST['ppp_port']))
770
					$a_ppps[$pppid]['ports'] = $_POST['ppp_port'];
771
				else
772
					$a_ppps[$pppid]['ports'] = $wancfg['if'];
773
				$a_ppps[$pppid]['username'] = $_POST['pptp_username'];
774
				$a_ppps[$pppid]['password'] = base64_encode($_POST['pptp_password']);
775
				$a_ppps[$pppid]['localip'] = $_POST['pptp_local'];
776
				$a_ppps[$pppid]['subnet'] = $_POST['pptp_subnet'];
777
				$a_ppps[$pppid]['gateway'] = $_POST['pptp_remote'];
778
				$a_ppps[$pppid]['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
779
				if (!empty($_POST['idletimeout']))
780
					$a_ppps[$pppid]['idletimeout'] = $_POST['pptp_idletimeout'];
781
				else
782
					unset($a_ppps[$pppid]['idletimeout']);
783
				$wancfg['if'] = $_POST['type'].$_POST['ptpid'];
784
				$wancfg['ipaddr'] = $_POST['type'];
785
				if($gateway_item) {
786
					$a_gateways[] = $gateway_item;
787
				}
788
				break;
789
			case "none":
790
				break;
791
		}
792
		switch($_POST['type6']) {
793
			case "staticv6":
794
				$wancfg['ipaddrv6'] = $_POST['ipaddrv6'];
795
				$wancfg['subnetv6'] = $_POST['subnetv6'];
796
				$wancfg['dhcp6-pd-sla-id'] = $_POST['dhcp6-pd-sla-id'];
797
				$wancfg['prefix-6rd-id'] = $_POST['prefix-6rd-id'];
798
				if ($_POST['gatewayv6'] != "none") {
799
					$wancfg['gatewayv6'] = $_POST['gatewayv6'];
800
				}
801
				break;
802
			case "dhcp6":
803
				$wancfg['ipaddrv6'] = "dhcp6";
804
				$wancfg['dhcp6-duid'] = $_POST['dhcp6-duid'];
805
				$wancfg['dhcp6-ia-pd-len'] = $_POST['dhcp6-ia-pd-len'];
806
				if($gateway_item) {
807
					$a_gateways[] = $gateway_item;
808
				}
809
				break;
810
			case "6rd":
811
				$wancfg['ipaddrv6'] = "6rd";
812
				$wancfg['prefix-6rd'] = $_POST['prefix-6rd'];
813
				$wancfg['prefix-6rd-v4plen'] = $_POST['prefix-6rd-v4plen'];
814
				$wancfg['gateway-6rd'] = $_POST['gateway-6rd'];
815
				if($gateway_item) {
816
					$a_gateways[] = $gateway_item;
817
				}
818
				break;
819
			case "none":
820
				break;
821
		}
822
		handle_pppoe_reset($_POST);
823

    
824
		if($_POST['blockpriv'] == "yes") {
825
			$wancfg['blockpriv'] = true;
826
		} else {
827
			unset($wancfg['blockpriv']);
828
		}
829
		if($_POST['blockbogons'] == "yes") {
830
			$wancfg['blockbogons'] = true;
831
		} else {
832
			unset($wancfg['blockbogons']);
833
		}
834
		$wancfg['spoofmac'] = $_POST['spoofmac'];
835
		if (empty($_POST['mtu'])) {
836
			unset($wancfg['mtu']);
837
		} else {
838
			$wancfg['mtu'] = $_POST['mtu'];
839
		}
840
		if (empty($_POST['mss'])) {
841
			unset($wancfg['mss']);
842
		} else {
843
			$wancfg['mss'] = $_POST['mss'];
844
		}
845
		if (empty($_POST['mediaopt'])) {
846
			unset($wancfg['media']);
847
			unset($wancfg['mediaopt']);
848
		} else {
849
			$mediaopts = explode(' ', $_POST['mediaopt']);	
850
			if ($mediaopts[0] != ''){ $wancfg['media'] = $mediaopts[0]; }
851
			if ($mediaopts[1] != ''){ $wancfg['mediaopt'] = $mediaopts[1]; }
852
			else { unset($wancfg['mediaopt']); }
853
		}
854
		if (isset($wancfg['wireless'])) {
855
			handle_wireless_post();
856
		}
857

    
858
		conf_mount_ro();
859
		write_config();
860

    
861
		if (file_exists("{$g['tmp_path']}/.interfaces.apply")) {
862
			$toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.interfaces.apply"));
863
		} else {
864
			$toapplylist = array();
865
		}
866
		$toapplylist[$if] = array();
867
		/* we need to be able remove IP aliases for IPv6 */
868
		if(($old_wancfg['ipaddrv6'] != $wancfg['ipaddrv6']) && (is_ipaddrv6($old_wancfg['ipaddrv6']))) {
869
			$toapplylist[$if]['ipaddrv6'] = $old_wancfg['ipaddrv6'];
870
		}
871
		
872
		file_put_contents("{$g['tmp_path']}/.interfaces.apply", serialize($toapplylist));
873

    
874
		mark_subsystem_dirty('interfaces');
875

    
876
		/* regenerate cron settings/crontab file */
877
		configure_cron();
878

    
879
		header("Location: interfaces.php?if={$if}");
880
		exit;
881
	}
882

    
883
} // end if($_POST)
884

    
885
function handle_wireless_post() {
886
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr, $wlanbaseif;
887
	if (!is_array($wancfg['wireless']))
888
		$wancfg['wireless'] = array();
889
	$wancfg['wireless']['standard'] = $_POST['standard'];
890
	$wancfg['wireless']['mode'] = $_POST['mode'];
891
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
892
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
893
	$wancfg['wireless']['channel'] = $_POST['channel'];
894
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
895
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
896
	$wancfg['wireless']['distance'] = $_POST['distance'];
897
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
898
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
899
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
900
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
901
		foreach($wl_countries_attr as $wl_country) {
902
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
903
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
904
				break;
905
			}
906
		}
907
	}
908
	if (!is_array($wancfg['wireless']['wpa']))
909
		$wancfg['wireless']['wpa'] = array();
910
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
911
	$wancfg['wireless']['wpa']['auth_algs'] = $_POST['auth_algs'];
912
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
913
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
914
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
915
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
916
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
917
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
918
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
919
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
920
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
921
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
922
	$wancfg['wireless']['auth_server_addr2'] = $_POST['auth_server_addr2'];
923
	$wancfg['wireless']['auth_server_port2'] = $_POST['auth_server_port2'];
924
	$wancfg['wireless']['auth_server_shared_secret2'] = $_POST['auth_server_shared_secret2'];
925
	
926
	if ($_POST['persistcommonwireless'] == "yes") {
927
		if (!is_array($config['wireless']['interfaces'][$wlanbaseif]))
928
			$config['wireless']['interfaces'][$wlanbaseif] = array();
929
	} else if (isset($config['wireless']['interfaces'][$wlanbaseif]))
930
		unset($config['wireless']['interfaces'][$wlanbaseif]);
931
	if (isset($_POST['diversity']) && is_numeric($_POST['diversity']))
932
		$wancfg['wireless']['diversity'] = $_POST['diversity'];
933
	else if (isset($wancfg['wireless']['diversity']))
934
		unset($wancfg['wireless']['diversity']);
935
	if (isset($_POST['txantenna']) && is_numeric($_POST['txantenna']))
936
		$wancfg['wireless']['txantenna'] = $_POST['txantenna'];
937
	else if (isset($wancfg['wireless']['txantenna']))
938
		unset($wancfg['wireless']['txantenna']);
939
	if (isset($_POST['rxantenna']) && is_numeric($_POST['rxantenna']))
940
		$wancfg['wireless']['rxantenna'] = $_POST['rxantenna'];
941
	else if (isset($wancfg['wireless']['rxantenna']))
942
		unset($wancfg['wireless']['rxantenna']);
943
	if ($_POST['hidessid_enable'] == "yes")
944
		$wancfg['wireless']['hidessid']['enable'] = true;
945
	else if (isset($wancfg['wireless']['hidessid']['enable']))
946
		unset($wancfg['wireless']['hidessid']['enable']);
947
	if ($_POST['mac_acl_enable'] == "yes")
948
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
949
	else if (isset($wancfg['wireless']['wpa']['mac_acl_enable']))
950
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
951
	if ($_POST['rsn_preauth'] == "yes")
952
		$wancfg['wireless']['wpa']['rsn_preauth'] = true;
953
	else
954
		unset($wancfg['wireless']['wpa']['rsn_preauth']);
955
	if ($_POST['ieee8021x'] == "yes")
956
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
957
	else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable']))
958
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
959
	if ($_POST['wpa_strict_rekey'] == "yes")
960
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
961
	else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey']))
962
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
963
	if ($_POST['debug_mode'] == "yes")
964
		$wancfg['wireless']['wpa']['debug_mode'] = true;
965
	else if (isset($wancfg['wireless']['wpa']['debug_mode']))
966
		sunset($wancfg['wireless']['wpa']['debug_mode']);
967
	if ($_POST['wpa_enable'] == "yes")
968
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
969
	else if (isset($wancfg['wireless']['wpa']['enable']))
970
		unset($wancfg['wireless']['wpa']['enable']);
971
	if ($_POST['wep_enable'] == "yes") {
972
		if (!is_array($wancfg['wireless']['wep']))
973
			$wancfg['wireless']['wep'] = array();
974
		$wancfg['wireless']['wep']['enable'] = $_POST['wep_enable'] = true;
975
	} else if (isset($wancfg['wireless']['wep']))
976
		unset($wancfg['wireless']['wep']);
977
	if ($_POST['wme_enable'] == "yes") {
978
		if (!is_array($wancfg['wireless']['wme']))
979
			$wancfg['wireless']['wme'] = array();
980
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
981
	} else if (isset($wancfg['wireless']['wme']['enable']))
982
		unset($wancfg['wireless']['wme']['enable']);
983
	if ($_POST['puremode'] == "11g") {
984
		if (!is_array($wancfg['wireless']['pureg']))
985
			$wancfg['wireless']['pureg'] = array();
986
		$wancfg['wireless']['pureg']['enable'] = true;
987
	} else if ($_POST['puremode'] == "11n") {
988
		if (!is_array($wancfg['wireless']['puren']))
989
			$wancfg['wireless']['puren'] = array();
990
		$wancfg['wireless']['puren']['enable'] = true;
991
	} else {
992
		if (isset($wancfg['wireless']['pureg']))
993
			unset($wancfg['wireless']['pureg']);
994
		if (isset($wancfg['wireless']['puren']))
995
			unset($wancfg['wireless']['puren']);
996
	}
997
	if ($_POST['apbridge_enable'] == "yes") {
998
		if (!is_array($wancfg['wireless']['apbridge']))
999
			$wancfg['wireless']['apbridge'] = array();
1000
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
1001
	} else if (isset($wancfg['wireless']['apbridge']['enable']))
1002
		unset($wancfg['wireless']['apbridge']['enable']);
1003
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
1004
		if (!is_array($wancfg['wireless']['turbo']))
1005
			$wancfg['wireless']['turbo'] = array();
1006
		$wancfg['wireless']['turbo']['enable'] = true;
1007
	} else if (isset($wancfg['wireless']['turbo']['enable']))
1008
		unset($wancfg['wireless']['turbo']['enable']);
1009
	$wancfg['wireless']['wep']['key'] = array();
1010
	for ($i = 1; $i <= 4; $i++) {
1011
		if ($_POST['key' . $i]) {
1012
			$newkey = array();
1013
			$newkey['value'] = $_POST['key' . $i];
1014
			if ($_POST['txkey'] == $i)
1015
				$newkey['txkey'] = true;
1016
			$wancfg['wireless']['wep']['key'][] = $newkey;
1017
		}
1018
	}
1019
	interface_sync_wireless_clones($wancfg, true);
1020
}
1021

    
1022
function check_wireless_mode() {
1023
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
1024

    
1025
	if ($wancfg['wireless']['mode'] == $_POST['mode'])
1026
		return;
1027

    
1028
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif)))
1029
		$clone_count = 1;
1030
	else
1031
		$clone_count = 0;
1032
	if (is_array($config['wireless']['clone'])) {
1033
		foreach ($config['wireless']['clone'] as $clone) {
1034
			if ($clone['if'] == $wlanbaseif)
1035
				$clone_count++;
1036
		}
1037
	}
1038
	if ($clone_count > 1) {
1039
		$old_wireless_mode = $wancfg['wireless']['mode'];
1040
		$wancfg['wireless']['mode'] = $_POST['mode'];
1041
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
1042
			$input_errors[] = sprintf(gettext("Unable to change mode to %s.  You may already have the maximum number of wireless clones supported in this mode."), $wlan_modes[$wancfg['wireless']['mode']]);
1043
		} else {
1044
			mwexec("/sbin/ifconfig {$wlanif}_ destroy");
1045
		}
1046
		$wancfg['wireless']['mode'] = $old_wireless_mode;
1047
	}
1048
}
1049

    
1050
// Find all possible media options for the interface
1051
$mediaopts_list = array();
1052
$intrealname = $config['interfaces'][$if]['if'];
1053
exec("/sbin/ifconfig -m $intrealname | grep \"media \"", $mediaopts);
1054
foreach ($mediaopts as $mediaopt){
1055
	preg_match("/media (.*)/", $mediaopt, $matches);
1056
 	if (preg_match("/(.*) mediaopt (.*)/", $matches[1], $matches1)){
1057
		// there is media + mediaopt like "media 1000baseT mediaopt full-duplex"
1058
 		array_push($mediaopts_list, $matches1[1] . " " . $matches1[2]);
1059
	}else{
1060
		// there is only media like "media 1000baseT"
1061
		array_push($mediaopts_list, $matches[1]);
1062
	}
1063
}
1064

    
1065
$pgtitle = array(gettext("Interfaces"), $pconfig['descr']);
1066
$statusurl = "status_interfaces.php";
1067

    
1068
$closehead = false;
1069
include("head.inc");
1070
$types4 = array("none" => gettext("None"), "staticv4" => gettext("Static IPv4"), "dhcp" => gettext("DHCP"), "ppp" => gettext("PPP"), "pppoe" => gettext("PPPoE"), "pptp" => gettext("PPTP"), "l2tp" => gettext("L2TP") /* , "carpdev-dhcp" => "CarpDev"*/);
1071
$types6 = array("none" => gettext("None"), "staticv6" => gettext("Static IPv6"), "dhcp6" => gettext("DHCP6"), "srd" => gettext("6RD"));
1072

    
1073
?>
1074

    
1075
<script type="text/javascript" src="/javascript/numericupdown/js/numericupdown.js"></script>
1076
<link href="/javascript/numericupdown/css/numericupdown.css" rel="stylesheet" type="text/css" />
1077
<script type="text/javascript" src="/javascript/datepicker/js/datepicker.js"></script>
1078
<link href="/javascript/datepicker/css/datepicker.css" rel="stylesheet" type="text/css"/>
1079

    
1080
<script type="text/javascript">
1081
	function updateType(t) {
1082
		switch(t) {
1083
			case "none": {
1084
				jQuery('#staticv4, #dhcp, #pppoe, #pptp, #ppp').hide();
1085
				break;
1086
			}
1087
			case "staticv4": {
1088
				jQuery('#none, #dhcp, #pppoe, #pptp, #ppp').hide();
1089
				break;
1090
			}
1091
			case "dhcp": {
1092
				jQuery('#none, #staticv4, #pppoe, #pptp, #ppp').hide();
1093
				break;
1094
			}
1095
			case "ppp": {
1096
				jQuery('#none, #staticv4, #dhcp, #pptp, #pppoe').hide();
1097
				country_list();
1098
				break;
1099
			}
1100
			case "pppoe": {
1101
				jQuery('#none, #staticv4, #dhcp, #pptp, #ppp').hide();
1102
				break;
1103
			}
1104
			case "l2tp":
1105
			case "pptp": {
1106
				jQuery('#none, #staticv4, #dhcp, #pppoe, #ppp').hide();
1107
				jQuery('#pptp').show();
1108
				break;
1109
			}
1110
		}
1111
		if (t != "l2tp" && t != "pptp")
1112
			jQuery('#'+t).show();
1113
	}
1114
	function updateTypeSix(t) {
1115
		switch(t) {
1116
			case "none": {
1117
				jQuery('#staticv6, #dhcp6, #srd').hide();
1118
				break;
1119
			}
1120
			case "staticv6": {
1121
				jQuery('#none, #dhcp6, #srd').hide();
1122
				break;
1123
			}
1124
			case "dhcp6": {
1125
				jQuery('#none, #staticv6, #srd').hide();
1126
				break;
1127
			}
1128
			case "srd": {
1129
				jQuery('#none, #dhcp6, #staticv6').hide();
1130
				break;
1131
			}
1132
		}
1133
		if (t != "l2tp" && t != "pptp")
1134
			jQuery('#'+t).show();
1135
	}
1136

    
1137
	function show_allcfg(obj) {
1138
		if (obj.checked)
1139
			jQuery('#allcfg').show();
1140
		else
1141
			jQuery('#allcfg').hide();
1142
	}
1143

    
1144
	function show_reset_settings(reset_type) {
1145
		if (reset_type == 'preset') {
1146
			jQuery('#pppoepresetwrap').show();
1147
			jQuery('#pppoecustomwrap').hide();
1148
		}
1149
		else if (reset_type == 'custom') {
1150
			jQuery('#pppoecustomwrap').show();
1151
			jQuery('#pppoepresetwrap').hide();
1152
		} else {
1153
			jQuery('#pppoecustomwrap').hide();
1154
			jQuery('#pppoepresetwrap').hide();
1155
		}
1156
	}
1157
	function show_mon_config() {
1158
		jQuery("#showmonbox").html('');
1159
		jQuery('#showmon').css('display','block');
1160
	}
1161

    
1162
	function openwindow(url) {
1163
		var oWin = window.open(url,"pfSensePop","width=620,height=400,top=150,left=150");
1164
		if (oWin==null || typeof(oWin)=="undefined")
1165
			return false;
1166
		else
1167
			return true;
1168
	}
1169
	function country_list() {
1170
		jQuery('#country').children().remove();
1171
		jQuery('#provider').children().remove();
1172
		jQuery('#providerplan').children().remove();
1173
		jQuery.ajax("getserviceproviders.php",{
1174
			success: function(response) {
1175
				var responseTextArr = response.split("\n");
1176
				responseTextArr.sort();
1177
				responseTextArr.each( function(value) {
1178
					var option = new Element('option');
1179
					country = value.split(":");
1180
					option.text = country[0];
1181
					option.value = country[1];
1182
					jQuery('#country').append(option);
1183
				});
1184
			}
1185
		});
1186
		jQuery('#trcountry').css('display',"table-row");
1187
	}
1188

    
1189
	function providers_list() {
1190
		jQuery('#provider').children().remove();
1191
		jQuery('#providerplan').children().remove();
1192
		jQuery.ajax("getserviceproviders.php",{
1193
			type: 'post',
1194
			data: {country : jQuery('#country').val()},
1195
			success: function(response) {
1196
				var responseTextArr = response.split("\n");
1197
				responseTextArr.sort();
1198
				responseTextArr.each( function(value) {
1199
					var option = new Element('option');
1200
					option.text = value;
1201
					option.value = value;
1202
					jQuery('#provider').append(option);
1203
				});
1204
			}
1205
		});
1206
		jQuery('#trprovider').css("display","table-row");
1207
		jQuery('#trproviderplan').css("display","none");
1208
	}
1209

    
1210
	function providerplan_list() {
1211
		jQuery('#providerplan').children().remove();
1212
		jQuery('#providerplan').append( new Element('option') );
1213
		jQuery.ajax("getserviceproviders.php",{
1214
			type: 'post',
1215
			data: {country : jQuery('#country').val(), provider : jQuery('#provider').val()},
1216
			success: function(response) {
1217
				var responseTextArr = response.split("\n");
1218
				responseTextArr.sort();
1219
				responseTextArr.each( function(value) {
1220
					if(value != "") {
1221
						providerplan = value.split(":");
1222

    
1223
						var option = new Element('option');
1224
						option.text = providerplan[0] + " - " + providerplan[1];
1225
						option.value = providerplan[1];
1226
						jQuery('#providerplan').append(option);
1227
					}
1228
				});
1229
			}
1230
		});
1231
		jQuery('#trproviderplan').css("display","table-row");
1232
	}
1233

    
1234
	function prefill_provider() {
1235
		jQuery.ajax("getserviceproviders.php",{
1236
			type: 'post',
1237
			data: {country : jQuery('#country').val(), provider : jQuery('#provider').val(), plan : jQuery('#providerplan').val()},
1238
			success: function(data,textStatus,response) {
1239
				var xmldoc = response.responseXML;
1240
				var provider = xmldoc.getElementsByTagName('connection')[0];
1241
				jQuery('#username').val('');
1242
				jQuery('#password').val('');
1243
				if(provider.getElementsByTagName('apn')[0].firstChild.data == "CDMA") {
1244
					jQuery('#phone').val('#777');
1245
					jQuery('#apn').val('');
1246
				} else {
1247
					jQuery('#phone').val('*99#');
1248
					jQuery('#apn').val(provider.getElementsByTagName('apn')[0].firstChild.data);
1249
				}
1250
				username = provider.getElementsByTagName('username')[0].firstChild.data;
1251
				password = provider.getElementsByTagName('password')[0].firstChild.data;
1252
				jQuery('#username').val(username);
1253
				jQuery('#password').val(password);
1254
			}
1255
		});
1256
	}
1257

    
1258
</script>
1259
</head>
1260
	<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
1261
	<?php include("fbegin.inc"); ?>
1262
	<form action="interfaces.php" method="post" name="iform" id="iform">
1263
		<?php if ($input_errors) print_input_errors($input_errors); ?>
1264
		<?php if (is_subsystem_dirty('interfaces')): ?><p>
1265
		<?php print_info_box_np(sprintf(gettext("The %s configuration has been changed."),$wancfg['descr'])."<p>".gettext("You must apply the changes in order for them to take effect.")."<p>".gettext("Don't forget to adjust the DHCP Server range if needed after applying."));?><br />
1266
		<?php endif; ?>
1267
		<?php if ($savemsg) print_info_box($savemsg); ?>
1268
		<table width="100%" border="0" cellpadding="6" cellspacing="0">
1269
			<tr>
1270
				<td id="mainarea">
1271
					<div class="tabcont">
1272
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
1273
						<tr>
1274
							<td colspan="2" valign="top" class="listtopic"><?=gettext("General configuration"); ?></td>
1275
						</tr>
1276
						<tr>
1277
							<td width="22%" valign="top" class="vncell"><?=gettext("Enable"); ?></td>
1278
							<td width="78%" class="vtable">
1279
								<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable'] == true) echo "checked"; ?> onClick="show_allcfg(this);">
1280
							<strong><?=gettext("Enable Interface"); ?></strong>
1281
							</td>
1282
						</tr>
1283
					</table>
1284
					<div style="display:none;" name="allcfg" id="allcfg">
1285
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
1286
						<tr>
1287
							<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
1288
							<td width="78%" class="vtable">
1289
								<input name="descr" type="text" class="formfld unknown" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
1290
								<br><span class="vexpl"><?= gettext("Enter a description (name) for the interface here."); ?></span>
1291
							</td>
1292
						</tr>
1293
						<tr>
1294
							<td valign="middle" class="vncell"><strong><?=gettext("IPv4 Configuration Type"); ?></strong></td>
1295
							<td class="vtable">
1296
								<select name="type" onChange="updateType(this.value);" class="formselect" id="type">
1297
								<?php
1298
									foreach ($types4 as $key => $opt) {
1299
										echo "<option onClick=\"updateType('{$key}');\"";
1300
										if ($key == $pconfig['type'])
1301
											echo " selected";
1302
										echo " value=\"{$key}\" >" . htmlspecialchars($opt);
1303
										echo "</option>";
1304
									}
1305
								?>
1306
								</select>
1307
							</td>
1308
						</tr>
1309
						<tr>
1310
							<td valign="middle" class="vncell"><strong><?=gettext("IPv6 Configuration Type"); ?></strong></td>
1311
							<td class="vtable">
1312
								<select name="type6" onChange="updateTypeSix(this.value);" class="formselect" id="type6">
1313
								<?php
1314
									foreach ($types6 as $key => $opt) {
1315
										echo "<option onClick=\"updateTypeSix('{$key}');\"";
1316
										if ($key == $pconfig['type6'])
1317
											echo " selected";
1318
										echo " value=\"{$key}\" >" . htmlspecialchars($opt);
1319
										echo "</option>";
1320
									}
1321
								?>
1322
								</select>
1323
							</td>
1324
						</tr>
1325
						<tr>
1326
							<td valign="top" class="vncell"><?=gettext("MAC address"); ?></td>
1327
							<td class="vtable">
1328
								<input name="spoofmac" type="text" class="formfld unknown" id="spoofmac" size="30" value="<?=htmlspecialchars($pconfig['spoofmac']);?>">
1329
								<?php
1330
									$ip = getenv('REMOTE_ADDR');
1331
									$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
1332
									$mac = str_replace("\n","",$mac);
1333
									if($mac):
1334
								?>
1335
									<a OnClick="document.forms[0].spoofmac.value='<?=$mac?>';" href="#"><?=gettext("Insert my local MAC address"); ?></a>
1336
								<?php endif; ?>
1337
								<br>
1338
								<?=gettext("This field can be used to modify (\"spoof\") the MAC " .
1339
								"address of this interface"); ?><br>
1340
								<?=gettext("(may be required with some cable connections)"); ?><br>
1341
								<?=gettext("Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx " .
1342
								"or leave blank"); ?>
1343
							</td>
1344
						</tr>
1345
						<tr>
1346
							<td valign="top" class="vncell"><?=gettext("MTU"); ?></td>
1347
							<td class="vtable">
1348
								<input name="mtu" type="text" class="formfld unknown" id="mtu" size="8" value="<?=htmlspecialchars($pconfig['mtu']);?>">
1349
								<br>
1350
								<?=gettext("If you leave this field blank, the adapter's default MTU will " .
1351
								"be used. This is typically 1500 bytes but can vary in some circumstances."); ?>
1352
							</td>
1353
						</tr>
1354
						<tr>
1355
							<td valign="top" class="vncell"><?=gettext("MSS"); ?></td>
1356
							<td class="vtable">
1357
								<input name="mss" type="text" class="formfld unknown" id="mss" size="8" value="<?=htmlspecialchars($pconfig['mss']);?>">
1358
								<br>
1359
								<?=gettext("If you enter a value in this field, then MSS clamping for " .
1360
								"TCP connections to the value entered above minus 40 (TCP/IP " .
1361
								"header size) will be in effect."); ?>
1362
							</td>
1363
						</tr>
1364
						<?php 
1365
						if (count($mediaopts_list) > 0){
1366
						$mediaopt_from_config = $config['interfaces'][$if]['media'] . ' ' . $config['interfaces'][$if]['mediaopt'];
1367
						echo "<tr>";
1368
							echo '<td valign="top" class="vncell">' . gettext("Speed and duplex") . '</td>';
1369
							echo '<td class="vtable">';
1370
                                			echo '<div id="showadvmediabox"';
1371
								if ($mediaopt_from_config != 'autoselect ' && $mediaopt_from_config != ' ') echo " style='display:none'>";
1372
								else echo '>';
1373
								echo '<input type="button" onClick="show_advanced_media()" value="' . gettext("Advanced") . '"></input> - ' . gettext("Show advanced option");
1374
							echo "</div>";
1375
							echo '<div id="showmediaadv" ';
1376
							if ($mediaopt_from_config == 'autoselect ' || $mediaopt_from_config == ' ') echo "style='display:none'>";
1377
							else echo '>';
1378
								echo '<select name="mediaopt" class="formselect" id="mediaopt">';
1379
								print "<option value=\"\">Default (no preference, typically autoselect)</option>";
1380
								print "<option value=\"\">------- Media Supported by this interface -------</option>";
1381
								foreach($mediaopts_list as $mediaopt){
1382
									if ($mediaopt != rtrim($mediaopt_from_config)){
1383
										print "<option value=\"$mediaopt\">" . gettext("$mediaopt") . "</option>";
1384
									} else {
1385
										print "<option value=\"$mediaopt\" selected>" . gettext("$mediaopt") . "</option>";
1386
									}
1387
								}
1388
								echo '</select><br>';
1389
								echo gettext("Here you can explicitly set speed and duplex mode for this interface. WARNING: You MUST leave this set to autoselect (automatically negotiate speed) unless the port this interface connects to has its speed and duplex forced.");
1390
						echo '</div>';
1391
							echo '</td>';
1392
						echo '</tr>';
1393
						}
1394
						?>
1395
						<tr>
1396
							<td colspan="2" valign="top" height="16"></td>
1397
						</tr>
1398
						<tr style="display:none;" name="none" id="none">
1399
						</tr>
1400
						<tr style="display:none;" name="staticv4" id="staticv4">
1401
							<td colspan="2" style="padding:0px;">
1402
								<table width="100%" border="0" cellpadding="6" cellspacing="0">
1403
									<tr>
1404
										<td colspan="2" valign="top" class="listtopic"><?=gettext("Static IPv4 configuration"); ?></td>
1405
									</tr>
1406
									<tr>
1407
										<td width="22%" valign="top" class="vncellreq"><?=gettext("IPv4 address"); ?></td>
1408
										<td width="78%" class="vtable">
1409
											<input name="ipaddr" type="text" class="formfld unknown" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>">
1410
											/
1411
											<select name="subnet" class="formselect" id="subnet">
1412
												<?php
1413
												for ($i = 32; $i > 0; $i--) {
1414
													if($i <> 31) {
1415
														echo "<option value=\"{$i}\" ";
1416
														if ($i == $pconfig['subnet']) echo "selected";
1417
														echo ">" . $i . "</option>";
1418
													}
1419
												}
1420
												?>
1421
											</select>
1422
										</td>
1423
									</tr>
1424
									<tr>
1425
										<td width="22%" valign="top" class="vncell"><?=gettext("Gateway"); ?></td>
1426
										<td width="78%" class="vtable">
1427
											<select name="gateway" class="formselect" id="gateway">
1428
												<option value="none" selected><?=gettext("None"); ?></option>
1429
													<?php
1430
													if(count($a_gateways) > 0) {
1431
														foreach ($a_gateways as $gateway) {
1432
															if(($gateway['interface'] == $if)  && (is_ipaddrv4($gateway['gateway']))) {
1433
													?>
1434
															<option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gateway']) echo "selected"; ?>>
1435
																<?=htmlspecialchars($gateway['name']) . " - " . htmlspecialchars($gateway['gateway']);?>
1436
															</option>
1437
													<?php
1438
															}
1439
														}
1440
													}
1441
													?>
1442
											</select>
1443
											- or  <strong><a OnClick="show_add_gateway();" href="#"><?=gettext("add a new one."); ?></a></strong>
1444
											<br/>
1445
											<div id='addgwbox'>
1446
												<?=gettext("If this interface is an Internet connection, select an existing Gateway from the list or add one using the link above"); ?>
1447
											</div>
1448
											<div id='notebox'>
1449
											</div>
1450
											<div id="status">
1451
											</div>
1452
											<div style="display:none" id="addgateway" name="addgateway">
1453
												<p>
1454
												<table border="1" style="background:#990000; border-style: none none none none; width:225px;">
1455
													<tr>
1456
														<td>
1457
															<table bgcolor="#990000" cellpadding="1" cellspacing="1">
1458
																<tr><td>&nbsp;</td>
1459
																<tr>
1460
																	<td colspan="2"><center><b><font color="white"><?=gettext("Add new gateway:"); ?></font></b></center></td>
1461
																</tr>
1462
																<tr><td>&nbsp;</td>
1463
																<?php
1464
																if($if == "wan" || $if == "WAN")
1465
																	$checked = " CHECKED";
1466
																?>
1467
																<tr>
1468
																	<td width="45%" align="right"><font color="white"><?=gettext("Default  gateway:"); ?></td><td><input type="checkbox" id="defaultgw" name="defaultgw"<?=$checked?>></td>
1469
																</tr>
1470
																<tr>
1471
																	<td align="right"><font color="white"><?=gettext("Gateway Name:"); ?></td><td><input id="name" name="name" value="<?=$wancfg['descr'] . "GW"?>"></td>
1472
																</tr>
1473
																<tr>
1474
																	<td align="right"><font color="white"><?=gettext("Gateway IPv4:"); ?></td><td><input id="gatewayip" name="gatewayip"></td>
1475
																</tr>
1476
																<tr>
1477
																	<td align="right"><font color="white"><?=gettext("Description:"); ?></td><td><input id="gatewaydescr" name="gatewaydescr"></td>
1478
																</tr>
1479
																<tr><td>&nbsp;</td>
1480
																<tr>
1481
																	<td>&nbsp;</td>
1482
																	<td>
1483
																		<center>
1484
																			<div id='savebuttondiv'>
1485

    
1486

    
1487
																				<input id="gwsave" type="Button" value="<?=gettext("Save Gateway"); ?>" onClick='hide_add_gatewaysave();'>
1488
																				<input id="gwcancel" type="Button" value="<?=gettext("Cancel"); ?>" onClick='hide_add_gateway();'>
1489
																			</div>
1490
																		</center>
1491
																	</td>
1492
																</tr>
1493
																<tr><td>&nbsp;</td></tr>
1494
															</table>
1495
														</td>
1496
													</tr>
1497
												</table>
1498
												<p/>
1499
											</div>
1500
										</td>
1501
									</tr>
1502
								</table>
1503
							</td>
1504
						</tr>
1505
						<tr style="display:none;" name="staticv6" id="staticv6">
1506
							<td colspan="2" style="padding:0px;">
1507
								<table width="100%" border="0" cellpadding="6" cellspacing="0">
1508
									<tr>
1509
										<td colspan="2" valign="top">&nbsp;</td>
1510
									</tr>
1511
									<tr>
1512
										<td colspan="2" valign="top" class="listtopic"><?=gettext("Static IPv6 configuration"); ?></td>
1513
									</tr>
1514
									<tr>
1515
										<td width="22%" valign="top" class="vncellreq"><?=gettext("IPv6 address"); ?></td>
1516
										<td width="78%" class="vtable">
1517
											<input name="ipaddrv6" type="text" class="formfld unknown" id="ipaddrv6" size="28" value="<?=htmlspecialchars($pconfig['ipaddrv6']);?>">
1518
											/
1519
											<select name="subnetv6" class="formselect" id="subnetv6">
1520
												<?php
1521
												for ($i = 128; $i > 0; $i--) {
1522
													if($i <> 127) {
1523
														echo "<option value=\"{$i}\" ";
1524
														if ($i == $pconfig['subnetv6']) echo "selected";
1525
														echo ">" . $i . "</option>";
1526
													}
1527
												}
1528
												?>
1529
											</select>
1530
										</td>
1531
									</tr>
1532
									<tr>
1533
										<td width="22%" valign="top" class="vncell"><?=gettext("Gateway IPv6"); ?></td>
1534
										<td width="78%" class="vtable">
1535
											<select name="gatewayv6" class="formselect" id="gatewayv6">
1536
												<option value="none" selected><?=gettext("None"); ?></option>
1537
													<?php
1538
													if(count($a_gateways) > 0) {
1539
														foreach ($a_gateways as $gateway) {
1540
															if(($gateway['interface'] == $if) && (is_ipaddrv6($gateway['gateway']))) {
1541
													?>
1542
															<option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gatewayv6']) echo "selected"; ?>>
1543
																<?=htmlspecialchars($gateway['name']) . " - " . htmlspecialchars($gateway['gateway']);?>
1544
															</option>
1545
													<?php
1546
															}
1547
														}
1548
													}
1549
													?>
1550
											</select>
1551
											- or <strong><a OnClick="show_add_gateway_v6();" href="#"><?=gettext("add a new one."); ?></a></strong>
1552
											<br/>
1553
											<div id='addgwboxv6'>
1554
											<?=gettext("If this interface is an Internet connection, select an existing Gateway from the list or add a new one using the link above"); ?>
1555
											</div>
1556
											<div id='noteboxv6'>
1557
											</div>
1558
											<div id="statusv6">
1559
											</div>
1560
											<div style="display:none" id="addgatewayv6" name="addgatewayv6">
1561
												<p>
1562
												<table border="1" style="background:#990000; border-style: none none none none; width:225px;">
1563
													<tr>
1564
														<td>
1565
															<table bgcolor="#990000" cellpadding="1" cellspacing="1">
1566
																<tr><td>&nbsp;</td>
1567
																<tr>
1568
																	<td colspan="2"><center><b><font color="white"><?=gettext("Add new v6 gateway:"); ?></font></b></center></td>
1569
																</tr>
1570
																<tr><td>&nbsp;</td>
1571
																<?php
1572
																if($if == "wan" || $if == "WAN")
1573
																	$checked = " CHECKED";
1574
																?>
1575
																<tr>
1576
																	<td width="45%" align="right"><font color="white"><?=gettext("Default v6 gateway:"); ?></td><td><input type="checkbox" id="defaultgwv6" name="defaultgwv6"<?=$checked?>></td>
1577
																</tr>
1578
																<tr>
1579
																	<td align="right"><font color="white"><?=gettext("Gateway Name IPv6:"); ?></td><td><input id="namev6" name="namev6" value="<?=$wancfg['descr'] . "GWv6"?>"></td>
1580
																</tr>
1581
																<tr>
1582
																	<td align="right"><font color="white"><?=gettext("Gateway IPv6:"); ?></td><td><input id="gatewayipv6" name="gatewayipv6"></td>
1583
																</tr>
1584
																<tr>
1585
																	<td align="right"><font color="white"><?=gettext("Description:"); ?></td><td><input id="gatewaydescrv6" name="gatewaydescrv6"></td>
1586
																</tr>
1587
																<tr><td>&nbsp;</td>
1588
																<tr>
1589
																	<td>&nbsp;</td>
1590
																	<td>
1591
																		<center>
1592
																			<div id='savebuttondivv6'>
1593
																				<input id="gwsavev6" type="Button" value="<?=gettext("Save Gateway"); ?>" onClick='hide_add_gatewaysave_v6();'>
1594
																				<input id="gwcancelv6" type="Button" value="<?=gettext("Cancel"); ?>" onClick='hide_add_gateway_v6();'>
1595
																			</div>
1596
																		</center>
1597
																	</td>
1598
																</tr>
1599
																<tr><td>&nbsp;</td></tr>
1600
															</table>
1601
														</td>
1602
													</tr>
1603
												</table>
1604
												<p/>
1605
											</div>
1606
										</td>
1607
									</tr>
1608
									<tr>
1609
										<td width="22%" valign="top" class="vncell"><?=gettext("DHCPv6 Prefix Delegation ID"); ?></td>
1610
										<td width="78%" class="vtable">
1611
											<select name="dhcp6-pd-sla-id" class="formselect" id="dhcp6-pd-sla-id">
1612
												<?php
1613
												// Needs to check if the ID is not used on another interface
1614
												foreach($ifdescrs as $pdif => $pddescr) {
1615
													if(is_numeric($config['interfaces'][$pdif]['dhcp6-ia-pd-len'])) {
1616
														$pdlen = $config['interfaces'][$pdif]['dhcp6-ia-pd-len'];
1617
														continue;
1618
													}
1619
												}
1620
												
1621
												if($pconfig['dhcp6-pd-sla-id'] == "none")
1622
													$selected = "selected";
1623
												echo "<option value=\"none\" {$selected}>". gettext("None") ."</option>\n";
1624
												$numbers = pow(2, $pdlen);
1625
												for($i = 0;$i < $numbers; $i++) {
1626
													echo "<option value=\"{$i}\" ";
1627
													if ("$i" == $pconfig['dhcp6-pd-sla-id']) {
1628
														echo "selected";
1629
													}
1630
													echo ">" . dechex($i) . "</option>";
1631
												}
1632
												?> 
1633
											</select>
1634
											<?=gettext("This ID sets the delegated DHCP-PD prefix number which will be used to setup the interface.");?>
1635
										</td>
1636
									</tr>
1637
									<tr>
1638
										<td width="22%" valign="top" class="vncell"><?=gettext("6RD Rapid Deployment network ID"); ?></td>
1639
										<td width="78%" class="vtable">
1640
											<select name="prefix-6rd-id" class="formselect" id="prefix-6rd-id">
1641
												<?php
1642
												// Needs to check if the ID is not used on another interface
1643
												foreach($ifdescrs as $rdif => $rddescr) {
1644
													if(is_numeric($config['interfaces'][$rdif]['prefix-6rd-v4plen'])) {
1645
														$rdlen = $config['interfaces'][$rdif]['prefix-6rd-v4plen'];
1646
														continue;
1647
													}
1648
												}
1649
												if($pconfig['prefix-6rd-id'] == "none")
1650
													$selected = "selected";
1651
												echo "<option value=\"none\" {$selected}>". gettext("None") ."</option>\n";
1652
												$numbers = pow(2, $rdlen);
1653
												for($i = 0;$i < $numbers; $i++) {
1654
													echo "<option value=\"{$i}\" ";
1655
													if ("$i" == $pconfig['prefix-6rd-id']) {
1656
														echo "selected";
1657
													}
1658
													echo ">" . dechex($i) . "</option>";
1659
												}
1660
												?> 
1661
											</select>
1662
											<?=gettext("This ID sets the 6RD network prefix which will be used to setup the interface.");?>
1663
										</td>
1664
									</tr>
1665
								</table>
1666
							</td>
1667
						</tr>
1668
						<tr style="display:none;" name="dhcp" id="dhcp">
1669
							<td colspan="2" style="padding: 0px;">
1670
								<table width="100%" border="0" cellpadding="6" cellspacing="0">
1671
									<tr>
1672
										<td colspan="2" valign="top" class="listtopic"><?=gettext("DHCP client configuration"); ?></td>
1673
									</tr>
1674
									<!-- Uncomment to expose DHCP+ in GUI
1675
									<tr>
1676
										<td width="22%" valign="top" class="vncell"><?=gettext("Enable DHCP+"); ?></td>
1677
										<td width="78%" class="vtable">
1678
											<input name="dhcp_plus" type="checkbox" value="yes" <?php if ($pconfig['dhcp_plus'] == true) echo "checked"; ?> >
1679
										<strong><?=gettext("Enable DHCP+L2TP or DHCP+PPTP."); ?></strong>
1680
										<br/>
1681
										<?=gettext("Status changes on this interface will trigger reconfiguration (if necessary) of the associated PPTP/L2TP link."); ?>
1682
										</td>
1683
									</tr>
1684
									-->
1685
									<tr>
1686
										<td width="22%" valign="top" class="vncell"><?=gettext("Hostname"); ?></td>
1687
										<td width="78%" class="vtable">
1688
											<input name="dhcphostname" type="text" class="formfld unknown" id="dhcphostname" size="40" value="<?=htmlspecialchars($pconfig['dhcphostname']);?>">
1689
											<br>
1690
											<?=gettext("The value in this field is sent as the DHCP client identifier " .
1691
											"and hostname when requesting a DHCP lease. Some ISPs may require " .
1692
											"this (for client identification)."); ?>
1693
										</td>
1694
									</tr>
1695
									<tr>
1696
										<td width="22%" valign="top" class="vncell"><?=gettext("Alias IPv4 address"); ?></td>
1697
										<td width="78%" class="vtable">
1698
											<input name="alias-address" type="text" class="formfld unknown" id="alias-address" size="20" value="<?=htmlspecialchars($pconfig['alias-address']);?>">
1699
											<select name="alias-subnet" class="formselect" id="alias-subnet">
1700
												<?php
1701
												for ($i = 32; $i > 0; $i--) {
1702
													if($i <> 31) {
1703
														echo "<option value=\"{$i}\" ";
1704
														if ($i == $pconfig['alias-subnet']) echo "selected";
1705
														echo ">" . $i . "</option>";
1706
													}
1707
												}
1708
												?>
1709
											</select>
1710
											<?=gettext("The value in this field is used as a fixed alias IPv4 address by the " .
1711
											"DHCP client."); ?>
1712
										</td>
1713
									</tr>									
1714
								</table>
1715
							</td>
1716
						</tr>
1717
						<tr style="display:none;" name="dhcp6" id="dhcp6">
1718
							<td colspan="2" style="padding: 0px;">
1719
								<table width="100%" border="0" cellpadding="6" cellspacing="0">
1720
									<tr>
1721
										<td colspan="2" valign="top" class="listtopic"><?=gettext("DHCP6 client configuration"); ?></td>
1722
									</tr>
1723
									<tr>
1724
										<td width="22%" valign="top" class="vncell"><?=gettext("DHCPv6 Unique Identifier (DUID)"); ?></td>
1725
										<td width="78%" class="vtable">
1726
											<input name="dhcp6-duid" type="text" class="formfld unknown" id="dhcp6-duid" size="40" value="<?=htmlspecialchars($pconfig['dhcp6-duid']);?>">
1727
											<br>
1728
											<?=gettext("The value in this field is sent as the DHCPv6 client identifier " .
1729
											"when requesting a DHCPv6 lease."); ?><br />
1730
											<?php	if(is_readable("/var/db/dhcp6c_duid")) {
1731
													// $current_duid = file_get_contents("/var/db/dhcp6c_duid");
1732
												}
1733
												printf(gettext("The current DUID is: '%s'"),$current_duid);
1734
											?>
1735
											
1736
										</td>
1737
									</tr>
1738
									<tr>
1739
										<td width="22%" valign="top" class="vncell"><?=gettext("DHCPv6 Prefix Delegation size"); ?></td>
1740
										<td width="78%" class="vtable">
1741
											<select name="dhcp6-ia-pd-len" class="formselect" id="dhcp6-ia-pd-len">
1742
												<?php
1743
												$sizes = array("none" => "None", 16 => "48", 12 => "52", 8 => "56", 4 => "60", 2 => "62", 1 => "63", 0 => "64");
1744
												foreach($sizes as $bits => $length) {
1745
													echo "<option value=\"{$bits}\" ";
1746
													if (is_numeric($pconfig['dhcp6-ia-pd-len']) && ($bits == $pconfig['dhcp6-ia-pd-len'])) echo "selected";
1747
													echo ">" . $length . "</option>";
1748
												}
1749
												?>
1750
											</select>
1751
											<br>
1752
											<?=gettext("The value in this field is the delegated prefix length provided by the DHCPv6 server. Normally specified by the ISP."); ?>
1753
										</td>
1754
									</tr>
1755
									
1756
								</table>
1757
							</td>
1758
						</tr>
1759
						<tr style="display:none;" name="srd" id="srd">
1760
							<td colspan="2" style="padding: 0px;">
1761
								<table width="100%" border="0" cellpadding="6" cellspacing="0">
1762
									<tr>
1763
										<td colspan="2" valign="top" class="listtopic"><?=gettext("6RD Rapid Deployment"); ?></td>
1764
									</tr>
1765
									<tr>
1766
										<td width="22%" valign="top" class="vncell"><?=gettext("6RD prefix"); ?></td>
1767
										<td width="78%" class="vtable">
1768
											<input name="prefix-6rd" type="text" class="formfld unknown" id="prefix-6rd" size="40" value="<?=htmlspecialchars($pconfig['prefix-6rd']);?>">
1769
											<br>
1770
											<?=gettext("The value in this field is the 6RD IPv6 prefix assigned by your ISP. e.g. '2001:db8::/32'") ?><br />
1771
										</td>
1772
									</tr>
1773
									<tr>
1774
										<td width="22%" valign="top" class="vncell"><?=gettext("6RD Border Relay"); ?></td>
1775
										<td width="78%" class="vtable">
1776
											<input name="gateway-6rd" type="text" class="formfld unknown" id="gateway-6rd" size="40" value="<?=htmlspecialchars($pconfig['gateway-6rd']);?>">
1777
											<br>
1778
											<?=gettext("The value in this field is 6RD IPv4 gateway address assigned by your ISP") ?><br />
1779
										</td>
1780
									</tr>
1781
									<tr>
1782
										<td width="22%" valign="top" class="vncell"><?=gettext("6RD IPv4 Prefix length"); ?></td>
1783
										<td width="78%" class="vtable">
1784
											<select name="prefix-6rd-v4plen" class="formselect" id="prefix-6rd-v4plen">
1785
												<?php
1786
												for ($i = 0; $i < 32; $i++) {
1787
													echo "<option value=\"{$i}\" ";
1788
													if (is_numeric($pconfig['prefix-6rd-v4plen']) && ($i == $pconfig['prefix-6rd-v4plen'])) echo "selected";
1789
													echo ">" . $i . " bits</option>";
1790
												}
1791
												?>
1792
											</select>
1793
											<br>
1794
											<?=gettext("The value in this field is the 6RD IPv4 prefix length. Normally specified by the ISP. A value of 0 means we embed the entire IPv4 address in the 6RD prefix."); ?>
1795
										</td>
1796
									</tr>
1797
									
1798
								</table>
1799
							</td>
1800
						</tr>
1801
						<tr style="display:none;" name="ppp" id="ppp">
1802
							<td colspan="2" style="padding: 0px;">
1803
								<table width="100%" border="0" cellpadding="6" cellspacing="0">
1804
									<tr>
1805
										<td colspan="2" valign="top" class="listtopic"><?=gettext("PPP configuration"); ?></td>
1806
									</tr>
1807
									<tr name="ppp_provider" id="ppp_provider">
1808
										<td width="22%" valign="top" class="vncell"><?=gettext("Service Provider"); ?></td>
1809
										<td width="78%" class="vtable">
1810
											<table border="0" cellpadding="0" cellspacing="0">
1811
												<tr id="trcountry">
1812
													<td><?=gettext("Country:"); ?> &nbsp;&nbsp;</td>
1813
													<td>
1814
														<select class="formselect" name="country" id="country" onChange="providers_list()">
1815
															<option></option>
1816
														</select>
1817
													</td>
1818
												</tr>
1819
												<tr id="trprovider" style="display:none">
1820
													<td><?=gettext("Provider:"); ?> &nbsp;&nbsp;</td>
1821
													<td>
1822
														<select class="formselect" name="provider" id="provider" onChange="providerplan_list()">
1823
															<option></option>
1824
														</select>
1825
													</td>
1826
												</tr>
1827
												<tr id="trproviderplan" style="display:none">
1828
													<td><?=gettext("Plan:"); ?> &nbsp;&nbsp;</td>
1829
													<td>
1830
														<select class="formselect" name="providerplan" id="providerplan" onChange="prefill_provider()">
1831
															<option></option>
1832
														</select>
1833
													</td>
1834
												</tr>
1835
											</table>
1836
											<br/><span class="vexpl"><?=gettext("Select to fill in data for your service provider."); ?></span>
1837
										</td>
1838
									</tr>
1839
									<tr>
1840
										<td width="22%" valign="top" class="vncell"><?=gettext("Username"); ?></td>
1841
										<td width="78%" class="vtable">
1842
										<input name="username" type="text" class="formfld user" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>">
1843
										</td>
1844
									</tr>
1845
									<tr>
1846
										<td width="22%" valign="top" class="vncell"><?=gettext("Password"); ?></td>
1847
										<td width="78%" class="vtable">
1848
										<input name="password" type="password" class="formfld pwd" id="password" size="20" value="<?=htmlspecialchars($pconfig['password']);?>">
1849
										</td>
1850
									</tr>
1851
									<tr name="phone_num" id="phone_num">
1852
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Phone Number"); ?></td>
1853
										<td width="78%" class="vtable">
1854
											<input name="phone" type="text" class="formfld unknown" id="phone" size="12" value="<?=htmlspecialchars($pconfig['phone']);?>">
1855
										</td>
1856
									</tr>
1857
									<tr name="apn_" id="apn_">
1858
										<td width="22%" valign="top" class="vncell"><?=gettext("Access Point Name (APN)"); ?></td>
1859
										<td width="78%" class="vtable">
1860
											<input name="apn" type="text" class="formfld unknown" id="apn" size="40" value="<?=htmlspecialchars($pconfig['apn']);?>">
1861
										</td>
1862
									</tr>
1863
									<tr name="interface" id="interface" >
1864
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Modem Port"); ?></td>
1865
										<td width="78%" class="vtable">
1866
											<select name="port" id="port" class="formselect">
1867
											<?php
1868
												$portlist = glob("/dev/cua*");
1869
												$modems = glob("/dev/modem*");
1870
												$portlist = array_merge($portlist, $modems);
1871
												foreach ($portlist as $port) {
1872
													if(preg_match("/\.(lock|init)$/", $port))
1873
														continue;
1874
													echo "<option value=\"".trim($port)."\"";
1875
													if ($pconfig['port'] == $port)
1876
														echo "selected";
1877
													echo ">{$port}</option>";
1878
												}?>
1879
											</select>
1880
										</td>
1881
									</tr>
1882
									<td width="22%" valign="top" class="vncell"><?=gettext("Advanced PPP"); ?></td>
1883
										<?php if (isset($pconfig['pppid'])): ?>
1884
											<td width="78%" class="vtable">
1885
											<a href="/interfaces_ppps_edit.php?id=<?=htmlspecialchars($pconfig['pppid']);?>" class="navlnk"><?=gettext("Click here"); ?> </a>
1886
											<?=gettext("to edit PPP configuration."); ?>
1887
											</td>
1888
										<?php else: ?>
1889
											<td width="78%" class="vtable">
1890
											<a href="/interfaces_ppps_edit.php" class="navlnk"><?=gettext("Click here"); ?> </a>
1891
											<?=gettext("to create a PPP configuration."); ?>
1892
											</td>
1893
										<?php endif; ?>
1894
									</tr>
1895
								</table>
1896
							</td>
1897
						</tr>
1898
						<tr style="display:none;" name="pppoe" id="pppoe">
1899
							<td colspan="2" style="padding:0px;">
1900
								<table width="100%" border="0" cellpadding="6" cellspacing="0">
1901
									<tr>
1902
										<td colspan="2" valign="top" class="listtopic"><?=gettext("PPPoE configuration"); ?></td>
1903
									</tr>
1904
									<tr>
1905
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Username"); ?></td>
1906
										<td width="78%" class="vtable">
1907
												<input name="pppoe_username" type="text" class="formfld user" id="pppoe_username" size="20" value="<?=htmlspecialchars($pconfig['pppoe_username']);?>">
1908
										</td>
1909
									</tr>
1910
									<tr>
1911
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Password"); ?></td>
1912
										<td width="78%" class="vtable">
1913
											<input name="pppoe_password" type="password" class="formfld pwd" id="pppoe_password" size="20" value="<?=htmlspecialchars($pconfig['pppoe_password']);?>">
1914
										</td>
1915
									</tr>
1916
									<tr>
1917
										<td width="22%" valign="top" class="vncell"><?=gettext("Service name"); ?></td>
1918
										<td width="78%" class="vtable"><input name="provider" type="text" class="formfld unknown" id="provider" size="20" value="<?=htmlspecialchars($pconfig['provider']);?>">
1919
											<br> <span class="vexpl"><?=gettext("Hint: this field can usually be left empty"); ?></span>
1920
										</td>
1921
									</tr>
1922
									<tr>
1923
										<td width="22%" valign="top" class="vncell"><?=gettext("Dial on demand"); ?></td>
1924
										<td width="78%" class="vtable">
1925
											<input name="pppoe_dialondemand" type="checkbox" id="pppoe_dialondemand" value="enable" <?php if ($pconfig['pppoe_dialondemand']) echo "checked"; ?>>
1926
											<strong><?=gettext("Enable Dial-On-Demand mode"); ?></strong><br>
1927
											<?=gettext("This option causes the interface to operate in dial-on-demand mode, allowing you to have a "); ?><i><?=gettext("virtual full time"); ?></i> <?=gettext("connection. The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected."); ?>
1928
										</td>
1929
									</tr>
1930
									<tr>
1931
										<td width="22%" valign="top" class="vncell"><?=gettext("Idle timeout"); ?></td>
1932
										<td width="78%" class="vtable">
1933
											<input name="pppoe_idletimeout" type="text" class="formfld unknown" id="pppoe_idletimeout" size="8" value="<?=htmlspecialchars($pconfig['pppoe_idletimeout']);?>"> <?=gettext("seconds"); ?><br><?=gettext("If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. An idle timeout of zero disables this feature."); ?>
1934
										</td>
1935
									</tr>
1936
									<tr>
1937
										<td width="22%" valign="top" class="vncell"><?=gettext("Periodic reset");?></td>
1938
										<td width="78%" class="vtable">
1939
											<table id="presetwrap" cellspacing="0" cellpadding="0" width="100%">
1940
												<tr>
1941
													<td align="left" valign="top">
1942
														<p style="margin: 4px; padding: 4px 0 4px 0; width: 94%;">
1943
														<select valign="top" id="reset_type" name="pppoe-reset-type" class="formselect" onChange="show_reset_settings(this.value);">
1944
															<option value = ""><?=gettext("Disabled"); ?></option>
1945
															<option value="custom" <?php if ($pconfig['pppoe-reset-type'] == "custom") echo "selected"; ?>><?=gettext("Custom"); ?></option>
1946
															<option value="preset" <?php if ($pconfig['pppoe-reset-type'] == "preset") echo "selected"; ?>><?=gettext("Pre-Set"); ?></option>
1947
														</select> <?=gettext("Select a reset timing type"); ?>
1948
														</p>
1949
														<?php if ($pconfig['pppoe_pr_custom']): ?>
1950
															<p style="margin: 2px; padding: 4px; width: 94%;" id="pppoecustomwrap">
1951
														<?php else: ?>
1952
															<p style="margin: 2px; padding: 4px; width: 94%; display: none;" id="pppoecustomwrap">
1953
														<?php endif; ?>
1954
														<input type="text" name="pppoe_resethour" class="fd_incremental_inp_range_0_23 fd_increment_1 fd_classname_dec_buttonDec fd_classname_inc_buttonInc" maxlength="2" id="pppoe_resethour" value="<?= $pconfig['pppoe_resethour']; ?>" size="3" />
1955
														<?=gettext("hour (0-23)"); ?><br />
1956
														<input type="text" name="pppoe_resetminute" class="fd_incremental_inp_range_0_59 fd_increment_1 fd_classname_dec_buttonDec fd_classname_inc_buttonInc" maxlength="2" id="pppoe_resetminute" value="<?= $pconfig['pppoe_resetminute']; ?>" size="3" />
1957
														<?=gettext("minute (0-59)"); ?><br />
1958
														<input name="pppoe_resetdate" type="text" class="w8em format-m-d-y highlight-days-67" id="pppoe_resetdate" maxlength="10" size="10" value="<?=htmlspecialchars($pconfig['pppoe_resetdate']);?>" />
1959
														<?=gettext("reset at a specific date (mm/dd/yyyy)"); ?>
1960
														<br />&nbsp;<br />
1961
														<span class="red"><strong><?=gettext("Note:"); ?> </strong></span>
1962
														<?=gettext("If you leave the date field empty, the reset will be executed each day at the time you did specify using the minutes and hour field."); ?>
1963
														</p>
1964
														<?php if ($pconfig['pppoe_pr_preset']): ?>
1965
															<p style="margin: 2px; padding: 4px; width: 94%;" id="pppoepresetwrap">
1966
														<?php else: ?>
1967
															<p style="margin: 2px; padding: 4px; width: 94%; display: none;" id="pppoepresetwrap">
1968
														<?php endif; ?>
1969
														<input name="pppoe_pr_preset_val" type="radio" id="pppoe_monthly" value="monthly" <?php if ($pconfig['pppoe_monthly']) echo "checked=\"checked\""; ?> />
1970
														<?=gettext("reset at each month ('0 0 1 * *')"); ?>
1971
														<br />
1972
														<input name="pppoe_pr_preset_val" type="radio" id="pppoe_weekly" value="weekly" <?php if ($pconfig['pppoe_weekly']) echo "checked=\"checked\""; ?> />
1973
														<?=gettext("reset at each week ('0 0 * * 0')"); ?>
1974
														<br />
1975
														<input name="pppoe_pr_preset_val" type="radio" id="pppoe_daily" value="daily" <?php if ($pconfig['pppoe_daily']) echo "checked=\"checked\""; ?> />
1976
														<?=gettext("reset at each day ('0 0 * * *')"); ?>
1977
														<br />
1978
														<input name="pppoe_pr_preset_val" type="radio" id="pppoe_hourly" value="hourly" <?php if ($pconfig['pppoe_hourly']) echo "checked=\"checked\""; ?> />
1979
														<?=gettext("reset at each hour ('0 * * * *')"); ?>
1980
														</p>
1981
													</td>
1982
												</tr>
1983
											</table>
1984
										</td>
1985
									</tr>
1986

    
1987
									<tr>
1988
										<td width="22%" valign="top" class="vncell"><?=gettext("Advanced and MLPPP"); ?></td>
1989
										<?php if (isset($pconfig['pppid'])): ?>
1990
											<td width="78%" class="vtable">
1991
											<a href="/interfaces_ppps_edit.php?id=<?=htmlspecialchars($pconfig['pppid']);?>" class="navlnk"><?=gettext("Click here"); ?> </a>
1992
											<?=gettext("for additional PPPoE configuration options. Save first if you made changes."); ?>
1993
											</td>
1994
										<?php else: ?>
1995
											<td width="78%" class="vtable">
1996
											<a href="/interfaces_ppps_edit.php" class="navlnk"><?=gettext("Click here"); ?> </a>
1997
											<?=gettext("for advanced PPPoE configuration options and MLPPP configuration."); ?>
1998
											</td>
1999
										<?php endif; ?>
2000
									</tr>
2001
								</table>
2002
							</td>
2003
						</tr>
2004
						<tr style="display:none;" name="pptp" id="pptp">
2005
							<td colspan="2" style="padding:0px;">
2006
								<table width="100%" border="0" cellpadding="6" cellspacing="0">
2007
									<tr>
2008
										<td colspan="2" valign="top" class="listtopic"><?=gettext("PPTP/L2TP configuration"); ?></td>
2009
									</tr>
2010
									<tr>
2011
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Username"); ?></td>
2012
										<td width="78%" class="vtable">
2013
											<input name="pptp_username" type="text" class="formfld user" id="pptp_username" size="20" value="<?=htmlspecialchars($pconfig['pptp_username']);?>">
2014
										</td>
2015
									</tr>
2016
									<tr>
2017
										<td width="22%" valign="top" class="vncellreq"><?=gettext("Password"); ?></td>
2018
										<td width="78%" class="vtable">
2019
											<input name="pptp_password" type="password" class="formfld pwd" id="pptp_password" size="20" value="<?=htmlspecialchars($pconfig['pptp_password']);?>">
2020
										</td>
2021
									</tr>
2022
									<tr>
2023
										<td width="22%" width="100" valign="top" class="vncellreq"><?=gettext("Local IP address"); ?></td>
2024
										<td width="78%" class="vtable">
2025
											<input name="pptp_local" type="text" class="formfld unknown" id="pptp_local" size="20"  value="<?=htmlspecialchars($pconfig['pptp_local'][0]);?>">
2026
											/
2027
											<select name="pptp_subnet" class="formselect" id="pptp_subnet">
2028
												<?php for ($i = 31; $i > 0; $i--): ?>
2029
													<option value="<?=$i;?>" <?php if ($i == $pconfig['pptp_subnet'][0]) echo "selected"; ?>>
2030
														<?=$i;?></option>
2031
												<?php endfor; ?>
2032
											</select>
2033
										</td>
2034
									</tr>
2035
									<tr>
2036
										<td width="22%" width="100" valign="top" class="vncellreq"><?=gettext("Remote IP address"); ?></td>
2037
										<td width="78%" class="vtable">
2038
											<input name="pptp_remote" type="text" class="formfld unknown" id="pptp_remote" size="20" value="<?=htmlspecialchars($pconfig['pptp_remote'][0]);?>">
2039
										</td>
2040
									</tr>
2041
									<tr>
2042
										<td width="22%" valign="top" class="vncell"><?=gettext("Dial on demand"); ?></td>
2043
										<td width="78%" class="vtable">
2044
											<input name="pptp_dialondemand" type="checkbox" id="pptp_dialondemand" value="enable" <?php if ($pconfig['pptp_dialondemand']) echo "checked"; ?>>
2045
											<strong><?=gettext("Enable Dial-On-Demand mode"); ?></strong><br>
2046
											<?=gettext("This option causes the interface to operate in dial-on-demand mode, allowing you to have a"); ?> <i><?=gettext("virtual full time"); ?></i> <?=gettext("connection. The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected."); ?>
2047
										</td>
2048
									</tr>
2049
									<tr>
2050
										<td width="22%" valign="top" class="vncell"><?=gettext("Idle timeout"); ?></td>
2051
										<td width="78%" class="vtable">
2052
											<input name="pptp_idletimeout" type="text" class="formfld unknown" id="pptp_idletimeout" size="8" value="<?=htmlspecialchars($pconfig['pptp_idletimeout']);?>"> <?=gettext("seconds"); ?><br><?=gettext("If no qualifying outgoing packets are transmitted for the specified number of seconds, the connection is brought down. An idle timeout of zero disables this feature."); ?>
2053
										</td>
2054
									</tr>
2055
									<tr>
2056
										<td width="22%" valign="top" class="vncell"><?=gettext("Advanced"); ?></td>
2057
										<?php if (isset($pconfig['pppid'])): ?>
2058
											<td width="78%" class="vtable">
2059
											<a href="/interfaces_ppps_edit.php?id=<?=htmlspecialchars($pconfig['pppid']);?>" class="navlnk"><?=gettext("Click here");?></a>
2060
											<?=gettext("for additional PPTP and L2TP configuration options. Save first if you made changes.");?>
2061
											</td>
2062
										<?php else: ?>
2063
											<td width="78%" class="vtable">
2064
											<a href="/interfaces_ppps_edit.php" class="navlnk"><?=gettext("Click here");?></a>
2065
											<?=gettext("for advanced PPTP and L2TP configuration options");?>.
2066
											</td>
2067
										<?php endif; ?>
2068
									</tr>
2069
								</table>
2070
							</td>
2071
						</tr>
2072
						<?php
2073
							/* Wireless interface? */
2074
							if (isset($wancfg['wireless'])):
2075
						?>
2076
						<tr>
2077
							<td colspan="2" valign="top" height="16"></td>
2078
						</tr>
2079
						<tr>
2080
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Common wireless configuration - Settings apply to all wireless networks on"); ?> <?=$wlanbaseif;?>.</td>
2081
						</tr>
2082
						<tr>
2083
							<td valign="top" class="vncell"><?=gettext("Persist common settings");?></td>
2084
							<td class="vtable">
2085
								<input name="persistcommonwireless" type="checkbox" value="yes"  class="formfld" id="persistcommonwireless" <?php if ($pconfig['persistcommonwireless']) echo "checked";?>>
2086
								<br/><?=gettext("Enabling this preserves the common wireless configuration through interface deletions and reassignments.");?>
2087
							</td>
2088
						</tr>
2089
						<tr>
2090
							<td valign="top" class="vncellreq"><?=gettext("Standard"); ?></td>
2091
							<td class="vtable">
2092
							<select name="standard" class="formselect" id="standard">
2093
								<?php
2094
								foreach($wl_modes as $wl_standard => $wl_channels) {
2095
									echo "<option ";
2096
									if ($pconfig['standard'] == "$wl_standard")
2097
										echo "selected ";
2098
									echo "value=\"$wl_standard\">802.$wl_standard</option>\n";
2099
								}
2100
								?>
2101
							</select>
2102
							</td>
2103
						</tr>
2104
						<?php if (isset($wl_modes['11g'])): ?>
2105
						<tr>
2106
							<td valign="top" class="vncellreq">802.11g OFDM <?=gettext("Protection Mode"); ?></td>
2107
							<td class="vtable">
2108
								<select name="protmode" class="formselect" id="protmode">
2109
									<option <?php if ($pconfig['protmode'] == 'off') echo "selected";?> value="off"><?=gettext("Protection mode off"); ?></option>
2110
									<option <?php if ($pconfig['protmode'] == 'cts') echo "selected";?> value="cts"><?=gettext("Protection mode CTS to self"); ?></option>
2111
									<option <?php if ($pconfig['protmode'] == 'rtscts') echo "selected";?> value="rtscts"><?=gettext("Protection mode RTS and CTS"); ?></option>
2112
								</select>
2113
								<br/>
2114
								<?=gettext("For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network."); ?>
2115
								<br/>
2116
							</td>
2117
						</tr>
2118
						<?php else: ?>
2119
						<input name="protmode" type="hidden" id="protmode" value="off">
2120
						<?php endif; ?>
2121
						<tr>
2122
							<td valign="top" class="vncellreq"><?=gettext("Transmit power"); ?></td>
2123
							<td class="vtable">
2124
								<select name="txpower" class="formselect" id="txpower">
2125
									<?
2126
									for($x = 99; $x > 0; $x--) {
2127
										if($pconfig["txpower"] == $x)
2128
											$SELECTED = " SELECTED";
2129
										else
2130
											$SELECTED = "";
2131
										echo "<option {$SELECTED}>{$x}</option>\n";
2132
									}
2133
									?>
2134
								</select><br/>
2135
								<?=gettext("Note: Typically only a few discreet power settings are available and the driver will use the setting closest to the specified value.  Not all adapters support changing the transmit power setting."); ?>
2136
							</td>
2137
						</tr>
2138
						<tr>
2139
							<td valign="top" class="vncellreq"><?=gettext("Channel"); ?></td>
2140
							<td class="vtable">
2141
								<select name="channel" class="formselect" id="channel">
2142
									<option <?php if ($pconfig['channel'] == 0) echo "selected"; ?> value="0"><?=gettext("Auto"); ?></option>
2143
									<?php
2144
									foreach($wl_modes as $wl_standard => $wl_channels) {
2145
										if($wl_standard == "11g") { $wl_standard = "11b/g"; }
2146
										else if($wl_standard == "11ng") { $wl_standard = "11b/g/n"; }
2147
										else if($wl_standard == "11na") { $wl_standard = "11a/n"; }
2148
										foreach($wl_channels as $wl_channel) {
2149
											echo "<option ";
2150
											if ($pconfig['channel'] == "$wl_channel") {
2151
												echo "selected ";
2152
											}
2153
											echo "value=\"$wl_channel\">$wl_standard - $wl_channel";
2154
											if(isset($wl_chaninfo[$wl_channel]))
2155
												echo " ({$wl_chaninfo[$wl_channel][1]} @ {$wl_chaninfo[$wl_channel][2]} / {$wl_chaninfo[$wl_channel][3]})";
2156
											echo "</option>\n";
2157
										}
2158
									}
2159
									?>
2160
								</select>
2161
								<br/>
2162
								<?=gettext("Legend: wireless standards - channel # (frequency @ max TX power / TX power allowed in reg. domain)"); ?>
2163
								<br/>
2164
								<?=gettext("Note: Not all channels may be supported by your card.  Auto may override the wireless standard selected above."); ?>
2165
							</td>
2166
						</tr>
2167
						<?php if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"]) || isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])): ?>
2168
						<tr>
2169
							<td valign="top" class="vncell"><?=gettext("Antenna settings"); ?></td>
2170
							<td class="vtable">
2171
								<table border="0" cellpadding="0" cellspacing="0">
2172
									<tr>
2173
										<?php if (isset($wl_sysctl["{$wl_sysctl_prefix}.diversity"])): ?>
2174
										<td>
2175
											<?=gettext("Diversity"); ?><br/>
2176
											<select name="diversity" class="formselect" id="diversity">
2177
												<option <?php if (!isset($pconfig['diversity'])) echo "selected"; ?> value=""><?=gettext("Default"); ?></option>
2178
												<option <?php if ($pconfig['diversity'] === '0') echo "selected"; ?> value="0"><?=gettext("Off"); ?></option>
2179
												<option <?php if ($pconfig['diversity'] === '1') echo "selected"; ?> value="1"><?=gettext("On"); ?></option>
2180
											</select>
2181
										</td>
2182
										<td>&nbsp;&nbsp</td>
2183
										<?php endif; ?>
2184
										<?php if (isset($wl_sysctl["{$wl_sysctl_prefix}.txantenna"])): ?>
2185
										<td>
2186
											<?=gettext("Transmit antenna"); ?><br/>
2187
											<select name="txantenna" class="formselect" id="txantenna">
2188
												<option <?php if (!isset($pconfig['txantenna'])) echo "selected"; ?> value=""><?=gettext("Default"); ?></option>
2189
												<option <?php if ($pconfig['txantenna'] === '0') echo "selected"; ?> value="0"><?=gettext("Auto"); ?></option>
2190
												<option <?php if ($pconfig['txantenna'] === '1') echo "selected"; ?> value="1"><?=gettext("#1"); ?></option>
2191
												<option <?php if ($pconfig['txantenna'] === '2') echo "selected"; ?> value="2"><?=gettext("#2"); ?></option>
2192
											</select>
2193
										</td>
2194
										<td>&nbsp;&nbsp</td>
2195
										<?php endif; ?>
2196
										<?php if (isset($wl_sysctl["{$wl_sysctl_prefix}.rxantenna"])): ?>
2197
										<td>
2198
											<?=gettext("Receive antenna"); ?><br/>
2199
											<select name="rxantenna" class="formselect" id="rxantenna">
2200
												<option <?php if (!isset($pconfig['rxantenna'])) echo "selected"; ?> value=""><?=gettext("Default"); ?></option>
2201
												<option <?php if ($pconfig['rxantenna'] === '0') echo "selected"; ?> value="0"><?=gettext("Auto"); ?></option>
2202
												<option <?php if ($pconfig['rxantenna'] === '1') echo "selected"; ?> value="1"><?=gettext("#1"); ?></option>
2203
												<option <?php if ($pconfig['rxantenna'] === '2') echo "selected"; ?> value="2"><?=gettext("#2"); ?></option>
2204
											</select>
2205
										</td>
2206
										<?php endif; ?>
2207
									</tr>
2208
								</table>
2209
								<br/>
2210
								<?=gettext("Note: The antenna numbers do not always match up with the labels on the card."); ?>
2211
							</td>
2212
						</tr>
2213
						<?php endif; ?>
2214
						<?php if (isset($wl_sysctl["{$wl_sysctl_prefix}.slottime"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.acktimeout"]) && isset($wl_sysctl["{$wl_sysctl_prefix}.ctstimeout"])): ?>
2215
						<tr>
2216
							<td valign="top" class="vncell"><?=gettext("Distance setting"); ?></td>
2217
							<td class="vtable">
2218
								<input name="distance" type="text" class="formfld unknown" id="distance" size="5" value="<?=htmlspecialchars($pconfig['distance']);?>">
2219
								<br/>
2220
								<?=gettext("Note: This field can be used to tune ACK/CTS timers to fit the distance between AP and Client"); ?><br/>
2221
								<?=gettext("(measured in Meters and works only for Atheros based cards !)"); ?>
2222
							</td>
2223
						</tr>
2224
						<?php endif; ?>
2225
						<tr>
2226
							<td valign="top" class="vncell"><?=gettext("Regulatory settings"); ?></td>
2227
							<td class="vtable">
2228
								<?=gettext("Regulatory domain"); ?><br/>
2229
								<select name="regdomain" class="formselect" id="regdomain">
2230
									<option <?php if (empty($pconfig['regdomain'])) echo "selected"; ?> value=""><?=gettext("Default"); ?></option>
2231
									<?php
2232
									foreach($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
2233
										echo "<option ";
2234
										if ($pconfig['regdomain'] == $wl_regdomains_attr[$wl_regdomain_key]['ID']) {
2235
											echo "selected ";
2236
										}
2237
										echo "value=\"{$wl_regdomains_attr[$wl_regdomain_key]['ID']}\">{$wl_regdomain['name']}</option>\n";
2238
									}
2239
									?>
2240
								</select>
2241
								<br/>
2242
								<?=gettext("Note: Some cards have a default that is not recognized and require changing the regulatory domain to one in this list for the changes to other regulatory settings to work."); ?>
2243
								<br/><br/>
2244
								<?=gettext("Country (listed with country code and regulatory domain)"); ?><br/>
2245
								<select name="regcountry" class="formselect" id="regcountry">
2246
									<option <?php if (empty($pconfig['regcountry'])) echo "selected"; ?> value=""><?=gettext("Default"); ?></option>
2247
									<?php
2248
									foreach($wl_countries as $wl_country_key => $wl_country) {
2249
										echo "<option ";
2250
										if ($pconfig['regcountry'] == $wl_countries_attr[$wl_country_key]['ID']) {
2251
											echo "selected ";
2252
										}
2253
										echo "value=\"{$wl_countries_attr[$wl_country_key]['ID']}\">{$wl_country['name']} -- ({$wl_countries_attr[$wl_country_key]['ID']}, " . strtoupper($wl_countries_attr[$wl_country_key]['rd'][0]['REF']) . ")</option>\n";
2254
									}
2255
									?>
2256
								</select>
2257
								<br/>
2258
								<?=gettext("Note: Any country setting other than \"Default\" will override the regulatory domain setting"); ?>.
2259
								<br/><br/>
2260
								<?=gettext("Location"); ?><br/>
2261
								<select name="reglocation" class="formselect" id="reglocation">
2262
									<option <?php if (empty($pconfig['reglocation'])) echo "selected"; ?> value=""><?=gettext("Default"); ?></option>
2263
									<option <?php if ($pconfig['reglocation'] == 'indoor') echo "selected"; ?> value="indoor"><?=gettext("Indoor"); ?></option>
2264
									<option <?php if ($pconfig['reglocation'] == 'outdoor') echo "selected"; ?> value="outdoor"><?=gettext("Outdoor"); ?></option>
2265
									<option <?php if ($pconfig['reglocation'] == 'anywhere') echo "selected"; ?> value="anywhere"><?=gettext("Anywhere"); ?></option>
2266
								</select>
2267
								<br/><br/>
2268
								<?=gettext("These settings may affect which channels are available and the maximum transmit power allowed on those channels.  Using the correct settings to comply with local regulatory requirements is recommended."); ?>
2269
								<br/>
2270
								<?=gettext("Note: All wireless networks on this interface will be temporarily brought down when changing regulatory settings.  Some of the regulatory domains or country codes may not be allowed by some cards.  These settings may not be able to add additional channels that are not already supported."); ?>
2271
							</td>
2272
						</tr>
2273
						<tr>
2274
							<td colspan="2" valign="top" height="16"></td>
2275
						</tr>
2276
						<tr>
2277
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Network-specific wireless configuration");?></td>
2278
						</tr>
2279
						<tr>
2280
							<td valign="top" class="vncellreq"><?=gettext("Mode"); ?></td>
2281
							<td class="vtable">
2282
								<select name="mode" class="formselect" id="mode">
2283
									<option <?php if ($pconfig['mode'] == 'bss') echo "selected";?> value="bss"><?=gettext("Infrastructure (BSS)"); ?></option>
2284
									<option <?php if ($pconfig['mode'] == 'adhoc') echo "selected";?> value="adhoc"><?=gettext("Ad-hoc (IBSS)"); ?></option>
2285
									<option <?php if ($pconfig['mode'] == 'hostap') echo "selected";?> value="hostap"><?=gettext("Access Point"); ?></option>
2286
								</select>
2287
							</td>
2288
						</tr>
2289
						<tr>
2290
							<td valign="top" class="vncellreq"><?=gettext("SSID"); ?></td>
2291
							<td class="vtable">
2292
								<input name="ssid" type="text" class="formfld unknown" id="ssid" size="20" value="<?=htmlspecialchars($pconfig['ssid']); ?>">
2293
								<br/>
2294
								<?=gettext("Note: Only required in Access Point mode. If left blank in Ad-hoc or Infrastructure mode, this interface will connect to any available SSID"); ?>
2295
							</td>
2296
						</tr>
2297
						<?php if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])): ?>
2298
						<tr>
2299
							<td valign="top" class="vncell"><?=gettext("Minimum wireless standard"); ?></td>
2300
							<td class="vtable">
2301
								<select name="puremode" class="formselect" id="puremode">
2302
									<option <?php if ($pconfig['puremode'] == 'any') echo "selected";?> value="any"><?=gettext("Any"); ?></option>
2303
									<?php if (isset($wl_modes['11g'])): ?>
2304
									<option <?php if ($pconfig['puremode'] == '11g') echo "selected";?> value="11g"><?=gettext("802.11g"); ?></option>
2305
									<?php endif; ?>
2306
									<option <?php if ($pconfig['puremode'] == '11n') echo "selected";?> value="11n"><?=gettext("802.11n"); ?></option>
2307
								</select>
2308
								<br/>
2309
								<?=gettext("When operating as an access point, allow only stations capable of the selected wireless standard to associate (stations not capable are not permitted to associate)."); ?>
2310
							</td>
2311
						</tr>
2312
						<?php elseif (isset($wl_modes['11g'])): ?>
2313
						<tr>
2314
							<td valign="top" class="vncell"><?=gettext("802.11g only"); ?></td>
2315
							<td class="vtable">
2316
								<input name="puremode" type="checkbox" value="11g"  class="formfld" id="puremode" <?php if ($pconfig['puremode'] == '11g') echo "checked";?>>
2317
								<br/><?=gettext("When operating as an access point in 802.11g mode, allow only 11g-capable stations to associate (11b-only stations are not permitted to associate)."); ?>
2318
							</td>
2319
						</tr>
2320
						<?php endif; ?>
2321
						<tr>
2322
							<td valign="top" class="vncell"><?=gettext("Allow intra-BSS communication"); ?></td>
2323
							<td class="vtable">
2324
								<input name="apbridge_enable" type="checkbox" value="yes"  class="formfld" id="apbridge_enable" <?php if ($pconfig['apbridge_enable']) echo "checked";?>>
2325
								<br/>
2326
								<?=gettext("When operating as an access point, enable this if you want to pass packets between wireless clients directly."); ?>
2327
								<br/>
2328
								<?=gettext("Disabling the internal bridging is useful when traffic is to be processed with packet filtering."); ?>
2329
							</td>
2330
						</tr>
2331
						<tr>
2332
							<td valign="top" class="vncell"><?=gettext("Enable WME"); ?></td>
2333
							<td class="vtable">
2334
								<input name="wme_enable" type="checkbox" class="formfld" id="wme_enable" value="yes" <?php if ($pconfig['wme_enable']) echo "checked";?>>
2335
								<br/><?=gettext("Setting this option will force the card to use WME (wireless QoS)."); ?>
2336
							</td>
2337
						</tr>
2338
						<tr>
2339
							<td valign="top" class="vncell"><?=gettext("Enable Hide SSID"); ?></td>
2340
							<td class="vtable">
2341
								<input name="hidessid_enable" type="checkbox" class="formfld" id="hidessid_enable" value="yes" <?php if ($pconfig['hidessid_enable']) echo "checked";?>>
2342
								<br/>
2343
								<?=gettext("Setting this option will force the card to NOT broadcast its SSID"); ?>
2344
								<br/>
2345
								<?=gettext("(this might create problems for some clients)."); ?>
2346
							</td>
2347
						</tr>
2348
						<tr>
2349
							<td valign="top" class="vncell"><?=gettext("WEP"); ?></td>
2350
							<td class="vtable">
2351
								<input name="wep_enable" type="checkbox" id="wep_enable" value="yes" <?php if ($pconfig['wep_enable']) echo "checked"; ?>>
2352
								<strong><?=gettext("Enable WEP"); ?></strong>
2353
								<table border="0" cellspacing="0" cellpadding="0">
2354
									<tr>
2355
										<td>&nbsp;</td>
2356
										<td>&nbsp;</td>
2357
										<td>&nbsp;<?=gettext("TX key"); ?>&nbsp;</td>
2358
									</tr>
2359
									<tr>
2360
										<td><?=gettext("Key 1:"); ?>&nbsp;&nbsp;</td>
2361
										<td>
2362
											<input name="key1" type="text" class="formfld unknown" id="key1" size="30" value="<?=htmlspecialchars($pconfig['key1']);?>">
2363
										</td>
2364
										<td align="center">
2365
											<input name="txkey" type="radio" value="1" <?php if ($pconfig['txkey'] == 1) echo "checked";?>>
2366
										</td>
2367
									</tr>
2368
									<tr>
2369
										<td><?=gettext("Key 2:"); ?>&nbsp;&nbsp;</td>
2370
										<td>
2371
											<input name="key2" type="text" class="formfld unknown" id="key2" size="30" value="<?=htmlspecialchars($pconfig['key2']);?>">
2372
										</td>
2373
										<td align="center">
2374
											<input name="txkey" type="radio" value="2" <?php if ($pconfig['txkey'] == 2) echo "checked";?>>
2375
										</td>
2376
									</tr>
2377
									<tr>
2378
										<td><?=gettext("Key 3:"); ?>&nbsp;&nbsp;</td>
2379
										<td>
2380
											<input name="key3" type="text" class="formfld unknown" id="key3" size="30" value="<?=htmlspecialchars($pconfig['key3']);?>">
2381
										</td>
2382
										<td align="center">
2383
											<input name="txkey" type="radio" value="3" <?php if ($pconfig['txkey'] == 3) echo "checked";?>>
2384
										</td>
2385
									</tr>
2386
									<tr>
2387
										<td><?=gettext("Key 4:"); ?>&nbsp;&nbsp;</td>
2388
										<td>
2389
											<input name="key4" type="text" class="formfld unknown" id="key4" size="30" value="<?=htmlspecialchars($pconfig['key4']);?>">
2390
										</td>
2391
										<td align="center">
2392
											<input name="txkey" type="radio" value="4" <?php if ($pconfig['txkey'] == 4) echo "checked";?>>
2393
										</td>
2394
									</tr>
2395
								</table>
2396
								<br/>
2397
								<?=gettext("40 (64) bit keys may be entered as 5 ASCII characters or 10 hex digits preceded by '0x'."); ?><br/>
2398
								<?=gettext("104 (128) bit keys may be entered as 13 ASCII characters or 26 hex digits preceded by '0x'."); ?>
2399
							</td>
2400
						</tr>
2401
						<tr>
2402
							<td valign="top" class="vncell"><?=gettext("WPA"); ?></td>
2403
							<td class="vtable">
2404
								<input name="wpa_enable" type="checkbox" class="formfld" id="wpa_enable" value="yes" <?php if ($pconfig['wpa_enable']) echo "checked"; ?>>
2405
								<strong><?=gettext("Enable WPA"); ?></strong>
2406
								<br/><br/>
2407
								<table border="0" cellspacing="0" cellpadding="0">
2408
									<tr>
2409
										<td>&nbsp;</td>
2410
										<td>&nbsp;<?=gettext("WPA Pre Shared Key"); ?>&nbsp;</td>
2411
									</tr>
2412
									<tr>
2413
										<td><?=gettext("PSK:"); ?>&nbsp;&nbsp;</td>
2414
										<td>
2415
											<input name="passphrase" type="text" class="formfld unknown" id="passphrase" size="66" value="<?=htmlspecialchars($pconfig['passphrase']);?>">
2416
										</td>
2417
									</tr>
2418
								</table>
2419
								<br/><?=gettext("Passphrase must be from 8 to 63 characters."); ?>
2420
							</td>
2421
						</tr>
2422
						<tr>
2423
							<td valign="top" class="vncell"><?=gettext("WPA Mode"); ?></td>
2424
							<td class="vtable">
2425
								<select name="wpa_mode" class="formselect" id="wpa_mode">
2426
									<option <?php if ($pconfig['wpa_mode'] == '1') echo "selected";?> value="1"><?=gettext("WPA"); ?></option>
2427
									<option <?php if ($pconfig['wpa_mode'] == '2') echo "selected";?> value="2"><?=gettext("WPA2"); ?></option>
2428
									<option <?php if ($pconfig['wpa_mode'] == '3') echo "selected";?> value="3"><?=gettext("Both"); ?></option>
2429
								</select>
2430
							</td>
2431
						</tr>
2432
						<tr>
2433
							<td valign="top" class="vncell"><?=gettext("WPA Key Management Mode"); ?></td>
2434
							<td class="vtable">
2435
								<select name="wpa_key_mgmt" class="formselect" id="wpa_key_mgmt">
2436
									<option <?php if ($pconfig['wpa_key_mgmt'] == 'WPA-PSK') echo "selected";?> value="WPA-PSK"><?=gettext("Pre Shared Key"); ?></option>
2437
									<option <?php if ($pconfig['wpa_key_mgmt'] == 'WPA-EAP') echo "selected";?> value="WPA-EAP"><?=gettext("Extensible Authentication Protocol"); ?></option>
2438
									<option <?php if ($pconfig['wpa_key_mgmt'] == 'WPA-PSK WPA-EAP') echo "selected";?> value="WPA-PSK WPA-EAP"><?=gettext("Both"); ?></option>
2439
								</select>
2440
							</td>
2441
						</tr>
2442
						<tr>
2443
							<td valign="top" class="vncell"><?=gettext("Authentication"); ?></td>
2444
							<td class="vtable">
2445
								<select name="auth_algs" class="formselect" id="auth_algs">
2446
									<option <?php if ($pconfig['auth_algs'] == '1') echo "selected";?> value="1"><?=gettext("Open System Authentication"); ?></option>
2447
									<option <?php if ($pconfig['auth_algs'] == '2') echo "selected";?> value="2"><?=gettext("Shared Key Authentication"); ?></option>
2448
									<option <?php if ($pconfig['auth_algs'] == '3') echo "selected";?> value="3"><?=gettext("Both"); ?></option>
2449
								</select>
2450
								<br/><?=gettext("Note: Shared Key Authentication requires WEP."); ?></br>
2451
							</td>
2452
						</tr>
2453
						<tr>
2454
							<td valign="top" class="vncell"><?=gettext("WPA Pairwise"); ?></td>
2455
							<td class="vtable">
2456
								<select name="wpa_pairwise" class="formselect" id="wpa_pairwise">
2457
									<option <?php if ($pconfig['wpa_pairwise'] == 'CCMP TKIP') echo "selected";?> value="CCMP TKIP"><?=gettext("Both"); ?></option>
2458
									<option <?php if ($pconfig['wpa_pairwise'] == 'CCMP') echo "selected";?> value="CCMP"><?=gettext("AES (recommended)"); ?></option>
2459
									<option <?php if ($pconfig['wpa_pairwise'] == 'TKIP') echo "selected";?> value="TKIP"><?=gettext("TKIP"); ?></option>
2460
								</select>
2461
							</td>
2462
						</tr>
2463
						<tr>
2464
							<td valign="top" class="vncell"><?=gettext("Key Rotation"); ?></td>
2465
							<td class="vtable">
2466
								<input name="wpa_group_rekey" type="text" class="formfld unknown" id="wpa_group_rekey" size="30" value="<?php echo $pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60";?>">
2467
								<br/><?=gettext("Allowed values are 1-9999 but should not be longer than Master Key Regeneration time."); ?>
2468
							</td>
2469
						</tr>
2470
						<tr>
2471
							<td valign="top" class="vncell"><?=gettext("Master Key Regeneration"); ?></td>
2472
							<td class="vtable">
2473
								<input name="wpa_gmk_rekey" type="text" class="formfld" id="wpa_gmk_rekey" size="30" value="<?php echo $pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600";?>">
2474
								<br/><?=gettext("Allowed values are 1-9999 but should not be shorter than Key Rotation time."); ?>
2475
							</td>
2476
						</tr>
2477
						<tr>
2478
							<td valign="top" class="vncell"><?=gettext("Strict Key Regeneration"); ?></td>
2479
							<td class="vtable">
2480
								<input name="wpa_strict_rekey" type="checkbox" value="yes"  class="formfld" id="wpa_strict_rekey" <?php if ($pconfig['wpa_strict_rekey']) echo "checked"; ?>>
2481
								<br/><?=gettext("Setting this option will force the AP to rekey whenever a client disassociates."); ?>
2482
							</td>
2483
						</tr>
2484
						<tr>
2485
							<td valign="top" class="vncell"><?=gettext("Enable IEEE802.1X Authentication"); ?></td>
2486
							<td class="vtable">
2487
								<input name="ieee8021x" type="checkbox" value="yes"  class="formfld" id="ieee8021x" <?php if ($pconfig['ieee8021x']) echo "checked";?>>
2488
								<br/><?=gettext("Setting this option will enable 802.1x authentication."); ?>
2489
								<br/><span class="red"><strong><?=gettext("NOTE"); ?>:</strong></span> <?=gettext("this option requires checking the \"Enable WPA box\"."); ?>
2490
							</td>
2491
						</tr>
2492
						<tr>
2493
							<td valign="top" class="vncell"><?=gettext("802.1X Authentication Server IP Address"); ?></td>
2494
							<td class="vtable">
2495
								<input name="auth_server_addr" id="auth_server_addr" type="text" class="formfld unknown" size="66" value="<?=htmlspecialchars($pconfig['auth_server_addr']);?>">
2496
								<br/><?=gettext("Enter the IP address of the 802.1X Authentication Server.  This is commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)"); ?>
2497
							</td>
2498
						</tr>
2499
						<tr>
2500
							<td valign="top" class="vncell"><?=gettext("802.1X Authentication Server Port"); ?></td>
2501
							<td class="vtable">
2502
								<input name="auth_server_port" id="auth_server_port" type="text" class="formfld unknown" size="66" value="<?=htmlspecialchars($pconfig['auth_server_port']);?>">
2503
								<br/><?=gettext("Leave blank for the default 1812 port."); ?>
2504
							</td>
2505
						</tr>
2506
						<tr>
2507
							<td valign="top" class="vncell"><?=gettext("802.1X Authentication Server Shared Secret"); ?></td>
2508
							<td class="vtable">
2509
								<input name="auth_server_shared_secret" id="auth_server_shared_secret" type="text" class="formfld unknown" size="66" value="<?=htmlspecialchars($pconfig['auth_server_shared_secret']);?>">
2510
								<br/>
2511
							</td>
2512
						</tr>
2513
						<tr>
2514
					<td valign="top" class="vncell"><?=gettext("Secondary 802.1X Authentication Server IP Address"); ?></td>
2515
							<td class="vtable">
2516
								<input name="auth_server_addr2" id="auth_server_addr2" type="text" class="formfld unknown" size="66" value="<?=htmlspecialchars($pconfig['auth_server_addr2']);?>">
2517
								<br/><?=gettext("Enter the IP address of the 802.1X Authentication Server.  This is commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)"); ?>
2518
							</td>
2519
						</tr>
2520
						<tr>
2521
							<td valign="top" class="vncell"><?=gettext("Secondary 802.1X Authentication Server Port"); ?></td>
2522
							<td class="vtable">
2523
								<input name="auth_server_port2" id="auth_server_port2" type="text" class="formfld unknown" size="66" value="<?=htmlspecialchars($pconfig['auth_server_port2']);?>">
2524
								<br/><?=gettext("Leave blank for the default 1812 port."); ?>
2525
							</td>
2526
						</tr>
2527
						<tr>
2528
							<td valign="top" class="vncell"><?=gettext("Secondary 802.1X Authentication Server Shared Secret"); ?></td>
2529
							<td class="vtable">
2530
								<input name="auth_server_shared_secret2" id="auth_server_shared_secret2" type="text" class="formfld unknown" size="66" value="<?=htmlspecialchars($pconfig['auth_server_shared_secret2']);?>">
2531
								<br/>
2532
							</td>
2533
						</tr>
2534
						<tr>
2535
							<td valign="top" class="vncell">802.1X <?=gettext("Authentication Roaming Preauth"); ?></td>
2536
							<td class="vtable">
2537
								<input name="rsn_preauth" id="rsn_preauth" type="checkbox" class="formfld unknown" size="66" value="yes" <? if ($pconfig['rsn_preauth']) echo "checked"; ?>>
2538
								<br/>
2539
							</td>
2540
						</tr>
2541
						<?php endif; ?>
2542
						<tr>
2543
							<td colspan="2" valign="top" height="16"></td>
2544
						</tr>
2545
						<tr>
2546
							<td colspan="2" valign="top" class="listtopic"><?=gettext("Private networks"); ?></td>
2547
						</tr>
2548
						<tr>
2549
							<td valign="middle" class="vncell">&nbsp;</td>
2550
							<td class="vtable">
2551
								<a name="rfc1918"></a>
2552
								<input name="blockpriv" type="checkbox" id="blockpriv" value="yes" <?php if ($pconfig['blockpriv']) echo "checked"; ?>>
2553
								<strong><?=gettext("Block private networks"); ?></strong><br>
2554
								<?=gettext("When set, this option blocks traffic from IP addresses that are reserved " .
2555
								"for private  networks as per RFC 1918 (10/8, 172.16/12, 192.168/16) as"); ?>
2556
								<?=gettext("well as loopback addresses (127/8)."); ?>&nbsp;&nbsp; <?=gettext("You should generally " .
2557
								"leave this option turned on, unless your WAN network lies in such " .
2558
								"a private address space, too."); ?>
2559
							</td>
2560
						</tr>
2561
						<tr>
2562
							<td valign="middle" class="vncell">&nbsp;</td>
2563
							<td class="vtable">
2564
								<input name="blockbogons" type="checkbox" id="blockbogons" value="yes" <?php if ($pconfig['blockbogons']) echo "checked"; ?>>
2565
								<strong><?=gettext("Block bogon networks"); ?></strong><br>
2566
								<?=gettext("When set, this option blocks traffic from IP addresses that are reserved " .
2567
								"(but not RFC 1918) or not yet assigned by IANA."); ?>&nbsp;&nbsp;
2568
								<?=gettext("Bogons are prefixes that should never appear in the Internet routing table, " .
2569
								"and obviously should not appear as the source address in any packets you receive."); ?>
2570
							</td>
2571
						</tr>
2572
					</table> <!-- End "allcfg" table -->
2573
					</div> <!-- End "allcfg" div -->
2574

    
2575
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
2576
						<tr>
2577
							<td width="22%" valign="top">
2578
								&nbsp;
2579
							</td>
2580
							<td width="78%">
2581
								<br/>
2582
								<input id="save" name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">
2583
								<input id="cancel" type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
2584
								<input name="if" type="hidden" id="if" value="<?=$if;?>">
2585
								<?php if ($wancfg['if'] == $a_ppps[$pppid]['if']) : ?>
2586
								<input name="ppp_port" type="hidden" value="<?=htmlspecialchars($pconfig['port']);?>">
2587
								<?php endif; ?>
2588
								<input name="ptpid" type="hidden" value="<?=htmlspecialchars($pconfig['ptpid']);?>">
2589
							</td>
2590
						</tr>
2591
					</table>
2592
				</td>
2593
			</tr>
2594
		</table>
2595
		<!--
2596
		</div>
2597
		</td></tr>
2598
		</table>
2599
		-->
2600
	</form>
2601
	<script type="text/javascript">
2602
		var gatewayip;
2603
		var name;
2604
		var gatewayipv6;
2605
		var namev6;
2606
		function show_add_gateway() {
2607
			document.getElementById("addgateway").style.display = '';
2608
			document.getElementById("addgwbox").style.display = 'none';
2609
			document.getElementById("gateway").style.display = 'none';
2610
			document.getElementById("save").style.display = 'none';
2611
			document.getElementById("cancel").style.display = 'none';
2612
			document.getElementById("gwsave").style.display = '';
2613
			document.getElementById("gwcancel").style.display = '';
2614
			jQuery('#notebox').html("");
2615
		}
2616
		function show_add_gateway_v6() {
2617
			document.getElementById("addgatewayv6").style.display = '';
2618
			document.getElementById("addgwboxv6").style.display = 'none';
2619
			document.getElementById("gatewayv6").style.display = 'none';
2620
			document.getElementById("save").style.display = 'none';
2621
			document.getElementById("cancel").style.display = 'none';
2622
			document.getElementById("gwsave").style.display = '';
2623
			document.getElementById("gwcancel").style.display = '';
2624
			jQuery('#noteboxv6').html("");
2625
		}
2626
		function hide_add_gateway() {
2627
			document.getElementById("addgateway").style.display = 'none';
2628
			document.getElementById("addgwbox").style.display = '';
2629
			document.getElementById("gateway").style.display = '';
2630
			document.getElementById("save").style.display = '';
2631
			document.getElementById("cancel").style.display = '';
2632
			document.getElementById("gwsave").style.display = '';
2633
			document.getElementById("gwcancel").style.display = '';
2634
		}
2635
		function hide_add_gateway_v6() {
2636
			document.getElementById("addgatewayv6").style.display = 'none';
2637
			document.getElementById("addgwboxv6").style.display = '';
2638
			document.getElementById("gatewayv6").style.display = '';
2639
			document.getElementById("save").style.display = '';
2640
			document.getElementById("cancel").style.display = '';
2641
			document.getElementById("gwsave").style.display = '';
2642
			document.getElementById("gwcancel").style.display = '';
2643
		}
2644
		function hide_add_gatewaysave() {
2645
			document.getElementById("addgateway").style.display = 'none';
2646
			jQuery('#status').html('<img src="/themes/metallic/images/misc/loader.gif"> One moment please...');
2647
			var iface = jQuery('#if').val();
2648
			name = jQuery('#name').val();
2649
			var descr = jQuery('#gatewaydescr').val();
2650
			gatewayip = jQuery('#gatewayip').val();
2651

    
2652
			var defaultgw = jQuery('#defaultgw').val();
2653
			var url = "system_gateways_edit.php";
2654
			var pars = 'isAjax=true&defaultgw=' + escape(defaultgw) + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
2655
			jQuery.ajax(
2656
				url,
2657
				{
2658
					type: 'post',
2659
					data: pars,
2660
					error: report_failure,
2661
					complete: save_callback
2662
				});
2663
		}
2664
		function hide_add_gatewaysave_v6() {
2665
			document.getElementById("addgatewayv6").style.display = 'none';
2666
			jQuery('#statusv6').html('<img src="/themes/metallic/images/misc/loader.gif"> One moment please...');
2667
			var iface = jQuery('#if').val();
2668
			name = jQuery('#namev6').val();
2669
			var descr = jQuery('#gatewaydescrv6').val();
2670
			gatewayip = jQuery('#gatewayipv6').val();
2671
			var defaultgw = jQuery('#defaultgwv6').val();
2672
			var url_v6 = "system_gateways_edit.php";
2673
			var pars_v6 = 'isAjax=true&defaultgw=' + escape(defaultgw) + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip);
2674
			jQuery.ajax(
2675
				url_v6,
2676
				{
2677
					type: 'post',
2678
					data: pars_v6,
2679
					error: report_failure_v6,
2680
					complete: save_callback_v6
2681
				});
2682
		}
2683
		function addOption(selectbox,text,value)
2684
		{
2685
			var optn = document.createElement("OPTION");
2686
			optn.text = text;
2687
			optn.value = value;
2688
			selectbox.append(optn);
2689
			selectbox.prop('selectedIndex',selectbox.children().length-1);
2690
			jQuery('#notebox').html("<p/><strong><?=gettext("NOTE:"); ?></strong> <?=gettext("You can manage Gateways"); ?> <a target='_new' href='system_gateways.php'><?=gettext("here"); ?></a>.");
2691
		}
2692
		function addOption_v6(selectbox,text,value)
2693
		{
2694
			var optn = document.createElement("OPTION");
2695
			optn.text = text;
2696
			optn.value = value;
2697
			selectbox.append(optn);
2698
			selectbox.prop('selectedIndex',selectbox.children().length-1);
2699
			jQuery('#noteboxv6').html("<p/><strong><?=gettext("NOTE:"); ?></strong> <?=gettext("You can manage Gateways"); ?> <a target='_new' href='system_gateways.php'><?=gettext("here"); ?></a>.");
2700
		}
2701
		function report_failure() {
2702
			alert("Sorry, we could not create your IPv4 gateway at this time.");
2703
			hide_add_gateway();
2704
		}
2705
		function report_failure_v6() {
2706
			alert("Sorry, we could not create your IPv6 gateway at this time.");
2707
			hide_add_gateway_v6();
2708
		}
2709
		function save_callback(transport) {
2710
			var response = transport.responseText;
2711
			if(response) {
2712
				document.getElementById("addgateway").style.display = 'none';
2713
				hide_add_gateway();
2714
				jQuery('#status').html('');
2715
				var gwtext = escape(name) + " - " + gatewayip;
2716
				addOption(jQuery('#gateway'), gwtext, name);
2717
				// Auto submit form?
2718
				//document.iform.submit();
2719
				//jQuery('#status').html('<img src="/themes/metallic/images/misc/loader.gif">');
2720
			} else {
2721
				report_failure();
2722
			}
2723
		}
2724
		function show_advanced_media() {
2725
			document.getElementById("showadvmediabox").innerHTML='';
2726
			aodiv = document.getElementById('showmediaadv');
2727
			aodiv.style.display = "block";
2728
		}
2729
		function save_callback_v6(transport) {
2730
			var response_v6 = transport.responseText;
2731
			if(response_v6) {
2732
				document.getElementById("addgatewayv6").style.display = 'none';
2733
				hide_add_gateway_v6();
2734
				jQuery('#statusv6').html('');
2735
				var gwtext_v6 = escape(name) + " - " + gatewayip;
2736
				addOption_v6(jQuery('#gatewayv6'), gwtext_v6, name);
2737
				// Auto submit form?
2738
				//document.iform.submit();
2739
				//jQuery('#statusv6').html('<img src="/themes/metallic/images/misc/loader.gif">');
2740
			} else {
2741
				report_failure_v6();
2742
			}
2743
		}
2744
		<?php
2745
		echo "show_allcfg(document.iform.enable);";
2746
		echo "updateType('{$pconfig['type']}');\n";
2747
		echo "updateTypeSix('{$pconfig['type6']}');\n";
2748
		?>
2749
	</script>
2750
	<?php include("fend.inc"); ?>
2751
	</body>
2752
</html>
(89-89/239)