2005-09-28 18:13:38 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2005-09-28 19:57:51 +02:00
|
|
|
import psycopg, getopt, sys
|
2005-09-28 18:13:38 +02:00
|
|
|
|
2005-09-28 19:57:51 +02:00
|
|
|
from gvadm import PasswordTools, DomainTools
|
2005-09-28 18:13:38 +02:00
|
|
|
|
|
|
|
def usage():
|
2005-09-28 19:57:51 +02:00
|
|
|
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]}
|
2005-09-28 18:13:38 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2005-09-28 19:57:51 +02:00
|
|
|
try:
|
|
|
|
options = getopt.getopt(sys.argv[1:], "h", ['help', 'password=', 'domain='])
|
|
|
|
except getopt.GetoptError:
|
|
|
|
usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if (not options[0] or
|
|
|
|
dict(options[0]).has_key('-h') or
|
|
|
|
dict(options[0]).has_key('--help') or
|
|
|
|
not dict(options[0]).has_key('--domain') or
|
|
|
|
not dict(options[0])['--domain'].strip()):
|
|
|
|
usage()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# specify the domain
|
|
|
|
domain = dict(options[0])['--domain']
|
|
|
|
try:
|
|
|
|
DomainTools.validate_domain(domain)
|
|
|
|
except DomainTools.InvalidDomain, iv:
|
|
|
|
print iv
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# specify the password
|
|
|
|
password = None
|
|
|
|
|
|
|
|
if dict(options[0]).has_key('--password'):
|
|
|
|
password = PasswordTools.check_password(dict(options[0])['--password'])
|
|
|
|
if (password == None):
|
|
|
|
password = PasswordTools.generate_password()
|
|
|
|
|
|
|
|
print domain
|
|
|
|
print password
|
|
|
|
|
|
|
|
print PasswordTools.md5_crypt_password(password)
|