#!/usr/bin/perl
#
# This works with Net-SNMP and UCD-SNMP

$host=shift;
$comm=shift || 'public';
$type=shift || 'cisco';

$conf='/usr/local/dialup_admin/conf/admin.conf';
open CONF, "<$conf"
	or die "Could not open configuration file\n";
while(<CONF>){
	chomp;
	($key,$val)=(split /:\s*/,$_);
	$snmp_type = $val if ($key eq 'general_snmp_type');
	$snmpwalk = $val if ($key eq 'general_snmpwalk_command');
}
close CONF;

die "general_snmp_type directive is not set in admin.conf\n" if ($snmp_type eq '');
die "Could not find snmpwalk binary. Please make sure that the \$snmpwalk variable points to the right location\n" if (! -x $snmpwalk);

$snmpwalkcmd="$snmpwalk $host $comm" if ($snmp_type = 'ucd');
$snmpwalkcmd="$snmpwalk -v 1 -c $comm $host" if ($snmp_type = 'net');

if ($type eq 'cisco'){
	$walk =`$snmpwalkcmd  .iso.org.dod.internet.private.enterprises.9.9.150.1.1.3.1.2`;
	if ($walk =~ /^$/ || $walk =~ /No Such Object/){
		$walk =`$snmpwalkcmd .iso.org.dod.internet.private.enterprises.9.10.19.1.3.1.1.3`;
		if ($walk =~ /^$/ || $walk =~ /No Such Object/){
			$walk =`$snmpwalkcmd .iso.org.dod.internet.private.enterprises.9.2.9.2.1.18`;
		}
	}
}
elsif ($type eq 'lucent'){
	$walk =`$snmpwalkcmd .iso.org.dod.internet.private.enterprises.529.10.4.1.12`;
}
elsif ($type eq 'usrhiper'){
	$walk =`$snmpwalkcmd .iso.org.dod.internet.private.enterprises.429.4.10.1.1.18`;
}

while($walk=~/\"([\@\.\w\-]+?)\"/g){
 $user=lc($1);
 if($out) {
  $out=$out.",'$user'";
 }else{
  $out="'$user'";
 }
}
print "$out\n";
