#!/usr/bin/perl -Tw use warnings; use strict; $|++; # file: index.cgi # Herve Saint-Amand # Universitaet des Saarlandes # Tue May 13 20:09:25 2008 # When we do Moses translation of Web pages there's a little tool frame at the # top of the screen. This script takes care of printing the frameset and that # top frame. It also invokes the main script with the proper URL param. # You're most probably not interested in the code that's in here. Have a look # a translate.cgi instead. That's where the meat is. #------------------------------------------------------------------------------ # includes use CGI; use CGI::Carp qw/fatalsToBrowser/; use URI::Escape; #------------------------------------------------------------------------------ # constants, global vars (my $SELF_URL = $ENV{QUERY_STRING}) =~ s![^/]*$!!; my $TRANSLATE_CGI = 'translate.cgi'; #------------------------------------------------------------------------------ # read CGI params my %params = %{{ # absolute URL of the page to translate. Will be passed on to translate.cgi url => undef, # ID of the frame we're currently printing frame => undef, }}; my $cgi = new CGI; foreach my $p (keys %params) { $params{$p} = $cgi->param ($p) if (defined $cgi->param ($p)); } # check that we have a URL and it's absolute die "No URL?" unless $params{url}; $params{url} = "http://$params{url}" unless ($params{url} =~ m!^[a-z]+://!); # check frame ID param die "Invalid frame ID" if ($params{frame} && $params{frame} ne 'top'); #------------------------------------------------------------------------------ # print out my $URL = uri_escape ($params{url}); print "Content-Type: text/html\n\n"; print "\n" . " \n" . " $params{url} -- Moses translation\n" . " \n" . " \n"; if (!$params{url}) { print " \n" . "

Moses Web Interface

\n" . "
\n" . " \n" . " \n" . "
\n" . " \n"; } elsif (!$params{frame}) { print " \n" . " \n" . " \n" . " \n"; } else { print " \n" . " \n" . " Moses translation of\n" . " $params{url}\n" . " \n" . " \n"; } print "\n"; #------------------------------------------------------------------------------