awall-cli 847 Bytes
Newer Older
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
1 2 3 4 5 6 7 8
#!/usr/bin/lua

--[[
Alpine Wall
Copyright (C) 2012 Kaarle Ritvanen
Licensed under the terms of GPL2
]]--

9
require 'alt_getopt'
10 11 12
require 'lfs'
require 'stringy'

13 14 15
short_opts = 'o:V'
long_opts = {['output-dir']='o',
	     verify='V'}
16

17 18 19 20 21 22 23 24 25 26 27 28 29
if stringy.endswith(arg[0], '/awall-cli') then
   basedir = string.sub(arg[0], 1, -11)
   input = {basedir..'/json'}

   short_opts = short_opts..'i:'
   long_opts['input-dir'] = 'i'
end

for switch, value in pairs(alt_getopt.get_opts(arg, short_opts, long_opts)) do
   if switch == 'i' then table.insert(input, value)
   elseif switch == 'o' then
      iptdir = value
      ipsfile = value..'/ipset'
30
   elseif switch == 'V' then verify = true
31
   else assert(false) end
32
end
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
33

34

Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
35
require 'awall'
36
awall.loadmodules(basedir)
37

38
config = awall.Config.new(input)
39
if verify then config:test() end
40
config:dump(iptdir, ipsfile)