Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mailinabox
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
Administrator
mailinabox
Commits
33f06f29
Commit
33f06f29
authored
Jun 17, 2014
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
let the user override some DNS records
parent
88709506
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
12 deletions
+36
-12
daemon.py
management/daemon.py
+1
-1
dns_update.py
management/dns_update.py
+31
-8
management.sh
setup/management.sh
+2
-1
system.sh
setup/system.sh
+2
-2
No files found.
management/daemon.py
View file @
33f06f29
...
@@ -62,7 +62,7 @@ def dns_update():
...
@@ -62,7 +62,7 @@ def dns_update():
def
dns_get_ds_records
():
def
dns_get_ds_records
():
from
dns_update
import
get_ds_records
from
dns_update
import
get_ds_records
try
:
try
:
return
get_ds_records
(
env
)
return
get_ds_records
(
env
)
.
replace
(
"
\t
"
,
" "
)
# tabs confuse godaddy
except
Exception
as
e
:
except
Exception
as
e
:
return
(
str
(
e
),
500
)
return
(
str
(
e
),
500
)
...
...
management/dns_update.py
View file @
33f06f29
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
########################################################################
########################################################################
import
os
,
os
.
path
,
urllib
.
parse
,
datetime
,
re
import
os
,
os
.
path
,
urllib
.
parse
,
datetime
,
re
import
rtyaml
from
mailconfig
import
get_mail_domains
from
mailconfig
import
get_mail_domains
from
utils
import
shell
,
load_env_vars_from_file
from
utils
import
shell
,
load_env_vars_from_file
...
@@ -34,7 +35,7 @@ def do_dns_update(env):
...
@@ -34,7 +35,7 @@ def do_dns_update(env):
updated_domains
=
[]
updated_domains
=
[]
for
i
,
(
domain
,
zonefile
)
in
enumerate
(
zonefiles
):
for
i
,
(
domain
,
zonefile
)
in
enumerate
(
zonefiles
):
# Build the records to put in the zone.
# Build the records to put in the zone.
records
=
build_zone
(
domain
,
env
)
records
=
build_zone
(
domain
,
zonefile
,
env
)
# See if the zone has changed, and if so update the serial number
# See if the zone has changed, and if so update the serial number
# and write the zone file.
# and write the zone file.
...
@@ -91,24 +92,43 @@ def do_dns_update(env):
...
@@ -91,24 +92,43 @@ def do_dns_update(env):
########################################################################
########################################################################
def
build_zone
(
domain
,
env
):
def
build_zone
(
domain
,
zonefile
,
env
):
records
=
[]
records
=
[]
records
.
append
((
None
,
"NS"
,
"ns1.
%
s."
%
env
[
"PUBLIC_HOSTNAME"
]))
records
.
append
((
None
,
"NS"
,
"ns1.
%
s."
%
env
[
"PUBLIC_HOSTNAME"
]))
records
.
append
((
None
,
"NS"
,
"ns2.
%
s."
%
env
[
"PUBLIC_HOSTNAME"
]))
records
.
append
((
None
,
"NS"
,
"ns2.
%
s."
%
env
[
"PUBLIC_HOSTNAME"
]))
records
.
append
((
None
,
"A"
,
env
[
"PUBLIC_IP"
]))
if
env
.
get
(
'PUBLIC_IPV6'
):
records
.
append
((
None
,
"AAAA"
,
env
[
"PUBLIC_IPV6"
]))
records
.
append
((
None
,
"MX"
,
"10
%
s."
%
env
[
"PUBLIC_HOSTNAME"
]))
records
.
append
((
None
,
"MX"
,
"10
%
s."
%
env
[
"PUBLIC_HOSTNAME"
]))
records
.
append
((
None
,
"TXT"
,
'"v=spf1 mx -all"'
))
records
.
append
((
None
,
"TXT"
,
'"v=spf1 mx -all"'
))
records
.
append
((
"www"
,
"A"
,
env
[
"PUBLIC_IP"
]))
if
env
.
get
(
'PUBLIC_IPV6'
):
records
.
append
((
"www"
,
"AAAA"
,
env
[
"PUBLIC_IPV6"
]))
# In PUBLIC_HOSTNAME, also define ns1 and ns2.
# In PUBLIC_HOSTNAME, also define ns1 and ns2.
if
domain
==
env
[
"PUBLIC_HOSTNAME"
]:
if
domain
==
env
[
"PUBLIC_HOSTNAME"
]:
records
.
append
((
"ns1"
,
"A"
,
env
[
"PUBLIC_IP"
]))
records
.
append
((
"ns1"
,
"A"
,
env
[
"PUBLIC_IP"
]))
records
.
append
((
"ns2"
,
"A"
,
env
[
"PUBLIC_IP"
]))
records
.
append
((
"ns2"
,
"A"
,
env
[
"PUBLIC_IP"
]))
def
has_rec
(
qname
,
rtype
):
for
rec
in
records
:
if
rec
[
0
]
==
qname
and
rec
[
1
]
==
rtype
:
return
True
return
False
# The user may set other records that don't conflict with our settings.
custom_zone_file
=
os
.
path
.
join
(
env
[
'STORAGE_ROOT'
],
'dns/custom'
,
zonefile
.
replace
(
".txt"
,
".yaml"
))
if
os
.
path
.
exists
(
custom_zone_file
):
custom_zone
=
rtyaml
.
load
(
open
(
custom_zone_file
))
for
qname
,
value
in
custom_zone
.
items
():
if
has_rec
(
qname
,
value
):
continue
if
isinstance
(
value
,
str
):
records
.
append
((
qname
,
"A"
,
value
))
elif
isinstance
(
value
,
dict
):
for
rtype
,
value2
in
value
.
items
():
if
rtype
==
"TXT"
:
value2
=
"
\"
"
+
value2
+
"
\"
"
records
.
append
((
qname
,
rtype
,
value2
))
# Add defaults if not overridden by the user's custom settings.
if
not
has_rec
(
None
,
"A"
):
records
.
append
((
None
,
"A"
,
env
[
"PUBLIC_IP"
]))
if
env
.
get
(
'PUBLIC_IPV6'
)
and
not
has_rec
(
None
,
"AAAA"
):
records
.
append
((
None
,
"AAAA"
,
env
[
"PUBLIC_IPV6"
]))
if
not
has_rec
(
"www"
,
"A"
):
records
.
append
((
"www"
,
"A"
,
env
[
"PUBLIC_IP"
]))
if
env
.
get
(
'PUBLIC_IPV6'
)
and
not
has_rec
(
"www"
,
"AAAA"
):
records
.
append
((
"www"
,
"AAAA"
,
env
[
"PUBLIC_IPV6"
]))
# If OpenDKIM is in use..
# If OpenDKIM is in use..
opendkim_record_file
=
os
.
path
.
join
(
env
[
'STORAGE_ROOT'
],
'mail/dkim/mail.txt'
)
opendkim_record_file
=
os
.
path
.
join
(
env
[
'STORAGE_ROOT'
],
'mail/dkim/mail.txt'
)
if
os
.
path
.
exists
(
opendkim_record_file
):
if
os
.
path
.
exists
(
opendkim_record_file
):
...
@@ -121,6 +141,9 @@ def build_zone(domain, env):
...
@@ -121,6 +141,9 @@ def build_zone(domain, env):
records
.
append
((
"_adsp._domainkey"
,
"TXT"
,
'"dkim=all"'
))
records
.
append
((
"_adsp._domainkey"
,
"TXT"
,
'"dkim=all"'
))
records
.
append
((
"_dmarc"
,
"TXT"
,
'"v=DMARC1; p=quarantine"'
))
records
.
append
((
"_dmarc"
,
"TXT"
,
'"v=DMARC1; p=quarantine"'
))
# Sort the records. The None records *must* go first. Otherwise it doesn't matter.
records
.
sort
(
key
=
lambda
rec
:
(
rec
[
0
]
is
not
None
,
str
(
rec
[
0
])))
return
records
return
records
########################################################################
########################################################################
...
...
setup/management.sh
View file @
33f06f29
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
source
setup/functions.sh
source
setup/functions.sh
apt_install python3-flask links duplicity
apt_install python3-flask links duplicity libyaml-dev
pip3
install
rtyaml
# Create a backup directory and a random key for encrypting backups.
# Create a backup directory and a random key for encrypting backups.
mkdir
-p
$STORAGE_ROOT
/backup
mkdir
-p
$STORAGE_ROOT
/backup
...
...
setup/system.sh
View file @
33f06f29
...
@@ -7,7 +7,7 @@ apt-get -qq -y upgrade
...
@@ -7,7 +7,7 @@ apt-get -qq -y upgrade
# Install basic utilities.
# Install basic utilities.
apt_install python3 wget curl bind9-host
apt_install python3
python3-pip
wget curl bind9-host
# Turn on basic services:
# Turn on basic services:
#
#
...
...
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