#!/usr/bin/perl # Name: Cyber Ads (Free Edition) # Version: 1.0 # Last Modified: 9-9-98 by Philip A. Hagen # The user-configurable variables are listed below. You need to define these # before uploading the program, or it will not work properly. # Most of these variables are in the following format: # $variable = "value"; # The # symbol will not be in front of the actual variables, however, as this # is used to "comment out" lines in Perl. In other words, lines that begin with # the # symbol are ignored by Perl when it executes the program. The $ sign # is used to indicate variables in Perl, while the items in between the quotation # marks represent the assigned value of that variable. The semicolon indicates # the end of the statement. Therefore, in the example above, if you wanted to # change the value for that variable, the only thing that you should change is # the portion in between the quotation marks. For example, to change the value # of the variable $variable to "red", you would edit it as follows: # $variable = "red"; # Again, you would not put the # symbol in front of $variable. We did that # here only because this is an example that we do not want the program to # actually execute. # Two other things you should note are that if you use quotation marks as part # of the value (in other words, inside of the quotation marks that define the # value), then you must "comment them out" by putting a back slash symbol (the # "\" symbol) in front of them. For example: # $variable = "The \"red\" light"; # Also, if you use the @ symbol in any of your value statements, you must # similarly comment it out by putting a backslash symbol in front of it, # such as in the following: # $my_email_address = "me\@mydomain.com"; ################################################################# # The variables are defined below. # $this_script_url should be set to the full URL of this classifieds program on your # server. $this_script_url = "http://www.rainforestpets.net/cgi-bin/classifieds/classifieds.cgi"; $contact_url = "http://www.rainforestpets.net/"; # $master_admin_email_address should be set to your e-mail address $master_admin_email_address="ramtuff\@rainforestpets.net"; # $admin_name should be set to the name of the administrator $admin_name = "John Powell"; # $sitename should be set to the name of your web site $sitename = "RainForest Pets - Pet Classifieds"; # $siteurl should be set to the full URL of your web site $siteurl = "http://www.rainforestpets.net/"; # $slogan should be set to whatever slogan or catchphrase you use for your site $slogan = "\"Buy - Sell - Trade at RainForest Pets Classifieds! Get Paid to Surf The Net! Join For Free http://www.utopiad.com/member/getPaid?refId=129462 Become Your Own Publisher BONUS #1) Report Package Disk #1, #2, #3, and #4 (712 re sellable reports) BONUS #2) Infodisk 500 - Several hundred reports with a built in interface to easily locate and print them. Sized so that it can be duplicated on one standard IBM floppy and resold. BONUS #3) 167 Business and Financial Reports - Like Infodisk 500 this is a DOS based program that can be copied onto a floppy disk and resold. It has 167 reports in a easy to use index so you can locate them by name or subject. Re sellable. Send 19.95 + 3.00 S&H To: Flights of Fancy PO Box 343 Chisholm Mn 55719\""; # $sendmail should be set to the full server path to sendmail on your Unix server # By default, this is set to "/usr/sbin/sendmail", but on many Unix systems, it is # located at "/usr/lib/sendmail". If you don't know this, you might try typing # "whereis sendmail" or "which sendmail" from a Telnet prompt. $sendmail="/usr/lib/sendmail"; # The following variable should be set to the location of the date command # on your Unix server. If you don't know this, you might try typing # "whereis date" or "which date" from a Telnet prompt. The most common # locations are "/bin/date" or "/usr/bin/date". $date_command = "/bin/date"; # If set equal to "on", $notify_add will cause the program to notify the administrator # by e-mail anytime that an ad is posted to the system $notify_add = "on"; # If set equal to "on", $reply_user will cause the program to send a reply e-mail # to the user who just posted an ad thanking them and reminding them of their ad # number so that they can delete their ad in the future $reply_user = "on"; # If set equal to "on", $notify_delete will cause the program to notify the # administrator by e-mail anytime someone deletes an ad $notify_delete = "on"; # $classdir should point to the full server path of the new directory that you created # for this program where the ads.counter file and the HTML pages for the ads will be # stored $classdir = "/var/www/rainforestpets.net/classified"; # $htmldir should point to the full URL of the new directory that you created for # this program where the ads.counter file and the HTML pages for the ads will be # stored. You might also want to store the Cyber Ads logo graphic here. # Do *not* include the trailing slash ("/") at the end. $htmldir = "http://www.rainforestpets.net/classified"; # The @categories array defines the ad categories that the program will use. For each # category, you need to list it in the following format: # "Long Name of Category|shortname", where the long name is the name that will be displayed # at the top of pages in that category. This can contain several words and spaces. The # short name can contain only one word with no spaces, as this is used internally by the # program for keeping track of the categories. @categories = ("Aquarium|aqua","Aquarium Products|aquapro","Birds|birds","Bird Products|birdpro","Cats|cat","Cat Products|catpro","Dogs|dog","Dog Products|dogpro","Exotic Animal|exotic","Exotic Animal Products|exoticpro","Misc|misc","Reptiles|reptile","Reptile Products|reptilepro","Small Animal|small","Small Animal Products|smallpro","Merchandise|merchandise","Wanted|want"); # The following subroutine defines how the HTML pages that are dynamically generated by the # program will appear. This subroutine (pagesetup) defines how the beginning part of the # HTML is defined. You can set the general background images or colors here, as well as # the title that will appear at the top of each page. Please be careful to modify only the # HTML in between the "qq~" and the "~;" code, or you will cause a syntax error that will # break the program. sub pagesetup { print qq~ RainForest Pets - Pet Classifieds
RainForest Pets - Pet Classifieds

Welcome to the Pet Classifieds.



pslogo.gif - 2503 Bytes

flukerban2.gif - 30.33 K




~; } # The following subroutine defines how the HTML pages that are dynamically generated by the # program will appear. This subroutine (pageclose) defines how the end part of the HTML # is defined. This includes the general navigation tables that appear at the bottom of # every page. Please be careful to modify only the HTML in between the "qq~" and # the "~;" code, or you will cause a syntax error that will break the program. sub pageclose { print qq~

~; &generic_form_header; print qq~

Classifieds Home

RainForest Pets Home

Cyber Ads Free Edition


utopiad_468b.gif - 12819 Bytes

cfsanibanner.gif - 49.06 K


Copyright© RainForest Pets 1995 - 2004 All rights Reserved
~; } # This subroutine defines the HTML for the pages that store the ads for each category. # Please be careful to modify only the HTML in between the "qq~" and # the "~;" code, or you will cause a syntax error that will break the program. sub print_default_html { print HTMLFILE qq~ RainForest Pets - Pet Classifieds $long_category_name
RainForest Pets - Pet Classifieds
$long_category_name

RainForest Pets Home

Cyber Ads Free Edition


NetRadio Homepage


Copyright© RainForest Pets 1995 - 2000 All rights Reserved
~; } # End of user-configurable variables. You should not edit anything past this line. ######################################################################## print "Content-type: text/html\n\n"; ####################################################################### # Read and Parse Form Data # ####################################################################### # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g; if ($allow_html != 1) { $value =~ s/<([^>]|\n)*>//g; } else { unless ($name eq 'body') { $value =~ s/<([^>]|\n)*>//g; } } $in{$name} = $value; } if ($in{'add_item_button'} ne "") { &generic_header("Post Classified Ad Form"); &pagesetup; &generic_form_header; &add_entry_form; &pageclose; exit; } elsif ($in{'post_ad_button'} ne "") { &post_ad; } elsif ($in{'delete_item_button'} ne "") { &generic_header("Remove Classified Ad Form"); &pagesetup; &generic_form_header; &delete_search_form; &pageclose; exit; } elsif ($in{'remove_ad_button'} ne "") { &remove; } elsif ($in{'remove_all_button'} ne "") { &remove_all; } elsif ($in{'view_database_button'} ne "") { &generic_header("View Classified Ads Form"); &pagesetup; &generic_form_header; &view_database_form; &pageclose; exit; } elsif ($in{'view_ads_button'} ne "") { &view_ads; } else { &pagesetup; &display_frontpage; &pageclose; } sub view_database_form { print qq~
Quick Search

~; print qq~

From the following category:

~; } sub view_ads { if ($in{'category'} eq "") { &category_error; } if (-e "$classdir/$in{'category'}.html") { print "\n"; # print "Location: $htmldir/$in{'category'}.html\n\n"; } else { &no_ads_message; } exit; } sub no_ads_message { &generic_header("No Matches Found"); &pagesetup; print qq~

No Matches Found

We're sorry, but it appears that there currently are no ads in this category. Please go back and try another category.

~; &pageclose; } sub add_entry_form { print qq~
Contact Information

Please provide the following contact information.

Your Name
Street Address
City
State/Province
Zip/Postal Code
Country
Telephone Number
E-mail Address ( Required to Post Ad )
URL of your home page
Check here if you want to display your postal address and telephone number in your ad

Your Ad

Please fill in the details of your ad below.

~; foreach $category (@categories) { @fields = split (/\|/, $category); print qq~ ~; } print qq~

Categories
Please check the category that you want to place your ad in
$fields[0]

If none of the categories above was applicable for your ad, what categories would you like to see us add here?
Caption
Text of your ad (HTML is not allowed. Hit the Return key once for a line break, or twice for a new paragraph.)

~; } sub post_ad { $counter = 0; # Get the Date for Entry $date = `$date_command +"%A, %B %d, %Y"`; chop($date); $shortdate = `$date_command +"%D"`; chop($shortdate); if (($in{'name'} eq "") || ($in{'email'} eq "") || ($in{'street'} eq "") || ($in{'city'} eq "") || ($in{'state'} eq "") || ($in{'zip'} eq "") || ($in{'country'} eq "") || ($in{'phone'} eq "") || ($in{'category'} eq "") || ($in{'text'} eq "")) { &required_error; } @fields = split (/\|/, $in{'category'}); $long_category_name = $fields[0]; $short_category_name = $fields[1]; $in{'text'} =~ s/\n/
/g; # Lock the file for security so the file is not damaged if more than one user tries to access it at the same time. $quit = 0; while ($quit != 1) { if (-e "$classdir/$short_category_name.lock") { # The file exists, time to take a nap sleep(1); } else { # Create the lock file, thereby locking the Classified Ad file open (LOCK,">$classdir/$short_category_name.lock"); close LOCK; } # Open the data file to read the number of the last post open (ADFILE, "$classdir/ads.counter"); $old_counter = ; # chop $old_counter; # Update the Ad Number by one $old_counter++; $new_counter = $old_counter; # Rewrite the data file open (ADFILE, ">$classdir/ads.counter"); print ADFILE "$new_counter"; close(ADFILE); # If it doesn't already exist, create the HTML file where the ads will be # stored for this category unless (-e "$classdir/$short_category_name.html") { open (HTMLFILE,"+>$classdir/$short_category_name.html"); &print_default_html; close (HTMLFILE); } # Append the user's ad and description to the ad file open(ADFILE,"$classdir/$short_category_name.html") || die $!; @main = ; close(ADFILE); open(ADFILE,">$classdir/$short_category_name.html") || die $!; foreach $main_line (@main) { if ($main_line =~ //) { print ADFILE "\n"; print ADFILE "\n"; print ADFILE qq~
$in{'caption'}
Ad Number: $new_counter Date Posted: $shortdate
Contact: $in{'name'}
~; if ($in{'display_address'} eq "on") { print ADFILE qq~ $in{'street'}
$in{'city'}, $in{'state'} $in{'zip'}
$in{'country'}~; } print ADFILE qq~
Telephone: ~; if ($in{'display_address'} eq "on") { print ADFILE qq~ $in{'phone'}~; } print ADFILE qq~
E-mail: $in{'email'}
Web Site: $in{'url'}

Description
$in{'text'}

\n ~; print ADFILE "\n"; } else { print ADFILE "$main_line"; } } # unlock the lock file unlink("$classdir/$short_category_name.lock"); if ($reply_user eq "on") { open( MAIL, "|$sendmail $in{'email'}" ) || die "can't open sendmail: $email: $!\n"; print MAIL "To: $in{'email'}\n"; print MAIL "From: $master_admin_email_address\n"; print MAIL "Subject: $sitename Classified Ads\n"; print MAIL "Reply-to: $master_admin_email_address\n\n"; print MAIL "Thank you for submitting your classified ad in the $long_category_name section of the $sitename Ads. Your ad has been posted and appears as follows:\n\n"; print MAIL "Ad Number: $new_counter\n"; print MAIL "Subject: $in{'caption'}\n"; print MAIL "Posted on: $shortdate\n"; print MAIL "Reply to: $in{'name'} at $in{'email'}\n"; print MAIL "Text of ad: $in{'text'}\n"; print MAIL "URL (if any): $in{'url'}\n\n"; print MAIL "You can come back at any time and delete your posting as necessary. We hope you enjoy the new $sitename Ads and will come back often. Also, please make a note of your ad number now for future reference. You will need it if you ever want to delete your classified ad. The ad number for this ad is the following: ad number: $new_counter If you did not post a classified ad on the $sitename Classifieds and believe that you have received this by mistake, please accept our apologies and notify us immediately. As a security measure, you are receiving this message because someone used your e-mail address when posting a classified ad on the $sitename Classified Ads.\n\n"; print MAIL "Sincerely,\n\n"; print MAIL "$admin_name, Webmaster\n"; print MAIL "$sitename\n"; print MAIL "$siteurl\n"; print MAIL "$slogan\n"; close(MAIL); } if (($master_admin_email_address ne "") && ($notify_add eq "on")) { open( MAIL, "|$sendmail $master_admin_email_address" ) || die "can't open sendmail notify: $master_admin_email_address: $!\n"; print MAIL "To: $master_admin_email_address\n"; print MAIL "From: $in{'name'} <$in{'email'}>\n"; print MAIL "Subject: New Classified Ad\n"; print MAIL "Reply-to: $in{'email'}\n\n"; print MAIL "The following classified ad was added to the $long_category_name section of the $sitename Classified Ads by $in{'name'}:\n\n"; print MAIL "Ad Number: $new_counter\n"; print MAIL "Subject: $in{'caption'}\n"; print MAIL "Posted on: $shortdate\n"; print MAIL "Reply to: $in{'name'} at $in{'email'}\n"; print MAIL "Text of ad: $in{'text'}\n"; print MAIL "URL (if any): $in{'url'}\n\n"; print MAIL "They recommended the following new categories (this will be blank if they made no recommendations): $in{'category_wanted'}"; close(MAIL); } &successful_addition_message; $quit = 1; } } # End of sub post_ad sub successful_addition_message { &generic_header("Success: Your Ad has been posted to the Classifieds"); &pagesetup; print qq~

Your ad has been successfully posted!

Please make a note of your ad number, as you will need it if you ever want to delete this ad. Your ad number is $new_counter.

~; &pageclose; } sub required_error { print qq~Missing Field\n~; &pagesetup; print qq~

Missing Field

\n I am sorry, but you did not select a value for a required field. All fields must be filled in. Would you please go BACK and make sure that you have selected a value for all of the required fields. Thank you.
~; &pageclose; exit; } sub delete_search_form { print qq~

Deleting Your Classified Ad

To delete your classified ad, fill out the form below completely and click the "Delete This Ad" button. If the form is not filled out completely, your ad will not be removed from the system.

Ad Information

Please select the category where your ad is located:
Your Name
E-mail Address
Ad Number


~; } sub remove { if (($in{'name'} eq "") || ($in{'email'} eq "") || ($in{'addno'} eq "") || ($in{'category'} eq "")) { &required_error; } # Lock the file for security so the file is not damaged if more than one user tries to access it at the same time. $quit = 0; while ($quit != 1) { if (-e "$classdir/$in{'category'}.lock") { # The file exists, time to take a nap sleep(1); } else { # Create the lock file, thereby locking the Classified Ad file open (LOCK,">$classdir/$in{'category'}.lock"); close LOCK; } # Remove the user's ad and description from the ad file open(ADFILE,"$classdir/$in{'category'}.html") || die $!; @main = ; close(ADFILE); $del = "0"; $del1 = "0"; open(ADFILE,">$classdir/$in{'category'}.html") || die $!; foreach $main_line (@main) { if ($main_line =~ //) { $del = "0"; } } else { print ADFILE "$main_line"; } } # unlock the lock file unlink("$classdir/$in{'category'}.lock"); if ($del1 eq "0"){ &unsuccessful_modification_message; } else { &successful_deletion_message; if (($master_admin_email_address ne "") && ($notify_delete eq "on")) { open( MAIL, "|$sendmail $master_admin_email_address" ) || die "can't open sendmail notify: $master_admin_email_address: $!\n"; print MAIL "To: $master_admin_email_address\n"; print MAIL "From: $in{'name'} <$in{'email'}>\n"; print MAIL "Subject: Classified Ad Deleted\n"; print MAIL "Reply-to: $in{'email'}\n\n"; print MAIL "Ad number $in{'addno'} was deleted from the $in{'category'} section of the $sitename Classified Ads by $in{'name'}.\n\n"; close(MAIL); } } $quit = 1; } # End of while ($quit != 1) exit; } sub unsuccessful_modification_message { &generic_header("Error: Ad Not Found"); &pagesetup; print qq~

Error: Ad Not Found

The ad you selected was not found. Please make sure that you have entered your name, e-mail address, and ad number correctly on the deletion form. Thank you.~; &pageclose; } sub successful_deletion_message { &generic_header("Success: Your ad has been successfully deleted"); &pagesetup; print qq~

The Ad that you selected has been Deleted from the Classifieds!

The following ad was deleted from the classifieds:

$deleted_ad

~; &display_frontpage; &pageclose; } sub display_frontpage { print qq~ Please choose an option from the buttons below.

~; } sub generic_header { local ($title) = @_; print qq~ $title ~; } sub generic_form_header { print qq~

~; } sub category_error { print qq~Error: No Category Chosen\n~; &pagesetup; print qq~

Error: No Category Chosen

\n We're sorry, but you did not select a category. Would you please go BACK and make sure that you have selected a category. Thank you.

~; &pageclose; exit; }