Location: PHPKode > scripts > Adsense Checker > acheck/acheck.php
<?php
// Adsense Hacking Check
// (c) 2007 Scriptol.com
// Check the Adsense codes on your website.
// Could be replaced by a code for the account of a hacker.
// FTP program. The program ***changes nothing*** on your website.
// Licence: Mozilla.
// Script available at http://www.scriptol.com
//
include_once("path.php");
include_once("dirlist.php");
include_once("ftp.php");
include_once("dom.php");
include_once("tools.php");
$QUIET=false;
$REMODE=false;
$DISPNUM=false;
$DISPDIR=false;
$server="";
$user="";
$pass="";
$params=array();
$connection=0;
$counter=0;
$okcount=0;
$badcount=0;
$pages=array();
$extensions=array(".php",".html",".htm",".asp",".xhtml",".php3",".php4",".php5",".aspx");
$codeList=array();
$temporary="sol-adsense-checker.000.temp";
$log=0;
function display($t)
{
   global $VERBOSE;
   if($VERBOSE)
   {
      echo $t, "\n";
   }
   global $log;
   fwrite($log,$t."\n");
   return;
}

function parsePage($temp,$url)
{
   $mask="/google_ad_client(.+);/i";
   $count=0;
   $page=array();
   $page=file($temp);
   $content=implode("\n",$page);
   $results=array();
   preg_match_all($mask,$content,$results);
   $results=$results[1];

   if((count($results)===0))
   {
      return;
   }
   reset($results);
   do
   {
      $t= current($results);
      $res=array();
      preg_match("/[\"\'](.+)[\"\']/i",$t,$res);
      $t=$res[1];
      display($t);
      global $codeList;
      if(!in_array($t,$codeList))
      {
         array_push($codeList,$t);
         echo "+";
      }
      $count+=1;
   }
   while(!(next($results) === false));

   global $DISPNUM;
   if($DISPNUM)
   {
      echo $count;
   }
   else
   {
      echo ".";
   }
   return;
}

function syncConnect()
{
   global $connection;
   global $server;
   $connection=ftp_connect($server);
   if($connection===0)
   {
      die("Not connected");
   }
   global $user;
   global $pass;
   if(ftp_login($connection,$user,$pass)===true)
   {
      echo "Connected on $server as $user", "\n";
      if(ftp_pasv($connection,true)===true)
      {
         echo "Passive mode turned on", "\n";
      }
      else
      {
         echo "Enable to set passive mode", "\n";
      }
      return true;
   }
   else
   {
      echo "Enable to connect as $user on $server", "\n";
   }
   return false;
}

function syncDisconnect()
{
   global $connection;
   ftp_close($connection);
   return;
}

function convertUnix($src)
{
   return str_replace("\\","/",$src);
}

function ftpDownload($locfile,$src)
{
   global $DEBUG;
   if($DEBUG)
   {
      echo "Download $src into $locfile", "\n";
   }
   global $connection;
   $result=@ftp_get($connection,$locfile,$src,FTP_BINARY);
   if($result!=true)
   {
      echo "Error, enable to get the $src file from ", " ", ftp_pwd($connection), "\n";
      return false;
   }
   return true;
}

function ftpCheck($ftpdir)
{
   $ext="";
   $content=array();
      global $connection;
   @ftp_chdir($connection,$ftpdir);
   $content=ftp_nlist($connection,'.');

   if(empty($content))
   {
      return;
   }
   reset($content);
   do
   {
      $name= current($content);
      if($name{0}===".")
      {
         continue;
      }
      $ext=Path::getExtension($name);
      global $extensions;
      if(!in_array($ext,$extensions))
      {
         continue;
      }
      display("Processing $name");
      global $temporary;
      if(!ftpDownload($temporary,$name))
      {
         continue;
      }
      parsePage($temporary,$name);
   }
   while(!(next($content) === false));

   reset($content);
   do
   {
      $name= current($content);
      $ext=Path::getExtension($name);
      if($ext!=false)
      {
         continue;
      }
      $currdir=ftp_pwd($connection);
      if(@ftp_chdir($connection,$name))
      {
         global $DISPDIR;
         if($DISPDIR)
         {
            echo "\n$currdir/$name ";
         }
         ftpCheck($name);
                  @ftp_chdir($connection,"..");
         global $DEBUG;
         if($DEBUG)
         {
            echo "Return to", " ", ftp_pwd($connection), "\n";
         }
      }
   }
   while(!(next($content) === false));

   return;
}

function ftpProcess($ftpdir)
{
   if(syncConnect()===false)
   {
      return;
   }
      global $connection;
   @ftp_chdir($connection,"www");
   echo "Working ";
   global $DISPDIR;
   if($DISPDIR)
   {
      echo "\nroot ";
   }
   ftpCheck($ftpdir);
   echo "\n";
   syncDisconnect();
   return;
}

function usage()
{
   echo "\n";
   echo "Adsense Hacking Checker (c) 2007 Scriptol.com - Freeware.", "\n";
   echo "---------------------------------------------------------", "\n";
   echo "Check the Adsense codes on your website.", "\n";
   echo "Syntax:", "\n";
   echo "  solp adheck [options] -llogin -ppassword ftpadr", "\n";
   echo "Options:", "\n";
   echo "  -v verbose, display more infos.", "\n";
   echo "  -q quiet, display nothing.", "\n";
   echo "  -n display the number of ads in the page.", "\n";
   echo "  -s display sub-directories.", "\n";
   echo "  -ddirectory pass the remote sub-directory", "\n";
   echo "  -furl pass url if not in ftp.domain.tld format", "\n";
   echo "Arguments:", "\n";
   echo "  -ppassword.", "\n";
   echo "  -llogin.", "\n";
   echo "  ftpadr: remote ftp address (as ftp.scriptol.com)", "\n";
   echo "You will be prompted for omitted arguments.", "\n";
   exit(0);
   return;
}

function processCommand($argnum,$arguments)
{
   $opt="";
   $remotedir="";
   if($argnum<2)
   {
      usage();
   }
   reset($arguments);
   do
   {
      $param= current($arguments);
      if(strlen($param)>1)
      {
         $opt=substr($param,0,2);
      }
      else
      {
         usage();
      }
      if($opt==="-v")
      {
         global $VERBOSE;
         $VERBOSE=true;
         continue;
      }
      if($opt==="-q")
      {
         global $QUIET;
         $QUIET=true;
         continue;
      }
      if($opt==="-n")
      {
         global $DISPNUM;
         $DISPNUM=true;
         continue;
      }
      if($opt==="-s")
      {
         global $DISPDIR;
         $DISPDIR=true;
         continue;
      }
      if($opt==="-u")
      {
         global $DEBUG;
         $DEBUG=true;
         continue;
      }
      if($opt==="-p")
      {
         global $pass;
         $pass=substr($param,2);
         if($pass ==false)
         {
            die("-p must be followed by the password.");
         }
         continue;
      }
      if($opt==="-l")
      {
         global $user;
         $user=substr($param,2);
         if($user ==false)
         {
            die("-l must be followed by the login.");
         }
         continue;
      }
      if($opt==="-d")
      {
         $remotedir=substr($param,2);
         global $REMODE;
         $REMODE=true;
         if($remotedir ==false)
         {
            die("-d requires a sub-directory.");
         }
         continue;
      }
      if($opt==="-f")
      {
         global $server;
         $server=substr($param,2);
         global $REMODE;
         $REMODE=true;
         if($server ==false)
         {
            die("-f requires a sub-directory.");
         }
         continue;
      }
      if($opt{0}==="-")
      {
         die("$opt unknow command.");
      }
      if(substr($param,0,4)==="ftp.")
      {
         global $server;
         $server=$param;
         global $REMODE;
         $REMODE=true;
         continue;
      }
      echo "Unknown command $param", "\n";
      usage();
   }
   while(!(next($arguments) === false));

   global $user;
   if($user ==false)
   {
            echo "Login: ";
      $fp=fopen("php://stdin","r");
      $user=rtrim(fgets($fp,65536));
      fclose($fp);
   }
   if($user ==false)
   {
      exit(0);
   }
   global $pass;
   if($pass ==false)
   {
            echo "Password: ";
      $fp=fopen("php://stdin","r");
      $pass=rtrim(fgets($fp,65536));
      fclose($fp);
   }
   if($pass ==false)
   {
      exit(0);
   }
   global $server;
   if($server ==false)
   {
            echo "FTP adress:";
      $fp=fopen("php://stdin","r");
      $server=rtrim(fgets($fp,65536));
      fclose($fp);
   }
   if($server ==false)
   {
      exit(0);
   }
   global $params;
   $params["server"]=$server;
   $params["user"]=$user;
   $params["pass"]=$pass;
   $params["remdir"]=$remotedir;

   return;
}

function main($argc,$argv)
{
   $x=array_slice($argv,1);
   $remdir="";
   processCommand($argc,$x);
   global $server;
   global $params;
   $server=$params["server"];
   global $user;
   $user=$params["user"];
   global $pass;
   $pass=$params["pass"];
   $remdir=$params["remdir"];

   global $QUIET;
   if(!$QUIET)
   {
      echo "Adsence Hacking Checker - Freeware by Scriptol.com", "\n";
      global $VERBOSE;
      if($VERBOSE===true)
      {
         echo "Verbose mode enabled.", "\n";
      }
      global $DEBUG;
      if($DEBUG===true)
      {
         echo "Debug mode enabled.", "\n";
      }
      global $DISPNUM;
      if($DISPNUM===true)
      {
         echo "Number of ads will be displayed.", "\n";
      }
      global $REMODE;
      if($REMODE===true)
      {
         echo "Remote directory $remdir.", "\n";
      }
      echo "FTP address $server", "\n";
   }
   global $log;
   $log=fopen("acheck.log","w");
   ftpProcess($remdir);
   fclose($log);
   if($QUIET)
   {
      return 0;
   }
   echo "List of Adsense code found:", "\n";
   global $codeList;
   reset($codeList);
   do
   {
      $a= current($codeList);
      print_r($a);
      echo "\n";
   }
   while(!(next($codeList) === false));

   return 0;
}

main(intVal($argc),$argv);

?>
Return current item: Adsense Checker