mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
domain
This commit is contained in:
parent
0b41a48596
commit
72dd190f39
1 changed files with 38 additions and 11 deletions
|
@ -3,7 +3,8 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import datetime
|
import datetime
|
||||||
import requests
|
import re
|
||||||
|
from urllib import urlopen
|
||||||
from yunohost import YunoHostError, win_msg, colorize, validate, get_required_args
|
from yunohost import YunoHostError, win_msg, colorize, validate, get_required_args
|
||||||
|
|
||||||
def domain_list(args, connections):
|
def domain_list(args, connections):
|
||||||
|
@ -53,8 +54,7 @@ def domain_add(args, connections):
|
||||||
"""
|
"""
|
||||||
yldap = connections['ldap']
|
yldap = connections['ldap']
|
||||||
attr_dict = { 'objectClass' : ['mailDomain', 'top'] }
|
attr_dict = { 'objectClass' : ['mailDomain', 'top'] }
|
||||||
request_ip = requests.get('http://ip.yunohost.org')
|
ip = str(urlopen('http://ip.yunohost.org').read())
|
||||||
ip = str(request_ip.text)
|
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
timestamp = str(now.year) + str(now.month) + str(now.day)
|
timestamp = str(now.year) + str(now.month) + str(now.day)
|
||||||
result = []
|
result = []
|
||||||
|
@ -88,6 +88,20 @@ def domain_add(args, connections):
|
||||||
else:
|
else:
|
||||||
raise YunoHostError(17, _("Zone file already exists for ") + domain)
|
raise YunoHostError(17, _("Zone file already exists for ") + domain)
|
||||||
|
|
||||||
|
conf_lines = [
|
||||||
|
'zone "'+ domain +'" {',
|
||||||
|
' type master;',
|
||||||
|
' file "/var/lib/bind/'+ domain +'.zone";',
|
||||||
|
' allow-transfer {',
|
||||||
|
' 127.0.0.1;',
|
||||||
|
' localnets;',
|
||||||
|
' };',
|
||||||
|
'};'
|
||||||
|
]
|
||||||
|
with open('/etc/bind/named.conf.local', 'a') as conf:
|
||||||
|
for line in conf_lines:
|
||||||
|
conf.write(line + '\n')
|
||||||
|
|
||||||
if yldap.add('virtualdomain=' + domain + ',ou=domains', attr_dict):
|
if yldap.add('virtualdomain=' + domain + ',ou=domains', attr_dict):
|
||||||
result.append(domain)
|
result.append(domain)
|
||||||
continue
|
continue
|
||||||
|
@ -124,6 +138,18 @@ def domain_remove(args, connections):
|
||||||
os.remove('/var/lib/bind/'+ domain +'.zone')
|
os.remove('/var/lib/bind/'+ domain +'.zone')
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
with open('/etc/bind/named.conf.local', 'r') as conf:
|
||||||
|
conf_lines = conf.readlines()
|
||||||
|
with open('/etc/bind/named.conf.local', 'w') as conf:
|
||||||
|
in_block = False
|
||||||
|
for line in conf_lines:
|
||||||
|
if re.search(r'^zone "'+ domain, line):
|
||||||
|
in_block = True
|
||||||
|
if in_block:
|
||||||
|
if re.search(r'^};$', line):
|
||||||
|
in_block = False
|
||||||
|
else:
|
||||||
|
conf.write(line)
|
||||||
result.append(domain)
|
result.append(domain)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
@ -131,3 +157,4 @@ def domain_remove(args, connections):
|
||||||
|
|
||||||
win_msg(_("Domain(s) successfully deleted"))
|
win_msg(_("Domain(s) successfully deleted"))
|
||||||
return { 'Domains' : result }
|
return { 'Domains' : result }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue