Project

General

Profile

Download (77.5 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", "{$g['varetc_path']}/pppoe_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($ptpid_) {
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.$ptpid_) !== false) {
74
				return array("ID" => $i, "ITEM" => $item);
75
			}
76
		}
77
	}
78
	return NULL;
79
}
80

    
81
if (!is_array($config['ppps']['ppp']))
82
	$config['ppps']['ppp'] = array();
83

    
84
$a_ppps = &$config['ppps']['ppp'];
85

    
86
function remove_bad_chars($string) {
87
	return preg_replace('/[^a-z|_|0-9]/i','',$string);
88
}
89

    
90
if (!is_array($config['gateways']['gateway_item']))
91
	$config['gateways']['gateway_item'] = array();
92

    
93
$a_gateways = &$config['gateways']['gateway_item'];
94

    
95
$wancfg = &$config['interfaces'][$if];
96

    
97
if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
98
	foreach ($a_ppps as $pppid => $ppp) {
99
		if ($wancfg['ptpid'] == $ppp['ptpid'])
100
			break;
101
	}
102
}
103

    
104
if ($wancfg['ptpid'] == $a_ppps[$pppid]['ptpid']) {
105
	$pconfig['pppid'] = $pppid;
106
	if ($a_ppps[$pppid]['type'] == "pppoe"){
107
		$pconfig['pppoe_username'] = $a_ppps[$pppid]['username'];
108
		$pconfig['pppoe_password'] = base64_decode($a_ppps[$pppid]['password']);
109
		$pconfig['provider'] = $a_ppps[$pppid]['provider'];
110
		$pconfig['pppoe_dialondemand'] = isset($a_ppps[$pppid]['ondemand']);
111
		$pconfig['pppoe_idletimeout'] = $a_ppps[$pppid]['idletimeout'];
112

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

    
170
// Populate page descr if it does not exist.
171
if($if == "wan" && !$wancfg['descr']) {
172
	$wancfg['descr'] = "WAN";
173
} else if ($if == "lan" && !$wancfg['descr']) {
174
	$wancfg['descr'] = "LAN";
175
}
176
$pconfig['descr'] = remove_bad_chars($wancfg['descr']);
177

    
178
$pconfig['enable'] = isset($wancfg['enable']);
179

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

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

    
213
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
214
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
215
$pconfig['spoofmac'] = $wancfg['spoofmac'];
216
$pconfig['mtu'] = $wancfg['mtu'];
217

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

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

    
304
		/* sync filter configuration */
305
		setup_gateways_monitor();
306

    
307
		clear_subsystem_dirty('staticroutes');
308
		
309
		filter_configure();
310
		
311
		enable_rrd_graphing();
312
	}
313
	header("Location: interfaces.php?if={$if}");
314
	exit;
315
} else
316

    
317
if ($_POST && $_POST['enable'] != "yes") {
318
	unset($wancfg['enable']);
319
	if (isset($wancfg['wireless'])) {
320
		interface_sync_wireless_clones($wancfg, false);
321
	}
322
	write_config("Interface {$_POST['descr']}({$if}) is now disabled.");
323
	mark_subsystem_dirty('interfaces');
324
	header("Location: interfaces.php?if={$if}");
325
	exit;
326
} else
327

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

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

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

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

    
499
		$wancfg['descr'] = remove_bad_chars($_POST['descr']);
500
		$wancfg['enable'] =  $_POST['enable']  == "yes" ? true : false;
501

    
502
		/* for dynamic interfaces we tack a gateway item onto the array to prevent system
503
		 * log messages from appearing. They can also manually add these items */
504
		/* 1st added gateway gets a default bit */
505
		if(!empty($a_gateways)) {
506
			$gateway_item = array();
507
			/* check for duplicates */
508
			$skip = false;
509
			foreach($a_gateways as $item) {
510
				if(($item['interface'] == "$if") && ($item['gateway'] == "dynamic")) {
511
					$skip = true;
512
				}
513
			}
514
			if($skip == false) {
515
				$gateway_item['gateway'] = "dynamic";
516
				$gateway_item['descr'] = "Interface {$if} dynamic gateway";
517
				$gateway_item['name'] = "GW_" . strtoupper($if);
518
				$gateway_item['interface'] = "{$if}";
519
			} else {
520
				unset($gateway_item);
521
			}
522
		}
523
		
524
		// Here the else condition code assumes only that strings of form "opt#" will be passed.
525
		if ($if == "wan")
526
			$if_num = "0";
527
		else 
528
			$if_num = substr($if, 3);
529
			
530
		switch($_POST['type']) {
531
			case "static":
532
				$wancfg['ipaddr'] = $_POST['ipaddr'];
533
				$wancfg['subnet'] = $_POST['subnet'];
534
				if ($_POST['gateway'] != "none") {
535
					$wancfg['gateway'] = $_POST['gateway'];
536
				}
537
				break;
538
			case "dhcp":
539
				$wancfg['ipaddr'] = "dhcp";
540
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
541
				$wancfg['alias-address'] = $_POST['alias-address'];
542
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
543
				if($gateway_item) {
544
					$a_gateways[] = $gateway_item;
545
				}
546
				break;
547
			case "carpdev-dhcp":
548
				$wancfg['ipaddr'] = "carpdev-dhcp";
549
				$wancfg['dhcphostname'] = $_POST['dhcphostname'];
550
				$wancfg['alias-address'] = $_POST['alias-address'];
551
				$wancfg['alias-subnet'] = $_POST['alias-subnet'];
552
				if($gateway_item) {
553
					$a_gateways[] = $gateway_item;
554
				}
555
				break;
556
			case "pppoe":
557
				$ppp['ptpid'] = $_POST['ptpid'];
558
				$ppp['type'] = $_POST['type'];
559
				if (isset($_POST['ppp_port']))
560
					$ppp['ports'] = $_POST['ppp_port'];
561
				else
562
					$ppp['ports'] = $wancfg['if'];
563
				$ppp['username'] = $_POST['pppoe_username'];
564
				$ppp['password'] = base64_encode($_POST['pppoe_password']);
565
				if (!empty($_POST['provider']))
566
					$ppp['provider'] = $_POST['provider'];
567
				else
568
					unset($ppp['provider']);
569
				$ppp['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
570
				if (!empty($_POST['idletimeout']))
571
					$ppp['idletimeout'] = $_POST['pppoe_idletimeout'];
572
				else
573
					unset($ppp['idletimeout']);
574

    
575
				if (!empty($_POST['pppoe-reset-type']))
576
					$ppp['pppoe-reset-type'] = $_POST['pppoe-reset-type'];
577
				else
578
					unset($ppp['pppoe-reset-type']);
579
				$wancfg['if'] = $_POST['type'] . $if_num;
580
				$wancfg['ptpid'] = $_POST['ptpid'];
581
				$wancfg['ipaddr'] = $_POST['type'];
582
				if($gateway_item) {
583
					$a_gateways[] = $gateway_item;
584
				}
585
				
586
				break;
587
			case "pptp":
588
				$ppp['ptpid'] = $_POST['ptpid'];
589
				$ppp['type'] = $_POST['type'];
590
				if (isset($_POST['ppp_port']))
591
					$ppp['ports'] = $_POST['ppp_port'];
592
				else
593
					$ppp['ports'] = $wancfg['if'];
594
				$ppp['username'] = $_POST['pptp_username'];
595
				$ppp['password'] = base64_encode($_POST['pptp_password']);
596
				$ppp['localip'] = $_POST['pptp_local'];
597
				$ppp['subnet'] = $_POST['pptp_subnet'];
598
				$ppp['gateway'] = $_POST['pptp_remote'];
599
				$ppp['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
600
				if (!empty($_POST['idletimeout']))
601
					$ppp['idletimeout'] = $_POST['pptp_idletimeout'];
602
				else
603
					unset($ppp['idletimeout']);
604
				
605
				$wancfg['if'] = $_POST['type'] . $if_num;
606
				$wancfg['ptpid'] = $_POST['ptpid'];
607
				$wancfg['ipaddr'] = $_POST['type'];
608
				if($gateway_item) {
609
					$a_gateways[] = $gateway_item;
610
				}
611
				break;
612
		}
613
		handle_pppoe_reset();
614
		/* reset cron items if necessary */
615
		if (empty($_POST['pppoe-reset-type'])) {
616
			/* test whether a cron item exists and unset() it if necessary */
617
			$itemhash = getMPDCRONSettings($_POST['ptpid']);
618
			$item = $itemhash['ITEM'];
619
			if (isset($item))
620
				unset($config['cron']['item'][$itemhash['ID']]); 
621
		}
622
		if($_POST['blockpriv'] == "yes") {
623
			$wancfg['blockpriv'] = true;
624
		} else {
625
			unset($wancfg['blockpriv']);
626
		}
627
		if($_POST['blockbogons'] == "yes") {
628
			$wancfg['blockbogons'] = true;
629
		} else {
630
			unset($wancfg['blockbogons']);
631
		}
632
		$wancfg['spoofmac'] = $_POST['spoofmac'];
633
		if (empty($_POST['mtu'])) {
634
			unset($wancfg['mtu']);
635
		} else {
636
			$wancfg['mtu'] = $_POST['mtu'];
637
		}
638
		if (isset($wancfg['wireless'])) {
639
			handle_wireless_post();
640
		}
641
		
642
		if (isset($_POST['pppid']) && $a_ppps[$pppid])
643
			$a_ppps[$pppid] = $ppp;
644
		else
645
			$a_ppps[] = $ppp;
646
		
647
		write_config();
648
		mark_subsystem_dirty('interfaces');
649
		/* regenerate cron settings/crontab file */
650
		configure_cron();
651
		conf_mount_ro();
652
		header("Location: interfaces.php?if={$if}");
653
		exit;
654
	}
655
	
656
	
657
	
658
} // end if($_POST) 
659

    
660
function handle_pppoe_reset() {
661
	global $_POST, $config, $g, $wancfg, $if;
662
	/* perform a periodic reset? */
663
	if(!isset($_POST['pppoe-reset-type'])) {
664
		setup_pppoe_reset_file($_POST['ptpid']);		
665
		return;
666
	}
667
	if (!is_array($config['cron']['item'])) 
668
		$config['cron']['item'] = array(); 
669
	$itemhash = getMPDCRONSettings($_POST['ptpid'], $_POST['if']);
670
	$item = $itemhash['ITEM'];
671
	if (empty($item)) 
672
		$item = array();
673
	if (isset($_POST['pppoe-reset-type']) && $_POST['pppoe-reset-type'] == "custom") {
674
		$item['minute'] = $_POST['pppoe_resetminute'];
675
		$item['hour'] = $_POST['pppoe_resethour'];
676
		if (isset($_POST['pppoe_resetdate']) && $_POST['pppoe_resetdate'] <> "" && strlen($_POST['pppoe_resetdate']) == 10) {
677
			$date = explode("/", $_POST['pppoe_resetdate']);
678
			$item['mday'] = $date[1];
679
			$item['month'] = $date[0];
680
		} else {
681
			$item['mday'] = "*";
682
			$item['month'] = "*";
683
		}
684
		$item['wday'] = "*";
685
		$item['who'] = "root";
686
		$item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid'];
687
	} else if (isset($_POST['pppoe-reset-type']) && $_POST['pppoe-reset-type'] == "preset") {
688
		switch ($_POST['pppoe_pr_preset_val']) {
689
			case "monthly":
690
				$item['minute'] = "0";
691
				$item['hour'] = "0";
692
				$item['mday'] = "1";
693
				$item['month'] = "*";
694
				$item['wday'] = "*";
695
				$item['who'] = "root";
696
				$item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid'];
697
				break;
698
	        case "weekly":
699
				$item['minute'] = "0";
700
				$item['hour'] = "0";
701
				$item['mday'] = "*";
702
				$item['month'] = "*";
703
				$item['wday'] = "0";
704
				$item['who'] = "root";
705
				$item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid'];
706
				break;
707
			case "daily":
708
				$item['minute'] = "0";
709
				$item['hour'] = "0";
710
				$item['mday'] = "*";
711
				$item['month'] = "*";
712
				$item['wday'] = "*";
713
				$item['who'] = "root";
714
				$item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid'];
715
				break;
716
			case "hourly":
717
				$item['minute'] = "0";
718
				$item['hour'] = "*";
719
				$item['mday'] = "*";
720
				$item['month'] = "*";
721
				$item['wday'] = "*";
722
				$item['who'] = "root";
723
				$item['command'] = CRON_PPPOE_CMD_FILE.$_POST['ptpid'];
724
			break;
725
		} // end switch
726
	} // end if
727
	if (isset($itemhash['ID'])) 
728
		$config['cron']['item'][$itemhash['ID']] = $item;
729
	else 
730
		$config['cron']['item'][] = $item;
731

    
732
}
733

    
734
function handle_wireless_post() {
735
	global $_POST, $config, $g, $wancfg, $if, $wl_countries_attr;
736
	if (!is_array($wancfg['wireless']))
737
		$wancfg['wireless'] = array();
738
	$wancfg['wireless']['standard'] = $_POST['standard'];
739
	$wancfg['wireless']['mode'] = $_POST['mode'];
740
	$wancfg['wireless']['protmode'] = $_POST['protmode'];
741
	$wancfg['wireless']['ssid'] = $_POST['ssid'];
742
	$wancfg['wireless']['channel'] = $_POST['channel'];
743
	$wancfg['wireless']['authmode'] = $_POST['authmode'];
744
	$wancfg['wireless']['txpower'] = $_POST['txpower'];
745
	$wancfg['wireless']['distance'] = $_POST['distance'];
746
	$wancfg['wireless']['regdomain'] = $_POST['regdomain'];
747
	$wancfg['wireless']['regcountry'] = $_POST['regcountry'];
748
	$wancfg['wireless']['reglocation'] = $_POST['reglocation'];
749
	if (!empty($wancfg['wireless']['regdomain']) && !empty($wancfg['wireless']['regcountry'])) {
750
		foreach($wl_countries_attr as $wl_country) {
751
			if ($wancfg['wireless']['regcountry'] == $wl_country['ID']) {
752
				$wancfg['wireless']['regdomain'] = $wl_country['rd'][0]['REF'];
753
				break;
754
			}
755
		}
756
	}
757
	if (!is_array($wancfg['wireless']['wpa']))
758
		$wancfg['wireless']['wpa'] = array();
759
	$wancfg['wireless']['wpa']['macaddr_acl'] = $_POST['macaddr_acl'];
760
	$wancfg['wireless']['wpa']['auth_algs'] = $_POST['auth_algs'];
761
	$wancfg['wireless']['wpa']['wpa_mode'] = $_POST['wpa_mode'];
762
	$wancfg['wireless']['wpa']['wpa_key_mgmt'] = $_POST['wpa_key_mgmt'];
763
	$wancfg['wireless']['wpa']['wpa_pairwise'] = $_POST['wpa_pairwise'];
764
	$wancfg['wireless']['wpa']['wpa_group_rekey'] = $_POST['wpa_group_rekey'];
765
	$wancfg['wireless']['wpa']['wpa_gmk_rekey'] = $_POST['wpa_gmk_rekey'];
766
	$wancfg['wireless']['wpa']['passphrase'] = $_POST['passphrase'];
767
	$wancfg['wireless']['wpa']['ext_wpa_sw'] = $_POST['ext_wpa_sw'];
768
	$wancfg['wireless']['auth_server_addr'] = $_POST['auth_server_addr'];
769
	$wancfg['wireless']['auth_server_port'] = $_POST['auth_server_port'];
770
	$wancfg['wireless']['auth_server_shared_secret'] = $_POST['auth_server_shared_secret'];
771
	if ($_POST['hidessid_enable'] == "yes")
772
		$wancfg['wireless']['hidessid']['enable'] = true;
773
	else if (isset($wancfg['wireless']['hidessid']['enable']))
774
		unset($wancfg['wireless']['hidessid']['enable']);
775
	if ($_POST['mac_acl_enable'] == "yes")
776
		$wancfg['wireless']['wpa']['mac_acl_enable'] = true;
777
	else if (isset($wancfg['wireless']['wpa']['mac_acl_enable']))
778
		unset($wancfg['wireless']['wpa']['mac_acl_enable']);
779
	if ($_POST['ieee8021x'] == "yes")
780
		$wancfg['wireless']['wpa']['ieee8021x']['enable'] = true;
781
	else if (isset($wancfg['wireless']['wpa']['ieee8021x']['enable']))
782
		unset($wancfg['wireless']['wpa']['ieee8021x']['enable']);
783
	if ($_POST['wpa_strict_rekey'] == "yes")
784
		$wancfg['wireless']['wpa']['wpa_strict_rekey'] = true;
785
	else if (isset($wancfg['wireless']['wpa']['wpa_strict_rekey']))
786
		unset($wancfg['wireless']['wpa']['wpa_strict_rekey']);
787
	if ($_POST['debug_mode'] == "yes")
788
		$wancfg['wireless']['wpa']['debug_mode'] = true;
789
	else if (isset($wancfg['wireless']['wpa']['debug_mode']))
790
		sunset($wancfg['wireless']['wpa']['debug_mode']);
791
	if ($_POST['wpa_enable'] == "yes")
792
		$wancfg['wireless']['wpa']['enable'] = $_POST['wpa_enable'] = true;
793
	else if (isset($wancfg['wireless']['wpa']['enable']))
794
		unset($wancfg['wireless']['wpa']['enable']);
795
	if ($_POST['wep_enable'] == "yes") {
796
		if (!is_array($wancfg['wireless']['wep']))
797
			$wancfg['wireless']['wep'] = array();
798
		$wancfg['wireless']['wep']['enable'] = $_POST['wep_enable'] = true;
799
	} else if (isset($wancfg['wireless']['wep']))
800
		unset($wancfg['wireless']['wep']);
801
	if ($_POST['wme_enable'] == "yes") {
802
		if (!is_array($wancfg['wireless']['wme']))
803
			$wancfg['wireless']['wme'] = array();
804
		$wancfg['wireless']['wme']['enable'] = $_POST['wme_enable'] = true;
805
	} else if (isset($wancfg['wireless']['wme']['enable']))
806
		unset($wancfg['wireless']['wme']['enable']);
807
	if ($_POST['puremode'] == "11g") {
808
		if (!is_array($wancfg['wireless']['pureg']))
809
			$wancfg['wireless']['pureg'] = array();
810
		$wancfg['wireless']['pureg']['enable'] = true;
811
	} else if ($_POST['puremode'] == "11n") {
812
		if (!is_array($wancfg['wireless']['puren']))
813
			$wancfg['wireless']['puren'] = array();
814
		$wancfg['wireless']['puren']['enable'] = true;
815
	} else {
816
		if (isset($wancfg['wireless']['pureg']))
817
			unset($wancfg['wireless']['pureg']);
818
		if (isset($wancfg['wireless']['puren']))
819
			unset($wancfg['wireless']['puren']);
820
	}
821
	if ($_POST['apbridge_enable'] == "yes") {
822
		if (!is_array($wancfg['wireless']['apbridge']))
823
			$wancfg['wireless']['apbridge'] = array();
824
		$wancfg['wireless']['apbridge']['enable'] = $_POST['apbridge_enable'] = true;
825
	} else if (isset($wancfg['wireless']['apbridge']['enable']))
826
		unset($wancfg['wireless']['apbridge']['enable']);
827
	if ($_POST['standard'] == "11g Turbo" || $_POST['standard'] == "11a Turbo") {
828
		if (!is_array($wancfg['wireless']['turbo']))
829
			$wancfg['wireless']['turbo'] = array();
830
		$wancfg['wireless']['turbo']['enable'] = true;
831
	} else if (isset($wancfg['wireless']['turbo']['enable']))
832
		unset($wancfg['wireless']['turbo']['enable']);
833
	$wancfg['wireless']['wep']['key'] = array();
834
	for ($i = 1; $i <= 4; $i++) {
835
		if ($_POST['key' . $i]) {
836
			$newkey = array();
837
			$newkey['value'] = $_POST['key' . $i];
838
			if ($_POST['txkey'] == $i)
839
				$newkey['txkey'] = true;
840
			$wancfg['wireless']['wep']['key'][] = $newkey;
841
		}
842
	}
843
	interface_sync_wireless_clones($wancfg, true);
844
}
845

    
846
function check_wireless_mode() {
847
	global $_POST, $config, $g, $wlan_modes, $wancfg, $if, $wlanif, $wlanbaseif, $old_wireless_mode, $input_errors;
848

    
849
	if ($wancfg['wireless']['mode'] == $_POST['mode'])
850
		return;
851

    
852
	if (does_interface_exist(interface_get_wireless_clone($wlanbaseif)))
853
		$clone_count = 1;
854
	else
855
		$clone_count = 0;
856
	if (is_array($config['wireless']['clone'])) {
857
		foreach ($config['wireless']['clone'] as $clone) {
858
			if ($clone['if'] == $wlanbaseif)
859
				$clone_count++;
860
		}
861
	}
862
	if ($clone_count > 1) {
863
		$old_wireless_mode = $wancfg['wireless']['mode'];
864
		$wancfg['wireless']['mode'] = $_POST['mode'];
865
		if (!interface_wireless_clone("{$wlanif}_", $wancfg)) {
866
			$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.";
867
		} else {
868
			mwexec("/sbin/ifconfig {$wlanif}_ destroy");
869
		}
870
		$wancfg['wireless']['mode'] = $old_wireless_mode;
871
	}
872
}
873

    
874
$pgtitle = array("Interfaces", $pconfig['descr']);
875
$closehead = false;
876
include("head.inc");
877
$types = array("none" => "None", "static" => "Static", "dhcp" => "DHCP", "pppoe" => "PPPoE", "pptp" => "PPTP" /* , "carpdev-dhcp" => "CarpDev"*/); 
878

    
879
?>
880

    
881
<script type="text/javascript" src="/javascript/numericupdown/js/numericupdown.js"></script>
882
<link href="/javascript/numericupdown/css/numericupdown.css" rel="stylesheet" type="text/css" />
883
<script type="text/javascript" src="/javascript/datepicker/js/datepicker.js"></script>
884
<link href="/javascript/datepicker/css/datepicker.css" rel="stylesheet" type="text/css"/>
885

    
886
<script type="text/javascript">
887
	function updateType(t) {
888
		switch(t) {
889
			case "none": {
890
				$('static','dhcp','pppoe','pptp').invoke('hide');
891
				break;
892
			}
893
			case "static": {
894
				$('none','dhcp','pppoe','pptp').invoke('hide');
895
				break;
896
			}
897
			case "dhcp": {
898
				$('none','static','pppoe','pptp').invoke('hide');
899
				break;
900
			}
901
			case "pppoe": {
902
				$('none','static','dhcp','pptp').invoke('hide');
903
				break;
904
			}
905
			case "pptp": {
906
				$('none','static','dhcp','pppoe').invoke('hide');
907
				break;
908
			}
909
		}
910
		$(t).show();
911
	}
912

    
913
	function show_allcfg(obj) {
914
		if (obj.checked)
915
			$('allcfg').show();
916
		else
917
			$('allcfg').hide();
918
	}
919

    
920
	function show_reset_settings(reset_type) {
921
		if (reset_type == 'preset') { 
922
			Effect.Appear('pppoepresetwrap', { duration: 0.0 });
923
			Effect.Fade('pppoecustomwrap', { duration: 0.0 }); 
924
		} 
925
		else if (reset_type == 'custom') { 
926
			Effect.Appear('pppoecustomwrap', { duration: 0.0 });
927
			Effect.Fade('pppoepresetwrap', { duration: 0.0 });
928
		} else {
929
			Effect.Fade('pppoecustomwrap', { duration: 0.0 });
930
			Effect.Fade('pppoepresetwrap', { duration: 0.0 });
931
		}
932
	}
933
	function show_mon_config() {
934
		document.getElementById("showmonbox").innerHTML='';
935
		aodiv = document.getElementById('showmon');
936
		aodiv.style.display = "block";
937
	}
938

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