var basicS=new Object;var scannedSsids=[[],[],[],[],[]];var toggleReload=false;var currentLanIp;var googleDns=["8.8.8.8","8.8.4.4"];var openDns=["208.67.222.222","208.67.220.220"];var openDnsFS=["208.67.222.123","208.67.220.123"];var quad9DNS=["9.9.9.9","149.112.112.112"];var ncDns=["178.32.31.41","106.187.47.17","176.58.118.172"];var onDns=["66.244.95.20","95.211.32.162","95.142.171.235"];var ncTlds=[".bit"];var onTlds=[".glue",".parody",".dyn",".bbs",".free",".fur",".geek",".gopher",".indy",".ing",".null",".oss",".micro"];var wanMacLoc="wan";function saveChanges(){errorList=proofreadAll();if(errorList.length>0){errorString=errorList.join("\n")+"\n\n"+UI.ErrChanges;alert(errorString)}else{var uci=uciOriginal.clone();var uciCompare=uciOriginal.clone();var doReboot=!isBridge(uciOriginal)&&document.getElementById("global_bridge").checked;if(doReboot){setControlsEnabled(false,true,basicS.WaitRb)}else{setControlsEnabled(false,true,UI.WaitSettings)}var preCommands="";if(wifiDevG==""&&wirelessDriver!=""){wifiDevG=wirelessDriver=="broadcom"?"wl0":"radio0";preCommands=preCommands+"uci set wireless."+wifiDevG+"=wifi-device\n";preCommands=preCommands+"uci set wireless."+wifiDevG+".type="+wirelessDriver+"\n";preCommands=preCommands+"uci commit\n";uci.set("wireless",wifiDevG,"","wifi-device");uci.set("wireless",wifiDevG,"type",wirelessDriver);if(wirelessDriver=="mac80211"){uci.set("wireless",wifiDevG,"hwmode","11g")}}var wifiDelIndex=0;var allWirelessInterfaceSections=uci.getAllSectionsOfType("wireless","wifi-iface");for(wifiDelIndex=0;wifiDelIndex0?wirelessIfs[0]:"")}else{uci.set("network","lan","ifname",defaultLanIf)}currentModes=getSelectedValue("wifi_mode");var guestGSelected=wifiGSelected&&(getSelectedValue("wifi_guest_mode")=="dual"||getSelectedValue("wifi_guest_mode")=="24ghz");var guestASelected=wifiASelected&&(getSelectedValue("wifi_guest_mode")=="dual"||getSelectedValue("wifi_guest_mode")=="5ghz");var apcfg="";var ap2cfg="";var apgncfg="";var apgn2cfg="";var othercfg="";if(currentModes.match(/ap/)){var macConflict=[];macConflict.push(currentLanMac,defaultWanMac,currentWanMac,document.getElementById("wan_mac").value);macConflict=macConflict.concat(currentWirelessMacs);if(wifiGSelected){apcfg="ap_g";uci.set("wireless",apcfg,"","wifi-iface");uci.set("wireless",apcfg,"device",wifiDevG);uci.set("wireless",apcfg,"mode","ap");uci.set("wireless",apcfg,"network","lan");uci.set("wireless",apcfg,"disassoc_low_ack","0");preCommands=preCommands+"uci set wireless."+apcfg+"='wifi-iface' \n";if(guestGSelected){apgncfg="ap_gn_g";uci.set("wireless",apgncfg,"","wifi-iface");uci.set("wireless",apgncfg,"device",wifiDevG);uci.set("wireless",apgncfg,"mode","ap");uci.set("wireless",apgncfg,"network","lan");uci.set("wireless",apgncfg,"disassoc_low_ack","0");uci.set("wireless",apgncfg,"is_guest_network","1");if(!distribTarget.match(/ramips/)){var mac=document.getElementById("wifi_guest_mac_g").value;if(mac==""){do{if(distribTarget.match(/mvebu/)){wmacIdx=wirelessIfs.indexOf(wifiDevG.replace("radio","wlan"));ref=currentWirelessMacs[wmacIdx];mac=getRandomMacWithMask(true,true,ref,"fd:ff:ff:ff:ff:f0")}else{mac=getRandomMac(true,true)}}while(macConflict.join(",").toLowerCase().split(",").indexOf(mac.toLowerCase())!=-1)}macConflict.push(mac);uci.set("wireless",apgncfg,"macaddr",mac)}preCommands=preCommands+"uci set wireless."+apgncfg+"='wifi-iface' \n"}}if(wifiASelected){apacfg="ap_a";uci.set("wireless",apacfg,"","wifi-iface");uci.set("wireless",apacfg,"device",wifiDevA);uci.set("wireless",apacfg,"mode","ap");uci.set("wireless",apacfg,"network","lan");uci.set("wireless",apacfg,"disassoc_low_ack","0");preCommands=preCommands+"uci set wireless."+apacfg+"='wifi-iface' \n";if(guestASelected){apgnacfg="ap_gn_a";uci.set("wireless",apgnacfg,"","wifi-iface");uci.set("wireless",apgnacfg,"device",wifiDevA);uci.set("wireless",apgnacfg,"mode","ap");uci.set("wireless",apgnacfg,"network","lan");uci.set("wireless",apgnacfg,"disassoc_low_ack","0");uci.set("wireless",apgnacfg,"is_guest_network","1");var mac=document.getElementById("wifi_guest_mac_a").value;if(mac==""){do{if(distribTarget.match(/mvebu/)){wmacIdx=wirelessIfs.indexOf(wifiDevA.replace("radio","wlan"));ref=currentWirelessMacs[wmacIdx];mac=getRandomMacWithMask(true,true,ref,"fd:ff:ff:ff:ff:f0")}else{mac=getRandomMac(true,true)}}while(macConflict.join(",").toLowerCase().split(",").indexOf(mac.toLowerCase())!=-1)}macConflict.push(mac);uci.set("wireless",apgnacfg,"macaddr",mac);preCommands=preCommands+"uci set wireless."+apgnacfg+"='wifi-iface' \n"}if(dualBandSelected){ap2cfg=apacfg;if(guestASelected){apgn2cfg=apgnacfg}}else{apcfg=apacfg;if(guestASelected){apgncfg=apgnacfg}}}if(currentModes=="ap+wds"){var wdsData=getTableDataArray(document.getElementById("wifi_wds_mac_table_container").firstChild,1,0);var wdsList=[];var wIndex=0;for(wIndex=0;wIndex0&&wimode.match(/sta/);if(fixedChannels){var ssidIndex=getSelectedValue("wifi_list_ssid2");fixedChannels=ssidIndex!="custom";if(fixedChannels){otherCfgDev=scannedSsids[4][parseInt(ssidIndex)]=="A"?wifiDevA:wifiDevG}}if(!fixedChannels){if(dualBandSelected){otherCfgDev=getSelectedValue("wifi_client_band")=="5"?wifiDevA:wifiDevG}else{otherCfgDev=wifiASelected?wifiDevA:wifiDevG}}otherMode=currentModes.replace(/\+?ap\+?/,"");othercfg=otherMode+"cfg";uci.set("wireless",othercfg,"","wifi-iface");uci.set("wireless",othercfg,"device",otherCfgDev);uci.set("wireless",othercfg,"mode",otherMode);uci.set("wireless",othercfg,"network",getSelectedValue("wan_protocol").match(/wireless/)?"wan":"lan");if(wirelessDriver=="mac80211"&&document.getElementById("wan_use_mac").checked&&wimode.match(/sta/)&&getSelectedValue("wan_protocol").match(/wireless/)){uci.set("wireless",othercfg,"macaddr",document.getElementById("wan_mac").value)}preCommands=preCommands+"uci set wireless."+othercfg+"='wifi-iface' \n"}preCommands=preCommands+"uci commit \n";macFilterEnabled=getSelectedValue("mac_filter_enabled")=="enabled";var macTable=document.getElementById("mac_table_container").firstChild;var macList=getTableDataArray(macTable,true,false);var policy=getSelectedValue("mac_filter_policy");var macListStr=macList.join(" ");if(wirelessDriver=="broadcom"){if(!macFilterEnabled||macListStr==""){uci.remove("wireless",wifiDevG,policyOption);uci.remove("wireless",wifiDevG,"maclist")}else{uci.set("wireless",wifiDevG,policyOption,policy);uci.set("wireless",wifiDevG,"maclist",macListStr)}}else{for(wsecIndex=0;wsecIndex0){uci.createListOption("dhcp",dnsmasqSection,"server",true);uci.createListOption("dhcp",dnsmasqSection,"rebind_domain",true);uci.set("dhcp",dnsmasqSection,"server",altServerDefs[0]);uci.set("dhcp",dnsmasqSection,"rebind_domain",altServerDefs[1])}var firewallDefaultSections=uciOriginal.getAllSectionsOfType("firewall","defaults");var forceDNS=document.getElementById("lan_dns_force").checked?"1":"";uciOriginal.set("firewall",firewallDefaultSections[0],"force_router_dns",forceDNS);uci.set("firewall",firewallDefaultSections[0],"force_router_dns",forceDNS);var fdCommand=forceDNS=="1"?"\nuci set firewall.@defaults[0].force_router_dns=1 \n":"\nuci -q del firewall.@defaults[0].force_router_dns \n";preCommands=preCommands+fdCommand;var pingSection=getPingSection();var isPingDrop=document.getElementById("drop_wan_ping").checked?"DROP":"ACCEPT";uciOriginal.set("firewall",pingSection,"target",isPingDrop);uci.set("firewall",pingSection,"target",isPingDrop);var dhcpSection=getDhcpSection(uciOriginal);var newMask=document.getElementById("lan_mask").value;var newIp=document.getElementById("lan_ip").value;var routerIpEnd=parseInt(newIp.split(".")[3]);var oldStart=parseInt(uciOriginal.get("dhcp",dhcpSection,"start"));var oldEnd=oldStart+parseInt(uciOriginal.get("dhcp",dhcpSection,"limit"))-1;if(!rangeInSubnet(newMask,newIp,oldStart,oldEnd)||routerIpEnd>=oldStart&&routerIpEnd<=oldEnd){var newRange=getSubnetRange(newMask,newIp);var newStart;var newEnd;if(routerIpEnd-newRange[0]>newRange[1]-routerIpEnd){newStart=newRange[0];newEnd=routerIpEnd-1}else{newStart=routerIpEnd+1;newEnd=newRange[1]}uci.set("dhcp",dhcpSection,"start",newStart);uci.set("dhcp",dhcpSection,"limit",newEnd+1-newStart)}ppoeReconnectIds=["wan_pppoe_reconnect_pings","wan_pppoe_interval"];wifiSsidId=wifiGSelected?"wifi_ssid1":"wifi_ssid1a";wifiGuestSsidId=wifiGSelected?"wifi_guest_ssid1":"wifi_guest_ssid1a";inputIds=["wan_protocol","wan_pppoe_user","wan_pppoe_pass","wan_pppoe_max_idle",ppoeReconnectIds,"wan_static_ip","wan_static_mask","wan_static_gateway","wan_mac","wan_mtu","lan_ip","lan_mask","lan_gateway",wifiSsidId,"wifi_hidden","wifi_isolate","wifi_encryption1","wifi_pass1","wifi_wep1",wifiGuestSsidId,"wifi_guest_hidden","wifi_guest_isolate","wifi_guest_encryption1","wifi_guest_pass1","wifi_guest_wep1","wifi_server1","wifi_port1","wifi_pass2","wifi_wep2","wan_3g_device","wan_3g_user","wan_3g_pass","wan_3g_apn","wan_3g_pincode","wan_3g_service","wan_3g_isp"];options=["proto","username","password","demand","keepalive","ipaddr","netmask","gateway","macaddr","mtu","ipaddr","netmask","gateway","ssid","hidden","isolate","encryption","key","key","ssid","hidden","isolate","encryption","key","key","auth_server","auth_port","key","key","device","username","password","apn","pincode","service","mobile_isp"];var sv=setVariableFromValue;var svm=setVariableFromModifiedValue;var svcat=setVariableFromConcatenation;var svcond=setVariableConditionally;setFunctions=[sv,sv,sv,svm,svcat,sv,sv,sv,svcond,svcond,sv,sv,sv,sv,svcond,svcond,sv,sv,sv,sv,svcond,svcond,sv,sv,sv,sv,sv,sv,sv,sv,sv,sv,sv,sv,sv,sv];var f=false;var t=true;var minutesToSeconds=function(value){return value*60};var lowerCase=function(value){return value.toLowerCase()};var ifCustomMac=function(value){return document.getElementById("wan_use_mac").checked==true||defaultWanMac!=currentWanMac};var ifCustomMtu=function(value){return document.getElementById("wan_use_mtu").checked==true&&document.getElementById("wan_mtu").value!=1500};var ifHiddenChecked=function(value){return getSelectedValue("wifi_hidden")=="disabled"?1:0};var ifIsolateChecked=function(value){return getSelectedValue("wifi_isolate")=="enabled"?1:0};var ifGuestHiddenChecked=function(value){return getSelectedValue("wifi_guest_hidden")=="disabled"?1:0};var ifGuestIsolateChecked=function(value){return getSelectedValue("wifi_guest_isolate")=="enabled"?1:0};var demandParams=[f,minutesToSeconds];var macParams=[ifCustomMac,f,document.getElementById("wan_mac").value.toLowerCase()];var mtuParams=[ifCustomMtu,t,""];var hiddenParams=[ifHiddenChecked,f,"1"];var isolateParams=[ifIsolateChecked,f,"1"];var guestHiddenParams=[ifGuestHiddenChecked,f,"1"];var guestIsolateParams=[ifGuestIsolateChecked,f,"1"];additionalParams=[f,f,f,demandParams,f,f,f,f,macParams,mtuParams,f,f,f,f,hiddenParams,isolateParams,f,f,f,f,guestHiddenParams,guestIsolateParams,f,f,f,f,f,f,f,f,f,f,f,f,f,f];pppoeReconnectVisibilityIds=["wan_pppoe_reconnect_pings_container","wan_pppoe_interval_container"];multipleVisibilityIds=[pppoeReconnectVisibilityIds];wirelessSections=[apcfg,apcfg,apcfg,apcfg,apcfg,apcfg,apgncfg,apgncfg,apgncfg,apgncfg,apgncfg,apgncfg,apcfg,apcfg,othercfg,othercfg];visibilityIds=[];pkgs=[];sections=[];var idIndex;for(idIndex=0;idIndex28){pkgs.push("network");sections.push("wan");uci.remove("network","wan",options[idIndex])}else if(idIndex<13){pkgs.push("network");sections.push("lan");uci.remove("network","lan",options[idIndex])}else{pkgs.push("wireless");sections.push(wirelessSections.shift())}}setVariables(inputIds,visibilityIds,uci,pkgs,sections,options,setFunctions,additionalParams);if(apgncfg&&uci.get("wireless",apgncfg,"ssid")==""){uci.set("wireless",apgncfg,"disabled","1")}if(getSelectedValue("wifi_mode")!="disabled"){var ssid2="";var enc2="";if(document.getElementById("wifi_ssid2_container").style.display!="none"){ssid2=document.getElementById("wifi_ssid2").value;enc2=getSelectedValue("wifi_encryption2")}else if(document.getElementById("wifi_custom_ssid2_container").style.display!="none"){ssid2=document.getElementById("wifi_custom_ssid2").value;enc2=getSelectedValue("wifi_encryption2")}else if(document.getElementById("wifi_list_ssid2_container").style.display!="none"){ssid2=scannedSsids[0][parseInt(getSelectedValue("wifi_list_ssid2"))];enc2=scannedSsids[1][parseInt(getSelectedValue("wifi_list_ssid2"))]}if(ssid2!=""){uci.set("wireless",othercfg,"ssid",ssid2);uci.set("wireless",othercfg,"encryption",enc2)}if(ap2cfg!=""){var dup_sec_options=function(pkg,fromcfg,tocfg,optlist){var opti;for(opti=0;opti0?dnsList.join(" "):dns;if(notBridge&&uci.get("network","wan","")!=""&&dns!=lanGateway){uci.set("network","wan","dns",dns);uci.set("network","wan","peerdns","0")}}else if(notBridge&&uci.get("network","wan","")!=""){uci.remove("network","wan","peerdns")}uci.set("network","lan","dns",dns);var oldLanIp=uciOriginal.get("network","lan","ipaddr");if(oldLanIp!=currentLanIp&&oldLanIp!=""&¤tLanIp!=""){adjustIpCommands="\nsh /usr/lib/gargoyle/update_router_ip.sh "+oldLanIp+" "+currentLanIp}var commands=uci.getScriptCommands(uciCompare);var restartNetworkCommand=(wirelessDriver=="broadcom"?"\niwconfig wl0 txpower 31\n":"")+"sh /usr/lib/gargoyle/restart_network.sh ;\n";if(doReboot){restartNetworkCommand="\nsh /usr/lib/gargoyle/reboot.sh ;\n"}var regenerateCacheCommand="\nrm -rf /tmp/cached_basic_vars ;\n/usr/lib/gargoyle/cache_basic_vars.sh >/dev/null 2>/dev/null\n";commands=preCommands+commands+adjustIpCommands+bridgeEnabledCommands+restartNetworkCommand+regenerateCacheCommand;var param=getParameterDefinition("commands",commands)+"&"+getParameterDefinition("hash",document.cookie.replace(/^.*hash=/,"").replace(/[\t ;]+.*$/,""));var stateChangeFunction=function(req){if(req.readyState==4){if(oldLanIp==currentLanIp&&!doReboot){uciOriginal=uci.clone();resetData();setControlsEnabled(true)}}};runAjax("POST","utility/run_commands.sh",param,stateChangeFunction);if(oldLanIp!=currentLanIp||doReboot){currentProtocol=location.href.match(/^https:/)?"https":"http";testLocation=currentProtocol+"://"+currentLanIp+":"+window.location.port+"/utility/reboot_test.sh";testReboot=function(){toggleReload=true;setTimeout("testReboot()",5*1e3);document.getElementById("reboot_test").src=testLocation};setTimeout("testReboot()",25*1e3);setTimeout("reloadPage()",240*1e3)}}}function reloadPage(){if(toggleReload){var reloadState=document.getElementById("reboot_test").readyState;if(typeof reloadState=="undefined"||reloadState==null||reloadState=="complete"){toggleReload=false;document.getElementById("reboot_test").src="";currentProtocol=location.href.match(/^https:/)?"https":"http";window.location=currentProtocol+"://"+currentLanIp+":"+window.location.port+window.location.pathname}}}function generateWepKey(length){var keyIndex=0;var key="";var hex=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];while(keyIndex0?null:basicS.WDSMAC}return error};var errors=[];if(document.getElementById("global_gateway").checked){var inputIds=["wan_pppoe_user","wan_pppoe_pass","wan_pppoe_max_idle","wan_pppoe_reconnect_pings","wan_pppoe_interval","wan_static_ip","wan_static_mask","wan_static_gateway","wan_mac","wan_mtu","lan_ip","lan_mask","lan_gateway","wifi_txpower","wifi_txpower_5ghz","wifi_ssid1","wifi_pass1","wifi_wep1","wifi_guest_pass1","wifi_guest_wep1","wifi_server1","wifi_port1","wifi_ssid2","wifi_pass2","wifi_wep2","wan_3g_device","wan_3g_apn"];var functions=[vlr1,vlr1,vn,vn,vn,vip,vnm,vip,vm,vn,vip,vnm,vip,vtp,vtpa,vlr1,vlr8,vw,vlr8,vw,vip,vn,vlr1,vlr8,vw,vlr1,vlr1];var optInputIds=["wifi_ssid1a","wifi_guest_ssid1","wifi_guest_ssid1a"];for(index in optInputIds){var input=optInputIds[index];if(document.getElementById(input+"_container").style.display=="block"){inputIds.push(input);functions.push(vlr1)}}var returnCodes=new Array;var visibilityIds=new Array;var idIndex;for(idIndex=0;idIndex0){var rc=removeChannels.shift();removeOptionFromSelectElement("bridge_channel",rc,document);removeOptionFromSelectElement("wifi_channel1",rc,document);removeOptionFromSelectElement("wifi_channel2",rc,document)}if(leaseStart!=""){setElementEnabled(document.getElementById("dhcp_renew_button"),true);setElementEnabled(document.getElementById("dhcp_release_button"),true);var releaseDate=new Date;var leaseStartSeconds=parseInt(currentDateSeconds)-parseInt(uptime)+parseInt(leaseStart);releaseDate.setTime(leaseStartSeconds*1e3+parseInt(leaseLifetime)*1e3+timezoneOffset*1e3);setChildText("dhcp_expires",localdate(releaseDate));setChildText("dhcp_ip",currentWanIp)}else{setElementEnabled(document.getElementById("dhcp_renew_button"),true);setElementEnabled(document.getElementById("dhcp_release_button"),false)}setChildText("bridge_wifi_mac",currentWirelessMacs[0],null,null,null);setChildText("wifi_mac",currentWirelessMacs[0],null,null,null);var confIsBridge=isBridge(uciOriginal);var confIsGateway=!confIsBridge;document.getElementById("global_gateway").checked=confIsGateway;document.getElementById("global_bridge").checked=confIsBridge;document.getElementById("bridge_ip").value=uciOriginal.get("network","lan","ipaddr");document.getElementById("bridge_mask").value=uciOriginal.get("network","lan","netmask");document.getElementById("bridge_gateway").value=uciOriginal.get("network","lan","gateway");var bridgeWdsTableData=[];if(confIsBridge){var bridgeSection=getBridgeSection(uciOriginal);var mode=uciOriginal.get("wireless",bridgeSection,"client_bridge")=="1"?"client_bridge":"wds";setSelectedValue("bridge_mode",mode);document.getElementById("bridge_ssid").value=uciOriginal.get("wireless",bridgeSection,"ssid");var repeaterSection="";var testSections=uciOriginal.getAllSectionsOfType("wireless","wifi-iface");var testIndex=0;for(testIndex=0;testIndex=52&&selectedValue<=144?true:false;document.getElementById("wifi_channel1_5ghz_dfs").style.display=dfsChan==true?"block":"none";document.getElementById("wifi_channel2_5ghz_dfs").style.display=dfsChan==true?"block":"none";document.getElementById("bridge_channel_5ghz_dfs").style.display=dfsChan==true?"block":"none"}else{setSelectedValue("wifi_channel1",selectedValue);setSelectedValue("wifi_channel2",selectedValue);setSelectedValue("bridge_channel",selectedValue);updateTxPower("wifi_max_txpower","wifi_txpower","G")}}function resetWirelessMode(){setSelectedValue("wifi_mode",getWirelessMode(uciOriginal))}function validateWep(text){return validateHex(text)==0&&(text.length==10||text.length==26)?0:1}function proofreadWep(input){proofreadText(input,validateWep,0)}function addTextToSingleColumnTable(textId,tableContainerId,validator,preprocessor,validReturn,duplicatesAllowed,columnName){var val=document.getElementById(textId).value;if(validator(val)!=validReturn){alert(basicS.SpcEr1+" "+columnName+" "+basicS.SpcEr2)}else{val=preprocessor(val);var singleTable=document.getElementById(tableContainerId).firstChild;var singleTableData=getTableDataArray(singleTable,true,false);var inTable=false;var tabIndex=0;for(tabIndex=0;tabIndex0){var oldSsid=document.getElementById(ssidField).value;document.getElementById("wifi_custom_ssid2").value=oldSsid;document.getElementById("bridge_custom_ssid").value=oldSsid;var ssidDisplay=[];var ssidValue=[];var ssidIndex=0;for(ssidIndex=0;ssidIndex0){var scannedIndex=getSelectedValue(selectId);setSelectedValue("bridge_list_ssid",scannedIndex);setSelectedValue("wifi_list_ssid2",scannedIndex);document.getElementById("wifi_hwmode").disabled=0;document.getElementById("wifi_hwmode_5ghz").disabled=0;var ic=scannedIndex=="custom"?1:0;var inc=ic==0?1:0;if(inc){scannedIndex=parseInt(scannedIndex);var enc=scannedSsids[1][scannedIndex];var chan=scannedSsids[2][scannedIndex];var band=scannedSsids[4][scannedIndex];if(GwifiN){var modes=["11gn","11g"];var mnames=["B+G+N","B+G"]}else{var modes=["11g"];var mnames=["B+G"]}if(band=="A"){modes.unshift("disabled");mnames.unshift(UI.Disabled);document.getElementById("wifi_hwmode").disabled=1}else{setAllowableSelections("bridge_hwmode",modes,mnames)}setAllowableSelections("wifi_hwmode",modes,mnames);document.getElementById("wifi_hwmode").selectedIndex=0;if(dualBandWireless){if(AwifiAC){var modes=["11anac","11an","11a"];var mnames=["A+N+AC","A+N","A"]}else if(AwifiN){var modes=["11an","11a"];var mnames=["A+N","A"]}else{var modes=["11a"];var mnames=["A"]}if(band=="G"){modes.unshift("disabled");mnames.unshift(UI.Disabled);document.getElementById("wifi_hwmode_5ghz").disabled=1}else{setAllowableSelections("bridge_hwmode",modes,mnames)}setAllowableSelections("wifi_hwmode_5ghz",modes,mnames);document.getElementById("wifi_hwmode_5ghz").selectedIndex=0}setSelectedValue("wifi_encryption2",enc);setSelectedValue("bridge_encryption",enc);var enc=getSelectedText("wifi_encryption2");setChildText("wifi_fixed_encryption2",enc);setChildText("bridge_fixed_encryption",enc);var chanEl1="wifi_channel1"+(band=="A"?"_5ghz":"");var chanEl2="wifi_channel2"+(band=="A"?"_5ghz":"");var chanElB="bridge_channel"+(band=="A"?"_5ghz":"");setSelectedValue(chanEl1,chan);setSelectedValue(chanEl2,chan);setSelectedValue(chanElB,chan);setChildText("wifi_fixed_channel1",chan);setChildText("wifi_fixed_channel2",chan);setChildText("bridge_fixed_channel",chan)}var be=getSelectedValue("bridge_encryption");var we=getSelectedValue("wifi_encryption2");var bp=be.match(/psk/)||be.match(/WPA/)?1:0;var bw=be.match(/wep/)||be.match(/WEP/)?1:0;var wp=we.match(/psk/)||we.match(/WPA/)?1:0;var ww=we.match(/wep/)||we.match(/WEP/)?1:0;setVisibility(visIds,[1,ic,0,ic,inc,ic,inc,1,ic,0,ic,inc,ic,inc,ic*isAp,inc*isAp,wp,ww,bp,bw])}else{var be=getSelectedValue("bridge_encryption");var we=getSelectedValue("wifi_encryption2");var bp=be.match(/psk/)||be.match(/WPA/)?1:0;var bw=be.match(/wep/)||be.match(/WEP/)?1:0;var wp=we.match(/psk/)||we.match(/WPA/)?1:0;var ww=we.match(/wep/)||we.match(/WEP/)?1:0;setVisibility(visIds,[0,0,1,1,0,1,0,0,0,1,1,0,1,0,isAp,0,wp,ww,bp,bw])}if(ic){modes=[];mnames=[];for(x=0;x=0&&eqIndex=0&&splitIndex>idIndex){var val=line.substr(splitIndex+1);val=val.replace(/^[^\"]*\"/g,"");val=val.replace(/\".*$/g,"");vals.push(val)}}return vals};while(cells.length>0){var cellData=cells.shift();var cellLines=cellData.split(/[\r\n]+/);var ssid=getCellValues("ESSID",cellLines).shift();var channel=getCellValues("Channel",cellLines).shift();var qualStr=getCellValues("Quality",cellLines).shift();var encStr=getCellValues("Encryption",cellLines).shift();if(ssid!=null&&channel!=null&&qualStr!=null&&encStr!=null){var enc="psk2";if(encStr.match(/WPA2 PSK/)){enc="psk2"}else if(encStr.match(/WPA PSK/)){enc="psk"}else if(encStr.match(/WEP/)){enc="wep"}else if(encStr.match(/none/)){enc="none"}var splitQual=qualStr.replace(/[\t ]+Sig.*$/g,"").split(/\//);var quality=Math.round(parseInt(splitQual[0])*100/parseInt(splitQual[1]));quality=quality>100?100:quality;parsed[0].push(ssid);parsed[1].push(enc);parsed[2].push(channel);parsed[3].push(quality);parsed[4].push(channel>30?"A":"G")}}var qualityIndices=[];var qIndex;for(qIndex=0;qIndex0){var i=qualityIndices.shift()[0];var pIndex;for(pIndex=0;pIndex<5;pIndex++){sortedParsed[pIndex].push(parsed[pIndex][i])}}return sortedParsed}function setChannelWidth(selectCtl,band){if(wirelessDriver==""){return}var chw=getSelectedValue(selectCtl.id);var hplus=chw=="HT40+";var h40=chw=="HT40+"||chw=="HT40-";var vht=chw=="VHT20"||chw=="VHT40"||chw=="VHT80"||chw=="VHT160";if(band=="G"){setSelectedValue("wifi_channel_width",getSelectedValue(selectCtl.id));setSelectedValue("bridge_channel_width",getSelectedValue(selectCtl.id));setAllowableSelections("bridge_channel",mac80211Channels["G"],mac80211Channels["G"],document);setAllowableSelections("wifi_channel1",mac80211Channels["G"],mac80211Channels["G"],document);setAllowableSelections("wifi_channel2",mac80211Channels["G"],mac80211Channels["G"],document);var removeChannels=[];var rIndex=1;for(rIndex=1;rIndex<=4&&h40;rIndex++){removeChannels.push(hplus?mac80211Channels["G"][mac80211Channels["G"].length-rIndex]:rIndex)}while(removeChannels.length>0){var rc=removeChannels.shift();removeOptionFromSelectElement("bridge_channel",rc,document);removeOptionFromSelectElement("wifi_channel1",rc,document);removeOptionFromSelectElement("wifi_channel2",rc,document)}updateTxPower("wifi_max_txpower","wifi_txpower","G")}else if(band=="A"&&mac80211Channels["A"]!=null){var origAChan=mac80211Channels["A"];var aChannels=origAChan;if(h40){aChannels=[];var validAPlus=[36,44,52,60,100,108,116,124,132,140,149,157];var validAMinus=[40,48,56,64,104,112,120,128,136,144,153,161];var validTest=hplus?arrToHash(validAPlus):arrToHash(validAMinus);for(var chanIndex=0;chanIndex0&&wimode.match(/sta/);var ssidIndex=getSelectedValue("wifi_list_ssid2");fixedChannels=fixedChannels&&ssidIndex!="custom";if(fixedChannels){var fixedChannel=scannedSsids[2][parseInt(ssidIndex)].trim();var fixedBand=scannedSsids[4][parseInt(ssidIndex)];channels[fixedBand]=fixedChannel;if(dualBandSelected){var otherBand=fixedBand=="G"?"A":"G";var otherSelectId=otherBand=="G"?"wifi_channel1":"wifi_channel1_5ghz";channels[otherBand]=getSelectedValue(otherSelectId).trim()}}if(!fixedChannels){if(wifiGSelected){channels["G"]=getSelectedValue("wifi_channel1")}if(wifiASelected){channels["A"]=getSelectedValue("wifi_channel1_5ghz")}}}else{var bridgeModeA=getSelectedValue("bridge_hwmode");var bridgeModeA=!String(bridgeModeA).match(/11g/);if(bridgeModeA){channels["A"]=document.getElementById("bridge_fixed_channel_container").style.display!="none"?document.getElementById("bridge_fixed_channel").firstChild.data.trim():getSelectedValue("bridge_channel_5ghz").trim()}else{channels["G"]=document.getElementById("bridge_fixed_channel_container").style.display!="none"?document.getElementById("bridge_fixed_channel").firstChild.data.trim():getSelectedValue("bridge_channel").trim()}}return channels}function setHwMode(selectCtl){if(document.getElementById("wifi_hwmode_container").style.display=="none"&&document.getElementById("bridge_hwmode_container").style.display=="none"){return}hwGmode=getSelectedValue("wifi_hwmode");hwAmode=getSelectedValue("wifi_hwmode_5ghz");if(getSelectedValue("wifi_mode").match(/sta/)){if(hwGmode=="disabled"&&hwAmode=="disabled"){if(dualBandWireless&&selectCtl.id.match(/5ghz/g)){document.getElementById("wifi_hwmode").selectedIndex=1;hwGmode=getSelectedValue("wifi_hwmode")}else if(dualBandWireless){document.getElementById("wifi_hwmode_5ghz").selectedIndex=1;hwAmode=getSelectedValue("wifi_hwmode_5ghz")}else{document.getElementById("wifi_hwmode").selectedIndex=1;hwGmode=getSelectedValue("wifi_hwmode")}}if(selectCtl.id.match(/bridge/)){var allWirelessSections=uciOriginal.getAllSectionsOfType("wireless","wifi-iface");var seci=0;for(seci=0;seci0&&(wimode.match(/sta/)||document.getElementById("global_bridge").checked);var fixedChannelBand="";if(fixedChannels){var ssidIndex=getSelectedValue("wifi_list_ssid2");fixedChannels=ssidIndex!="custom";if(fixedChannels){fixedChannelBand=scannedSsids[4][parseInt(ssidIndex)]}}if(selectCtl.id=="wifi_hwmode"){var gname=getSelectedText("wifi_guest_mode");var gval=getSelectedValue("wifi_guest_mode");var mvalues=["disabled"];var mnames=[UI.Disabled];if(dualMode==true){mvalues.push("dual");mnames.push(UI.Enabled);mvalues.push("24ghz");mnames.push(basicS.F24GHzOnly);mvalues.push("5ghz");mnames.push(basicS.F5GHzOnly);gval=gname==UI.Enabled?"dual":gval}else if(hwAmode!="disabled"){mvalues.push("5ghz");mnames.push(UI.Enabled);gval=gval!="disabled"?"5ghz":gval}else{mvalues.push("24ghz");mnames.push(UI.Enabled);gval=gval!="disabled"?"24ghz":gval}setAllowableSelections("wifi_guest_mode",mvalues,mnames);setSelectedValue("wifi_guest_mode",gval)}var gmode=getSelectedValue("wifi_guest_mode");setChildText("wifi_guest_ssid1a_label",dualMode==true&&gmode=="dual"?basicS.GNet5ID:basicS.GNetID);document.getElementById("wifi_ssid1a").value=document.getElementById("wifi_ssid1a").value==""?document.getElementById("wifi_ssid1").value+" 5GHz":document.getElementById("wifi_ssid1a").value;setChildText("wifi_guest_ssid1_label",dualMode==true&&gmode=="dual"?basicS.GNet24ID:basicS.GNetID);document.getElementById("wifi_guest_ssid1a").value=document.getElementById("wifi_guest_ssid1a").style.display=="block"&&document.getElementById("wifi_guest_ssid1a").value==""&&document.getElementById("wifi_guest_ssid1").value!=""?document.getElementById("wifi_guest_ssid1").value+" 5GHz":document.getElementById("wifi_guest_ssid1a").value;for(ci=0;cichMaxPwr?""+chMaxPwr:""+dbm;lab.firstChild.data="(0 - "+chMaxPwr+"dBm)";lab.style.color=atMax?"gray":"black"}}function renewDhcpLease(){var commands=[];commands.push("killall -SIGUSR1 udhcpc");commands.push("sleep 1");commands.push("wait_sec=10");commands.push("while [ $(uci -p /tmp/state get network.wan.ipaddr 2>/dev/null) == NULL ] && [ $wait_sec -gt 0 ] ; do");commands.push("sleep 1");commands.push("done");var param=getParameterDefinition("commands",commands.join("\n"))+"&"+getParameterDefinition("hash",document.cookie.replace(/^.*hash=/,"").replace(/[\t ;]+.*$/,""));setControlsEnabled(false,true,basicS.RnwL);var stateChangeFunction=function(req){if(req.readyState==4){setControlsEnabled(true);window.location.reload(true)}};runAjax("POST","utility/run_commands.sh",param,stateChangeFunction)}function releaseDhcpLease(){var commands=[];commands.push("killall -SIGUSR2 udhcpc");commands.push("uci -P /var/state set network.wan.ipaddr=''");commands.push("uci -P /var/state set network.wan.lease_lifetime=''");commands.push("uci -P /var/state set network.wan.lease_acquired=''");commands.push("uci -P /var/state set network.wan.gateway=''");commands.push("uci -P /var/state set network.wan.lease_server=''");commands.push("uci -P /var/state set network.wan.up=0");commands.push("uci commit");var param=getParameterDefinition("commands",commands.join("\n"))+"&"+getParameterDefinition("hash",document.cookie.replace(/^.*hash=/,"").replace(/[\t ;]+.*$/,""));setControlsEnabled(false,true,basicS.RlsL);setElementEnabled(document.getElementById("dhcp_release_button"),false);var stateChangeFunction=function(req){setChildText("dhcp_expires","");setChildText("dhcp_ip","");if(req.readyState==4){setTimeout(setControlsEnabled(true),2*1e3)}};runAjax("POST","utility/run_commands.sh",param,stateChangeFunction)}function singleEthernetIsWan(){return singleEthernetPort()&&document.getElementById("global_gateway").checked&&getSelectedValue("wan_protocol").match(/wired/)}function singleEthernetPort(){return defaultWanIf==""||defaultWanIf==defaultLanIf}function getAltServerDefs(currentAltDefs,currentRebindServers,altDefsEnabled){var defs=[];var domains=[];var definedTlds={};var setTlds={};var tldLists=[ncTlds,onTlds];var tli;var cadi;var crsi;for(tli=0;tli0){setAllowableSelections(field,scannedDevices,scannedDevices);set3GDevice(getSelectedValue("wan_3g_list_device"));document.getElementById("wan_3g_device").style.display="none";document.getElementById("wan_3g_list_device").style.display="block"}else{alert(basicS.NoDv)}setControlsEnabled(true)}};runAjax("POST","utility/scan_3gdevices.sh",param,stateChangeFunction)}function updateService(){setSelectedValue("wan_3g_isp","custom");updateApnDetails();document.getElementById("wan_3g_user").value="";document.getElementById("wan_3g_pass").value="";showApn()}function showApn(){document.getElementById("wan_3g_apn_container").style.display=getSelectedValue("wan_3g_service")!="cdma"&&getSelectedValue("wan_protocol")=="3g"||getSelectedValue("wan_protocol")=="qmi"||getSelectedValue("wan_protocol")=="ncm"||getSelectedValue("wan_protocol")=="mbim"?"block":"none"}function getPingSection(){var ruleSections=uciOriginal.getAllSectionsOfType("firewall","rule");var ruleIndex;for(ruleIndex=0;ruleIndex>y&1)}}macPairs[x]=("0"+parseInt(macPair).toString(16)).slice(-2)}retVal=macPairs.join(":")}return retVal}function setNthBitToX(val,n,x){val=val&~(1<0){splitLine=line.split(/[\t]+/);name=stripQuotes(splitLine.pop());code=stripQuotes(splitLine.pop());countryName[code]=name}}return countryName}function checkWifiCountryVisibility(){if(typeof geo_countrycode==="undefined"||geo_countrycode===null){return false}else if(uciOriginal.get("wireless",uciWirelessDevs[0],"country")==""){var selOpt=countryName[geo_countrycode];if(selOpt==""){return false}else if(document.getElementById("wireless_country").length==1){removeAllOptionsFromSelectElement(document.getElementById("wireless_country"));removeAllOptionsFromSelectElement(document.getElementById("bridge_wireless_country"));addOptionToSelectElement("wireless_country",countryName["00"],"00");addOptionToSelectElement("bridge_wireless_country",countryName["00"],"00");addOptionToSelectElement("wireless_country",selOpt,geo_countrycode);addOptionToSelectElement("bridge_wireless_country",selOpt,geo_countrycode)}}if(document.getElementById("wireless_country").length==1){return false}return true}function syncWifiCountrySelection(elSelected){var selIdx=elSelected.selectedIndex;if(elSelected.id=="bridge_wireless_country"){document.getElementById("wireless_country").selectedIndex=selIdx}else{document.getElementById("bridge_wireless_country").selectedIndex=selIdx}}