1
0
Fork 0
gnuviechadmin-historic/testdb/addpopuser.py
Jan Dittberner dea15a6c4f - repository reorganization
git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/trunk@242 a67ec6bc-e5d5-0310-a910-815c51eb3124
2008-01-12 22:24:08 +00:00

45 lines
1.2 KiB
Python

#!/usr/bin/env python
#
# Copyright (c) 2007 Jan Dittberner
# $Id$
#
import getopt, sys
from gnuviechadmin.dblayer import *
def usage():
print """Usage information:
=====================
%(process)s -h|--help
- prints this help text
%(process)s --domain=<domain> [--password=<password>]
- adds a new pop user for the given domain
- if the optional password is ommitted a generated one is used
- the password is checked using cracklib
- if the password is too weak a generated one is used
""" % {'process': sys.argv[0]}
if __name__ == "__main__":
try:
(options, args) = getopt.getopt(sys.argv[1:], "h", ['help', 'password=', 'domain='])
except getopt.GetoptError:
usage()
sys.exit(1)
if (not options or
dict(options).has_key('-h') or
dict(options).has_key('--help') or
not dict(options).has_key('--domain') or
not dict(options)['--domain'].strip()):
usage()
sys.exit(1)
# specify the domain
query = session.query(Domain)
domain = query.get_by(name = dict(options)['--domain'].strip())
if not domain:
print "Invalid Domain"
print "valid domains are:\n%s" % ("\n".join(query.get()))
sys.exit(1)
print domain.popaccounts