Re: Annoucement: Local Browser Execution

Gisle.Aas@nr.no
Date: Wed, 15 Dec 93 17:41:08 +0100
From: Gisle.Aas@nr.no
Message-id: <9312151641.AA11330@nora.nr.no>
To: Axel Belinfante <Axel.Belinfante@cs.utwente.nl>
Cc: www-talk@nxoc01.cern.ch
Subject: Re: Annoucement: Local Browser Execution
In-reply-to: <9312151414.AA18443@utis179.cs.utwente.nl>
References: <9312151304.AA13944@dxmint.cern.ch> <9312151414.AA18443@utis179.cs.utwente.nl>
Reply-To: Gisle.Aas@nr.no
Axel.Belinfante@cs.utwente.nl writes:
> It should catch the standard output of the commands in a (tmp)file, and
> be ready to give this file to Mosaic via the remote control feature.
> This is where the information about the document BASE will be needed:
> the stdout of the command is supposed to be HTML, which might contain
> relative links. I think that the Mosaic feature recently added to
> handle mailed documents will solve/handle this.
> 
> One remaing problem: how/when do we remove the tmp-file that contains
> the standard output?
> 
> What do people think? Could this be made to work? I'll try anyway.. :-)

I have tried it and it works:

----------------------------------------------cut here----------
#!/local/bin/perl

$allowed = "(imaker|cal|ls)$";  # only programs that match this regex are allowed to run

$file = shift || &usage;
open(F, "$file") || die;
$cmd = <F>;
chop($cmd);
#print "<$cmd>\n"; exit;
@ARGV = split(/ /, $cmd);

if ($ARGV[0] =~ /^-/) {
   $how = shift;
   grep($_ eq $how, "-html", "-text", "-xterm", "-null") || &usage;
};
$how = "-html" unless defined $how;
die "Not allowed to run this program \"$ARGV[0]\""
    unless $ARGV[0] =~ /$allowed/;


if ($how eq "-text" || $how eq "-html")
{
   open(PIDFILE, "$ENV{'HOME'}/.mosaicpid") || die "No mosaic is running";
   $pid = <PIDFILE>;
   close(PIDFILE);

   $tmpfile = "/tmp/out-$$";
   $tmpfile .= ".txt"  if $how eq "-text";
   $tmpfile .= ".html" if $how eq "-html";
   open(STDOUT, ">$tmpfile");
}
if ($how eq "-null")
{
   open(STDOUT, ">/dev/null");
   open(STDERR, ">/dev/null");
}
if ($how eq "-xterm")
{
   @xterm = ("xterm", "-e");
}

open(STDIN, "/dev/null");

system @xterm,@ARGV;

if ($how eq "-text" || $how eq "-html")
{
   open(CONTROL,"> /tmp/Mosaic.$pid");
   
   print CONTROL "goto\n";
   print CONTROL "file://localhost$tmpfile\n";

   close(CONTROL);

   kill "USR1",$pid;
   system "(sleep 5; rm -f $tmpfile)&"
}



sub usage
{
   die "Usage: mosaic-run [-text|-html|-xterm|-null] command args...\n";
}