
# get_dialup.pl 
# By Chris Candreva   <chris@westnet.com> V1.0 11/5/1997
# require 'get_dialup.pl' early in your code. 
# This is intended as a sample ONLY. The regular expressions MUST be
# modified for your local naming convention.
# PLEASE do not ask me for help with this code. I am providing it for free 
# as an exmaple, but can not support it.
#
# On exit:
# $login will have the username
# $fname will have the first name of the user

    #Get username given IP number

	# Path info -- modify for your local system.
	$finger = '/usr/ucb/finger';
	$pmwho = '/usr/local/bin/pmwho';

	$host = $ENV{'REMOTE_HOST'};
	$ip = $ENV{'REMOTE_ADDR'};
	$ipl = length($ip);
	
	# If hostname ends with .dialup.westnet.com, the userid is the first
	# is the first part of the host name. For static IP customers
	if ( $host =~ /dialup\.westnet\.com$/)
	{
		($login,$tmp)=split(/\./,$host,2);
	}
		
	# Query the correct Annex 3 terminal server 
	elsif ( $host =~ /^port\d{1,2}\.ts\d\.westnet\.com/) {
		($port,$ts)=split(/\./,$host,2);
		open (IN_DIALUP,"$finger \@$ts |");
		while (<IN_DIALUP>) {
			if (/$ip\s*$/) {
				$login = substr($_,10,8);
				$login =~ s/[ \t]//g;
				last;
			}
		}
		close IN_DIALUP;
	}

	# Query PortMaster using pmwho command. This code is unreliable.
	# Should also check for IP addresses in results of pmwho, not just
	# host names.
	# Once again, the regex will have to be modified for your machines.
	elsif ( $host =~ /^isdn\d{1,2}\.pm\d\.westnet\.com/ ) {
		$tmp = substr($host, 0, 16);
		$ts = substr($host,7);

		open (IN_DIALUP,"$pmwho $ts|");
		while(<IN_DIALUP>) {
			if ( (substr($_, 21, 16) eq $tmp) ||
					(substr($_, 21, $ipl) eq $ip)) {
				$login = substr($_, 5, 15);
				$login =~ s/[ \t]//g;
				last;
			}
		}							
	}

	# You can hard code machines here, for example, machines on your
	# local network. This should be customized.
	else {
#		if ($host eq 'vtoc.westnet.com') {$login = 'chris';}
#		elsif ($host eq 'valentine.westnet.com' ) {$login = 'lillian';}
	}

	@info = getpwnam($login);
	$i = index($info[6],' ');
	$fname = substr($info[6],0,$i);

1;
