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
805dec16
Commit
805dec16
authored
Jun 28, 2012
by
Kaarle Ritvanen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
4 verbosity levels for dump command
parent
520c88ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
22 deletions
+69
-22
awall-cli
awall-cli
+35
-13
awall/util.lua
awall/util.lua
+34
-9
No files found.
awall-cli
View file @
805dec16
...
...
@@ -51,7 +51,9 @@ List optional policies:
another policy which is in use.
Dump variable and zone definitions:
awall dump
awall dump [level]
Verbosity level is an integer in range 0-3 and defaults to 0.
]]
)
os.exit
()
...
...
@@ -121,22 +123,42 @@ end
config
=
policyset
:
load
()
if
mode
==
'dump'
then
level
=
0
+
(
arg
[
opind
]
or
0
)
require
'json'
expconfig
=
config
:
expand
()
for
i
,
section
in
ipairs
({
'variable'
,
'zone'
})
do
if
config
.
data
[
section
]
then
print
(
string.upper
(
string.sub
(
section
,
1
,
1
))
..
string.sub
(
section
,
2
,
-
1
)
..
's:'
)
lines
=
{}
for
k
,
v
in
pairs
(
config
.
data
[
section
])
do
def
=
json
.
encode
(
v
)
exp
=
json
.
encode
(
expconfig
[
section
][
k
])
if
exp
~=
def
then
def
=
def
..
' = '
..
exp
end
table.insert
(
lines
,
k
..
' = '
..
def
..
' ('
..
config
.
source
[
section
][
k
]
..
')'
)
function
capitalize
(
cls
)
return
string.upper
(
string.sub
(
cls
,
1
,
1
))
..
string.sub
(
cls
,
2
,
-
1
)
end
for
cls
,
objs
in
pairs
(
config
.
data
)
do
if
level
>
2
or
(
level
==
2
and
cls
~=
'service'
)
or
util
.
contains
({
'variable'
,
'zone'
},
cls
)
then
if
level
==
0
then
print
(
capitalize
(
cls
)
..
's:'
)
end
items
=
{}
for
k
,
v
in
pairs
(
objs
)
do
exp
=
expconfig
[
cls
][
k
]
expj
=
json
.
encode
(
exp
)
src
=
config
.
source
[
cls
][
k
]
if
level
==
0
then
table.insert
(
items
,
{
k
,
expj
,
src
})
else
table.insert
(
items
,
{
k
,
{{
capitalize
(
cls
)
..
' '
..
k
,
json
.
encode
(
v
)},
{
'('
..
src
..
')'
,
util
.
compare
(
exp
,
v
)
and
''
or
'-> '
..
expj
}}})
end
end
table.sort
(
items
,
function
(
a
,
b
)
return
a
[
1
]
<
b
[
1
]
end
)
if
level
==
0
then
util
.
printtabular
(
items
)
else
util
.
printtabulars
(
util
.
map
(
items
,
function
(
x
)
return
x
[
2
]
end
))
print
()
end
table.sort
(
lines
)
for
i
,
line
in
ipairs
(
lines
)
do
print
(
line
)
end
print
()
end
end
...
...
awall/util.lua
View file @
805dec16
...
...
@@ -38,19 +38,44 @@ function extend(tbl1, tbl2)
for
i
,
var
in
listpairs
(
tbl2
)
do
table.insert
(
tbl1
,
var
)
end
end
function
printtabular
(
tbl
)
function
compare
(
a
,
b
)
local
t
=
type
(
a
)
if
t
~=
type
(
b
)
then
return
false
end
if
t
~=
'table'
then
return
a
==
b
end
local
keys
=
{}
for
k
,
v
in
pairs
(
a
)
do
if
not
compare
(
v
,
b
[
k
])
then
return
false
end
table.insert
(
keys
,
k
)
end
for
k
,
v
in
pairs
(
b
)
do
if
not
contains
(
keys
,
k
)
then
return
false
end
end
return
true
end
function
printtabulars
(
tables
)
local
colwidth
=
{}
for
i
,
row
in
ipairs
(
tbl
)
do
for
j
,
col
in
ipairs
(
row
)
do
colwidth
[
j
]
=
math.max
(
colwidth
[
j
]
or
0
,
string.len
(
col
))
for
i
,
tbl
in
ipairs
(
tables
)
do
for
j
,
row
in
ipairs
(
tbl
)
do
for
k
,
col
in
ipairs
(
row
)
do
colwidth
[
k
]
=
math.max
(
colwidth
[
k
]
or
0
,
string.len
(
col
))
end
end
end
for
i
,
row
in
ipairs
(
tbl
)
do
for
j
,
col
in
ipairs
(
row
)
do
if
j
>
1
then
io.write
(
' '
)
end
io.write
(
col
)
for
k
=
1
,
colwidth
[
j
]
-
string.len
(
col
)
do
io.write
(
' '
)
end
for
i
,
tbl
in
ipairs
(
tables
)
do
for
j
,
row
in
ipairs
(
tbl
)
do
for
k
=
1
,
#
row
do
if
k
>
1
then
io.write
(
' '
)
end
io.write
(
row
[
k
])
if
k
<
#
row
then
for
l
=
1
,
colwidth
[
k
]
-
string.len
(
row
[
k
])
do
io.write
(
' '
)
end
end
end
io.write
(
'
\n
'
)
end
io.write
(
'
\n
'
)
end
end
function
printtabular
(
tbl
)
printtabulars
({
tbl
})
end
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