Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
awall
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpine
awall
Commits
4bfc8d8b
Commit
4bfc8d8b
authored
Mar 16, 2012
by
Kaarle Ritvanen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dumping and testing functions separated
module for ipset tool-related functionality
parent
2e000241
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
21 deletions
+73
-21
awall-cli
awall-cli
+2
-1
awall/init.lua
awall/init.lua
+13
-12
awall/ipset.lua
awall/ipset.lua
+39
-0
awall/iptables.lua
awall/iptables.lua
+15
-8
awall/model.lua
awall/model.lua
+4
-0
No files found.
awall-cli
View file @
4bfc8d8b
...
...
@@ -25,4 +25,5 @@ if testmode then
awall
.
ipsfile
=
'output/ipset'
end
awall
.
translate
()
awall
.
test
()
awall
.
dump
()
awall/init.lua
View file @
4bfc8d8b
...
...
@@ -10,6 +10,7 @@ require 'json'
require
'lfs'
require
'stringy'
require
'awall.ipset'
require
'awall.iptables'
require
'awall.model'
require
'awall.util'
...
...
@@ -33,9 +34,11 @@ function loadmodules(path)
end
function
translate
()
local
function
readconfig
()
config
=
{}
awall
.
model
.
reset
()
awall
.
iptables
.
reset
()
for
i
,
dir
in
ipairs
(
confdirs
)
do
local
fnames
=
{}
...
...
@@ -117,18 +120,16 @@ function translate()
for
i
,
trule
in
ipairs
(
rule
:
trules
())
do
insertrule
(
trule
)
end
end
end
end
function
dump
()
readconfig
()
awall
.
ipset
.
dump
(
ipsfile
)
awall
.
iptables
.
dump
(
iptdir
)
end
if
config
.
ipset
then
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
ips
:
write
(
line
..
'
\n
'
)
end
ips
:
close
()
end
function
test
()
readconfig
()
awall
.
ipset
.
create
()
awall
.
iptables
.
test
()
end
awall/ipset.lua
0 → 100644
View file @
4bfc8d8b
--[[
Ipset file dumper for Alpine Wall
Copyright (C) 2012 Kaarle Ritvanen
Licensed under the terms of GPL2
]]
--
module
(
...
,
package
.
seeall
)
local
function
commands
()
local
config
=
awall
.
config
local
res
=
{}
if
config
.
ipset
then
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
table.insert
(
res
,
line
..
'
\n
'
)
end
end
return
res
end
function
create
()
for
i
,
line
in
ipairs
(
commands
())
do
local
pid
,
stdin
=
lpc
.
run
(
'ipset'
,
'-!'
,
'restore'
)
stdin
:
write
(
line
)
stdin
:
close
()
if
lpc
.
wait
(
pid
)
~=
0
then
io.stderr
:
write
(
'ipset command failed: '
..
line
)
end
end
end
function
dump
(
ipsfile
)
local
file
=
io.output
(
ipsfile
)
for
i
,
line
in
ipairs
(
commands
())
do
file
:
write
(
line
)
end
file
:
close
()
end
awall/iptables.lua
View file @
4bfc8d8b
...
...
@@ -18,13 +18,16 @@ local families = {inet={cmd='iptables-restore', file='rules-save'},
local
builtin
=
{
'INPUT'
,
'FORWARD'
,
'OUTPUT'
,
'PREROUTING'
,
'POSTROUTING'
}
config
=
{}
setmetatable
(
config
,
{
__index
=
function
(
t
,
k
)
t
[
k
]
=
{}
setmetatable
(
t
[
k
],
getmetatable
(
t
))
return
t
[
k
]
end
})
function
reset
()
config
=
{}
setmetatable
(
config
,
{
__index
=
function
(
t
,
k
)
t
[
k
]
=
{}
setmetatable
(
t
[
k
],
getmetatable
(
t
))
return
t
[
k
]
end
})
end
reset
()
local
function
dumpfile
(
family
,
iptfile
)
iptfile
:
write
(
'# '
..
families
[
family
].
file
..
' generated by awall\n'
)
...
...
@@ -43,13 +46,17 @@ local function dumpfile(family, iptfile)
end
end
function
dump
(
dir
)
function
test
(
)
for
family
,
tbls
in
pairs
(
config
)
do
local
pid
,
stdin
=
lpc
.
run
(
families
[
family
].
cmd
,
'-t'
)
dumpfile
(
family
,
stdin
)
stdin
:
close
()
assert
(
lpc
.
wait
(
pid
)
==
0
)
end
end
function
dump
(
dir
)
for
family
,
tbls
in
pairs
(
config
)
do
dumpfile
(
family
,
io.output
(
dir
..
'/'
..
families
[
family
].
file
))
end
end
awall/model.lua
View file @
4bfc8d8b
...
...
@@ -360,6 +360,10 @@ function Rule:newchain(base)
return
base
..
'-'
..
lastid
[
base
]
end
function
reset
()
lastid
=
{}
end
classmap
=
{
zone
=
Zone
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment