#!/usr/bin/perl ############################################################################# ## pod.cgi version 1.95 ## ## Personal Open Directory (POD) - dmoz Version ## ## John M. Grohol ## Originally Released: 04 Jan 1999 ## http://grohol.com/ ## ## This version: ## 25 Mar 2004 ## ## Based on maxcomm.cgi by Ross Faulds Internationalization modification by ## Checkpoint Computer Consultants Ltd Scott Stevenson ## http://www.computer-mentors.co.uk/ extra_lovin@yahoo.com ## Richard A. Chiswell ## (01 Feb 2000 (1.70d+) - 12 Dec 2000) ## http://www.beebware.com/ ## ## Copyright 1999-2004 by John M. Grohol. All rights reserved. ## ## Free to distribute, but you cannot charge for this work or any ## derivatives thereof. No warranties on this program are made or implied. ## ## Warning: ## Because of the dynamic nature of the ODP third-party provider we're ## using (Dmoz.Org), this script changes frequently to keep up-to-date ## with changes ODP makes to the formatting of their site. ## Be prepared to update this script regularly. Starting with version 1.31, ## changes are noted also within the script itself. ## ## ############################################################################# ## Configuration area ## ## Configuration variables are now in separate file called "podvars.pm" ## Place this file in the same directory as POD (add full path before ## filename below if you're having troubles). ## See the documentation for full installation and configuration details require "podvars.pm"; ############################################################################# ## Please avoid altering the code beyond this point. If you make any ## changes, please contact the authors so that your changes can be ## integrated into the official version so everybody can benefit ############################################################################# $SIG{ALRM} = 'pod_timout'; # increment is the subroutine to call when the alarm(80); # Script will timeout after 20 seconds # (change if you'd like) # Declare all the bits and pieces $pod_version="v1.95"; require 5.004; use CGI; if (defined($pod_modperl)) { CGI->compile(':all'); }; # Any error messages send to the browser use CGI::Carp 'fatalsToBrowser'; $CGI::POST_MAX=5*1024; # maximum of 5k length posts accepted - helps prevent DOS attacks $CGI::DISABLE_UPLOADS=1; # no uploads permitted - helps prevent DOS attacks use LWP::UserAgent; use HTTP::Request; use HTTP::Response; ############################################################################# ## Main program ############################################################################# &pod_main; exit 0; sub pod_main { &pod_init; if ($pod_debug) { print "Content-Type:text/html\n\n
pod_main$pod_fullpath$pod_dirextpod_mainpod_outputpod_outputpod_redirect $pod_pr_redirecttopod_redirectpod_modify_content/pod_modify_content\n"; }; } sub pod_modify_content_cgi { # Modifies all references to the DMoz cgi-bin and re-writes them to point # correctly back to this script if (($pod_line =~ /[Aa][Cc][Tt][Ii][Oo][Nn]/) && (!($pod_line =~ /cgi-bin/))) { $pod_line =~ s/action=\"([^2]+)2\.cgi\"/action=\"http:\/\/dmoz\.org\/cgi-bin\/$1~~2\.cgi\"/; } $pod_line =~ s/~~//gi; $pod_line =~ s/http:\/\/dmoz\.org\/cgi-bin\/feedback.cgi/$pod_fullpath\/cgi-bin\/feedback\.cgi/gi; $pod_line =~ s/http:\/\/dmoz\.org\/cgi-bin\/add2\.cgi/$pod_fullpath\/cgi-bin\/add2.cgi/gi; $pod_line =~ s/http:\/\/dmoz\.org\/cgi-bin\/update2\.cgi/$pod_fullpath\/cgi-bin\/update2.cgi/gi; $pod_line =~ s/http:\/\/dmoz\.org\/cgi-bin\/update3\.cgi/$pod_fullpath\/cgi-bin\/update3.cgi/gi; $pod_line =~ s/http:\/\/dmoz\.org\/cgi-bin\/send2\.cgi/$pod_fullpath\/cgi-bin\/send2.cgi/gi; $pod_line =~ s/http:\/\/dmoz\.org\/cgi-bin\/apply2\.cgi/$pod_fullpath\/cgi-bin\/apply2.cgi/gi; $pod_line =~ s/http:\/\/dmoz\.org\/cgi-bin\/forgot\.cgi/$pod_fullpath\/cgi-bin\/forgot.cgi/gi; $pod_line =~ s/action=\"\/cgi-bin\/feedback2\.cgi\"/action=\"http:\/\/dmoz.org\/cgi-bin\/feedback2\.cgi\"/gi; } sub pod_escape { my($text, $patn) = @_; return undef unless defined $text; if (defined $patn){ unless (exists $subst{$patn}) { $subst{$patn}=eval "sub {\$_[0] =~ s/([$patn])/\$pod_escapes{\$1}/g; }"; } &{$subst{$patn}}($text); } else { $text =~ s/([\x00-\x20"#%;<>?{}|\\\\^~`\[\]\x7F-\xFF])/$pod_escapes{$1}/g; #" } return $text; } sub pod_unescape { my @copy = @_; for (@copy) { s/%([\dA-Fa-f]{2})/chr(hex($1))/eg; } wantarray ? @copy : $copy[0]; } # Amazon.com link # Slight change by WizarDave sub pod_amazon { if ($pod_debug) { print "Entering: pod_amazon\n"; }; if (length($pod_dir) > 3) { $pod_topx = $pod_dir; if (index($pod_topx,"?") > 0) { if ($pod_topx =~ "nsidircat") { $pod_triz=rindex($pod_topx,"?"); if (!(defined($pod_amazon_missing))) { $pod_triz=$pod_triz-1; } } else { $pod_triz = rindex($pod_topx,"?"); } } else { $pod_triz=length($pod_triz); if (!(defined($pod_amazon_missing))) { $pod_triz=$pod_triz-1; } } $pod_topx = substr($pod_topx,0,$pod_triz); $pod_tidx = rindex($pod_topx,"/"); $pod_topic = substr($pod_topx,$pod_tidx); } else { $pod_topic = $pod_cgi_search; } # 1.76 if (length($pod_topic) < 3) { $pod_topic = $pod_cgi_search; } $pod_topic =~ s/\///g; $pod_topic_dis = $pod_topic; $pod_topic =~ s/[_ ]/+/g; $pod_topic_dis =~ s/_/ /g; $pod_output="$pod_output ~; if (!($pod_topic)) { $pod_output="$pod_output pod_amazon\n"; }; } sub pod_read_headers { ## This function rips out all the possible parameters which could ## have been sent to this script in the cgi call. These must be ## retained in case they need to be sent to Dmoz.org if ($pod_debug) { print "Entering: pod_read_headers\n"; }; $pod_cgi_all=$pod_q->param("all"); $pod_cgi_ax=$pod_q->param("a.x"); $pod_cgi_affiliation=$pod_q->param("affiliation"); $pod_cgi_cat=$pod_q->param("cat"); $pod_cgi_co=$pod_q->param("co"); $pod_cgi_comments=$pod_q->param("comments"); $pod_cgi_cp=$pod_q->param("cp"); $pod_cgi_description=$pod_q->param("description"); $pod_cgi_des_one=$pod_q->param("des1"); $pod_cgi_des_two=$pod_q->param("des2"); $pod_cgi_des_three=$pod_q->param("des3"); $pod_cgi_desc=$pod_q->param("desc"); $pod_cgi_direct=$pod_q->param("direct"); $pod_cgi_email=$pod_q->param("email"); $pod_cgi_emailaddr=$pod_q->param("emailaddr"); $pod_cgi_firstname=$pod_q->param("firstname"); $pod_cgi_fo=$pod_q->param("fo"); $pod_cgi_id=$pod_q->param("id"); $pod_cgi_index=$pod_q->param("index"); $pod_cgi_jsites=$pod_q->param("jsites"); $pod_cgi_jstart=$pod_q->param("jstart"); $pod_cgi_lastname=$pod_q->param("lastname"); $pod_cgi_lk=$pod_q->param("lk"); $pod_cgi_morecat=$pod_q->param("morecat"); if ($pod_dir =~ /morecat/) { $pod_cgi_morecat = 1; } $pod_cgi_newurl=$pod_q->param("newurl"); $pod_cgi_password=$pod_q->param("password"); $pod_cgi_passverify=$pod_q->param("passverify"); $pod_cgi_reason=$pod_q->param("reason"); $pod_cgi_start = $pod_q->param("start"); $pod_cgi_search = $pod_q->param("search"); if (($pod_dir =~ /search/) && (!($pod_dir =~ /srp/))) { $pod_trg=rindex($pod_dir, "search"); $pod_tre=index($pod_dir,"=",$pod_trg); $pod_cgi_search=substr($pod_dir,$pod_tre+1); } $pod_cgi_search=~ s/\`//g; $pod_cgi_search=~ s/\'//g; $pod_cgi_so=$pod_q->param("so"); $pod_cgi_title=$pod_q->param("title"); $pod_cgi_tit_one=$pod_q->param("tit1"); $pod_cgi_tit_two=$pod_q->param("tit2"); $pod_cgi_tit_three=$pod_q->param("tit3"); $pod_cgi_url=$pod_q->param("url"); $pod_cgi_url_one=$pod_q->param("url1"); $pod_cgi_url_two=$pod_q->param("url2"); $pod_cgi_url_three=$pod_q->param("url3"); $pod_cgi_user=$pod_q->param("user"); $pod_cgi_username=$pod_q->param("username"); $pod_cgi_where=$pod_q->param("where"); # The following two lines allow you to pass an alternative # inital category by passing the variable pod_debug_path $pod_cgi_debug_dir=$pod_q->param("pod_debug_path"); if ($pod_cgi_debug_dir) { $pod_dir=$pod_cgi_debug_dir; }; if ($pod_debug) { print "Leaving: pod_read_headers\n"; }; } sub pod_get_first_page { ## Fetch the pages from the Dmoz server, but re-write the URLs of certain ## ones so we fetch the correct page. if ($pod_debug) { print "Entering pod_get_first_page\n"; }; my $pod_gfp_toget = 0; $pod_cgi_search =~ s/ /+/g; if ($pod_dir =~ /\/osearch/) { $pod_url = "http://search.dmoz.org/cgi-bin/osearch\?search\=$pod_cgi_search"; if ($pod_cgi_start) { $pod_url = $pod_url . "&start=$pod_cgi_start"; } if ($pod_cgi_fo) { $pod_url = $pod_url . "&fo=$pod_cgi_fo"; } if ($pod_cgi_so) { $pod_url = $pod_url . "&so=$pod_cgi_so"; } if ($pod_cgi_co) { $pod_url = $pod_url . "&co=$pod_cgi_co"; } if ($pod_cgi_ax) { $pod_url = $pod_url . "&a.x=$pod_cgi_ax";} } elsif (($pod_cgi_search) && (not($pod_cgi_jstart)) && (!($pod_cgi_morecat))) { $pod_url = "http://search.dmoz.org/cgi-bin/search\?search\=$pod_cgi_search&a.x=$pod_cgi_ax"; } elsif (($pod_cgi_jstart > 0) && (!($pod_cgi_morecat))) { $pod_url = "http://search.dmoz.org/cgi-bin/search\?cp=$pod_cgi_cp&search\=$pod_cgi_search&a.x=$pod_cgi_ax&jstart=$pod_cgi_jstart"; } elsif ($pod_cgi_morecat > 0) { $pod_url = "http://search.dmoz.org/cgi-bin/search\?search\=$pod_cgi_search&a.x=$pod_cgi_ax&morecat=$pod_cgi_morecat"; } elsif ($pod_dir =~ "/searchguide.html") { $pod_url ="http://search.dmoz.org/searchguide.html"; } elsif ($pod_dir =~ "/cgi-bin/add2.cgi") { $pod_gfp_toget=1; } elsif ($pod_dir =~ "/cgi-bin/update2.cgi") { $pod_gfp_toget=2; } elsif ($pod_dir =~ "/cgi-bin/update3.cgi") { $pod_gfp_toget=3; } elsif ($pod_dir =~ "/cgi-bin/apply2.cgi") { $pod_gfp_toget=4; } elsif ($pod_dir =~ "/cgi-bin/forgot.cgi") { $pod_gfp_toget=5; } elsif (($pod_dir =~ "/rdf/") && ($pod_dir =~ ".gz")) { # Handle RDF dumps $pod_validpage=2; $pod_url=$pod_which_dir.$pod_dir; } else { $pod_url = $pod_which_dir . $pod_dir; if ($pod_cgi_jsites) { $pod_url = $pod_url . "&jsites=$pod_cgi_jsites"; } if ($pod_cgi_jstart) { $pod_url = $pod_url . "&jstart=$pod_cgi_jstart"; } if ($pod_cgi_start) { $pod_url = $pod_url . "&start=$pod_cgi_start"; } if ($pod_cgi_fo) { $pod_url = $pod_url . "&fo=$pod_cgi_fo"; } if ($pod_cgi_so) { $pod_url = $pod_url . "&so=$pod_cgi_so"; } if ($pod_cgi_co) { $pod_url = $pod_url . "&co=$pod_cgi_co"; } if ($pod_cgi_search) { $pod_url = $pod_url . "&search=$pod_cgi_search"; } if ($pod_morecat) { $pod_url = $pod_url . "&morecat=$pod_morecat"; } } if ($pod_gfp_toget > 0) { $pod_url=$pod_which_dir.$pod_dir; } # Don't escape out the URL yet... # Sometimes (for example, in conjunction with the search system) it # returns 404. # $pod_url=&pod_escape($pod_url); if ($pod_debug) { print "Parsed URL: $pod_url\n"; }; if ($pod_validpage==0) { # 1.90 my $rand_num = ""; srand(time ^ $$); $rand_num = int(rand(50)); my $br_ver = ""; if ($rand_num gt 30) { $br_ver = "5"; } elsif ($rand_num lt 20) { $br_ver = "01"; } else { $br_ver = "0"; } my $pod_ua = LWP::UserAgent->new(); $ag_ver = "Mozilla/4.0 (compatible; MSIE 5." . $br_ver . "; Windows 98)"; $pod_ua->agent($ag_ver); # my $pod_ua =new LWP::UserAgent; # $pod_ua->agent("$pod_useragent"); if (defined($pod_proxy)) { $pod_ua->proxy('http',$pod_proxy); } my $pod_req; my $tmp_text; if ($pod_gfp_toget==0) { $pod_req = new HTTP::Request('GET',$pod_url); $pod_req->content_type('application/x-www-form-urlencoded'); } else { $pod_req = new HTTP::Request('POST',$pod_url); $pod_req->content_type('application/x-www-form-urlencoded'); if ($pod_gfp_toget==1) { $tmp_text="index=$pod_cgi_index&where=$pod_cgi_where". "&url=$pod_cgi_url&title=$pod_cgi_title&". "description=$pod_cgi_description&email=$pod_cgi_email"; } elsif ($pod_gfp_toget==2) { $tmp_text="lk=$pod_cgi_lk&id=&pod_cgi_id&where=$pod_cgi_where". "&url=$pod_cgi_url"; } elsif ($pod_gfp_toget==3) { $tmp_text="where=$pod_cgi_where&direct=$pod_cgi_direct". "&url=$pod_cgi_url&lk=$pod_cgi_lk&id=$pod_cgi_id". "&newurl=$pod_cgi_newurl&title=$pod_cgi_title". "&desc=$pod_cgi_desc&emailaddr=$pod_cgi_emailaddr". "&reason=$pod_cgi_reason"; } elsif ($pod_gfp_toget==4) { $tmp_text="where=$pod_cgi_where&id=$pod_cgi_id&lk=$pod_cgi_lk". "&firstname=$pod_cgi_firstname&lastname=$pod_cgi_lastname". "&emailaddr=$pod_cgi_emailaddr&username=$pod_cgi_username". "&password=$pod_cgi_password&passverify=$pod_cgi_passverify". "&comments=$pod_cgi_comments&affiliation=$pod_cgi_affiliation". "&url1=$pod_cgi_url_one&tit1=$pod_cgi_tit_one". "&des1=$pod_cgi_des_one". "&url2=$pod_cgi_url_two&tit1=$pod_cgi_tit_two". "&des1=$pod_cgi_des_two". "&url3=$pod_cgi_url_three&tit1=$pod_cgi_tit_three". "&des1=$pod_cgi_des_three"; } elsif ($pod_gfp_toget==5) { $tmp_text="user=$pod_cgi_user"; } $pod_req->content($tmp_text); } $pod_req->header('Referer',"$pod_referer"); if ($pod_debug) { print " URL fetching: $pod_url\n"; if ($pod_gfp_toget==0) { print "Getting... \n"; } else { print "POSTing... \n$tmp_text \n"; } print " \n"; } my $pod_res = $pod_ua->request($pod_req); # Check the outcome of the response $pod_base=$pod_res->base; if ($pod_res->is_success) { $pod_cgi_content = $pod_res -> content(); } else { $pod_validpage=1; $pod_status=$pod_res->status_line; $pod_output="$pod_output POD encountered the following error while trying to run:\n\n";
}
} else {
# a redirect
$pod_cgi_content=$pod_url;
if ($pod_debug) {
print " |