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

$PROGRAM="dbm_drop";
$VERSION="1.00";

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

$user    =$ARGV[0];

if ( "ZXSYS$user" eq "ZXSYS") {
     print "usage $PROGRAM <username_to drop>\n";
     exit 1;} 

read_config();
update_dbm($user,$domain);
mail_support();

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 update_dbm {
    my ($user) =@_;
    shift;
    my ($domain)=@_;
       $domain =~ s/\012//g;
    my $dbmfile="$dbmdir$database";
    my $db_rec="";
    my $dbe   =";";

    print "Drop User\t\t\t$user\n";
    
    dbmopen(%DB,"$dbmfile",0600)||die "Cannot open $dbmfile\n";
            $db_rec=$DB{"$user"};
            $d_before=$db_rec;
            delete $DB{"$user"};
    dbmclose(%DB);

}

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

sub mail_support {

     open (MAIL, "| $sendmail $contact") || die "Can't open $sendmail!\n";
     print MAIL "To: $contact\n";
     print MAIL "From:$PROGRAM\n";
     print MAIL "Subject:$PROGRAM : Telnet Database updated\n";
     print MAIL
"------------------------------------------------------\n\n";
     print MAIL "$user has been dropped from telnet database\n";
     print MAIL "Was authorised from:- $d_before\n";
     close (MAIL);
}                

