Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
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
Nounous
re2o
Commits
ef6b6243
Commit
ef6b6243
authored
Mar 17, 2018
by
Maël Kervella
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Add support for firewall
parent
7028788c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
1 deletion
+60
-1
api/urls.py
api/urls.py
+3
-0
api/views.py
api/views.py
+57
-1
No files found.
api/urls.py
View file @
ef6b6243
...
...
@@ -35,6 +35,9 @@ urlpatterns = [
url
(
r
'^services/(?P<server_name>\w+)/(?P<service_name>\w+)/regen/$'
,
views
.
services_server_service_regen
),
url
(
r
'^services/(?P<server_name>\w+)/$'
,
views
.
services_server
),
# Firewall
url
(
r
'^firewall/ouverture_ports/$'
,
views
.
firewall_ouverture_ports
),
# DHCP
url
(
r
'^dhcp/mac-ip/$'
,
views
.
dhcp_mac_ip
),
...
...
api/views.py
View file @
ef6b6243
...
...
@@ -30,7 +30,8 @@ from django.views.decorators.csrf import csrf_exempt
from
re2o.utils
import
all_has_access
,
all_active_assigned_interfaces
from
users.models
import
Club
from
machines.models
import
Service_link
,
Service
,
Interface
,
Domain
from
machines.models
import
(
Service_link
,
Service
,
Interface
,
Domain
,
OuverturePortList
)
from
.serializers
import
*
from
.utils
import
JSONError
,
JSONSuccess
,
accept_method
...
...
@@ -114,6 +115,61 @@ def services_server(request, server_name):
return
JSONSuccess
(
seria
.
data
)
@
csrf_exempt
@
login_required
@
permission_required
(
'machines.serveur'
)
@
accept_method
([
'GET'
])
def
firewall_ouverture_ports
(
request
):
"""The list of the ports authorized to be openned by the firewall
Returns:
GET:
A JSONSuccess response with a `data` field containing:
* a field `ipv4` containing:
* a field `tcp_in` containing:
* a list of port number where ipv4 tcp in should be ok
* a field `tcp_out` containing:
* a list of port number where ipv4 tcp ou should be ok
* a field `udp_in` containing:
* a list of port number where ipv4 udp in should be ok
* a field `udp_out` containing:
* a list of port number where ipv4 udp out should be ok
* a field `ipv6` containing:
* a field `tcp_in` containing:
* a list of port number where ipv6 tcp in should be ok
* a field `tcp_out` containing:
* a list of port number where ipv6 tcp ou should be ok
* a field `udp_in` containing:
* a list of port number where ipv6 udp in should be ok
* a field `udp_out` containing:
* a list of port number where ipv6 udp out should be ok
"""
r
=
{
'ipv4'
:{},
'ipv6'
:{}}
for
o
in
OuverturePortList
.
objects
.
all
().
prefetch_related
(
'ouvertureport_set'
).
prefetch_related
(
'interface_set'
,
'interface_set__ipv4'
):
pl
=
{
"tcp_in"
:
set
(
map
(
str
,
o
.
ouvertureport_set
.
filter
(
protocole
=
OuverturePort
.
TCP
,
io
=
OuverturePort
.
IN
))),
"tcp_out"
:
set
(
map
(
str
,
o
.
ouvertureport_set
.
filter
(
protocole
=
OuverturePort
.
TCP
,
io
=
OuverturePort
.
OUT
))),
"udp_in"
:
set
(
map
(
str
,
o
.
ouvertureport_set
.
filter
(
protocole
=
OuverturePort
.
UDP
,
io
=
OuverturePort
.
IN
))),
"udp_out"
:
set
(
map
(
str
,
o
.
ouvertureport_set
.
filter
(
protocole
=
OuverturePort
.
UDP
,
io
=
OuverturePort
.
OUT
))),
}
for
i
in
filter_active_interfaces
(
o
.
interface_set
):
if
i
.
may_have_port_open
():
d
=
r
[
'ipv4'
].
get
(
i
.
ipv4
.
ipv4
,
{})
d
[
"tcp_in"
]
=
d
.
get
(
"tcp_in"
,
set
()).
union
(
pl
[
"tcp_in"
])
d
[
"tcp_out"
]
=
d
.
get
(
"tcp_out"
,
set
()).
union
(
pl
[
"tcp_out"
])
d
[
"udp_in"
]
=
d
.
get
(
"udp_in"
,
set
()).
union
(
pl
[
"udp_in"
])
d
[
"udp_out"
]
=
d
.
get
(
"udp_out"
,
set
()).
union
(
pl
[
"udp_out"
])
r
[
'ipv4'
][
i
.
ipv4
.
ipv4
]
=
d
if
i
.
ipv6
():
for
ipv6
in
i
.
ipv6
():
d
=
r
[
'ipv6'
].
get
(
ipv6
.
ipv6
,
{})
d
[
"tcp_in"
]
=
d
.
get
(
"tcp_in"
,
set
()).
union
(
pl
[
"tcp_in"
])
d
[
"tcp_out"
]
=
d
.
get
(
"tcp_out"
,
set
()).
union
(
pl
[
"tcp_out"
])
d
[
"udp_in"
]
=
d
.
get
(
"udp_in"
,
set
()).
union
(
pl
[
"udp_in"
])
d
[
"udp_out"
]
=
d
.
get
(
"udp_out"
,
set
()).
union
(
pl
[
"udp_out"
])
r
[
'ipv6'
][
ipv6
.
ipv6
]
=
d
return
JSONSuccess
(
r
)
@
csrf_exempt
@
login_required
@
permission_required
(
'machines.serveur'
)
...
...
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