portconfig.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. --[[
  2. LuCI - Lua Configuration Interface
  3. Copyright 2014 Nils Schneider <nils@nilsschneider.net>
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. $Id$
  9. ]]--
  10. local uci = luci.model.uci.cursor()
  11. local sysconfig = require 'gluon.sysconfig'
  12. local wan = uci:get_all("network", "wan")
  13. local wan6 = uci:get_all("network", "wan6")
  14. local dns = uci:get_first("gluon-wan-dnsmasq", "static")
  15. local f = SimpleForm("portconfig", translate("WAN connection"))
  16. f.template = "admin/expertmode"
  17. local s
  18. local o
  19. s = f:section(SimpleSection, nil, nil)
  20. o = s:option(ListValue, "ipv4", translate("IPv4"))
  21. o:value("dhcp", translate("Automatic (DHCP)"))
  22. o:value("static", translate("Static"))
  23. o:value("none", translate("Disabled"))
  24. o.default = wan.proto
  25. o = s:option(Value, "ipv4_addr", translate("IP address"))
  26. o:depends("ipv4", "static")
  27. o.value = wan.ipaddr
  28. o.datatype = "ip4addr"
  29. o.rmempty = false
  30. o = s:option(Value, "ipv4_netmask", translate("Netmask"))
  31. o:depends("ipv4", "static")
  32. o.value = wan.netmask or "255.255.255.0"
  33. o.datatype = "ip4addr"
  34. o.rmempty = false
  35. o = s:option(Value, "ipv4_gateway", translate("Gateway"))
  36. o:depends("ipv4", "static")
  37. o.value = wan.gateway
  38. o.datatype = "ip4addr"
  39. o.rmempty = false
  40. s = f:section(SimpleSection, nil, nil)
  41. o = s:option(ListValue, "ipv6", translate("IPv6"))
  42. o:value("dhcpv6", translate("Automatic (RA/DHCPv6)"))
  43. o:value("static", translate("Static"))
  44. o:value("none", translate("Disabled"))
  45. o.default = wan6.proto
  46. o = s:option(Value, "ipv6_addr", translate("IP address"))
  47. o:depends("ipv6", "static")
  48. o.value = wan6.ip6addr
  49. o.datatype = "ip6addr"
  50. o.rmempty = false
  51. o = s:option(Value, "ipv6_gateway", translate("Gateway"))
  52. o:depends("ipv6", "static")
  53. o.value = wan6.ip6gw
  54. o.datatype = "ip6addr"
  55. o.rmempty = false
  56. if dns then
  57. s = f:section(SimpleSection, nil, nil)
  58. o = s:option(DynamicList, "dns", translate("Static DNS servers"))
  59. o:write(nil, uci:get("gluon-wan-dnsmasq", dns, "server"))
  60. o.datatype = "ipaddr"
  61. end
  62. s = f:section(SimpleSection, nil, nil)
  63. o = s:option(Flag, "mesh_wan", translate("Enable meshing on the WAN interface"))
  64. o.default = uci:get_bool("network", "mesh_wan", "auto") and o.enabled or o.disabled
  65. o.rmempty = false
  66. if sysconfig.lan_ifname then
  67. o = s:option(Flag, "mesh_lan", translate("Enable meshing on the LAN interface"))
  68. o.default = uci:get_bool("network", "mesh_lan", "auto") and o.enabled or o.disabled
  69. o.rmempty = false
  70. end
  71. function f.handle(self, state, data)
  72. if state == FORM_VALID then
  73. uci:set("network", "wan", "proto", data.ipv4)
  74. if data.ipv4 == "static" then
  75. uci:set("network", "wan", "ipaddr", data.ipv4_addr)
  76. uci:set("network", "wan", "netmask", data.ipv4_netmask)
  77. uci:set("network", "wan", "gateway", data.ipv4_gateway)
  78. else
  79. uci:delete("network", "wan", "ipaddr")
  80. uci:delete("network", "wan", "netmask")
  81. uci:delete("network", "wan", "gateway")
  82. end
  83. uci:set("network", "wan6", "proto", data.ipv6)
  84. if data.ipv6 == "static" then
  85. uci:set("network", "wan6", "ip6addr", data.ipv6_addr)
  86. uci:set("network", "wan6", "ip6gw", data.ipv6_gateway)
  87. else
  88. uci:delete("network", "wan6", "ip6addr")
  89. uci:delete("network", "wan6", "ip6gw")
  90. end
  91. uci:set("network", "mesh_wan", "auto", data.mesh_wan)
  92. if sysconfig.lan_ifname then
  93. uci:set("network", "mesh_lan", "auto", data.mesh_lan)
  94. if data.mesh_lan == '1' then
  95. uci:set("network", "client", "ifname", "bat0")
  96. else
  97. uci:set("network", "client", "ifname", sysconfig.lan_ifname .. " bat0")
  98. end
  99. end
  100. uci:save("network")
  101. uci:commit("network")
  102. if dns then
  103. if #data.dns > 0 then
  104. uci:set("gluon-wan-dnsmasq", dns, "server", data.dns)
  105. else
  106. uci:delete("gluon-wan-dnsmasq", dns, "server")
  107. end
  108. uci:save("gluon-wan-dnsmasq")
  109. uci:commit("gluon-wan-dnsmasq")
  110. end
  111. end
  112. return true
  113. end
  114. return f