Commit 8ae476a9 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

test mode moved to awall-cli from init.lua

parent 02587950
......@@ -6,7 +6,23 @@ Copyright (C) 2012 Kaarle Ritvanen
Licensed under the terms of GPL2
]]--
require 'lfs'
require 'stringy'
testmode = stringy.endswith(arg[0], '/awall-cli')
if testmode then
path = string.sub(arg[0], 1, -11)
lfs.chdir(path)
end
require 'awall'
awall.loadmodules(testmode and '.')
if testmode then
awall.confdirs = {'json', 'input'}
awall.iptdir = 'output'
awall.ipsfile = 'output/ipset'
end
awall.translate()
......@@ -15,17 +15,21 @@ require 'awall.model'
require 'awall.util'
local testmode = arg[0] ~= '/usr/sbin/awall'
confdirs = {'/usr/share/awall', '/etc/awall'}
iptdir = '/etc/iptables'
ipsfile = '/etc/ipset.d/awall'
local modules = {package.loaded['awall.model']}
local modpath = testmode and '.' or '/usr/share/lua/5.1'
for modfile in lfs.dir(modpath..'/awall/modules') do
if stringy.endswith(modfile, '.lua') then
local name = 'awall.modules.'..string.sub(modfile, 1, -5)
require(name)
table.insert(modules, package.loaded[name])
local loaded = false
function loadmodules(path)
for modfile in lfs.dir((path or '/usr/share/lua/5.1')..'/awall/modules') do
if stringy.endswith(modfile, '.lua') then
local name = 'awall.modules.'..string.sub(modfile, 1, -5)
require(name)
table.insert(modules, package.loaded[name])
end
end
end
......@@ -34,10 +38,6 @@ function translate()
config = {}
local confdirs = testmode and {'json',
'config'} or {'/usr/share/awall',
'/etc/awall'}
for i, dir in ipairs(confdirs) do
local fnames = {}
for fname in lfs.dir(dir) do table.insert(fnames, fname) end
......@@ -119,17 +119,17 @@ function translate()
end
end
awall.iptables.dump(testmode and 'output' or '/etc/iptables')
awall.iptables.dump(iptdir)
if config.ipset then
ipsfile = io.output(testmode and 'output/ipset' or '/etc/ipset.d/awall')
local ips = io.output(ipsfile)
for name, params in pairs(config.ipset) do
if not params.type then error('Type not defined for set '..name) end
local line = 'create '..name..' '..params.type
if params.family then line = line..' family '..params.family end
ipsfile:write(line..'\n')
ips:write(line..'\n')
end
ipsfile:close()
ips:close()
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment