home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / mail / listserv / utils / new-list.pl.Z / new-list.pl
Encoding:
Perl Script  |  1994-06-15  |  5.6 KB  |  169 lines

  1. #!/usr/local/bin/perl
  2.  
  3. #$Author: sf@ced.berkeley.edu $
  4. #$Date: 94/06/10 13:17:23 $
  5. #$Log:    create_list,v $
  6. # Revision 1.1  94/06/13  10:15:13  sf
  7. # Initial revision
  8. # To create a mailing list.
  9. #
  10. # Files changed after running this program:
  11. #   ~server/config
  12. #   ~server/owners
  13. #   /ced/custom/aliases/mailhost/aliases.request, server must have w permission
  14. #
  15. # Usage:
  16. # create_list [-t mro>] [-f filename] <list-name> <owner's email> <passwd> <comment>
  17. #
  18. # Example:
  19. # ./create_list test-list sf@ced.berkeley.edu secret "TEST LIST"
  20. #
  21. # -t mro: The type of the list. Optional. 
  22. #        m: morderated -- Article approval needed,
  23. #               r: restrictive -- Sub/unsubscription approval needed,
  24. #               o: open -- all people can send messages(but only members can
  25. #                            get the messages)
  26. #              The default is unmoderated, "public" and "closed" list. 
  27. #                         
  28. # -f filename:  The name of a file containing initial subscription. Optional.
  29. #
  30. #               Format of members file:
  31. #               Emailname Fullname 
  32. #
  33. #               Example:  sf@ced.berkeley.edu  Susan Feng 
  34. #                     carrier@ced.berkeley.edu Stephen Carrier 
  35. #                 
  36. # list-name:     Name of the list. e.g admin-help
  37. # owner's email: owner's email address. e.g. sf@ced.berkeley.edu
  38. # passwd:        Passwd for list owner to manage the list. 
  39. # Comment:       A short description for the list, should be quoted.
  40. #
  41.  
  42. #
  43. # THINGS YOU MAY NEED TO CHANGE !!!
  44. #
  45. $server_home='/usr/server';
  46. $archive='/usr/server/archives/mailing-lists';
  47. $aliases='/ced/custom/aliases/mailhost/aliases.request';
  48. $config_tmp="config.$$";
  49. $subscribe_tmp="subscribe.$$";
  50. $domain="ced.berkeley.edu";
  51. $listserv="listserv@$domain";
  52.  
  53. die "Usage: $0 [-t mro] [-f filename] <list-name> <owner's email> <passwd> <comment> \n" unless ($#ARGV >= 3);
  54.  
  55. #
  56. # check sanity
  57. #
  58. chdir ($server_home) || die "Cant' go to server's home. $!\n";
  59. open(ALIASES,">> $aliases") || die "Can't open $aliases. $!\n";
  60. open(CONFIG,">> config") || die "Can't open config file. $!\n";
  61. open(OWNER,">>owners") || die "Can't open owners file. $!\n";
  62.  
  63. #
  64. # Check options
  65. #
  66. while ( $ARGV[0] =~ /^-/ ) {
  67.     $_ = shift;
  68.     if ( /^-t$/ ) { 
  69.     $type=shift; 
  70.         die "Wrong type: $type.\nUsage: $0 [-t mro] [-f filename] <list-name> <owner's email> <passwd> <comment> \n" unless ( $type =~ /r|m|o/ );
  71.     } else { 
  72.        if ( /^-f$/ ) {
  73.            $filename=shift;
  74.            die "No such a file or file is empty: $filename.\n" unless ( -s $filename );
  75.        } else {
  76.            die "I don't recognize this option: $_\n"; 
  77.        }
  78.     }
  79. }
  80.  
  81. ($list_name=shift) =~y/A-Z/a-z/; #list name in lowercase
  82. ($LIST_NAME=$list_name) =~ y/a-z/A-Z/; #list name in upercase
  83.  
  84. $list_owner=shift;
  85. die "Wrong email format for owner.\nUsage: $0 [<-t mro<days>] <list-name> <owner's email> <passwd> <comment> \n" unless ( $list_owner =~ /@/ );
  86.  
  87. $passwd=shift;
  88. $comment=shift;
  89.  
  90.  
  91. die "$LIST_NAME already exists.\n" unless ! -d "lists/" . $LIST_NAME;
  92.  
  93. if ( $type =~ /o/ ) { 
  94.     # Open list, anybody can send message to the list, use -s option for list
  95.     print CONFIG "list $list_name $list_name@$domain $list_owner $passwd -s -e -m 25 -P\n";
  96. } else {
  97.     # Closed list. only members can send messages to the list.
  98.     print CONFIG "list $list_name $list_name@$domain $list_owner $passwd  -e -m 25 -P\n";
  99. }
  100.  
  101. print CONFIG "archive $list_name $archive/$list_name %y-%m listserver/$list_name -\n";
  102. print CONFIG "default $list_name {\n mail = ack\n } \n";
  103. print CONFIG "comment $list_name # $comment\n";
  104. close CONFIG;
  105. print OWNER "$list_owner $list_name CCALL\n";
  106.  
  107. if ( $type =~ /r/ ) {
  108.  # restrictive list, use -a option for listserv
  109.   open(CONFIG,"config");
  110.   open(CONFIG_TMP,">>$config_tmp");
  111.   while (<CONFIG>) {
  112.    s/^server(\s+\S*)(.*$)/server\1 -a $LIST_NAME \2/;
  113.    print CONFIG_TMP $_;
  114.   } 
  115.   system("cp config config.bak");
  116.   rename ("$config_tmp","config") || die "Could not rename $config_tmp to config. $!\n";
  117. }
  118.  
  119. #
  120. # change aliase file
  121. #
  122. if ( $type =~ /m/ ) {
  123.     # moderated list
  124.     print ALIASES "$list_name: \"|/usr/server/catmail -L $LIST_NAME -m -f\"\n"; 
  125. } else {
  126.     print ALIASES "$list_name: \"|/usr/server/catmail -L $LIST_NAME  -f\"\n"; 
  127. };
  128.  
  129. #
  130. # Generate a mail message to list owner who will subscribe initial users
  131. #
  132. #     if the members file is not empty
  133. #       then
  134. #            send a message to list-owner to tell him how to subscribe
  135. #            these members
  136. #       else
  137. #            Just send a message to notify him list has been created.
  138. #            Also send a help file to him.
  139. #       fi
  140. #
  141. #
  142. if ( $filename ne "" ) {
  143.     open(MEMBERS, $filename) || die "Can' open subscribers. $!\n";
  144.     open(SUB,">$subscribe_tmp") || die "Can' create subscribers. $!\n";
  145.     print SUB "Please send the following message to $listserv\n to make initial subscription for members of the list.\n";
  146.     print SUB "---------Cut From Here-------------\n";
  147.     while (<MEMBERS>) {
  148.        ($email, $fn1, $fn2, $fn3) = split;
  149.         if ( $email =~ /@/ ) { 
  150.            $fullname= $fn1 . " " . $fn2 . " " . $fn3;
  151.            print SUB "system $list_name $passwd $email #sub $list_name $fullname\n";
  152.         } else {
  153.            print "Wrong email name $email. \n\n";
  154.         } 
  155.     }
  156.     close SUB;
  157.     if ( -s "$subscribe_tmp" ) {
  158.       system("/usr/ucb/Mail -s 'New list has been created.'  $list_owner < $subscribe_tmp");
  159.       unlink $subscribe_tmp;
  160.     }
  161. }
  162. system("/usr/ucb/Mail -s 'New list $list_name has been created.'  $list_owner < help/general");
  163.  
  164. print "New list \"$list_name\" has been created.\n";
  165. print "Please as root, run whatever needed to update sendmail aliases file and restart sendmail.\n";
  166. print "Please as server, run /usr/server/start to restart serverd.\n";
  167.