2008-01-12 23:24:08 +01:00
|
|
|
#!/usr/bin/env python
|
2008-06-06 21:20:18 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-01-12 23:24:08 +01:00
|
|
|
#
|
2008-06-06 21:20:18 +02:00
|
|
|
# Copyright (C) 2007, 2008 by Jan Dittberner.
|
2008-01-12 23:24:08 +01:00
|
|
|
#
|
2008-06-06 21:20:18 +02:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
# USA.
|
|
|
|
#
|
|
|
|
# Version: $Id$
|
|
|
|
import getopt
|
|
|
|
import sys
|
2008-01-12 23:24:08 +01:00
|
|
|
from gnuviechadmin.dblayer import *
|
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
|
2008-01-12 23:24:08 +01:00
|
|
|
def usage():
|
2008-06-06 21:20:18 +02:00
|
|
|
print """Usage information:
|
|
|
|
=====================
|
|
|
|
%(process)s -h|--help
|
|
|
|
- prints this help text
|
2008-01-12 23:24:08 +01:00
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
%(process)s --domain=<domain> --sysuser=<sysuser> --type=MASTER|SLAVE \
|
|
|
|
[[--ns=<nameserver>] [--mx=<mxserver[,prio]>] [--a=<ipaddress>] ...]
|
|
|
|
- adds a new domain
|
|
|
|
""" % {'process': sys.argv[0]}
|
2008-01-12 23:24:08 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2008-06-06 21:20:18 +02:00
|
|
|
try:
|
|
|
|
(options, args) = getopt.getopt(sys.argv[1:], "h",
|
|
|
|
['help',
|
|
|
|
'domain=', 'sysuser=',
|
|
|
|
'type=', 'ns=', 'mx=', 'a='])
|
|
|
|
except getopt.GetoptError:
|
|
|
|
usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if (not options or
|
|
|
|
'-h' in dict(options) or
|
|
|
|
'--help' in dict(options) or
|
|
|
|
not '--domain' in dict(options) or
|
|
|
|
not '--sysuser' in dict(options) or
|
|
|
|
not dict(options)['--sysuser'].strip() or
|
|
|
|
not dict(options)['--domain'].strip()):
|
|
|
|
usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
po = {}
|
|
|
|
for (key, value) in options:
|
|
|
|
if key in po:
|
|
|
|
po[key].append(value.strip())
|
|
|
|
else:
|
|
|
|
po[key] = [value.strip()]
|
|
|
|
|
|
|
|
# fetch the sysuser
|
|
|
|
query = session.query(SysUser)
|
|
|
|
sysuser = query.get_by(name = po['--sysuser'][0])
|
|
|
|
if not sysuser:
|
|
|
|
print "Invalid system user"
|
|
|
|
allsysusers = query.get_by(name = '*')
|
|
|
|
if allsysusers:
|
|
|
|
print "Valid system users are:\n%s" % ("\n".join(allsysusers))
|
|
|
|
else:
|
|
|
|
print "No system users defined yet."
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
print sysuser.domains
|