#!/usr/bin/perl -w # # IMAP4 authenticator for Squid # Copyright (C) 2008 Quixotech Systems, LLC # # This program is based on the following program: # POP3 authenticator for Squid # Copyright (C) 2006 Henrik Nordstrom # # 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, USA. # # Change log: # 2008-02-11 Robert M. Kettles Initial revision # use strict; use vars qw/ $server $imap /; use Mail::IMAPClient; $|=1; if ( @ARGV != 1 ) { print STDERR "Usage: $0 IMAP4 server\n"; exit 1 } $server = shift @ARGV; while() { my ($username, $password) = split(/\s+/); $username =~ s/%([0-9a-f][0-9a-f])/pack("H2",$1)/gie; $password =~ s/%([0-9a-f][0-9a-f])/pack("H2",$1)/gie; $imap = Mail::IMAPClient->new(Server => $server); if (!$imap) { print "ERR IMAP Server not responding for authentication.\n"; next; } $imap->connect( User => $username, Password => $password, Authmechanism => "LOGIN"); if ( $imap->IsAuthenticated()) { print "OK User $username authenticated.\n"; $imap->logout; undef $imap; next; } else { print "ERR Username or password incorrect.\n"; undef $imap; next; } }