#!/usr/local/bin/perl 
###################################################################################
#
#   Embperl - Copyright (c) 1997-2004 Gerald Richter / ECOS
#
#   You may distribute under the terms of either the GNU General Public
#   License or the Artistic License, as specified in the Perl README file.
#   For use with Apache httpd and mod_perl, see also Apache copyright.
#
#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
#   $Id: epocgi.pl,v 1.1 2004/11/15 20:29:33 drayner Exp $
#
###################################################################################

our($revision, $revision_suffix);
BEGIN {
  if ($ENV{'PMG_REVISION'}) {
    $revision = $ENV{'PMG_REVISION'};
  }
  elsif (-f '.beta') {
    $revision = 'beta';
  }
  if ($revision) {
    $revision_suffix = '.' . $revision;
  }
  else {
    $revision_suffix = '';
  }

  my $home = $ENV{'PMG_HOMEDIR'};
  if (!defined($home)) {
    $ENV{'PMG_HOMEDIR'} = $home = '/home/pmguser';
  }
  require "$home/pmg/bin$revision_suffix/environment.pl";
  &setPerlLib();
}

use FCGI;
use Embperl;
use Embperl::Object;

$^W = 1 if ($revision_suffix || $isAlphaServer);

my $home = $ENV{'PMG_HOMEDIR'};
my $tmpdir = $home . '/pmg/tmp';
my $config = {
  'use_env' => 1,
  'use_redirect_env' => 1,
  'cookie_name' => 'SID',
  'cookie_path' => '/',
  'appname' => 'savicom',
  'object_app' => '_app.pl',
  #'debug' => 0x0040020,
  #'log' => $home . '/pmg/tmp/embperl.log',
};

my($rc, $time);
my $request = FCGI::Request;
while ($request->Accept() >= 0) {
  $ENV{'TMPDIR'} = $tmpdir;
  $ENV{'EMBPERL_URIMATCH'} = '\.html$';
  $ENV{'EMBPERL_EXPIRES_IN'} = 0;
  $rc = Embperl::Object::Execute($config);
  if ($rc) {
    $time = localtime();
    print <<EOT;
Status: $rc
Content-Type: text/html

<HTML><HEAD><TITLE>Embperl Error</TITLE></HEAD>
<BODY bgcolor=\"#FFFFFF\">
<H1>epocgi Server Error: $rc</H1>
Please contact the server administrator, $ENV{SERVER_ADMIN} and inform them of the time the error occurred, and anything you might have done that may have caused the error.<P><P>
$ENV{SERVER_SOFTWARE} Embperl $Embperl::VERSION [$time]<P>
</BODY></HTML>

EOT
  }
}

