1#! @PYTHON@ 2# 3# Copyright (C) 2004-2018 by the Free Software Foundation, Inc. 4# 5# This program is free software; you can redistribute it and/or 6# modify it under the terms of the GNU General Public License 7# as published by the Free Software Foundation; either version 2 8# of the License, or (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; if not, write to the Free Software 17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 19# Inspired by Florian Weimer. 20 21"""Reset the passwords for members of a mailing list. 22 23This script resets all the passwords of a mailing list's members. It can also 24be used to reset the lists of all members of all mailing lists, but it is your 25responsibility to let the users know that their passwords have been changed. 26 27This script is intended to be run as a bin/withlist script, i.e. 28 29% bin/withlist -l -r reset_pw listname [options] 30 31Options: 32 -v / --verbose 33 Print what the script is doing. 34""" 35 36import sys 37import getopt 38 39import paths 40from Mailman import Utils 41from Mailman.i18n import C_ 42 43 44try: 45 True, False 46except NameError: 47 True = 1 48 False = 0 49 50 51 52def usage(code, msg=''): 53 if code: 54 fd = sys.stderr 55 else: 56 fd = sys.stdout 57 print >> fd, C_(__doc__.replace('%', '%%')) 58 if msg: 59 print >> fd, msg 60 sys.exit(code) 61 62 63 64def reset_pw(mlist, *args): 65 try: 66 opts, args = getopt.getopt(args, 'v', ['verbose']) 67 except getopt.error, msg: 68 usage(1, msg) 69 70 verbose = False 71 for opt, args in opts: 72 if opt in ('-v', '--verbose'): 73 verbose = True 74 75 listname = mlist.internal_name() 76 if verbose: 77 print C_('Changing passwords for list: %(listname)s') 78 79 for member in mlist.getMembers(): 80 randompw = Utils.MakeRandomPassword() 81 mlist.setMemberPassword(member, randompw) 82 if verbose: 83 print C_('New password for member %(member)40s: %(randompw)s') 84 85 mlist.Save() 86 87 88 89if __name__ == '__main__': 90 usage(0) 91