#!/usr/bin/perl ############################################################################## # Film Facts Script Version 1.0.2 # # Copyright 2000 Randy L. Moulton bigmachine@pacbell.net # # Created 07/22/00 Last Modified 08/01/00 # # # ############################################################################## # COPYRIGHT NOTICE # # Copyright 2000 Randy L. Moulton All Rights Reserved. # # # # You should carefully read all of the following terms and conditions # # before using this program. Your use of this software indicates # # your acceptance of this license agreement. # # # # This program is being distributed as freeware for personal use. # # It may be modified free of charge, so long as this copyright # # notice remains intact. # # # # Commercial use requires licensing and registration. # # # # By using this program you agree to indemnify Randy L. Moulton any # # liability. # # # # Selling the code for this program without prior written consent is # # expressly forbidden. # # # ############################################################################## ############################################################################## # $AllowableSites variable # As a security precaution, the page calling 'display.cgi' # must be registered in the $AllowableSites # # Ex: $AllowableSites = ('www.yoursite.com') # (Note: single quotes only) ############################################################################## @AllowableSites = ('7plusrailroader.com'); ############################################################################## # $AddressPath Variable # This is the directory location, on your server, that contain # the FilmFact Data files. # # Ex: $AddressPath= "/home/httpd/yoursite/"; ############################################################################## $AddressPath = "/home/sevenplusrailroadercom/public_html/"; ############################################################################## # $Mask_htm Variable # This is the directory location, on your server, that has the mask template. # Note: The mask template needs to be located in the cgi-bin. # # Ex: $Mask_htm= "/home/httpd/yoursite/cgi-bin/filmmask.htm"; ############################################################################## $Mask_htm = "/home/sevenplusrailroadercom/public_html/cgi-bin/photomask.htm"; ############################################################################## # Main # # ############################################################################## #Make sure that the site calling the script is on our list of @AllowableSites if (!&ValidSite) { print "Content-type: text/html\n\n"; print "Access Denied. You're not on the accessiblity list.\n"; exit; } #Make sure that the QueryString contains 1 item. This is a FilmFact data file #name that is passed to the script. (i.e., liberty.txt) if (!&ValidQueryString) { print "Content-type: text/html\n\n"; print "Access Denied. Parameter list is invalid or missing.\n\n"; exit; } #Make sure both the datafile and filmmask files exist; if (!&BothFilesExist) { print "Required File Missing.\n\n"; exit; } #Get the data from $DataFile &ExtractData; #Open the mask template $Mask_htm &GetTheMask; #Scan and create the output &FormatOutput; ############################################################################## # Subroutines # # ############################################################################## ############################################################################## # Subroutine: BothFilesExist # # ############################################################################## # BothFilesExist sub BothFilesExist { #Make sure data file exists if ( -e $DataFile) { #$DataFile exists if ( -e $Mask_htm) { #$Mask_htm exists too return(1); #files exist } else { print "Content-type: text/html\n\n"; print "Mask File does not exist: $Mask_htm\n\n"; return(0); #return false } } else { print "Content-type: text/html\n\n"; print "Data File does not exist: $DataFile\n\n"; return(0); #return false } } ############################################################################## # Subroutine: ExtractData # # ############################################################################## # ExtractData sub ExtractData { #Open $DataFile and load into @Data array if (!open(DATAFILE, "$DataFile")) { print "Content-type: text/html\n\n"; print "File not found: $DataFile\n\n"; exit; } @Data = ; close(DATAFILE); $DataLineCount = @Data; #Load individual data sections into discreet variables. $Caption = $Data[1]; $Image = $Data[3]; #Find exactly where the Treatment and Producer notes are $i = 0; while ($i <= $DataLineCount) { #$_ is a default argument. $_ = @Data[$i]; if (//) { $TreatmentStart = $i + 1; #this is 1st line of treatment } if (//) { $TreatmentEnd = $i - 1; #this is last line of treatment $NotesStart = $i + 1; #this is 1st line of producers notes } if ( ($i == $DataLineCount) and ($TreatmentEnd == 0) ) #end of file { $TreatmentEnd = $i; } $i++; } #end while #Now load the Treatment list if ($TreatmentStart > 0) { for ($i = $TreatmentStart; $i <= $TreatmentEnd; $i++) { push(@Treatment, $Data[$i]); }#end for } else { push(@Treatment, 'Treatment Unavailable'); } if ($NotesStart > 0) #then there are producer notes { #Now load the Producers Notes list for ($i = $NotesStart; $i <= $DataLineCount; $i++) { push(@ProducerNotes, $Data[$i]); } #end for } else { push(@ProducerNotes, ''); } } ############################################################################## # Subroutine: GetTheMask # # ############################################################################## # GetTheMask sub GetTheMask { #Open input mask_htm load into @Mask array if (!open(FILE, "$Mask_htm")) { print "Content-type: text/html\n\n"; print "File not found: $Mask_htm\n\n"; exit; } @Mask = ; close(FILE); $LineCount = @Mask; } #end GetTheMask ############################################################################## # Subroutine: ValidQueryString # # ############################################################################## sub ValidQueryString { @pairs = split(/,/, $ENV{'QUERY_STRING'}); #if ($#pairs != 1) # { # return(0); #not enough parameters # } $DataFile = $pairs[0]; #do some error checking # Make sure $Image has value if (!$DataFile) { return(0); #variables is blank } $DataFile = $AddressPath.$DataFile; return(1); #variable passed error checking } ############################################################################## # Subroutine: ValidSite # # ############################################################################## sub ValidSite { foreach $Site (@AllowableSites) { if ($ENV{'HTTP_REFERER'} =~ m|http://([^/]*)$Site|i) { return(1); #site is valid } } return(0); #site is invalid } ############################################################################## # Subroutine: FormatOutput # Scans @Mask array looking for '' or '' or # '' or ''. When any of these is found # substitute the values found in the FilmFact datafile. Otherwise print # out the $Mask html code unchanged. ############################################################################## sub FormatOutput { print "Content-type: text/html\n\n"; for ($i=0; $i <= $LineCount; $i++) { #This seems a little clearer. #$Temp = $Mask[$i]; #if ($Temp eq "\n") #$_ is a default argument. The next 2 lines work. $_ = @Mask[$i]; if ( (//) || (/!--Caption-->/) || (//) || (//) ) { if (//) { print ""; } else { if (/!--Caption-->/) { print "$Caption"; } else { if (//) { print "@Treatment"; } else { if (//) {print "@ProducerNotes"; } } } } } else { print $_; } } #end for } #end sub FormatOutput