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
1900e512
Commit
1900e512
authored
Jul 21, 2015
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve the sort order of domains - siblings to the primary hostname were not sorted right
parent
d0ccde7b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
25 deletions
+55
-25
CHANGELOG.md
CHANGELOG.md
+1
-0
utils.py
management/utils.py
+54
-25
No files found.
CHANGELOG.md
View file @
1900e512
...
@@ -19,6 +19,7 @@ System:
...
@@ -19,6 +19,7 @@ System:
*
ownCloud updated to version 8.1.0.
*
ownCloud updated to version 8.1.0.
*
When upgrading, network checks like blocked port 25 are now skipped.
*
When upgrading, network checks like blocked port 25 are now skipped.
*
Tweaks to the intrusion detection rules for IMAP.
*
Tweaks to the intrusion detection rules for IMAP.
*
Improve the sort order of the domains in the status checks.
v0.12c (July 19, 2015)
v0.12c (July 19, 2015)
----------------------
----------------------
...
...
management/utils.py
View file @
1900e512
...
@@ -24,32 +24,52 @@ def safe_domain_name(name):
...
@@ -24,32 +24,52 @@ def safe_domain_name(name):
return
urllib
.
parse
.
quote
(
name
,
safe
=
''
)
return
urllib
.
parse
.
quote
(
name
,
safe
=
''
)
def
sort_domains
(
domain_names
,
env
):
def
sort_domains
(
domain_names
,
env
):
# Put domain names in a nice sorted order. For web_update, PRIMARY_HOSTNAME
# Put domain names in a nice sorted order.
# must appear first so it becomes the nginx default server.
# The nice order will group domain names by DNS zone, i.e. the top-most
# First group PRIMARY_HOSTNAME and its subdomains, then parent domains of PRIMARY_HOSTNAME, then other domains.
# domain name that we serve that ecompasses a set of subdomains. Map
groups
=
(
[],
[],
[]
)
# each of the domain names to the zone that contains them. Walk the domains
for
d
in
domain_names
:
# from shortest to longest since zones are always shorter than their
if
d
==
env
[
'PRIMARY_HOSTNAME'
]
or
d
.
endswith
(
"."
+
env
[
'PRIMARY_HOSTNAME'
]):
# subdomains.
groups
[
0
]
.
append
(
d
)
zones
=
{
}
elif
env
[
'PRIMARY_HOSTNAME'
]
.
endswith
(
"."
+
d
):
for
domain
in
sorted
(
domain_names
,
key
=
lambda
d
:
len
(
d
)):
groups
[
1
]
.
append
(
d
)
for
z
in
zones
.
values
():
if
domain
.
endswith
(
"."
+
z
):
# We found a parent domain already in the list.
zones
[
domain
]
=
z
break
else
:
else
:
groups
[
2
]
.
append
(
d
)
# 'break' did not occur: there is no parent domain, so it is its
# own zone.
# Within each group, sort parent domains before subdomains and after that sort lexicographically.
zones
[
domain
]
=
domain
def
sort_group
(
group
):
# Find the top-most domains.
# Sort the zones.
top_domains
=
sorted
(
d
for
d
in
group
if
len
([
s
for
s
in
group
if
d
.
endswith
(
"."
+
s
)])
==
0
)
zone_domains
=
sorted
(
zones
.
values
(),
ret
=
[]
key
=
lambda
d
:
(
for
d
in
top_domains
:
# PRIMARY_HOSTNAME or the zone that contains it is always first.
ret
.
append
(
d
)
not
(
d
==
env
[
'PRIMARY_HOSTNAME'
]
or
env
[
'PRIMARY_HOSTNAME'
]
.
endswith
(
"."
+
d
)),
ret
.
extend
(
sort_group
([
s
for
s
in
group
if
s
.
endswith
(
"."
+
d
)])
)
return
ret
# Then just dumb lexicographically.
d
,
groups
=
[
sort_group
(
g
)
for
g
in
groups
]
))
return
groups
[
0
]
+
groups
[
1
]
+
groups
[
2
]
# Now sort the domain names that fall within each zone.
domain_names
=
sorted
(
domain_names
,
key
=
lambda
d
:
(
# First by zone.
zone_domains
.
index
(
zones
[
d
]),
# PRIMARY_HOSTNAME is always first within the zone that contains it.
d
!=
env
[
'PRIMARY_HOSTNAME'
],
# Followed by any of its subdomains.
not
d
.
endswith
(
"."
+
env
[
'PRIMARY_HOSTNAME'
]),
# Then in right-to-left lexicographic order of the .-separated parts of the name.
list
(
reversed
(
d
.
split
(
"."
))),
))
return
domain_names
def
sort_email_addresses
(
email_addresses
,
env
):
def
sort_email_addresses
(
email_addresses
,
env
):
email_addresses
=
set
(
email_addresses
)
email_addresses
=
set
(
email_addresses
)
...
@@ -200,3 +220,12 @@ def wait_for_service(port, public, env, timeout):
...
@@ -200,3 +220,12 @@ def wait_for_service(port, public, env, timeout):
if
time
.
perf_counter
()
>
start
+
timeout
:
if
time
.
perf_counter
()
>
start
+
timeout
:
return
False
return
False
time
.
sleep
(
min
(
timeout
/
4
,
1
))
time
.
sleep
(
min
(
timeout
/
4
,
1
))
if
__name__
==
"__main__"
:
from
dns_update
import
get_dns_domains
from
web_update
import
get_web_domains
,
get_default_www_redirects
env
=
load_environment
()
domains
=
get_dns_domains
(
env
)
|
set
(
get_web_domains
(
env
)
+
get_default_www_redirects
(
env
))
domains
=
sort_domains
(
domains
,
env
)
for
domain
in
domains
:
print
(
domain
)
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