Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5cd533d2
authored
Oct 15, 2013
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: fix TXT record, refactor dns()
parent
aa53d585
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
24 deletions
+45
-24
circle/firewall/fw.py
+41
-21
circle/firewall/migrations/0038_auto__chg_field_record_address.py
+0
-0
circle/firewall/models.py
+4
-3
No files found.
circle/firewall/fw.py
View file @
5cd533d2
...
@@ -320,39 +320,39 @@ def ipv6_to_arpa(ipv6):
...
@@ -320,39 +320,39 @@ def ipv6_to_arpa(ipv6):
# ^ PTR
# ^ PTR
# C CNAME
# C CNAME
# : generic
# : generic
# 'fqdn:s:ttl TXT
def
dns
():
def
generate_ptr_records
():
vlans
=
models
.
Vlan
.
objects
.
all
()
# regex = re.compile(r'^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$')
DNS
=
[]
DNS
=
[]
for
i_vlan
in
vlans
:
for
host
in
models
.
Host
.
objects
.
order_by
(
'vlan'
)
.
all
():
# m = regex.search(i_vlan.net4)
rev
=
host
.
vlan
.
reverse_domain
rev
=
i_vlan
.
reverse_domain
ipv4
=
str
(
host
.
pub_ipv4
if
host
.
pub_ipv4
and
not
host
.
shared_ip
else
host
.
ipv4
)
for
i_host
in
i_vlan
.
host_set
.
all
():
ipv4
=
(
i_host
.
pub_ipv4
if
i_host
.
pub_ipv4
and
not
i_host
.
shared_ip
else
i_host
.
ipv4
)
i
=
ipv4
.
split
(
'.'
,
4
)
i
=
ipv4
.
split
(
'.'
,
4
)
reverse
=
(
i_host
.
reverse
if
i_
host
.
reverse
and
reverse
=
(
host
.
reverse
if
host
.
reverse
and
len
(
i_host
.
reverse
)
else
i_
host
.
get_fqdn
())
len
(
host
.
reverse
)
else
host
.
get_fqdn
())
# ipv4
# ipv4
if
i_
host
.
ipv4
:
if
host
.
ipv4
:
DNS
.
append
(
"^
%
s:
%
s:
%
s"
%
(
DNS
.
append
(
"^
%
s:
%
s:
%
s"
%
(
(
rev
%
{
'a'
:
int
(
i
[
0
]),
'b'
:
int
(
i
[
1
]),
'c'
:
int
(
i
[
2
]),
(
rev
%
{
'a'
:
int
(
i
[
0
]),
'b'
:
int
(
i
[
1
]),
'c'
:
int
(
i
[
2
]),
'd'
:
int
(
i
[
3
])}),
'd'
:
int
(
i
[
3
])}),
reverse
,
models
.
settings
[
'dns_ttl'
]))
reverse
,
models
.
settings
[
'dns_ttl'
]))
# ipv6
# ipv6
if
i_
host
.
ipv6
:
if
host
.
ipv6
:
DNS
.
append
(
"^
%
s:
%
s:
%
s"
%
(
ipv6_to_arpa
(
i_host
.
ipv6
),
DNS
.
append
(
"^
%
s:
%
s:
%
s"
%
(
ipv6_to_arpa
(
str
(
host
.
ipv6
)
),
reverse
,
models
.
settings
[
'dns_ttl'
]))
reverse
,
models
.
settings
[
'dns_ttl'
]))
return
DNS
def
txt_to_octal
(
txt
):
return
'
\\
'
+
'
\\
'
.
join
([
'
%03
o'
%
ord
(
x
)
for
x
in
txt
])
for
domain
in
models
.
Domain
.
objects
.
all
():
DNS
.
append
(
"Z
%
s:
%
s:support.ik.bme.hu::::::
%
s"
%
def
generate_records
():
(
domain
.
name
,
settings
[
'dns_hostname'
],
DNS
=
[]
models
.
settings
[
'dns_ttl'
]))
for
r
in
models
.
Record
.
objects
.
all
():
for
r
in
models
.
Record
.
objects
.
all
():
if
r
.
type
==
'A'
:
if
r
.
type
==
'A'
:
...
@@ -371,19 +371,39 @@ def dns():
...
@@ -371,19 +371,39 @@ def dns():
'ttl'
:
r
.
ttl
})
'ttl'
:
r
.
ttl
})
elif
r
.
type
==
'PTR'
:
elif
r
.
type
==
'PTR'
:
DNS
.
append
(
"^
%
s:
%
s:
%
s"
%
(
r
.
fqdn
,
r
.
address
,
r
.
ttl
))
DNS
.
append
(
"^
%
s:
%
s:
%
s"
%
(
r
.
fqdn
,
r
.
address
,
r
.
ttl
))
elif
r
.
type
==
'TXT'
:
DNS
.
append
(
"'
%
s:
%
s:
%
s"
%
(
r
.
fqdn
,
txt_to_octal
(
r
.
address
),
r
.
ttl
))
return
DNS
def
dns
():
DNS
=
[]
# host PTR record
DNS
+=
generate_ptr_records
()
# domain SOA record
for
domain
in
models
.
Domain
.
objects
.
all
():
DNS
.
append
(
"Z
%
s:
%
s:support.ik.bme.hu::::::
%
s"
%
(
domain
.
name
,
settings
[
'dns_hostname'
],
models
.
settings
[
'dns_ttl'
]))
# records
DNS
+=
generate_records
()
return
DNS
return
DNS
def
dhcp
():
def
dhcp
():
vlans
=
models
.
Vlan
.
objects
.
all
()
regex
=
re
.
compile
(
r'^([0-9]+)\.([0-9]+)\.[0-9]+\.[0-9]+\s+'
regex
=
re
.
compile
(
r'^([0-9]+)\.([0-9]+)\.[0-9]+\.[0-9]+\s+'
r'([0-9]+)\.([0-9]+)\.[0-9]+\.[0-9]+$'
)
r'([0-9]+)\.([0-9]+)\.[0-9]+\.[0-9]+$'
)
DHCP
=
[]
DHCP
=
[]
# /tools/dhcp3/dhcpd.conf.generated
# /tools/dhcp3/dhcpd.conf.generated
for
i_vlan
in
vlans
:
for
i_vlan
in
models
.
Vlan
.
objects
.
all
()
:
if
(
i_vlan
.
dhcp_pool
):
if
(
i_vlan
.
dhcp_pool
):
m
=
regex
.
search
(
i_vlan
.
dhcp_pool
)
m
=
regex
.
search
(
i_vlan
.
dhcp_pool
)
if
(
m
or
i_vlan
.
dhcp_pool
==
"manual"
):
if
(
m
or
i_vlan
.
dhcp_pool
==
"manual"
):
...
...
circle/firewall/migrations/0038_auto__chg_field_record_address.py
0 → 100644
View file @
5cd533d2
This diff is collapsed.
Click to expand it.
circle/firewall/models.py
View file @
5cd533d2
...
@@ -457,7 +457,6 @@ class Host(models.Model):
...
@@ -457,7 +457,6 @@ class Host(models.Model):
type
=
'A'
)
.
save
()
type
=
'A'
)
.
save
()
if
self
.
ipv6
:
if
self
.
ipv6
:
print
'aaaaaaaaa'
,
self
.
ipv6
Record
.
objects
.
filter
(
host
=
self
,
name
=
self
.
hostname
,
Record
.
objects
.
filter
(
host
=
self
,
name
=
self
.
hostname
,
type
=
'AAAA'
)
.
update
(
address
=
self
.
ipv6
)
type
=
'AAAA'
)
.
update
(
address
=
self
.
ipv6
)
record_count
=
self
.
record_set
.
filter
(
host
=
self
,
record_count
=
self
.
record_set
.
filter
(
host
=
self
,
...
@@ -673,7 +672,7 @@ class Record(models.Model):
...
@@ -673,7 +672,7 @@ class Record(models.Model):
verbose_name
=
_
(
'host'
))
verbose_name
=
_
(
'host'
))
type
=
models
.
CharField
(
max_length
=
6
,
choices
=
CHOICES_type
,
type
=
models
.
CharField
(
max_length
=
6
,
choices
=
CHOICES_type
,
verbose_name
=
_
(
'type'
))
verbose_name
=
_
(
'type'
))
address
=
models
.
CharField
(
max_length
=
4
0
,
address
=
models
.
CharField
(
max_length
=
20
0
,
verbose_name
=
_
(
'address'
))
verbose_name
=
_
(
'address'
))
ttl
=
models
.
IntegerField
(
default
=
600
,
verbose_name
=
_
(
'ttl'
))
ttl
=
models
.
IntegerField
(
default
=
600
,
verbose_name
=
_
(
'ttl'
))
owner
=
models
.
ForeignKey
(
User
,
verbose_name
=
_
(
'owner'
))
owner
=
models
.
ForeignKey
(
User
,
verbose_name
=
_
(
'owner'
))
...
@@ -701,10 +700,12 @@ class Record(models.Model):
...
@@ -701,10 +700,12 @@ class Record(models.Model):
val_ipv4
(
self
.
address
)
val_ipv4
(
self
.
address
)
elif
self
.
type
==
'AAAA'
:
elif
self
.
type
==
'AAAA'
:
val_ipv6
(
self
.
address
)
val_ipv6
(
self
.
address
)
elif
self
.
type
in
[
'CNAME'
,
'NS'
,
'PTR'
,
'TXT'
]:
elif
self
.
type
in
[
'CNAME'
,
'NS'
,
'PTR'
]:
val_domain
(
self
.
address
)
val_domain
(
self
.
address
)
elif
self
.
type
==
'MX'
:
elif
self
.
type
==
'MX'
:
val_mx
(
self
.
address
)
val_mx
(
self
.
address
)
elif
self
.
type
==
'TXT'
:
pass
else
:
else
:
raise
ValidationError
(
_
(
"Unknown record type."
))
raise
ValidationError
(
_
(
"Unknown record type."
))
...
...
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