#!/usr/bin/perl
################################################################
# DO NOT EDIT ANYTHING BELOW #
################################################################
################################################################
# TITLE: Popularity #
# VERSION: 1.36 #
# CREATED ON: August 13, 2000 #
# LAST UPDATED: October 22, 2000 #
# E-MAIL: support@cgibiz.com #
# WEB SITE: http://www.cgibiz.com #
################################################################
# COPYRIGHT (C) 2000 ARVYDAS STRAUSAS. ALL RIGHTS RESERVED #
################################################################
# Copyright Notice #
# ---------------- #
# This script can be freely used and distributed, but any #
# modification of it without the written consent of Arvydas #
# Strausas is strictly prohibited. Copying any of the code #
# contained within this script and claiming it as your own is #
# also prohibited. You may not remove any of these header #
# notices. By using this code you agree to indemnify author #
# from any liability that might arise from it's use. #
################################################################
use integer;use cg;use Socket;cg::content_type("text/html");$cg::params{"version"}=de("Qpxfsfe!cz!=b!ubshfu>`cmbol!isfg>#iuuq;00xxx/dhjcj{/dpn#?Qpqvmbsjuz!2/47=0b?");my$url=$cg::params{"url"};$url=~s/http:\/\///os;$url=cg::escape($url);my$template="form";my@report;my$i;my$s;my@engines=("AltaVista","www.altavista.com/cgi-bin/query?pg=q&kl=XX&q=link%3A\$url+-+host%3A\$url&search=Search"," pages found.","Details
","Google","www.google.com/search?q=link%3A\$url",". ","Details
","HotBot","hotbot.lycos.com/?MT=http%3A%2F%2F\$url&submit=SEARCH&SM=url&DV=0&RG=all&RD=RG&DC=10&DE=2&_v=2&OPs=MDRTP","","Details
","Infoseek","www.go.com/Split?qt=link%3A\$url+-site%3A\$url&sv=IS&lk=noframes&pat=go"," matches","Details","Lycos","lycospro.lycos.com/srchpro/?aloc=sb_init_mylink&first=1&lpv=1&type=advwebsites&query=&t=all&mlu=\$url&mli=&mle=&x=0&y=0"," web","Details");if($url){my$ur;my$popularity;my$content;for($i=0;$i<@engines;$i+=4){if(!$cg::params{$engines[$i]}){next;}$ur=$engines[$i+1];$ur=~s/\$url/$url/gs;if($content=http_request($ur)){if($engines[$i]=~/hotbot/ios){my$j=index($content," than ");my$k;my$l;if($j>0){$k=rindex($content,">",$j)+1;$l=index($content,"<",$j);}else{$j=index($content," matches ");$j=index($content," Matches ")if$j<0;$k=rindex($content,">",$j)+1;$l=$j;}$popularity=substr($content,$k,$l-$k);$popularity=~s/ / /gios;}else{$content=~/([0123456789,]+)$engines[$i + 2]/i;$popularity=$1;}if(length($popularity)<128){$ur=$engines[$i+3];$ur=~s/\$url/$url/gs;my@ar=($engines[$i],$popularity,$ur);push(@report,\@ar);}}}$template="report";}open(TEMPLATE,"templates/$template.html")or error("templates/$template.html");while(defined($s=)){if(index($s,"\$popularity")>=0){foreach(@report){$cg::params{"engine"}=$_->[0];$cg::params{"popularity"}=$_->[1];$cg::params{"details"}=$_->[2];$_=$s;s/\$(\w+)/$cg::params{$1}/ges;cg::print($_);}}else{$s=~s/\$(\w+)/$cg::params{$1}/ges;cg::print($s);}}close(TEMPLATE);if($cg::page!~/$cg::params{"version"}/o){$cg::page="";}sub de{my$s=$_[0];$s=~s/([\!-\~])/chr(ord($1) - 1)/eg;return$s;}sub http_request{my$query=$_[0];my$i=index($query,"/");my$host=substr($query,0,$i);my$addr=sockaddr_in(80,inet_aton($host));$query="GET ".substr($query,$i)." HTTP/1.1\nReferer: http://www.cgibiz.com\nUser-agent: Popularity\nHost: $host\n\n";my$content;if(socket(SOCKET,PF_INET,SOCK_STREAM,getprotobyname("tcp"))&&connect(SOCKET,$addr)){syswrite(SOCKET,$query,length($query));$/="\0";$content=;$/="\n";close(SOCKET);}return$content;}sub error{cg::print "Error
$_[0]
$!
$cg::params{'version'}";exit();}