diff options
author | Hannu Nyman <hannu.nyman@iki.fi> | 2016-03-30 15:29:01 +0300 |
---|---|---|
committer | Hannu Nyman <hannu.nyman@iki.fi> | 2016-03-30 15:29:01 +0300 |
commit | 2c1777582cf8216a97518c900f511edc44eaa0f6 (patch) | |
tree | 5fa4cbe24ea48ee237bbd01ae60c93663809d49f /applications | |
parent | 859e4353783c3c9b6b23eaa51604d360a73c1236 (diff) | |
parent | af5c9d4fb4d37b735e37835853da19ab90721d7e (diff) |
Merge pull request #688 from Wedmer/master
[luci-app-openvpn] Optimized code and added suggested fix from #650
Diffstat (limited to 'applications')
-rw-r--r-- | applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua index 8b2ce5a85..1a1d33aa2 100644 --- a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua +++ b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua @@ -25,6 +25,10 @@ uci:foreach( "openvpn_recipes", "openvpn_recipe", end ) +function s.getPID(section) + return sys.exec("%s | grep -w %s | grep openvpn | grep -v grep | awk '{print $1}'" % { psstring,section} ) +end + function s.parse(self, section) local recipe = luci.http.formvalue( luci.cbi.CREATE_PREFIX .. self.config .. "." .. @@ -68,7 +72,7 @@ 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} ) + local pid = s.getPID(section) if pid and #pid > 0 and tonumber(pid) ~= nil then return (sys.process.signal(pid, 0)) and translatef("yes (%i)", pid) @@ -83,7 +87,7 @@ 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} ) + local pid = s.getPID(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) @@ -94,7 +98,7 @@ 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} ) + local pid = s.getPID(section) sys.process.signal(pid,15) else luci.sys.call("/etc/init.d/openvpn start %s" % section) |