X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=applications%2Fluci-openvpn%2Fluasrc%2Fmodel%2Fcbi%2Fopenvpn.lua;h=0fa60fd0292dd2f6656c6fd168221b2bdbeb869f;hb=fc862361804f67784c1fb7491366032aaf137f50;hp=22cdcb4d6ed65c66f5d549e4253dfa9b14afea9c;hpb=7fe7d6d5e654d2092f89d81b0e1627fb99eb1a74;p=project%2Fluci.git diff --git a/applications/luci-openvpn/luasrc/model/cbi/openvpn.lua b/applications/luci-openvpn/luasrc/model/cbi/openvpn.lua index 22cdcb4d6..0fa60fd02 100644 --- a/applications/luci-openvpn/luasrc/model/cbi/openvpn.lua +++ b/applications/luci-openvpn/luasrc/model/cbi/openvpn.lua @@ -12,16 +12,12 @@ You may obtain a copy of the License at $Id$ ]]-- -require("luci.fs") -require("luci.ip") -require("luci.sys") -require("luci.model.uci") +local fs = require "nixio.fs" +local sys = require "luci.sys" +local uci = require "luci.model.uci".cursor() - -local uci = luci.model.uci.cursor() - -local m = Map("openvpn") -local s = m:section( TypedSection, "openvpn" ) +local m = Map("openvpn", translate("OpenVPN")) +local s = m:section( TypedSection, "openvpn", translate("OpenVPN instances"), translate("Below is a list of configured OpenVPN instances and their current state") ) s.template = "cbi/tblsection" s.template_addremove = "openvpn/cbi-select-input-add" s.addremove = true @@ -57,39 +53,63 @@ function s.create(self, name) self.sectiontype .. ".select" ) - uci:section( - "openvpn", "openvpn", name, - uci:get_all( "openvpn_recipes", recipe ) - ) + if name and not name:match("[^a-zA-Z0-9_]") then + uci:section( + "openvpn", "openvpn", name, + uci:get_all( "openvpn_recipes", recipe ) + ) - uci:delete("openvpn", name, "_role") - uci:delete("openvpn", name, "_description") - uci:save("openvpn") + uci:delete("openvpn", name, "_role") + uci:delete("openvpn", name, "_description") + uci:save("openvpn") - luci.http.redirect( self.extedit:format(name) ) + luci.http.redirect( self.extedit:format(name) ) + else + self.invalid_cts = true + end end -s:option( Flag, "enable" ) +s:option( Flag, "enabled", translate("Enabled") ) -local active = s:option( DummyValue, "_active" ) +local active = s:option( DummyValue, "_active", translate("Started") ) function active.cfgvalue(self, section) - if luci.fs.isfile("/var/run/openvpn_%s.pid" % section) then - local pid = io.lines("/var/run/openvpn_%s.pid" % section)() - if pid and #pid > 0 and tonumber(pid) ~= nil then - return (luci.sys.process.signal(pid, 0)) and "yes (" .. pid .. ")" or "no" - end + local pid = fs.readfile("/var/run/openvpn-%s.pid" % section) + if pid and #pid > 0 and tonumber(pid) ~= nil then + return (sys.process.signal(pid, 0)) + and translatef("yes (%i)", pid) + or translate("no") + end + return translate("no") +end + +local updown = s:option( Button, "_updown", translate("Start/Stop") ) +updown._state = false +function updown.cbid(self, section) + local pid = fs.readfile("/var/run/openvpn-%s.pid" % section) + self._state = pid and #pid > 0 and sys.process.signal(pid, 0) + self.option = self._state and "stop" or "start" + return AbstractValue.cbid(self, section) +end +function updown.cfgvalue(self, section) + self.title = self._state and "stop" or "start" + self.inputstyle = self._state and "reset" or "reload" +end +function updown.write(self, section, value) + if self.option == "stop" then + luci.sys.call("/etc/init.d/openvpn down %s" % section) + else + luci.sys.call("/etc/init.d/openvpn up %s" % section) end - return "no" end -local port = s:option( DummyValue, "port" ) +local port = s:option( DummyValue, "port", translate("Port") ) function port.cfgvalue(self, section) local val = AbstractValue.cfgvalue(self, section) return val or "1194" end -local proto = s:option( DummyValue, "proto" ) +local proto = s:option( DummyValue, "proto", translate("Protocol") ) function proto.cfgvalue(self, section) local val = AbstractValue.cfgvalue(self, section) return val or "udp"