| 1 | ############################################################################## | ||
| 2 | # The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. # | ||
| 3 | # # | ||
| 4 | # This program is free software; you can redistribute it and/or # | ||
| 5 | # modify it under the terms of the GNU General Public License # | ||
| 6 | # as published by the Free Software Foundation; either version 2 # | ||
| 7 | # of the License, or (at your option) any later version. # | ||
| 8 | # # | ||
| 9 | # This program is distributed in the hope that it will be useful, # | ||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
| 12 | # GNU General Public License for more details. # | ||
| 13 | # # | ||
| 14 | # You should have received a copy of the GNU General Public License # | ||
| 15 | # along with this program; if not, write to the Free Software # | ||
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.# | ||
| 17 | # # | ||
| 18 | # Jon Howell can be contacted at: # | ||
| 19 | # 6211 Sudikoff Lab, Dartmouth College # | ||
| 20 | # Hanover, NH 03755-3510 # | ||
| 21 | # jonh@cs.dartmouth.edu # | ||
| 22 | # # | ||
| 23 | # An electronic copy of the GPL is available at: # | ||
| 24 | # http://www.gnu.org/copyleft/gpl.html # | ||
| 25 | # # | ||
| 26 | ############################################################################## | ||
| 27 | |||
| 28 | use strict; | ||
| 29 | |||
| 30 | package FAQ::OMatic::submitGroup; | ||
| 31 | |||
| 32 | use CGI; | ||
| 33 | use FAQ::OMatic; | ||
| 34 | use FAQ::OMatic::Auth; | ||
| 35 | use FAQ::OMatic::Groups; | ||
| 36 | use FAQ::OMatic::Versions; | ||
| 37 | |||
| 38 | sub main { | ||
| 39 | my $cgi = FAQ::OMatic::dispatch::cgi(); | ||
| 40 | my $params = FAQ::OMatic::getParams($cgi); | ||
| 41 | |||
| 42 | FAQ::OMatic::mirrorsCantEdit($cgi, $params); | ||
| 43 | |||
| 44 | my $action = $params->{'_action'}; | ||
| 45 | my $group = $params->{'group'}; | ||
| 46 | my $member = $params->{'_member'}; | ||
| 47 | |||
| 48 | FAQ::OMatic::Auth::ensurePerm( | ||
| 49 | '-operation'=>'PermEditGroups', | ||
| 50 | '-restart'=>FAQ::OMatic::commandName(), | ||
| 51 | '-cgi'=>$cgi, | ||
| 52 | '-extraTime'=>1, | ||
| 53 | '-failexit'=>1); | ||
| 54 | |||
| 55 | if ($action eq 'add') { | ||
| 56 | FAQ::OMatic::Groups::validGroupName($group); | ||
| 57 | |||
| 58 | # Things that aren't email addresses (no '@') are taken | ||
| 59 | # to be domains to match. | ||
| 60 | #if (not FAQ::OMatic::validEmail($member)) { | ||
| 61 | # FAQ::OMatic::gripe('error', "'$member' doesn't appear to " | ||
| 62 | # ."be a valid email address."); | ||
| 63 | #} | ||
| 64 | |||
| 65 | # THANKS: To "Mark D. Nagel" <nagel@intelenet.net> for catching | ||
| 66 | # this bad case. | ||
| 67 | if (($member eq '') or ($member=~m/\s/)) { | ||
| 68 | FAQ::OMatic::gripe('error', | ||
| 69 | "Member field ('$member') is empty or contains whitespace."); | ||
| 70 | } | ||
| 71 | |||
| 72 | FAQ::OMatic::Groups::addMember($group, $member); | ||
| 73 | |||
| 74 | FAQ::OMatic::Versions::setVersion('CustomGroups', '1'); | ||
| 75 | } elsif ($action eq 'remove') { | ||
| 76 | FAQ::OMatic::Groups::validGroupName($group); | ||
| 77 | |||
| 78 | FAQ::OMatic::Groups::removeMember($group, $member); | ||
| 79 | } else { | ||
| 80 | FAQ::OMatic::gripe('error', "Invalid action '$action'."); | ||
| 81 | } | ||
| 82 | |||
| 83 | my $url = FAQ::OMatic::makeAref('editGroups', {}, 'url'); | ||
| 84 | FAQ::OMatic::redirect($cgi, $url); | ||
| 85 | } | ||
| 86 | |||
| 87 | 1; |