gaggio has asked for the wisdom of the Perl Monks concerning the following question:

Hey, as I'm currently moving from a static web site to a 100% dynamic one (like Everything :-), I am facing the following problem:

What is the best way to simulate Exec Server Side Includes. I have a couple of those in my static web pages, but of course, when a page is dynamically generated, the webserver does not parse anything, so my SSIs are not executed anymore.

I have thought about the exec() function, the backticks trick, etc.
What would you do?
Is it less secure than a "real" SSI?
Thanks for your help.

Replies are listed 'Best First'.
Re: Best way to
by davorg (Chancellor) on Jun 27, 2000 at 16:37 UTC

    The way that I always approach this is to create all CGI scripts that need to be called from SSI as modules which export a function which produces the necessary HTML output. I then create a wrapper script which just loads the module, prints a CGI header and calls the function. I can then call this script in an SSI call. When I need to use the same functionality within a dynamically created page I can use the module and call the function.

    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000
    <http://www.yapc.org/Europe/>
RE: Best way to
by lhoward (Vicar) on Jun 27, 2000 at 16:33 UTC
    This question depends on so many things:
    1. What webserver are you using?
    2. Did you write the SSI programs yourself? Do you have access to the sourcecode? Are they written in perl?
    3. Do you have mod_perl?
    If this were my project runing under Apache w/ mod_perl and the SSI scripts were programs that I had written; I would convert all the SSI's to perl modules and call them via mod_perl from the new .cgi programs.
Re: Best way to
by gaggio (Friar) on Jun 27, 2000 at 17:44 UTC
    OK, thanks guys, but I need to refine my question a little:

    I am running apache, but I'm not sure if it supports mod_perl, since I am not administrating the webserver at my university (and I think that I don't really need to know to obtain what I'm looking for).
    Creating a module is something that I could do, but remember that laziness is what makes a programmer (maybe not a Perl Monk?), so my question was more something like:

    What is the best way, when parsing my template html files (which contain SSI exec calls) to produce the same effect as a real SSI call, without having to change anything to the SSI scripts.

    The scripts are written in Perl, of course, so I have access to the source code. Rewriting them as a module would not be a big hassle, but simplicity and ease are good virtues (wouldn't that be cool if I could redistribute my SSI scripts for somebody who wants to use them as real SSIs?).
      You could do the backtick way (as davorg mentioned), but if you are using mod_perl, you may want to look at Apache::SSI. This may (or may not) do what you want with minimal changes. But, if you are changing the whole way your system works (static to dynamic) you may want to not put a bandaid on it and simply redo it all the right way. What is the right way? Well, that is for you to decide. Maybe HTML::Mason is, or Embperl, etc...

      Cheers,
      KM

      In that case I would be tempted just to execute tha scripts using `...` and insert the output in the approprite place.

      I can think of two potential problems with that tho'

      1. The paths to the scripts in your SSI calls will be URLs, but you'll need absolute filepaths.
      2. All of the scripts that are called from SSIs will return 'Content-type:' headers which will no longer be needed.
      --
      <http://www.dave.org.uk>

      European Perl Conference - Sept 22/24 2000
      <http://www.yapc.org/Europe/>
Re: Best way to
by gaggio (Friar) on Jun 27, 2000 at 18:54 UTC
    I just had an other idea: what about just reading the file that contains the SSI perl script in an array, (and yes, remove the content-type output line), join() the array into a single string, and then do an eval() on that?