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
18 require("luci.model.uci")
21 local uci = luci.model.uci.cursor()
23 local m = Map("openvpn")
24 local s = m:section( TypedSection, "openvpn" )
25 s.template = "cbi/tblsection"
26 s.template_addremove = "openvpn/cbi-select-input-add"
28 s.add_select_options = { }
29 s.extedit = luci.dispatcher.build_url(
30 "admin", "services", "openvpn", "basic", "%s"
33 uci:load("openvpn_recipes")
34 uci:foreach( "openvpn_recipes", "openvpn_recipe",
36 s.add_select_options[section['.name']] =
37 section['_description'] or section['.name']
41 function s.parse(self, section)
42 local recipe = luci.http.formvalue(
43 luci.cbi.CREATE_PREFIX .. self.config .. "." ..
44 self.sectiontype .. ".select"
47 if recipe and not s.add_select_options[recipe] then
48 self.invalid_cts = true
50 TypedSection.parse( self, section )
54 function s.create(self, name)
55 local recipe = luci.http.formvalue(
56 luci.cbi.CREATE_PREFIX .. self.config .. "." ..
57 self.sectiontype .. ".select"
61 "openvpn", "openvpn", name,
62 uci:get_all( "openvpn_recipes", recipe )
65 uci:delete("openvpn", name, "_role")
66 uci:delete("openvpn", name, "_description")
69 luci.http.redirect( self.extedit:format(name) )
73 s:option( Flag, "enable" )
75 local active = s:option( DummyValue, "_active" )
76 function active.cfgvalue(self, section)
77 if luci.fs.isfile("/var/run/openvpn_%s.pid" % section) then
78 local pid = io.lines("/var/run/openvpn_%s.pid" % section)()
79 if pid and #pid > 0 and tonumber(pid) ~= nil then
80 return (luci.sys.process.signal(pid, 0)) and "yes (" .. pid .. ")" or "no"
86 local port = s:option( DummyValue, "port" )
87 function port.cfgvalue(self, section)
88 local val = AbstractValue.cfgvalue(self, section)
92 local proto = s:option( DummyValue, "proto" )
93 function proto.cfgvalue(self, section)
94 local val = AbstractValue.cfgvalue(self, section)