#!/usr/bin/perl #---------------------------------------------------------------- # # Script Name: index.cgi # # Author : michael budash, mbudash@sonic.net # # Date : 06/28/2001 # # Purpose : modify admin.he.net via screen-scrape to shield # user from the fact that it's hurricane at all, # as well as to limit what they can do. # #---------------------------------------------------------------- use strict; use CGI qw/:standard/; use LWP::UserAgent; $|++; print header(); # the hurricane support host my $adminhost = 'admin.he.net'; # build any header and footer html my $header = makeheader(); my $footer = makefooter(); # we *always* need to send this fake cookie to hurricane my $h = new HTTP::Headers Cookie => 'cookie=1'; # create the request object my $req = new HTTP::Request ('POST', 'http://' . $adminhost . '/index.cgi', $h); $req->content_type('application/x-www-form-urlencoded'); # build the socket's post content from *all* params passed to this script my $qs; foreach (param()) { $qs .= "$_=" . CGI::escape(param($_)) . '&'; } chop $qs; $req->content($qs); # create the user agent object my $ua = new LWP::UserAgent; # perform the request my $res = $ua->request($req); if (!($res->is_success)) { print "Sorry - could not connect!"; exit; } # capture the returned content my $content = $res->content; # debug - show the post content passed to hurricane #$content =~ s/
\n/; # remove any link or form action references to hurricane $content =~ s{https?://$adminhost/?}{}sg; # slice and dice the main page; if (param('menu') eq 'main' || !param('menu') || (param('form_result') eq 'true' && param('menu') eq 'add_mbox')) { # remove any straggler 'MAILBOX: xxxx' and clear the param that made it happen $content =~ s/MAILBOX:\s+\w+//s; param('mbox', ''); # remove top table and replace with just account's domain name and link $content =~ s{
(\S+@\S+)\s+.+?\(default mailbox\)/s;
$default_mailbox = $1;
$content =~ s/(menu=configure_default_mbox&)/$1default_mailbox=$default_mailbox&/s;
}
# slice and dice the 'configure_default_mbox' page
if (param('menu') eq 'configure_default_mbox') {
# connect to server, see if ~/.forward exists
use Net::Telnet ();
$default_mailbox = param('default_mailbox');
my $server = substr($default_mailbox, 0, 4);
chop($server) if ($server =~ /0$/);
my $t = new Net::Telnet (Timeout => 10,
Prompt => '/' . $server . ':~\$ $/');
$t->errmode("return");
my ($telnet_error, $exists);
if (!defined($t->open("$server.he.net"))) {
$telnet_error = "Net::Telnet error: " . $t->errmsg;
}
elsif (!defined($t->login(param('account'), param('auth')))) {
$telnet_error = "Net::Telnet error: " . $t->errmsg;
}
else {
$exists = (($t->cmd("ls .forward"))[0] =~ /No such/) ? 0 : 1;
}
# first time thru. set checkbox: 'checked' if ~/.forward already exists,
# else unchecked; also add hidden form field containing default_mailbox param.
if (param('form_result') ne 'true') {
my $checked = $exists ? ' checked' : '';
$content =~ s/(type="checkbox").+?>/$1$checked>/s;
$content =~ s/<\/form>/\n/si;
if ($telnet_error) {
$content =~ s{will take effect.+?\n}{$&
$telnet_error }s;
}
}
# submit hit. if checked, create ~/.forward (if doesn't already exist); else delete it (if exists)
else {
if (param('form_wildcard')) {
if (!$exists) {
$t->cmd("echo \"" . param('default_mailbox') . "\" > .forward");
}
}
elsif ($exists) {
$t->cmd("rm .forward");
}
}
}
# add certain of the params to all links
$content =~ s/index\.cgi\?.+?"/addparams($&)/ge;
$content =~ s/index\.cgi/$ENV{SCRIPT_NAME}/sg;
# remove hurricane copyright
$content =~ s{Copyright © 1994 - 2001 Hurricane Electric. All Rights Reserved.
}{};
# add any header and footer
$content =~ s{}{$&\n$header}is;
$content =~ s{