Project

General

Profile

Download (76.6 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 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("guiconfig.inc");
48
require("ipsec.inc");
49
require("functions.inc");
50
require("captiveportal.inc");
51
require("filter.inc");
52
require("shaper.inc");
53
require("rrd.inc");
54
require("vpn.inc");
55

    
56
if ($_REQUEST['if']) {
57
	$if = $_REQUEST['if'];
58
} else {
59
	$if = "wan";
60
}
61

    
62
define("CRON_PPPOE_CMD_FILE", "/conf/pppoe{$if}restart");
63
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
64
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
65
define("CRON_DAILY_PATTERN", "0 0 * * *");
66
define("CRON_HOURLY_PATTERN", "0 * * * *");
67

    
68
function getMPDCRONSettings() {
69
	global $config;
70
	if (is_array($config['cron']['item'])) {
71
		for ($i = 0; $i < count($config['cron']['item']); $i++) {
72
			$item = $config['cron']['item'][$i];
73
			if (strpos($item['command'], CRON_PPPOE_CMD_FILE) !== false) {
74
				return array("ID" => $i, "ITEM" => $item);
75
			}
76
		}
77
	}
78
	return NULL;
79
}
80

    
81
function getMPDResetTimeFromConfig() {
82
	$itemhash = getMPDCRONSettings();
83
	$cronitem = $itemhash['ITEM'];
84
	if (isset($cronitem)) {
85
		return "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}";
86
	} else {
87
		return NULL;
88
	}
89
}
90

    
91
function remove_bad_chars($string) {
92
	return preg_replace('/[^a-z|_|0-9]/i','',$string);
93
}
94

    
95
if (!is_array($config['gateways']['gateway_item']))
96
	$config['gateways']['gateway_item'] = array();
97

    
98
$a_gateways = &$config['gateways']['gateway_item'];
99

    
100
$wancfg = &$config['interfaces'][$if];
101

    
102
$pconfig['pppoe_username'] = $wancfg['pppoe_username'];
103
$pconfig['pppoe_password'] = $wancfg['pppoe_password'];
104
$pconfig['provider'] = $wancfg['provider'];
105
$pconfig['pppoe_dialondemand'] = isset($wancfg['ondemand']);
106
$pconfig['pppoe_idletimeout'] = $wancfg['timeout'];
107

    
108
/* ================================================ */
109
/* = force a connection reset at a specific time? = */
110
/* ================================================ */
111

    
112
if (isset($wancfg['pppoe']['pppoe-reset-type'])) {
113
	$resetTime = getMPDResetTimeFromConfig();  
114
	$pconfig['pppoe_preset'] = true;
115
	if ($wancfg['pppoe']['pppoe-reset-type'] == "custom") {
116
		$resetTime_a = split(" ", $resetTime);
117
		$pconfig['pppoe_pr_custom'] = true;
118
		$pconfig['pppoe_resetminute'] = $resetTime_a[0];
119
		$pconfig['pppoe_resethour'] = $resetTime_a[1];
120
		/*  just initialize $pconfig['pppoe_resetdate'] if the
121
		 *  coresponding item contains appropriate numeric values.
122
		 */
123
		if ($resetTime_a[2] <> "*" && $resetTime_a[3] <> "*") 
124
			$pconfig['pppoe_resetdate'] = "{$resetTime_a[3]}/{$resetTime_a[2]}/" . date("Y");
125
	} else if ($wancfg['pppoe']['pppoe-reset-type'] == "preset") {
126
		$pconfig['pppoe_pr_preset'] = true;
127
		switch ($resetTime) {
128
			case CRON_MONTHLY_PATTERN:
129
				$pconfig['pppoe_monthly'] = true;
130
				break;
131
			case CRON_WEEKLY_PATTERN:
132
				$pconfig['pppoe_weekly'] = true;
133
				break;
134
			case CRON_DAILY_PATTERN:
135
				$pconfig['pppoe_daily'] = true;
136
				break;
137
			case CRON_HOURLY_PATTERN:
138
				$pconfig['pppoe_hourly'] = true;
139
				break;
140
		}
141
	}
142
}
143

    
144
$pconfig['pptp_username'] = $wancfg['pptp_username'];
145
$pconfig['pptp_password'] = $wancfg['pptp_password'];
146
$pconfig['pptp_local'] = $wancfg['local'];
147
$pconfig['pptp_subnet'] = $wancfg['subnet'];
148
$pconfig['pptp_remote'] = $wancfg['remote'];
149
$pconfig['pptp_dialondemand'] = isset($wancfg['ondemand']);
150
$pconfig['pptp_idletimeout'] = $wancfg['timeout'];
151

    
152
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
153
$pconfig['alias-address'] = $wancfg['alias-address'];
154
$pconfig['alias-subnet'] = $wancfg['alias-subnet'];
155

    
156
// Populate page descr if it does not exist.
157
if($if == "wan" && !$wancfg['descr']) {
158
	$wancfg['descr'] = "WAN";
159
} else if ($if == "lan" && !$wancfg['descr']) {
160
	$wancfg['descr'] = "LAN";
161
}
162
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
163

    
164
if ($if == "wan" || $if == "lan")
165
	$pconfig['enable'] = true;
166
else
167
	$pconfig['enable'] = isset($wancfg['enable']);
168

    
169
if (is_array($config['aliases']['alias'])) {
170
	foreach($config['aliases']['alias'] as $alias) {
171
		if($alias['name'] == $wancfg['descr']) {
172
			$input_errors[] = gettext("Sorry, an alias with the name {$wancfg['descr']} already exists.");
173
		}
174
	}
175
}
176

    
177
switch($wancfg['ipaddr']) {
178
	case "dhcp":
179
		$pconfig['type'] = "dhcp";
180
		break;
181
	case "carpdev-dhcp":
182
		$pconfig['type'] = "carpdev-dhcp";
183
		$pconfig['ipaddr'] = "";
184
		break;
185
	case "pppoe":
186
		$pconfig['type'] = "pppoe";
187
		break;
188
	case "pptp":
189
		$pconfig['type'] = "pptp";
190
		break;
191
	default:
192
		if(is_ipaddr($wancfg['ipaddr'])) {
193
			$pconfig['type'] = "static";
194
			$pconfig['ipaddr'] = $wancfg['ipaddr'];
195
			$pconfig['subnet'] = $wancfg['subnet'];
196
			$pconfig['gateway'] = $wancfg['gateway'];
197
			$pconfig['pointtopoint'] = $wancfg['pointtopoint'];
198
		} else {
199
			$pconfig['type'] = "none";
200
		}
201
		break;
202
}
203

    
204
// Handle PPP type interfaces
205
if($wancfg['serialport']) 
206
	$pconfig['type'] = "none";
207

    
208
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
209
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
210
$pconfig['spoofmac'] = $wancfg['spoofmac'];
211
$pconfig['mtu'] = $wancfg['mtu'];
212

    
213
/* Wireless interface? */
214
if (isset($wancfg['wireless'])) {
215
	/* Get wireless modes */
216
	$wlanif = get_real_interface($if);
217
	if (!does_interface_exist($wlanif))
218
		interface_wireless_clone($wlanif, $wancfg);
219
	$wlanbaseif = interface_get_wireless_base($wancfg['if']);
220
	$wl_modes = get_wireless_modes($if);
221
	$wl_regdomain_xml_attr = array();
222
	$wl_regdomain_xml = parse_xml_regdomain($wl_regdomain_xml_attr);
223
	$wl_regdomains = &$wl_regdomain_xml['regulatory-domains']['rd'];
224
	$wl_regdomains_attr = &$wl_regdomain_xml_attr['regulatory-domains']['rd'];
225
	$wl_countries = &$wl_regdomain_xml['country-codes']['country'];
226
	$wl_countries_attr = &$wl_regdomain_xml_attr['country-codes']['country'];
227
	$pconfig['standard'] = $wancfg['wireless']['standard'];
228
	$pconfig['mode'] = $wancfg['wireless']['mode'];
229
	$pconfig['protmode'] = $wancfg['wireless']['protmode'];
230
	$pconfig['ssid'] = $wancfg['wireless']['ssid'];
231
	$pconfig['channel'] = $wancfg['wireless']['channel'];
232
	$pconfig['txpower'] = $wancfg['wireless']['txpower'];
233
	$pconfig['distance'] = $wancfg['wireless']['distance'];
234
	$pconfig['regdomain'] = $wancfg['wireless']['regdomain'];
235
	$pconfig['regcountry'] = $wancfg['wireless']['regcountry'];
236
	$pconfig['reglocation'] = $wancfg['wireless']['reglocation'];
237
	$pconfig['wme_enable'] = isset($wancfg['wireless']['wme']['enable']);
238
	if (isset($wancfg['wireless']['puren']['enable']))
239
		$pconfig['puremode'] = '11n';
240
	else if (isset($wancfg['wireless']['pureg']['enable']))
241
		$pconfig['puremode'] = '11g';
242
	else
243
		$pconfig['puremode'] = 'any';
244
	$pconfig['apbridge_enable'] = isset($wancfg['wireless']['apbridge']['enable']);
245
	$pconfig['authmode'] = $wancfg['wireless']['authmode'];
246
	$pconfig['hidessid_enable'] = isset($wancfg['wireless']['hidessid']['enable']);
247
	$pconfig['auth_server_addr'] = $wancfg['wireless']['auth_server_addr'];
248
	$pconfig['auth_server_port'] = $wancfg['wireless']['auth_server_port'];
249
	$pconfig['auth_server_shared_secret'] = $wancfg['wireless']['auth_server_shared_secret'];
250
	if (is_array($wancfg['wireless']['wpa'])) {
251
		$pconfig['debug_mode'] = $wancfg['wireless']['wpa']['debug_mode'];
252
		$pconfig['macaddr_acl'] = $wancfg['wireless']['wpa']['macaddr_acl'];
253
		$pconfig['mac_acl_enable'] = isset($wancfg['wireless']['wpa']['mac_acl_enable']);
254
		$pconfig['auth_algs'] = $wancfg['wireless']['wpa']['auth_algs'];
255
		$pconfig['wpa_mode'] = $wancfg['wireless']['wpa']['wpa_mode'];
256
		$pconfig['wpa_key_mgmt'] = $wancfg['wireless']['wpa']['wpa_key_mgmt'];
257
		$pconfig['wpa_pairwise'] = $wancfg['wireless']['wpa']['wpa_pairwise'];
258
		$pconfig['wpa_group_rekey'] = $wancfg['wireless']['wpa']['wpa_group_rekey'];
259
		$pconfig['wpa_gmk_rekey'] = $wancfg['wireless']['wpa']['wpa_gmk_rekey'];
260
		$pconfig['wpa_strict_rekey'] = isset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
261
		$pconfig['passphrase'] = $wancfg['wireless']['wpa']['passphrase'];
262
		$pconfig['ieee8021x'] = isset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
263
		$pconfig['ext_wpa_sw'] = $wancfg['wireless']['wpa']['ext_wpa_sw'];
264
		$pconfig['wpa_enable'] = isset($wancfg['wireless']['wpa']['enable']);
265
	}
266
	$pconfig['wep_enable'] = isset($wancfg['wireless']['wep']['enable']);
267
	$pconfig['mac_acl'] = $wancfg['wireless']['mac_acl'];
268
	if (is_array($wancfg['wireless']['wep']) && is_array($wancfg['wireless']['wep']['key'])) {
269
		$i = 1;
270
		foreach ($wancfg['wireless']['wep']['key'] as $wepkey) {
271
			$pconfig['key' . $i] = $wepkey['value'];
272
			if (isset($wepkey['txkey']))
273
				$pconfig['txkey'] = $i;
274
			$i++;
275
		}
276
		if (!isset($wepkey['txkey']))
277
			$pconfig['txkey'] = 1;
278
	}
279
}
280

    
281
if ($_POST['apply']) {
282
	unset($input_errors);
283
	if (!is_subsystem_dirty('interfaces'))
284
		$intput_errors[] = "You have already applied your settings!";
285
	else {	
286
		unlink_if_exists("{$g['tmp_path']}/config.cache");
287
		clear_subsystem_dirty('interfaces');
288
		if ($pconfig['enable'])
289
			interface_configure($if, true);
290
		else
291
			interface_bring_down($if);
292
		
293
		/* restart snmp so that it binds to correct address */		
294
		services_snmpd_configure();		
295
		if ($if == "lan") 		
296
			$savemsg = "The changes have been applied.  You may need to correct your web browser's IP address.";
297

    
298
		/* sync filter configuration */
299
		setup_gateways_monitor();
300

    
301
		clear_subsystem_dirty('staticroutes');
302
		
303
		filter_configure();
304
		
305
		enable_rrd_graphing();
306
	}
307
	header("Location: interfaces.php?if={$if}");
308
	exit;
309
} else
310

    
311
if ($_POST && $_POST['enable'] != "yes") {
312
	unset($wancfg['enable']);
313
	if (isset($wancfg['wireless'])) {
314
		interface_sync_wireless_clones($wancfg, false);
315
	}
316
	write_config("Interface {$_POST['descr']}({$if}) is now disabled.");
317
	mark_subsystem_dirty('interfaces');
318
	header("Location: interfaces.php?if={$if}");
319
	exit;
320
} else
321

    
322
if ($_POST) {
323
	unset($input_errors);
324
	$pconfig = $_POST;
325
	conf_mount_rw();
326
	/* filter out spaces from descriptions  */
327
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
328
	/* okay first of all, cause we are just hiding the PPPoE HTML
329
	 * fields releated to PPPoE resets, we are going to unset $_POST
330
	 * vars, if the reset feature should not be used. Otherwise the
331
	 * data validation procedure below, may trigger a false error
332
	 * message.
333
	 */
334
	if (empty($_POST['pppoe_preset'])) {
335
		unset($_POST['pppoe_pr_type']);                
336
		unset($_POST['pppoe_resethour']);
337
		unset($_POST['pppoe_resetminute']);
338
		unset($_POST['pppoe_resetdate']);
339
		unset($_POST['pppoe_pr_preset_val']);
340
	}
341
	/* optional interface if list */
342
	$iflist = get_configured_interface_with_descr();
343
	/* description unique? */
344
	foreach ($iflist as $ifent => $ifdescr) {
345
		if ($if != $ifent && $ifdescr == $_POST['descr'])
346
			$input_errors[] = "An interface with the specified description already exists.";
347
	}
348
	/* input validation */
349
	if (isset($config['dhcpd']) && isset($config['dhcpd'][$if]['enable']) && $_POST['type'] != "static")
350
		$input_errors[] = "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.";
351

    
352
	switch($_POST['type']) {
353
		case "static":
354
			$reqdfields = explode(" ", "ipaddr subnet gateway");
355
			$reqdfieldsn = explode(",", "IP address,Subnet bit count,Gateway");
356
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
357
			break;
358
		case "PPPoE":
359
			if ($_POST['pppoe_dialondemand']) {
360
				$reqdfields = explode(" ", "pppoe_username pppoe_password pppoe_dialondemand pppoe_idletimeout");
361
				$reqdfieldsn = explode(",", "PPPoE username,PPPoE password,Dial on demand,Idle timeout value");
362
			} else {
363
				$reqdfields = explode(" ", "pppoe_username pppoe_password");
364
				$reqdfieldsn = explode(",", "PPPoE username,PPPoE password");
365
			}
366
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
367
			break;
368
		case "PPTP":
369
			if ($_POST['pptp_dialondemand']) {
370
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote pptp_dialondemand pptp_idletimeout");
371
				$reqdfieldsn = explode(",", "PPTP username,PPTP password,PPTP local IP address,PPTP subnet,PPTP remote IP address,Dial on demand,Idle timeout value");
372
			} else {
373
				$reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote");
374
				$reqdfieldsn = explode(",", "PPTP username,PPTP password,PPTP local IP address,PPTP subnet,PPTP remote IP address");
375
			}
376
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
377
			break;
378
	}
379

    
380
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
381
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
382
	if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) 
383
		$input_errors[] = "A valid IP address must be specified.";
384
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) 
385
		$input_errors[] = "A valid subnet bit count must be specified.";
386
	if (($_POST['alias-address'] && !is_ipaddr($_POST['alias-address']))) 
387
		$input_errors[] = "A valid alias IP address must be specified.";
388
	if (($_POST['alias-subnet'] && !is_numeric($_POST['alias-subnet']))) 
389
		$input_errors[] = "A valid alias subnet bit count must be specified.";
390
	if ($_POST['gateway'] != "none") {
391
		$match = false;
392
		foreach($a_gateways as $gateway) {
393
			if(in_array($_POST['gateway'], $gateway)) {
394
				$match = true;
395
			}
396
		}
397
		if(!$match) {
398
			$input_errors[] = "A valid gateway must be specified.";
399
		}
400
	}
401
	if (($_POST['pointtopoint'] && !is_ipaddr($_POST['pointtopoint']))) 
402
		$input_errors[] = "A valid point-to-point IP address must be specified.";
403
	if (($_POST['provider'] && !is_domain($_POST['provider']))) 
404
		$input_errors[] = "The service name contains invalid characters.";
405
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) 
406
		$input_errors[] = "The idle timeout value must be an integer.";
407
	if ($_POST['pppoe_resethour'] <> "" && !is_numericint($_POST['pppoe_resethour']) && 
408
		$_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) 
409
			$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
410
	if ($_POST['pppoe_resetminute'] <> "" && !is_numericint($_POST['pppoe_resetminute']) && 
411
		$_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59) 
412
			$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
413
	if ($_POST['pppoe_resetdate'] <> "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) 
414
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
415
	if (($_POST['pptp_local'] && !is_ipaddr($_POST['pptp_local']))) 
416
		$input_errors[] = "A valid PPTP local IP address must be specified.";
417
	if (($_POST['pptp_subnet'] && !is_numeric($_POST['pptp_subnet']))) 
418
		$input_errors[] = "A valid PPTP subnet bit count must be specified.";
419
	if (($_POST['pptp_remote'] && !is_ipaddr($_POST['pptp_remote']))) 
420
		$input_errors[] = "A valid PPTP remote IP address must be specified.";
421
	if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout'])) 
422
		$input_errors[] = "The idle timeout value must be an integer.";
423
	if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) 
424
		$input_errors[] = "A valid MAC address must be specified.";
425
	if ($_POST['mtu'] && ($_POST['mtu'] < 576)) 
426
		$input_errors[] = "The MTU must be greater than 576 bytes.";
427
	/* Wireless interface? */
428
	if (isset($wancfg['wireless'])) {
429
		$reqdfields = explode(" ", "mode ssid");
430
		$reqdfieldsn = explode(",", "Mode,SSID");
431
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
432
		check_wireless_mode();
433
		/* loop through keys and enforce size */
434
		for ($i = 1; $i <= 4; $i++) {
435
			if ($_POST['key' . $i]) {
436
				/* 64 bit */
437
				if (strlen($_POST['key' . $i]) == 5)
438
					continue;
439
				if (strlen($_POST['key' . $i]) == 10) {
440
					/* hex key */
441
					if (stristr($_POST['key' . $i], "0x") == false) {
442
						$_POST['key' . $i] = "0x" . $_POST['key' . $i];
443
					}
444
					continue;
445
				}
446
				if (strlen($_POST['key' . $i]) == 12) {
447
					/* hex key */
448
					if(stristr($_POST['key' . $i], "0x") == false) {
449
					$_POST['key' . $i] = "0x" . $_POST['key' . $i];
450
					}
451
					continue;
452
				}
453
				/* 128 bit */
454
				if (strlen($_POST['key' . $i]) == 13)
455
					continue;
456
				if (strlen($_POST['key' . $i]) == 26) {
457
					/* hex key */
458
					if (stristr($_POST['key' . $i], "0x") == false)
459
						$_POST['key' . $i] = "0x" . $_POST['key' . $i];
460
					continue;
461
				}
462
				if(strlen($_POST['key' . $i]) == 28)
463
					continue;
464
				$input_errors[] =  "Invalid WEP key size.   Sizes should be 40 (64) bit keys or 104 (128) bit.";
465
				break;
466
			}
467
		}
468

    
469
		if ($_POST['passphrase']) {
470
                	$passlen = strlen($_POST['passphrase']);
471
                	if ($passlen < 8 || $passlen > 64)
472
                        	$input_errors[] = "The length of the passphrase should be between 8 and 63 characters.";
473
		}
474
	}
475
	if (!$input_errors) {
476
		unset($wancfg['ipaddr']);
477
		unset($wancfg['subnet']);
478
		unset($wancfg['gateway']);
479
		unset($wancfg['pointtopoint']);
480
		unset($wancfg['dhcphostname']);
481
		unset($wancfg['pppoe_username']);
482
		unset($wancfg['pppoe_password']);
483
		unset($wancfg['pptp_username']);
484
		unset($wancfg['pptp_password']);
485
		unset($wancfg['provider']);
486
		unset($wancfg['ondemand']);
487
		unset($wancfg['timeout']);
488
		if ($wancfg['pppoe']['pppoe-reset-type'])
489
			unset($wancfg['pppoe']['pppoe-reset-type']);
490
		unset($wancfg['local']);
491
		unset($wancfg['subnet']);
492
		unset($wancfg['remote']);
493

    
494
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
495
		if ($if == "wan" || $if == "lan") {
496
			$wancfg['enable'] = true;
497
		} else {
498
			$wancfg['enable'] =  $_POST['enable']  == "yes" ? true : false;
499
		}
500

    
501
		/* for dynamic interfaces we tack a gateway item onto the array to prevent system
502
		 * log messages from appearing. They can also manually add these items */
503
		/* 1st added gateway gets a default bit */
504
		$gateway_item = array();
505
		if(empty($a_gateways)) {
506
			$gateway_item['defaultgw'] = "true";
507
		} else {
508
			/* check for duplicates */
509
			$skip = false;
510
			foreach($a_gateways as $item) {
511
				if(($item['interface'] == "$if") && ($item['gateway'] == "dynamic")) {
512
					$skip = true;
513
				}
514
			}
515
			if($skip == false) {
516
				$gateway_item['gateway'] = "dynamic";
517
				$gateway_item['descr'] = "Interface {$if} dynamic gateway";
518
				$gateway_item['name'] = "GW_" . strtoupper($if);
519
				$gateway_item['interface'] = "{$if}";
520
			} else {
521
				unset($gateway_item);
522
			}
523
		}
524

    
525
		switch($_POST['type']) {
526
			case "static":
527
				$wancfg['ipaddr'] = $_POST['ipaddr'];
528
				$wancfg['subnet'] = $_POST['subnet'];
529
				if ($_POST['gateway'] != "none") {
530
					$wancfg['gateway'] = $_POST['gateway'];
531
				}
532
				if (isset($wancfg['ispointtopoint'])) {
533
					$wancfg['pointtopoint'] = $_POST['pointtopoint'];
534
				}
535
				break;
536
			case "dhcp":
537
				$wancfg['ipaddr'] = "dhcp";
538
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
539
				$wancfg['alias-address'] = $_POST['alias-address'];
540
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
541
				if($gateway_item) {
542
					$a_gateways[] = $gateway_item;
543
				}
544
				break;
545
			case "carpdev-dhcp":
546
				$wancfg['ipaddr'] = "carpdev-dhcp";
547
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
548
				$wancfg['alias-address'] = $_POST['alias-address'];
549
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
550
				if($gateway_item) {
551
					$a_gateways[] = $gateway_item;
552
				}
553
				break;
554
			case "pppoe":
555
				$wancfg['ipaddr'] = "pppoe";
556
				$wancfg['pppoe_username'] = $_POST['pppoe_username'];
557
				$wancfg['pppoe_password'] = $_POST['pppoe_password'];
558
				$wancfg['provider'] = $_POST['provider'];
559
				$wancfg['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
560
				$wancfg['timeout'] = $_POST['pppoe_idletimeout'];
561
				if($gateway_item) {
562
					$a_gateways[] = $gateway_item;
563
				}
564
				break;
565
			case "pptp":
566
				$wancfg['ipaddr'] = "pptp";
567
				$wancfg['pptp_username'] = $_POST['pptp_username'];
568
				$wancfg['pptp_password'] = $_POST['pptp_password'];
569
				$wancfg['local'] = $_POST['pptp_local'];
570
				$wancfg['subnet'] = $_POST['pptp_subnet'];
571
				$wancfg['remote'] = $_POST['pptp_remote'];
572
				$wancfg['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
573
				$wancfg['timeout'] = $_POST['pptp_idletimeout'];
574
				if($gateway_item) {
575
					$a_gateways[] = $gateway_item;
576
				}
577
				break;
578
		}
579
		handle_pppoe_reset();
580
		/* reset cron items if necessary */
581
		if (empty($_POST['pppoe_preset'])) {
582
			/* test whether a cron item exists and unset() it if necessary */
583
			$itemhash = getMPDCRONSettings();
584
			$item = $itemhash['ITEM'];
585
			if (isset($item))
586
				unset($config['cron']['item'][$itemhash['ID']]); 
587
		}
588
		if($_POST['blockpriv'] == "yes") {
589
			$wancfg['blockpriv'] = true;
590
		} else {
591
			unset($wancfg['blockpriv']);
592
		}
593
		if($_POST['blockbogons'] == "yes") {
594
			$wancfg['blockbogons'] = true;
595
		} else {
596
			unset($wancfg['blockbogons']);
597
		}
598
		$wancfg['spoofmac'] = $_POST['spoofmac'];
599
		if (empty($_POST['mtu'])) {
600
			unset($wancfg['mtu']);
601
		} else {
602
			$wancfg['mtu'] = $_POST['mtu'];
603
		}
604
		if (isset($wancfg['wireless'])) {
605
			handle_wireless_post();
606
		}
607
		write_config();
608
		mark_subsystem_dirty('interfaces');
609
		/* regenerate cron settings/crontab file */
610
		configure_cron();
611
		conf_mount_ro();
612
		header("Location: interfaces.php?if={$if}");
613
		exit;
614
	}
615
} // end if($_POST) 
616

    
617
function handle_pppoe_reset() {
618
	global $_POST, $config, $g, $wancfg, $if;
619
	/* perform a periodic reset? */
620
	if(!isset($_POST['pppoe_preset'])) {
621
		setup_pppoe_reset_file($if, false);		
622
		return;
623
	}
624
	if (!is_array($config['cron']['item'])) 
625
		$config['cron']['item'] = array(); 
626
	$itemhash = getMPDCRONSettings();
627
	$item = $itemhash['ITEM'];
628
	if (empty($item)) 
629
		$item = array();
630
	if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] == "custom") {
631
		$wancfg['pppoe']['pppoe-reset-type'] = "custom";
632
		$pconfig['pppoe_pr_custom'] = true;
633
		$item['minute'] = $_POST['pppoe_resetminute'];
634
		$item['hour'] = $_POST['pppoe_resethour'];
635
		if (isset($_POST['pppoe_resetdate']) && $_POST['pppoe_resetdate'] <> "" && strlen($_POST['pppoe_resetdate']) == 10) {
636
			$date = explode("/", $_POST['pppoe_resetdate']);
637
			$item['mday'] = $date[1];
638
			$item['month'] = $date[0];
639
		} else {
640
			$item['mday'] = "*";
641
			$item['month'] = "*";
642
		}
643
		$item['wday'] = "*";
644
		$item['who'] = "root";
645
		$item['command'] = CRON_PPPOE_CMD_FILE;
646
	} else if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] = "preset") {
647
		$wancfg['pppoe']['pppoe-reset-type'] = "preset";
648
		$pconfig['pppoe_pr_preset'] = true;
649
		switch ($_POST['pppoe_pr_preset_val']) {
650
			case "monthly":
651
				$item['minute'] = "0";
652
				$item['hour'] = "0";
653
				$item['mday'] = "1";
654
				$item['month'] = "*";
655
				$item['wday'] = "*";
656
				$item['who'] = "root";
657
				$item['command'] = CRON_PPPOE_CMD_FILE;
658
				break;
659
	        	case "weekly":
660
				$item['minute'] = "0";
661
				$item['hour'] = "0";
662
				$item['mday'] = "*";
663
				$item['month'] = "*";
664
				$item['wday'] = "0";
665
				$item['who'] = "root";
666
				$item['command'] = CRON_PPPOE_CMD_FILE;
667
				break;
668
			case "daily":
669
				$item['minute'] = "0";
670
				$item['hour'] = "0";
671
				$item['mday'] = "*";
672
				$item['month'] = "*";
673
				$item['wday'] = "*";
674
				$item['who'] = "root";
675
				$item['command'] = CRON_PPPOE_CMD_FILE;
676
				break;
677
			case "hourly":
678
				$item['minute'] = "0";
679
				$item['hour'] = "*";
680
				$item['mday'] = "*";
681
				$item['month'] = "*";
682
				$item['wday'] = "*";
683
				$item['who'] = "root";
684
				$item['command'] = CRON_PPPOE_CMD_FILE;
685
				break;
686
		} // end switch
687
	} // end if
688
	if (isset($itemhash['ID'])) 
689
		$config['cron']['item'][$itemhash['ID']] = $item;
690
	else 
691
		$config['cron']['item'][] = $item;
692
	/* finally install the pppoerestart file */
693
	if (isset($_POST['pppoe_preset'])) {
694
		setup_pppoe_reset_file($if, true);
695
		$wancfg['pppoe_reset'] = true;
696
		$wancfg['pppoe_preset'] = true;
697
		sigkillbypid("{$g['varrun_path']}/cron.pid", "HUP");
698
	} else {
699
		unset($wancfg['pppoe_reset']);
700
		unset($wancfg['pppoe_preset']);		
701
		setup_pppoe_reset_file($if, false);	
702
	}
703
}
704

    
705
function handle_wireless_post() {
706
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr;
707
	if (!is_array($wancfg['wireless']))
708
		$wancfg['wireless'] = array();
709
	$wancfg['wireless']['standard'] = $_POST['standard'];
710
	$wancfg['wireless']['mode'] = $_POST['mode'];
711
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
712
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
713
	$wancfg['wireless']['channel'] = $_POST['channel'];
714
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
715
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
716
	$wancfg['wireless']['distance'] = $_POST['distance'];
717
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
718
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
719
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
720
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
721
		foreach($wl_countries_attr as $wl_country) {
722
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
723
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
724
				break;
725
			}
726
		}
727
	}
728
	if (!is_array($wancfg['wireless']['wpa']))
729
		$wancfg['wireless']['wpa'] = array();
730
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
731
	$wancfg['wireless']['wpa']['auth_algs'] = $_POST['auth_algs'];
732
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
733
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
734
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
735
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
736
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
737
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
738
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
739
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
740
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
741
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
742
	if ($_POST['hidessid_enable'] == "yes")
743
		$wancfg['wireless']['hidessid']['enable'] = true;
744
	else if (isset($wancfg['wireless']['hidessid']['enable']))
745
		unset($wancfg['wireless']['hidessid']['enable']);
746
	if ($_POST['mac_acl_enable'] == "yes")
747
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
748
	else if (isset($wancfg['wireless']['wpa']['mac_acl_enable']))
749
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
750
	if ($_POST['ieee8021x'] == "yes")
751
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
752
	else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable']))
753
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
754
	if ($_POST['wpa_strict_rekey'] == "yes")
755
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
756
	else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey']))
757
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
758
	if ($_POST['debug_mode'] == "yes")
759
		$wancfg['wireless']['wpa']['debug_mode'] = true;
760
	else if (isset($wancfg['wireless']['wpa']['debug_mode']))
761
		sunset($wancfg['wireless']['wpa']['debug_mode']);
762
	if ($_POST['wpa_enable'] == "yes")
763
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
764
	else if (isset($wancfg['wireless']['wpa']['enable']))
765
		unset($wancfg['wireless']['wpa']['enable']);
766
	if ($_POST['wep_enable'] == "yes") {
767
		if (!is_array($wancfg['wireless']['wep']))
768
			$wancfg['wireless']['wep'] = array();
769
		$wancfg['wireless']['wep']['enable'] = $_POST['wep_enable'] = true;
770
	} else if (isset($wancfg['wireless']['wep']))
771
		unset($wancfg['wireless']['wep']);
772
	if ($_POST['wme_enable'] == "yes") {
773
		if (!is_array($wancfg['wireless']['wme']))
774
			$wancfg['wireless']['wme'] = array();
775
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
776
	} else if (isset($wancfg['wireless']['wme']['enable']))
777
		unset($wancfg['wireless']['wme']['enable']);
778
	if ($_POST['puremode'] == "11g") {
779
		if (!is_array($wancfg['wireless']['pureg']))
780
			$wancfg['wireless']['pureg'] = array();
781
		$wancfg['wireless']['pureg']['enable'] = true;
782
	} else if ($_POST['puremode'] == "11n") {
783
		if (!is_array($wancfg['wireless']['puren']))
784
			$wancfg['wireless']['puren'] = array();
785
		$wancfg['wireless']['puren']['enable'] = true;
786
	} else {
787
		if (isset($wancfg['wireless']['pureg']))
788
			unset($wancfg['wireless']['pureg']);
789
		if (isset($wancfg['wireless']['puren']))
790
			unset($wancfg['wireless']['puren']);
791
	}
792
	if ($_POST['apbridge_enable'] == "yes") {
793
		if (!is_array($wancfg['wireless']['apbridge']))
794
			$wancfg['wireless']['apbridge'] = array();
795
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
796
	} else if (isset($wancfg['wireless']['apbridge']['enable']))
797
		unset($wancfg['wireless']['apbridge']['enable']);
798
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
799
		if (!is_array($wancfg['wireless']['turbo']))
800
			$wancfg['wireless']['turbo'] = array();
801
		$wancfg['wireless']['turbo']['enable'] = true;
802
	} else if (isset($wancfg['wireless']['turbo']['enable']))
803
		unset($wancfg['wireless']['turbo']['enable']);
804
	$wancfg['wireless']['wep']['key'] = array();
805
	for ($i = 1; $i <= 4; $i++) {
806
		if ($_POST['key' . $i]) {
807
			$newkey = array();
808
			$newkey['value'] = $_POST['key' . $i];
809
			if ($_POST['txkey'] == $i)
810
				$newkey['txkey'] = true;
811
			$wancfg['wireless']['wep']['key'][] = $newkey;
812
		}
813
	}
814
	interface_sync_wireless_clones($wancfg, true);
815
}
816

    
817
function check_wireless_mode() {
818
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
819

    
820
	if ($wancfg['wireless']['mode'] == $_POST['mode'])
821
		return;
822

    
823
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif)))
824
		$clone_count = 1;
825
	else
826
		$clone_count = 0;
827
	if (is_array($config['wireless']['clone'])) {
828
		foreach ($config['wireless']['clone'] as $clone) {
829
			if ($clone['if'] == $wlanbaseif)
830
				$clone_count++;
831
		}
832
	}
833
	if ($clone_count > 1) {
834
		$old_wireless_mode = $wancfg['wireless']['mode'];
835
		$wancfg['wireless']['mode'] = $_POST['mode'];
836
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
837
			$input_errors[] = "Unable to change mode to {$wlan_modes[$wancfg['wireless']['mode']]}.  You may already have the maximum number of wireless clones supported in this mode.";
838
		} else {
839
			mwexec("/sbin/ifconfig {$wlanif}_ destroy");
840
		}
841
		$wancfg['wireless']['mode'] = $old_wireless_mode;
842
	}
843
}
844

    
845
$pgtitle = array("Interfaces", $pconfig['descr']);
846
$closehead = false;
847
include("head.inc");
848
$types = array("none" => "None", "static" => "Static", "dhcp" => "DHCP", "pppoe" => "PPPoE", "pptp" => "PPTP" /* , "carpdev-dhcp" => "CarpDev"*/); 
849

    
850
?>
851

    
852
<script type="text/javascript" src="/javascript/numericupdown/js/numericupdown.js"></script>
853
<link href="/javascript/numericupdown/css/numericupdown.css" rel="stylesheet" type="text/css" />
854
<script type="text/javascript" src="/javascript/datepicker/js/datepicker.js"></script>
855
<link href="/javascript/datepicker/css/datepicker.css" rel="stylesheet" type="text/css"/>
856

    
857
<script type="text/javascript">
858
	function updateType(t){
859
		switch(t) {
860
	<?php
861
		/* OK, so this is sick using php to generate javascript, but it needed to be done */
862
		foreach ($types as $key => $val) {
863
			echo "case \"{$key}\": {\n";
864
			$t = $types;
865
			foreach ($t as $k => $v) {
866
				if ($k != $key) {
867
					echo "$('{$k}').hide();\n";
868
				}
869
			}
870
			echo "}\n";
871
		}
872
	?>
873
		}
874
		$(t).show();
875
	}
876

    
877
	function show_allcfg(obj) {
878
		if (obj.checked)
879
			$('allcfg').show();
880
		else
881
			$('allcfg').hide();
882
	}
883
	
884
	function show_periodic_reset(obj) {
885
		if (obj.checked)
886
			$('presetwrap').show();
887
		else
888
			$('presetwrap').hide();
889
	}
890

    
891
	function show_mon_config() {
892
		document.getElementById("showmonbox").innerHTML='';
893
		aodiv = document.getElementById('showmon');
894
		aodiv.style.display = "block";
895
	}
896

    
897
	function openwindow(url) {
898
		var oWin = window.open(url,"pfSensePop","width=620,height=400,top=150,left=150");
899
		if (oWin==null || typeof(oWin)=="undefined") 
900
			return false;
901
		else 
902
			return true;
903
	}
904
</script>
905
</head>
906
	<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
907
	<?php include("fbegin.inc"); ?>
908
	<form action="interfaces.php" method="post" name="iform" id="iform">
909
		<?php if ($input_errors) print_input_errors($input_errors); ?>
910
		<?php if (is_subsystem_dirty('interfaces')): ?><p>
911
		<?php print_info_box_np(gettext("The {$wancfg['descr']} configuration has been changed.<p>You must apply the changes in order for them to take effect.<p>Don't forget to adjust the DHCP Server range if needed before applying."));?><br />
912
		<?php endif; ?>
913
		<?php if ($savemsg) print_info_box($savemsg); ?>
914
		<table width="100%" border="0" cellpadding="6" cellspacing="0">
915
		<tr>
916
                                <td id="mainarea">
917
                                        <div class="tabcont">
918
		<table width="100%" border="0" cellpadding="6" cellspacing="0">
919
		<tr>
920
			<td colspan="2" valign="top" class="listtopic">General configuration</td>
921
		</tr>
922
		<?php if ($if != "wan" && $if != "lan"): ?>
923
		<tr>
924
			<td width="22%" valign="top" class="vncell">Enable</td>
925
			<td width="78%" class="vtable">
926
				<input name="enable" type="checkbox" value="yes" <?php if ($pconfig['enable'] == true) echo "checked"; ?> onClick="show_allcfg(this);">
927
			<strong>Enable Interface</strong>
928
			</td>
929
		</tr>
930
		<?php else: ?>
931
		<input name="enable" type="hidden" value="yes">
932
		<?php endif; ?>
933
		</table>
934
		<div style="display:none;" name="allcfg" id="allcfg">
935
		<table width="100%" border="0" cellpadding="6" cellspacing="0">
936
			<tr>
937
				<td width="22%" valign="top" class="vncell">Description</td>
938
				<td width="78%" class="vtable">
939
					<input name="descr" type="text" class="formfld unknown" id="descr" size="30" value="<?=htmlspecialchars($pconfig['descr']);?>">
940
					<br><span class="vexpl">Enter a description (name) for the interface here.</span>
941
				</td>
942
			</tr>
943
		<?
944
		 if(!$wancfg['serialport']):
945
		?>
946
			<tr>
947
				<td valign="middle" class="vncell"><strong>Type</strong></td>
948
				<td class="vtable"> 
949
					<select name="type" onChange="updateType(this.value);" class="formselect" id="type">
950
					<?php 
951
						foreach ($types as $key => $opt) { 
952
							echo "<option onClick=\"updateType('{$key}');\"";
953
							if ($key == $pconfig['type']) 
954
								echo " selected";
955
							echo " value=\"{$key}\" >" . htmlspecialchars($opt);
956
							echo "</option>";
957
					    } 
958
					?>
959
					</select>
960
				</td>
961
			</tr>
962
			<?php endif; ?>
963
			<tr>
964
				<td valign="top" class="vncell">MAC address</td>
965
				<td class="vtable">
966
					<input name="spoofmac" type="text" class="formfld unknown" id="spoofmac" size="30" value="<?=htmlspecialchars($pconfig['spoofmac']);?>">
967
				    <?php
968
						$ip = getenv('REMOTE_ADDR');
969
						$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
970
						$mac = str_replace("\n","",$mac);
971
						if($mac):
972
					?>
973
						<a OnClick="document.forms[0].spoofmac.value='<?=$mac?>';" href="#">Insert my local MAC address</a>
974
					<?php endif; ?>
975
					<br>
976
					This field can be used to modify (&quot;spoof&quot;) the MAC
977
					address of the WAN interface<br>
978
					(may be required with some cable connections)<br>
979
					Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx
980
					or leave blank
981
				</td>
982
			</tr>
983
			<tr>
984
				<td valign="top" class="vncell">MTU</td>
985
				<td class="vtable"> 
986
					<input name="mtu" type="text" class="formfld unknown" id="mtu" size="8" value="<?=htmlspecialchars($pconfig['mtu']);?>">
987
					<br>
988
					If you enter a value in this field, then MSS clamping for
989
					TCP connections to the value entered above minus 40 (TCP/IP
990
					header size) will be in effect. If you leave this field blank,
991
					an MTU of 1500 bytes will be assumed.
992
				</td>
993
			</tr>
994
			<tr>
995
				<td colspan="2" valign="top" height="16"></td>
996
			</tr>			
997
			<tr style="display:none;" name="none" id="none">
998
			</tr>
999
			<tr style="display:none;" name="static" id="static">
1000
				<td colspan="2" style="padding:0px;">
1001
					<table width="100%" border="0" cellpadding="6" cellspacing="0">
1002
						<tr>
1003
							<td colspan="2" valign="top" class="listtopic">Static IP configuration</td>
1004
						</tr>
1005
						<tr>
1006
							<td width="22%" valign="top" class="vncellreq">IP address</td>
1007
							<td width="78%" class="vtable"> 
1008
								<input name="ipaddr" type="text" class="formfld unknown" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>">
1009
								/
1010
								<select name="subnet" class="formselect" id="subnet">
1011
									<?php
1012
									for ($i = 32; $i > 0; $i--) {
1013
										if($i <> 31) {
1014
											echo "<option value=\"{$i}\" ";
1015
											if ($i == $pconfig['subnet']) echo "selected";
1016
											echo ">" . $i . "</option>";
1017
										}
1018
									}
1019
									?>
1020
								</select>
1021
							</td>
1022
						</tr>
1023
						<?php if (isset($wancfg['ispointtopoint'])): ?>
1024
							<tr>
1025
								<td width="22%" valign="top" class="vncellreq">Point-to-point IP address </td>
1026
								<td width"78%" class="vtable">
1027
									<input name="pointtopoint" type="text" class="formfld unknown" id="pointtopoint" size="20" value="<?=htmlspecialchars($pconfig['pointtopoint']);?>">
1028
								</td>
1029
							</tr>
1030
						<?php endif; ?>
1031
						<tr>
1032
							<td width="22%" valign="top" class="vncellreq">Gateway</td>
1033
							<td width="78%" class="vtable">
1034
								<select name="gateway" class="formselect" id="gateway">
1035
									<option value="none" selected>None</option>
1036
										<?php
1037
										if(count($a_gateways) > 0) {
1038
											foreach ($a_gateways as $gateway) {
1039
												if($gateway['interface'] == $if) {
1040
										?>
1041
												<option value="<?=$gateway['name'];?>" <?php if ($gateway['name'] == $pconfig['gateway']) echo "selected"; ?>>
1042
													<?=htmlspecialchars($gateway['name']);?>
1043
												</option>
1044
										<?php
1045
												}
1046
											}
1047
										}
1048
										?>
1049
								</select>
1050
								<br/>
1051
								<div id='addgwbox'>
1052
									If this interface is an Internet connection, select an existing Gateway from the list or <a OnClick="show_add_gateway();" href="#">add a new one</a>.
1053
								</div>
1054
								<div id='notebox'>
1055
								</div>
1056
								<div id="status">
1057
								</div>								
1058
								<div style="display:none" id="addgateway" name="addgateway">
1059
									<p> 
1060
									<table border="1" style="background:#990000; border-style: none none none none; width:225px;"><tr><td>
1061
										<table bgcolor="#990000" cellpadding="1" cellspacing="1">
1062
											<tr><td>&nbsp;</td>
1063
											<tr>
1064
												<td colspan="2"><center><b><font color="white">Add new gateway:</b></center></td>
1065
											</tr>
1066
											<tr><td>&nbsp;</td>
1067
											<?php
1068
											if($if == "wan" || $if == "WAN")
1069
												$checked = " CHECKED";
1070
											?>
1071
											<tr>
1072
												<td width="45%" align="right"><font color="white">Default  gateway:</td><td><input type="checkbox" id="defaultgw" name="defaultgw"<?=$checked?>></td>
1073
											</tr>												
1074
											<tr>
1075
												<td align="right"><font color="white">Gateway Name:</td><td><input id="name" name="name" value="<?=$wancfg['descr'] . "GW"?>"></td>
1076
											</tr>
1077
											<tr>
1078
												<td align="right"><font color="white">Gateway IP:</td><td><input id="gatewayip" name="gatewayip"></td>
1079
											</tr>
1080
											<tr>
1081
												<td align="right"><font color="white">Description:</td><td><input id="gatewaydescr" name="gatewaydescr"></td>
1082
											</tr>
1083
											<tr><td>&nbsp;</td>
1084
											<tr>
1085
												<td colspan="2">
1086
													<center>
1087
														<div id='savebuttondiv'>
1088
															<input type="hidden" name="addrtype" id="addrtype" value="IPv4" />
1089
															<input id="gwsave" type="Button" value="Save Gateway" onClick='hide_add_gatewaysave();'> 
1090
															<input id="gwcancel" type="Button" value="Cancel" onClick='hide_add_gateway();'>
1091
														</div>
1092
													</center>
1093
												</td>
1094
											</tr>
1095
											<tr><td>&nbsp;</td>
1096
										</table>
1097
										</td></tr></table>
1098
									<p/>
1099
								</div>
1100
							</td>
1101
						</tr>
1102
					</table>
1103
				</td>
1104
				</tr>
1105
				<tr style="display:none;" name="dhcp" id="dhcp">
1106
					<td colspan="2" style="padding: 0px;">
1107
						<table width="100%" border="0" cellpadding="6" cellspacing="0">
1108
							<tr>
1109
								<td colspan="2" valign="top" class="listtopic">DHCP client configuration</td>
1110
							</tr>
1111
							<tr>
1112
								<td width="22%" valign="top" class="vncell">Hostname</td>
1113
								<td width="78%" class="vtable">
1114
									<input name="dhcphostname" type="text" class="formfld unknown" id="dhcphostname" size="40" value="<?=htmlspecialchars($pconfig['dhcphostname']);?>">
1115
									<br>
1116
									The value in this field is sent as the DHCP client identifier
1117
									and hostname when requesting a DHCP lease. Some ISPs may require
1118
									this (for client identification).
1119
								</td>
1120
							</tr>
1121
							<tr>
1122
								<td width="22%" valign="top" class="vncell">Alias IP address</td>
1123
								<td width="78%" class="vtable"> 
1124
									<input name="alias-address" type="text" class="formfld unknown" id="alias-address" size="20" value="<?=htmlspecialchars($pconfig['alias-address']);?>">
1125
									<select name="alias-subnet" class="formselect" id="alias-subnet">
1126
										<?php
1127
										for ($i = 32; $i > 0; $i--) {
1128
											if($i <> 31) {
1129
												echo "<option value=\"{$i}\" ";
1130
												if ($i == $pconfig['alias-subnet']) echo "selected";
1131
												echo ">" . $i . "</option>";
1132
											}
1133
										}
1134
										?>
1135
									</select>
1136
									The value in this field is used as a fixed alias IP address by the
1137
									DHCP client.
1138
								</td>
1139
							</tr>
1140
						</table>
1141
					</td>
1142
				</tr>
1143
				<tr style="display:none;" name="pppoe" id="pppoe">
1144
					<td colspan="2" style="padding:0px;">
1145
						<table width="100%" border="0" cellpadding="6" cellspacing="0">
1146
							<tr>
1147
								<td colspan="2" valign="top" class="listtopic">PPPoE configuration</td>
1148
							</tr>
1149
							<tr>
1150
								<td width="22%" valign="top" class="vncellreq">Username</td>
1151
								<td width="78%" class="vtable">
1152
										<input name="pppoe_username" type="text" class="formfld user" id="pppoe_username" size="20" value="<?=htmlspecialchars($pconfig['pppoe_username']);?>">
1153
								</td>
1154
							</tr>
1155
							<tr>
1156
								<td width="22%" valign="top" class="vncellreq">Password</td>
1157
								<td width="78%" class="vtable">
1158
									<input name="pppoe_password" type="password" class="formfld pwd" id="pppoe_password" size="20" value="<?=htmlspecialchars($pconfig['pppoe_password']);?>">
1159
								</td>
1160
							</tr>
1161
							<tr>
1162
								<td width="22%" valign="top" class="vncell">Service name</td>
1163
								<td width="78%" class="vtable"><input name="provider" type="text" class="formfld unknown" id="provider" size="20" value="<?=htmlspecialchars($pconfig['provider']);?>">
1164
									<br> <span class="vexpl">Hint: this field can usually be left empty</span>
1165
								</td>
1166
							</tr>
1167
							<tr>
1168
								<td width="22%" valign="top" class="vncell">Dial on demand</td>
1169
								<td width="78%" class="vtable">
1170
									<input name="pppoe_dialondemand" type="checkbox" id="pppoe_dialondemand" value="enable" <?php if ($pconfig['pppoe_dialondemand']) echo "checked"; ?>>
1171
									<strong>Enable Dial-On-Demand mode</strong><br>
1172
		    						This option causes the interface to operate in dial-on-demand mode, allowing you to have a <i>virtual full time</i> connection. The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.
1173
								</td>
1174
							</tr>
1175
							<tr>
1176
								<td width="22%" valign="top" class="vncell">Idle timeout</td>
1177
								<td width="78%" class="vtable">
1178
									<input name="pppoe_idletimeout" type="text" class="formfld unknown" id="pppoe_idletimeout" size="8" value="<?=htmlspecialchars($pconfig['pppoe_idletimeout']);?>"> seconds<br>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.
1179
								</td>
1180
							</tr>
1181
							<tr>
1182
								<td width="22%" valign="top" class="vncell"><?=gettext("Periodic reset");?></td>
1183
								<td width="78%" class="vtable">
1184
									<input name="pppoe_preset" type="checkbox" id="pppoe_preset" value="yes" <?php if ($pconfig['pppoe_preset']) echo "checked=\"checked\""; ?> onclick="show_periodic_reset(this);" />
1185
										<?= gettext("enable periodic PPPoE resets"); ?>
1186
										<br />
1187
										<?php if ($pconfig['pppoe_preset']): ?>
1188
											<table id="presetwrap" cellspacing="0" cellpadding="0" width="100%">
1189
											<?php else: ?>
1190
												<table id="presetwrap" cellspacing="0" cellpadding="0" width="100%" style="display: none;">
1191
												<?php endif; ?>
1192
												<tr>
1193
													<td align="left" valign="top">
1194
														<p style="margin: 4px; padding: 4px 0 4px 0; width: 94%;">
1195
															<input name="pppoe_pr_type" type="radio" id="pppoe_pr_custom" value="custom" <?php if ($pconfig['pppoe_pr_custom']) echo "checked=\"checked\""; ?> onclick="if (this.checked) { Effect.Appear('pppoecustomwrap', { duration: 0.0 }); Effect.Fade('pppoepresetwrap', { duration: 0.0 }); }" /> 
1196
																<?= gettext("provide a custom reset time"); ?>
1197
																<br />
1198
																<input name="pppoe_pr_type" type="radio" id="pppoe_pr_preset" value="preset" <?php if ($pconfig['pppoe_pr_preset']) echo "checked=\"checked\""; ?> onclick="if (this.checked) { Effect.Appear('pppoepresetwrap', { duration: 0.0 }); Effect.Fade('pppoecustomwrap', { duration: 0.0 }); }" /> 
1199
																	<?= gettext("select reset time from a preset"); ?>
1200
																</p>
1201
																<?php if ($pconfig['pppoe_pr_custom']): ?>
1202
																	<p style="margin: 2px; padding: 4px; width: 94%;" id="pppoecustomwrap">
1203
																	<?php else: ?>
1204
																		<p style="margin: 2px; padding: 4px; width: 94%; display: none;" id="pppoecustomwrap">
1205
																		<?php endif; ?>
1206
																		<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" /> 
1207
																		<?= gettext("hour (0-23)"); ?><br />
1208
																		<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" /> 
1209
																		<?= gettext("minute (0-59)"); ?><br />
1210
																		<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']);?>" /> 
1211
																		<?= gettext("reset at a specific date (mm/dd/yyyy)"); ?>
1212
																		<br />&nbsp;<br />
1213
																		<span class="red"><strong>Note: </strong></span>
1214
																		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.
1215
																	</p>
1216
																	<?php if ($pconfig['pppoe_pr_preset']): ?>
1217
																		<p style="margin: 2px; padding: 4px; width: 94%;" id="pppoepresetwrap">
1218
																		<?php else: ?>
1219
																			<p style="margin: 2px; padding: 4px; width: 94%; display: none;" id="pppoepresetwrap">
1220
																			<?php endif; ?>
1221
																			<input name="pppoe_pr_preset_val" type="radio" id="pppoe_monthly" value="monthly" <?php if ($pconfig['pppoe_monthly']) echo "checked=\"checked\""; ?> /> 
1222
																			<?= gettext("reset at each month ('0 0 1 * *')"); ?>
1223
																			<br />
1224
																			<input name="pppoe_pr_preset_val" type="radio" id="pppoe_weekly" value="weekly" <?php if ($pconfig['pppoe_weekly']) echo "checked=\"checked\""; ?> /> 
1225
																			<?= gettext("reset at each week ('0 0 * * 0')"); ?>
1226
																			<br />
1227
																			<input name="pppoe_pr_preset_val" type="radio" id="pppoe_daily" value="daily" <?php if ($pconfig['pppoe_daily']) echo "checked=\"checked\""; ?> /> 
1228
																			<?= gettext("reset at each day ('0 0 * * *')"); ?>
1229
																			<br />
1230
																			<input name="pppoe_pr_preset_val" type="radio" id="pppoe_hourly" value="hourly" <?php if ($pconfig['pppoe_hourly']) echo "checked=\"checked\""; ?> /> 
1231
																			<?= gettext("reset at each hour ('0 * * * *')"); ?>
1232
																		</p>
1233
																	</td>
1234
																</tr>
1235
															</table>
1236
														</td>
1237
													</tr>
1238
												</table>
1239
											</td>
1240
										</tr>
1241
										<tr style="display:none;" name="pptp" id="pptp">
1242
											<td colspan="2" style="padding:0px;">
1243
												<table width="100%" border="0" cellpadding="6" cellspacing="0">
1244
													<tr>
1245
														<td colspan="2" valign="top" class="listtopic">PPTP configuration</td>
1246
													</tr>
1247
													<tr>
1248
														<td width="22%" valign="top" class="vncellreq">Username</td>
1249
														<td width="78%" class="vtable">
1250
															<input name="pptp_username" type="text" class="formfld user" id="pptp_username" size="20" value="<?=htmlspecialchars($pconfig['pptp_username']);?>">
1251
														</td>
1252
													</tr>
1253
													<tr>
1254
														<td width="22%" valign="top" class="vncellreq">Password</td>
1255
														<td width="78%" class="vtable">
1256
															<input name="pptp_password" type="text" class="formfld pwd" id="pptp_password" size="20" value="<?=htmlspecialchars($pconfig['pptp_password']);?>">
1257
														</td>
1258
													</tr>
1259
													<tr>
1260
														<td width="22%" width="100" valign="top" class="vncellreq">Local IP address</td>
1261
														<td width="78%" class="vtable"> 
1262
															<input name="pptp_local" type="text" class="formfld unknown" id="pptp_local" size="20"  value="<?=htmlspecialchars($pconfig['pptp_local']);?>">
1263
															/
1264
															<select name="pptp_subnet" class="formselect" id="pptp_subnet">
1265
																<?php for ($i = 31; $i > 0; $i--): ?>
1266
																	<option value="<?=$i;?>" <?php if ($i == $pconfig['pptp_subnet']) echo "selected"; ?>>
1267
																		<?=$i;?>
1268
																	</option>
1269
																<?php endfor; ?>
1270
															</select>
1271
														</td>
1272
													</tr>
1273
													<tr>
1274
														<td width="22%" width="100" valign="top" class="vncellreq">Remote IP address</td>
1275
														<td width="78%" class="vtable">
1276
															<input name="pptp_remote" type="text" class="formfld unknown" id="pptp_remote" size="20" value="<?=htmlspecialchars($pconfig['pptp_remote']);?>">
1277
														</td>
1278
													</tr>
1279
													<tr>
1280
														<td width="22%" valign="top" class="vncell">Dial on demand</td>
1281
														<td width="78%" class="vtable">
1282
															<input name="pptp_dialondemand" type="checkbox" id="pptp_dialondemand" value="enable" <?php if ($pconfig['pptp_dialondemand']) echo "checked"; ?>>
1283
															<strong>Enable Dial-On-Demand mode</strong><br>
1284
															This option causes the interface to operate in dial-on-demand mode, allowing you to have a <i>virtual full time</i> connection. The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected.
1285
														</td>
1286
													</tr>
1287
													<tr>
1288
														<td width="22%" valign="top" class="vncell">Idle timeout</td>
1289
														<td width="78%" class="vtable">
1290
															<input name="pptp_idletimeout" type="text" class="formfld unknown" id="pptp_idletimeout" size="8" value="<?=htmlspecialchars($pconfig['pptp_idletimeout']);?>"> seconds<br>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.
1291
														</td>
1292
													</tr>
1293
												</table>
1294
											</td>
1295
										</tr>
1296
										<?php
1297
											/* Wireless interface? */
1298
											if (isset($wancfg['wireless'])):
1299
										?>
1300
										<tr>
1301
											<td colspan="2" valign="top" height="16"></td>
1302
										</tr>										
1303
										<tr>
1304
											<td colspan="2" valign="top" class="listtopic">Common wireless configuration - Settings apply to all wireless networks on <?=$wlanbaseif;?>.</td>
1305
										</tr>
1306
										<tr>
1307
											<td valign="top" class="vncellreq">Standard</td>
1308
											<td class="vtable">
1309
											<select name="standard" class="formselect" id="standard">
1310
												<?php
1311
												foreach($wl_modes as $wl_standard => $wl_channels) {
1312
													echo "<option ";
1313
													if ($pconfig['standard'] == "$wl_standard")
1314
														echo "selected ";
1315
													echo "value=\"$wl_standard\">802.$wl_standard</option>\n";
1316
												}
1317
												?>
1318
											</select>
1319
										</td>
1320
									</tr>
1321
									<?php if (isset($wl_modes['11g'])): ?>
1322
									<tr>
1323
										<td valign="top" class="vncellreq">802.11g OFDM Protection Mode</td>
1324
										<td class="vtable">
1325
											<select name="protmode" class="formselect" id="protmode">
1326
												<option <? if ($pconfig['protmode'] == 'off') echo "selected";?> value="off">Protection mode off</option>
1327
												<option <? if ($pconfig['protmode'] == 'cts') echo "selected";?> value="cts">Protection mode CTS to self</option>
1328
												<option <? if ($pconfig['protmode'] == 'rtscts') echo "selected";?> value="rtscts">Protection mode RTS and CTS</option>
1329
											</select>
1330
											<br/>
1331
											For IEEE 802.11g, use the specified technique for protecting OFDM frames in a mixed 11b/11g network.
1332
											<br/>
1333
										</td>
1334
									</tr>
1335
									<?php else: ?>
1336
									<input name="protmode" type="hidden" id="protmode" value="off">
1337
									<?php endif; ?>
1338
										<tr>
1339
											<td valign="top" class="vncellreq">Transmit power</td>
1340
											<td class="vtable">
1341
												<select name="txpower" class="formselect" id="txpower">
1342
													<?
1343
													for($x = 99; $x > 0; $x--) {
1344
														if($pconfig["txpower"] == $x)
1345
															$SELECTED = " SELECTED";
1346
														else
1347
															$SELECTED = "";
1348
														echo "<option {$SELECTED}>{$x}</option>\n";
1349
													}
1350
													?>
1351
												</select><br/>
1352
												Note: Typically only a few discreet power settings are available and the driver will use the setting closest to the specified value.  Not all adaptors support changing the transmit power setting.
1353
											</td>
1354
										</tr>
1355
										<tr>
1356
											<td valign="top" class="vncellreq">Channel</td>
1357
											<td class="vtable">
1358
												<select name="channel" class="formselect" id="channel">
1359
													<option <? if ($pconfig['channel'] == 0) echo "selected"; ?> value="0">Auto</option>
1360
													<?php
1361
													foreach($wl_modes as $wl_standard => $wl_channels) {
1362
														if($wl_standard == "11g") { $wl_standard = "11b/g"; }
1363
														else if($wl_standard == "11ng") { $wl_standard = "11b/g/n"; }
1364
														else if($wl_standard == "11na") { $wl_standard = "11a/n"; }
1365
														foreach($wl_channels as $wl_channel) {
1366
															echo "<option ";
1367
															if ($pconfig['channel'] == "$wl_channel") {
1368
																echo "selected ";
1369
															}
1370
															echo "value=\"$wl_channel\">$wl_standard - $wl_channel</option>\n";
1371
														}
1372
													}
1373
													?>
1374
												</select>
1375
												<br/>
1376
												Note: Not all channels may be supported by your card.  Auto may override the wireless standard selected above.
1377
											</td>
1378
										</tr>
1379
										<tr>
1380
											<td valign="top" class="vncell">Distance setting</td>
1381
											<td class="vtable">
1382
												<input name="distance" type="text" class="formfld unknown" id="distance" size="5" value="<?=htmlspecialchars($pconfig['distance']);?>">
1383
												<br/>
1384
												Note: This field can be used to tune ACK/CTS timers to fit the distance between AP and Client<br/>
1385
												(measured in Meters and works only for Atheros based cards !)
1386
											</td>
1387
										</tr>
1388
										<tr>
1389
											<td valign="top" class="vncell">Regulatory settings</td>
1390
											<td class="vtable">
1391
												Regulatory domain<br/>
1392
												<select name="regdomain" class="formselect" id="regdomain">
1393
													<option <? if (empty($pconfig['regdomain'])) echo "selected"; ?> value="">Default</option>
1394
													<?php
1395
													foreach($wl_regdomains as $wl_regdomain_key => $wl_regdomain) {
1396
														echo "<option ";
1397
														if ($pconfig['regdomain'] == $wl_regdomains_attr[$wl_regdomain_key]['ID']) {
1398
															echo "selected ";
1399
														}
1400
														echo "value=\"{$wl_regdomains_attr[$wl_regdomain_key]['ID']}\">{$wl_regdomain['name']}</option>\n";
1401
													}
1402
													?>
1403
												</select>
1404
												<br/><br/>
1405
												Country (listed with country code and regulatory domain)<br/>
1406
												<select name="regcountry" class="formselect" id="regcountry">
1407
													<option <? if (empty($pconfig['regcountry'])) echo "selected"; ?> value="">Default</option>
1408
													<?php
1409
													foreach($wl_countries as $wl_country_key => $wl_country) {
1410
														echo "<option ";
1411
														if ($pconfig['regcountry'] == $wl_countries_attr[$wl_country_key]['ID']) {
1412
															echo "selected ";
1413
														}
1414
														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";
1415
													}
1416
													?>
1417
												</select>
1418
												<br/>
1419
												Note: Any country setting other than "Default" will override the regulatory domain setting.
1420
												<br/><br/>
1421
												Location<br/>
1422
												<select name="reglocation" class="formselect" id="reglocation">
1423
													<option <? if ($pconfig['reglocation'] == 'indoor') echo "selected"; ?> value="indoor">Indoor</option>
1424
													<option <? if ($pconfig['reglocation'] == 'outdoor') echo "selected"; ?> value="outdoor">Outdoor</option>
1425
													<option <? if ($pconfig['reglocation'] == 'anywhere') echo "selected"; ?> value="anywhere">Anywhere</option>
1426
												</select>
1427
												<br/><br/>
1428
												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.
1429
												<br/>
1430
												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.
1431
											</td>
1432
										</tr>
1433
										<tr>
1434
											<td colspan="2" valign="top" height="16"></td>
1435
										</tr>										
1436
										<tr>
1437
											<td colspan="2" valign="top" class="listtopic">Wireless configuration</td>
1438
										</tr>
1439
									<tr>
1440
										<td valign="top" class="vncellreq">Mode</td>
1441
										<td class="vtable">
1442
											<select name="mode" class="formselect" id="mode">
1443
												<option <? if ($pconfig['mode'] == 'bss') echo "selected";?> value="bss">Infrastructure (BSS)</option>
1444
												<option <? if ($pconfig['mode'] == 'adhoc') echo "selected";?> value="adhoc">Ad-hoc (IBSS)</option>
1445
												<option <? if ($pconfig['mode'] == 'hostap') echo "selected";?> value="hostap">Access Point</option>
1446
											</select>
1447
										</td>
1448
									</tr>
1449
									<tr>
1450
										<td valign="top" class="vncellreq">SSID</td>
1451
										<td class="vtable">
1452
											<input name="ssid" type="text" class="formfld unknown" id="ssid" size="20" value="<?=htmlspecialchars($pconfig['ssid']); ?>">
1453
										</td>
1454
                					</tr>
1455
									<?php if (isset($wl_modes['11ng']) || isset($wl_modes['11na'])): ?>
1456
									<tr>
1457
										<td valign="top" class="vncell">Minimum wireless standard</td>
1458
										<td class="vtable">
1459
											<select name="puremode" class="formselect" id="puremode">
1460
												<option <? if ($pconfig['puremode'] == 'any') echo "selected";?> value="any">Any</option>
1461
												<?php if (isset($wl_modes['11g'])): ?>
1462
												<option <? if ($pconfig['puremode'] == '11g') echo "selected";?> value="11g">802.11g</option>
1463
												<?php endif; ?>
1464
												<option <? if ($pconfig['puremode'] == '11n') echo "selected";?> value="11n">802.11n</option>
1465
											</select>
1466
											<br/>
1467
											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).
1468
										</td>
1469
									</tr>
1470
									<?php elseif (isset($wl_modes['11g'])): ?>
1471
									<tr>
1472
										<td valign="top" class="vncell">802.11g only</td>
1473
										<td class="vtable">
1474
											<input name="puremode" type="checkbox" value="11g"  class="formfld" id="puremode" <? if ($pconfig['puremode'] == '11g') echo "checked";?>>
1475
											<br/>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).
1476
										</td>
1477
									</tr>
1478
									<?php endif; ?>
1479
									<tr>
1480
										<td valign="top" class="vncell">Allow intra-BSS communication</td>
1481
										<td class="vtable">
1482
											<input name="apbridge_enable" type="checkbox" value="yes"  class="formfld" id="apbridge_enable" <? if ($pconfig['apbridge_enable']) echo "checked";?>>
1483
											<br/>
1484
											When operating as an access point, enable this if you want to pass packets between wireless clients directly.
1485
											<br/>
1486
											Disabling the internal bridging is useful when traffic is to be processed with packet filtering.
1487
										</td>
1488
									</tr>
1489
									<tr>
1490
										<td valign="top" class="vncell">Enable WME</td>
1491
										<td class="vtable">
1492
											<input name="wme_enable" type="checkbox" class="formfld" id="wme_enable" value="yes" <? if ($pconfig['wme_enable']) echo "checked";?>>
1493
											<br/>Setting this option will force the card to use WME (wireless QoS).
1494
										</td>
1495
									</tr>
1496
									<tr>
1497
										<td valign="top" class="vncell">Enable Hide SSID</td>
1498
										<td class="vtable">
1499
											<input name="hidessid_enable" type="checkbox" class="formfld" id="hidessid_enable" value="yes" <? if ($pconfig['hidessid_enable']) echo "checked";?>>
1500
											<br/>
1501
											Setting this option will force the card to NOT broadcast its SSID
1502
											<br/>
1503
											(this might create problems for some clients). </td>
1504
										</tr>
1505
										<tr>
1506
											<td valign="top" class="vncell">WEP</td>
1507
											<td class="vtable"> 
1508
												<input name="wep_enable" type="checkbox" id="wep_enable" value="yes" <? if ($pconfig['wep_enable']) echo "checked"; ?>>
1509
												<strong>Enable WEP</strong>
1510
												<table border="0" cellspacing="0" cellpadding="0">
1511
													<tr>
1512
														<td>&nbsp;</td>
1513
														<td>&nbsp;</td>
1514
														<td>&nbsp;TX key&nbsp;</td>
1515
													</tr>
1516
													<tr>
1517
														<td>Key 1:&nbsp;&nbsp;</td>
1518
														<td>
1519
															<input name="key1" type="text" class="formfld unknown" id="key1" size="30" value="<?=htmlspecialchars($pconfig['key1']);?>">
1520
														</td>
1521
														<td align="center">
1522
															<input name="txkey" type="radio" value="1" <? if ($pconfig['txkey'] == 1) echo "checked";?>>
1523
														</td>
1524
													</tr>
1525
													<tr>
1526
														<td>Key 2:&nbsp;&nbsp;</td>
1527
														<td>
1528
															<input name="key2" type="text" class="formfld unknown" id="key2" size="30" value="<?=htmlspecialchars($pconfig['key2']);?>">
1529
														</td>
1530
														<td align="center">
1531
															<input name="txkey" type="radio" value="2" <? if ($pconfig['txkey'] == 2) echo "checked";?>>
1532
														</td>
1533
													</tr>
1534
													<tr>
1535
														<td>Key 3:&nbsp;&nbsp;</td>
1536
														<td>
1537
															<input name="key3" type="text" class="formfld unknown" id="key3" size="30" value="<?=htmlspecialchars($pconfig['key3']);?>">
1538
														</td>
1539
														<td align="center">
1540
															<input name="txkey" type="radio" value="3" <? if ($pconfig['txkey'] == 3) echo "checked";?>>
1541
														</td>
1542
													</tr>
1543
													<tr>
1544
														<td>Key 4:&nbsp;&nbsp;</td>
1545
														<td>
1546
															<input name="key4" type="text" class="formfld unknown" id="key4" size="30" value="<?=htmlspecialchars($pconfig['key4']);?>">
1547
														</td>
1548
														<td align="center">
1549
															<input name="txkey" type="radio" value="4" <? if ($pconfig['txkey'] == 4) echo "checked";?>>
1550
														</td>
1551
													</tr>
1552
												</table>
1553
												<br/>
1554
												40 (64) bit keys may be entered as 5 ASCII characters or 10 hex digits preceded by '0x'.<br/>
1555
												104 (128) bit keys may be entered as 13 ASCII characters or 26 hex digits preceded by '0x'.
1556
											</td>
1557
										</tr>
1558
										<tr>
1559
											<td valign="top" class="vncell">WPA</td>
1560
											<td class="vtable">
1561
												<input name="wpa_enable" type="checkbox" class="formfld" id="wpa_enable" value="yes" <? if ($pconfig['wpa_enable']) echo "checked"; ?>>
1562
												<strong>Enable WPA</strong>
1563
												<br/><br/>
1564
												<table border="0" cellspacing="0" cellpadding="0">
1565
													<tr>
1566
														<td>&nbsp;</td>
1567
														<td>&nbsp;WPA Pre Shared Key&nbsp;</td>
1568
													</tr>
1569
													<tr>
1570
														<td>PSK:&nbsp;&nbsp;</td>
1571
														<td>
1572
															<input name="passphrase" type="text" class="formfld unknown" id="passphrase" size="66" value="<?=htmlspecialchars($pconfig['passphrase']);?>">
1573
														</td>
1574
													</tr>
1575
												</table>
1576
												<br/>Passphrase must be from 8 to 63 characters.
1577
											</td>
1578
										</tr>
1579
										<tr>
1580
											<td valign="top" class="vncell">WPA Mode</td>
1581
											<td class="vtable">
1582
												<select name="wpa_mode" class="formselect" id="wpa_mode">
1583
													<option <? if ($pconfig['wpa_mode'] == '1') echo "selected";?> value="1">WPA</option>
1584
													<option <? if ($pconfig['wpa_mode'] == '2') echo "selected";?> value="2">WPA2</option>
1585
													<option <? if ($pconfig['wpa_mode'] == '3') echo "selected";?> value="3">Both</option>
1586
												</select>
1587
											</td>
1588
										</tr>
1589
										<tr>
1590
											<td valign="top" class="vncell">WPA Key Management Mode</td>
1591
											<td class="vtable"> 
1592
												<select name="wpa_key_mgmt" class="formselect" id="wpa_key_mgmt">
1593
													<option <? if ($pconfig['wpa_key_mgmt'] == 'WPA-PSK') echo "selected";?> value="WPA-PSK">Pre Shared Key</option>
1594
													<option <? if ($pconfig['wpa_key_mgmt'] == 'WPA-EAP') echo "selected";?> value="WPA-EAP">Extensible Authentication Protocol</option>
1595
													<option <? if ($pconfig['wpa_key_mgmt'] == 'WPA-PSK WPA-EAP') echo "selected";?> value="WPA-PSK WPA-EAP">Both</option>
1596
 												</select>
1597
											</td>
1598
										</tr>
1599
										<tr>
1600
											<td valign="top" class="vncell">Authentication</td>
1601
											<td class="vtable">
1602
												<select name="auth_algs" class="formselect" id="auth_algs">
1603
													<option <? if ($pconfig['auth_algs'] == '1') echo "selected";?> value="1">Open System Authentication</option>
1604
													<option <? if ($pconfig['auth_algs'] == '2') echo "selected";?> value="2">Shared Key Authentication</option>
1605
													<option <? if ($pconfig['auth_algs'] == '3') echo "selected";?> value="3">Both</option>
1606
												</select>
1607
												<br/>Note: Shared Key Authentication requires WEP.</br>
1608
											</td>
1609
										</tr>
1610
										<tr>
1611
											<td valign="top" class="vncell">WPA Pairwise</td>
1612
											<td class="vtable">
1613
												<select name="wpa_pairwise" class="formselect" id="wpa_pairwise">
1614
													<option <? if ($pconfig['wpa_pairwise'] == 'CCMP TKIP') echo "selected";?> value="CCMP TKIP">Both</option>
1615
													<option <? if ($pconfig['wpa_pairwise'] == 'CCMP') echo "selected";?> value="CCMP">AES (recommended)</option>
1616
													<option <? if ($pconfig['wpa_pairwise'] == 'TKIP') echo "selected";?> value="TKIP">TKIP</option>
1617
												</select>
1618
											</td>
1619
										</tr>
1620
										<tr>
1621
											<td valign="top" class="vncell">Key Rotation</td>
1622
											<td class="vtable">
1623
												<input name="wpa_group_rekey" type="text" class="formfld unknown" id="wpa_group_rekey" size="30" value="<? echo $pconfig['wpa_group_rekey'] ? $pconfig['wpa_group_rekey'] : "60";?>">
1624
												<br/>Allowed values are 1-9999 but should not be longer than Master Key Regeneration time.
1625
											</td>
1626
										</tr>
1627
										<tr>
1628
											<td valign="top" class="vncell">Master Key Regeneration</td>
1629
											<td class="vtable">
1630
												<input name="wpa_gmk_rekey" type="text" class="formfld" id="wpa_gmk_rekey" size="30" value="<? echo $pconfig['wpa_gmk_rekey'] ? $pconfig['wpa_gmk_rekey'] : "3600";?>">
1631
												<br/>Allowed values are 1-9999 but should not be shorter than Key Rotation time.
1632
											</td>
1633
										</tr>
1634
										<tr>
1635
											<td valign="top" class="vncell">Strict Key Regeneration</td>
1636
											<td class="vtable">
1637
												<input name="wpa_strict_rekey" type="checkbox" value="yes"  class="formfld" id="wpa_strict_rekey" <? if ($pconfig['wpa_strict_rekey']) echo "checked"; ?>>
1638
												<br/>Setting this option will force the AP to rekey whenever a client disassociates.
1639
											</td>
1640
										</tr>
1641
										<tr>
1642
											<td valign="top" class="vncell">Enable IEEE802.1X Authentication</td>
1643
											<td class="vtable">
1644
												<input name="ieee8021x" type="checkbox" value="yes"  class="formfld" id="ieee8021x" <? if ($pconfig['ieee8021x']) echo "checked";?>>
1645
												<br/>Setting this option will enable 802.1x authentication.
1646
											</td>
1647
										</tr>
1648
										<tr>
1649
											<td valign="top" class="vncell">802.1X Authentication Server IP Address</td>
1650
											<td class="vtable">
1651
												<input name="auth_server_addr" id="auth_server_addr" type="text" class="formfld unknown" size="66" value="<?=htmlspecialchars($pconfig['auth_server_addr']);?>">
1652
												<br/>Enter the IP address of the 802.1X Authentication Server.  This is commonly a Radius server (FreeRadius, Internet Authentication Services, etc.)
1653
											</td>
1654
										</tr>
1655
										<tr>
1656
											<td valign="top" class="vncell">802.1X Authentication Server Port</td>
1657
											<td class="vtable">
1658
												<input name="auth_server_port" id="auth_server_port" type="text" class="formfld unknown" size="66" value="<?=htmlspecialchars($pconfig['auth_server_port']);?>">
1659
												<br/>Leave blank for the default 1812 port.
1660
											</td>
1661
										</tr>
1662
										<tr>
1663
											<td valign="top" class="vncell">802.1X Authentication Server Shared Secret</td>
1664
											<td class="vtable">
1665
												<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']);?>">
1666
												<br/>
1667
											</td>
1668
										</tr>
1669
									<? endif; ?>
1670
									<tr>
1671
										<td colspan="2" valign="top" height="16"></td>
1672
									</tr>
1673
									<tr>
1674
										<td colspan="2" valign="top" class="listtopic">Private networks</td>
1675
									</tr>
1676
									<tr>
1677
										<td valign="middle" class="vncell">&nbsp;</td>
1678
										<td class="vtable">
1679
											<a name="rfc1918"></a> 
1680
											<input name="blockpriv" type="checkbox" id="blockpriv" value="yes" <?php if ($pconfig['blockpriv']) echo "checked"; ?>>
1681
											<strong>Block private networks</strong><br>
1682
											When set, this option blocks traffic from IP addresses that are reserved 
1683
											for private  networks as per RFC 1918 (10/8, 172.16/12, 192.168/16) as 
1684
											well as loopback addresses (127/8).&nbsp;&nbsp; You should generally
1685
											leave this option turned on, unless your WAN network lies in such 
1686
											a private address space, too. 
1687
										</td>
1688
									</tr>
1689
									<tr>
1690
										<td valign="middle" class="vncell">&nbsp;</td>
1691
										<td class="vtable"> 
1692
											<input name="blockbogons" type="checkbox" id="blockbogons" value="yes" <?php if ($pconfig['blockbogons']) echo "checked"; ?>>
1693
											<strong>Block bogon networks</strong><br>
1694
											When set, this option blocks traffic from IP addresses that are reserved 
1695
											(but not RFC 1918) or not yet assigned by IANA.&nbsp;&nbsp;
1696
											Bogons are prefixes that should never appear in the Internet routing table, 
1697
											and obviously should not appear as the source address in any packets you receive.
1698
										</td>
1699
									</tr>
1700
								</tr>
1701
				</table>
1702
				</div>
1703
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
1704
								<tr>
1705
									<td width="100" valign="top">
1706
										&nbsp;
1707
									</td>
1708
									<td>
1709
										<br/>
1710
										<input id="save" name="Submit" type="submit" class="formbtn" value="Save"> 
1711
										<input id="cancel" type="button" class="formbtn" value="Cancel" onclick="history.back()">
1712
										<input name="if" type="hidden" id="if" value="<?=$if;?>">
1713
									</td>
1714
								</tr>
1715
							</table>
1716
						</td>
1717
					</table>
1718
					</div>
1719
					</td></tr>
1720
					</table>
1721
				</form>
1722
				<script type="text/javascript">
1723
					var gatewayip;
1724
					var name;
1725
					function show_add_gateway() {
1726
						document.getElementById("addgateway").style.display = '';
1727
						document.getElementById("addgwbox").style.display = 'none';
1728
						document.getElementById("gateway").style.display = 'none';
1729
						document.getElementById("save").style.display = 'none';
1730
						document.getElementById("cancel").style.display = 'none';
1731
						document.getElementById("gwsave").style.display = '';
1732
						document.getElementById("gwcancel").style.display = '';
1733
						$('notebox').innerHTML="";
1734
					}
1735
					function hide_add_gateway() {
1736
						document.getElementById("addgateway").style.display = 'none';
1737
						document.getElementById("addgwbox").style.display = '';	
1738
						document.getElementById("gateway").style.display = '';
1739
						document.getElementById("save").style.display = '';
1740
						document.getElementById("cancel").style.display = '';
1741
						document.getElementById("gwsave").style.display = '';
1742
						document.getElementById("gwcancel").style.display = '';
1743
					}
1744
					function hide_add_gatewaysave() {
1745
						document.getElementById("addgateway").style.display = 'none';
1746
						$('status').innerHTML = '<img src="/themes/metallic/images/misc/loader.gif"> One moment please...';
1747
						var iface = $F('if');
1748
						name = $('name').getValue();
1749
						var descr = $('gatewaydescr').getValue();
1750
						gatewayip = $('gatewayip').getValue();
1751
						addrtype = $('addrtype').getValue();
1752
						var defaultgw = $('defaultgw').getValue();
1753
						var url = "system_gateways_edit.php";
1754
						var pars = 'isAjax=true&defaultgw=' + escape(defaultgw) + '&interface=' + escape(iface) + '&name=' + escape(name) + '&descr=' + escape(descr) + '&gateway=' + escape(gatewayip) + '&type=' + escape(addrtype);
1755
						var myAjax = new Ajax.Request(
1756
							url,
1757
							{
1758
								method: 'post',
1759
								parameters: pars,
1760
								onFailure: report_failure,
1761
								onComplete: save_callback
1762
							});	
1763
					}
1764
					function addOption(selectbox,text,value)
1765
					{
1766
						var optn = document.createElement("OPTION");
1767
						optn.text = text;
1768
						optn.value = value;
1769
						selectbox.options.add(optn);
1770
						selectbox.selectedIndex = (selectbox.options.length-1);
1771
						$('notebox').innerHTML="<p/><strong>NOTE:</strong> You can manage Gateways <a target='_new' href='system_gateways.php'>here</a>.";
1772
					}				
1773
					function report_failure() {
1774
						alert("Sorry, we could not create your gateway at this time.");
1775
						hide_add_gateway();
1776
					}
1777
					function save_callback(transport) {
1778
						var response = transport.responseText;
1779
						if(response) {
1780
							document.getElementById("addgateway").style.display = 'none';
1781
							hide_add_gateway();
1782
							$('status').innerHTML = '';
1783
							addOption($('gateway'), name, name);
1784
							// Auto submit form?
1785
							//document.iform.submit();
1786
							//$('status').innerHTML = '<img src="/themes/metallic/images/misc/loader.gif">';
1787
						} else {
1788
							report_failure();
1789
						}
1790
					}
1791
					<?php
1792
					if ($if == "wan" || $if == "lan")
1793
						echo "\$('allcfg').show();";
1794
					else
1795
						echo "show_allcfg(document.iform.enable);";
1796
					echo "updateType('{$pconfig['type']}')";
1797
					?>
1798
				</script>
1799
				<?php include("fend.inc"); ?>
1800
		</body>
1801
</html>
(80-80/218)