Project

General

Profile

Download (37.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces_mlppp_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9
	Copyright (C) 2010 Gabriel B. <gnoahb@gmail.com>.
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
	pfSense_MODULE:	interfaces
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-interfaces-mlppp-edit
39
##|*NAME=Interfaces: MLPPP: Edit page
40
##|*DESCR=Allow access to the 'Interfaces: MLPPP: Edit' page.
41
##|*MATCH=interfaces_mlppp_edit.php*
42
##|-PRIV
43

    
44
require("guiconfig.inc");
45

    
46
define("CRON_PPPOE_CMD_FILE", "/conf/pppoe{$if}restart");
47
define("CRON_MONTHLY_PATTERN", "0 0 1 * *");
48
define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
49
define("CRON_DAILY_PATTERN", "0 0 * * *");
50
define("CRON_HOURLY_PATTERN", "0 * * * *");
51

    
52
if (!is_array($config['ppps']['ppp']))
53
	$config['ppps']['ppp'] = array();
54

    
55
$a_ppps = &$config['ppps']['ppp'];
56

    
57
$portlist = get_interface_list();
58

    
59
function getMPDCRONSettings() {
60
	global $config;
61
	if (is_array($config['cron']['item'])) {
62
		for ($i = 0; $i < count($config['cron']['item']); $i++) {
63
			$item = $config['cron']['item'][$i];
64
			if (strpos($item['command'], CRON_PPPOE_CMD_FILE) !== false) {
65
				return array("ID" => $i, "ITEM" => $item);
66
			}
67
		}
68
	}
69
	return NULL;
70
}
71

    
72
function getMPDResetTimeFromConfig() {
73
	$itemhash = getMPDCRONSettings();
74
	$cronitem = $itemhash['ITEM'];
75
	if (isset($cronitem)) {
76
		return "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}";
77
	} else {
78
		return NULL;
79
	}
80
}
81

    
82
function remove_bad_chars($string) {
83
	return preg_replace('/[^a-z|_|0-9]/i','',$string);
84
}
85

    
86
$id = $_GET['id'];
87
if (isset($_POST['id']))
88
	$id = $_POST['id'];
89

    
90

    
91
if (isset($id) && $a_ppps[$id]) {
92
	$pconfig['type'] = $a_ppps[$id]['type'];
93
	$pconfig['interfaces'] = $a_ppps[$id]['ports'];
94
	$pconfig['username'] = $a_ppps[$id]['username'];
95
	$pconfig['password'] = base64_decode($a_ppps[$id]['password']);
96
	if (isset($a_ppps[$id]['defaultgw']))
97
		$pconfig['defaultgw'] = true;
98
	if (isset($a_ppps[$id]['ondemand']))
99
		$pconfig['ondemand'] = true;
100
	$pconfig['idletimeout'] = $a_ppps[$id]['idletimeout'];
101
	$pconfig['uptime'] = $a_ppps[$id]['uptime'];
102
	$pconfig['descr'] = $a_ppps[$id]['descr'];
103
	$pconfig['bandwidth'] = $a_ppps[$id]['bandwidth'];
104
	$pconfig['mtu'] = $a_ppps[$id]['mtu'];
105
	$pconfig['mru'] = $a_ppps[$id]['mru'];
106
	$pconfig['mrru'] = $a_ppps[$id]['mrru'];
107
	if (isset($a_ppps[$id]['shortseq']))
108
		$pconfig['shortseq'] = true;
109
	if (isset($a_ppps[$id]['acfcomp']))
110
		$pconfig['acfcomp'] = true;
111
	if (isset($a_ppps[$id]['protocomp']))
112
		$pconfig['protocomp'] = true;
113
	if (isset($a_ppps[$id]['vjcomp']))
114
		$pconfig['vjcomp'] = true;
115
	if (isset($a_ppps[$id]['tcpmssfix']))
116
		$pconfig['tcpmssfix'] = true;
117
	if ($a_ppps[$id]['type'] == "ppp") {
118
		$pconfig['initstr'] = base64_decode($a_ppps[$id]['initstr']);
119
		$pconfig['simpin'] = $a_ppps[$id]['simpin'];
120
		$pconfig['pin-wait'] = $a_ppps[$id]['pin-wait'];
121
		$pconfig['apn'] = $a_ppps[$id]['apn'];
122
		$pconfig['apnum'] = $a_ppps[$id]['apnum'];
123
		$pconfig['phone'] = $a_ppps[$id]['phone'];
124
		$pconfig['connect-timeout'] = $a_ppps[$id]['connect-timeout'];
125
		$pconfig['localip'] = $a_ppps[$id]['localip'];
126
		$pconfig['gateway'] = $a_ppps[$id]['gateway'];
127
	}
128
	if ($a_ppps[$id]['type'] == "pptp") {
129
		$pconfig['localip'] = $a_ppps[$id]['localip'];
130
		$pconfig['subnet'] = $a_ppps[$id]['subnet'];
131
		$pconfig['gateway'] = $a_ppps[$id]['gateway'];
132
	}
133
	if ($a_ppps[$id]['type'] == "pppoe") {
134
		$pconfig['provider'] = $a_ppps[$id]['provider'];
135
		/* ================================================ */
136
		/* = force a connection reset at a specific time? = */
137
		/* ================================================ */
138
		
139
		if (isset($a_ppps[$id]['pppoe-reset-type'])) {
140
			$resetTime = getMPDResetTimeFromConfig();  
141
			$pconfig['pppoe_preset'] = true;
142
			if ($a_ppps[$id]['pppoe-reset-type'] == "custom") {
143
				$resetTime_a = split(" ", $resetTime);
144
				$pconfig['pppoe_pr_custom'] = true;
145
				$pconfig['pppoe_resetminute'] = $resetTime_a[0];
146
				$pconfig['pppoe_resethour'] = $resetTime_a[1];
147
				/*  just initialize $pconfig['pppoe_resetdate'] if the
148
				 *  coresponding item contains appropriate numeric values.
149
				 */
150
				if ($resetTime_a[2] <> "*" && $resetTime_a[3] <> "*") 
151
					$pconfig['pppoe_resetdate'] = "{$resetTime_a[3]}/{$resetTime_a[2]}/" . date("Y");
152
			} else if ($a_ppps[$id]['pppoe-reset-type'] == "preset") {
153
				$pconfig['pppoe_pr_preset'] = true;
154
				switch ($resetTime) {
155
					case CRON_MONTHLY_PATTERN:
156
						$pconfig['pppoe_monthly'] = true;
157
						break;
158
					case CRON_WEEKLY_PATTERN:
159
						$pconfig['pppoe_weekly'] = true;
160
						break;
161
					case CRON_DAILY_PATTERN:
162
						$pconfig['pppoe_daily'] = true;
163
						break;
164
					case CRON_HOURLY_PATTERN:
165
						$pconfig['pppoe_hourly'] = true;
166
						break;
167
				}
168
			}
169
		}
170
	}
171
	
172
}
173

    
174
if ($_POST) {
175

    
176
	unset($input_errors);
177
	$pconfig = $_POST;
178
	
179
	/* filter out spaces from descriptions  */
180
	$_POST['descr'] = remove_bad_chars($_POST['descr']);
181
	
182
	/* okay first of all, cause we are just hiding the PPPoE HTML
183
	 * fields releated to PPPoE resets, we are going to unset $_POST
184
	 * vars, if the reset feature should not be used. Otherwise the
185
	 * data validation procedure below, may trigger a false error
186
	 * message.
187
	 */
188
	if (empty($_POST['pppoe_preset'])) {
189
		unset($_POST['pppoe_pr_type']);                
190
		unset($_POST['pppoe_resethour']);
191
		unset($_POST['pppoe_resetminute']);
192
		unset($_POST['pppoe_resetdate']);
193
		unset($_POST['pppoe_pr_preset_val']);
194
	}
195

    
196
	/* input validation */
197

    
198
	switch($_POST['type']) {
199
		case "ppp":
200
			$reqdfields = explode(" ", "interfaces phone");
201
			$reqdfieldsn = explode(",", "Link Interface(s),Phone Number");
202
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
203
			break;
204
		case "pppoe":
205
			if ($_POST['ondemand']) {
206
				$reqdfields = explode(" ", "interfaces username password ondemand idletimeout");
207
				$reqdfieldsn = explode(",", "Link Interface(s),Username,Password,Dial on demand,Idle timeout value");
208
			} else {
209
				$reqdfields = explode(" ", "interfaces username password");
210
				$reqdfieldsn = explode(",", "Link Interface(s),Username,Password");
211
			}
212
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
213
			break;
214
		case "pptp":
215
			if ($_POST['ondemand']) {
216
				$reqdfields = explode(" ", "interfaces username password localip subnet gateway ondemand idletimeout");
217
				$reqdfieldsn = explode(",", "Link Interface(s),Username,Password,Local IP address,Subnet,Remote IP address,Dial on demand,Idle timeout value");
218
			} else {
219
				$reqdfields = explode(" ", "interfaces username password localip subnet gateway");
220
				$reqdfieldsn = explode(",", "Link Interface(s),Username,Password,Local IP address,Subnet,Remote IP address");
221
			}
222
			do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
223
			break;
224
		default:
225
			$input_errors[] = "Please choose a Link Type.";
226
			break;
227
	}
228
	if (($_POST['provider'] && !is_domain($_POST['provider']))) 
229
		$input_errors[] = "The service name contains invalid characters.";
230
	if (($_POST['idletimeout'] != "") && !is_numericint($_POST['idletimeout'])) 
231
		$input_errors[] = "The idle timeout value must be an integer.";
232
	if ($_POST['pppoe_resethour'] <> "" && !is_numericint($_POST['pppoe_resethour']) && 
233
		$_POST['pppoe_resethour'] >= 0 && $_POST['pppoe_resethour'] <=23) 
234
		$input_errors[] = gettext("A valid PPPoE reset hour must be specified (0-23).");
235
	if ($_POST['pppoe_resetminute'] <> "" && !is_numericint($_POST['pppoe_resetminute']) && 
236
		$_POST['pppoe_resetminute'] >= 0 && $_POST['pppoe_resetminute'] <=59) 
237
		$input_errors[] = gettext("A valid PPPoE reset minute must be specified (0-59).");
238
	if ($_POST['pppoe_resetdate'] <> "" && !is_numeric(str_replace("/", "", $_POST['pppoe_resetdate']))) 
239
		$input_errors[] = gettext("A valid PPPoE reset date must be specified (mm/dd/yyyy).");
240
	if (($_POST['localip'] && !is_ipaddr($_POST['localip']))) 
241
		$input_errors[] = "A valid PPTP local IP address must be specified.";
242
	if (($_POST['subnet'] && !is_numeric($_POST['subnet']))) 
243
		$input_errors[] = "A valid PPTP subnet bit count must be specified.";
244
	if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) 
245
		$input_errors[] = "A valid PPTP remote IP address must be specified.";
246
		
247
	if ($_POST['mtu'] && ($_POST['mtu'] < 576)) 
248
		$input_errors[] = "The MTU must be greater than 576 bytes.";
249
	if ($_POST['mru'] && ($_POST['mru'] < 576)) 
250
		$input_errors[] = "The MRU must be greater than 576 bytes.";
251
/*
252
	foreach ($a_ppps as $ppp) {
253
		if (isset($id) && ($a_ppps[$id]) && ($a_ppps[$id] === $ppp))
254
			continue;
255

    
256
		if ($ppp['serialport'] == $_POST['serialport']) {
257
			$input_errors[] = "Serial port is in use";
258
			break;
259
		}
260
	}
261
*/	
262

    
263
	if (!$input_errors) {
264
		$ppp = array();
265
		$ppp['type'] = $_POST['type'];
266
		$ppp['ports'] = implode(',', $_POST['interfaces']);
267
		$ppp['username'] = $_POST['username'];
268
		$ppp['password'] = base64_encode($_POST['password']);
269
		$ppp['defaultgw'] = $_POST['defaultgw'] ? true : false;
270
		$ppp['ondemand'] = $_POST['ondemand'] ? true : false;
271
		if (!empty($_POST['idletimeout']))
272
			$ppp['idletimeout'] = $_POST['idletimeout'];
273
		else 
274
			unset($ppp['idletimeout']);
275
		$ppp['uptime'] = $_POST['uptime'] ? true : false;
276
		if (!empty($_POST['descr']))
277
			$ppp['descr'] = $_POST['descr'];
278
		else
279
			unset($ppp['descr']);
280
		switch($_POST['type']) {
281
			case "ppp":
282
				if (!empty($_POST['initstr']))
283
					$ppp['initstr'] = base64_encode($_POST['initstr']);
284
				else
285
					unset($ppp['initstr']);
286
				if (!empty($_POST['simpin'])) {
287
					$ppp['simpin'] = $_POST['simpin'];
288
					$ppp['pin-wait'] = $_POST['pin-wait'];
289
				} else {
290
					unset($ppp['simpin']);
291
					unset($ppp['pin-wait']);
292
				}
293
				
294
				if (!empty($_POST['apn'])){
295
					$ppp['apn'] = $_POST['apn'];
296
					if (!empty($_POST['apnum']))
297
						$ppp['apnum'] = $_POST['apnum'];
298
					else
299
						$ppp['apnum'] = "1";
300
				} else {
301
					unset($ppp['apn']);
302
					unset($ppp['apnum']);
303
				}
304
				$ppp['phone'] = $_POST['phone'];
305
				if (!empty($_POST['localip']))
306
					$ppp['localip'] = $_POST['localip'];
307
				else
308
					unset($ppp['localip']);
309
				if (!empty($_POST['gateway']))
310
					$ppp['gateway'] = $_POST['gateway'];
311
				else
312
					unset($ppp['gateway']);
313
				if (!empty($_POST['connect-timeout']))
314
					$ppp['connect-timeout'] = $_POST['connect-timeout'];
315
				else
316
					unset($ppp['connect-timeout']);
317
				break;
318
			case "pppoe":
319
				if (!empty($_POST['provider']))
320
					$ppp['provider'] = $_POST['provider'];
321
				else
322
					unset($ppp['provider']);
323
				handle_pppoe_reset();
324
				break;
325
			case "pptp":
326
				$ppp['localip'] = $_POST['localip'];
327
				$ppp['subnet'] = $_POST['subnet'];
328
				$ppp['gateway'] = $_POST['gateway'];
329
				break;
330
			default:
331
				break;
332
			
333
		}
334
		/* reset cron items if necessary */
335
		if (empty($_POST['pppoe_preset'])) {
336
			/* test whether a cron item exists and unset() it if necessary */
337
			$itemhash = getMPDCRONSettings();
338
			$item = $itemhash['ITEM'];
339
			if (isset($item))
340
				unset($config['cron']['item'][$itemhash['ID']]); 
341
		}
342
		$ppp['shortseq'] = $_POST['shortseq'] ? true : false;
343
		$ppp['acfcomp'] = $_POST['acfcomp'] ? true : false;
344
		$ppp['protocomp'] = $_POST['protocomp'] ? true : false;
345
		$ppp['vjcomp'] = $_POST['vjcomp'] ? true : false;
346
		$ppp['tcpmssfix'] = $_POST['tcpmssfix'] ? true : false;
347
		if (isset($_POST['bandwidth']))
348
			$ppp['bandwidth'] = $_POST['bandwidth'];
349
		else 
350
			unset($ppp['bandwidth']);
351
		if (isset($_POST['mtu']))
352
			$ppp['mtu'] = $_POST['mtu'];
353
		else 
354
			unset($ppp['mtu']);
355
		if (isset($_POST['mru']))
356
			$ppp['mru'] = $_POST['mru'];
357
		else 
358
			unset($ppp['mru']);
359
			
360
			
361
        $iflist = get_configured_interface_list();
362
        /*
363
        foreach ($iflist as $if) {
364
        	if ($config['interfaces'][$if]['if'] == basename($a_ppps[$id]['port']))
365
				$config['interfaces'][$if]['if'] = basename($ppp['port']);
366
		}
367
		*/
368
		if (isset($id) && $a_ppps[$id])
369
			$a_ppps[$id] = $ppp;
370
		else
371
			$a_ppps[] = $ppp;
372

    
373
		write_config();
374

    
375
		header("Location: interfaces_mlppp.php");
376
		exit;
377
	}
378
} // end if($_POST)
379

    
380
function handle_pppoe_reset() {
381
	global $_POST, $config, $g, $ppp, $if;
382
	/* perform a periodic reset? */
383
	if(!isset($_POST['pppoe_preset'])) {
384
		setup_pppoe_reset_file($if, false);		
385
		return;
386
	}
387
	if (!is_array($config['cron']['item'])) 
388
		$config['cron']['item'] = array(); 
389
	$itemhash = getMPDCRONSettings();
390
	$item = $itemhash['ITEM'];
391
	if (empty($item)) 
392
		$item = array();
393
	if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] == "custom") {
394
		$ppp['pppoe-reset-type'] = "custom";
395
		$pconfig['pppoe_pr_custom'] = true;
396
		$item['minute'] = $_POST['pppoe_resetminute'];
397
		$item['hour'] = $_POST['pppoe_resethour'];
398
		if (isset($_POST['pppoe_resetdate']) && $_POST['pppoe_resetdate'] <> "" && strlen($_POST['pppoe_resetdate']) == 10) {
399
			$date = explode("/", $_POST['pppoe_resetdate']);
400
			$item['mday'] = $date[1];
401
			$item['month'] = $date[0];
402
		} else {
403
			$item['mday'] = "*";
404
			$item['month'] = "*";
405
		}
406
		$item['wday'] = "*";
407
		$item['who'] = "root";
408
		$item['command'] = CRON_PPPOE_CMD_FILE;
409
	} else if (isset($_POST['pppoe_pr_type']) && $_POST['pppoe_pr_type'] = "preset") {
410
		$ppp['pppoe-reset-type'] = "preset";
411
		$pconfig['pppoe_pr_preset'] = true;
412
		switch ($_POST['pppoe_pr_preset_val']) {
413
			case "monthly":
414
				$item['minute'] = "0";
415
				$item['hour'] = "0";
416
				$item['mday'] = "1";
417
				$item['month'] = "*";
418
				$item['wday'] = "*";
419
				$item['who'] = "root";
420
				$item['command'] = CRON_PPPOE_CMD_FILE;
421
				break;
422
	        case "weekly":
423
				$item['minute'] = "0";
424
				$item['hour'] = "0";
425
				$item['mday'] = "*";
426
				$item['month'] = "*";
427
				$item['wday'] = "0";
428
				$item['who'] = "root";
429
				$item['command'] = CRON_PPPOE_CMD_FILE;
430
				break;
431
			case "daily":
432
				$item['minute'] = "0";
433
				$item['hour'] = "0";
434
				$item['mday'] = "*";
435
				$item['month'] = "*";
436
				$item['wday'] = "*";
437
				$item['who'] = "root";
438
				$item['command'] = CRON_PPPOE_CMD_FILE;
439
				break;
440
			case "hourly":
441
				$item['minute'] = "0";
442
				$item['hour'] = "*";
443
				$item['mday'] = "*";
444
				$item['month'] = "*";
445
				$item['wday'] = "*";
446
				$item['who'] = "root";
447
				$item['command'] = CRON_PPPOE_CMD_FILE;
448
				break;
449
		} // end switch
450
	} // end if
451
	if (isset($itemhash['ID'])) 
452
		$config['cron']['item'][$itemhash['ID']] = $item;
453
	else 
454
		$config['cron']['item'][] = $item;
455
	/* finally install the pppoerestart file */
456
	if (isset($_POST['pppoe_preset'])) {
457
		setup_pppoe_reset_file($if, true);
458
		//$ppp['pppoe_reset'] = true;
459
		$ppp['pppoe_preset'] = true;
460
		sigkillbypid("{$g['varrun_path']}/cron.pid", "HUP");
461
	} else {
462
		//unset($ppp['pppoe_reset']);
463
		unset($ppp['pppoe_preset']);		
464
		setup_pppoe_reset_file($if, false);	
465
	}
466
}
467

    
468
$closehead = false;
469
$pgtitle = array("Interfaces","MLPPP","Edit");
470
include("head.inc");
471

    
472
$types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" => "PPTP"/*,  "l2tp" => "L2TP", "tcp" => "TCP", "udp" => "UDP", "ng" => "Netgraph" */  ); 
473

    
474
?>
475

    
476
<script type="text/javascript">
477
	function update_select_list(new_options, select_list){
478
		var option_array = new_options.split("|");
479
		select_list.options.length = 0;
480
		for(var j=0; j < option_array.length-1; j++){
481
			var option = option_array[j].split(",");
482
			var selected = Boolean(parseInt(option[2]));
483
			select_list.options[j] = new Option(option[0], option[1], false, selected);
484
			//this line for debugging the javascript above
485
			//select_list.options[option_array.length-1+j] = new Option(option[2].toString() +" "+ selected.toString());
486
		}
487
	}
488
	
489
	function show_bandwidth_input() {
490
		var bboxes = $('bandwidth_input').innerHTML;
491
		$('bandwidth_input').show();
492
	}
493
	
494
	function updateType(t){
495
		var serialports = $('serialports').innerHTML;
496
		var ports = $('ports').innerHTML;
497
		var select_list = document.iform["interfaces[]"];
498
		switch(t) {
499
			case "select": {
500
				$('ppp','pppoe','pptp','ipfields','prefil_ppp').invoke('hide');
501
				select_list.options.length = 0;
502
				select_list.options[0] = new Option("Select Link Type First","");
503
				break;
504
			}
505
			case "ppp": {
506
				update_select_list(serialports, select_list);
507
				$('select','pppoe','pptp','subnet').invoke('hide');
508
				$('ipfields','prefil_ppp').invoke('show');
509
				
510
				break;
511
			}
512
			case "pppoe": {
513
				update_select_list(ports, select_list);
514
				$('select','ppp','pptp','ipfields','prefil_ppp').invoke('hide');
515
				break;
516
			}
517
			case "pptp": {
518
				update_select_list(ports, select_list);
519
				$('select','ppp','pppoe','prefil_ppp').invoke('hide');
520
				$('ipfields','subnet').invoke('show');
521
				break;
522
			}
523
			default:
524
				select_list.options.length = 0;
525
				break;
526
		}
527
		$(t).show();
528
	}
529
	
530
	function show_more_settings(obj,element_id) {
531
		if (obj.checked)
532
			$(element_id).show();
533
		else
534
			$(element_id).hide();
535
	}
536
	
537
	function prefill_att() {
538
		$('initstr').value = "Q0V1E1S0=0&C1&D2+FCLASS=0";
539
		$('apn').value = "ISP.CINGULAR";
540
		$('apnum').value = "1";
541
		$('phone').value = "*99#";
542
		$('username').value = "att";
543
		$('password').value = "att";
544
	}
545
	function prefill_sprint() {
546
		$('initstr').value = "E1Q0";
547
		$('apn').value = "";
548
		$('apnum').value = "";
549
		$('phone').value = "#777";
550
		$('username').value = "sprint";
551
		$('password').value = "sprint";
552
	}
553
	function prefill_vzw() {
554
		$('initstr').value = "E1Q0s7=60";
555
		$('apn').value = "";
556
		$('apnum').value = "";
557
		$('phone').value = "#777";
558
		$('username').value = "123@vzw3g.com";
559
		$('password').value = "vzw";
560
	}
561
	document.observe("dom:loaded", function() { updateType(<?php echo "'{$pconfig['type']}'";?>); });
562
</script>
563
</head>
564
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
565
<?php include("fbegin.inc"); ?>
566
<?php if ($input_errors) print_input_errors($input_errors); ?>
567
	<form action="interfaces_mlppp_edit.php" method="post" name="iform" id="iform">
568
	  <table id="interfacetable" width="100%" border="0" cellpadding="6" cellspacing="0">
569
		<tr>
570
			<td colspan="2" valign="top" class="listtopic">MLPPP configuration</td>
571
		</tr>
572
		<tr>
573
			<td valign="middle" class="vncell"><strong>Link Type</strong></td>
574
			<td class="vtable"> 
575
				<select name="type" onChange="updateType(this.value);"  class="formselect" id="type">
576
				<?php 
577
					foreach ($types as $key => $opt) { 
578
						echo "<option onClick=\"updateType('{$key}');\"";
579
						if ($key == $pconfig['type']) 
580
							echo " selected";
581
						echo " value=\"{$key}\" >" . htmlspecialchars($opt) . "</option>";
582
					} 
583
				?>
584
				</select>
585
			</td>
586
		</tr>
587
		<tr name="interface" id="interface" >
588
			<td width="22%" valign="top" class="vncellreq">Link interface(s)</td>
589
			<td width="78%" class="vtable">
590
				<select name="interfaces[]" multiple="true" class="formselect" size="4">
591
					<option></option>
592
				</select>
593
				<br/><span class="vexpl">Interfaces or ports participating in the multilink connection.</span>
594
				<span id="prefil_ppp">
595
				<p/>Click a link to fill in defaults for these carriers:&nbsp;
596
				<a href='#' onClick='javascript:prefill_att();'>ATT</A>
597
				<a href='#' onClick='javascript:prefill_sprint();'>Sprint</A>
598
				<a href='#' onClick='javascript:prefill_vzw();'>Verizon</A>
599
				</span>
600
			</td>
601
		</tr>
602
		<tr style="display:none" name="portlists" id="portlists">
603
			<td id="serialports"><?php
604
					$selected_ports = explode(",",$pconfig['interfaces']);
605
					$serial = glob("/dev/cua*");
606
					$modems = glob("/dev/modem*");
607
					$serialports = array_merge($serial, $modems);
608
					foreach ($serialports as $port) {
609
						if(preg_match("/\.(lock|init)$/", $port))
610
							continue;
611
						echo $port.",".trim($port);
612
						if (in_array($port,$selected_ports))
613
							echo ",1|";
614
						else
615
							echo ",|";
616
					}
617
			?></td>
618
			<td id="ports"><?php
619
					foreach ($portlist as $ifn => $ifinfo){
620
					//if (is_jumbo_capable($ifn)) {
621
						echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")") . ",{$ifn}";
622
						//echo "\"{$ifn}\"";
623
						if (stristr($pconfig['interfaces'], $ifn))
624
							echo ",1|";
625
						else
626
							echo ",|";
627
					}
628
			?></td>
629
		</tr>
630
		<tr>
631
			<td width="22%" valign="top" class="vncell">Username</td>
632
			<td width="78%" class="vtable">
633
			<input name="username" type="text" class="formfld usr" id="username" size="20" value="<?=htmlspecialchars($pconfig['username']);?>">
634
			</td>
635
		</tr>
636
		<tr>
637
			<td width="22%" valign="top" class="vncell">Password</td>
638
			<td width="78%" class="vtable">
639
			<input name="password" type="password" class="formfld pwd" id="password" size="20" value="<?=htmlspecialchars($pconfig['password']);?>">
640
			</td>
641
		</tr>
642
		<tr>
643
			<td width="22%" valign="top" class="vncell">Gateway</td>
644
			<td width="78%" class="vtable">
645
				<input type="checkbox" value="on" id="defaultgw" name="defaultgw" <?php if (isset($pconfig['defaultgw'])) echo "checked"; ?>>This link will be used as the default gateway.
646
			</td>
647
		</tr>
648
		<tr>
649
		<td valign="top" class="vncell">Dial On Demand</td>
650
			<td class="vtable">
651
				<input type="checkbox" value="on" id="ondemand" name="ondemand" <?php if (isset($pconfig['ondemand'])) echo "checked"; ?>> Enable Dial-on-Demand mode
652
				<br/> <span class="vexpl">This option causes the interface to operate in dial-on-demand mode, allowing you to have a virtual full time connection. 
653
				The interface is configured, but the actual connection of the link is delayed until qualifying outgoing traffic is detected. </span>
654
			</td>
655
		</tr>
656
		<tr>
657
			<td valign="top" class="vncell">Idle Timeout</td>
658
			<td class="vtable">
659
				<input name="idletimeout" type="text" class="formfld unknown" id="idletimeout" size="6" value="<?=htmlspecialchars($pconfig['idletimeout']);?>"> seconds
660
				<br/> <span class="vexpl">Sets the idle timeout value for the bundle. If no incoming or outgoing packets are transmitted for the set number of seconds 
661
				the connection is brought down. An idle timeout of zero disables this feature. <bold>Default is 0.</bold>
662
				<br/>When the idle timeout occurs, if the dial-on-demand option is enabled, mpd goes back into dial-on-demand mode. Otherwise, the interface is brought down and all associated routes removed.</span>
663
			</td>
664
		</tr>
665
		<tr>
666
		<td valign="top" class="vncell">Uptime Logging</td>
667
			<td class="vtable">
668
				<input type="checkbox" value="on" id="uptime" name="uptime" <?php if (isset($pconfig['uptime'])) echo "checked"; ?>> Enable persistent logging of connection uptime.
669
				<br/> <span class="vexpl">This option causes cumulative uptime to be recorded and displayed on the Status Interfaces page.</span>
670
			</td>
671
		</tr>
672
		<tr>
673
			<td width="22%" valign="top" class="vncell">Description</td>
674
			<td width="78%" class="vtable">
675
				<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
676
				<br/> <span class="vexpl">You may enter a description here for your reference (not parsed).</span>
677
			</td>
678
		</tr>
679
		<tr>
680
			<td colspan="2" valign="top" height="16"></td>
681
		</tr>
682
		<tr style="display:none" name="select" id="select">
683
		</tr>
684
		<tr style="display:none" name="ppp" id="ppp">
685
			<td colspan="2" style="padding:0px;">
686
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
687
					<tr>
688
						<td colspan="2" valign="top" class="listtopic">PPP configuration</td>
689
					</tr>
690
					<tr>
691
						<td width="22%" valign="top" class="vncell">Init String</td>
692
						<td width="78%" class="vtable">
693
							<input type="text" size="40" class="formfld unknown" id="initstr" name="initstr" value="<?=htmlspecialchars($pconfig['initstr']);?>">
694
							<br/><span class="vexpl">Note: Enter the modem initialization string here. Do NOT include the "AT" string at the beginning of the command. Many modern USB 3G
695
							modems don't need an initialization string.</span>
696
						</td>
697
					</tr>
698
					<tr>
699
					  <td width="22%" valign="top" class="vncell">Sim PIN</td>
700
					  <td width="78%" class="vtable">
701
						<input name="simpin" type="text" class="formfld unknown" id="simpin" size="12" value="<?=htmlspecialchars($pconfig['simpin']);?>">
702
					</td>
703
					</tr>
704
					<tr>
705
					  <td width="22%" valign="top" class="vncell">Sim PIN wait</td>
706
					  <td width="78%" class="vtable">
707
						<input name="pin-wait" type="text" class="formfld unknown" id="pin-wait" size="2" value="<?=htmlspecialchars($pconfig['pin-wait']);?>">
708
						<br/><span class="vexpl">Note: Time to wait for SIM to discover network after PIN is sent to SIM (seconds).</span>
709
					</td>
710
					</tr>
711
					<tr>
712
					  <td width="22%" valign="top" class="vncell">Access Point Name (APN)</td>
713
					  <td width="78%" class="vtable">
714
						<input name="apn" type="text" class="formfld unknown" id="apn" size="40" value="<?=htmlspecialchars($pconfig['apn']);?>">
715
					</td>
716
					</tr>
717
					<tr>
718
					  <td width="22%" valign="top" class="vncell">APN number (optional)</td>
719
					  <td width="78%" class="vtable">
720
						<input name="apnum" type="text" class="formfld unknown" id="apnum" size="2" value="<?=htmlspecialchars($pconfig['apnum']);?>">
721
						<br/><span class="vexpl">Note: Defaults to 1 if you set APN above. Ignored if you set no APN above.</span>
722
					</td>
723
					</tr>
724
					<tr>
725
					  <td width="22%" valign="top" class="vncell">Phone Number</td>
726
					  <td width="78%" class="vtable">
727
						<input name="phone" type="text" class="formfld unknown" id="phone" size="40" value="<?=htmlspecialchars($pconfig['phone']);?>">
728
						<br/><span class="vexpl">Note: Typically (*99# or *99***# or *99***1#) for GSM networks and *777 for CDMA networks</span>
729
					  </td>
730
					</tr>
731
					<tr>
732
						<td width="22%" valign="top" class="vncell">Connection Timeout</td>
733
						<td width="78%" class="vtable">
734
							<input name="connect-timeout" type="text" class="formfld unknown" id="connect-timeout" size="2" value="<?=htmlspecialchars($pconfig['connect-timeout']);?>">
735
							<br/><span class="vexpl">Note: Enter timeout in seconds for connection to be established (sec.) Default is 45 sec.</span>
736
						</td>
737
					</tr>
738
				</table>
739
			</td>
740
		</tr>
741
		<tr style="display:none" name="pppoe" id="pppoe">
742
			<td colspan="2" style="padding:0px;">
743
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
744
					<tr>
745
						<td colspan="2" valign="top" class="listtopic">PPPoE configuration</td>
746
					</tr>
747
					<tr>
748
						<td width="22%" valign="top" class="vncell">Service name</td>
749
						<td width="78%" class="vtable"><input name="provider" type="text" class="formfld unknown" id="provider" size="20" value="<?=htmlspecialchars($pconfig['provider']);?>">
750
							<br/> <span class="vexpl">Hint: this field can usually be left empty</span>
751
						</td>
752
					</tr>
753
					<tr>
754
						<td width="22%" valign="top" class="vncell"><?=gettext("Periodic reset");?></td>
755
						<td width="78%" class="vtable">
756
							<input name="pppoe_preset" type="checkbox" id="pppoe_preset" value="yes" <?php if ($pconfig['pppoe_preset']) echo "checked"; ?> onclick="show_more_settings(this,presetwrap);" />
757
							<?= gettext("enable periodic PPPoE resets"); ?>
758
							<br />
759
							<?php if ($pconfig['pppoe_preset']): ?>
760
							<table id="presetwrap" cellspacing="0" cellpadding="0" width="100%">
761
							<?php else: ?>
762
							<table id="presetwrap" cellspacing="0" cellpadding="0" width="100%" style="display: none;">
763
								<?php endif; ?>
764
								<tr>
765
									<td align="left" valign="top">
766
										<p style="margin: 4px; padding: 4px 0 4px 0; width: 94%;">
767
											<input name="pppoe_pr_type" type="radio" id="pppoe_pr_custom" value="custom" <?php if ($pconfig['pppoe_pr_custom']) echo "checked=\"checked\""; ?> onclick="if (this.checked) { Effect.Appear('pppoecustomwrap', { duration: 0.0 }); Effect.Fade('pppoepresetwrap', { duration: 0.0 }); }" /> 
768
												<?= gettext("provide a custom reset time"); ?>
769
												<br />
770
												<input name="pppoe_pr_type" type="radio" id="pppoe_pr_preset" value="preset" <?php if ($pconfig['pppoe_pr_preset']) echo "checked=\"checked\""; ?> onclick="if (this.checked) { Effect.Appear('pppoepresetwrap', { duration: 0.0 }); Effect.Fade('pppoecustomwrap', { duration: 0.0 }); }" /> 
771
													<?= gettext("select reset time from a preset"); ?>
772
												</p>
773
												<?php if ($pconfig['pppoe_pr_custom']): ?>
774
													<p style="margin: 2px; padding: 4px; width: 94%;" id="pppoecustomwrap">
775
													<?php else: ?>
776
														<p style="margin: 2px; padding: 4px; width: 94%; display: none;" id="pppoecustomwrap">
777
														<?php endif; ?>
778
														<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" /> 
779
														<?= gettext("hour (0-23)"); ?><br />
780
														<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" /> 
781
														<?= gettext("minute (0-59)"); ?><br />
782
														<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']);?>" /> 
783
														<?= gettext("reset at a specific date (mm/dd/yyyy)"); ?>
784
														<br />&nbsp;<br />
785
														<span class="red"><strong>Note: </strong></span>
786
														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.
787
													</p>
788
													<?php if ($pconfig['pppoe_pr_preset']): ?>
789
														<p style="margin: 2px; padding: 4px; width: 94%;" id="pppoepresetwrap">
790
														<?php else: ?>
791
															<p style="margin: 2px; padding: 4px; width: 94%; display: none;" id="pppoepresetwrap">
792
															<?php endif; ?>
793
															<input name="pppoe_pr_preset_val" type="radio" id="pppoe_monthly" value="monthly" <?php if ($pconfig['pppoe_monthly']) echo "checked=\"checked\""; ?> /> 
794
															<?= gettext("reset at each month ('0 0 1 * *')"); ?>
795
															<br />
796
															<input name="pppoe_pr_preset_val" type="radio" id="pppoe_weekly" value="weekly" <?php if ($pconfig['pppoe_weekly']) echo "checked=\"checked\""; ?> /> 
797
															<?= gettext("reset at each week ('0 0 * * 0')"); ?>
798
															<br />
799
															<input name="pppoe_pr_preset_val" type="radio" id="pppoe_daily" value="daily" <?php if ($pconfig['pppoe_daily']) echo "checked=\"checked\""; ?> /> 
800
															<?= gettext("reset at each day ('0 0 * * *')"); ?>
801
															<br />
802
															<input name="pppoe_pr_preset_val" type="radio" id="pppoe_hourly" value="hourly" <?php if ($pconfig['pppoe_hourly']) echo "checked=\"checked\""; ?> /> 
803
															<?= gettext("reset at each hour ('0 * * * *')"); ?>
804
											</p>
805
									</td>
806
								</tr>
807
							</table>
808
						</td>
809
					</tr>
810
				</table>
811
			</td>
812
		</tr>
813
		<tr style="display:none" name="pptp" id="pptp">
814
			<td colspan="2" style="padding:0px;">
815
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
816
					<tr>
817
						<td colspan="2" valign="top" class="listtopic">PPTP configuration</td>
818
					</tr>
819
				</table>
820
			</td>
821
		</tr>
822
		<tr style="display:none" id="ipfields">
823
			<td colspan="2" style="padding:0px;">
824
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
825
					<tr>
826
						<td width="22%" valign="top" class="vncell">Local IP address</td>
827
						<td width="78%" class="vtable"> 
828
							<input name="localip" type="text" class="formfld unknown" id="localip" size="20"  value="<?=htmlspecialchars($pconfig['localip']);?>">
829
							/
830
							<select style="display:none" name="subnet" class="formselect" id="subnet">
831
							<?php for ($i = 31; $i > 0; $i--): ?>
832
								<option value="<?=$i;?>"<?php if ($i == $pconfig['subnet']) echo "selected"; ?>><?=$i;?></option>
833
							<?php endfor; ?>
834
							</select>
835
							<br><span class="vexpl">Note: Local IP/subnet is required for PPTP connections. LocalIP is automatically assigned for PPP links if this field is empty.</span>
836
						</td>
837
					</tr>
838
					<tr>
839
						<td width="22%" valign="top" class="vncell">Remote IP (Gateway)</td>
840
						<td width="78%" class="vtable">
841
							<input name="gateway" type="text" class="formfld unknown" id="gateway" size="20" value="<?=htmlspecialchars($pconfig['gateway']);?>">
842
							<br><span class="vexpl">Note: This is where the packets will be routed. Remote IP is required for PPTP connections. Remote IP is automatically assigned for PPP links if this field is empty.</span>
843
						</td>
844
					</tr>
845
				</table>
846
			</td>
847
		<tr>
848
			<td colspan="2" valign="top" height="16"></td>
849
		</tr>
850
		<tr>
851
			<td colspan="2" valign="top" class="listtopic">Advanced Options</td>
852
		</tr>
853
		<tr>
854
			<td width="22%" width="100" valign="top" class="vncell">Bandwidth</td>
855
			<td width="78%" class="vtable">
856
			<input name="bandwidths" type="checkbox" id="bandwidths" value="yes" <?php if (isset($pconfig['bandwidth'])) echo "checked"; ?> onclick="show_more_settings(this,bandwidth_input);" />
857
			Set bandwidths for links in multilink connections.
858
			<span style="display:none" id="bandwidth_input"><br/><input name="bandwidth" type="text" class="formfld unknown" id="bandwidth" size="40" value="<?=htmlspecialchars($pconfig['bandwidth']);?>">
859
			<br/> <span class="vexpl">Set Bandwidth for each link ONLY when links have different bandwidths.</span>
860
			</span>
861
		  </td>
862
		</tr>
863
		<tr>
864
		  <td width="22%" width="100" valign="top" class="vncell">Link MTU</td>
865
		  <td width="78%" class="vtable">
866
			<input name="mtu" type="text" class="formfld unknown" id="mtu" size="6" value="<?=htmlspecialchars($pconfig['mtu']);?>">
867
			<br> <span class="vexpl">Set MTU for each link if links have different bandwidths, otherwise, leave blank.</span>
868
		  </td>
869
		</tr>
870
		<tr>
871
		  <td width="22%" width="100" valign="top" class="vncell">Link MRU</td>
872
		  <td width="78%" class="vtable">
873
			<input name="mru" type="text" class="formfld unknown" id="mru" size="6" value="<?=htmlspecialchars($pconfig['mru']);?>">
874
			<br> <span class="vexpl">Set MRU for each link separated by commas, otherwise, leave blank.</span>
875
		  </td>
876
		</tr>
877
		<tr>
878
			<td width="22%" valign="top" class="vncell">Compression</td>
879
			<td width="78%" class="vtable">
880
				<input type="checkbox" value="on" id="vjcomp" name="vjcomp" <?php if (isset($pconfig['vjcomp'])) echo "checked"; ?>>&nbsp;Enable vjcomp(compression).
881
				<br/> <span class="vexpl">This option enables Van Jacobson TCP header compression, which saves several bytes per TCP data packet. 
882
				You almost always want this option. This compression ineffective for TCP connections with enabled modern extensions like time 
883
				stamping or SACK, which modify TCP options between sequential packets.</span>
884
			</td>
885
		</tr>
886
		<tr>
887
			<td width="22%" valign="top" class="vncell">TCPmssFix</td>
888
			<td width="78%" class="vtable">
889
				<input type="checkbox" value="on" id="tcpmssfix" name="tcpmssfix" <?php if (isset($pconfig['tcpmssfix'])) echo "checked"; ?>>&nbsp;Enable tcpmssfix.
890
				<br/> <span class="vexpl">This option causes mpd to adjust incoming and outgoing TCP SYN segments so that the requested maximum segment size is not greater than the amount 
891
				allowed by the interface MTU. This is necessary in many setups to avoid problems caused by routers that drop ICMP Datagram Too Big messages. Without these messages,
892
				the originating machine sends data, it passes the rogue router then hits a machine that has an MTU that is not big enough for the data. Because the IP Don't Fragment option is set,
893
				this machine sends an ICMP Datagram Too Big message back to the originator and drops the packet. The rogue router drops the ICMP message and the originator never 
894
				gets to discover that it must reduce the fragment size or drop the IP Don't Fragment option from its outgoing data.</span>
895
			</td>
896
		</tr>
897
		<tr>
898
			<td width="22%" valign="top" class="vncell">ShortSeq</td>
899
			<td width="78%" class="vtable">
900
				<input type="checkbox" value="on" id="shortseq" name="shortseq" <?php if (isset($pconfig['shortseq'])) echo "checked"; ?>>&nbsp;Enable shortseq.
901
				<br/> <span class="vexpl">This option is only meaningful if multi-link PPP is negotiated. It proscribes shorter multi-link fragment headers, saving two bytes on every frame.</span>
902
			</td>
903
		</tr>
904
		<tr>
905
			<td width="22%" valign="top" class="vncell">ACFComp</td>
906
			<td width="78%" class="vtable">
907
				<input type="checkbox" value="on" id="acfcomp" name="acfcomp" <?php if (isset($pconfig['acfcomp'])) echo "checked"; ?>>&nbsp;Enable acfcomp.
908
				<br/> <span class="vexpl">Address and control field compression. This option only applies to asynchronous link types. It saves two bytes per frame.</span>
909
			</td>
910
		</tr>
911
		<tr>
912
			<td width="22%" valign="top" class="vncell">ProtoComp</td>
913
			<td width="78%" class="vtable">
914
				<input type="checkbox" value="on" id="protocomp" name="protocomp" <?php if (isset($pconfig['protocomp'])) echo "checked"; ?>>&nbsp;Enable protocomp(compression).
915
				<br/> <span class="vexpl">Protocol field compression. This option saves one byte per frame for most frames.</span>
916
			</td>
917
		</tr>
918
		<tr>
919
			<td width="22%" valign="top">&nbsp;</td>
920
			<td width="78%">
921
				<input name="Submit" type="submit" class="formbtn" value="Save">
922
				<input type="button" value="Cancel" onclick="history.back()">
923
				<?php if (isset($id) && $a_ppps[$id]): ?>
924
					<input name="id" type="hidden" value="<?=$id;?>">
925
				<?php endif; ?>
926
			</td>
927
		</tr>
928
	</table>
929
</form>
930
<?php include("fend.inc"); ?>
931
</body>
932
</html>
(91-91/218)