Gossamer Forum
Home : Products : DBMan : Installation :

SSI and HTML.pl

Quote Reply
SSI and HTML.pl
Is there a way to include pages (e.g. SSI or perhaps CGI)? It seems that if I include <!--#include file="../../page.htm" -->, the directive isn't processed because it's in a CGI script rather than an HTML document like SSI should be. Is there any way around this?

Also, when viewing records in default mode - default mode only - can I eliminate the footer and the "Your Search returned 1 matches"??

Thanks,
Blake

My html.pl
www.outermost.net/html_pl.txt

My default.cfg
www.outermost.net/default_cfg.txt
Quote Reply
Re: SSI and HTML.pl In reply to
I was thinking about this problem and was wondering if there is some CGI-based way to call a file. It can check to see if files exist, so there should be a CGI command to call an htm or txt file and include it. Just a thought, but does anyone know of a command like this?

-Blake Kunisch
Quote Reply
Re: SSI and HTML.pl In reply to
What are you trying to accomplish? What is the end result you want to see?


------------------
JPD





Quote Reply
Re: SSI and HTML.pl In reply to
I asked this over in the general Perl and CGI discussion area and received the exact result I needed. Here's the thread:
http://www.gossamer-threads.com/...um8/HTML/000601.html

Thanks for all your help!
-Blake Kunisch
Quote Reply
Re: SSI and HTML.pl In reply to
Or here:

http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/000311.html
Quote Reply
Re: SSI and HTML.pl In reply to
How about calling another CGI from DBMan?
i.e. I need to include an output of another cgi program
Quote Reply
Re: SSI and HTML.pl In reply to
That's another problem I'm having. For example I would like to be able to include a poll CGI and a Advertising CGI in my script, but I can't seem to get them to work. I'm able to make due without them (just using text links), but it would be nice to be able to execute CGI from within DBMan. Any suggestions??

-Blake Kunisch
Quote Reply
Re: SSI and HTML.pl In reply to
blakex,

What codes are you using to attempt the execution of cgi files within the html.pl file?

Have you tried inserting these codes as a sub-routine in default.cgi, then calling them as &Insert_Banner; (or something like that) in html.pl file?

Just a suggestion.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: SSI and HTML.pl In reply to
That would be the way to do it, I would think. Thanks Eliot!

Blake, please let us know if that works for you. There are lots of questions about SSI and I've never known how to answer them.


------------------
JPD





Quote Reply
Re: SSI and HTML.pl In reply to
Try this in your db.cgi file.

Code:
sub Insert_Banner {
open(FILE, "/path/to/file.ext") or die("Couldn't open the file.");
@lines = <FILE>;
close(FILE);
foreach $line (@lines) {
print $line;
}
}

Change the /path/to/file.ext to your banner or poll program.

Then in html.pl file, use these codes:

Code:
|;
&Insert_Banner;
print qq|

Hope this helps.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

(I edited this so that the name of the db.cgi file would be the same as everyone else has. Eliot forgets that he has renamed the file. Smile )


[This message has been edited by JPDeni (edited August 09, 1999).]
Quote Reply
Re: SSI and HTML.pl In reply to
It would be kind of hard to insert the CGI as a subroutine and call it via an & call, you can see in the code below that some of the same variables are used which could mess things up. Here's the poll CGI that I want to include:
Code:
$q = 1; # the question you want to ask

$polldir = '/usr/local/www/net-outermos/cgi-bin/lite/poll';
$graph_image = 'http://outermost.net/images/survey/white.jpg';
$cgi = 'http://www.outermost.net/cgi-bin/lite/poll/robpoll.cgi';

$check_cookies = 1; # how to block multi-voting
$check_ip = 1; # 1 = use, 0 = don't

$tablecolor = 'ffcc99'; # these colors can be entered as a word like
$textcolor = '880000'; # 'black' or an RGB value like '#FFFFFF'
$textfont = 'arial';
$textsize = 2;
$border = 0;
$cellpadding = 1;
$cellspacing = 0;

$graph_height = 5;
$graph_width = 0.5; # factor for the graph width

$include_percent = 0; # 1 = include this option, 0 = don't
$include_graph = 0;
$include_total = 1;

#########################################################################
# Don't change anything below here unless you know what you're doing Smile #
#########################################################################

print "Content-type: text/html\n\n";

$ip = $ENV{REMOTE_ADDR};
$ssi_total = $include_percent + $include_graph + 2;
$polldata = "$polldir/data.txt";
$Cookie_Exp_Date = 'Tue, 31-Dec-1999 00:00:00 GMT';
$Secure_Cookie = '0';
$Cookie_Path = '/';

@Cookie_Encode_Chars = ('\%', '\+', '\;', '\,', '\=', '\&', '\:\:', '\s');

%Cookie_Encode_Chars = ('\%', '%25',
'\+', '%2B',
'\;', '%3B',
'\,', '%2C',
'\=', '%3D',
'\&', '%26',
'\:\:', '%3A%3A',
'\s', '+');

@Cookie_Decode_Chars = ('\+', '\%3A\%3A', '\%26', '\%3D', '\%2C', '\%3B',
'\%2B', '\%25');

%Cookie_Decode_Chars = ('\+', ' ',
'\%3A\%3A', '::',
'\%26', '&',
'\%3D', '=',
'\%2C', ',',
'\%3B', ';',
'\%2B', '+',
'\%25', '%');

open(FILE, "$polldata") &#0124; &#0124;
&file_open_error($polldata); @lines = <FILE>;
close(FILE);
$num = @lines;

($num_questions,$nochop) = split(/``/,$lines[0]);
(@num_answers) = split(/``/,$lines[1]);
(@q_id) = split(/``/,$lines[2]);
(@questions) = split(/``/,$lines[3]);
(@answers) = split(/``/,$lines[4]);
($encrypted_password, $nochop) = split(/``/, $lines[5]);

$total_answers[0] = 0;

for ($a = 1; $a < $num_questions; $a++) {
$total_answers[$a] = $total_answers[$a-1] + $num_answers[$a-1];
}

&ssi_results($q-1) if ($ENV{QUERY_STRING} eq 'results');
&go;
exit;
sub go {

&check($q-1);
&ssi_results($q-1) if ($foundip eq 'Yes');

print "<form action=\"$cgi\" method=\"post\">\n";

print "<table bgcolor=$tablecolor border=$border cellpadding=$cellpadding cellspacing=$cellspacing>\n";

print "<tr><th colspan=2><font face=$textfont color=$textcolor size=$textsize>$questions[$q-1]</font></th></tr>\n";

for ($b = $total_answers[$q-1]; $b < $total_answers[$q-1]+$num_answers[$q-1]; $b++) {
$c = $b-$total_answers[$q-1] + 1;
print "<tr>\n";
print "<td><input type=\"radio\" name=\"response\" value=\"$c\"></td>\n";
print "<td align=left><font face=$textfont color=$textcolor size=$textsize>$answers[$b]</td></tr>\n";
}

print "<tr><td align=center colspan=2>\n";
print "<input type=\"hidden\" name=\"what\" value=\"votessi\">\n";
print "<input type=\"hidden\" name=\"q\" value=\"$q\">\n";
print "<input type=\"submit\" value=\"Submit Vote\">\n";
print "</td></tr>\n";
print "</table>\n";
print "</form>\n";
print "</center></font></body></html>\n";

exit;

}

sub ssi_results {

local($qu) = @_;

open(FILE, "$polldir/q$q_id[$qu]\.txt") &#0124; &#0124; &file_open_error("q$q_id[$qu]\.txt");
@lines = <FILE>;
close(FILE);
@values = split(/``/, $lines[0]);
$nv = @values;
$total = 0;

for ($a = 0; $a < $nv; $a++) {
$total += $values[$a];
}

for ($a = 0; $a < $nv; $a++) {
if ($values[$a] > 0) {
$values_p[$a] = sprintf("%.2f", ($values[$a]/$total) * 100);
} else {
$values_p[$a] = 0;
}
$values_g[$a] = int($graph_width * $values_p[$a])+1;
}

print "<font face=\"$textfont\" size=\"$textsize\" color=\"$textcolor\">";
print "You have voted on this topic.</font><br>\n\n";

print "<table bgcolor=\"$tablecolor\" cellpadding=$cellpadding cellspacing=$cellspacing>\n";
print "<tr><th colspan=$ssi_total><font face=\"$textfont\" size=\"$textsize\" color=\"$textcolor\">";
print "$questions[$qu]</font></td></tr>\n";

$c = 0;
for ($b = $total_answers[$qu]; $b < $total_answers[$qu]+$num_answers[$qu]; $b++) {
print "<tr>\n";
print "<td align=left><font face=\"$textfont\" size=\"$textsize\" color=\"$textcolor\">$answers[$b]</font></td>\n";
print "<td align=center><font face=\"$textfont\" size=\"$textsize\" color=\"$textcolor\">$values[$c]</td></font>\n";
if ($include_percent == 1) {
print "<td align=center><font face=\"$textfont\" size=\"$textsize\" color=\"$textcolor\">$values_p[$c] %</font></td>\n";
}
if ($include_graph == 1) {
print "<td align=left><img src=\"$graph_image\" height=\"$graph_height\" ";
print "width=\"$values_g[$c]\"></td>\n";
}
print "</tr>\n";
$c++;
}
if ($include_total == 1) {
print "<tr>\n";
print "<th><font face=\"$textfont\" size=\"$textsize\" color=\"$textcolor\">TOTAL</font></th>\n";
print "<th><font face=\"$textfont\" size=\"$textsize\" color=\"$textcolor\">$total</font></th>\n";

if ($include_percent == 1) {
print "<th><font face=\"$textfont\" size=\"$textsize\" color=\"$textcolor\">100.00 %</font></th>\n";
}
if ($include_graph == 1) {
print "<td><font color=$tablecolor>..</font></td>\n";
}
print "</tr>\n";

}

print "</table>\n";

exit;

}

sub check {

local($qu) = @_;
$foundip = 'No';

if ($check_cookies) {
if (&GetCookies('questions')) {
(@answered) = split(/,/,$Cookies{'questions'});
for ($f = 0; $f < @answered - 1; $f++) {
$foundip = 'Yes' if ($answered[$f] == $q_id[$qu]);
}
}
else {
$Cookies{'questions'} = "No Cookies Found";
}
}

if ($check_ip) {
open(FILE, "$polldir/ip$q_id[$qu]\.txt") &#0124; &#0124; &file_open_error("ip$q_id[$qu]\.txt");
@lines = <FILE>;
close(FILE);
$numip = @lines;
$voted[$a] = 'No';
for ($b = 0; $b < $numip; $b++) {
($check_ip,$nochop) = split(/``/,$lines[$b]);
if ($check_ip eq $ip) {
$foundip = 'Yes';
$b = $numip;
}
}
}

}

sub file_open_error {
local($err) = @_;
&fatal_error("Can't Open $err");
exit;
}

sub fatal_error {
local($e) = @_;
print "<font face=arial size=3>";
print "[ RobPoll Fatal Error: $e ]</font>\n";
exit;
}

sub GetCookies {

local(@ReturnCookies) = @_;
local($cookie_flag) = 0;
local($cookie,$value);

if ($ENV{'HTTP_COOKIE'}) {

if ($ReturnCookies[0] ne '') {

foreach (split(/; /,$ENV{'HTTP_COOKIE'})) {

($cookie,$value) = split(/=/);

foreach $char (@Cookie_Decode_Chars) {
$cookie =~ s/$char/$Cookie_Decode_Chars{$char}/g;
$value =~ s/$char/$Cookie_Decode_Chars{$char}/g;
}

foreach $ReturnCookie (@ReturnCookies) {
if ($ReturnCookie eq $cookie) {
$Cookies{$cookie} = $value;
$cookie_flag = "1";
}
}
}

}
else {

foreach (split(/; /,$ENV{'HTTP_COOKIE'})) {
($cookie,$value) = split(/=/);

foreach $char (@Cookie_Decode_Chars) {
$cookie =~ s/$char/$Cookie_Decode_Chars{$char}/g;
$value =~ s/$char/$Cookie_Decode_Chars{$char}/g;
}

$Cookies{$cookie} = $value;
}
$cookie_flag = 1;
}
}

return $cookie_flag;
}

sub SetCookieExpDate {

if ($_[0] =~ /^\w{3}\,\s\d{2}\-\w{3}-\d{4}\s\d{2}\:\d{2}\:\d{2}\sGMT$/ &#0124; &#0124; $_[0] eq '') {
$Cookie_Exp_Date = $_[0];
return 1;
}
else {
return 0;
}
}

sub SetCookiePath {
$Cookie_Path = $_[0];
}

sub SetCookies {

local(@cookies) = @_;
local($cookie,$value,$char);

while( ($cookie,$value) = @cookies ) {

foreach $char (@Cookie_Encode_Chars) {
$cookie =~ s/$char/$Cookie_Encode_Chars{$char}/g;
$value =~ s/$char/$Cookie_Encode_Chars{$char}/g;
}

print 'Set-Cookie: ' . $cookie . '=' . $value . ';';

if ($Cookie_Exp_Date) {
print ' expires=' . $Cookie_Exp_Date . ';';
}

if ($Cookie_Path) {
print ' path=' . $Cookie_Path . ';';
}

if ($Cookie_Domain) {
print ' domain=' . $Cookie_Domain . ';';
}

if ($Secure_Cookie) {
print ' secure';
}

print "\n";

shift(@cookies); shift(@cookies);
}
}

If anyone knows how I could insert as a subroutine, that would be great, but if not, no problem...

-Blake
Quote Reply
Re: SSI and HTML.pl In reply to
I think I may have a lead on how to modify the banner routine you are looking to add into DBMAN. It will take some work, but I think it can be done. I have just added in a hit counter routine that relies on SSI into my db.cgi file and then called the routine by &hitcount; in html.pl file. The following instructions are not seamless to say the least, but it will allow your banners to show up dynamically in your DBMAN pages.

1) Copy the top configuration variables into your default.cfg file.

2) Basically, what you need to do is add the following lines into the sub main of db.cgi in the midst of the elsif statements before the admin_display statement:

Code:
# New routines for banner program

elsif ($in{'banner'}) { if ($per_view) { &banner; }} else { &html_unauth; } }
elsif ($in{'go'}) { if ($per_view) { &go; }} else { &html_unauth; } }
elsif ($in{'ssi_results'}) { if ($per_view) { &ssi_results; }} else { &html_unauth; } }
elsif ($in{'check'}) { if ($per_view) { &check; }} else { &html_unauth; } }
elsif ($in{'file_open_error'}) { if ($per_view) { &file_open_error; }} else { &html_unauth; } }
elsif ($in{'GetCookies'}) { if ($per_view) { &GetCookies; }} else { &html_unauth; } }
elsif ($in{'SetCookieExpDate'}) { if ($per_view) { &SetCookieExpDate; }} else { &html_unauth; } }
elsif ($in{'SetCookies '}) { if ($per_view) { &SetCookies ; }} else { &html_unauth; } }

# End routines for banner program

3) Then copy the main part of your script starting with the print "Content-type: text/html\n\n"; and paste into a new sub-routine in the db.cgi file. DO NOT COPY THE CONTENT statement. LEAVE THIS OUT. Name the sub-routine,banner.

4) Then copy the rest of your sub-routines below this new banner sub-routine.

5) In your html.pl file, insert the following codes to call the banner sub-routine:

Code:
|;
&banner;
print qq|

Try it and see if it works.

Good luck.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 14, 1999).]