Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
20d3af76
authored
Jan 04, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pretty print rules
parent
12844905
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
8 deletions
+24
-8
firewall/admin.py
+1
-1
firewall/models.py
+22
-7
firewall/tasks.py
+1
-0
No files found.
firewall/admin.py
View file @
20d3af76
...
...
@@ -14,7 +14,7 @@ class VlanAdmin(admin.ModelAdmin):
ordering
=
(
'vid'
,)
class
RuleAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'r_type'
,
'desc'
,
'description'
,
'vlan_l'
,
'owner'
,
'extra'
,
'direction'
,
'accept'
,
'proto'
,
'sport'
,
'dport'
,
'nat'
,
'nat_dport'
)
list_display
=
(
'r_type'
,
'
color_
desc'
,
'description'
,
'vlan_l'
,
'owner'
,
'extra'
,
'direction'
,
'accept'
,
'proto'
,
'sport'
,
'dport'
,
'nat'
,
'nat_dport'
)
list_filter
=
(
'r_type'
,
'vlan'
,
'owner'
,
'direction'
,
'accept'
,
'proto'
,
'nat'
)
admin
.
site
.
register
(
Host
,
HostAdmin
)
...
...
firewall/models.py
View file @
20d3af76
# -*- coding: utf8 -*-
from
django.contrib.auth.models
import
User
from
django.db
import
models
from
django.forms
import
fields
,
ValidationError
...
...
@@ -25,15 +27,28 @@ class Rule(models.Model):
def
__unicode__
(
self
):
return
self
.
desc
()
def
color_desc
(
self
):
para
=
'</span>'
if
(
self
.
dport
):
para
=
"dport=
%
s
%
s"
%
(
self
.
dport
,
para
)
if
(
self
.
sport
):
para
=
"sport=
%
s
%
s"
%
(
self
.
sport
,
para
)
if
(
self
.
proto
):
para
=
"proto=
%
s
%
s"
%
(
self
.
proto
,
para
)
para
=
'<span style="color: #00FF00;">'
+
para
return
'<span style="color: #FF0000;">['
+
self
.
r_type
+
']</span> '
+
(
self
.
vlan_l
()
+
'<span style="color: #0000FF;">→</span>'
+
self
.
r_type
if
self
.
direction
==
'1'
else
self
.
r_type
+
'<span style="color: #0000FF;">→</span>'
+
self
.
vlan_l
())
+
' '
+
para
+
' '
+
self
.
description
color_desc
.
allow_tags
=
True
def
desc
(
self
):
para
=
""
if
(
self
.
dport
):
para
=
"dport=
%
s
%
s"
%
(
self
.
dport
,
para
)
if
(
self
.
sport
):
para
=
"
d
port=
%
s
%
s"
%
(
self
.
sport
,
para
)
para
=
"
s
port=
%
s
%
s"
%
(
self
.
sport
,
para
)
if
(
self
.
proto
):
para
=
"
dport
=
%
s
%
s"
%
(
self
.
proto
,
para
)
return
'['
+
self
.
r_type
+
'] '
+
(
self
.
vlan_l
()
+
'
->'
+
self
.
r_type
if
self
.
direction
else
self
.
r_type
+
'->
'
+
self
.
vlan_l
())
+
' '
+
para
+
' '
+
self
.
description
para
=
"
proto
=
%
s
%
s"
%
(
self
.
proto
,
para
)
return
'['
+
self
.
r_type
+
'] '
+
(
self
.
vlan_l
()
+
'
→'
+
self
.
r_type
if
self
.
direction
==
'1'
else
self
.
r_type
+
'→
'
+
self
.
vlan_l
())
+
' '
+
para
+
' '
+
self
.
description
def
vlan_l
(
self
):
retval
=
[]
for
vl
in
self
.
vlan
.
all
():
...
...
@@ -113,9 +128,9 @@ class Host(models.Model):
def
rules_l
(
self
):
retval
=
[]
for
rl
in
self
.
rules
.
all
():
retval
.
append
(
str
(
rl
))
return
'
,
'
.
join
(
retval
)
retval
.
append
(
str
(
rl
.
color_desc
()
))
return
'
<br>
'
.
join
(
retval
)
rules_l
.
allow_tags
=
True
def
enable_net
(
self
):
self
.
groups
.
add
(
Group
.
objects
.
get
(
name
=
"netezhet"
))
...
...
@@ -126,7 +141,7 @@ class Host(models.Model):
for
host
in
Host
.
objects
.
filter
(
pub_ipv4
=
self
.
pub_ipv4
):
if
host
.
rules
.
filter
(
nat
=
True
,
proto
=
proto
,
dport
=
public
):
raise
ValidationError
(
"A
%
s
%
s port mar hasznalva"
%
(
proto
,
public
))
rule
=
Rule
(
direction
=
'1'
,
owner
=
self
.
owner
,
description
=
"
%
s
%
s
%
s
->
%
s"
%
(
self
.
hostname
,
proto
,
public
,
private
),
dport
=
public
,
proto
=
proto
,
nat
=
True
,
accept
=
True
,
r_type
=
"host"
,
nat_dport
=
private
)
rule
=
Rule
(
direction
=
'1'
,
owner
=
self
.
owner
,
description
=
"
%
s
%
s
%
s
→
%
s"
%
(
self
.
hostname
,
proto
,
public
,
private
),
dport
=
public
,
proto
=
proto
,
nat
=
True
,
accept
=
True
,
r_type
=
"host"
,
nat_dport
=
private
)
rule
.
full_clean
()
rule
.
save
()
rule
.
vlan
.
add
(
Vlan
.
objects
.
get
(
name
=
"PUB"
))
...
...
firewall/tasks.py
View file @
20d3af76
...
...
@@ -36,6 +36,7 @@ class ReloadTask(Task):
dhcp
()
print
"vege"
except
:
raise
print
"nem sikerult :("
print
"leall"
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