#!/usr/bin/perl -w

# 2003-10-30 Dobrica Pavlinusic <dpavlin@rot13.org>
#
# fingers server and allows to add users to .htusers file with
# auth_pop3 for user authentification
#
# uses Net::Finger from CPAN
#
# usage:
#
# finger2htusers.pl something@server >> .htusers
#

use strict;
use Net::Finger;


if (! @ARGV) {
	print "usage: $0 something\@server >> .htusers\n";
	exit 1;
}

print "# finger2htuser.pl start of output on ",scalar localtime(time),"\n";

foreach my $addr (@ARGV) {
	my @lines = finger($addr);
	my ($f_what,$f_server) = split(/@/,$addr);
	$f_server="localhost" if (! $f_server);
	foreach (@lines) {
		if (m/Login:\s*(\S+)\s+Name:\s*(.+)\s*$/i) {
			my ($login,$name) = ($1,$2);
			print "$login:$name:auth_pop3:$login\@$f_server\n";
		}
	}
}

exit;
