#!/usr/bin/perl ################################# # This version requires perl 5. Some servers will require the first line to be # Changed in order to point to the perl 5 source. Talk to your web server technicians ######################################################################### # Bible Lookup Program v 1.0 # by Chris Priebe, Authentic Walk Ministries, 2000 # http://www.authenticwalk.com # # This program is dedicated to God and His servants # Please feel free to copy and modify this program # for any task that would honor our King ########################################################################## # Originally taken from the Bible toolbox # http://www.authenticwalk.com/bibletoolbox # # This script is designed to look up a Bible chapter on your web page # It takes the reference given in a form, parses it, and redirects the user # Please make sure you are not infringing in any copyright laws before beginning # # It can be modified to send a user to a commentary, a discussion # on a chapter or book of the Bible, or a user-built list of sermon ideas # I would suggest starting with the New Testament until you can get the # content up so users aren't annoyed that there never is anything on their request # You can find Bible versions from http://www.ebible.org/bible/ # # I wrote this program because when I first set out to write the Bible Toolbox # I could not find any script out there on this topic. And so I want to give # this script to Christian webmasters so as a body we can develop useful content # on the web for Christian research. # Please email me at biblescript@authenticwalk.com so I can see what you have done # and perhaps add you to the Bible Toolbox once the content is large and useful enough. # If you like, please link to me. More information on that can be found at # http://authenticwalk.com/bibletoolbox/help/connect.htm # ########################################################################### # SETTING IT UP # Make sure the first line (above) points to your perl program on your server # copy this file into your cgi-bin on your server in ASCII mode (not binary) # Note: Not all servers allow cgi scripts. If this is the case then you will have to use # the html code by itself and point the form to http://www.authenticwalk.com/cgi-bin/lookup.cgi # and it will send the user to the right page on your site. # CHMOD the file to 755 # Put the HTML form code (below) into your web page # Copy the web page as normal in your web directory # Make 66 directories in your root directory (one for each Bible book name) # NOTE: if you do not want it to check the referal url and send back to that domain then you need to # enter the web address to your root directory in the variable $my_root_directory when it appears later in the program # Make sure it ends in /"; The file structure will look like # http://www.MyDomainName.com/MyDirectoryIWantItToStartIn/Genesis/ # http://www.MyDomainName.com/MyDirectoryIWantItToStartIn/Exodus/ # and so on. (if you need the spelling, make sure it is the same as in %BooksOfBible # Name each chapter of that book "The Chapter Number".htm and put it in the right directory # For instance, the html for genesis chapter 1 is # http://www.MyDomainName.com/MyDirectoryIWantItToStartIn/Genesis/1.htm # The name of the book would be # http://www.MyDomainName.com/MyDirectoryIWantItToStartIn/Genesis/index.htm # If you do not have an index.htm then it will view all the contents of that folder # # Enter the server address of your root directory (ask your server administrator for that) # This is so the program can check to make sure there is a file there before it sends you # If you want to skip this, set the value below to "" #$my_server_address = "/home/mydomain/"; $my_server_address = ""; # ############################################################## # THE HTML CODE TO PUT ON YOUR WEB PAGE # Make sure you change YourDomainName to your Domain name both here and in the # error message below. # #
#

#
# ############################################################# # This is a list of all the books of the Bible and their abbreviations # The program checks to see if either the abbreviation or part of the full # name has been entered, if so it returns the full name %BooksOfBible = ( "Genesis" , "ge", "Exodus" , "ex", "Leviticus" , "le", "Numbers" , "nu", "Deuteronomy" , "de", "Joshua" , " jos", "Judges" , " jud", "Ruth" , "ru", "1Samuel" , "1sa", "2Samuel" , "2sa", "1Kings" , "1ki", "2Kings" , "2ki", "1Chronicles" , "1ch", "2Chronicles" , "2ch", "Ezra" , "ezr", "Nehemiah" , "ne", "Esther" , "es", "Job" , "job", "Psalms" , "ps", "Proverbs" , "pr", "Ecclesiastes" , "ec", "Songofsongs" , "so", "Isaiah" , "isa", "Jeremiah" , "jer", "Lamentations" , "la", "Ezekiel" , "eze", "Daniel" , "da", "Hosea" , "ho", "Joel" , "joe", "Amos" , "am", "Obadiah" , "ob", "Jonah" , "jon", "Micah" , "mic", "Nahum" , "na", "Habakkuk" , "hab", "Zephaniah" , "zep", "Haggai" , "hag", "Zechariah" , "zec", "Malachi" , "mal", "Matthew" , "mt", "Mark" , "mr", "Luke" , "lu", "John" , "joh", "Acts" , "ac", "Romans" , "ro", "1Corinthians" , "1co", "2Corinthians" , "2co", "Galatians" , "ga", "Ephesians" , "eph", "Philippians" , "php", "Colossians" , "col", "1Thessalonians" , "1th", "2Thessalonians" , "2th", "1Timothy" , "1ti", "2Timothy" , "2ti", "Titus" , "tit", "Philemon" , "phm", "Hebrews" , "heb", "James" , "jas", "1Peter" , "1pe", "2Peter" , "2pe", "1John" , "1jo", "2John" , "2jo", "3John" , "3jo", "Jude" , "jude", "Revelation" , "re" ); # First off we will determine the base address to send the user to # This is based on where they came, if you do not want to use that # method you can delete the next 6 lines and simply set it to whatever you like in a line like the one below #$my_root_directory = "http://www.MyDomainName.com/"; $ENV{'HTTP_REFERER'} =~ /(.*\/)(.*?)\/.*?/; ($my_root_directory, $book) = ($1, $2); foreach $key (keys(%BooksOfBible)) # Figure out if the url has a Bible bookname in it, if it does, delete it since we'll add a new one later {if ($book eq $key) {$book = "";} } if ($book ne "") {$my_root_directory = "$my_root_directory$book/";} # If there was no bookname than it is important to add that part back onto the address # Get the form input $buffer = $ENV{'QUERY_STRING'}; @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } ############################# # For Testing purposes only # # $FORM{"reference"} = "James 1"; # Remove a space in the book name so can split correctly @array = split(//, $FORM{"reference"}); if (@array[1] eq " ") {@array[1]="";} $reference = join ("", @array); @ref = split (" ", $reference); #Get the proper book name if ($FORM{"reference"} eq "") {&errormsg("Please enter a Bible reference to look up");exit;} # If you recieved the above error and did enter a reference then check the html form and make sure the textbox is named reference foreach $key (keys(%BooksOfBible)) # Go through all the books of the Bible and run a test {$test = "\U$ref[0]\E"; # Put the reference up till the first space in all capital letters in $test if (("\U$key\E" =~ /^\b$test.*$/i) || ("\U$BooksOfBible{$key}\E" eq $test)) # If it is any of the first letters of the full name or the abbreviation we got a hit {$book = $key; # Save the full book name last; # Exit the loop since we found it } # End of if } # End of foreach if ($book eq "") {&errormsg("I could not find that book name. Please enter any part of the full books name or an abbreviation of it and try again");exit;} # We could not find the book they wanted so display an error message. if ($ref[1] =~ /([\d]{1,3})/) # If the part of the reference after the space is a number 1 to 3 digits long {$chapter = "$1.html"; # I put the html part here so that if there is no chapter it will just load the directory $verse = $'; if ($verse =~ /:([\d]+)/) {$chapter = "$chapter\#$1";} # In this case the verse is a bookmark on the page, you may change that to whatever you like } else {$chapter = "";} ###################################### # A NOTE about security # A security risk most often happens when a users data is used to perform a function (especially system commands) # A problem occurs when they enter in bad data # Since there input is only accepted if it matches our list of book names # And the chapter can only be a number between 0 and 999 # there is no risk because they cannot give bad characters. # Be careful though if you expand this program to always check their data #################################################### # Now redirect the user to that page # In order for this to work, the content-type cannot be defined yet # I would like to add an error check to make sure the page was indeed loaded # If you know how to do that let me know if ($my_server_address ne "") # Skip the check file command if no server address to check {if (-e "$my_server_address$book/$chapter") {$success = "yes";} else {&errormsg("This chapter does not exist at this time, perhaps check to make sure the reference $book $chapter is correct or try a more familiar chapter");exit;} } print "Location: $my_root_directory$book/$chapter\n\n"; # There was an error, display a message sub errormsg { print "Content-type:text/html\n\n"; print "Error Message\n"; print "
$_[0]
\n"; print "

Please press the back button and try again

\n"; print "
\n"; }