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
local active = s:option( DummyValue, "_active", translate("openvpn_active") )
function active.cfgvalue(self, section)
- local pid = fs.readfile("/var/run/openvpn_%s.pid" % section)
+ 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("openvpn_active_yes", pid)
+ and translatef("openvpn_active_yes", "yes (%i)", pid)
or translate("openvpn_active_no")
end
return translate("openvpn_active_no")
end
+local updown = s:option( Button, "_updown", translate("openvpn_updown", "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
+end
+
local port = s:option( DummyValue, "port", translate("openvpn_port") )
function port.cfgvalue(self, section)
local val = AbstractValue.cfgvalue(self, section)