Project

General

Profile

Download (40.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces_wan.php
5
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7

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

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

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

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

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

    
34
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
35
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
36
define("CRON_DAILY_PATTERN", "0 0 * * *");
37
define("CRON_HOURLY_PATTERN", "0 * * * *");
38
define("CRON_PPPOE_CMD_FILE", "/etc/pppoerestart");
39
define("CRON_PPPOE_CMD", "#!/bin/sh\necho '<?php require(\"interfaces.inc\"); interfaces_wan_pppoe_restart(); services_dyndns_reset(); ?>' | /usr/local/bin/php -q");
40

    
41
function getMPDCRONSettings() {
42
  global $config;
43

    
44
  if (is_array($config['cron']['item'])) {
45
    for ($i = 0; $i < count($config['cron']['item']); $i++) {
46
      $item =& $config['cron']['item'][$i];
47

    
48
      if (strpos($item['command'], CRON_PPPOE_CMD_FILE) !== false) {
49
        return array("ID" => $i, "ITEM" => $item);
50
      }
51
    }
52
  }
53

    
54
  return NULL;
55
}
56

    
57
function getMPDResetTimeFromConfig() {
58
  $itemhash = getMPDCRONSettings();
59
  $cronitem = $itemhash['ITEM'];
60

    
61
  if (isset($cronitem)) {
62

    
63
    return "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}";
64
  } else {
65
    return NULL;
66
  }
67
}
68

    
69
require("guiconfig.inc");
70

    
71
$wancfg = &$config['interfaces']['wan'];
72
$optcfg = &$config['interfaces']['wan'];
73

    
74
$pconfig['username'] = $config['pppoe']['username'];
75
$pconfig['password'] = $config['pppoe']['password'];
76
$pconfig['provider'] = $config['pppoe']['provider'];
77
$pconfig['pppoe_dialondemand'] = isset($config['pppoe']['ondemand']);
78
$pconfig['pppoe_idletimeout'] = $config['pppoe']['timeout'];
79

    
80
/* ================================================ */
81
/* = force a connection reset at a specific time? = */
82
/* ================================================ */
83

    
84
if (isset($wancfg['pppoe']['pppoe-reset-type'])) {
85
  $resetTime = getMPDResetTimeFromConfig();  
86
  $pconfig['pppoe_preset'] = true;
87
  
88
  if ($wancfg['pppoe']['pppoe-reset-type'] == "custom") {
89
    $resetTime_a = split(" ", $resetTime);
90
    $pconfig['pppoe_pr_custom'] = true;
91
    $pconfig['pppoe_resetminute'] = $resetTime_a[0];
92
    $pconfig['pppoe_resethour'] = $resetTime_a[1];
93

    
94
    /* just initialize $pconfig['pppoe_resetdate'] if the
95
     * coresponding item contains appropriate numeric values.
96
     */
97
    if ($resetTime_a[2] <> "*" && $resetTime_a[3] <> "*") {
98
      $pconfig['pppoe_resetdate'] = "{$resetTime_a[3]}/{$resetTime_a[2]}/" . date("Y");
99
    }
100
  } else if ($wancfg['pppoe']['pppoe-reset-type'] == "preset") {
101
    $pconfig['pppoe_pr_preset'] = true;
102
    
103
    switch ($resetTime) {
104
      case CRON_MONTHLY_PATTERN:
105
        $pconfig['pppoe_monthly'] = true;
106
        break;
107
      case CRON_WEEKLY_PATTERN:
108
        $pconfig['pppoe_weekly'] = true;
109
        break;
110
      case CRON_DAILY_PATTERN:
111
        $pconfig['pppoe_daily'] = true;
112
        break;
113
      case CRON_HOURLY_PATTERN:
114
        $pconfig['pppoe_hourly'] = true;
115
        break;
116
    }
117
  }
118
}
119

    
120
$pconfig['pptp_username'] = $config['pptp']['username'];
121
$pconfig['pptp_password'] = $config['pptp']['password'];
122
$pconfig['pptp_local'] = $config['pptp']['local'];
123
$pconfig['pptp_subnet'] = $config['pptp']['subnet'];
124
$pconfig['pptp_remote'] = $config['pptp']['remote'];
125
$pconfig['pptp_dialondemand'] = isset($config['pptp']['ondemand']);
126
$pconfig['pptp_idletimeout'] = $config['pptp']['timeout'];
127

    
128
$pconfig['disableftpproxy'] = isset($wancfg['disableftpproxy']);
129

    
130
$pconfig['dhcphostname'] = $wancfg['dhcphostname'];
131

    
132
if ($wancfg['ipaddr'] == "dhcp") {
133
	$pconfig['type'] = "DHCP";
134
} else if ($wancfg['ipaddr'] == "pppoe") {
135
	$pconfig['type'] = "PPPoE";
136
} else if ($wancfg['ipaddr'] == "pptp") {
137
	$pconfig['type'] = "PPTP";
138
} else {
139
	$pconfig['type'] = "Static";
140
	$pconfig['ipaddr'] = $wancfg['ipaddr'];
141
	$pconfig['subnet'] = $wancfg['subnet'];
142
	$pconfig['gateway'] = $config['interfaces']['wan']['gateway'];
143
	$pconfig['pointtopoint'] = $wancfg['pointtopoint'];
144
}
145

    
146
$pconfig['blockpriv'] = isset($wancfg['blockpriv']);
147
$pconfig['blockbogons'] = isset($wancfg['blockbogons']);
148
$pconfig['spoofmac'] = $wancfg['spoofmac'];
149
$pconfig['mtu'] = $wancfg['mtu'];
150

    
151
/* Wireless interface? */
152
if (isset($wancfg['wireless'])) {
153
	require("interfaces_wlan.inc");
154
	wireless_config_init();
155
}
156

    
157
if ($_POST) {
158

    
159
	unset($input_errors);
160
	$pconfig = $_POST;
161
  
162
  /* okay first of all, cause we are just hidding the PPPoE HTML
163
   * fields releated to PPPoE resets, we are going to unset $_POST
164
   * vars, if the reset feature should not be used. Otherwise the
165
   * data validation procedure below, may trigger a false error
166
   * message.
167
   */
168
  if (empty($_POST['pppoe_preset'])) {
169
    unset($_POST['pppoe_pr_type']);
170
    unset($_POST['pppoe_resethour']);
171
    unset($_POST['pppoe_resetminute']);
172
    unset($_POST['pppoe_resetdate']);
173
    unset($_POST['pppoe_pr_preset_val']);
174
    unlink_if_exists(CRON_PPPOE_CMD_FILE);
175
  }
176

    
177
	if($_POST['gateway'] and $pconfig['gateway'] <> $_POST['gateway']) {
178
		/* enumerate slbd gateways and make sure we are not creating a route loop */
179
		if(is_array($config['load_balancer']['lbpool'])) {
180
			foreach($config['load_balancer']['lbpool'] as $lbpool) {
181
				if($lbpool['type'] == "gateway") {
182
				    foreach ((array) $lbpool['servers'] as $server) {
183
			            $svr = split("\|", $server);
184
			            if($svr[1] == $pconfig['gateway'])  {
185
			            		$_POST['gateway']  = $pconfig['gateway'];
186
			            		$input_errors[] = "Cannot change {$svr[1]} gateway.  It is currently referenced by the load balancer pools.";
187
			            }
188
					}
189
				}
190
			}
191
			foreach($config['filter']['rule'] as $rule) {
192
				if($rule['gateway'] == $pconfig['gateway']) {
193
	            		$_POST['gateway']  = $pconfig['gateway'];
194
	            		$input_errors[] = "Cannot change {$svr[1]} gateway.  It is currently referenced by the filter rules via policy based routing.";
195
				}
196
			}
197
		}
198
	}
199

    
200
	/* input validation */
201
	if ($_POST['type'] == "Static") {
202
		$reqdfields = explode(" ", "ipaddr subnet gateway");
203
		$reqdfieldsn = explode(",", "IP address,Subnet bit count,Gateway");
204
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
205
	} else if ($_POST['type'] == "PPPoE") {
206
		if ($_POST['pppoe_dialondemand']) {
207
			$reqdfields = explode(" ", "username password pppoe_dialondemand pppoe_idletimeout");
208
			$reqdfieldsn = explode(",", "PPPoE username,PPPoE password,Dial on demand,Idle timeout value");
209
		} else {
210
			$reqdfields = explode(" ", "username password");
211
			$reqdfieldsn = explode(",", "PPPoE username,PPPoE password");
212
		}
213
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
214
	} else if ($_POST['type'] == "PPTP") {
215
		if ($_POST['pptp_dialondemand']) {
216
			$reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote pptp_dialondemand pptp_idletimeout");
217
			$reqdfieldsn = explode(",", "PPTP username,PPTP password,PPTP local IP address,PPTP subnet,PPTP remote IP address,Dial on demand,Idle timeout value");
218
		} else {
219
			$reqdfields = explode(" ", "pptp_username pptp_password pptp_local pptp_subnet pptp_remote");
220
			$reqdfieldsn = explode(",", "PPTP username,PPTP password,PPTP local IP address,PPTP subnet,PPTP remote IP address");
221
		}
222
		do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
223
	} 
224

    
225
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
226
	$_POST['spoofmac'] = strtolower(str_replace("-", ":", $_POST['spoofmac']));
227

    
228
	if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
229
		$input_errors[] = "A valid IP address must be specified.";
230
	}
231
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) {
232
		$input_errors[] = "A valid subnet bit count must be specified.";
233
	}
234
	if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
235
		$input_errors[] = "A valid gateway must be specified.";
236
	}
237
	if (($_POST['pointtopoint'] && !is_ipaddr($_POST['pointtopoint']))) {
238
		$input_errors[] = "A valid point-to-point IP address must be specified.";
239
	}
240
	if (($_POST['provider'] && !is_domain($_POST['provider']))) {
241
		$input_errors[] = "The service name contains invalid characters.";
242
	}
243
	if (($_POST['pppoe_idletimeout'] != "") && !is_numericint($_POST['pppoe_idletimeout'])) {
244
		$input_errors[] = "The idle timeout value must be an integer.";
245
	}
246
  if ($_POST['pppoe_resethour'] <> "" && 
247
      !is_numericint($_POST['pppoe_resethour']) && 
248
    $_POST['pppoe_resethour'] >= 0 && 
249
    $_POST['pppoe_resethour'] <=23) {
250
    $input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
251
  }
252
  if ($_POST['pppoe_resetminute'] <> "" && 
253
      !is_numericint($_POST['pppoe_resetminute']) && 
254
    $_POST['pppoe_resetminute'] >= 0 && 
255
    $_POST['pppoe_resetminute'] <=59) {
256
    $input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
257
  }
258
  if ($_POST['pppoe_resetdate'] <> "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) {
259
    $input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
260
  }
261
	if (($_POST['pptp_local'] && !is_ipaddr($_POST['pptp_local']))) {
262
		$input_errors[] = "A valid PPTP local IP address must be specified.";
263
	}
264
	if (($_POST['pptp_subnet'] && !is_numeric($_POST['pptp_subnet']))) {
265
		$input_errors[] = "A valid PPTP subnet bit count must be specified.";
266
	}
267
	if (($_POST['pptp_remote'] && !is_ipaddr($_POST['pptp_remote']))) {
268
		$input_errors[] = "A valid PPTP remote IP address must be specified.";
269
	}
270
	if (($_POST['pptp_idletimeout'] != "") && !is_numericint($_POST['pptp_idletimeout'])) {
271
		$input_errors[] = "The idle timeout value must be an integer.";
272
	}
273
	if (($_POST['spoofmac'] && !is_macaddr($_POST['spoofmac']))) {
274
		$input_errors[] = "A valid MAC address must be specified.";
275
	}
276
	if ($_POST['mtu'] && (($_POST['mtu'] < 576) || ($_POST['mtu'] > 1500))) {
277
		$input_errors[] = "The MTU must be between 576 and 1500 bytes.";
278
	}
279

    
280
	/* Wireless interface? */
281
	if (isset($wancfg['wireless'])) {
282
		$wi_input_errors = wireless_config_post();
283
		if ($wi_input_errors) {
284
			$input_errors = array_merge($input_errors, $wi_input_errors);
285
		}
286
	}
287

    
288
	if (!$input_errors) {
289

    
290
		$bridge = discover_bridge($wancfg['if'], filter_translate_type_to_real_interface($wancfg['bridge']));
291
		if($bridge <> "-1") {
292
			destroy_bridge($bridge);
293
		}
294

    
295
		unset($wancfg['ipaddr']);
296
		unset($wancfg['subnet']);
297
		unset($config['interfaces']['wan']['gateway']);
298
		unset($wancfg['pointtopoint']);
299
		unset($wancfg['dhcphostname']);
300
    if (is_array($wancfg['pppoe'])) {
301
      unset($config['pppoe']['username']);
302
      unset($config['pppoe']['password']);
303
      unset($config['pppoe']['provider']);
304
      unset($config['pppoe']['ondemand']);
305
      unset($config['pppoe']['timeout']);
306
      unset($wancfg['pppoe']['pppoe-reset-type']);
307
    }
308
    if (is_array($wancfg['pptp'])) {
309
      unset($config['pptp']['username']);
310
      unset($config['pptp']['password']);
311
      unset($config['pptp']['local']);
312
      unset($config['pptp']['subnet']);
313
      unset($config['pptp']['remote']);
314
      unset($config['pptp']['ondemand']);
315
      unset($config['pptp']['timeout']);
316
    }
317
	
318
	unset($wancfg['disableftpproxy']);
319

    
320
		/* per interface pftpx helper */
321
		if($_POST['disableftpproxy'] == "yes") {
322
			$wancfg['disableftpproxy'] = true;
323
			system_start_ftp_helpers();
324
		} else {
325
			system_start_ftp_helpers();
326
		}
327

    
328
		if ($_POST['type'] == "Static") {
329
			$wancfg['ipaddr'] = $_POST['ipaddr'];
330
			$wancfg['subnet'] = $_POST['subnet'];
331
			$config['interfaces']['wan']['gateway'] = $_POST['gateway'];
332
			if (isset($wancfg['ispointtopoint']))
333
				$wancfg['pointtopoint'] = $_POST['pointtopoint'];
334
		} else if ($_POST['type'] == "DHCP") {
335
			$wancfg['ipaddr'] = "dhcp";
336
			$wancfg['dhcphostname'] = $_POST['dhcphostname'];
337
		} else if ($_POST['type'] == "PPPoE") {
338
			$wancfg['ipaddr'] = "pppoe";
339
			$config['pppoe']['username'] = $_POST['username'];
340
			$config['pppoe']['password'] = $_POST['password'];
341
			$config['pppoe']['provider'] = $_POST['provider'];
342
			$config['pppoe']['ondemand'] = $_POST['pppoe_dialondemand'] ? true : false;
343
			$config['pppoe']['timeout'] = $_POST['pppoe_idletimeout'];
344
      
345
      /* perform a periodic reset? */
346
      if (isset($_POST['pppoe_preset'])) {
347
        if (! is_array($config['cron']['item'])) { $config['cron']['item'] = array(); }
348

    
349
        $itemhash = getMPDCRONSettings();
350
        $item = $itemhash['ITEM'];
351

    
352
        if (empty($item)) {
353
          $item = array();
354
        }
355

    
356
        if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] == "custom") {
357
          $wancfg['pppoe']['pppoe-reset-type'] = "custom";
358
          $pconfig['pppoe_pr_custom'] = true;
359

    
360
          $item['minute'] = $_POST['pppoe_resetminute'];
361
          $item['hour'] = $_POST['pppoe_resethour'];
362

    
363
          if (isset($_POST['pppoe_resetdate']) && 
364
              $_POST['pppoe_resetdate'] <> "" && 
365
              strlen($_POST['pppoe_resetdate']) == 10) {
366
            $date = explode("/", $_POST['pppoe_resetdate']);
367

    
368
            $item['mday'] = $date[1];
369
            $item['month'] = $date[0];
370
          } else {
371
            $item['mday'] = "*";
372
            $item['month'] = "*";
373
          }
374

    
375
          $item['wday'] = "*";
376
          $item['who'] = "root";
377
          $item['command'] = CRON_PPPOE_CMD_FILE;
378
        } else if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] = "preset") {
379
          $wancfg['pppoe']['pppoe-reset-type'] = "preset";
380
          $pconfig['pppoe_pr_preset'] = true;
381

    
382
          switch ($_POST['pppoe_pr_preset_val']) {
383
            case "monthly":
384
              $item['minute'] = "0";
385
              $item['hour'] = "0";
386
              $item['mday'] = "1";
387
              $item['month'] = "*";
388
              $item['wday'] = "*";
389
              $item['who'] = "root";
390
              $item['command'] = CRON_PPPOE_CMD_FILE;
391
              break;
392
            case "weekly":
393
              $item['minute'] = "0";
394
              $item['hour'] = "0";
395
              $item['mday'] = "*";
396
              $item['month'] = "*";
397
              $item['wday'] = "0";
398
              $item['who'] = "root";
399
              $item['command'] = CRON_PPPOE_CMD_FILE;
400
              break;
401
            case "daily":
402
              $item['minute'] = "0";
403
              $item['hour'] = "0";
404
              $item['mday'] = "*";
405
              $item['month'] = "*";
406
              $item['wday'] = "*";
407
              $item['who'] = "root";
408
              $item['command'] = CRON_PPPOE_CMD_FILE;
409
              break;
410
            case "hourly":
411
              $item['minute'] = "0";
412
              $item['hour'] = "*";
413
              $item['mday'] = "*";
414
              $item['month'] = "*";
415
              $item['wday'] = "*";
416
              $item['who'] = "root";
417
              $item['command'] = CRON_PPPOE_CMD_FILE;
418
              break;
419
          } // end switch
420
        } // end if
421

    
422
        if (isset($itemhash['ID'])) {
423
          $config['cron']['item'][$itemhash['ID']] = $item;
424
        } else {
425
          $config['cron']['item'][] = $item;
426
        }
427
      } // end if
428
		} else if ($_POST['type'] == "PPTP") {
429
			$wancfg['ipaddr'] = "pptp";
430
			$config['pptp']['username'] = $_POST['pptp_username'];
431
			$config['pptp']['password'] = $_POST['pptp_password'];
432
			$config['pptp']['local'] = $_POST['pptp_local'];
433
			$config['pptp']['subnet'] = $_POST['pptp_subnet'];
434
			$config['pptp']['remote'] = $_POST['pptp_remote'];
435
			$config['pptp']['ondemand'] = $_POST['pptp_dialondemand'] ? true : false;
436
			$config['pptp']['timeout'] = $_POST['pptp_idletimeout'];
437
		}
438
    
439
    /* reset cron items if necessary */
440
    if (empty($_POST['pppoe_preset'])) {
441
      /* test whether a cron item exists and unset() it if necessary */
442
      $itemhash = getMPDCRONSettings();
443
      $item = $itemhash['ITEM'];
444

    
445
      if (isset($item)) { unset($config['cron']['item'][$itemhash['ID']]); }
446
    }
447

    
448
		if($_POST['blockpriv'] == "yes")
449
			$wancfg['blockpriv'] = true;
450
		else
451
			unset($wancfg['blockpriv']);
452

    
453
		if($_POST['blockbogons'] == "yes")
454
			$wancfg['blockbogons'] = true;
455
		else
456
			unset($wancfg['blockbogons']);
457

    
458
		$wancfg['spoofmac'] = $_POST['spoofmac'];
459
		$wancfg['mtu'] = $_POST['mtu'];
460

    
461
		write_config();
462
    
463
		/* finally install the pppoerestart file */
464
		if (isset($_POST['pppoe_preset'])) {
465
      config_lock();
466
      conf_mount_rw();
467
      
468
      if (! file_exists(CRON_PPPOE_CMD_FILE)) {
469
        file_put_contents(CRON_PPPOE_CMD_FILE, CRON_PPPOE_CMD);
470
        chmod(CRON_PPPOE_CMD_FILE, 0700);
471
      }
472
      
473
      /* regenerate cron settings/crontab file */
474
      configure_cron();
475
      sigkillbypid("{$g['varrun_path']}/cron.pid", "HUP");
476
      
477
      conf_mount_ro();
478
      config_unlock();
479
		}
480

    
481

    
482
		$retval = 0;
483

    
484
		$savemsg = get_std_save_message($retval);
485
	}
486
}
487

    
488
$pgtitle = "Interfaces: WAN";
489
$closehead = false;
490
include("head.inc");
491

    
492
?>
493

    
494
<script type="text/javascript" src="/javascript/numericupdown/js/numericupdown.js"></script>
495
<link href="/javascript/numericupdown/css/numericupdown.css" rel="stylesheet" type="text/css" />
496

    
497
<script type="text/javascript" src="/javascript/datepicker/js/datepicker.js"></script>
498
<link href="/javascript/datepicker/css/datepicker.css" rel="stylesheet" type="text/css" />
499

    
500
<script type="text/javascript" src="/javascript/scriptaculous/prototype.js"></script>
501
<script type="text/javascript" src="/javascript/scriptaculous/scriptaculous.js"></script>
502

    
503
<script type="text/javascript">
504
<!--
505
function enable_change(enable_change) {
506
	if (document.iform.pppoe_dialondemand.checked || enable_change) {
507
		document.iform.pppoe_idletimeout.disabled = 0;
508
	} else {
509
		document.iform.pppoe_idletimeout.disabled = 1;
510
	}
511
}
512

    
513
function enable_change_pptp(enable_change_pptp) {
514
	if (document.iform.pptp_dialondemand.checked || enable_change_pptp) {
515
		document.iform.pptp_idletimeout.disabled = 0;
516
		document.iform.pptp_local.disabled = 0;
517
		document.iform.pptp_remote.disabled = 0;
518
	} else {
519
		document.iform.pptp_idletimeout.disabled = 1;
520
	}
521
}
522

    
523
function type_change(enable_change,enable_change_pptp) {
524
	switch (document.iform.type.selectedIndex) {
525
		case 0:
526
			document.iform.username.disabled = 1;
527
			document.iform.password.disabled = 1;
528
			document.iform.provider.disabled = 1;
529
			document.iform.pppoe_dialondemand.disabled = 1;
530
			document.iform.pppoe_idletimeout.disabled = 1;
531
      		document.iform.pppoe_preset.disabled = 1;
532
      		document.iform.pppoe_preset.checked = 0;
533
      		Effect.Fade('presetwrap', { duration: 1.0 });
534
			document.iform.ipaddr.disabled = 0;
535
			document.iform.subnet.disabled = 0;
536
			document.iform.gateway.disabled = 0;
537
			document.iform.pptp_username.disabled = 1;
538
			document.iform.pptp_password.disabled = 1;
539
			document.iform.pptp_local.disabled = 1;
540
			document.iform.pptp_subnet.disabled = 1;
541
			document.iform.pptp_remote.disabled = 1;
542
			document.iform.pptp_dialondemand.disabled = 1;
543
			document.iform.pptp_idletimeout.disabled = 1;
544
			document.iform.dhcphostname.disabled = 1;
545
			break;
546
		case 1:
547
			document.iform.username.disabled = 1;
548
			document.iform.password.disabled = 1;
549
			document.iform.provider.disabled = 1;
550
			document.iform.pppoe_dialondemand.disabled = 1;
551
			document.iform.pppoe_idletimeout.disabled = 1;
552
			document.iform.pppoe_preset.disabled = 1;
553
      		document.iform.pppoe_preset.checked = 0;
554
      		Effect.Fade('presetwrap', { duration: 1.0 });
555
			document.iform.ipaddr.disabled = 1;
556
			document.iform.subnet.disabled = 1;
557
			document.iform.gateway.disabled = 1;
558
			document.iform.pptp_username.disabled = 1;
559
			document.iform.pptp_password.disabled = 1;
560
			document.iform.pptp_local.disabled = 1;
561
			document.iform.pptp_subnet.disabled = 1;
562
			document.iform.pptp_remote.disabled = 1;
563
			document.iform.pptp_dialondemand.disabled = 1;
564
			document.iform.pptp_idletimeout.disabled = 1;
565
			document.iform.dhcphostname.disabled = 0;
566
			break;
567
		case 2:
568
			document.iform.username.disabled = 0;
569
			document.iform.password.disabled = 0;
570
			document.iform.provider.disabled = 0;
571
			document.iform.pppoe_dialondemand.disabled = 0;
572
			if (document.iform.pppoe_dialondemand.checked || enable_change) {
573
				document.iform.pppoe_idletimeout.disabled = 0;
574
			} else {
575
				document.iform.pppoe_idletimeout.disabled = 1;
576
			}
577
      document.iform.pppoe_preset.disabled = 0;
578
			document.iform.ipaddr.disabled = 1;
579
			document.iform.subnet.disabled = 1;
580
			document.iform.gateway.disabled = 1;
581
			document.iform.pptp_username.disabled = 1;
582
			document.iform.pptp_password.disabled = 1;
583
			document.iform.pptp_local.disabled = 1;
584
			document.iform.pptp_subnet.disabled = 1;
585
			document.iform.pptp_remote.disabled = 1;
586
			document.iform.pptp_dialondemand.disabled = 1;
587
			document.iform.pptp_idletimeout.disabled = 1;
588
			document.iform.dhcphostname.disabled = 1;
589
			break;
590
		case 3:
591
			document.iform.username.disabled = 1;
592
			document.iform.password.disabled = 1;
593
			document.iform.provider.disabled = 1;
594
			document.iform.pppoe_dialondemand.disabled = 1;
595
			document.iform.pppoe_idletimeout.disabled = 1;
596
      		document.iform.pppoe_preset.disabled = 1;
597
      		document.iform.pppoe_preset.checked = 0;
598
      		Effect.Fade('presetwrap', { duration: 1.0 });			
599
			document.iform.ipaddr.disabled = 1;
600
			document.iform.subnet.disabled = 1;
601
			document.iform.gateway.disabled = 1;
602
			document.iform.pptp_username.disabled = 0;
603
			document.iform.pptp_password.disabled = 0;
604
			document.iform.pptp_local.disabled = 0;
605
			document.iform.pptp_subnet.disabled = 0;
606
			document.iform.pptp_remote.disabled = 0;
607
			document.iform.pptp_dialondemand.disabled = 0;
608
			if (document.iform.pptp_dialondemand.checked || enable_change_pptp) {
609
				document.iform.pptp_idletimeout.disabled = 0;
610
			} else {
611
				document.iform.pptp_idletimeout.disabled = 1;
612
			}
613
			document.iform.dhcphostname.disabled = 1;
614
			break;
615
	}
616
}
617
//-->
618
</script>
619
</head>
620
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
621
<?php include("fbegin.inc"); ?>
622
<p class="pgtitle"><?=$pgtitle?></p>
623
<?php if ($input_errors) print_input_errors($input_errors); ?>
624
<?php if ($savemsg) print_info_box($savemsg); ?>
625
            <form action="interfaces_wan.php" method="post" name="iform" id="iform">
626
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
627
                <tr>
628
                  <td colspan="2" valign="top" class="listtopic">General configuration</td>
629
                </tr>
630
                <tr>
631
                  <td valign="middle" class="vncell"><strong>Type</strong></td>
632
                  <td class="vtable"> <select name="type" class="formfld" id="type" onchange="type_change()">
633
                      <?php $opts = split(" ", "Static DHCP PPPoE PPTP");
634
				foreach ($opts as $opt): ?>
635
                      <option <?php if ($opt == $pconfig['type']) echo "selected";?>>
636
                      <?=htmlspecialchars($opt);?>
637
                      </option>
638
                      <?php endforeach; ?>
639
                    </select></td>
640
                </tr>
641
                <tr>
642
                  <td valign="top" class="vncell">MAC address</td>
643
                  <td class="vtable"> <input name="spoofmac" type="text" class="formfld" id="spoofmac" size="30" value="<?=htmlspecialchars($pconfig['spoofmac']);?>">
644
		    <?php
645
			$ip = getenv('REMOTE_ADDR');
646
			$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
647
			$mac = str_replace("\n","",$mac);
648
		    ?>
649
		    <a OnClick="document.forms[0].spoofmac.value='<?=$mac?>';" href="#">Copy my MAC address</a>
650
		    <br>
651
                    This field can be used to modify (&quot;spoof&quot;) the MAC
652
                    address of the WAN interface<br>
653
                    (may be required with some cable connections)<br>
654
                    Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx
655
                    or leave blank</td>
656
                </tr>
657
                <tr>
658
                  <td valign="top" class="vncell">MTU</td>
659
                  <td class="vtable"> <input name="mtu" type="text" class="formfld" id="mtu" size="8" value="<?=htmlspecialchars($pconfig['mtu']);?>">
660
                    <br>
661
                    If you enter a value in this field, then MSS clamping for
662
                    TCP connections to the value entered above minus 40 (TCP/IP
663
                    header size) will be in effect. If you leave this field blank,
664
                    an MTU of 1492 bytes for PPPoE and 1500 bytes for all other
665
                    connection types will be assumed.</td>
666
                </tr>
667
                <tr>
668
                  <td colspan="2" valign="top" height="16"></td>
669
                </tr>
670
                <tr>
671
                  <td colspan="2" valign="top" class="listtopic">Static IP configuration</td>
672
                </tr>
673
                <tr>
674
                  <td width="100" valign="top" class="vncellreq">IP address</td>
675
                  <td class="vtable"> <input name="ipaddr" type="text" class="formfld" id="ipaddr" size="20" value="<?=htmlspecialchars($pconfig['ipaddr']);?>">
676
                    /
677
                    <select name="subnet" class="formfld" id="subnet">
678
			<?php
679
			for ($i = 32; $i > 0; $i--) {
680
				if($i <> 31) {
681
					echo "<option value=\"{$i}\" ";
682
					if ($i == $pconfig['subnet']) echo "selected";
683
					echo ">" . $i . "</option>";
684
				}
685
			}
686
			?>
687
                    </select></td>
688
                </tr><?php if (isset($wancfg['ispointtopoint'])): ?>
689
                <tr>
690
                  <td valign="top" class="vncellreq">Point-to-point IP address </td>
691
                  <td class="vtable">
692
                    <input name="pointtopoint" type="text" class="formfld" id="pointtopoint" size="20" value="<?=htmlspecialchars($pconfig['pointtopoint']);?>">
693
                  </td>
694
                </tr><?php endif; ?>
695
                <tr>
696
                  <td valign="top" class="vncellreq">Gateway</td>
697
                  <td class="vtable"> <input name="gateway" type="text" class="formfld" id="gateway" size="20" value="<?=htmlspecialchars($pconfig['gateway']);?>">
698
                  </td>
699
                </tr>
700
                <tr>
701
                  <td colspan="2" valign="top" height="16"></td>
702
                </tr>
703
                <tr>
704
                  <td colspan="2" valign="top" class="listtopic">DHCP client configuration</td>
705
                </tr>
706
                <tr>
707
                  <td valign="top" class="vncell">Hostname</td>
708
                  <td class="vtable"> <input name="dhcphostname" type="text" class="formfld" id="dhcphostname" size="40" value="<?=htmlspecialchars($pconfig['dhcphostname']);?>">
709
                    <br>
710
                    The value in this field is sent as the DHCP client identifier
711
                    and hostname when requesting a DHCP lease. Some ISPs may require
712
                    this (for client identification).</td>
713
                </tr>
714
                <tr>
715
                  <td colspan="2" valign="top" height="16"></td>
716
                </tr>
717
                <tr>
718
                  <td colspan="2" valign="top" class="listtopic">PPPoE configuration</td>
719
                </tr>
720
                <tr>
721
                  <td valign="top" class="vncellreq">Username</td>
722
                  <td class="vtable"><input name="username" type="text" class="formfld" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>">
723
                  </td>
724
                </tr>
725
                <tr>
726
                  <td valign="top" class="vncellreq">Password</td>
727
                  <td class="vtable"><input name="password" type="password" class="formfld" id="password" size="20" value="<?=htmlspecialchars($pconfig['password']);?>">
728
                  </td>
729
                </tr>
730
                <tr>
731
                  <td valign="top" class="vncell">Service name</td>
732
                  <td class="vtable"><input name="provider" type="text" class="formfld" id="provider" size="20" value="<?=htmlspecialchars($pconfig['provider']);?>">
733
                    <br> <span class="vexpl">Hint: this field can usually be left
734
                    empty</span></td>
735
                </tr>
736
                <tr>
737
                  <td valign="top" class="vncell">Dial on demand</td>
738
                  <td class="vtable"><input name="pppoe_dialondemand" type="checkbox" id="pppoe_dialondemand" value="enable" <?php if ($pconfig['pppoe_dialondemand']) echo "checked"; ?> onClick="enable_change(false)" >
739
                    <strong>Enable Dial-On-Demand mode</strong><br>
740
		    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.</td>
741
                </tr>
742
                <tr>
743
                  <td valign="top" class="vncell">Idle timeout</td>
744
                  <td class="vtable">
745
                    <input name="pppoe_idletimeout" type="text" class="formfld" 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.</td>
746
                </tr>
747
                <tr>
748
                  <td valign="top" class="vncell"><?=gettext("Periodic reset");?></td>
749
                  <td class="vtable">
750
                    <input name="pppoe_preset" type="checkbox" id="pppoe_preset" value="yes" <?php if ($pconfig['pppoe_preset']) echo "checked=\"checked\""; ?> onclick="Effect.toggle('presetwrap', 'appear', { duration: 1.0 });" />
751
                    <?= gettext("enable periodic PPPoE resets"); ?>
752
                    <br />
753
                    <?php if ($pconfig['pppoe_preset']): ?>
754
                    <table id="presetwrap" cellspacing="0" cellpadding="0" width="100%">
755
                    <?php else: ?>
756
                    <table id="presetwrap" cellspacing="0" cellpadding="0" width="100%" style="display: none;">
757
                    <?php endif; ?>
758
                      <tr>
759
                        <td align="left" valign="top">
760
                          <p style="margin: 4px; padding: 4px 0 4px 0; width: 94%;">
761
                            <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: 1.0 }); Effect.Fade('pppoepresetwrap', { duration: 1.0 }); }" /> 
762
                            <?= gettext("provide a custom reset time"); ?>
763
                            <br />
764
                            <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: 1.0 }); Effect.Fade('pppoecustomwrap', { duration: 1.0 }); }" /> 
765
                            <?= gettext("select reset time from a preset"); ?>
766
                          </p>
767
                          <?php if ($pconfig['pppoe_pr_custom']): ?>
768
                          <p style="margin: 2px; padding: 4px; width: 94%;" id="pppoecustomwrap">
769
                          <?php else: ?>
770
                          <p style="margin: 2px; padding: 4px; width: 94%; display: none;" id="pppoecustomwrap">
771
                          <?php endif; ?>
772
                            <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" /> 
773
                            <?= gettext("hour (0-23)"); ?><br />
774
                            <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" /> 
775
                            <?= gettext("minute (0-59)"); ?><br />
776
                            <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']);?>" /> 
777
                            <?= gettext("reset at a specific date (mm/dd/yyyy)"); ?>
778
                            <br />&nbsp;<br />
779
                            <span class="red"><strong>Note: </strong></span>
780
                            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.
781
                          </p>
782
                          <?php if ($pconfig['pppoe_pr_preset']): ?>
783
                          <p style="margin: 2px; padding: 4px; width: 94%;" id="pppoepresetwrap">
784
                          <?php else: ?>
785
                          <p style="margin: 2px; padding: 4px; width: 94%; display: none;" id="pppoepresetwrap">
786
                          <?php endif; ?>
787
                            <input name="pppoe_pr_preset_val" type="radio" id="pppoe_monthly" value="monthly" <?php if ($pconfig['pppoe_monthly']) echo "checked=\"checked\""; ?> /> 
788
                            <?= gettext("reset at each month ('0 0 1 * *')"); ?>
789
                            <br />
790
                            <input name="pppoe_pr_preset_val" type="radio" id="pppoe_weekly" value="weekly" <?php if ($pconfig['pppoe_weekly']) echo "checked=\"checked\""; ?> /> 
791
                            <?= gettext("reset at each week ('0 0 * * 0')"); ?>
792
                            <br />
793
                            <input name="pppoe_pr_preset_val" type="radio" id="pppoe_daily" value="daily" <?php if ($pconfig['pppoe_daily']) echo "checked=\"checked\""; ?> /> 
794
                            <?= gettext("reset at each day ('0 0 * * *')"); ?>
795
                            <br />
796
                            <input name="pppoe_pr_preset_val" type="radio" id="pppoe_hourly" value="hourly" <?php if ($pconfig['pppoe_hourly']) echo "checked=\"checked\""; ?> /> 
797
                            <?= gettext("reset at each hour ('0 * * * *')"); ?>
798
                          </p>
799
                        </td>
800
                      </tr>
801
                    </table>
802
                  </td>
803
                </tr>                
804
                <tr>
805
                  <td colspan="2" valign="top" height="16"></td>
806
                </tr>
807
                <tr>
808
                  <td colspan="2" valign="top" class="listtopic">PPTP configuration</td>
809
                </tr>
810
                <tr>
811
                  <td valign="top" class="vncellreq">Username</td>
812
                  <td class="vtable"><input name="pptp_username" type="text" class="formfld" id="pptp_username" size="20" value="<?=htmlspecialchars($pconfig['pptp_username']);?>">
813
                  </td>
814
                </tr>
815
                <tr>
816
                  <td valign="top" class="vncellreq">Password</td>
817
                  <td class="vtable"><input name="pptp_password" type="text" class="formfld" id="pptp_password" size="20" value="<?=htmlspecialchars($pconfig['pptp_password']);?>">
818
                  </td>
819
                </tr>
820
                <tr>
821
                  <td width="100" valign="top" class="vncellreq">Local IP address</td>
822
                  <td class="vtable"> <input name="pptp_local" type="text" class="formfld" id="pptp_local" size="20" value="<?=htmlspecialchars($pconfig['pptp_local']);?>">
823
                    /
824
                    <select name="pptp_subnet" class="formfld" id="pptp_subnet">
825
                      <?php for ($i = 31; $i > 0; $i--): ?>
826
                      <option value="<?=$i;?>" <?php if ($i == $pconfig['pptp_subnet']) echo "selected"; ?>>
827
                      <?=$i;?>
828
                      </option>
829
                      <?php endfor; ?>
830
                    </select></td>
831
                </tr>
832
                <tr>
833
                  <td width="100" valign="top" class="vncellreq">Remote IP address</td>
834
                  <td class="vtable"> <input name="pptp_remote" type="text" class="formfld" id="pptp_remote" size="20" value="<?=htmlspecialchars($pconfig['pptp_remote']);?>">
835
                  </td>
836
                </tr>
837
                <tr>
838
                  <td valign="top" class="vncell">Dial on demand</td>
839
                  <td class="vtable"><input name="pptp_dialondemand" type="checkbox" id="pptp_dialondemand" value="enable" <?php if ($pconfig['pptp_dialondemand']) echo "checked"; ?> onClick="enable_change_pptp(false)" >
840
                    <strong>Enable Dial-On-Demand mode</strong><br>
841
		    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.</td>
842
                </tr>
843
                <tr>
844
                  <td valign="top" class="vncell">Idle timeout</td>
845
                  <td class="vtable">
846
                    <input name="pptp_idletimeout" type="text" class="formfld" 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.</td>
847
                </tr>
848
                <tr>
849
                  <td colspan="2" valign="top" height="16"></td>
850
                </tr>
851
                <tr>
852
                  <td colspan="2" valign="top" class="listtopic">FTP Helper</td>
853
                </tr>
854
				<tr>
855
					<td width="22%" valign="top" class="vncell">FTP Helper</td>
856
					<td width="78%" class="vtable">
857
						<input name="disableftpproxy" type="checkbox" id="disableftpproxy" value="yes" <?php if ($pconfig['disableftpproxy']) echo "checked"; ?> onclick="enable_change(false)" />
858
						<strong>Disable the userland FTP-Proxy application</strong>
859
						<br />
860
					</td>
861
				</tr>
862
		        <?php
863
				/* Wireless interface? */
864
				if (isset($wancfg['wireless']))
865
					wireless_config_print();
866
			?>
867
                <tr>
868
                  <td height="16" colspan="2" valign="top"></td>
869
                </tr>
870
                <tr>
871
                  <td valign="middle">&nbsp;</td>
872
                  <td class="vtable"><a name="rfc1918"></a> <input name="blockpriv" type="checkbox" id="blockpriv" value="yes" <?php if ($pconfig['blockpriv']) echo "checked"; ?>>
873
                    <strong>Block private networks</strong><br>
874
                    When set, this option blocks traffic from IP addresses that
875
                    are reserved for private<br>
876
                    networks as per RFC 1918 (10/8, 172.16/12, 192.168/16) as
877
                    well as loopback addresses<br>
878
                    (127/8). You should generally leave this option turned on,
879
                    unless your WAN network<br>
880
                    lies in such a private address space, too.</td>
881
                </tr>
882
                <tr>
883
                  <td valign="middle">&nbsp;</td>
884
                  <td class="vtable"> <input name="blockbogons" type="checkbox" id="blockbogons" value="yes" <?php if ($pconfig['blockbogons']) echo "checked"; ?>>
885
                    <strong>Block bogon networks</strong><br>
886
                    When set, this option blocks traffic from IP addresses that
887
                    are reserved (but not RFC 1918) or not yet assigned by IANA.<br>
888
                    Bogons are prefixes that should never appear in the Internet routing table, and obviously should not appear as the source address in any packets you receive.</td>
889
				</tr>
890
                <tr>
891
                  <td width="100" valign="top">&nbsp;</td>
892
                  <td> &nbsp;<br> <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change_pptp(true)&&enable_change(true)">
893
                  </td>
894
                </tr>
895
              </table>
896
</form>
897
<script language="JavaScript">
898
<!--
899
type_change();
900
//-->
901
</script>
902
<?php include("fend.inc"); ?>
903
</body>
904
</html>
905

    
906

    
907
<?php
908

    
909
if ($_POST) {
910

    
911
	if (!$input_errors) {
912

    
913
		unlink_if_exists("{$g['tmp_path']}/config.cache");
914

    
915
		ob_flush();
916
		flush();
917
		sleep(1);
918

    
919
		interfaces_wan_configure();
920

    
921
		reset_carp();
922

    
923
		/* sync filter configuration */
924
		filter_configure();
925

    
926
 		/* set up static routes */
927
		system_routing_configure();
928

    
929
	}
930
}
931

    
932
?>
(69-69/173)