Gossamer Forum
Home : Products : Links 2.0 : Discussions :

How to do multiple versions of top level page

Quote Reply
How to do multiple versions of top level page
I'd like to be able to have one set of users (staff) be able to add links to our Links 2.0 DB in the normal fashion. But I don't want the general public to be able to add them. What options are they for doing this?

Can Links support if logic statements that would verify a range of IP addresses and display different versions of a page accordingly? Is there another way to approach this?

I'm using the templates & CSS if that alters the approach.

Thanks in advance for any help.

Bobb



Quote Reply
Re: How to do multiple versions of top level page In reply to
If you can use SSI, you can hack Alex' Personlized Greetings script (http://www.gossamer-threads.com/...urces/Other_Scripts/) to something like this:

Code:
#!/usr/bin/perl5 -w

# Prints the Gossamer Threads Home Page greeting.
# Author: Alex Krohn (alex@gossamer-threads.com)

# NOTE: You need the list of domains to country names. I got mine from Analog and
# you can find it here:
#
# http://www.gossamer-threads.com/scripts/source/domains.tab
#

use strict;

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

my ($time, $greeting) = &get_date;
my $country = &get_country;

print qq~
<TABLE BORDER=0 WIDTH=100% CELLSPACING=10 CELLPADDING=10>
<TR BGCOLOR=#FF0000>
<TD>
~;
if ($ENV{'REMOTE_ADDR'}=='123.45.6.789') {
print qq|Dear collegue! Please <a href="add.cgi">add your favorite link</a> to our directory|;
}
elsif (defined $country) {
print qq|Browse our directory ...|;
}
print qq~</td></tr></table>
~;
exit;

sub get_country {
# --------------------------------------------------------------
my ($match, $code, $name);

if (exists $ENV{'REMOTE_HOST'} and ($ENV{'REMOTE_HOST'} =~ /\.(..)$/)) {
$match = $1;

open (DOMAINS, "./domains.tab") or (print "SYSTEM ERR: CANT OPEN FILE" and exit);
while (<DOMAINS>) {
chomp;
($code, $name) = split (/:/);
($code eq $match) and close DOMAINS and return $name;
}
close DOMAINS;
}
return undef;
}

sub get_date {
# --------------------------------------------------------------
my @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
my @months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - 10800);
($hour < 10) and ($hour = "0$hour");
($min < 10) and ($min = "0$min");
($sec < 10) and ($sec = "0$sec");

my $date = "$days[$wday] $months[$mon] $mday";
my ($greeting, $noon);

if ($hour < 12) { $greeting = "Good Morning"; }
elsif ($hour >=12 && $hour < 17) { $greeting = "Good Afternoon"; }
elsif ($hour >=17 && $hour < 24) { $greeting = "Good Evening"; }
else { $greeting = "Hello"; }

($hour < 12) and ($noon = "am");
($hour > 12) and ($hour = $hour - 12) and ($noon = "pm");
($hour == 00) and ($hour = 12);
($hour == 12) and ($noon = "pm");

return "$hour\:$min $noon on $days[$wday], $months[$mon] $mday", $greeting;
}
I haven't removed the time/date thing and stuff, but this should give you the idea. Of course, you need to edit the IP-address to your own.

HTH
John

Quote Reply
Re: How to do multiple versions of top level page In reply to
Hmmm ... perhaps this is enough:
Code:
print "Content-type: text/html\n\n";
if ($ENV{'REMOTE_ADDR'}=='123.45.6.789') {
print qq|Dear collegue! Please <a href="add.cgi">add your favorite link</a> to our directory|;
}
exit;
Save as, e.g., mycollegues.cgi, and call it with SSI thought your home.html template etc. You might need to set build extension to .shtml.


Quote Reply
Re: How to do multiple versions of top level page In reply to
Gotze

Thanks for the help.

I'm grappling with it now but have run into a snag with calling the script via SSI.

I created the script & called it staffonly.cgi. It looks like this

#!/bin/perl
# Uses if logic in calling for add link script

print "Content-type: text/html\n\n";
if ($ENV{'REMOTE_ADDR'}=='155.34.170.*') {
print qq|Dear collegue! Please <a href="add.cgi">add your favorite link</a> to our directory|;
}
exit;

Then I altered the Home template so that the link to add stuff calls the script, like this:



However, when it hits this line it gives me an SSI error message saying it can't process the directive. I know SSI is working because I have it putting a header on this same file just a couple of lines above this and it works fine.

Any suggestions? I haven't used SSI for anything but simple header/footer includes, so perhaps there's another command I should use instead of a simple "include virtual" to make it call a script?

TIA.

Bobb Menk

Quote Reply
Re: How to do multiple versions of top level page In reply to
Try
< !--#exec cgi="/cgi-bin/staffonly.cgi"-- >

(I put in a space after < and before > since the forum dislikes the format)

John

Quote Reply
Re: How to do multiple versions of top level page In reply to
John

Is it possible to alter this slightly so that after the test for IP range, it will either print an HTML file that includes a link to the "Add.cgi" routine, or print an HTML file that leaves out that link?

Something along the lines of:
"print qq|filename1.html
else print qq|filename2.html"

(Obviously I don't the correct syntax here, but you get the idea I think).

print "Content-type: text/html\n\n";
if ($ENV{'REMOTE_ADDR'}=='155.34.170.*') {
print qq|Dear collegue! Please <a href="add.cgi">add your favorite link</a> to our directory|;
}
exit;

Thanks for your help.

Bobb

Quote Reply
Re: How to do multiple versions of top level page In reply to
Do you mean complete HTML-files (starting with <html> and all)? If so, I cannot recommend that, since you will get bad coding (two sets of <html> and so forth).

One solution would be to have a simple index.cgi redirection script, like this:
Code:
#!/usr/bin/perl
if ($ENV{'REMOTE_ADDR'}=='155.34.170.*') {
print "Location: filename1.html\n\n";
}
else {
print "Location: filename2.html\n\n";
}
John

Quote Reply
Re: How to do multiple versions of top level page In reply to
John

Here's what I ended up doing (at least so far).

Simple SSI If statement in the home template that looks like this:

< !--#if expr="${REMOTE_ADDR} = /155.34.170./" -- >
< !--#include virtual="toolbar.txt" -- >
< !--#else -- >
< !--#include virtual="toolbar2.txt" -- >
< !--#endif -- >

If they're on staff, it shows them the Add Link link, if they're not, it shows them the toolbar without that link on it. Right now, it only works on the top level home page. When I include it in the category template it gives me an SSI error.

I'll be working on that next. If I can't make it work perhaps the alternate categories template mod can be of use.

Thanks again.

Bobb

Quote Reply
Re: How to do multiple versions of top level page In reply to
Wow, that's cool Smile
I didn't know if-statements can be used in SSI...

Quote Reply
Re: How to do multiple versions of top level page In reply to
Take a look at
http://bignosebird.com/sdocs/extend.shtml and http://bignosebird.com/sdocs/browser.shtml for the details.

Bobb

Quote Reply
Re: How to do multiple versions of top level page In reply to
Here's my next bit of the problem:

My if logic works only at the top level, when you go to a category, you need to repeat the SSI if statements. The obvious place to do so is in the Category.html template.

At the level it breaks because of a path problem. Obviously, one could keep copies of the included file in each of the category sub dirs, but that's a waste of space.

The SSI variable DOCUMENT_URI will return the path to the current document - is there a way to get just the path and not the file name from that variable?

It would look perhaps something like this:

< !--#if expr="${REMOTE_ADDR} = /155.34.170./" -- >
< !--#include virtual="${DOCUMENT_URI_PARSED_FOR_PATH}/toolbar.txt" -- >

Any thoughts on this one greatly appreciated.

Bobb