diff options
author | Dirk Brenken <dev@brenken.org> | 2018-11-24 16:33:54 +0100 |
---|---|---|
committer | Dirk Brenken <dev@brenken.org> | 2018-11-26 13:19:52 +0100 |
commit | 0f8e36f21416805f8dc2f0932db1bb81f1ccf39f (patch) | |
tree | 9b1aeaaafb4918d7077432b82d82ae10789ad622 /applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua | |
parent | 4bd7f4ba429eee697fb5f75c4ece5d03cc9514f5 (diff) |
luci-app-openvpn: "final" changeset
* add 'auth-user-pass' edit section in file mode (see screenshot)
* add port & protocol detection in file mode (see screenshot)
* don't mix file & normal edit modes any longer
* add CC compatibility fix (for turris devices)
* fix/refine JS instance name filter
* remove needless CSS rules
* unlink ovpn/auth files on section removal
* commit changes instantly (Add/Upload/Delete)
Signed-off-by: Dirk Brenken <dev@brenken.org>
Diffstat (limited to 'applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua')
-rw-r--r-- | applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua index ad607ae6c2..41266d860e 100644 --- a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua +++ b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua @@ -69,10 +69,14 @@ function s.create(self, name) local options = uci:get_all("openvpn_recipes", recipe) for k, v in pairs(options) do if k ~= "_role" and k ~= "_description" then + if type(v) == "boolean" then + v = v and "1" or "0" + end uci:set("openvpn", name, k, v) end end uci:save("openvpn") + uci:commit("openvpn") if extedit then luci.http.redirect( self.extedit:format(name) ) end @@ -80,10 +84,23 @@ function s.create(self, name) elseif #name > 0 then self.invalid_cts = true end - return 0 end +function s.remove(self, name) + local cfg_file = "/etc/openvpn/" ..name.. ".ovpn" + local auth_file = "/etc/openvpn/" ..name.. ".auth" + if fs.access(cfg_file) then + fs.unlink(cfg_file) + end + if fs.access(auth_file) then + fs.unlink(auth_file) + end + uci:delete("openvpn", name) + uci:save("openvpn") + uci:commit("openvpn") +end + s:option( Flag, "enabled", translate("Enabled") ) local active = s:option( DummyValue, "_active", translate("Started") ) @@ -124,12 +141,30 @@ end local port = s:option( DummyValue, "port", translate("Port") ) function port.cfgvalue(self, section) local val = AbstractValue.cfgvalue(self, section) + if not val then + local file_cfg = self.map:get(section, "config") + if file_cfg and fs.access(file_cfg) then + val = sys.exec("awk '{if(match(tolower($1),/^port$/)&&match($2,/[0-9]+/)){cnt++;printf $2;exit}}END{if(cnt==0)printf \"-\"}' " ..file_cfg) + if val == "-" then + val = sys.exec("awk '{if(match(tolower($1),/^remote$/)&&match($3,/[0-9]+/)){cnt++;printf $3;exit}}END{if(cnt==0)printf \"-\"}' " ..file_cfg) + end + end + end return val or "-" end local proto = s:option( DummyValue, "proto", translate("Protocol") ) function proto.cfgvalue(self, section) local val = AbstractValue.cfgvalue(self, section) + if not val then + local file_cfg = self.map:get(section, "config") + if file_cfg and fs.access(file_cfg) then + val = sys.exec("awk '{if(match(tolower($1),/^proto$/)&&match(tolower($2),/^udp[46]*$|^tcp[46]*-server$|^tcp[46]*-client$/)){cnt++;printf tolower($2);exit}}END{if(cnt==0)printf \"-\"}' " ..file_cfg) + if val == "-" then + val = sys.exec("awk '{if(match(tolower($1),/^remote$/)&&match(tolower($4),/^udp[46]*$|^tcp[46]*-server$|^tcp[46]*-client$/)){cnt++;printf $4;exit}}END{if(cnt==0)printf \"-\"}' " ..file_cfg) + end + end + end return val or "-" end |