#!/usr/athena/bin/perl

$locdb = "/var/local/www/data/bhadb";
require 'parseform.pl';

#print "Content-type: x-application/bha\n\n";
print "Content-type: text/plain\n\n";

&readlocdb;
%data = &parseform($ENV{'QUERY_STRING'});
$cmd = $ENV{'PATH_INFO'};
$cmd = substr($cmd, 1);
&$cmd();
&writelocdb;

sub readlocdb {
    open(DB, $locdb);
    while(<DB>){
	($user, $location) = split;
	$loc{$user} = $location;
    }
    close(DB);
}

sub SETLOC {
    $loc{$data{"user"}} = $ENV{'REMOTE_HOST'}.":".$data{'port'};
}

sub REQLOC {
    print $loc{$data{"user"}};
}

sub CONPONG {
}

sub REMLOC {
    undef $loc{$data{"user"}};
}

sub writelocdb {
    open(DB, ">$locdb");
    foreach $u (keys %loc){
	print DB "$u $loc{$u}\n";
    }
    close(DB);
}
