[Nagiosplug-checkins] CVS: nagiosplug/contrib check_pop3.pl,1.1.1.1,1.2

Karl DeBisschop kdebisschop at users.sourceforge.net
Tue Mar 2 20:37:15 CET 2004


Update of /cvsroot/nagiosplug/nagiosplug/contrib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22366

Modified Files:
	check_pop3.pl 
Log Message:
fix loop and \r\n (Jason Burnett - http://sourceforge.net/tracker/index.php?func=detail&aid=895677&group_id=29880&atid=397599)

Index: check_pop3.pl
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/contrib/check_pop3.pl,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** check_pop3.pl	28 Feb 2002 06:42:53 -0000	1.1.1.1
--- check_pop3.pl	3 Mar 2004 04:24:35 -0000	1.2
***************
*** 1,11 ****
  #!/usr/bin/perl
  # ------------------------------------------------------------------------------
! # File Name:		check_pop3.pl
! # Author:		Richard Mayhew - South Africa
! # Date:			2000/01/21
! # Version:		1.0
! # Description:		This script will check to see if an POP3 is running
! #			and whether authentication can take place.
! # Email:		netsaint at splash.co.za
  # ------------------------------------------------------------------------------
  # Copyright 1999 (c) Richard Mayhew
--- 1,11 ----
  #!/usr/bin/perl
  # ------------------------------------------------------------------------------
! # File Name:    check_pop3.pl
! # Author:    Richard Mayhew - South Africa
! # Date:      2000/01/21
! # Version:    1.0
! # Description:    This script will check to see if an POP3 is running
! #      and whether authentication can take place.
! # Email:    netsaint at splash.co.za
  # ------------------------------------------------------------------------------
  # Copyright 1999 (c) Richard Mayhew
***************
*** 15,27 ****
  # License GPL
  # ------------------------------------------------------------------------------
! # Date		Author		Reason
! # ----		------		------
! # 1999/09/20	RM		Creation
! # 1999/09/20	TP		Changed script to use strict, more secure by
! #				specifying $ENV variables. The bind command is
! #				still insecure through.  Did most of my work
! #				with perl -wT and 'use strict'
! # 2000/01/20	RM		Corrected POP3 Exit State.
! # 2000/01/21	RM		Fix Exit Codes Again!!
  # ------------------------------------------------------------------------------
  
--- 15,32 ----
  # License GPL
  # ------------------------------------------------------------------------------
! # Date    Author    Reason
! # ----    ------    ------
! # 1999/09/20  RM    Creation
! # 1999/09/20  TP    Changed script to use strict, more secure by
! #        specifying $ENV variables. The bind command is
! #        still insecure through.  Did most of my work
! #        with perl -wT and 'use strict'
! # 2000/01/20  RM    Corrected POP3 Exit State.
! # 2000/01/21  RM    Fix Exit Codes Again!!
! # 2003/12/30  CZ    Proper CRLF in communication w/server
! #        Fixed infinite loop
! #        Error checking on welcome banner, USER, PASS commands
! #        Better error condition handling
! 
  # ------------------------------------------------------------------------------
  
***************
*** 39,43 ****
  # ------------------------------------------------------------------[ Global ]--
  my $TIMEOUT = 60;
! 	
  # -------------------------------------------------------------------[ usage ]--
  sub usage
--- 44,48 ----
  # ------------------------------------------------------------------[ Global ]--
  my $TIMEOUT = 60;
! 
  # -------------------------------------------------------------------[ usage ]--
  sub usage
***************
*** 70,75 ****
  	$this = pack($sockaddr, AF_INET, 0, $thisaddr);
  	$that = pack($sockaddr, AF_INET, $in_remoteport, $thataddr);
! 	if (!bind(ClientSocket, $this)) { print "Connection Refused"; exit 2; }
! 	if (!connect(ClientSocket, $that)) { print "Connection Refused"; exit 2; }
  	select(ClientSocket); $| = 1; select(STDOUT);
  	return \*ClientSocket;
--- 75,80 ----
  	$this = pack($sockaddr, AF_INET, 0, $thisaddr);
  	$that = pack($sockaddr, AF_INET, $in_remoteport, $thataddr);
! 	if (!bind(ClientSocket, $this)) { print "Connection Refused\n"; exit 2; }
! 	if (!connect(ClientSocket, $that)) { print "Connection Refused\n"; exit 2; }
  	select(ClientSocket); $| = 1; select(STDOUT);
  	return \*ClientSocket;
***************
*** 98,133 ****
  	
  
! print ClientSocket "user $username\n";
! 
! #Debug Server
! #print "user $username\n";
! 
! #Sleep or 3 secs, incase server is slow.
! sleep 3;
  
! print ClientSocket "pass $password\n";
  
! #Debug Server
! #print "pass $password\n";
  
! while (<ClientSocket>) {
! 
! print ClientSocket "pass $password\n";
! 
! #Debug Server
! #print $_;
! 
! err($_) if (m/\-ERR\s+(.*)\s+.*/);
! message($_) if (m/\+OK Mailbox open,\s+(.*\d)\s+messages.*/);
! }
  }
  
  sub message 
  {
! 	my $answer = "UNKNOWN";
!   	$answer = "Pop3 OK - Total Messages On Server :- $1";	
  	alarm(0);
! 	print ClientSocket "quit\n";
! 	print "$answer";
  	exit 0;
  }
--- 103,139 ----
  	
  
! 	&err("no welcome banner\n") unless $_ = <ClientSocket>;
! 	&err("bad welcome banner: " . $_) unless $_ =~ /^\+OK/;
  
! 	print ClientSocket "USER $username\r\n";
  
! 	&err("no response to USER command\n") unless $_ = <ClientSocket>;
! 	&err("bad response to USER: " . $_) unless $_ =~ /^\+OK/;
  
! 	print ClientSocket "PASS $password\r\n";
! 
! 	&err("no response to PASS command\n") unless $_ = <ClientSocket>;
! 	&err("bad response to PASS: " . $_) unless $_ =~ /^\+OK/;
! 
! 	print ClientSocket "LIST\r\n";
! 
! 	my $bad = 1;
! 	my $msgs = 0;
! 	while (<ClientSocket>) {
! 		&err(($1||' UNKNOWN')."\n") if (m/\-ERR(.*)/);
! 		$bad = 0 if /^\+OK/;
! 		$msgs = $1 if /^(\d+)\s+/;
! 		last if /^\./;
! 	}
! 	&message("$msgs\n") unless $bad;
! 	&err("missing +OK to LIST command\n");
  }
  
  sub message 
  {
! 	my $msg = shift;
  	alarm(0);
! 	print ClientSocket "QUIT\r\n";
! 	print "POP3 OK - Total Messages On Server: $msg";
  	exit 0;
  }
***************
*** 135,144 ****
  sub err
  {
! 	my $answer = "UNKNOWN";
! 	$answer = "Pop3 Error :- $1";
  	alarm(0);
! 	print ClientSocket "quit\n";
! 	print "$answer";
  	exit 2;
  }
- 
--- 141,148 ----
  sub err
  {
! 	my $msg = shift;
  	alarm(0);
! 	print ClientSocket "QUIT\r\n";
! 	print "POP3 Error: $msg";
  	exit 2;
  }





More information about the Commits mailing list