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 /openvpn-model.lua | |
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
Diffstat (limited to 'openvpn-model.lua')
-rw-r--r-- | openvpn-model.lua | 124 |
1 files changed, 124 insertions, 0 deletions
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 + |