Welcome, Guest!!
follow us on... rss

Author Topic: Code Samples  (Read 11593 times)

Mike

  • Administrator
  • Sr. Member
  • *****
  • Posts: 300
    • View Profile
Code Samples
« on: January 30, 2009, 11:30:34 AM »
This thread will contain code samples written and contributed by BotScout users. If you'd like to post some code here, please let us know.
« Last Edit: January 30, 2009, 11:42:37 AM by Mike »
Please don't PM me for assistance- post your questions in the forum where others can see them.

Mike

  • Administrator
  • Sr. Member
  • *****
  • Posts: 300
    • View Profile
Re: Code Samples
« Reply #1 on: January 30, 2009, 11:42:51 AM »
*** DEPRECATED CODE ***
Use the code update in the post below this one that makes use of the "MULTI" query.

Code written and provided by MysteryFCM:
Code: [Select]
// *********************************************************************************
// BEGIN CHECK BOTSCOUT
// *********************************************************************************
//
// Check the e-mail address against BotScout
//
if($mail !='' && $sBSAPI !=''){
$bFoundMatch=false;
$fspamcheck = getURL('http://botscout.com/test/?key='.$sBSAPI.'&mail='.$mail);
if (strpos($fspamcheck, '! ') !==False) {
$bFoundMatch = false;
echo 'Error: '.$fspamcheck;
}else{
if (strpos($fspamcheck, 'Y|') !==False) {
$bFoundMatch = true;
}
}
if($bFoundMatch==true){
$bsspambot = true;
} // End if($bsxml->appears == 'Y') (Email)
} // End If

//
// Now check the IP
//
if($ip !='' && $sBSAPI !=''){
$bFoundMatch=false;
$fspamcheck = getURL('http://botscout.com/test/?key='.$sBSAPI.'&ip='.$ip);
if (strpos($fspamcheck, '! ') !==False) {
$bFoundMatch = false;
echo 'Error: '.$fspamcheck;
}else{
if (strpos($fspamcheck, 'Y|') !==False) {
$bFoundMatch = true;
}
}
if($bFoundMatch==true){
$bsspambot = true;
} // End if($bsxml->appears == 'Y') (IP)
       } // End If

//
// Lets check the username
//
if($name !='' && $sBSAPI !=''){
$bFoundMatch=false;
$fspamcheck = getURL('http://botscout.com/test/?key='.$sBSAPI.'&name='.$name);
if (strpos($fspamcheck, '! ') !==False) {
$bFoundMatch = false;
echo 'Error: '.$fspamcheck;
}else{
if (strpos($fspamcheck, 'Y|') !==False) {
$bFoundMatch = true;
}
}
if($bFoundMatch==true){
               $bsspambot = true;
} // End if($bsxml->appears == 'Y') (username)
} // End If

if($bsspambot == true){
$spambot = true; // Required seperately now that dumping to a text file is optional
echo 'BotScout ';
}
// *********************************************************************************
// END CHECK BOTSCOUT
// *********************************************************************************


getURL is a function I wrote that allows determination of whether to use cURL or file_get_contents;

Code:

function getURL($sURL){
if(function_exists('file_get_contents')){
// Use file_get_contents
$sURLTemp = file_get_contents($sURL);
}else{
// Use cURL (if available)
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $sURL);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$sURLTemp = curl_exec($curl);
curl_close($curl);
}
return $sURLTemp;
}
« Last Edit: June 18, 2009, 10:21:20 AM by Mike »
Please don't PM me for assistance- post your questions in the forum where others can see them.

MysteryFCM

  • Moderator
  • Full Member
  • *****
  • Posts: 200
    • View Profile
    • I.T. Mate
Re: Code Samples
« Reply #2 on: June 17, 2009, 10:02:36 PM »
PHP function for checking BotScout, generously provided by MysteryFCM

This code uses the "MULTI" query, which is the preferred (recommended)
way to run queries against the BotScout database.


Code: [Select]
// *********************************************************************************
// BEGIN CHECK BOTSCOUT
// *********************************************************************************
//
// Check the username etc against BotScout. Done using a single query for efficiency
// as we don't need multiple queries for the plain version.
//
// If any of the values are missing, BotScout will ignore them (better for us as it
// prevents us having to deal with them, which thus prevents spammers potentially
// abusing it)
//
public function CheckBotScout($sBSMail, $sBSIP, $sBSName){
$sBSAPI = ''; // YOUR API KEY HERE
$bFoundMatch=false;
// What do you want to base your match on?
//
// 1,2 = Match if username AND IP are listed
// 1,3 = Match if username and Email are listed
// 2,3 = Match if IP and Email are listed
//
// You can use more than one at a time if required, by seperating them with |, for example;
//
// $sBaseMatch = '1,2|2,3';
//
$sBaseMatch = '';
$sBSURL = 'http://botscout.com/test/?multi&key='.$sBSAPI.'&mail='.$sBSMail.'&ip='.$sBSIP.'&name='.$sBSName;
$fspamcheck = getURL($sBSURL);
// BotScout error codes begin with an apostrophe, so we'll check for those first
if (strpos($fspamcheck, '! ') !==False) {
$bFoundMatch = false; // If an error is returned, we can't determine if it was a hit or miss, so default to miss
echo 'Error: '.$fspamcheck;
}else{
// $sSpamData[3] = IP
// $sSpamData[5] = Email
// $sSpamData[7] = Username
if($_GET['debug']=='1'){echo 'SENT: '.$sBSURL.'RECEIVED: '.$fspamcheck.'<br>';}
$sSpamData = explode('|',$fspamcheck);
if($sSpamData[0] == 'Y'){
switch($BaseMatch){
case "1,2": // Match username and IP
if($sSpamData[7] > 0 && $sSpamData[3] > 0){$bFoundMatch = true;}else{$bFoundMatch = false;}
break;
case "1,3": // Match username and E-mail
if($sSpamData[7] > 0 && $sSpamData[5] > 0){$bFoundMatch = true;}else{$bFoundMatch = false;}
break;
case "2,3": // Match IP and E-mail
if($sSpamData[3] > 0 && $sSpamData[5] > 0){$bFoundMatch = true;}else{$bFoundMatch = false;}
break;
case "1,2|1,3": // Match username and IP OR username + E-mail
if($sSpamData[7] > 0 && $sSpamData[3] > 0 || $sSpamData[7] > 0 && $sSpamData[5] > 0){$bFoundMatch = true;}else{$bFoundMatch = false;}
break;
case "1,2|1,3|2,3": // Match username and IP OR username + E-mail OR IP + E-mail
if($sSpamData[7] > 0 && $sSpamData[3] > 0 || $sSpamData[7] > 0 && $sSpamData[5] > 0 || $sSpamData[3] > 0 && $sSpamData[5] > 0){$bFoundMatch = true;}else{$bFoundMatch = false;}
break;
case "1,2|2,3": // Match username and IP OR IP + E-mail
if($sSpamData[7] > 0 && $sSpamData[3] > 0 || $sSpamData[3] > 0 && $sSpamData[5] > 0){$bFoundMatch = true;}else{$bFoundMatch = false;}
break;
case "1,3|2,3": // Match username and Email OR IP + E-mail
if($sSpamData[7] > 0 && $sSpamData[5] > 0 || $sSpamData[3] > 0 && $sSpamData[5] > 0){$bFoundMatch = true;}else{$bFoundMatch = false;}
break;
case "1,2,3": // Match Username, IP and E-mail
if($sSpamData[7] > 0 && $sSpamData[3] > 0 && $sSpamData[5] > 0){$bFoundMatch = true;}else{$bFoundMatch = false;}
break;
default:
$bFoundMatch = true; break;
} // End Switch
}else{
$bFoundMatch = false;
} // End if($sSpamData[0] ...
} // End if (strpos($fspamcheck, '! ') !==False)
if($bFoundMatch==true){
return 'TRUE';
}else{
return 'FALSE';
} // End if($bFoundMatch==true)
}
// *********************************************************************************
// END CHECK BOTSCOUT
// *********************************************************************************
« Last Edit: June 18, 2009, 10:25:00 AM by Mike »
Regards
Steven Burn
I.T. Mate / hpHosts
it-mate.co.uk / hosts-file.net