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
f8645117
Commit
f8645117
authored
Oct 17, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(proxy) add basic auth support for remote ACL's, replace urllib2 with requests.
parent
1af75a82
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
15 deletions
+45
-15
dialogEditBlacklist.xml
.../controllers/OPNsense/Proxy/forms/dialogEditBlacklist.xml
+12
-0
Proxy.xml
src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.xml
+8
-0
fetchACLs.py
src/opnsense/scripts/proxy/fetchACLs.py
+21
-15
externalACLs.conf
...nsense/service/templates/OPNsense/Proxy/externalACLs.conf
+4
-0
No files found.
src/opnsense/mvc/app/controllers/OPNsense/Proxy/forms/dialogEditBlacklist.xml
View file @
f8645117
...
@@ -17,6 +17,18 @@
...
@@ -17,6 +17,18 @@
<type>
text
</type>
<type>
text
</type>
<help>
Enter an url to fetch the blacklist from.
</help>
<help>
Enter an url to fetch the blacklist from.
</help>
</field>
</field>
<field>
<id>
blacklist.username
</id>
<label>
username (optional)
</label>
<type>
text
</type>
<help>
(optional) user credentials.
</help>
</field>
<field>
<id>
blacklist.password
</id>
<label>
password (optional)
</label>
<type>
password
</type>
<help>
(optional) user credentials.
</help>
</field>
<field>
<field>
<id>
blacklist.filter
</id>
<id>
blacklist.filter
</id>
<label>
categories (if available)
</label>
<label>
categories (if available)
</label>
...
...
src/opnsense/mvc/app/models/OPNsense/Proxy/Proxy.xml
View file @
f8645117
...
@@ -315,6 +315,14 @@
...
@@ -315,6 +315,14 @@
<Required>
Y
</Required>
<Required>
Y
</Required>
<ValidationMessage>
This does not look like a valid url.
</ValidationMessage>
<ValidationMessage>
This does not look like a valid url.
</ValidationMessage>
</url>
</url>
<username
type=
"TextField"
>
<Required>
N
</Required>
<mask>
/^([\t\n\v\f\r 0-9a-zA-Z.,_\x{00A0}-\x{FFFF}]){1,255}$/u
</mask>
</username>
<password
type=
"TextField"
>
<Required>
N
</Required>
<mask>
/^([\t\n\v\f\r 0-9a-zA-Z.,_\x{00A0}-\x{FFFF}]){1,255}$/u
</mask>
</password>
<filter
type=
"JsonKeyValueStoreField"
>
<filter
type=
"JsonKeyValueStoreField"
>
<Required>
N
</Required>
<Required>
N
</Required>
<SourceField>
filename
</SourceField>
<SourceField>
filename
</SourceField>
...
...
src/opnsense/scripts/proxy/fetchACLs.py
View file @
f8645117
...
@@ -28,7 +28,6 @@
...
@@ -28,7 +28,6 @@
"""
"""
import
tempfile
import
tempfile
import
urllib2
import
os
import
os
import
json
import
json
import
glob
import
glob
...
@@ -37,7 +36,9 @@ import tarfile
...
@@ -37,7 +36,9 @@ import tarfile
import
gzip
import
gzip
import
zipfile
import
zipfile
import
syslog
import
syslog
import
shutil
from
ConfigParser
import
ConfigParser
from
ConfigParser
import
ConfigParser
import
requests
acl_config_fn
=
'/usr/local/etc/squid/externalACLs.conf'
acl_config_fn
=
'/usr/local/etc/squid/externalACLs.conf'
acl_target_dir
=
'/usr/local/etc/squid/acl'
acl_target_dir
=
'/usr/local/etc/squid/acl'
...
@@ -48,7 +49,7 @@ class Downloader(object):
...
@@ -48,7 +49,7 @@ class Downloader(object):
""" Download helper
""" Download helper
"""
"""
def
__init__
(
self
,
url
,
timeout
):
def
__init__
(
self
,
url
,
username
,
password
,
timeout
):
""" init new
""" init new
:param url: source url
:param url: source url
:param timeout: timeout in seconds
:param timeout: timeout in seconds
...
@@ -56,24 +57,23 @@ class Downloader(object):
...
@@ -56,24 +57,23 @@ class Downloader(object):
self
.
_url
=
url
self
.
_url
=
url
self
.
_timeout
=
timeout
self
.
_timeout
=
timeout
self
.
_source_handle
=
None
self
.
_source_handle
=
None
self
.
_username
=
username
self
.
_password
=
password
def
fetch
(
self
):
def
fetch
(
self
):
""" fetch (raw) source data into tempfile using self._source_handle
""" fetch (raw) source data into tempfile using self._source_handle
"""
"""
try
:
if
self
.
_username
is
not
None
:
f
=
urllib2
.
urlopen
(
self
.
_url
,
timeout
=
self
.
_timeout
)
req
=
requests
.
get
(
url
=
self
.
_url
,
stream
=
True
,
timeout
=
self
.
_timeout
,
auth
=
(
self
.
_username
,
self
.
_password
))
# flush to temp file
self
.
_source_handle
=
tempfile
.
NamedTemporaryFile
()
while
True
:
data
=
f
.
read
(
1024
)
if
not
data
:
break
else
:
else
:
self
.
_source_handle
.
write
(
data
)
req
=
requests
.
get
(
url
=
self
.
_url
,
stream
=
True
,
timeout
=
self
.
_timeout
)
if
req
.
status_code
==
200
:
self
.
_source_handle
=
tempfile
.
NamedTemporaryFile
()
shutil
.
copyfileobj
(
req
.
raw
,
self
.
_source_handle
)
self
.
_source_handle
.
seek
(
0
)
self
.
_source_handle
.
seek
(
0
)
f
.
close
()
else
:
except
(
urllib2
.
URLError
,
urllib2
.
HTTPError
,
IOError
)
as
e
:
syslog
.
syslog
(
syslog
.
LOG_ERR
,
'proxy acl: error downloading
%
s (http code:
%
s)'
%
(
self
.
_url
,
syslog
.
syslog
(
syslog
.
LOG_ERR
,
'proxy acl: error downloading
%
s'
%
self
.
_url
)
req
.
status_code
)
)
self
.
_source_handle
=
None
self
.
_source_handle
=
None
def
get_files
(
self
):
def
get_files
(
self
):
...
@@ -271,7 +271,13 @@ def main():
...
@@ -271,7 +271,13 @@ def main():
# only generate files if enabled, otherwise dump empty files
# only generate files if enabled, otherwise dump empty files
if
cnf
.
has_option
(
section
,
'enabled'
)
and
cnf
.
get
(
section
,
'enabled'
)
==
'1'
:
if
cnf
.
has_option
(
section
,
'enabled'
)
and
cnf
.
get
(
section
,
'enabled'
)
==
'1'
:
download_url
=
cnf
.
get
(
section
,
'url'
)
download_url
=
cnf
.
get
(
section
,
'url'
)
acl
=
Downloader
(
download_url
,
acl_max_timeout
)
if
cnf
.
has_option
(
section
,
'username'
):
download_username
=
cnf
.
get
(
section
,
'username'
)
download_password
=
cnf
.
get
(
section
,
'password'
)
else
:
download_username
=
None
download_password
=
None
acl
=
Downloader
(
download_url
,
download_username
,
download_password
,
acl_max_timeout
)
all_filenames
=
list
()
all_filenames
=
list
()
for
filename
,
line
in
acl
.
download
():
for
filename
,
line
in
acl
.
download
():
if
filename_in_ignorelist
(
os
.
path
.
basename
(
filename
)):
if
filename_in_ignorelist
(
os
.
path
.
basename
(
filename
)):
...
...
src/opnsense/service/templates/OPNsense/Proxy/externalACLs.conf
View file @
f8645117
...
@@ -7,5 +7,9 @@
...
@@ -7,5 +7,9 @@
url
:{{
blacklist
.
url
}}
url
:{{
blacklist
.
url
}}
enabled
:{{
blacklist
.
enabled
}}
enabled
:{{
blacklist
.
enabled
}}
filter
:{{
blacklist
.
filter
|
default
(
''
)}}
filter
:{{
blacklist
.
filter
|
default
(
''
)}}
{%
if
blacklist
.
username
|
default
(
''
) !=
''
%}
username
={{
blacklist
.
username
}}
password
={{
blacklist
.
password
|
default
(
''
)}}
{%
endif
%}
{%
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