#!/usr/bin/perl ################################################################################ # Created : Martin Foster # Modified : 17/02/2003 ################################################################################ # # Webring - Script part of Ethereal Realms, designed to link up hybrid and # publicly listed realms. # Copyright (C) 2000-2003 Martin Foster # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Author of this script can be contacted at the following: # E-Mail : martin@ethereal-realms.org # Address : 204 - 817, 5th Street NE # Calgary, Alberta # T2E 3W9 # ################################################################################ use CGI qw(:standard); # Common gateway interface use CGI::Carp qw(fatalsToBrowser); # CGI Error logs use strict; # Strict variable enforcement use Ethereal::Database; # Database handler use Ethereal::Param; # Parameter control ################################################################################ # Data Members ################################################################################ my $cgi; # Common gateway interface handle my $database; # Database handle my $sname; # Simply the script name my $sparam; # Scripted parameter string my %sparam; # Scripted parameters my %system; # System hash ################################################################################ # Program Area ################################################################################ # Initial handles $cgi = new CGI; $database = new Ethereal::Database(); # Connect and fetch $database->Connect(); # Link with hash $database->GetHashSystem(\%system); # Pull script name $sname = $cgi->url(-full=>1); $sparam = $cgi->url(-path_info=>1); # Determine need # Escape $sname = quotemeta($sname); # Needed addition $sparam = ($sparam =~ /\/$/) ? $sparam : "$sparam/"; # Truncate $sparam =~ s/^$sname\///; # Retrieve parameters ($sparam{'ROOM'}, $sparam{'MOVE'}) = split(/\//, $sparam); # Need to redirect if ((defined($sparam{'ROOM'})) && (defined($sparam{'MOVE'}))) { # Unescape $sparam{'ROOM'} = $cgi->unescape($sparam{'ROOM'}); # Call subroutine Redirect($database, \%sparam, \%system); } else { # Redirect to safe place $cgi->redirect($system{'LocScriptHub'}); } ################################################################################ # Sub-Routines ################################################################################ ##################### # Redirect # # This will handle the information gathering, determine where the user currently # is and send him off to a brave new world. sub Redirect { ##################### # Data members my $database = shift; # Database handle my $sparam = shift; # Uncovered parameters my $system = shift; # System level hash my $data = $database->{'HANDLE'}; # Direct handle my $res; # Results page my $statement; # Statement handle my $count; # Current position my $pos; # Set position my $size; # Returned entries my %val; # Referencing sanity ##################### # Program area # Sanity %val = ( RealmName => 0, RealmHomepage => 1 ); # Retrieve list # Prepare and execute $statement = $data->prepare("SELECT RealmName, RealmHomepage FROM Realm WHERE RealmHomepage IS NOT NULL ORDER BY RealmName"); $statement->execute(); # Pull results if ($res = $statement->fetchall_arrayref()) { # Determine size $size = @{$res}; # Loop and search for ($count=0; $count < $size; $count++) { # Bypass misses next if ($res->[$count]->[$val{'RealmName'}] !~ /$sparam->{'ROOM'}/i); # Match found # Next if ($sparam->{'MOVE'} =~ /NEXT/i) { # Determine position $pos = (($count+1) < $size) ? $count + 1 : 0; } # Previous elsif ($sparam->{'MOVE'} =~ /PREV/i) { # Determine position $pos = (($count-1) >= 0) ? $count - 1 : $size - 1; } # Random elsif ($sparam->{'MOVE'} =~ /RAND/i) { # Legacy random srand(); # Randomly figure it out $pos = int(rand() * $size); } # Improper commands else { # Redirect $cgi->redirect($system->{'LocScriptHub'}); # Premature exit last; } # Redirect to proper location $cgi->redirect($res->[$pos]->[$val{'RealmHomepage'}]); # Premature exit last; } # End query $statement->finish(); # Return return 1; } # Redirect $cgi->redirect($system->{'LocScriptHub'}); # Retunr return 0; }