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
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
6b7e5230
Commit
6b7e5230
authored
Jun 26, 2012
by
Kaarle Ritvanen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new class for configuration loaded from policy files but not yet translated to iptables rules
parent
c4e427e6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
46 deletions
+59
-46
awall-cli
awall-cli
+3
-1
awall/init.lua
awall/init.lua
+2
-42
awall/policy.lua
awall/policy.lua
+54
-3
No files found.
awall-cli
View file @
6b7e5230
...
...
@@ -115,11 +115,13 @@ if awall.util.contains({'disable', 'enable'}, mode) then
os.exit
()
end
config
=
policyset
:
load
()
require
'awall.iptables'
awall
.
loadmodules
(
basedir
)
config
=
awall
.
Config
.
new
(
policyset
)
config
=
awall
.
Config
.
new
(
config
)
if
mode
==
'translate'
then
if
verify
then
config
:
test
()
end
...
...
awall/init.lua
View file @
6b7e5230
...
...
@@ -59,51 +59,11 @@ PolicySet = policy.PolicySet
Config
=
object
.
class
(
object
.
Object
)
function
Config
:
init
(
policy
set
)
function
Config
:
init
(
policy
config
)
self
.
input
=
policy
set
:
loa
d
()
self
.
input
=
policy
config
:
expan
d
()
self
.
iptables
=
iptables
.
IPTables
.
new
()
local
function
expandvars
(
obj
)
for
k
,
v
in
pairs
(
obj
)
do
if
type
(
v
)
==
'table'
then
expandvars
(
v
)
else
local
visited
=
{}
local
val
=
v
local
pattern
=
'%$(%a[%w_]*)'
while
type
(
val
)
==
'string'
and
string.find
(
val
,
pattern
)
do
local
si
,
ei
,
name
=
string.find
(
val
,
pattern
)
if
util
.
contains
(
visited
,
name
)
then
error
(
'Circular variable definition: '
..
name
)
end
table.insert
(
visited
,
name
)
local
var
=
self
.
input
.
variable
[
name
]
if
not
var
then
error
(
'Invalid variable reference: '
..
name
)
end
if
si
==
1
and
ei
==
string.len
(
val
)
then
val
=
var
elseif
util
.
contains
({
'number'
,
'string'
},
type
(
var
))
then
val
=
string.sub
(
val
,
1
,
si
-
1
)
..
var
..
string.sub
(
val
,
ei
+
1
,
-
1
)
else
error
(
'Attempted to concatenate complex variable: '
..
name
)
end
end
obj
[
k
]
=
val
~=
''
and
val
or
nil
end
end
end
for
k
,
v
in
pairs
(
self
.
input
)
do
if
k
~=
'variable'
then
expandvars
(
v
)
end
end
local
function
insertrules
(
trules
)
for
i
,
trule
in
ipairs
(
trules
)
do
local
t
=
self
.
iptables
.
config
[
trule
.
family
][
trule
.
table
][
trule
.
chain
]
...
...
awall/policy.lua
View file @
6b7e5230
...
...
@@ -13,9 +13,60 @@ require 'lpc'
require
'awall.object'
require
'awall.util'
local
object
=
awall
.
object
local
util
=
awall
.
util
local
PolicyConfig
=
object
.
class
(
object
.
Object
)
function
PolicyConfig
:
init
(
data
)
self
.
data
=
data
end
function
PolicyConfig
:
eval
(
value
)
local
visited
=
{}
local
pattern
=
'%$(%a[%w_]*)'
while
type
(
value
)
==
'string'
and
string.find
(
value
,
pattern
)
do
local
si
,
ei
,
name
=
string.find
(
value
,
pattern
)
if
util
.
contains
(
visited
,
name
)
then
error
(
'Circular variable definition: '
..
name
)
end
table.insert
(
visited
,
name
)
local
var
=
self
.
data
.
variable
[
name
]
if
not
var
then
error
(
'Invalid variable reference: '
..
name
)
end
if
si
==
1
and
ei
==
string.len
(
value
)
then
value
=
var
elseif
util
.
contains
({
'number'
,
'string'
},
type
(
var
))
then
value
=
string.sub
(
value
,
1
,
si
-
1
)
..
var
..
string.sub
(
value
,
ei
+
1
,
-
1
)
else
error
(
'Attempted to concatenate complex variable: '
..
name
)
end
end
return
value
~=
''
and
value
or
nil
end
function
PolicyConfig
:
expand
()
local
function
expand
(
obj
)
for
k
,
v
in
pairs
(
obj
)
do
if
type
(
v
)
==
'table'
then
expand
(
v
)
else
obj
[
k
]
=
self
:
eval
(
v
)
end
end
end
for
k
,
v
in
pairs
(
self
.
data
)
do
if
k
~=
'variable'
then
expand
(
v
)
end
end
return
self
.
data
end
local
function
open
(
name
,
dirs
)
if
not
string.match
(
name
,
'^[%w-]+$'
)
then
error
(
'Invalid characters in policy name: '
..
name
)
...
...
@@ -64,7 +115,7 @@ local function list(dirs)
end
PolicySet
=
awall
.
object
.
class
(
awall
.
object
.
Object
)
PolicySet
=
object
.
class
(
object
.
Object
)
function
PolicySet
:
init
(
confdirs
,
importdirs
)
self
.
autodirs
=
confdirs
or
{
'/usr/share/awall/mandatory'
,
'/etc/awall'
}
...
...
@@ -125,7 +176,7 @@ function PolicySet:load()
for
i
,
pol
in
ipairs
(
list
(
self
.
autodirs
))
do
import
(
unpack
(
pol
))
end
return
input
,
imported
return
PolicyConfig
.
new
(
input
)
,
imported
end
...
...
@@ -160,7 +211,7 @@ function PolicySet:disable(name)
end
function
PolicySet
:
list
()
local
input
,
imported
=
self
:
load
()
local
config
,
imported
=
self
:
load
()
local
pols
=
list
(
self
.
importdirs
)
local
i
=
0
...
...
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