Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
14dfed33
Commit
14dfed33
authored
Feb 29, 2016
by
Ad Schellevis
Committed by
Franco Fichtner
Mar 03, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(proxy) add optional filter for remote blacklist
(cherry picked from commit
7df30b7d
)
parent
d99a5149
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
43 deletions
+59
-43
fetchACLs.py
src/opnsense/scripts/proxy/fetchACLs.py
+58
-43
externalACLs.conf
...nsense/service/templates/OPNsense/Proxy/externalACLs.conf
+1
-0
No files found.
src/opnsense/scripts/proxy/fetchACLs.py
View file @
14dfed33
...
@@ -126,46 +126,61 @@ if os.path.exists(acl_config_fn):
...
@@ -126,46 +126,61 @@ if os.path.exists(acl_config_fn):
cnf
=
ConfigParser
()
cnf
=
ConfigParser
()
cnf
.
read
(
acl_config_fn
)
cnf
.
read
(
acl_config_fn
)
for
section
in
cnf
.
sections
():
for
section
in
cnf
.
sections
():
# check if tag enabled exists in section
target_filename
=
acl_target_dir
+
'/'
+
section
if
cnf
.
has_option
(
section
,
'enabled'
):
if
cnf
.
has_option
(
section
,
'url'
):
# if enabled fetch file
# collect filters to apply
target_filename
=
acl_target_dir
+
'/'
+
section
acl_filters
=
list
()
if
cnf
.
has_option
(
section
,
'url'
):
if
cnf
.
has_option
(
section
,
'filter'
):
# define targets
for
acl_filter
in
cnf
.
get
(
section
,
'filter'
)
.
strip
()
.
split
(
','
):
targets
=
{
'domain'
:
{
'filename'
:
target_filename
,
'handle'
:
None
},
if
len
(
acl_filter
.
strip
())
>
0
:
'url'
:
{
'filename'
:
'
%
s.url'
%
target_filename
,
'handle'
:
None
}}
acl_filters
.
append
(
acl_filter
)
# download file
# define targets
if
cnf
.
get
(
section
,
'enabled'
)
==
'1'
:
targets
=
{
'domain'
:
{
'filename'
:
target_filename
,
'handle'
:
None
},
# only generate files if enabled, otherwise dump empty files
'url'
:
{
'filename'
:
'
%
s.url'
%
target_filename
,
'handle'
:
None
}}
download_url
=
cnf
.
get
(
section
,
'url'
)
acl
=
ACLDownload
(
download_url
,
acl_max_timeout
)
# only generate files if enabled, otherwise dump empty files
all_filenames
=
list
()
if
cnf
.
has_option
(
section
,
'enabled'
)
and
cnf
.
get
(
section
,
'enabled'
)
==
'1'
:
for
filename
,
filetype
,
line
in
acl
.
download
():
download_url
=
cnf
.
get
(
section
,
'url'
)
if
filename
not
in
all_filenames
:
acl
=
ACLDownload
(
download_url
,
acl_max_timeout
)
all_filenames
.
append
(
filename
)
all_filenames
=
list
()
if
filetype
in
targets
and
targets
[
filetype
][
'handle'
]
is
None
:
for
filename
,
filetype
,
line
in
acl
.
download
():
targets
[
filetype
][
'handle'
]
=
open
(
targets
[
filetype
][
'filename'
],
'wb'
)
if
filename
not
in
all_filenames
:
if
filetype
in
targets
:
all_filenames
.
append
(
filename
)
targets
[
filetype
][
'handle'
]
.
write
(
'
%
s
\n
'
%
line
)
# save index to disc
if
len
(
acl_filters
)
>
0
:
with
open
(
'
%
s.index'
%
target_filename
,
'wb'
)
as
idx_out
:
acl_found
=
False
index_data
=
dict
()
for
acl_filter
in
acl_filters
:
for
filename
in
all_filenames
:
if
filename
.
find
(
acl_filter
)
>
-
1
:
if
len
(
filename
.
split
(
'/'
))
>
3
:
acl_found
=
True
index_key
=
'/'
.
join
(
filename
.
split
(
'/'
)[
1
:
-
1
])
break
if
index_key
not
in
index_data
:
if
not
acl_found
:
index_data
[
index_key
]
=
index_key
# skip this acl entry
idx_out
.
write
(
json
.
dumps
(
index_data
))
continue
# cleanup
for
filetype
in
targets
:
if
filetype
in
targets
and
targets
[
filetype
][
'handle'
]
is
None
:
if
targets
[
filetype
][
'handle'
]
is
not
None
:
targets
[
filetype
][
'handle'
]
=
open
(
targets
[
filetype
][
'filename'
],
'wb'
)
targets
[
filetype
][
'handle'
]
.
close
()
if
filetype
in
targets
:
elif
cnf
.
get
(
section
,
'enabled'
)
!=
'1'
:
targets
[
filetype
][
'handle'
]
.
write
(
'
%
s
\n
'
%
line
)
if
os
.
path
.
isfile
(
targets
[
filetype
][
'filename'
]):
# save index to disc
# disabled, remove previous data
with
open
(
'
%
s.index'
%
target_filename
,
'wb'
)
as
idx_out
:
os
.
remove
(
targets
[
filetype
][
'filename'
])
index_data
=
dict
()
elif
not
os
.
path
.
isfile
(
targets
[
filetype
][
'filename'
]):
for
filename
in
all_filenames
:
# no data fetched and no file available, create new empty file
if
len
(
filename
.
split
(
'/'
))
>
3
:
with
open
(
targets
[
filetype
][
'filename'
],
'wb'
)
as
target_out
:
index_key
=
'/'
.
join
(
filename
.
split
(
'/'
)[
1
:
-
1
])
target_out
.
write
(
""
)
if
index_key
not
in
index_data
:
index_data
[
index_key
]
=
index_key
idx_out
.
write
(
json
.
dumps
(
index_data
))
# cleanup
for
filetype
in
targets
:
if
targets
[
filetype
][
'handle'
]
is
not
None
:
targets
[
filetype
][
'handle'
]
.
close
()
elif
cnf
.
has_option
(
section
,
'enabled'
)
and
cnf
.
get
(
section
,
'enabled'
)
!=
'1'
:
if
os
.
path
.
isfile
(
targets
[
filetype
][
'filename'
]):
# disabled, remove previous data
os
.
remove
(
targets
[
filetype
][
'filename'
])
elif
not
os
.
path
.
isfile
(
targets
[
filetype
][
'filename'
]):
# no data fetched and no file available, create new empty file
with
open
(
targets
[
filetype
][
'filename'
],
'wb'
)
as
target_out
:
target_out
.
write
(
""
)
src/opnsense/service/templates/OPNsense/Proxy/externalACLs.conf
View file @
14dfed33
...
@@ -6,5 +6,6 @@
...
@@ -6,5 +6,6 @@
[{{
blacklist
.
filename
}}]
[{{
blacklist
.
filename
}}]
url
:{{
blacklist
.
url
}}
url
:{{
blacklist
.
url
}}
enabled
:{{
blacklist
.
enabled
}}
enabled
:{{
blacklist
.
enabled
}}
filter
:{{
blacklist
.
filter
|
default
(
''
)}}
{%
endfor
%}
{%
endfor
%}
{%
endif
%}
{%
endif
%}
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