Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
34 deletions
+55
-34
circle/firewall/fw.py
+51
-31
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):
# ^ PTR
# C CNAME
# : generic
# 'fqdn:s:ttl TXT
def
dns
():
vlans
=
models
.
Vlan
.
objects
.
all
()
# regex = re.compile(r'^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$')
def
generate_ptr_records
():
DNS
=
[]
for
i_vlan
in
vlans
:
# m = regex.search(i_vlan.net4)
rev
=
i_vlan
.
reverse_domain
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
)
reverse
=
(
i_host
.
reverse
if
i_host
.
reverse
and
len
(
i_host
.
reverse
)
else
i_host
.
get_fqdn
())
# ipv4
if
i_host
.
ipv4
:
DNS
.
append
(
"^
%
s:
%
s:
%
s"
%
(
(
rev
%
{
'a'
:
int
(
i
[
0
]),
'b'
:
int
(
i
[
1
]),
'c'
:
int
(
i
[
2
]),
'd'
:
int
(
i
[
3
])}),
reverse
,
models
.
settings
[
'dns_ttl'
]))
# ipv6
if
i_host
.
ipv6
:
DNS
.
append
(
"^
%
s:
%
s:
%
s"
%
(
ipv6_to_arpa
(
i_host
.
ipv6
),
reverse
,
models
.
settings
[
'dns_ttl'
]))
for
host
in
models
.
Host
.
objects
.
order_by
(
'vlan'
)
.
all
():
rev
=
host
.
vlan
.
reverse_domain
ipv4
=
str
(
host
.
pub_ipv4
if
host
.
pub_ipv4
and
not
host
.
shared_ip
else
host
.
ipv4
)
i
=
ipv4
.
split
(
'.'
,
4
)
reverse
=
(
host
.
reverse
if
host
.
reverse
and
len
(
host
.
reverse
)
else
host
.
get_fqdn
())
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'
]))
# ipv4
if
host
.
ipv4
:
DNS
.
append
(
"^
%
s:
%
s:
%
s"
%
(
(
rev
%
{
'a'
:
int
(
i
[
0
]),
'b'
:
int
(
i
[
1
]),
'c'
:
int
(
i
[
2
]),
'd'
:
int
(
i
[
3
])}),
reverse
,
models
.
settings
[
'dns_ttl'
]))
# ipv6
if
host
.
ipv6
:
DNS
.
append
(
"^
%
s:
%
s:
%
s"
%
(
ipv6_to_arpa
(
str
(
host
.
ipv6
)),
reverse
,
models
.
settings
[
'dns_ttl'
]))
return
DNS
def
txt_to_octal
(
txt
):
return
'
\\
'
+
'
\\
'
.
join
([
'
%03
o'
%
ord
(
x
)
for
x
in
txt
])
def
generate_records
():
DNS
=
[]
for
r
in
models
.
Record
.
objects
.
all
():
if
r
.
type
==
'A'
:
...
...
@@ -371,19 +371,39 @@ def dns():
'ttl'
:
r
.
ttl
})
elif
r
.
type
==
'PTR'
:
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
def
dhcp
():
vlans
=
models
.
Vlan
.
objects
.
all
()
regex
=
re
.
compile
(
r'^([0-9]+)\.([0-9]+)\.[0-9]+\.[0-9]+\s+'
r'([0-9]+)\.([0-9]+)\.[0-9]+\.[0-9]+$'
)
DHCP
=
[]
# /tools/dhcp3/dhcpd.conf.generated
for
i_vlan
in
vlans
:
for
i_vlan
in
models
.
Vlan
.
objects
.
all
()
:
if
(
i_vlan
.
dhcp_pool
):
m
=
regex
.
search
(
i_vlan
.
dhcp_pool
)
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):
type
=
'A'
)
.
save
()
if
self
.
ipv6
:
print
'aaaaaaaaa'
,
self
.
ipv6
Record
.
objects
.
filter
(
host
=
self
,
name
=
self
.
hostname
,
type
=
'AAAA'
)
.
update
(
address
=
self
.
ipv6
)
record_count
=
self
.
record_set
.
filter
(
host
=
self
,
...
...
@@ -673,7 +672,7 @@ class Record(models.Model):
verbose_name
=
_
(
'host'
))
type
=
models
.
CharField
(
max_length
=
6
,
choices
=
CHOICES_type
,
verbose_name
=
_
(
'type'
))
address
=
models
.
CharField
(
max_length
=
4
0
,
address
=
models
.
CharField
(
max_length
=
20
0
,
verbose_name
=
_
(
'address'
))
ttl
=
models
.
IntegerField
(
default
=
600
,
verbose_name
=
_
(
'ttl'
))
owner
=
models
.
ForeignKey
(
User
,
verbose_name
=
_
(
'owner'
))
...
...
@@ -701,10 +700,12 @@ class Record(models.Model):
val_ipv4
(
self
.
address
)
elif
self
.
type
==
'AAAA'
:
val_ipv6
(
self
.
address
)
elif
self
.
type
in
[
'CNAME'
,
'NS'
,
'PTR'
,
'TXT'
]:
elif
self
.
type
in
[
'CNAME'
,
'NS'
,
'PTR'
]:
val_domain
(
self
.
address
)
elif
self
.
type
==
'MX'
:
val_mx
(
self
.
address
)
elif
self
.
type
==
'TXT'
:
pass
else
:
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