From 114990f43aa99a70482809cfe79ed97f60a81918 Mon Sep 17 00:00:00 2001 From: gnhb Date: Fri, 28 May 2010 22:05:40 +0700 Subject: Fixed problems in javascript and added L2TP support to GUI. --- usr/local/www/interfaces_ppps_edit.php | 159 +++++++++++---------- .../javascript/interfaces_ppps_edit/ppps_edit.js | 39 ++--- 2 files changed, 105 insertions(+), 93 deletions(-) (limited to 'usr') diff --git a/usr/local/www/interfaces_ppps_edit.php b/usr/local/www/interfaces_ppps_edit.php index b004bd4..17624f9 100644 --- a/usr/local/www/interfaces_ppps_edit.php +++ b/usr/local/www/interfaces_ppps_edit.php @@ -99,66 +99,70 @@ if (isset($id) && $a_ppps[$id]) { $pconfig['vjcomp'] = true; if (isset($a_ppps[$id]['tcpmssfix'])) $pconfig['tcpmssfix'] = true; - if ($a_ppps[$id]['type'] == "ppp") { - $pconfig['initstr'] = base64_decode($a_ppps[$id]['initstr']); - $pconfig['simpin'] = $a_ppps[$id]['simpin']; - $pconfig['pin-wait'] = $a_ppps[$id]['pin-wait']; - $pconfig['apn'] = $a_ppps[$id]['apn']; - $pconfig['apnum'] = $a_ppps[$id]['apnum']; - $pconfig['phone'] = $a_ppps[$id]['phone']; - $pconfig['connect-timeout'] = $a_ppps[$id]['connect-timeout']; - $pconfig['localip'] = explode(",",$a_ppps[$id]['localip']); - $pconfig['gateway'] = explode(",",$a_ppps[$id]['gateway']); - } - if ($a_ppps[$id]['type'] == "pptp") { - $pconfig['localip'] = explode(",",$a_ppps[$id]['localip']); - $pconfig['subnet'] = explode(",",$a_ppps[$id]['subnet']); - $pconfig['gateway'] = explode(",",$a_ppps[$id]['gateway']); - } - if ($a_ppps[$id]['type'] == "pppoe") { - $pconfig['provider'] = $a_ppps[$id]['provider']; - /* ================================================ */ - /* = force a connection reset at a specific time? = */ - /* ================================================ */ - - if (isset($a_ppps[$id]['pppoe-reset-type'])) { - $pconfig['pppoe-reset-type'] = $a_ppps[$id]['pppoe-reset-type']; - $itemhash = getMPDCRONSettings($a_ppps[$id]['ptpid']); - $cronitem = $itemhash['ITEM']; - if (isset($cronitem)) { - $resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}"; - } else { - $resetTime = NULL; - } + switch($a_ppps[$id]['type']) { + case "ppp": + $pconfig['initstr'] = base64_decode($a_ppps[$id]['initstr']); + $pconfig['simpin'] = $a_ppps[$id]['simpin']; + $pconfig['pin-wait'] = $a_ppps[$id]['pin-wait']; + $pconfig['apn'] = $a_ppps[$id]['apn']; + $pconfig['apnum'] = $a_ppps[$id]['apnum']; + $pconfig['phone'] = $a_ppps[$id]['phone']; + $pconfig['connect-timeout'] = $a_ppps[$id]['connect-timeout']; + $pconfig['localip'] = explode(",",$a_ppps[$id]['localip']); + $pconfig['gateway'] = explode(",",$a_ppps[$id]['gateway']); + break; + case "pptp": + $pconfig['localip'] = explode(",",$a_ppps[$id]['localip']); + $pconfig['subnet'] = explode(",",$a_ppps[$id]['subnet']); + $pconfig['gateway'] = explode(",",$a_ppps[$id]['gateway']); + if (isset($a_ppps[$id]['dhcp'])) + $pconfig['pptp_dhcp'] = true; + break; + case "pppoe": + $pconfig['provider'] = $a_ppps[$id]['provider']; + /* ================================================ */ + /* = force a connection reset at a specific time? = */ + /* ================================================ */ - if ($a_ppps[$id]['pppoe-reset-type'] == "custom") { - $resetTime_a = split(" ", $resetTime); - $pconfig['pppoe_pr_custom'] = true; - $pconfig['pppoe_resetminute'] = $resetTime_a[0]; - $pconfig['pppoe_resethour'] = $resetTime_a[1]; - /* just initialize $pconfig['pppoe_resetdate'] if the - * coresponding item contains appropriate numeric values. - */ - if ($resetTime_a[2] <> "*" && $resetTime_a[3] <> "*") - $pconfig['pppoe_resetdate'] = "{$resetTime_a[3]}/{$resetTime_a[2]}/" . date("Y"); - } else if ($a_ppps[$id]['pppoe-reset-type'] == "preset") { - $pconfig['pppoe_pr_preset'] = true; - switch ($resetTime) { - case CRON_MONTHLY_PATTERN: - $pconfig['pppoe_monthly'] = true; - break; - case CRON_WEEKLY_PATTERN: - $pconfig['pppoe_weekly'] = true; - break; - case CRON_DAILY_PATTERN: - $pconfig['pppoe_daily'] = true; - break; - case CRON_HOURLY_PATTERN: - $pconfig['pppoe_hourly'] = true; - break; + if (isset($a_ppps[$id]['pppoe-reset-type'])) { + $pconfig['pppoe-reset-type'] = $a_ppps[$id]['pppoe-reset-type']; + $itemhash = getMPDCRONSettings($a_ppps[$id]['ptpid']); + $cronitem = $itemhash['ITEM']; + if (isset($cronitem)) { + $resetTime = "{$cronitem['minute']} {$cronitem['hour']} {$cronitem['mday']} {$cronitem['month']} {$cronitem['wday']}"; + } else { + $resetTime = NULL; + } + + if ($a_ppps[$id]['pppoe-reset-type'] == "custom") { + $resetTime_a = split(" ", $resetTime); + $pconfig['pppoe_pr_custom'] = true; + $pconfig['pppoe_resetminute'] = $resetTime_a[0]; + $pconfig['pppoe_resethour'] = $resetTime_a[1]; + /* just initialize $pconfig['pppoe_resetdate'] if the + * coresponding item contains appropriate numeric values. + */ + if ($resetTime_a[2] <> "*" && $resetTime_a[3] <> "*") + $pconfig['pppoe_resetdate'] = "{$resetTime_a[3]}/{$resetTime_a[2]}/" . date("Y"); + } else if ($a_ppps[$id]['pppoe-reset-type'] == "preset") { + $pconfig['pppoe_pr_preset'] = true; + switch ($resetTime) { + case CRON_MONTHLY_PATTERN: + $pconfig['pppoe_monthly'] = true; + break; + case CRON_WEEKLY_PATTERN: + $pconfig['pppoe_weekly'] = true; + break; + case CRON_DAILY_PATTERN: + $pconfig['pppoe_daily'] = true; + break; + case CRON_HOURLY_PATTERN: + $pconfig['pppoe_hourly'] = true; + break; + } } } - } + break; } } @@ -239,12 +243,9 @@ if ($_POST) { foreach($_POST['interfaces'] as $iface){ if ($_POST['localip'][$iface] && !is_ipaddr($_POST['localip'][$iface])) $input_errors[] = "A valid local IP address must be specified for {$iface}."; -/* if (($_POST['subnet'][$iface] && !is_numeric($_POST['subnet'][$iface]))) - $input_errors[] = "A valid PPTP subnet bit count must be specified for {$iface}."; -*/ - if (($_POST['gateway'][$iface] && !is_ipaddr($_POST['gateway'][$iface]))) - $input_errors[] = "A valid gateway (remote IP) address must be specified for {$iface}."; - if (($_POST['bandwidth'][$iface] != "") && !is_numericint($_POST['bandwidth'][$iface])) + if ($_POST['gateway'][$iface] && !is_ipaddr($_POST['gateway'][$iface]) && !is_hostname($_POST['gateway'][$iface])) + $input_errors[] = "A valid gateway IP address OR hostname must be specified for {$iface}."; + if ($_POST['bandwidth'][$iface] && !is_numericint($_POST['bandwidth'][$iface])) $input_errors[] = "The bandwidth value for {$iface} must be an integer."; if ($_POST['mtu'][$iface] && ($_POST['mtu'][$iface] < 576)) $input_errors[] = "The MTU for {$iface} must be greater than 576 bytes."; @@ -338,6 +339,7 @@ if ($_POST) { break; case "pptp": + case "l2tp": foreach($_POST['interfaces'] as $iface){ if (isset($_POST['localip'][$iface])) $localip_array[] = $_POST['localip'][$iface]; @@ -346,6 +348,8 @@ if ($_POST) { if (isset($_POST['subnet'][$iface])) $subnet_array[] = $_POST['subnet'][$iface]; } + + $ppp['dhcp'] = $_POST['pptp_dhcp'] ? true : false; if (count($localip_array)) $ppp['localip'] = implode(',',$localip_array); else @@ -369,12 +373,7 @@ if ($_POST) { $ppp['protocomp'] = $_POST['protocomp'] ? true : false; $ppp['vjcomp'] = $_POST['vjcomp'] ? true : false; $ppp['tcpmssfix'] = $_POST['tcpmssfix'] ? true : false; -/* - $bw_array = array(); - $mtu_array = array(); - $mru_array = array(); - $mrru_array = array(); -*/ + foreach($_POST['interfaces'] as $iface){ if (isset($_POST['bandwidth'][$iface])) $bw_array[] = $_POST['bandwidth'][$iface]; @@ -509,7 +508,7 @@ $closehead = false; $pgtitle = array("Interfaces","PPPs","Edit"); include("head.inc"); -$types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" => "PPTP"/*, "l2tp" => "L2TP", "tcp" => "TCP", "udp" => "UDP"*/ ); +$types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" => "PPTP", "l2tp" => "L2TP"/*, "tcp" => "TCP", "udp" => "UDP"*/ ); ?> @@ -592,6 +591,7 @@ $types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" if($serport_count > $port_count) $port_count=$serport_count; ?> + @@ -767,7 +767,14 @@ $types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" - + + + + +
+ > +
+
@@ -777,11 +784,11 @@ $types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp" - + - +
" id="localiplabel" valign="top" class="vncell"> / - 0; $i--): ?> @@ -790,10 +797,10 @@ $types = array("select" => "Select", "ppp" => "PPP", "pppoe" => "PPPoE", "pptp"
" id="gatewaylabel" valign="top" class="vncell"> - -
+ +
diff --git a/usr/local/www/javascript/interfaces_ppps_edit/ppps_edit.js b/usr/local/www/javascript/interfaces_ppps_edit/ppps_edit.js index 0d441f6..5e8da66 100644 --- a/usr/local/www/javascript/interfaces_ppps_edit/ppps_edit.js +++ b/usr/local/www/javascript/interfaces_ppps_edit/ppps_edit.js @@ -23,11 +23,14 @@ function clear_selected(list_name){ function show_hide_linkfields(options){ var select_count = 0; - for(var j=0; j < options.length; j++){ - var count = select_count.toString(); + var port_count = parseInt($('port_count').innerHTML); + for(var j=0; j < port_count; j++){ + var count = j.toString(); var type = $('type').value; - var label = "link" + count; + var link = "link" + count; + var lnklabel = "linklabel" + count; var bw = "bandwidth" + count; + var bwlabel = "bwlabel" + count; var mtu = "mtu" + count; var mru = "mru" + count; var ipfields = "ipfields" + count; @@ -37,33 +40,32 @@ function show_hide_linkfields(options){ var gateway = "gateway" + count; var gatewaylabel = "gatewaylabel" + count; - $(ipfields,label,subnet).invoke('hide'); + $(ipfields,link).invoke('hide'); $(bw).name = "bandwidth[]"; $(mtu).name = "mtu[]"; $(mru).name = "mru[]"; $(localip).name = "localip[]"; $(subnet).name = "subnet[]"; + $(subnet).disabled = true; $(gateway).name = "gateway[]"; - if (options[j].selected){ - var lnklabel = "linklabel" + count; - var bwlabel = "bwlabel" + count; + if (j < options.length && options[j].selected){ $(lnklabel).innerHTML = "Link Parameters (" + options[j].value + ")"; $(bwlabel).innerHTML = "Bandwidth (" + options[j].value + ")"; $(bw).name = "bandwidth[" + options[j].value + "]"; $(mtu).name = "mtu[" + options[j].value + "]"; $(mru).name = "mru[" + options[j].value + "]"; - if (type == 'pptp' || type == 'ppp'){ - $(localiplabel).innerHTML = "Local IP (" + options[j].value + ")"; - $(gatewaylabel).innerHTML = "Gateway (" + options[j].value + ")"; - $(localip).name = "localip[" + options[j].value + "]"; - $(subnet).name = "subnet[" + options[j].value + "]"; - $(gateway).name = "gateway[" + options[j].value + "]"; - if (type == 'pptp'){ - $(subnet).show(); - } + $(localiplabel).innerHTML = "Local IP (" + options[j].value + ")"; + $(gatewaylabel).innerHTML = "Gateway (" + options[j].value + ")"; + $(localip).name = "localip[" + options[j].value + "]"; + $(subnet).name = "subnet[" + options[j].value + "]"; + $(gateway).name = "gateway[" + options[j].value + "]"; + if (type == 'pptp' || type == 'ppp' || type == 'l2tp'){ $(ipfields).show(); + if (type == 'pptp' || type == 'l2tp'){ + $(subnet).disabled = false; + } } - $(label).show(); + $(link).show(); select_count++; } } @@ -92,6 +94,9 @@ function updateType(t){ $('select','ppp','pptp','prefil_ppp').invoke('hide'); break; } + case "l2tp": { + t = "pptp"; + } case "pptp": { update_select_list(ports, select_list); $('select','ppp','pppoe','prefil_ppp').invoke('hide'); -- cgit v1.1