#!/usr/bin/perl # Name: e-Classifieds (Free Edition) # Version: 2.23 # Last Modified: 3-14-99 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. # $script_url should be set to the full URL of this classifieds program on your # server. $script_url = "http://www.highlanderweb.co.uk/members/classifieds/cgi-bin/classifieds.cgi"; # $master_admin_email_address should be set to your e-mail address $master_admin_email_address= "classifieds\@highlanderweb.co.uk"; # $admin_name should be set to the name of the administrator $admin_name = "Classifieds Administration"; # $sitename should be set to the name of your web site $sitename = "Highlander Web Magazine"; # $siteurl should be set to the full URL of your web site $siteurl = "http://www.highlanderweb.co.uk/members/classifieds"; # $slogan should be set to whatever slogan or catchphrase you use for your site $slogan = "\"Free Member Classifieds\""; # $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. # If you are running this program on Windows NT, you should set this to "". You # will not be able to use the e-mail routines for this program on a Windows NT # server. The commercial versions of the program include e-mail routines for # both Windows NT and Unix. $sendmail = "/usr/lib/sendmail"; # The following variable specifies the administrative password. You can # (and should) change this to whatever you want. $admin_password = "Ub181y"; # The following variable specifies the special multiplier that will be # used to generate a unique password for each ad. Please change this from # the default so that other users of this program will not be able to guess # your users' passwords. Also, we recommend against setting this to a round # number such as 1000, etc. It's much better to use a random number such as # 2748, etc. $password_multiplier = "3615"; # 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"; # If set equal to "on", $notify_delete_all will cause the program to notify the # administrator by e-mail anytime someone uses the administrative function to delete # all ads in a category. Normally, you would receive this message after deleting the # ads yourself, but this could be useful for informing you if someone obtains your # administrative password and deletes all ads in a particular category without your # knowledge or permission. $notify_delete_all = "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. For Unix servers, this new directory should have its permissions set to 777. # For Windows NT users, this should point to the full server path to this directory, # beginning with the drive letter and using forward slashes instead of backslashes, # such as "d:/InetPub/wwwroot/ads". $classdir = "/usr/local/etc/httpd/htdocs/highlandweb/members/classifieds"; # $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 should also store the e-Classifieds logo graphic here, as the license # for this free product requires you to display this logo in order to protect our # trademark rights, intellectual property rights, and other legal rights. # Do *not* include the trailing slash ("/") at the end. $htmldir = "http://www.highlanderweb.co.uk/members/classifieds"; # 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 = ("Automobiles & Related|autos", "Business Opportunities|busopps", "Computer Products|computer", "Employment|employment", "Financial|financial", "Housing|housing", "Merchandise|merchandise", "Professional Services|services", "Travel Related|travel"); # The following variable defines any special HTML code that you want to place in # between the and tags on each page. This could include meta tags # or JavaScript, but in most cases, you'll probably just want to leave this set # equal to "". Be sure to put a backslash in front of any quotation marks that # appear inside of your header code, and in front of the @ symbol anywhere that # it appears. $head_code = ""; # The following variable defines the background color of all pages. $bgcolor = "#E5A32F"; # The following variable defines the background graphic (if any) to be used on # all pages. $background = "../../images/high_back99.jpg"; # The following variable defines the default text color. $text_color = "#000000"; # The following variable defines the color for hypertext links. $link_color = "#FFFF00"; # The following variable defines the color for visited links. $vlink_color = "#FFCC00"; # The following variable defines the color for active links. $alink_color = "#FFFFFF"; # The following variable should be set to the URL of the small graphic of your # logo that will be placed in the upper left hand corner of the screen as a link # back to your site's main home page. This logo should be no larger than about # 110 pixels in width, or it may cause distortion of the display for some users # viewing your site using 640 x 480 resolution. If you do not have such a logo, # you can leave this set to "", and the program will display a large text link # back to your site's main home page as defined above in the $siteurl variable. $small_logo_url = "../../images/members_only_left.jpg"; # The following variable defines the HTML that will appear at # the top of the main section of the pages. Please be sure to "comment # out" any quotation marks or @ symbols in your HTML by placing the # backslash symbol ("\") in front of them. # We don't recommend putting much, if anything, here, because this will # cause the main body of the program to appear farther down on the pages, # and will cause your users to have to scroll more. You can safely leave # this empty as it appears in the default version. $header = ""; # The following variable defines the HTML that will appear at # the bottom of the main section of the pages. Please be sure to "comment # out" any quotation marks or @ symbols in your HTML by placing the # backslash symbol ("\") in front of them. # You might want to put your copyright notice or other information here. $footer = "

\"Pages

Highlander Web Magazine Ltd.
Registered in Scotland No. 172342
Email - classifieds\@highlanderweb.co.uk
Pages by Webspinner

"; # End of user-configurable variables. You should not edit anything past this line. ################################################################################# # The following subroutine (pagesetup) defines the HTML that will appear at # the beginning of every page created by this program. You should modify # only the text in between the "print qq~" and the "~;" statements. # Due to the complicated table structure used by the interface and the intertwined Perl # code, we strongly recommend against editing this code unless you are in expert in both # advanced HTML and Perl. # Also, please note that the license for this free program expressly forbids removal # of the e-Classifieds logo from the displays. Thank you for your cooperation. sub pagesetup { local ($title) = @_; print qq~ $slogan $head_code
~; if ($small_logo_url ne "") { print qq~ $sitename Home

~; } else { print qq~ $sitename Home

~; } print qq~
left right
Search Options

Search Ads

Ad Options

Place Free Ad

Delete Free Ad

Other Options

Classifieds Home

Powered by e-Classifieds
left right

$header
Highlander Web Magazine FREE Classifieds
~; } # The following subroutine (pageclose) defines the HTML that will appear # at the end of every page created by this program. You should modify # only the text in between the "print qq~" and the "~;" statements. sub pageclose { print qq~ $footer
~; } # This subroutine defines the HTML for the pages that store the ads for each category. # You should modify only the text in between the "print qq~" and the "~;" statements. # Due to the complicated table structure used by the interface and the intertwined Perl # code, we strongly recommend against editing this code unless you are in expert in both # advanced HTML and Perl. # Also, please note that the license for this free program expressly forbids removal # of the e-Classifieds logo from the displays. Thank you for your cooperation. sub print_default_html { print HTMLFILE qq~ $sitename Classifieds - $long_category_name $head_code
~; if ($small_logo_url ne "") { print HTMLFILE qq~ $sitename Home

~; } else { print HTMLFILE qq~ $sitename Home

~; } print HTMLFILE qq~
left right
Search Options

Search Ads

Ad Options

Place Free Ad

Delete Free Ad

Other Options

Classifieds Home

Powered by e-Classifieds
left right

$header
Highlander Web Magazine FREE Classifieds

$sitename Classifieds - $long_category_name

$footer
~; } ######################################################################## sub print_header { 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; } $current_date = &get_date; if (($in{'add_item_button'} ne "") || ($ENV{'QUERY_STRING'} =~ /place_ads/)) { &print_header; &pagesetup("Post Classified Ad Form"); &generic_form_header; &add_entry_form; &pageclose; exit; } elsif ($in{'post_ad_button'} ne "") { &print_header; &post_ad; } elsif (($in{'delete_item_button'} ne "") || ($ENV{'QUERY_STRING'} =~ /delete_ads/)) { &print_header; &pagesetup("Delete Classified Ad Form"); &generic_form_header; &delete_search_form; &pageclose; exit; } elsif ($in{'delete_button'} ne "") { &print_header; &delete; } elsif (($in{'admin_button'} ne "") || ($ENV{'QUERY_STRING'} =~ /admin/)) { &print_header; &pagesetup("Admin Logon"); &generic_form_header; &delete_all_form; &pageclose; exit; } elsif ($in{'delete_all_button'} ne "") { &print_header; &delete_all; } elsif ($in{'view_ads_button'} ne "") { &view_ads; } else { &print_header; &pagesetup; &display_frontpage; &pageclose; } sub view_ads { if ($in{'category'} eq "") { &print_header; &category_error; } if (-e "$classdir/$in{'category'}.html") { # print "\n"; print "Location: $htmldir/$in{'category'}.html\n\n"; } else { &print_header; &no_ads_message; } exit; } sub no_ads_message { &pagesetup("No Matches Found"); 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. Required fields are denoted by *.

    Your Name*
    Street Address
    City
    State/Province
    Zip/Postal Code
    Country
    Telephone Number
    E-mail Address*
    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. Required fields are denoted by *.

~; 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; if (($in{'name'} eq "") || ($in{'email'} eq "") || ($in{'category'} eq "") || ($in{'caption'} 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); $password = $new_counter * $password_multiplier; # 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: $current_date
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") && ($sendmail ne "")) { open( MAIL, "|$sendmail -t " ) || 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 Classified 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: $current_date\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 $sitename Classified Ads and will come back often. Your ad has been assigned a special password for editing purposes. Please make a note of your ad number and your password now for future reference. You will need them if you ever want to delete your classified ad. The ad number and password for this ad are as follows: ad number: $new_counter password: $password 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\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") && ($sendmail ne "")) { open( MAIL, "|$sendmail -t " ) || die "can't open sendmail notify: $master_admin_email_address: $!\n"; print MAIL "To: $master_admin_email_address\n"; print MAIL "From: $master_admin_email_address\n"; print MAIL "Subject: New Classified Ad\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 "Password: $password\n"; print MAIL "Subject: $in{'caption'}\n"; print MAIL "Posted on: $current_date\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 { &pagesetup("Success: Your Ad has been posted to the Classifieds"); print qq~

Your ad has been successfully posted!

Your ad has been assigned a special password for editing purposes. Please make a note of your ad number and your password, as you will need them if you ever want to delete this ad. Your ad number and your password are the following:
ad number: $new_counter
password: $password

~; &pageclose; } sub required_error { &pagesetup("Missing Field"); print qq~

Missing Field

\n We're sorry, but you did not select a value for a required field. All fields must be filled in. 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~

Delete Your Ad

To delete your classified ad, please fill out all fields in the form below and click on the "Delete This Ad" button. To delete your ad, you must select the category that this ad appears in and enter your name and e-mail address exactly as they appear in your ad. You also must enter the ad number and the password that was sent to you after you posted this ad. If the form is not filled out completely and accurately, your ad will not be deleted.

Ad Information

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


~; } sub delete { if (($in{'name'} eq "") || ($in{'email'} eq "") || ($in{'addno'} eq "") || ($in{'password'} eq "") || ($in{'category'} eq "")) { &required_error; } unless (-e "$classdir/$in{'category'}.html") { &no_ads_message; exit; } # 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; } # Delete the user's ad and description from the ad file open(ADFILE,"$classdir/$in{'category'}.html") || die $!; @main = ; close(ADFILE); $ad_to_delete = "0"; $deleted_ad_found = "0"; open(ADFILE,">$classdir/$in{'category'}.html") || die $!; foreach $main_line (@main) { if ($main_line =~ //) { $ad_to_delete = "0"; } } else { print ADFILE "$main_line"; } } close(ADFILE); # unlock the lock file unlink("$classdir/$in{'category'}.lock"); if ($incorrect_password eq "1"){ &password_error; } elsif ($deleted_ad_found eq "0"){ &unsuccessful_modification_message; } else { &successful_deletion_message; if (($master_admin_email_address ne "") && ($notify_delete eq "on") && ($sendmail ne "")) { open( MAIL, "|$sendmail -t " ) || die "can't open sendmail notify: $master_admin_email_address: $!\n"; print MAIL "To: $master_admin_email_address\n"; print MAIL "From: $master_admin_email_address\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 password_error { &pagesetup("Error: Incorrect Password"); print qq~

Error: Incorrect Password

\n We're sorry, but you did not enter the correct password. Please go BACK and make sure that you have entered the correct password. Thank you.

~; &pageclose; } sub unsuccessful_modification_message { &pagesetup("Error: Ad Not Found"); 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 { &pagesetup("Success: Your ad has been successfully deleted"); print qq~

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

The following ad was deleted from the classifieds:

$deleted_ad

~; &pageclose; } sub delete_all_form { print qq~

Delete All Ads in a Category

If you are the administrator, you can delete all ads in a particular category using the form below. You will need your administrative password to do so. Please select the category that you wish to clear and enter your administrative password in the form below and click on the Delete All Ads button.

Ad Information

Please select the category that you wish to clear:
Administrative Password


~; } sub delete_all { if ($in{'category'} eq "") { &required_error; } unless ($in{'password'} eq "$admin_password") { &admin_password_error; } unless (-e "$classdir/$in{'category'}.html") { &no_ads_message; exit; } unlink("$classdir/$in{'category'}.html"); &pagesetup("Success: All Ads Successfully Deleted"); print qq~

Ads Deleted

All ads in the $in{'category'} category have been deleted.

~; &pageclose; if (($master_admin_email_address ne "") && ($notify_delete_all eq "on") && ($sendmail ne "")) { open( MAIL, "|$sendmail -t " ) || die "can't open sendmail notify: $master_admin_email_address: $!\n"; print MAIL "To: $master_admin_email_address\n"; print MAIL "From: $master_admin_email_address\n"; print MAIL "Subject: Classified Ads Deleted\n"; print MAIL "This is simply a notification that all ads in the $in{'category'} category of the $sitename Classified Ads have been deleted. If you did not perform this deletion, then someone has obtained your administrative password and deleted ads from your site.\n\n"; close(MAIL); } exit; } sub display_frontpage { print qq~ Welcome to the $sitename Classified Ads! To view the ads, choose a category below and click on the View Ads button. You may also choose one of the options along the left hand side of this page.

~; foreach $category (@categories) { @fields = split (/\|/, $category); print qq~ ~; } print qq~
Classified Ad Categories~; &generic_form_header; print qq~
$fields[0]

~; } sub generic_form_header { print qq~

~; } sub get_date { local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$date); local (@days, @months); @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday', 'Friday','Saturday'); @months = ('January','February','March','April','May','June','July', 'August','September','October','November','December'); $time = time; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time); $year = (1900 + $year); if ($mon < 10) { $mon = "0$mon"; } if ($mday < 10) { $mday = "0$mday"; } $mon++; $date = "$mon/$mday/$year"; return $date; } sub category_error { &pagesetup("Error: No Category Chosen"); print qq~

Error: No Category Chosen

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

~; &pageclose; exit; } sub admin_password_error { &pagesetup("Error: Incorrect Password"); print qq~

Error: Incorrect Password

\n We're sorry, but you did not enter the correct administrative password. If you are the admin, please go BACK and make sure that you have entered the correct administrative password. Thank you.

~; &pageclose; exit; }