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 ($vip['interface'] == $if)
439
						$input_errors[] = gettext("This interface is referenced by 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 ($vip['interface'] == $if)
492
						$input_errors[] = gettext("This interface is referenced by 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

    
1127
				break;
1128
			}
1129
			case "srd": {
1130
				jQuery('#none, #dhcp6', '#staticv6').hide();
1131

    
1132
				break;
1133
			}
1134
		}
1135
		if (t != "l2tp" && t != "pptp")
1136
			jQuery('#'+t).show();
1137
	}
1138

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

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

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

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

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

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

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

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

    
1488

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

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

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

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