package HoTTProxy::UI;
use base qw(HTTP::Server::Simple::CGI);
use CGI qw / :standard :cgi-lib /;
use Digest::MD5 qw / md5_hex /;
use Date::Calc qw / Decode_Date_US /;
use strict;
# Provide a new method to set the basepath (HoTTProxy base directory)
sub basepath {
my $self = shift;
$self->{'basepath'} = shift if (@_);
return ( $self->{'basepath'} );
}
# Provide a new method to set the basepath (HoTTProxy base directory)
sub wwwpath {
my $self = shift;
$self->{'wwwpath'} = shift if (@_);
return ( $self->{'wwwpath'} );
}
# Overload the default HTTP::Server::Simple::CGI handler
sub handler {
my $self = shift;
# our @tool = ('Main Menu','Create User','Manage Users','Configuration','View Log');
# our @toolURL = ('/','/createuser','/manageusers','/config','/viewlog');
if ($ENV{'REMOTE_ADDR'} ne '127.0.0.1') {
print STDERR "!!!Warning!!! Refused attempted connection from $ENV{'REMOTE_ADDR'}.\n\n";
_Forbidden403();
} elsif ($ENV{'PATH_INFO'} eq '/') {
_Ok200();
_mainMenu();
} elsif (-e $self->{'wwwpath'} . $ENV{'PATH_INFO'}) {
_sendFile($self->{'wwwpath'} . $ENV{'PATH_INFO'});
} elsif ($ENV{'PATH_INFO'} eq '/createuser') {
_Ok200();
_editUser($self);
} elsif ($ENV{'PATH_INFO'} eq '/edituser') {
_Ok200();
_editUser($self,param('user'),param('t'));
} elsif ($ENV{'PATH_INFO'} eq '/deluser') {
_Ok200();
_deleteUser($self,param('u'),param('t'));
} elsif ($ENV{'PATH_INFO'} eq '/manageusers') {
_Ok200();
_manageUsers($self);
} elsif ($ENV{'PATH_INFO'} eq '/viewcookies') {
_Ok200();
_viewCookies($self,param('u'));
} elsif ($ENV{'PATH_INFO'} eq '/viewlog') {
_Ok200();
_viewLog($self);
} elsif ($ENV{'PATH_INFO'} eq '/config') {
_Ok200();
_editConfig($self);
} elsif ($ENV{'PATH_INFO'} =~ m/^\/debug/) {
print "HTTP/1.1 200 OK\n";
print "Content-type: text/html\n\n";
print "<p>Basepath: " . $self->{'basepath'} . "<br>\n";
print "WWWpath: " . $self->{'wwwpath'} . "</p>\n";
foreach my $i (sort(keys(%ENV))) {
print "$i -> $ENV{$i}<br>\n";
}
} else {
_NotFound404();
}
}
# Overload the default HTTP::Server::Simple::CGI print_banner
sub print_banner {
my $self = shift;
$| = 1;
print( "\n" . _sortableDate() . " HoTTProxy Admin HTTP Daemon Starting...");
sleep 1; # Give everything a chance to settle
print ( "\n\nYou may connect to the HoTTProxy Admin at http://localhost:" . $self->port . "/\n\n" );
}
sub _mainMenu {
print "<html>
<head>
<title>HoTTProxy - Administration</title>
<link rel=\"StyleSheet\" href=\"HoTTProxy.css\" type=\"text/css\" />
</head>
<body>
<center>
<table border=\"0\" width=\"600\" cellspacing=1 cellpadding=0>
<tr>
<td>
<center>
<p><img src=\"/BannerLogo.gif\"></p>
<h1>Administration Console</h1>
<h2>Main Menu</h2>
<table border=\"0\" cellspacing=1 cellpadding=10>
=1= |