+-- We might modify these configs too:
+m:chain("network")
+m:chain("firewall")
+
+function m.on_after_commit(self)
+ uci:apply(true)
+ luci.http.redirect(luci.dispatcher.build_url("admin", "services", "travelmate"))
+end
+
+-- Interface Wizard
+
+if uplink == "" then
+ ds = m:section(NamedSection, "global", "travelmate", translate("Interface Wizard"))
+
+ o = ds:option(Value, "", translate("Uplink interface"))
+ o.datatype = "and(uciname,rangelength(3,15))"
+ o.default = trmiface
+ o.rmempty = false
+
+ btn = ds:option(Button, "trm_iface", translate("Create Uplink Interface"),
+ translate("Create a new wireless wan uplink interface, 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(self, section)
+ -- Do uci changes. Note that we must not commit here as the rollback handler
+ -- needs to see "unsaved changes" in order to roll them back.
+ local iface = o:formvalue(section)
+ if iface then
+ uci:set("travelmate", section, "trm_iface", iface)
+ local net = nw:add_network(iface, { proto = "dhcp" })
+ if net then
+ local zone = fw:get_zone_by_network("wan")
+ if zone then
+ zone:add_network(iface)
+ end
+ end
+ end
+
+ -- Since we're prematurely terminating the cbi logic flow here and since we trigger
+ -- our modifications in a button write callback and not via cbi.apply, we do need to
+ -- tell cbi to trigger apply/rollback.
+ m.flow.autoapply = true
+ end
+ return m
+end
+