#! /usr/bin/env python # # Copyright (c) 2002 Anand Kumria # # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """Reset the password on an existing list and send an introductory email. Usage: %(PROGRAM)s [options] listname admin-password Options: -h/--help Print this help text and exit. You can specify as many of the arguments as you want on the command line: you will be prompted for the missing ones. Note that listnames are forced to lowercase. """ import sys import os import string import time import getpass import getopt import paths from Mailman import mm_cfg from Mailman import MailList from Mailman import Utils from Mailman import Errors from Mailman import Message from Mailman.Handlers import HandlerAPI from Mailman.Crypt import crypt PROGRAM = sys.argv[0] def getusername(): username = os.environ.get('USER') or os.environ.get('LOGNAME') if not username: import pwd username = pwd.getpwuid(os.getuid())[0] if not username: username = '' return username def usage(code, msg=''): print __doc__ if msg: print msg sys.exit(code) def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'h', ['help']) except getopt.error, msg: usage(1, msg) for opt, arg in opts: if opt in ('-h', '--help'): usage(0) if len(args) > 0: listname = args[0] else: listname = raw_input("Enter the name of the list: ") listname = string.lower(listname) if '@' in listname: usage(1, 'List name must not include "@": ' + listname) if len(args) > 1: list_pw = args[1] else: list_pw = getpass.getpass("Initial %s password: " % listname) # List passwords cannot be empty list_pw = string.strip(list_pw) if not list_pw: usage(1, 'The list password cannot be empty') try: mlist = MailList.MailList(listname, lock=1) except Errors.MMListError, e: print 'No such list "%s"\n%s' % (listname, e) sys.exit(1) try: mlist.password = crypt(list_pw , Utils.GetRandomSeed()) mlist.Save() # send the notice to the list owner(s) text = Utils.maketext( 'newlist.txt', {'listname' : listname, 'password' : list_pw, 'admin_url' : mlist.GetScriptURL('admin', absolute=1), 'listinfo_url': mlist.GetScriptURL('listinfo', absolute=1), 'requestaddr' : "%s-request@%s" % (listname, mlist.host_name), 'hostname' : mlist.host_name, }) for owner_mail in mlist.owner: msg = Message.UserNotification( owner_mail, 'mailman-owner@' + mlist.host_name, 'Your mailing list: ' + listname, text) HandlerAPI.DeliverToUser(mlist, msg) finally: mlist.Unlock() if __name__ == '__main__': main()