* 'install.sh'
- Also install docs
* 'VirtualMailManager/Account.py'
* 'VirtualMailManager/Alias.py'
* 'VirtualMailManager/Config.py'
* 'VirtualMailManager/Domain.py'
* 'VirtualMailManager/Exceptions.py'
* 'VirtualMailManager/VirtualMailManager.py'
* 'setup.py'
* 'vmm'
- Included global version number.
* 'VirtualMailManager/constants/VERSION.py'
- Added to repository.
#!/usr/bin/env python# -*- coding: UTF-8 -*-# Copyright 2007-2008 VEB IT# See COPYING for distribution information.# $Id$"""This is the vmm main script."""fromVirtualMailManager.constants.VERSIONimportVERSION__author__='Pascal Volk <p.volk@veb-it.de>'__version__=VERSION__revision__='rev '+'$Rev$'.split()[1]__date__='$Date$'.split()[1]importosimportsysfromgetpassimportgetpassfromVirtualMailManager.VirtualMailManagerimportVirtualMailManagerfromVirtualMailManager.ConfigimportVMMConfigimportVirtualMailManager.ExceptionsasVMMEimportVirtualMailManager.constants.EXITasEXIT__prog__=os.path.basename(sys.argv[0])defusage(excode=0,errMsg=None):sys.stderr.write("""\Usage: %s OPTION OBJECT ARGS* short long option object args (* = optional) da domainadd domain.tld transport* di domaininfo domain.tld detailed* dt domaintransport domain.tld transport dd domaindelete domain.tld delalias*|deluser*|delall* ua useradd user@domain.tld password* ui userinfo user@domain.tld du* un username user@domain.tld 'Users Name' up userpassword user@domain.tld password* u0 userdisable user@domain.tld u1 userenable user@domain.tld ud userdelete user@domain.tld aa aliasadd alias@domain.tld user@domain.tld ai aliasinfo alias@domain.tld ad aliasdelete alias@domain.tld cf configure section* h help v version""")%__prog__ifnoterrMsgisNone:sys.stderr.write('Error: %s\n'%errMsg)sys.exit(excode)defgetVMM():try:vmm=VirtualMailManager()returnvmmexcept(VMME.VMMException,VMME.VMMNotRootException,VMME.VMMPermException,VMME.VMMConfigException),e:sys.stderr.write("\aERROR: %s\n"%e[0][0])sys.exit(e[0][1])defconfigure():try:iflen(sys.argv)<3:vmm.configure()else:vmm.configure(sys.argv[2])except(EOFError,KeyboardInterrupt):sys.stderr.write('\nOuch!\n')sys.exit(EXIT.USER_INTERRUPT)exceptVMME.VMMConfigException,e:sys.stderr.write(str(e))sys.exit(EXIT.CONF_ERROR)sys.exit(0)def_readpass():clear0=''clear1='1'whileclear0!=clear1:whilelen(clear0)<1:clear0=getpass(prompt='Enter new password: ')iflen(clear0)<1:sys.stderr.write('Sorry, empty passwords are not permitted\n')clear1=getpass(prompt='Retype new password: ')ifclear0!=clear1:clear0=''sys.stderr.write('Sorry, passwords do not match\n')returnclear0def_printInfo(info,title):msg=title+' information'print'%s\n%s'%(msg,'-'*len(msg))fork,vininfo.items():print'\t%s: %s'%(k.title().ljust(15,'.'),v)printdef_printUsers(users,title):msg='Available '+titleprint'%s\n%s'%(msg,'-'*len(msg))iflen(users)>0:foruserinusers:print'\t%s'%userelse:print'\tNone'printdef_printAliases(alias,targets):msg='Alias information'print'%s\n%s'%(msg,'-'*len(msg))print'\tMail for %s goes to:'%aliasiflen(targets)>0:fortargetintargets:print'\t -> %s'%targetelse:print'\tNone'printdefdomain_add():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing domain name.')elifargc<4:vmm.domain_add(sys.argv[2].lower())else:vmm.domain_add(sys.argv[2].lower(),sys.argv[3])defdomain_delete():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing domain name.')elifargc<4:vmm.domain_delete(sys.argv[2].lower())else:vmm.domain_delete(sys.argv[2].lower(),sys.argv[3])defdomain_info():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing domain name.')elifargc<4:_printInfo(vmm.domain_info(sys.argv[2].lower()),'Domain')else:infos=vmm.domain_info(sys.argv[2].lower(),sys.argv[3])_printInfo(infos[0],'Domain')_printUsers(infos[1],'accounts')_printUsers(infos[2],'aliases')defdomain_transport():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing domain name and new transport.')ifargc<4:usage(EXIT.MISSING_ARGS,'Missing new transport.')else:vmm.domain_transport(sys.argv[2].lower(),sys.argv[3])defuser_add():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing e-mail address.')elifargc<4:password=_readpass()else:password=sys.argv[3]vmm.user_add(sys.argv[2].lower(),password)defuser_delete():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing e-mail address.')else:vmm.user_delete(sys.argv[2].lower())defuser_info():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing e-mail address.')elifargc<4:_printInfo(vmm.user_info(sys.argv[2].lower()),'Account')else:_printInfo(vmm.user_info(sys.argv[2].lower(),True),'Account')defuser_name():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing e-mail address and users name.')ifargc<4:usage(EXIT.MISSING_ARGS,'Missing users name.')else:vmm.user_name(sys.argv[2].lower(),sys.argv[3])defuser_enable():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing e-mail address.')else:vmm.user_enable(sys.argv[2].lower())defuser_disable():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing e-mail address.')else:vmm.user_disable(sys.argv[2].lower())defuser_password():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing e-mail address.')elifargc<4:password=_readpass()else:password=sys.argv[3]vmm.user_password(sys.argv[2].lower(),password)defalias_add():globalargcifargc<4:usage(EXIT.MISSING_ARGS,'Missing alias address and destination.')else:vmm.alias_add(sys.argv[2].lower(),sys.argv[3])defalias_info():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing alias address')else:_printAliases(sys.argv[2],vmm.alias_info(sys.argv[2].lower()))defalias_delete():globalargcifargc<3:usage(EXIT.MISSING_ARGS,'Missing alias address')else:vmm.alias_delete(sys.argv[2].lower())defshowWarnings():ifvmm.hasWarnings():print'\nWarnings:'forwinvmm.getWarnings():print" * ",w#def main():if__name__=='__main__':argc=len(sys.argv)ifargc<2:usage(EXIT.MISSING_ARGS)# -> exitvmm=getVMM()try:ifsys.argv[1]in['cf','configure']ornotvmm.setupIsDone():configure()exceptVMME.VMMConfigException,e:sys.stderr.write(str(e))sys.exit(EXIT.CONF_ERROR)exceptVMME.VMMException,e:sys.stderr.write("\aERROR: %s\n"%e[0][0])sys.exit(e[0][1])try:ifsys.argv[1]in['da','domainadd']:domain_add()elifsys.argv[1]in['di','domaininfo']:domain_info()elifsys.argv[1]in['dt','domaintransport']:domain_transport()elifsys.argv[1]in['dd','domaindelete']:domain_delete()elifsys.argv[1]in['ua','useradd']:user_add()elifsys.argv[1]in['ui','userinfo']:user_info()elifsys.argv[1]in['un','username']:user_name()elifsys.argv[1]in['up','userpassword']:user_password()elifsys.argv[1]in['u0','userdisable']:user_disable()elifsys.argv[1]in['u1','userenable']:user_enable()elifsys.argv[1]in['ud','userdelete']:user_delete()elifsys.argv[1]in['aa','aliasadd']:alias_add()elifsys.argv[1]in['ai','aliasinfo']:alias_info()elifsys.argv[1]in['ad','aliasdelete']:alias_delete()elifsys.argv[1]in['h','help']:usage()elifsys.argv[1]in['v','version']:print"%s, version %s (%s from %s)\n"%(__prog__,__version__,__revision__,__date__)else:usage(EXIT.UNKNOWN_OPTION,'Unknown option: »%s«'%sys.argv[1])showWarnings()except(EOFError,KeyboardInterrupt):sys.stderr.write('\nOuch!\n')sys.exit(EXIT.USER_INTERRUPT)exceptVMME.VMMException,e:sys.stderr.write("\aERROR: %s\n"%e[0][0])sys.exit(e[0][1])