#!/usr/bin/perl

use strict;

my $_WGET = "/usr/local/bin/wget --no-check-certificate -q -O -";
my $BASE = "https://rt.host.net/Ticket";
my $USERNAME = "staticuser";
my $PASSWORD = "staticpass";

my $ticketID = $ARGV[0];


my $QUERY = "${BASE}/Display.html?id=${ticketID}". #->
        "&user=${USERNAME}&pass=${PASSWORD}";
open (INFILE, "${_WGET} '${QUERY}' |") || die "Unable to open '${_WGET}' $!";
while (my $line = <INFILE>) {
        if ($line =~ /<TITLE>[^<]*<\/TITLE>/) { # Title Of Page
                print "${line}<base href=\"${BASE}\">\n";
                next;
        } elsif ($line =~ /<b>Ticket metadata<\/b>/) {
                print "<a href=\"https://rt.host.net/Ticket". #->
                        "/Display.html?id=${ticketID}\">". #->
                        "This is a cached copy of this page.  ". #->
                        "Click here to view live ticket</a><br>\n${line}";
                next;
        }
        print $line;
}
close (INFILE);
