#!/usr/local/web/bin/perl
### ---------------------------------------------------------------------- ###
#
# Fly tester
#
# *Requires* perl 5.001 or greater and the CGI module.
#
# (c) Copyright 1998, Martin Gleeson
#
#
# You may use and/or modify this script freely, but not redistribute it
# without my permission.
#
# Version 1.1, 11 June 1999
#
# - added mode to show diagnostic output
# - disallowed 'copy' and 'copyresized' due to security risk.
#
# Version 1.0, 25 September 1998
#
use strict;
### ---------------------------------------------------------------------- ###
# User configurable settings
### ---------------------------------------------------------------------- ###
# Where the temporary images will be stored
my $output_area = "/home/usr/its/gleeson/public_html/fly/graphs";
# URL path to same
my $graphs_url = "/%7Egleeson/fly/graphs";
# location of the fly program
my $flyprog = "/home/usr/its/gleeson/bin/fly";
### ---------------------------------------------------------------------- ###
# End of configurable settings - no editing required below this line.
### ---------------------------------------------------------------------- ###
use CGI;
my $q = new CGI;
my ($testcode, $version, $helpscreen, $diags);
&my_setup();
if($q->path_info =~ /quickref/) {
print $q->header(),
$q->start_html(-title=>'Fly Tester: Fly Quick Reference', -bgcolor=>"#FFFFFF"),
$q->h1('Fly Quick Reference'),
$q->hr(),
$q->pre($helpscreen),
$q->hr(),
$q->end_html();
} elsif($q->request_method() eq "GET") {
my $cw = 40;
my $ch = 30;
my $cell = $q->startform("POST",$q->url(),$CGI::URL_ENCODED) .
$q->textarea(-rows=>$ch, -columns=>$cw, -name=>"code", -default=>$testcode) .
$q->br() .
$q->div({-align=>"right"},
"Command window width: ",
$q->textfield(-name=>'cw', -default=>$cw, -size=>2, -maxlength=>3),
" height: ",
$q->textfield(-name=>'ch', -default=>$ch, -size=>3, -maxlength=>4),
$q->br,
"Show diagnostic output? ",
$q->checkbox(-name=>'do',-label=>''),
$q->br,
$q->submit(-name=>'Submit', -value=>'Generate Image'));
print $q->header(),
$q->start_html(-title=>'Fly Tester',
-bgcolor=>"#FFFFFF"),
$q->h1('Fly Test Page'),
$q->hr(),
$q->p("Here you can test ", $q->a({-href=>"http://www.unimelb.edu.au/fly/"},"fly"),
" commands and see the results instantly."),
$q->table({-border=>"0"},$q->Tr($q->td($cell))),
$q->hr(),
$q->p({-align=>"center"}, "This is part of the ",
$q->a({-href=>"http://www.unimelb.edu.au/fly/"},"fly"), " package."),
$q->hr(),
$q->endform(),
$q->end_html();
} elsif($q->request_method() eq "POST") {
my $code = $q->param('code');
$diags = $q->param('do');
my ($cell1, $cell2);
print $q->header(),
$q->start_html(-title=>'Fly Tester',
-bgcolor=>"#FFFFFF"),
$q->h1('Fly Test Page'),
$q->hr();
my $inputfile = "/tmp/fly.$$.input";
my $outputfile = "/tmp/fly.$$.output";
$code =~ s/
//g;
if($code =~ /^copy/m) {
print $q->h2("Error"),
$q->p("The copy and copyresized commands cannot be used from within this program.
"),
$q->hr(),
$q->p({-align=>"center"}, "This is part of the ",
$q->a({-href=>"http://www.unimelb.edu.au/fly/"},"fly"), " package."),
$q->hr(),
$q->end_html();
exit 0;
}
open INPUT, ">$inputfile" or die "Couldn't open $inputfile for writing: $!\n"; print INPUT $code; close INPUT;
my $return_code = system("$flyprog -i $inputfile -o $output_area/fly.$$.gif > $outputfile 2>&1");
if($return_code == 0) {
$cell1 = $q->p({-align=>'center'}, $q->img({-src=>"${graphs_url}/fly.$$.gif",
-alt=>"[Generated Graph]", -border=>"2"}));
my $url = $q->url();
if($diags) {
open OUTPUT, "$outputfile" or die "Couldn't open $outputfile for reading: $!\n";
my @lines =