diff options
Diffstat (limited to 'applications/luci-app-openvpn/luasrc/model')
3 files changed, 17 insertions, 8 deletions
diff --git a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn-advanced.lua b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn-advanced.lua index af515fc59a..1bbee83c35 100644 --- a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn-advanced.lua +++ b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn-advanced.lua @@ -235,7 +235,6 @@ for _, option in ipairs(params) do o.value = option[3] else if option[1] == DynamicList then - o.cast = nil function o.cfgvalue(...) local val = AbstractValue.cfgvalue(...) return ( val and type(val) ~= "table" ) and { val } or val diff --git a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn-basic.lua b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn-basic.lua index 8385839a8f..aaa1979c41 100644 --- a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn-basic.lua +++ b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn-basic.lua @@ -62,7 +62,6 @@ for _, option in ipairs(basicParams) do o.value = option[3] else if option[1] == DynamicList then - o.cast = nil function o.cfgvalue(...) local val = AbstractValue.cfgvalue(...) return ( val and type(val) ~= "table" ) and { val } or val diff --git a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua index 8b2ce5a85a..719145b887 100644 --- a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua +++ b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua @@ -25,6 +25,15 @@ uci:foreach( "openvpn_recipes", "openvpn_recipe", end ) +function s.getPID(section) -- Universal function which returns valid pid # or nil + local pid = sys.exec("%s | grep -w %s | grep openvpn | grep -v grep | awk '{print $1}'" % { psstring,section} ) + if pid and #pid > 0 and tonumber(pid) ~= nil then + return tonumber(pid) + else + return nil + end +end + function s.parse(self, section) local recipe = luci.http.formvalue( luci.cbi.CREATE_PREFIX .. self.config .. "." .. @@ -68,8 +77,8 @@ s:option( Flag, "enabled", translate("Enabled") ) local active = s:option( DummyValue, "_active", translate("Started") ) function active.cfgvalue(self, section) - local pid = sys.exec("%s | grep %s | grep openvpn | grep -v grep | awk '{print $1}'" % { psstring,section} ) - if pid and #pid > 0 and tonumber(pid) ~= nil then + local pid = s.getPID(section) + if pid ~= nil then return (sys.process.signal(pid, 0)) and translatef("yes (%i)", pid) or translate("no") @@ -83,8 +92,8 @@ updown.redirect = luci.dispatcher.build_url( "admin", "services", "openvpn" ) function updown.cbid(self, section) - local pid = sys.exec("%s | grep %s | grep openvpn | grep -v grep | awk '{print $1}'" % { psstring,section} ) - self._state = pid and #pid > 0 and sys.process.signal(pid, 0) + local pid = s.getPID(section) + self._state = pid ~= nil and sys.process.signal(pid, 0) self.option = self._state and "stop" or "start" return AbstractValue.cbid(self, section) end @@ -94,8 +103,10 @@ function updown.cfgvalue(self, section) end function updown.write(self, section, value) if self.option == "stop" then - local pid = sys.exec("%s | grep %s | grep openvpn | grep -v grep | awk '{print $1}'" % { psstring,section} ) - sys.process.signal(pid,15) + local pid = s.getPID(section) + if pid ~= nil then + sys.process.signal(pid,15) + end else luci.sys.call("/etc/init.d/openvpn start %s" % section) end |