Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
alpine
awall
Commits
0d6d0b76
Commit
0d6d0b76
authored
Sep 18, 2014
by
Kaarle Ritvanen
Browse files
utility function for setting default values
parent
f48f9461
Changes
5
Hide whitespace changes
Inline
Side-by-side
awall-cli
View file @
0d6d0b76
...
...
@@ -134,9 +134,7 @@ end
if
stringy
.
endswith
(
arg
[
0
],
'/awall-cli'
)
then
basedir
=
arg
[
0
]:
sub
(
1
,
-
11
)
if
not
pol_paths
.
mandatory
then
pol_paths
.
mandatory
=
{
'/etc/awall'
}
end
util
.
setdefault
(
pol_paths
,
'mandatory'
,
{
'/etc/awall'
})
table.insert
(
pol_paths
.
mandatory
,
basedir
..
'/json'
)
end
...
...
awall/model.lua
View file @
0d6d0b76
...
...
@@ -24,6 +24,7 @@ local extend = util.extend
local
filter
=
util
.
filter
local
listpairs
=
util
.
listpairs
local
maplist
=
util
.
maplist
local
setdefault
=
util
.
setdefault
local
startswith
=
require
(
'stringy'
).
startswith
...
...
@@ -82,12 +83,9 @@ function M.ConfigObject:uniqueid(key)
if
not
key
then
key
=
''
end
if
self
.
uniqueids
[
key
]
then
return
self
.
uniqueids
[
key
]
end
if
not
self
.
context
.
lastid
then
self
.
context
.
lastid
=
{}
end
local
lastid
=
self
.
context
.
lastid
local
lastid
=
setdefault
(
self
.
context
,
'lastid'
,
{})
local
res
=
join
(
key
,
self
.
label
)
if
not
lastid
[
res
]
then
lastid
[
res
]
=
-
1
end
lastid
[
res
]
=
lastid
[
res
]
+
1
lastid
[
res
]
=
setdefault
(
lastid
,
res
,
-
1
)
+
1
res
=
res
..
'-'
..
lastid
[
res
]
self
.
uniqueids
[
key
]
=
res
...
...
@@ -588,7 +586,7 @@ function M.Limit:init(...)
self
.
count
=
self
[
1
]
end
if
not
self
.
interval
then
self
.
interval
=
1
end
setdefault
(
self
,
'
interval
'
,
1
)
end
function
M
.
Limit
:
rate
()
return
math.ceil
(
self
.
count
/
self
.
interval
)
end
...
...
awall/modules/filter.lua
View file @
0d6d0b76
...
...
@@ -40,7 +40,7 @@ local LoggingRule = class(TranslatingRule)
function
LoggingRule
:
init
(
...
)
LoggingRule
.
super
(
self
):
init
(
...
)
if
not
self
.
action
then
self
.
action
=
'accept'
end
util
.
setdefault
(
self
,
'
action
'
,
'accept'
)
if
type
(
self
.
log
)
~=
'table'
then
self
.
log
=
loadclass
(
'log'
).
get
(
self
,
self
.
log
,
self
.
action
~=
'accept'
)
end
...
...
awall/policy.lua
View file @
0d6d0b76
...
...
@@ -208,7 +208,7 @@ function PolicySet:load()
raise
(
'Invalid top-level attribute: '
..
cls
..
' ('
..
name
..
')'
)
end
if
not
source
[
cls
]
then
source
[
cls
]
=
{}
end
util
.
setdefault
(
source
,
cls
,
{})
if
not
input
[
cls
]
then
input
[
cls
]
=
objs
...
...
awall/util.lua
View file @
0d6d0b76
...
...
@@ -79,6 +79,11 @@ function M.update(tbl1, tbl2)
return
tbl1
end
function
M
.
setdefault
(
t
,
k
,
v
)
if
t
[
k
]
==
nil
then
t
[
k
]
=
v
end
return
t
[
k
]
end
function
M
.
copy
(
tbl
)
return
M
.
update
({},
tbl
)
end
function
M
.
compare
(
a
,
b
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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