Advertisement
cetipabo

/www/docroot/modals/ethernet-modal.lp

Mar 7th, 2018
1,659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 42.15 KB | None | 0 0
  1. --pretranslated: do not change this file
  2.  
  3. -- Localization
  4. --NG-????? ResetButton and friendlyName on LAN-Interface Page
  5. --NG-71196 IPv6 Button pppoe realm
  6. --NG-71457
  7. --NG-73647 changes reloads pppoe
  8. --NG-78292 DHCP server disabled after reset
  9. --NG-72728
  10. --NG-68986 a revert been done
  11. --NG-89213 to revert the revert of the generic NG-68986 changes
  12. --NG-83015 IPv6
  13. --NG-96100 Local Network Modal not opened after upstep to 17.1.7745
  14. --NG-96425 TI-[GUI] - Changing SSID name of Guest 5GHz is not coherent in Wireless and Local Network Modal
  15. --NG-100782 [TI] Local Network card accepts LAN IP in Ospiti range when the subnet mask is changed
  16. --NG-102499 Assigning a Network Address/mask already in use shall not be possible
  17. --NG-70591 GUI : Unable to configure infinite lease time (-1) from GUI but data model allows
  18. gettext.textdomain('webui-core')
  19.  
  20. -- Process POST query
  21. local bit = require("bit")
  22. local proxy = require("datamodel")
  23. local lfs = require("lfs")
  24. local pairs, string ,ipairs, ngx = pairs, string, ipairs, ngx
  25. local session = ngx.ctx.session
  26. local ui_helper = require("web.ui_helper")
  27. local message_helper = require("web.uimessage_helper")
  28. local post_helper = require("web.post_helper")
  29. local content_helper = require("web.content_helper")
  30. local uinetwork = require("web.uinetwork_helper")
  31. local hosts_ac = uinetwork.getAutocompleteHostsList()
  32. local tonumber, tostring = tonumber, tostring
  33. local content, helpmsg
  34. local match, format = string.match, string.format
  35. local find, untaint = string.find, string.untaint
  36. local ipv42num = post_helper.ipv42num
  37. local broadcast_ip =post_helper.ipv42num("255.255.255.255")
  38. local timhelper = require("web.tim_helper")
  39.  
  40. -- Shortcuts to validation helpers to make lines shorter
  41. local aIPV = post_helper.advancedIPValidation
  42. local vB = post_helper.validateBoolean
  43. local vIP4N = post_helper.validateIPv4Netmask
  44. local vQTN = post_helper.validateQTN
  45. local gAV = post_helper.getAndValidation
  46. local gVIC = post_helper.getValidateInCheckboxgroup
  47. local gVIES = post_helper.getValidateInEnumSelect
  48.  
  49. local session = ngx.ctx.session
  50. local tech = false
  51. if session:getrole() == "engineer" then
  52.    tech = true
  53. end
  54.  
  55. local clear_network_stats = {
  56.     controls = {
  57.       class = "clear_network_stats"
  58.     },
  59.     group = {
  60.        class = "advanced hide"
  61.     },
  62.     button = {
  63.       ["data-name"] = "action",
  64.       ["data-value"] = "RESET"
  65.     }
  66. }
  67. local validateDHCPIgnore = post_helper.validateDHCPIgnore
  68. local pIPV = post_helper.isPublicIP
  69.  
  70. local dhcpDefaultExist
  71. local hosts_mac = {}
  72. for k, v in pairs(hosts_ac) do
  73.     local mac = match(k, "%[(.*)%]")
  74.     hosts_mac[#hosts_mac+1] = {mac, mac}
  75. end
  76.  
  77. hosts_mac[#hosts_mac+1] = {"custom",T"custom"}
  78.  
  79. if lfs.attributes("/www/lua/dhcpreset_helper.lua", "mode") == "file" then
  80.    dhcpDefaultExist = require("dhcpreset_helper")
  81. end
  82.  
  83. local function num2ipv4(ip)
  84.     local ret = bit.band(ip, 255)
  85.     ip = bit.rshift(ip,8)
  86.     for i=1,3 do
  87.         ret = bit.band(ip,255) .. "." .. ret
  88.         ip = bit.rshift(ip,8)
  89.     end
  90.     return ret
  91. end
  92.  
  93. local getargs = ngx.req.get_uri_args()
  94. local getintf = getargs.intf
  95.  
  96. local curintf = "lan"
  97. -- Get all the LAN interfaces
  98. local net_intfs_path = "rpc.network.interface."
  99. local all_intfs = content_helper.convertResultToObject(net_intfs_path .. "@.", proxy.get(net_intfs_path))
  100. local wireless_radio = {}
  101. for i,v in ipairs(proxy.getPN("rpc.wireless.ssid.", true)) do
  102.   local radios = match(v.path, "rpc%.wireless%.ssid%.@([^%.]+)%.")
  103.   if radios then
  104.     wireless_radio[radios] = true
  105.   end
  106. end
  107. local lan_intfs = {}
  108. local pppIntf, pppDev
  109. for k,v in ipairs(all_intfs) do
  110.     if v.type == "lan" and (not find(v["ppp.ll_intf"], "wl") or wireless_radio[untaint(v["ppp.ll_intf"])])then
  111.         local radio = "noradio"
  112.         local name = ""
  113.         if match(v["ppp.ll_dev"], "wl") then
  114.             name = proxy.get("rpc.wireless.ssid.@"..v["ppp.ll_dev"]..".ssid")[1].value
  115.                 if match(proxy.get("rpc.wireless.ssid.@"..v["ppp.ll_dev"]..".radio")[1].value, "radio_5G") then
  116.                     radio = "5GHz"
  117.                 else
  118.                     radio = "2,4GHz"
  119.                 end
  120.             end
  121.         if name ~= "" then
  122.             lan_intfs[#lan_intfs + 1] = {name = name, index = v.paramindex, radio = radio}
  123.         elseif v.name and v.name ~= "" then
  124.             lan_intfs[#lan_intfs + 1] = {name = v.name, index = v.paramindex, radio = radio}
  125.         else
  126.             lan_intfs[#lan_intfs + 1] = {name = v.paramindex, index = v.paramindex, radio = radio}
  127.         end
  128.     end
  129.     if v.paramindex == getintf then
  130.         curintf = v.paramindex
  131.         pppDev = v["ppp.ll_dev"]
  132.         pppIntf = v["ppp.ll_intf"]
  133.     end
  134. end
  135.  
  136.  
  137. ----------------------------------reset function-------------------------------------
  138. local function restdhcp()
  139. local file = io.open("/rom/etc/uci-defaults/tch_0035-network-lan","r")
  140. io.input(file)
  141. local lanip = ""
  142. local lanmask = ""
  143. local checkup = 0
  144.     while checkup == 0 do
  145.     local line = io.read()
  146.         if line ~= nil and (lanip == "" or lanip == nil) then
  147.             lanip=match(line,"uci set network%."..curintf.."%.ipaddr%=([%d]+%.[%d]+%.[%d]+%.[%d]+)")
  148.         end
  149.         if line ~= nil and (lanmask == "" or lanmask == nil) then
  150.             lanmask=match(line,"uci set network%."..curintf.."%.netmask%=([%d]+%.[%d]+%.[%d]+%.[%d]+)")
  151.         end
  152.         if lanip ~= "" and lanip ~= nil and lanmask ~= "" and lanmask ~= nil  then
  153.             checkup=1
  154.             io.close(file)
  155.         elseif line == nil then
  156.             checkup=2
  157.             io.close(file)
  158.         end
  159.     end
  160.     if checkup == 2 then
  161.     local file2 = io.open("/lib/functions/uci-defaults.sh","r")
  162.     io.input(file2)
  163.         while checkup == 2 do
  164.             local line = io.read()
  165.             if line ~= nil and (lanip == "" or lanip == nil) then
  166.                 lanip=match(line,"set network%."..curintf.."%.ipaddr%=%'([%d]+%.[%d]+%.[%d]+%.[%d]+)%'")
  167.             end
  168.             if line ~= nil and (lanmask == "" or lanmask == nil) then
  169.                 lanmask=match(line,"set network%."..curintf.."%.netmask%=%'([%d]+%.[%d]+%.[%d]+%.[%d]+)%'")
  170.             end
  171.             if lanip and lanip ~= "" and lanmask and lanmask ~= "" or line == nil then
  172.                 checkup=5
  173.                 io.close(file2)
  174.             end
  175.         end
  176.     end
  177.    
  178.     local founddev = 0
  179.     local ipstart = ""
  180.     local ipend = ""
  181.     local ltime = ""
  182.     local dhcpign = ""
  183.     local fp = io.open("/rom/etc/config/dhcp", "r")
  184.     local pattern = format("config dhcp %s",curintf)
  185.     io.input(fp)
  186.         while founddev == 0 do
  187.             local line =io.read()
  188.             if match(line,pattern) then
  189.                 while founddev == 0 do
  190.                 line =io.read()
  191.                     if line ~= nil and (ipstart == "" or ipstart == nil) then
  192.                         ipstart= match(line,"option start[%s]+'([%d]+)'")
  193.                     end
  194.                     if line ~= nil and (ipend == "" or ipend == nil) then
  195.                         ipend= match(line,"option limit[%s]+'([%d]+)'")
  196.                     end
  197.                     if line ~= nil and (ltime == "" or ltime == nil) then
  198.                         ltime= match(line,"option leasetime[%s]+'([%w]+)'")
  199.                     end
  200.                     if line ~= nil and (dhcpign == "" or dhcpign == nil) then
  201.                         dhcpign= match(line,"option ignore[%s]+'([%d]+)'")
  202.                     end
  203.                     if line == nil or match(line, "config dhcp") or ipstart~= nil and ipstart~="" and ipend ~= nil and ipend ~="" and ltime ~= nil and ltime ~="" and dhcpign ~= nil and dhcpign ~="" then
  204.                         founddev = 1
  205.                     end
  206.                 end
  207.             end
  208.             if line == nil then
  209.                 founddev = 1
  210.                
  211.             end
  212.         end
  213.         io.close(fp)
  214.         if dhcpign == nil or dhcpign == "" then
  215.             dhcpign = "0"
  216.         end
  217.     return lanip, lanmask, ipstart, ipend, ltime, dhcpign
  218. end
  219. ------------------------------------reset end-----------------------------------------------------------------
  220.  
  221. local IP6assign = "uci.network.interface.@" .. curintf .. ".ip6assign"
  222.  
  223. local mapParam = {
  224.   localIPv6 = "uci.network.interface.@" .. curintf .. ".ipv6"
  225. }
  226. local function validateIPv6(value, object, key)
  227.     local valid, msg = post_helper.validateBoolean(value, object, key)
  228.     if valid and value ~= proxy.get("uci.network.interface.@" .. curintf .. ".ipv6")[1].value then
  229.     local envIPv6 = proxy.get("uci.env.var.ppp_realm_ipv6")[1].value
  230.     local envIPv4 = proxy.get("uci.env.var.ppp_realm_ipv4")[1].value
  231.     local pppuser = "uci.network.interface.@wan.username"
  232.     local device = proxy.get("uci.network.device.")
  233.     local devifn = content_helper.convertResultToObject("uci.network.device.",device)
  234.     local devindex = {}
  235.     for i,v in ipairs(devifn) do
  236.             devindex[#devindex+1] = v.paramindex
  237.     end
  238.         if value == "0" then
  239.             proxy.set(pppuser, envIPv4)
  240.             proxy.set("uci.network.interface.@wan.ipv6", value)
  241.             proxy.set("uci.network.interface.@wan6.auto", value)
  242.             proxy.apply()
  243.             for i, v in ipairs(devindex) do
  244.                 proxy.set("uci.network.device."..v..".ipv6", value)
  245.             end
  246.             for i,v in pairs(lan_intfs) do
  247.                 if curintf ~= v.index then
  248.                 proxy.set("uci.network.interface.@"..v.index..".ipv6", value)
  249.                 end
  250.             end
  251.             -- In case we disable IPv6, we must first invalidate the existing prefix so that local devices know not to use IPv6 anymore
  252.             -- Do this here by set the ip6assign pref and only on ipv6 state change
  253.             local ipv6 = proxy.get(mapParam["localIPv6"]) -- get current value in datamodel to know if we're switching state
  254.             if ipv6 and ipv6.value ~= "0" then -- default is enabled so anything non 0 is enabled
  255.                 proxy.set(IP6assign, "0") -- the value will be set back to its current value by process_query
  256.                 proxy.apply()
  257.                 ngx.sleep(3) -- ugly but need to give it the time to complete
  258.             end
  259.         elseif value == "1" then
  260.             proxy.set(pppuser, envIPv6)
  261.             proxy.set("uci.network.interface.@wan.ipv6", value)
  262.             proxy.set("uci.network.interface.@wan6.auto", value)
  263.             for i, v in ipairs(devindex) do
  264.                 proxy.set("uci.network.device."..v..".ipv6", value)
  265.             end
  266.             for i,v in pairs(lan_intfs) do
  267.                 if curintf ~= v.index then
  268.                 proxy.set("uci.network.interface.@"..v.index..".ipv6", value)
  269.                 end
  270.             end
  271.             proxy.set(IP6assign, "64")
  272.             proxy.apply()
  273.         end
  274.         if isQtnGuestWiFi(pppDev) then
  275.             local ucipath = content_helper.getMatchedContent("uci.network.device.",{ifname = pppIntf})
  276.             if ucipath and #ucipath > 0 then
  277.                proxy.set(ucipath[1].path .. "ipv6", value)
  278.             end
  279.         end
  280.         -- Modify IPv6 at WAN-side accordingly:
  281.         -- this is especially necessary to make sure Neighbor Solicitation (for DAD etc.) messages are sent upon network reload
  282.                                                            
  283.         proxy.apply()
  284.     end
  285.     return valid, msg
  286. end
  287. --We need to update IPv6 state only when user want to update the IPv6 state alone.
  288. if ngx.var.request_method == "POST" and ngx.req.get_post_args().iPv6StateOnlyChanged == "yes" and curintf == "lan" then
  289.   local validation = {
  290.     localIPv6 = validateIPv6,
  291.   }
  292.   post_helper.handleQuery(mapParam, validation)
  293.   ngx.print(ui_helper.createMessages(message_helper.popMessages()))
  294.   ngx.exit(ngx.HTTP_OK)
  295. end
  296. -- Static leases
  297. local sleases_columns = {
  298.   {
  299.     header = T"Hostname",
  300.     name = "sleases_name",
  301.     param = "name",
  302.     type = "text",
  303.     attr = { input = { class="span2" } },
  304.   },
  305.   {
  306.     header = T"MAC address",
  307.     name = "sleases_mac",
  308.     param = "mac",
  309.     type = "select",
  310.     values = hosts_mac,
  311.     attr = { input = { class="span2", maxlength="17", id= "lease_mac" }, autocomplete=hosts_mac },
  312.     unique = true,
  313.   },
  314.   {
  315.     header = T"IP",
  316.     name = "sleases_ip",
  317.     param = "ip",
  318.     type = "text",
  319.     attr = { input = { class="span2", maxlength="15"}, autocomplete=hosts_ac },
  320.     unique = true,
  321.   },
  322.   {
  323.     header = "",
  324.     name = "sleases_owner",
  325.     param = "owner",
  326.     type = "hidden",
  327.     readonly = true,
  328.     attr = { },
  329.   },
  330. }
  331.  
  332. -- Function to avoid users to enter ReservedStatic name as custom static lease name
  333. local function sleases_name_validation(value)
  334.   if (value:find("^ReservedStatic") ~= nil) then
  335.     return nil, T"Cannot use reserved names as static lease name"
  336.   end
  337.   return true
  338. end
  339.  
  340. local function sleases_mac_validation(value, object, key)
  341.   local r1, r2 = post_helper.validateStringIsMAC(value)
  342.   if r1 then
  343.     if string.lower(value) == "ff:ff:ff:ff:ff:ff" then
  344.         return nil, T"The requested MAC address can't be the broadcast MAC"
  345.     else
  346.         object[key] = string.lower(value)
  347.     end
  348.   end
  349.   return r1, r2
  350. end
  351.  
  352. -- Function to check the input IP is in Reserved IP list
  353. local function reserved_ip_validation(value)
  354.     local reservedList = {}
  355.     local reservedIPList = proxy.get("uci.dhcp.host.")
  356.     reservedIPList = content_helper.convertResultToObject("uci.dhcp.host.", reservedIPList)
  357.     if reservedIPList then
  358.         for _,v in pairs(reservedIPList) do
  359.             if v["name"]:find("^ReservedStatic") ~= nil then
  360.                 reservedList[#reservedList + 1] = v["ip"]
  361.                 if value == v["ip"] then
  362.                     return nil
  363.                 end
  364.             end
  365.         end
  366.     end
  367.     return true
  368. end
  369.  
  370. local function sleases_ip_validation(value, object, key)
  371.     local contentdata = {
  372.       localdevIP = "uci.network.interface.@" .. curintf .. ".ipaddr",
  373.       localdevmask = "uci.network.interface.@" .. curintf .. ".netmask",
  374.     }
  375.     content_helper.getExactContent(contentdata)
  376.     return post_helper.staticLeaseIPValidation(value, contentdata)
  377. end
  378.  
  379. local sleases_valid = {
  380.     sleases_name = gAV(sleases_name_validation,post_helper.validateStringIsDomainName),
  381.     sleases_mac = gAV(sleases_mac_validation,vQTN),
  382.     sleases_ip = gAV(sleases_ip_validation,vQTN),
  383. }
  384.  
  385. local sleases_options = {
  386.     tableid = "sleases",
  387.     basepath = "uci.dhcp.host.@.",
  388.     createMsg = T"Add new static lease",
  389.     objectName  = post_helper.getRandomKey(),
  390.     addNamedObject = true,
  391. }
  392.  
  393.  
  394. local syshosts_data = proxy.get("sys.hosts.host.")
  395. local sleases_filter = function(data)
  396.     if data['owner'] == "portforward" then
  397.         local path
  398.         if syshosts_data then
  399.             for _, v in pairs(syshosts_data) do
  400.                 if v.value == data['mac'] then
  401.                     path = v.path
  402.                     break
  403.                 end
  404.             end
  405.             for _, v in pairs(syshosts_data) do
  406.                 if v.path == path and v.param == "HostName" then
  407.                     data['name'] = v.value
  408.                     break
  409.                 end
  410.             end
  411.         end
  412.         return { canEdit = false, canDelete = false }
  413.     end
  414.     if (data['name']:find("^ReservedStatic") == 1) then
  415.        return false
  416.     end
  417.     return true
  418. end
  419.  
  420. local sleases_data, sleases_helpmsg = post_helper.handleTableQuery(sleases_columns, sleases_options, sleases_filter, nil, sleases_valid)
  421.  
  422. local inUseFlag = false
  423. if ngx.var.request_method == "POST" then
  424.   local post_data = ngx.req.get_post_args()
  425.   if ( post_data.action == "TABLE-MODIFY" or  post_data.action == "TABLE-EDIT"  or  post_data.action == "TABLE-ADD") then
  426.     local text_mac_index = tonumber(post_data.index)
  427.     local text_mac
  428.     if  post_data.action == "TABLE-ADD" then
  429.       text_mac = post_data["sleases_mac"]
  430.     else
  431.       text_mac = sleases_data[text_mac_index][2]
  432.     end
  433.     local flag = true
  434.     for _,j in ipairs(hosts_mac) do
  435.       if text_mac == j[1] then
  436.         flag = false
  437.         break
  438.       end
  439.     end
  440.     if flag   then
  441.       sleases_columns[2] = {
  442.         header = T"MAC address",
  443.         name = "sleases_mac",
  444.         param = "mac",
  445.         type = "text",
  446.         attr = { input = { class="span2", maxlength="17", id= "lease_mac", value = text_mac }},
  447.         unique = true,
  448.       }
  449.     end
  450.     if post_data.action == "TABLE-MODIFY" or  post_data.action == "TABLE-ADD" then
  451.       local slease_ip = post_data.sleases_ip
  452.       local arranged_data = content_helper.convertResultToObject("sys.hosts.host.", syshosts_data)
  453.       if arranged_data then
  454.         for _, v in pairs(arranged_data) do
  455.             if v.DhcpLeaseTime ~= "" and v.IPAddress == slease_ip then
  456.                 inUseFlag = true
  457.                 break
  458.            end
  459.         end
  460.       end
  461.     end
  462.   end
  463. end
  464.  
  465. local cur_dhcp_intf = "lan"
  466. local dhcp_intfs_path = "uci.dhcp.dhcp."
  467. local all_dhcp_intfs = content_helper.convertResultToObject(dhcp_intfs_path .. "@.", proxy.get(dhcp_intfs_path))
  468.  
  469. for k,v in ipairs(all_dhcp_intfs) do
  470.     if v.interface == curintf then
  471.         cur_dhcp_intf = v.paramindex
  472.         break
  473.     end
  474. end
  475. -- Standard parameters
  476. local mapParams = {
  477.     dhcpStart = "uci.dhcp.dhcp.@" .. cur_dhcp_intf .. ".start",
  478.     dhcpLimit = "uci.dhcp.dhcp.@" .. cur_dhcp_intf .. ".limit",
  479.     dhcpv4State = "uci.dhcp.dhcp.@" .. cur_dhcp_intf .. ".dhcpv4",
  480.     dhcpIgnore = "uci.dhcp.dhcp.@" .. cur_dhcp_intf .. ".ignore",
  481.     leaseTime = "uci.dhcp.dhcp.@" .. cur_dhcp_intf .. ".leasetime",
  482.     localdevIP = "uci.network.interface.@" .. curintf .. ".ipaddr",
  483.     localdevmask = "uci.network.interface.@" .. curintf .. ".netmask",
  484.     --localIPv6 = "uci.network.interface.@" .. curintf .. ".ipv6",
  485.     eth0 = "uci.ethernet.port.@eth0.enable",
  486. }
  487.  
  488. local ethports = {
  489.     {"eth0", "eth0"},
  490. }
  491.  
  492. -- Generic solution for boards without eth1/2/3
  493. local ethport_count = 0
  494. for i = 1, 3 do
  495.     local ethport = "eth" .. i
  496.     local path = "uci.ethernet.port.@" .. ethport .. "."
  497.     local v = proxy.get(path .. "duplex")
  498.     if v ~= nil then
  499.         ethport_count = ethport_count + 1
  500.         table.insert(ethports, {ethport, ethport})
  501.         mapParams[ethport] = path .. "enable"
  502.     end
  503. end
  504.  
  505. local dnsIndex
  506. local dhcp = {}
  507. local baseDHCPOptions = "uci.dhcp.dhcp.@" .. cur_dhcp_intf .. ".dhcp_option."
  508. local dnsRemoved = false
  509.  
  510. -- Check if there is a custom DNS server, if so, then retrieve its index
  511. -- we'll update the parameters list to include it for retrieval
  512. dhcp.options = proxy.get(baseDHCPOptions)
  513. dnsIndex = #dhcp.options + 1 -- by default index is end of list
  514.  
  515. for i,v in ipairs(dhcp.options) do
  516.     if v.value:find("^6,") == 1 then
  517.         dnsIndex = tonumber(string.match(v.path, "%.@(%d+)%.$"))
  518.     end
  519. end
  520.  
  521. local function isNonPublicIPRange(ip)
  522.     if ip >= ipv42num("10.0.0.0") and ip <= ipv42num("10.255.255.255") or
  523.        ip >= ipv42num("172.16.0.0") and ip <= ipv42num("172.31.255.255") or
  524.        ip >= ipv42num("192.168.0.0") and ip <= ipv42num("192.168.255.255") then
  525.       return true
  526.     end
  527.       return nil
  528. end
  529.  
  530. local function validateDNS(value, object, key)
  531.     -- If there is no value, then we want to delete the dhcp_option if it exists
  532.     -- Otherwise, we want to check the value is an IP
  533.     if value == "" then
  534.         -- if the key does not exist, no harm done
  535.         proxy.del(mapParams[key]:sub(1,-6))
  536.         -- remove the value, there is nothing to set
  537.         object[key] = nil
  538.         dnsRemoved = true
  539.         return true
  540.     else
  541.         local dns = {}
  542.         for ip_Address in string.gmatch(value, '([^,]+)') do
  543.           dns[#dns + 1] = ip_Address
  544.       local valid, helpmsg_validip = post_helper.validateStringIsIP(ip_Address, object, key)
  545.       if valid then
  546.              --if pIPV(value) then
  547.              --   return nil, T"Public IP Range should not be used"
  548.              --end
  549.          -- Check for Limited Broadcast IP Address and "0.0.0.0" IP Address
  550.              local ipAddr = ipv42num(ip_Address)
  551.          if ipAddr == broadcast_ip or ipAddr == 0 then
  552.         return nil, T"Invalid IP Address"
  553.              end
  554.              --if not isNonPublicIPRange(ipAddr) then
  555.              --   return nil, T"Public IP Range should not be used"
  556.              --end
  557.           else
  558.         return nil, helpmsg_validip
  559.           end
  560.         end
  561.         if #dns > 3 then
  562.             return nil, nil
  563.         end
  564.         object[key] = "6," .. value -- DHCP option for DNS server is option 6
  565.         return true
  566.     end
  567. end
  568.  
  569. function isQtnGuestWiFi(intf)
  570.   if wireless_radio[untaint(intf)] then
  571.      local radio = proxy.get(format("rpc.wireless.ssid.@%s.radio", intf))
  572.      local isRemote = proxy.get(format("rpc.wireless.radio.@%s.remotely_managed", radio[1].value))
  573.      if isRemote and isRemote[1].value == "1" then
  574.         for _, v in ipairs(proxy.getPN("rpc.wireless.ap.", true)) do
  575.           local isGuest = proxy.get(v.path.."ap_isolation")
  576.           if isGuest and isGuest[1].value == "1" then
  577.             return true
  578.           end
  579.         end
  580.      end
  581.   end
  582. end
  583.  
  584. local function validateLeaseTime(value, postdata, key)
  585.    if value == '-1' or value == timhelper.ethtrans().eth_infinit then -- included '-1' as a feasible set value as specified in TR 181
  586.       postdata[key] = "infinite" -- included to ensure uci parameter is set as infinite
  587.       return true
  588.    else
  589.       local success, msg = post_helper.validateStringIsLeaseTime(value)
  590.       if success then
  591.          postdata["leaseTime"] = match(untaint(value), "^0*([1-9]%d*[smhdw]?)$")
  592.          return true
  593.       else
  594.          return nil, msg
  595.       end
  596.    end
  597. end
  598. --[[
  599. Function calculateDHCPStartAddress, Calculating DHCPStartaddress using localdeviceip, netmask, newstart and newlimit value. function returns DHCPStartAddress, DHCPEndAddress  and NetworkAddress
  600. ]]
  601. local function calculateDHCPStartAddress (baseip, netmask, start, numips)
  602.     local network = bit.band(baseip, netmask)
  603.     local ipmax = bit.bor(network, bit.bnot(netmask)) - 1
  604.     local ipstart = bit.bor(network, bit.band(start, bit.bnot(netmask)))
  605.     local ipend = ipstart+numips-1
  606.     ipstart = num2ipv4(ipstart)
  607.     if ipend > ipmax then
  608.       ipend = ipmax
  609.     end
  610.     ipend = num2ipv4(ipend)
  611.     network = num2ipv4(network)
  612.   return ipstart,ipend,network
  613. end
  614.  
  615. local function getDHCPData(object)
  616.   -- Check the entered IP is valid IP and convert it to number
  617.   local baseip = post_helper.validateStringIsIP(object["localdevIP"]) and ipv42num(object["localdevIP"])
  618.   local netmask = post_helper.validateStringIsIP(object["localdevmask"]) and ipv42num(object["localdevmask"])
  619.   local dhcpstart = post_helper.validateStringIsIP(object["dhcpStartAddress"]) and ipv42num(object["dhcpStartAddress"])
  620.   local dhcpend = post_helper.validateStringIsIP(object["dhcpEndAddress"]) and ipv42num(object["dhcpEndAddress"])
  621.  
  622.   return baseip, netmask, dhcpstart, dhcpend
  623. end
  624.  
  625. -- Validation is done for the dhcpLimit for the particular subnet
  626. -- If different subnet mask is given other than 255.255.255.0, then the
  627. -- DHCP Range limit has to be calculated from the new subnet and the validation
  628. -- has to be done for the new limit.
  629. local function validateLimit(value, object)
  630.   if match(value, "^[0-9]*$") then
  631.     local baseip, netmask, dhcpstart, dhcpend = getDHCPData(object)
  632.  
  633.     if not dhcpend then
  634.        return nil, T"DHCP End Address is Invalid"
  635.     end
  636.  
  637.     if dhcpstart and dhcpstart > dhcpend then
  638.        return nil, T"DHCP Start Address should not be greater than End Address"
  639.     end
  640.  
  641.     if baseip and netmask and dhcpstart then
  642.       local network = bit.band(baseip, netmask)
  643.       local ipmax = bit.bor(network, bit.bnot(netmask))
  644.       local numips = dhcpend - dhcpstart + 1
  645.       local limit = ipmax - network - 1
  646.  
  647.       if dhcpend == ipmax then
  648.           return nil, T"Broadcast Address should not be used"
  649.       end
  650.  
  651.       local validatorNumberInRange = post_helper.getValidateNumberInRange(1,limit)
  652.       local limitvalue =  validatorNumberInRange(numips)
  653.       if not limitvalue or dhcpend <= network or dhcpend >= ipmax then
  654.           return nil, T"DHCP End Address is not valid in Subnet Range"
  655.       end
  656.       return true
  657.     else
  658.       return nil
  659.     end
  660.   else
  661.     return nil, T"DHCP End Address is Invalid"
  662.   end
  663. end
  664.  
  665. -- Validation is done for the DHCP start Address for the particular subnet
  666. -- For different subnets, validation for dhcpStart Address has to be done
  667. -- from the new DHCP Range with respect to the subnet mask & Network Address
  668. local function validateDHCPStart(value, object)
  669.     if match(value, "^[0-9]*$") then
  670.       local baseip, netmask, dhcpstart, dhcpend = getDHCPData(object)
  671.  
  672.       if not dhcpstart then
  673.          return nil, T"DHCP Start Address is Invalid"
  674.       end
  675.  
  676.       if baseip and netmask and dhcpend then
  677.         local network = bit.band(baseip, netmask)
  678.         local ipmax = bit.bor(network, bit.bnot(netmask))
  679.         local start = dhcpstart - network
  680.         local numips = dhcpend - dhcpstart + 1
  681.  
  682.         local limit = ipmax - network - 1
  683.  
  684.         local validatorNumberInRange = post_helper.getValidateNumberInRange(1,limit)
  685.  
  686.         if dhcpstart == baseip then
  687.            return nil, T"DHCP Start Address should not be Local Device IP Address"
  688.         elseif dhcpstart == network then
  689.            return nil, T"DHCP Start Address should not be a Network Address"
  690.         end
  691.  
  692.         local val = validatorNumberInRange(start)
  693.         if not val or dhcpstart <= network or dhcpstart >= ipmax then
  694.             return nil, T"DHCP Start Address is not valid in Subnet Range"
  695.         end
  696.  
  697.         -- Setting the dhcpStart and dhcpLimit from the calculated DHCP Range
  698.         object["dhcpStart"] = tostring(start)
  699.         object["dhcpLimit"] = tostring(numips)
  700.  
  701.         return true
  702.       else
  703.         return nil
  704.       end
  705.     else
  706.       return nil, T"DHCP Start Address is Invalid"
  707.     end
  708. end
  709.  
  710. -- This function will validate the Modem IP Address and check for
  711. -- Valid IP Format, Limited Broadcast Address, Public IP Range, Multicast Address Range
  712. local function validateGWIP(value, object, key)
  713.    local val, errmsg = aIPV(value, object, key)
  714.     local post_data = ngx.req.get_post_args()
  715.    if not val then
  716.       return nil, errmsg
  717.    end
  718.  
  719.    local ip = ipv42num(value)
  720.    --<NG-100782
  721.    if isNonPublicIPRange(ip) then
  722.        local ipvalue = post_helper.validateStringIsIP(value) and ipv42num(value)
  723.        local ipmask = post_data["localdevmask"]
  724.        local ipnetmask = post_helper.validateStringIsIP(ipmask) and ipv42num(ipmask)
  725.        
  726.        local ipnetwork, ipmaxvalue
  727.             if ipvalue and ipnetmask then
  728.               ipnetwork = bit.band(ipvalue, ipnetmask)
  729.               ipmaxvalue = bit.bor(ipnetwork, bit.bnot(ipnetmask))
  730.             end
  731.         --NG-100782>
  732.         for _,intf in pairs(all_intfs) do
  733.             if intf.paramindex ~= curintf then
  734.                 local ipaddr = proxy.get("uci.network.interface.@" .. intf.paramindex .. ".ipaddr")[1].value
  735.                 local mask = proxy.get("uci.network.interface.@" .. intf.paramindex .. ".netmask")[1].value
  736.                 local baseip = post_helper.validateStringIsIP(ipaddr) and ipv42num(ipaddr)
  737.                 local netmask = post_helper.validateStringIsIP(mask) and ipv42num(mask)
  738.  
  739.                 local network, ipmax
  740.                 if baseip and netmask then
  741.                   network = bit.band(baseip, netmask)
  742.                   ipmax = bit.bor(network, bit.bnot(netmask))
  743.                 end
  744.            
  745.                 if network and ipmax then
  746.                     if ip >= network and ip <= ipmax then
  747.                         if intf.name ~= "" then
  748.                             return nil, T"Gateway IP should not be in " .. intf.name .. T" IP Range"
  749.                         else
  750.                             return nil, T"Gateway IP should not be in " .. intf.paramindex .. T" IP Range"
  751.                         end
  752.                     end
  753.                 --<NG-100782
  754.                     if ipnetwork <= network and network <= ipmaxvalue then
  755.                         if intf.name ~= "" then
  756.                             return nil, T"The IP address is part of the "..intf.name.." IP Range"
  757.                         else
  758.                             return nil, T"The IP address is part of the "..intf.paramindex.." IP Range"
  759.                         end
  760.                     end
  761.                 --NG-100782>
  762.                 end
  763.             end
  764.         end
  765.    else
  766.     return nil, T"Public IP Range should not be used"
  767.    end
  768.    return true
  769. end
  770.  
  771. local function isChecked(key, checked)
  772.     for _,v in ipairs(checked) do
  773.         if v == key then
  774.             return true
  775.         end
  776.     end
  777.     return false
  778. end
  779.  
  780. local function validateEthports(value, object, key)
  781.     local getValidateEthports = gVIC(ethports)
  782.     local ok, msg = getValidateEthports(value, object, key)
  783.  
  784.     if not ok then
  785.         return ok, msg
  786.     end
  787.  
  788.     for k,v in ipairs(ethports) do
  789.         object[v[1]] = nil
  790.         object[v[1]] = isChecked(v[1], value) and "1" or "0"
  791.     end
  792.  
  793.     return true
  794. end
  795.  
  796. local function validatedhcpIgnore(value, object, key)
  797.   local valid, msg = post_helper.getOptionalValidation(value, object, key)
  798.   if not valid then
  799.     return nil,  msg
  800.   end
  801.   if object["dhcpv4State"] == "server" then
  802.     if object["dhcpIgnore"] == "1" then
  803.       object["dhcpIgnore"] = "0"
  804.     end
  805.   end
  806.   return true
  807. end
  808.  
  809. local dhcpv4Stateselect = {
  810.     {"server"},
  811.     {"disabled"},
  812. }
  813.  
  814. local mapValid = {
  815.     localdevIP = validateGWIP,
  816.     --localIPv6 = validateIPv6,
  817.     dnsServer = validateDNS,
  818.     leaseTime = validateLeaseTime,
  819.     localdevmask = post_helper.getAndValidation(vIP4N,post_helper.validateStringIsIP),
  820.     dhcpStart = validateDHCPStart,
  821.     dhcpLimit = validateLimit,
  822.     dhcpv4State = gVIES(dhcpv4Stateselect),
  823.     dhcpIgnore = validatedhcpIgnore,
  824.     eth0 = vB,
  825.     ethports = validateEthports,
  826. }
  827. if curintf == "lan" then
  828.     mapParams.localIPv6 = "uci.network.interface.@" .. curintf .. ".ipv6"
  829.     mapValid.localIPv6 = validateIPv6
  830. end
  831.  
  832. for i = 1, ethport_count do
  833.   mapValid["eth" .. i] = vB
  834. end
  835.  
  836. -- This is quite convoluted but I only found this way to get it to work.
  837. -- getExactContent will return an error if we access an unknown instance
  838. -- so we cannot load from uci an option if it does not exist
  839. -- in the end we only add the parameter to the parameters list if:
  840. --    - it exists (get or post)
  841. --    - we're doing a post -> in this case, we add an entry and delete it if validation fails
  842. if (dnsIndex < #dhcp.options +1) or ( (ngx.var.request_method == "POST") and (ngx.req.get_post_args().action == "SAVE") ) then
  843.     mapParams["dnsServer"] = baseDHCPOptions .. "@" .. dnsIndex .. ".value"
  844. end
  845. if (dnsIndex == #dhcp.options + 1) and (ngx.var.request_method == "POST") and (ngx.req.get_post_args().action == "SAVE") then
  846.     proxy.add(baseDHCPOptions)
  847. end
  848.  
  849. if ngx.var.request_method == "POST" then
  850. local post_data = ngx.req.get_post_args()
  851.     if post_data["action"] == "RESET" then
  852.     local lanip, lanmask, ipstart, iplimit, ltime, dhcpig = restdhcp()
  853.         proxy.set("uci.network.interface.@"..curintf..".ipaddr",lanip)
  854.         proxy.set("uci.network.interface.@"..curintf..".netmask",lanmask)
  855.         proxy.set("uci.dhcp.dhcp.@"..curintf..".start", ipstart)
  856.         proxy.set("uci.dhcp.dhcp.@"..curintf..".limit", iplimit)
  857.         proxy.set("uci.dhcp.dhcp.@"..curintf..".leasetime", ltime)
  858.         proxy.set("uci.dhcp.dhcp.@"..curintf..".ignore", dhcpig)
  859.         if (dnsIndex < #dhcp.options +1) then
  860.             proxy.set(baseDHCPOptions .. "@" .. dnsIndex .. ".value", "6,"..lanip)
  861.         end
  862.     proxy.apply()
  863.     end
  864. end
  865.  
  866. content, helpmsg = post_helper.handleQuery(mapParams, mapValid)
  867. if (ngx.var.request_method == "POST")  and not next(helpmsg) then
  868.    local dhcp_options_path = "uci.dhcp.dhcp.@"..cur_dhcp_intf..".dhcp_option."
  869.    local dhcp_options = content_helper.convertResultToObject(dhcp_options_path,proxy.get(dhcp_options_path))
  870.     for _,v in ipairs(dhcp_options) do
  871.       if v.value:match("^3,") then
  872.         proxy.del(dhcp_options_path..v.paramindex..".")
  873.       end
  874.     end
  875. end
  876.  
  877. -- because we do the localdevmask validation in localdevIP validation, we check if local ip starts with error msg "[netmask]".
  878. -- If so move it to localdevmask
  879. if helpmsg["localdevIP"] then
  880.   local msg = match(helpmsg["localdevIP"], '^%[netmask%] (.*)')
  881.   if msg then
  882.     helpmsg["localdevIP"] = nil
  883.     helpmsg["localdevmask"] = msg
  884.   end
  885. end
  886. if helpmsg["dhcpLimit"] then
  887.     local msg = match(helpmsg["dhcpLimit"], '^%[dhcpStart%] (.*)')
  888.     if msg then
  889.         helpmsg["dhcpLimit"] = nil
  890.         helpmsg["dhcpStart"] = msg
  891.     end
  892. end
  893.  
  894. -- post_helper restores values that have been removed during validation
  895. -- so if you remove the dns server, it will still be displayed on the page (though correctly set in datamodel)
  896. -- this handles this case
  897. if dnsRemoved then
  898.     content["dnsServer"] = ""
  899. end
  900. if content["dnsServer"] == nil then
  901.     local localIP = proxy.get("uci.network.interface.@" .. curintf .. ".ipaddr")[1].value
  902.     content["dnsServer"] = localIP
  903. else
  904.     if content["dnsServer"]:find("^6,") == 1 then
  905.       content["dnsServer"] = (content["dnsServer"] or ""):sub(3) -- the dhcp option will contain "6," at the start
  906.    end
  907. end
  908.  
  909. if content["dhcpv4State"] == "" then
  910.     content["dhcpv4State"] = "server"
  911. end
  912. if content["localIPv6"] == "" then
  913.     content["localIPv6"] = "0"
  914. end
  915. if content["leaseTime"] == "infinite" then
  916.     content["leaseTime"] = timhelper.ethtrans().eth_infinit
  917. elseif not match(content["leaseTime"],"^0*([1-9]%d*[smhdw])$")then
  918.   content["leaseTime"] = content["leaseTime"] .. "s"
  919. end
  920. local baseip = ipv42num(content["localdevIP"])
  921. local netmask = ipv42num(content["localdevmask"])
  922. local start = tonumber(content["dhcpStart"])
  923. local numips = tonumber(content["dhcpLimit"])
  924. local ipstart,ipend,network
  925. if start and numips and not helpmsg["localdevIP"] and not helpmsg["localdevmask"] and not helpmsg["dhcpStart"] and not helpmsg["dhcpLimit"] then
  926.   ipstart,ipend,network = calculateDHCPStartAddress(baseip,netmask,start,numips)
  927.   session:store("dhcpStartAddr",ipstart)
  928.   session:store("dhcpEndAddr",ipend)
  929.   session:store("networkAddr",network)
  930. else
  931.   ipstart = ngx.req.get_post_args().dhcpStartAddress
  932.   ipend = ngx.req.get_post_args().dhcpEndAddress
  933.   network = session:retrieve("networkAddr")
  934.  end
  935. if helpmsg["leaseTime"] then
  936.   content["leaseTime"] = ngx.req.get_post_args().leaseTime
  937. end
  938.   if ngx.var.request_method == "POST" then
  939.     local gwIP = session:retrieve("old_ip")
  940.     session:store("old_ip",(content["localdevIP"]))
  941.  
  942.   -- Redirect the GUI only if the local GW device IP address is changed for the "lan" interface
  943.   if curintf == "lan" and content["localdevIP"]~= gwIP and not next(helpmsg) then  ngx.print('\
  944.    <script type="text/javascript">\
  945.      window.location="http://');  ngx.print(content["localdevIP"]); ngx.print('";\
  946.    </script>\
  947.    ');  session:logout()
  948.   end
  949. else
  950.   session:store("old_ip",(content["localdevIP"]))
  951. end
  952.  
  953. local ethports_checked = {}
  954. if type(content) == "table" then
  955.     for _,v in ipairs(ethports) do
  956.         if (content[v[1]] == "1") then
  957.             ethports_checked[#ethports_checked + 1] = v[1]
  958.         end
  959.     end
  960. end
  961.  
  962.   ngx.print('\
  963. \
  964. ');  ngx.print(ui_helper.createHeader(T"Local Network", true, false))   ngx.print('\
  965. \
  966.   <div class="modal-body update">\
  967.     <form class="form-horizontal" method="post" action="');  ngx.print( ngx.var.request_uri ); ngx.print('">\
  968.     ');  
  969.      -- Do not display the navlist on the list if only 1 lan interface
  970.      if #lan_intfs> 1 then
  971.        ngx.print('\
  972.     <div class="span2">\
  973.        <ul class="nav nav-list">\
  974.        ');  
  975.         local html = { format('<li class="nav-header">%s</li>', T"LAN Interfaces") }
  976.         for k,v in ipairs(lan_intfs) do
  977.             local prev = ""
  978.             if v.radio ~= prev then
  979.                 if v.radio ~= "noradio" then
  980.                     html[#html + 1] = format('<li class="nav-header">%s %s</li>', T"Access point", v.radio)
  981.                 else
  982.                     html[#html + 1] = format('<li class="nav-header">%s</li>', T"Ethernet")
  983.                 end
  984.                    
  985.             end
  986.             local active = ""
  987.             if v.index == curintf then
  988.                 active = "active"
  989.             end
  990.             local url = "modals/ethernet-modal.lp?intf=" .. v.index
  991.             html[#html+1] = format('<li class="%s"><a id = "%s" href="#" data-remote="%s">%s</a></li>', active, v.index, url, v.name)
  992.         end
  993.         ngx.print(html)
  994.           ngx.print('\
  995.        </ul>\
  996.     </div>\
  997.     <div class="span6">\
  998.        ');  
  999.         end
  1000.         ngx.print(ui_helper.createMessages(message_helper.popMessages()))
  1001.           ngx.print('\
  1002.          <fieldset>\
  1003.              <legend>');  ngx.print( T"Global Information" ); ngx.print('</legend>\
  1004.              ');  
  1005.               local advanced = {
  1006.                 group = {
  1007.                   class = "advanced hide"
  1008.                 }
  1009.               }
  1010.  
  1011.               -- Labels that shows the Local Device IP address & network subnet
  1012.                 local html = {}
  1013.              
  1014.                 html[#html + 1] = ui_helper.createInputText(T"Local Device IP address", "localdevIP", content["localdevIP"],{},helpmsg["localdevIP"])
  1015.                 html[#html + 1] = ui_helper.createInputText(T"Local Network subnet", "localdevmask", content["localdevmask"], advanced, helpmsg["localdevmask"])
  1016.                 html[#html + 1] =ui_helper.createButton(T"Reset to default", T"Reset", "icon-bolt", clear_network_stats)
  1017.                 if curintf == "lan" then
  1018.                     html[#html + 1] = ui_helper.createSwitch(T"IPv6 state", "localIPv6", content["localIPv6"])
  1019.                     if curintf == "lan" and tech then
  1020.                         html[#html + 1] = ui_helper.createCheckboxGroup(T"Ethernet Ports enabled", "ethports", ethports, ethports_checked, {checkbox = { class="inline" }}, nil)
  1021.                     end
  1022.                     local IPv6addr = proxy.get("rpc.network.interface.@"..curintf..".ip6addr")[1].value
  1023.                     if IPv6addr == "" then
  1024.                         html[#html + 1] = ui_helper.createLabel(T"LAN IPv6", T"IPv6 not assigned", advanced)
  1025.                     else
  1026.                     html[#html + 1] = ui_helper.createLabel(T"LAN IPv6", IPv6addr, advanced)
  1027.                     end
  1028.                 end
  1029.                 ngx.print(html)
  1030.                 ngx.print('\
  1031.              <legend>');  ngx.print( T"DHCP Settings" ); ngx.print('</legend>\
  1032.              ');  
  1033.                 -- Labels that shows DHCP info
  1034.                 local switchDHCP = {
  1035.                   values = {
  1036.                     on = "server",
  1037.                     off = "disabled"
  1038.                   }
  1039.                 }
  1040.               ngx.print(
  1041.                   ui_helper.createSwitch(T"DHCP Server", "dhcpv4State", content["dhcpv4State"],switchDHCP),
  1042.                   ui_helper.createLabel(T"Network address", network, advanced),
  1043.                   ui_helper.createInputText(T"DHCP Start address", "dhcpStartAddress", ipstart, advanced, helpmsg["dhcpStart"]),
  1044.                   ui_helper.createInputText(T"DHCP End address", "dhcpEndAddress", ipend, advanced, helpmsg["dhcpLimit"]),
  1045.                   ui_helper.createInputText(T"Lease time", "leaseTime", content["leaseTime"], advanced, helpmsg["leaseTime"]),
  1046.                   ui_helper.createInputText(T"DNS server", "dnsServer", content["dnsServer"], advanced, helpmsg["dnsServer"])
  1047.                 )
  1048.                  ngx.print('\
  1049.               ');  
  1050.                  --[[if dhcpDefaultExist then
  1051.                     local wait_for_reset = {
  1052.                         group = {
  1053.                            class = "advanced hide"
  1054.                         },
  1055.                         button = {
  1056.                            id = "btn-dhcp-reset"
  1057.                         }
  1058.                     }
  1059.                     ngx.print(ui_helper.createButton(T"Restore Default Configuration", T"Reset Configuration", "icon-bolt", wait_for_reset))
  1060.                  end]]
  1061.                  ngx.print('\
  1062.              ');  
  1063.               -- Do not display the static lease when the interface is not lan
  1064.               if curintf == "lan" then
  1065.                 ngx.print('\
  1066.                  <legend>');  ngx.print( T"Static leases" ); ngx.print('</legend>\
  1067.                  ');  
  1068.                     local confilictipchange_alert = {
  1069.                       alert = {
  1070.                           class = "alert hide",
  1071.                           id = "confilictipchange-msg"
  1072.                       }
  1073.                     }
  1074.                     ngx.print(
  1075.                       ui_helper.createAlertBlock(T"The latest added/modified static lease is set to an IP that is already in use, please perform a reboot to apply the changes", confilictipchange_alert),
  1076.                       ui_helper.createTable(sleases_columns, sleases_data, sleases_options, nil, sleases_helpmsg))
  1077.                 ngx.print('\
  1078.              </fieldset>\
  1079.              ');  
  1080.               end
  1081.                 ngx.print('\
  1082.          ');  
  1083.           -- Do not display the navlist on the list if only 1 lan interface
  1084.           if #lan_intfs > 1 then
  1085.             ngx.print('\
  1086.          </div>\
  1087.          ');  
  1088.           end
  1089.             ngx.print('\
  1090.          <input type="hidden" name="isAdvanced" id="isAdvanced" value="0">\
  1091.        </form>\
  1092.   </div>\
  1093. \
  1094. <script type=\'text/javascript\'>\
  1095. $(function() {\
  1096.    var iPv6StateOnlyChanged = 0;\
  1097.    $("input, select").on("change", function(){\
  1098.       if(this.id == "localIPv6" && iPv6StateOnlyChanged == 0)\
  1099.         iPv6StateOnlyChanged = 1;\
  1100.       else\
  1101.         iPv6StateOnlyChanged = 2;\
  1102.    });\
  1103.    //Override the save button click event to update the IPv6 state alone.\
  1104.    $("#save-config").click(function(){\
  1105.         if(iPv6StateOnlyChanged == 1){\
  1106.          var params = [];\
  1107.          params.push({\
  1108.            name : "action",\
  1109.            value : "SAVE"\
  1110.          },\
  1111.          {\
  1112.            name : "iPv6StateOnlyChanged",\
  1113.            value : "yes"\
  1114.          },\
  1115.          {\
  1116.            name : "localIPv6",\
  1117.            value : $("#localIPv6").val()\
  1118.          }, tch.elementCSRFtoken());\
  1119.          var target = $(".modal form").attr("action");\
  1120.          tch.showProgress(waitMsg);\
  1121.          $.post(target, params, function(response){\
  1122.            //The following block of code used to display the success/error message and manage the footer.\
  1123.            $(".alert").remove();\
  1124.            $("form").prepend(response);\
  1125.            $("#modal-changes").attr("style","display:none");\
  1126.            $("#modal-no-change").attr("style","display:block");\
  1127.            iPv6StateOnlyChanged = 0;\
  1128.            tch.removeProgress();\
  1129.          });\
  1130.          return false;\
  1131.         }\
  1132.     });\
  1133. \
  1134.    var currentlanip = "');  ngx.print( content["localdevIP"] ); ngx.print('";\
  1135.    $("[name=\'localdevIP\']").change(function(){\
  1136.      if (currentlanip == $("[name=\'dnsServer\']").val()){\
  1137.          $("[name=\'dnsServer\']").val($(this).val());\
  1138.          currentlanip = $(this).val();\
  1139.      }\
  1140.    });\
  1141. \
  1142.    $("#save-config").click(function(){\
  1143.      if($("#Hide_Advanced_id").is(":visible"))\
  1144.        $("#isAdvanced").val("1");\
  1145.      else\
  1146.        $("#isAdvanced").val("0");\
  1147.    });\
  1148. \
  1149. });\
  1150. $("[name =\'sleases_mac\']").change(function () {\
  1151.    if ((this.value) == "custom") {\
  1152.          $(this).replaceWith($(\'<input/>\',{\'type\':\'text\', \'name\':\'sleases_mac\'}));\
  1153.    }\
  1154. });\
  1155. \
  1156. ');  if dhcpDefaultExist then   ngx.print('\
  1157. $("#btn-dhcp-reset").click(function(){\
  1158.  ');  for k,v in pairs(dhcpDefaultExist) do   ngx.print('\
  1159.    $("#');  ngx.print(k); ngx.print('").val("');  ngx.print(v); ngx.print('");\
  1160.  ');  end  ngx.print('\
  1161.  $("#localIPv6").prev().removeClass("switcherOn").closest(".switch").removeClass("switchOn");\
  1162.  $("#dhcpState").prev().addClass("switcherOn").closest(".switch").addClass("switchOn");\
  1163.  $("#modal-changes").show();\
  1164.  $("#modal-no-change").hide();\
  1165. });\
  1166. ');  end  ngx.print('\
  1167.  ');  if inUseFlag == true then  ngx.print('\
  1168.  $("#confilictipchange-msg").show();\
  1169.  ');  end   ngx.print('\
  1170. </script>\
  1171. \
  1172. ');  ngx.print(ui_helper.createFooter())   ngx.print('\
  1173. ');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement