#!/usr/bin/perl5
#
# +---------------------------------------------------------------------+
# | dbm_list                                                            |
# | Written By   : Trans-Euro I.T Ltd                                   |
# | Written On   : May 3rd 1998                                         |
# |                                                                     |
# | Purpose        List the authorised telnet database                  |
# +---------------------------------------------------------------------+

$PROGRAM="dbm_list";
$VERSION="1.00";

$config  ="/usr/local/phalanx/phalanx.conf";
$dbmdir  ="/usr/local/phalanx/database/";
$contact ="";
$report  ="";
$database="";
$sendmail="";

read_config();
list_dbm();

exit 0;

# +---------------------------------------------------------------------+

sub read_config {
    my $line;

    open(CONFIG,"$config") || die "Cannot open configuration $config!\n";
     while($line=<CONFIG>) {
       $line=~s/\012//g;
       $line=~s/\ {1,}//g;
         SWITCH: {
          if ($line =~ /^CONTACT=/){(undef,$contact)=split(/=/,$line)};
          if ($line =~ /^REPORTFILE=/){(undef,$report)=split(/=/,$line)};
          if ($line =~ /^DATABASE=/){(undef,$database)=split(/=/,$line)};
          if ($line =~ /^SENDMAIL=/){(undef,$sendmail)=split(/=/,$line)};}}
    close(CONFIG);    
}

# +---------------------------------------------------------------------+

sub list_dbm {
    my $dbmfile="$dbmdir$database";

    dbmopen(%DATABASE,"$dbmfile",undef) || die "Cannot read $dbmfile\n";
       
       while (($key,$value)=each(%DATABASE)) {
               $key   =~ s/[\000-\038\177-\377]//g;
               $value =~ s/[\000-\038\177-\377]//g;
       print "User $key is authorised from :- $value\n";
                                          }
    dbmclose(%DATABASE);          
}
