From 0ad5307d3985005efd13fc16c492425e16c8de64 Mon Sep 17 00:00:00 2001 From: Kloadut Date: Wed, 31 Oct 2012 18:57:48 +0100 Subject: [PATCH 1/2] Add zone writing at domain creation' --- yunohost_domain.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/yunohost_domain.py b/yunohost_domain.py index 23737c85..93f8600f 100644 --- a/yunohost_domain.py +++ b/yunohost_domain.py @@ -2,6 +2,8 @@ import os import sys +import datetime +import requests from yunohost import YunoHostError, win_msg, colorize, validate, get_required_args def domain_list(args, connections): @@ -51,6 +53,10 @@ def domain_add(args, connections): """ yldap = connections['ldap'] attr_dict = { 'objectClass' : ['mailDomain', 'top'] } + request_ip = requests.get('http://ip.yunohost.org') + ip = str(request_ip.text) + now = datetime.datetime.now() + timestamp = str(now.year) + str(now.month) + str(now.day) result = [] args = get_required_args(args, { 'domain' : _('New domain') }) @@ -61,6 +67,27 @@ def domain_add(args, connections): validate({ domain : r'^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$' }) yldap.validate_uniqueness({ 'virtualdomain' : domain }) attr_dict['virtualdomain'] = domain + + try: + with open('/var/lib/bind/'+ domain +'.zone') as f: pass + except IOError as e: + zone_lines = [ + '$TTL 38400', + domain +'. IN SOA ns.'+ domain +'. root.'+ domain +'. '+ timestamp +' 10800 3600 604800 38400', + domain +'. IN NS ns.'+ domain +'.', + domain +'. IN A '+ ip, + domain +'. IN MX 5 mail.'+ domain +'.', + domain +'. IN TXT "v=spf1 a mx a:'+ domain +' ?all"', + 'mail.'+ domain +'. IN A '+ ip, + 'ns.'+ domain +'. IN A '+ ip, + 'root.'+ domain +'. IN A '+ ip + ] + with open('/var/lib/bind/' + domain + '.zone', 'w') as zone: + for line in zone_lines: + zone.write(line + '\n') + else: + raise YunoHostError(17, _("Zone file already exists for ") + domain) + if yldap.add('virtualdomain=' + domain + ',ou=domains', attr_dict): result.append(domain) continue @@ -93,6 +120,10 @@ def domain_remove(args, connections): for domain in args['domain']: validate({ domain : r'^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$' }) if yldap.remove('virtualdomain=' + domain + ',ou=domains'): + try: + os.remove('/var/lib/bind/'+ domain +'.zone') + except: + pass result.append(domain) continue else: From 00837e5f9890989e0e1382de31f87f61e4cc790b Mon Sep 17 00:00:00 2001 From: Alexis Gavoty Date: Thu, 1 Nov 2012 13:01:31 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ddb17b64..fd04cd31 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,10 @@ Specifications ### Monitoring - yunohost monitor info #FIX + yunohost monitor info [-h] [-u] [-d] [-p] [-c] [-m] [-i] + yunohost monitor process [-h] [-e PROCESS] [-d PROCESS] + [--stop PROCESS] [-c PORT] [-i] + [--start PROCESS] ### Tools