Solved

how to include SSI in CGI(perl) script?

Posted on 1998-06-22
19
572 Views
Last Modified: 2013-11-18
Greetings,

Does anybody know how to include a SSI into a perl script? here is an example:
#! /usr/bin/perl -w

select(STDOUT); $|=1;

print <<EOF;
Content-TYPE: text/html

<html>
....

<address>
Last Updated and Validated  on <!--#flastmod file="addentry.pl" -->
</address>
</body></html>
EOF

I know I could use stat or lstat function to get the result. just curious about how to do
it in SSI.

Thanks in advance

Peggy
0
Comment
Question by:pyang051597
  • 8
  • 4
  • 4
  • +2
19 Comments
 
LVL 6

Expert Comment

by:alamo
Comment Utility
Normally the server doesn't check the CGI output for SSI directives, as it would waste server time. You have to configure the server to tell it to parse .cgi (or .pl) output for SSI.
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
#You could also
print <<EOF;
.
Last Updated and Validated on @{[scalar localtime ((stat"addentry.pl")[9])]}
.
EOF
0
 

Author Comment

by:pyang051597
Comment Utility
How to configure the server to parse cgi output for SSI?

I increased the points, hoping you are more interested.


0
 

Author Comment

by:pyang051597
Comment Utility
How to configure the server to parse cgi output for SSI?

I increased to points, hoping you are more interested.


0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
Well, that's a good first step, next you need to tell us what server you are using :-)
0
 
LVL 2

Expert Comment

by:tpryor
Comment Utility
print `your_ssi.cgi`;

that would do it.

GL
t
0
 

Author Comment

by:pyang051597
Comment Utility
for simplicity, let's say APACHE server.
0
 
LVL 2

Expert Comment

by:tpryor
Comment Utility
oh i see, you are just curious.  you dont actually want to execute another (SSI) cgi script.

you wouldnt really configure the server to parse cgi output.

because it would be more efficent to call the (SSI) script within your perl script.

you just want to know how to configure your server that way so you can make sure that it is not configured that way to increase performance.  

oh, now I get it <gr>

t

0
 

Author Comment

by:pyang051597
Comment Utility
Yes, I like to know how to call the ssi script within perl script, but I dont know HOW, and I dont understand your "print `your_ssi.cgi`".  I think configuration of the server may be
easier.  

I am still interested in the answer, in both way, if possible

Thanks again.
 
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Expert Comment

by:tpryor
Comment Utility
print `your.cgi` executes another script and puts it's output where it was called from in the first script. dont need to configure the server to get the same results, more efficient, and IMHO its eassier <gr>

t
0
 

Author Comment

by:pyang051597
Comment Utility
Can you give me an example?

Thanks
0
 
LVL 2

Expert Comment

by:tpryor
Comment Utility
yep, Ill make it simple but you could have it be as complicated as you like in the real world no restrictions on this because they are just perl scripts.

make two perl scripts
In one (the ssi) set it uo the normal way except you dont need to print out the server header line (content-type: text/html\n\n).

just do
print "this is out put from the ssi<br>\n";

In the other
set it up in the normal way and dont forget the header line.
print "this is out put from my cgi<br>\n"
print `ssi.cgi`; # make sure the files are in the same dir or
                                # include the full path path/ssi.cgi
print "here is some more out put from my cgi<br>\n";

that should give you an idea of how it works.  It is quite simple.

GL,
t
0
 

Author Comment

by:pyang051597
Comment Utility
OK, i made 2 files, one is ssi.pl as follows:
#! /usr/bin/perl -w

print "this is out put from the ssi<br>\n";
print <<EOF;
Last Updated and Validated  on <!--#flastmod file="ssi.pl" -->
EOF

another file is called ssi_1.pl

#! /usr/bin/perl -w

select(STDOUT); $|=1;

print <<EOF;
Content-TYPE: text/html

<html>
<body>
EOF

print "this is out put from my cgi<br>\n" ;
print `./ssi.pl`;
print "</body>";
print "</html>";

but it did not work, what's wrong? I am on SUN workstation, using
APACHE server, the server has been configured so it SSI is included.

0
 

Author Comment

by:pyang051597
Comment Utility
Sorry, tpryor, I have to reopen the question, since the way you told me didn't work.

Thanks for help
0
 
LVL 1

Accepted Solution

by:
mikegrb earned 100 total points
Comment Utility
To answer you original question:

It is impossible (AFAIK).  If it where you would:
Add "AddHandler server-parsed .pl" to conf/srm.conf and then
'killall -HUP httpd' however the CGIs ending in .pl are now
treated as if they where .shtml and thus they are not executed
but simply parsed for SSI directives and sent to the browser.

You might take a look at
http://www.cgi-resources.com/Programs_and_Scripts/Perl/Server_Side_Include_Parsing/
and similiar sites and adapt an existing CGI to use as a require.


0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
Hi pyang,

As mikegrb says, Apache can not be configured to do SSI processing on the output of a script. (Their FAQ says they plan to add it). The link he gave has some good alternatives.

To explain why tpryor's approach didn't work - it was not a way to do <!--#flastmod file="ssi.pl" -->, it was a way to do <!--#exec cgi="ssi.pl" -->. So yes it was a way to simulate one feature of SSI (included scripts), but not the feature you originally asked for (flastmod).

The real answer was far simpler anyway, and now you have it.
0
 

Author Comment

by:pyang051597
Comment Utility
Thank you very much.

Alamo, I wish I could give you some credits as well. but I guess
there is no way to split the points, right?:)


0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
Not easily, you have to ask customer service.

In this case that's not necessary, but thanks.
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
print <<EOF;
<address>
Last Updated and Validated  on <!--#flastmod file="addentry.pl" -->
<address>
EOF
#can be emulated with
print <<EOF;
<address>
Last Updated and Validated on @{[scalar localtime ((stat"addentry.pl")[9])]
<address>
EOF

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now