luci-app-travelmate: sync with travelmate 0.7.2
authorDirk Brenken <dev@brenken.org>
Sun, 7 May 2017 16:57:08 +0000 (19:57 +0300)
committerHannu Nyman <hannu.nyman@iki.fi>
Sun, 7 May 2017 16:57:08 +0000 (19:57 +0300)
* simplify uplink interface setup (just one Click! ;-),
  now part of the overview tab (removed separate setup page!)
* cosmetics

Signed-off-by: Dirk Brenken <dev@brenken.org>
Conflict resolved by Hannu Nyman

applications/luci-app-travelmate/luasrc/controller/travelmate.lua
applications/luci-app-travelmate/luasrc/model/cbi/travelmate/configuration_tab.lua
applications/luci-app-travelmate/luasrc/model/cbi/travelmate/overview_tab.lua
applications/luci-app-travelmate/luasrc/model/cbi/travelmate/setup_tab.lua [deleted file]

index 4286b80..86382f6 100644 (file)
@@ -12,15 +12,14 @@ function index()
        if not nixio.fs.access("/etc/config/travelmate") then
                return
        end
-       entry({"admin", "services", "travelmate"}, firstchild(), _("Travelmate"), 30).dependent = false
-       entry({"admin", "services", "travelmate", "tab_from_cbi"}, cbi("travelmate/overview_tab"), _("Overview"), 10).leaf = true
+       entry({"admin", "services", "travelmate"}, firstchild(), _("Travelmate"), 40).dependent = false
+       entry({"admin", "services", "travelmate", "tab_from_cbi"}, cbi("travelmate/overview_tab", {hideresetbtn=true, hidesavebtn=true}), _("Overview"), 10).leaf = true
        entry({"admin", "services", "travelmate", "logfile"}, call("logread"), _("View Logfile"), 20).leaf = true
        entry({"admin", "services", "travelmate", "advanced"}, firstchild(), _("Advanced"), 100)
-       entry({"admin", "services", "travelmate", "advanced", "setup"}, cbi("travelmate/setup_tab"), _("Setup WWAN Interface"), 110).leaf = true
-       entry({"admin", "services", "travelmate", "advanced", "configuration"}, cbi("travelmate/configuration_tab"), _("Edit Travelmate Configuration"), 120).leaf = true
-       entry({"admin", "services", "travelmate", "advanced", "cfg_wireless"}, cbi("travelmate/cfg_wireless_tab"), _("Edit Wireless Configuration"), 130).leaf = true
-       entry({"admin", "services", "travelmate", "advanced", "cfg_network"}, cbi("travelmate/cfg_network_tab"), _("Edit Network Configuration"), 140).leaf = true
-       entry({"admin", "services", "travelmate", "advanced", "cfg_firewall"}, cbi("travelmate/cfg_firewall_tab"), _("Edit Firewall Configuration"), 150).leaf = true
+       entry({"admin", "services", "travelmate", "advanced", "configuration"}, cbi("travelmate/configuration_tab"), _("Edit Travelmate Configuration"), 110).leaf = true
+       entry({"admin", "services", "travelmate", "advanced", "cfg_wireless"}, cbi("travelmate/cfg_wireless_tab"), _("Edit Wireless Configuration"), 120).leaf = true
+       entry({"admin", "services", "travelmate", "advanced", "cfg_network"}, cbi("travelmate/cfg_network_tab"), _("Edit Network Configuration"), 130).leaf = true
+       entry({"admin", "services", "travelmate", "advanced", "cfg_firewall"}, cbi("travelmate/cfg_firewall_tab"), _("Edit Firewall Configuration"), 140).leaf = true
 end
 
 function logread()
index 6e9e287..4233da6 100644 (file)
@@ -7,6 +7,8 @@ local trminput = "/etc/config/travelmate"
 
 if not nixio.fs.access(trminput) then
        m = SimpleForm("error", nil, translate("Input file not found, please check your configuration."))
+       m.reset = false
+       m.submit = false
        return m
 end
 
index 085d413..6b07aab 100644 (file)
@@ -3,18 +3,18 @@
 
 local fs = require("nixio.fs")
 local uci = require("uci")
-local sys = require("luci.sys")
 local json = require("luci.jsonc")
+local nw  = require("luci.model.network").init()
+local fw  = require("luci.model.firewall").init()
+local uplink = uci.get("network", "trm_wwan") or ""
 local trminput = uci.get("travelmate", "global", "trm_rtfile") or "/tmp/trm_runtime.json"
 local parse = json.parse(fs.readfile(trminput) or "")
 
 m = Map("travelmate", translate("Travelmate"),
        translate("Configuration of the travelmate package to to enable travel router functionality. ")
-       .. translate("For further information ")
-       .. [[<a href="https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md" target="_blank">]]
-       .. translate("see online documentation")
-       .. [[</a>]]
-       .. translate("."))
+       .. translatef("For further information "
+       .. "<a href=\"%s\" target=\"_blank\">"
+       .. "see online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/travelmate/files/README.md"))
 
 -- Main travelmate options
 
@@ -44,6 +44,42 @@ o5 = s:option(Flag, "trm_debug", translate("Enable verbose debug logging"))
 o5.default = o5.disabled
 o5.rmempty = false
 
+-- Interface setup
+
+if uplink == "" then
+       dv = s:option(DummyValue, "_dummy", translate("Interface Setup"))
+       dv.template = "cbi/nullsection"
+       btn = s:option(Button, "", translate("Create Uplink Interface"),
+               translate("Automatically create a new wireless wan uplink interface 'trm_wwan', configure it to use dhcp and ")
+               .. translate("add it to the wan zone of the firewall. This step has only to be done once."))
+       btn.inputtitle = translate("Add Interface")
+       btn.inputstyle = "apply"
+       btn.disabled = false
+       function btn.write()
+               local name = "trm_wwan"
+               local net = nw:add_network(name, { proto = "dhcp" })
+               if net then
+                       nw:save("network")
+                       nw:commit("network")
+                       local zone = fw:get_zone_by_network("wan")
+                       if zone then
+                               zone:add_network(name)
+                               fw:save("firewall")
+                               fw:commit("firewall")
+                       end
+                       luci.sys.call("env -i /bin/ubus call network reload >/dev/null 2>&1")
+                       luci.http.redirect(luci.dispatcher.build_url("admin", "services", "travelmate"))
+               end
+       end
+else
+       dv = s:option(DummyValue, "_dummy", translate("Interface Setup"),
+               translate("<br />&nbsp;Network Interface 'trm_wwan' created successfully. ")
+               .. translatef("Scan &amp; Add new wireless stations via standard "
+               .. "<a href=\"%s\">"
+               .. "Wireless Setup</a>", luci.dispatcher.build_url("admin/network/wireless")))
+       dv.template = "cbi/nullsection"
+end
+
 -- Runtime information
 
 ds = s:option(DummyValue, "_dummy", translate("Runtime information"))
diff --git a/applications/luci-app-travelmate/luasrc/model/cbi/travelmate/setup_tab.lua b/applications/luci-app-travelmate/luasrc/model/cbi/travelmate/setup_tab.lua
deleted file mode 100644 (file)
index 6cd030c..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
--- Copyright 2017 Dirk Brenken (dev@brenken.org)
--- This is free software, licensed under the Apache License, Version 2.0
-
-local nw  = require("luci.model.network").init()
-local fw  = require("luci.model.firewall").init()
-local util = require("luci.util")
-local uci = require("luci.model.uci").cursor()
-
-m = SimpleForm("network", translate("Interface Setup"),
-       translate("Automatically create a new wireless wan interface, configure it to use dhcp and " ..
-       "add it to the wan zone of the firewall. This step has only to be done once."))
-m.reset = false
-
-iface = m:field(Value, "netname", translate("Name of the new wireless wan interface"),
-       translate("The allowed characters are: <code>A-Z</code>, <code>a-z</code>, " ..
-               "<code>0-9</code> and <code>_</code> (3-15 characters)."))
-iface.default = "wwan"
-iface.datatype = "and(uciname,minlength(3),maxlength(15))"
-
-function iface.validate(self, value, section)
-       local value = iface:formvalue(section)
-       local name = uci.get("network", value)
-       if name then
-               iface:add_error(section, translate("The given network interface name already exist"))
-       else
-               iface.datatype = false
-               iface.default = iface.disabled
-               f = m:field(DummyValue, "textfield", "&nbsp;", translatef("Direct Link: "
-                       .. "<a href=\"%s\">"
-                       .. "Wireless Setup</a>", luci.dispatcher.build_url("admin/network/wireless")))
-               f.default = translatef("Network Interface '%s' created successfully." ..
-                                       " Feel free to scan & add new stations via standard wireless setup.", value)
-               f.disabled = true
-       end
-       return value
-end
-
-function iface.write(self, section, value)
-       local name = iface:formvalue(section)
-       if name then
-               local net = nw:add_network(name, { proto = "dhcp" })
-               if net then
-                       nw:save("network")
-                       nw:commit("network")
-                       local zone = fw:get_zone_by_network("wan")
-                       if zone then
-                               zone:add_network(name)
-                               fw:save("firewall")
-                               fw:commit("firewall")
-                       end
-               end
-       end
-end
-
-return m