diff options
author | Mika Havela <mika.havela@gmail.com> | 2007-11-17 11:31:10 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2007-11-17 11:31:10 +0000 |
commit | 31ff3ba51554722d2afbdc8153801c5496ff02b8 (patch) | |
tree | f194089397d9acaa9e98df4181c73247a083cd41 | |
parent | d1f3722325d29c220401cba825915238374763b0 (diff) | |
download | acf-openvpn-31ff3ba51554722d2afbdc8153801c5496ff02b8.tar.bz2 acf-openvpn-31ff3ba51554722d2afbdc8153801c5496ff02b8.tar.xz |
OpenVPN initial thoughts on functionallity. Almost no functionallity at this point.
git-svn-id: svn://svn.alpinelinux.org/acf/openvpn/trunk@332 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | openvpn-controller.lua | 128 | ||||
-rw-r--r-- | openvpn-model.lua | 124 | ||||
-rw-r--r-- | openvpn-read-html.lsp | 36 | ||||
-rw-r--r-- | openvpn-server_config-html.lsp | 59 | ||||
-rw-r--r-- | openvpn.menu | 2 |
5 files changed, 349 insertions, 0 deletions
diff --git a/openvpn-controller.lua b/openvpn-controller.lua new file mode 100644 index 0000000..b088758 --- /dev/null +++ b/openvpn-controller.lua @@ -0,0 +1,128 @@ +-- the hostname controller + +module (..., package.seeall) + +-- Cause an http redirect to our "read" action +-- We use the self.conf table because it already has prefix,controller,etc +-- The redir code is defined in the application error handler (acf-controller) +local list_redir = function (self) + self.conf.action = "read" + self.conf.type = "redir" + error (self.conf) +end + +mvc={} +mvc.on_load = function(self, parent) + if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then + self.worker[self.conf.action] = list_redir(self) + end + +-- logit ("hostname.mvc.on_load activated") + +end + + +local function build_form ( model ) + local viewtable = {} + local configform = {} + local processform = {} + local messageform = {} +-- local conflist = model.conflist() + local conflist = "hej" + local formwith = 60 + -- cf.self is a global variable specifiying this controller + -- local url = cf.self or "" + +--[[ table.insert ( messageform , { + type = "label" , + value = "Logfile info" , + text = "Tail file <i><b>/var/log/messages</b></i><BR><font style='color:f00'>(Still working on this function)</font>" + } ) +]]-- + table.insert ( processform , { + type = "label" , + value = "Process information", + text = "Information on if process is running." + } ) + table.insert ( processform , { + type = "formtext", + label = "openvpn process status", +-- value = model.status("openvpn") + value = "hej" + } ) + + +-- if table.maxn(conflist)==0 then + if 0==0 then + table.insert ( configform , { + type = "label" , + value = "List of valid configurations" , + text = "No valid configurations could be found in <i><b>/etc/openvpn/</b></i><br>A valid config is called *.conf and has got at least the following parameters set: ca, cert, key, dev, proto (and for clients also parameter 'remote')" + } ) + else + -- Generate processlist + configform[1] = { + type = "label", + value = "List of valid configurations" , + text = "List is based on all valid configuration files named <i><b>/etc/openvpn/*.conf</b></i>" + } + for i=1,table.maxn(conflist) do + table.insert ( configform , { + type = "formtext" , +-- label = conflist[i].confname , + label = "hej" , +-- value = conflist[i].conftype or "" + value = "hej" or "" + } ) + end + end + + --- Define the main table used by the generic view renderer + viewtable[1] = { + type = "label", + value = "GENERAL" + } + viewtable[2] = { + type = "form", + method = "post", + action = "set", + -- Put the 'form' table in the view table + value = processform + } + viewtable[3] = { + type = "form", + method = "post", + action = "set", + --action = cf.self .. "/set", + -- Put the 'form' table in the view table + value = configform + } + viewtable[4] = { + type = "form", + method = "post", + action = "set", + --action = cf.self .. "/set", + -- Put the 'form' table in the view table + value = messageform + } + return viewtable +end + +-- Public methods +-- <prefix>/hostname/get + + +read = function (self) + local me = {} + me = cfe{name=conflistfilesaf, value="hej"} + return ( {conflistfiles = self.model:list_conffiles()} ) +-- return ({conflistfiles = me}) +-- return self.model:get() +-- return build_form(self) +end + + +server_config = function (self) +end + +create = update diff --git a/openvpn-model.lua b/openvpn-model.lua new file mode 100644 index 0000000..c5210b3 --- /dev/null +++ b/openvpn-model.lua @@ -0,0 +1,124 @@ +-- hostname model methods +module (..., package.seeall) + +require ("posix") +require ("fs") + +-- no initializer in model - use controller.init for that + +-- ################################################################################ +-- LOCAL FUNCTIONS +local function read_file_as_array ( path ) + local file, error = io.open(path) + if ( file == nil ) then + return nil, error + end + local f = {} + for line in file:lines() do + table.insert ( f , line ) + end + file:close() + return f +end + +local function has_init_script ( f ) + local initprefix = "/etc/init.d/openvpn" + local file = initprefix .. "." .. f + if f ~= "openvpn" then + if ( fs.is_file(file)) then + init = "yes" + else + init = nil + end + else + if ( fs.is_file(initprefix)) then + init = "yes" + else + init = nil + end + end + return init +end + +local function check_valid_config ( f ) + conf_ca = "" + conf_auth = "" + conf_type = "server" + conf_cert = "" + conf_key = "" + conf_dev = "" + conf_proto = "" + conf_remote = "" + conf_dev = "" + local conf_file_content = read_file_as_array( "/etc/openvpn/".. f ) + for i =1,table.maxn(conf_file_content) do + local lin = conf_file_content[i] + -- Filter out commented lines + if not string.find ( lin, "^[;#].*" ) then + -- The following code could probably de done much easier + -- Check for parameter of a valid configuration + if string.find ( lin, "^ca[%s \v]" ) then + conf_ca="ca" + end + if string.find ( lin, "^auth\-user\-pass[%s \v]" ) then + conf_auth="auth-user-pass" + end + if string.find ( lin, "^client[%s$]" ) then + conf_type = "client" + end + if string.find ( lin, "^cert[%s \v]" ) then + conf_cert = "cert" + end + if string.find ( lin, "^key[%s \v]" ) then + conf_key = "key" + end + if string.find ( lin, "^dev[%s \v]" ) then + conf_dev = "dev" + end + if string.find ( lin, "^proto[%s \v]" ) then + conf_proto = "proto" + end + if string.find ( lin, "^remote[%s \v]" ) then + conf_remote = "remote" + end + end + end + -- Check if config is invalid (missing parameters) + if conf_type == "client" then + if conf_dev == "" or conf_remote == "" then + conf_type="unknown" + end + else + if conf_dev == "" or conf_port == "" then + conf_type="unknown" + end + end + return conf_type +end + +local function list_rootfolder() + local files , errstr, errno = posix.dir ( "/etc/openvpn/" ) + return files +end + +-- ################################################################################ +-- PUBLIC FUNCTIONS +function list_conffiles() + conlistfiles = {} + local files = list_rootfolder() + if files then + for a,b in ipairs(files) do + if string.match (b, "^.*conf$") then + local conf_type = check_valid_config ( b ) + local init_script = has_init_script ( string.gsub(b, "(%w+)(\..*)", "%1") ) + table.insert ( conlistfiles, cfe{ value = b, type = conf_type, init = init_script} ) + end + end + return conlistfiles + end +end + +get = function (self) + return list_conffiles() +end + diff --git a/openvpn-read-html.lsp b/openvpn-read-html.lsp new file mode 100644 index 0000000..521e6b3 --- /dev/null +++ b/openvpn-read-html.lsp @@ -0,0 +1,36 @@ +<? local view = ... ?> +<? --[[ Notes + conflistfiles = Filename on config-files + test + ]]-- ?> +<html> +<body> +<h1>General</h1> +<h2>Available configs</h2> +<TABLE BORDER=0 WIDTH="100%"> + <TR style="background:#eee;font-weight:bold;vertical-align:top;"> + <TD WIDTH=100>Config</TD> + <TD WIDTH=70>Type</TD> + <TD WIDTH=70>Status</TD> + <TD>Connected Clients</TD> + </TR> + +<? for i = 1, table.maxn(view.conflistfiles) do ?> + <TR > + <TD><a href=""><?= view.conflistfiles[i].value ?></a></TD> + <TD><?= view.conflistfiles[i].type ?></TD> + <TD><?= view.conflistfiles[i].init ?></TD> + <TD>xxx</TD> + </TR> +<? end ?> +</TABLE> + +<h2>System info</h2> + +<dt>Program version</dt> +<dd>OpenVPN ver.x.x.x</dd> + + + +</body> +</html> diff --git a/openvpn-server_config-html.lsp b/openvpn-server_config-html.lsp new file mode 100644 index 0000000..41b28c5 --- /dev/null +++ b/openvpn-server_config-html.lsp @@ -0,0 +1,59 @@ +<? local view = ... ?> +<html> +<body> +<h1>Server config 'xxx.conf'</h1> +<h2>Server settings</h2> + +<dt>Mode</dt> +<dd>server</dd> + +<dt>Process running</dt> +<dd><input type="checkbox">xxx</input></dd> + +<dt>User device</dt> +<dd>xxx</dd> + +<dt>Listens on</dt> +<dd>xxx.xxx.xxx.xxx:xxxx (xxx)</dd> + +<dt>Logfile</dt> +<dd><a href="">xxx.log</a> (Verbosity level: x)</dd> + +<dt>Configfile</dt> +<dd><a href="">xxx.conf</a></dd> + +<h3>Connected clients status</h3> + +<dt>Last status was recorded</dt> +<dd><a href="">YYYY-MM-DD HH:MM:SS</a> (xx minutes ago)</dd> + +<dt>Maximum clients</dt> +<dd>xxx</dd> + +<dt>Connected clients</dt> +<dd><a href="">xxx</a></dd> + + +<h2>Certificate files</h2> + +<dt>DH</dt> +<dd><a href="">xxx.pem</a></dd> + +<dt>CA Certificate</dt> +<dd><a href="">xxx.pem</a></dd> + +<dt>Server Certificate</dt> +<dd><a href="">xxx.pem</a></dd> + +<dt>Server Private Key</dt> +<dd><a href="">xxx.pem</a></dd> + +<dt>TLS Authentication</dt> +<dd><a href="">xxx.pem</a></dd> + +<dt>CRL Verify File</dt> +<dd><a href="">xxx.pem</a> (server side)</dd> + + +</body> +</html> diff --git a/openvpn.menu b/openvpn.menu new file mode 100644 index 0000000..d465676 --- /dev/null +++ b/openvpn.menu @@ -0,0 +1,2 @@ +#CAT GROUP/DESC TAB ACTION +Connectivity OpenVPN OpenVPN read |