2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
15 local fs = require "nixio.fs"
16 local sys = require "luci.sys"
17 local uci = require "luci.model.uci".cursor()
19 local m = Map("openvpn", translate("openvpn"))
20 local s = m:section( TypedSection, "openvpn", translate("openvpn_overview"), translate("openvpn_overview_desc") )
21 s.template = "cbi/tblsection"
22 s.template_addremove = "openvpn/cbi-select-input-add"
24 s.add_select_options = { }
25 s.extedit = luci.dispatcher.build_url(
26 "admin", "services", "openvpn", "basic", "%s"
29 uci:load("openvpn_recipes")
30 uci:foreach( "openvpn_recipes", "openvpn_recipe",
32 s.add_select_options[section['.name']] =
33 section['_description'] or section['.name']
37 function s.parse(self, section)
38 local recipe = luci.http.formvalue(
39 luci.cbi.CREATE_PREFIX .. self.config .. "." ..
40 self.sectiontype .. ".select"
43 if recipe and not s.add_select_options[recipe] then
44 self.invalid_cts = true
46 TypedSection.parse( self, section )
50 function s.create(self, name)
51 local recipe = luci.http.formvalue(
52 luci.cbi.CREATE_PREFIX .. self.config .. "." ..
53 self.sectiontype .. ".select"
56 if name and not name:match("[^a-zA-Z0-9_]") then
58 "openvpn", "openvpn", name,
59 uci:get_all( "openvpn_recipes", recipe )
62 uci:delete("openvpn", name, "_role")
63 uci:delete("openvpn", name, "_description")
66 luci.http.redirect( self.extedit:format(name) )
68 self.invalid_cts = true
73 s:option( Flag, "enable", translate("openvpn_enable") )
75 local active = s:option( DummyValue, "_active", translate("openvpn_active") )
76 function active.cfgvalue(self, section)
77 local pid = fs.readfile("/var/run/openvpn-%s.pid" % section)
78 if pid and #pid > 0 and tonumber(pid) ~= nil then
79 return (sys.process.signal(pid, 0))
80 and translatef("openvpn_active_yes", "yes (%i)", pid)
81 or translate("openvpn_active_no")
83 return translate("openvpn_active_no")
86 local port = s:option( DummyValue, "port", translate("openvpn_port") )
87 function port.cfgvalue(self, section)
88 local val = AbstractValue.cfgvalue(self, section)
92 local proto = s:option( DummyValue, "proto", translate("openvpn_proto") )
93 function proto.cfgvalue(self, section)
94 local val = AbstractValue.cfgvalue(self, section)