[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: Executing cgi-script from minivend page
> ****** message to minivend-users from adfranse <info@afa.nl>
>
> Hello list,
>
> I would like to execute a cgi-script from a minivend page.
> I've tried several things, but none of them seem to work.
>
...
The short answer is that you can't get there from here. Try to adapt
them to fit in MV. It shouldn't be too difficult. You should try to
get away from CGI/SSI if you can anyway.
However, if you use Apache and can not, or would rather not adapt your
scripts, it is possible to kluge a fix with perl modules (ain't that
always the case!) to allow conventional SSI anywhere in MiniVend
pages. Its not trivial if you aren't already setup for it.
Apache modperl allows chaining content handlers (Its discussed in
detail in chapter 7 in O'Reilly's "Writing Apache Modules" book). The
gist is that if you can direct MV output through an Apache perl module
at all, you can pipe it through one or more modules by tie-ing the
handler to STDOUT (see book).
Here is a quick & dirty skeleton module (skips error checking,
assumes too much about SSI tags, ignores headers, etc) to embed
CGI/SSI output in MV pages (or pages from other sources for that
matter). You could maybe adapt it for a [cgi-sucker] tag kinda thingy:
Configure the server something like this to shanghai catalog requests
to a modperl shim which interfaces with MiniVend and pipes its output
through the cgi-sucker module:
# httpd.conf
#
<Location /cgi-bin/cattest> # catalog hook
SetHandler perl-script
PerlHandler Apache::sucker Apache::MiniVend
</Location>
# Apache::sucker.pm
#
package Apache::sucker;
#... setup junk omitted - see book
@ISA = Apache::Forward ### Apache::Forward is verbatim from the book
#
# we only need to overide PRINT and add a subroutine to slurp up a url
# Apache::sucker is only about 6 lines of real code, but
# it does pull lean on a bunch of its chums
#
BEGIN {
$ua = new LWP::UserAgent;
$ua->agent("EngineCharlie/0.0 ".$ua->agent);
}
sub PRINT {
my $s = shift;
my $l = join ' ',@_;
$l =~ s/<!--\#exec\s+cgi="(.*)"\s*-->/$s->sucker($1)/oige;
$s->forward($l);
}
sub sucker {
my ($s,$chunk) = @_;
#
# $chunk is the uri of the cgi script taken from the SSI tag
# and might look like "/cgi-bin/xyz.cgi"
#
# it could also be a non-local host, have arguments, ... but I assume
# here its a simple localhost request
#
return $ua->request(HTTP::Request->new('GET',"http://localhost/$chunk"))->content;
}
--
John Edstrom | edstrom @ slugo.hmsc.orst.edu