AdsCaptcha instead of ReCaptcha

Morus

www.votezone.eu , www.privateserversranking.com
Hi Guys,

I'm using at the moment Recaptcha for gatewat page
http://www.l2.votezone.eu/index.php?a=in&u=Lineage2Network
but I want to change it to AdsCaptcha but i have some difficulities. Any advise?
Below you can see code for /sources/in.php with recaptcha on it
Code:
if (!defined('VISIOLIST')) {
  die("This file cannot be accessed directly.");
}
 
class in extends in_out {
  function in() {
    global $CONF, $DB, $FORM, $TMPL;
 
    if (isset($_SERVER['HTTP_REFERER'])) {
      $referer = $DB->escape($_SERVER['HTTP_REFERER'], 1);
    }
 
    $go_to_rankings = 0;
    if (isset($FORM['a']) && $FORM['a'] == 'in') {
      $go_to_rankings = 1;
      $username = $DB->escape($FORM['u']);
    }
    else {
      // Get user by referer?
      $good_referer = 0;
      if (isset($referer) && !isset($FORM['a']) && strpos($referer, $CONF['list_url']) === FALSE) {
        // Make sure it's not a search engine
        if (strpos($referer, 'http://www.google.com/search') === FALSE && strpos($referer, 'http://search.yahoo.com') === FALSE && strpos($referer, 'http://search.msn.com') === FALSE) {
          $good_referer = 1;
        }
      }
 
      if ($good_referer) {
        $username = $this->get_username($referer);
      }
      else {
        $username = '';
      }
    }
 
    if ($username) {
      list($username_sql) = $DB->fetch("SELECT username FROM {$CONF['sql_prefix']}_sites WHERE username = '{$username}'", __FILE__, __LINE__);
      if ($username_sql == $username) {
        if ($CONF['gateway'] && !isset($FORM['sid'])) {
          $this->gateway($username);
        }
        else {
          if ($CONF['gateway']) {
            $valid = $this->check($username);
          }
          else {
            $valid = 1;
          }
// Recaptcha Mod
require_once($CONF['path'].'/sources/recaptchalib.php');
$privatekey = "MY KEY";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);
 
if (!$resp->is_valid) {
  unset($go_to_rankings);
  unset($valid);
  $TMPL['captcha_error'] = '<div class="error">Captcha was incorrect</div>';
          $this->gateway($username);
}
//
          if ($valid) {
            $this->record($username, 'in');
eval (PluginManager::getPluginManager ()->pluginHooks ('in_valid'));
 
          }
        }
      }
    }
 
    if ($go_to_rankings) {
      header("Location: {$CONF['list_url']}/?a=stats&u=$username");
      exit;
    }
  }
 
 
  function check($username) {
    global $CONF, $FORM;
 
    require_once("{$CONF['path']}/sources/misc/session.php");
    $session = new session;
    list($type, $data) = $session->get($FORM['sid']);
    $session->delete($FORM['sid']);
 
    if ($type == 'gateway' && $data == $username) {
      return 1;
    }
    else {
      return 0;
    }
  }
 
  function gateway($username) {
    global $DB, $LNG, $CONF, $FORM, $TMPL;
 
    require_once("{$CONF['path']}/sources/misc/session.php");
    $session = new session;
    $TMPL['sid'] = $session->create('gateway', $username);
 
    $TMPL['username'] = $username;
 
  // Recaptcha Mod
  require_once($CONF['path'].'/sources/recaptchalib.php');
  $publickey = "MY KEY";
  $TMPL['captcha_code'] = recaptcha_get_html($publickey);
  //
$result = $DB->query("SELECT title FROM {$CONF['sql_prefix']}_sites WHERE username = '{$username}' AND active='1'", __FILE__, __LINE__);
while (list($title) = $DB->fetch_array($result)) {
$TMPL['gateway_title'] = $title;
}
//
eval (PluginManager::getPluginManager ()->pluginHooks ('in_gateway'));
 
    echo $this->do_skin('gateway');
    exit;
  }
 
  function get_username($url) {
    global $CONF, $DB;
 
    $url = $this->short_url($url);
    $count = 0;
 
    $username = '';
    while (!$username) {
      list($username) = $DB->fetch("SELECT username FROM {$CONF['sql_prefix']}_sites WHERE short_url = '{$url}'", __FILE__, __LINE__);
 
      if (!$username) {
        $url = $this->short_url("{$url}.");
      }
 
      $count++;
      if ($count >= 10) {
        $username = 0;
        break;
      }
    }
 
    return $username;
  }
 
  function short_url($url) {
    // Lowercase
    $url = strtolower($url);
 
    // Get rid of www.
    $url = preg_replace('/\/\/www./', '//', $url);
 
    // Get rid of trailing slash
    $url = preg_replace('/\/$/', '', $url);
 
    // Get rid of page after the last slash
    preg_match('/^(http:\/\/.+)\/(.+)/', $url, $matches);
    if (!isset($matches[0])) {
      // Just a domain with a slash at the end
      $url = preg_replace('/^(http:\/\/.+)\//', '\\1', $url);
    }
    else {
      // All other URLs
      // Check to see if after the trailing slash is a file or a directory
      if (strpos($matches[2], '.')) { $url = $matches[1]; }
    }
 
    return $url;
  }
}
?>
And my gateway.html
Code:
<body>
{$wrapper_welcome}
<div id="header">
    <div id="logo"><a href="http://www.votezone.eu/"><img src="/images/votezone_logo.png" width=”300” height=”100” alt="{$list_name}"/></a></div>
<div id="logotext">Lineage 2 VoteZone Ranking Servers</div>
    <div id="headside">
    <div id="headbanner">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-8640561945009743";
/* 468x60, created 11/28/10 */
google_ad_slot = "3562668950";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
 
</div>
    </div>
</div>
 
<div id="gatewrap"><div id="gatewrap2">
    <h1>{$lng->gateway_header}</h1>
 
        <div id="gateway-top">{$gateway_top}</div>
 
        <p class="gatemessage">{$lng->gateway_text}</p><br /><br />
        <center><form method="post" action="{$list_url}/index.php?a=in&amp;u={$username}&amp;sid={$sid}">
  {$captcha_error}
  {$captcha_code}
  <br />
 
<center><font size="4"<b>Vote for:</b><br>{$gateway_title}</font></center>
  <div class="advertleft">
 
 
  <div class="votebox">
 
 
<br>
  <center><input type="image" STYLE="text-align:center; color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 14px; background-color: #72A4D2;" size="14" value="Solve captcha above and click here to vote for {$gateway_title}" class="cssbuttongo" /></center><br /><br /><br />
 
  </div>
 
       
       
 
<a href="{$list_url}/" class="" target=""><span>{$lng->gateway_no_vote}</span></a>
</div></div>
    <center><a href="{$list_url}/"><img src="{$skins_url}/{$skin_name}/images/advert/advert1468x60.png" alt="{$list_name}" /></a></center>
        <div class="floatLeft footerLeft">
</body>
</html>
For adscaptcha example php code you can find below
http://www.adscaptcha.com/Resources.aspx
 

Mark

Administrator
Staff member
adscaptcha integration looks identical to recaptcha, this should be no problem. As soon as I have some time I will take a look at integrating that option, then adding to gateway should be the same as you have done above.
 

Morus

www.votezone.eu , www.privateserversranking.com
I tried to integrate it on the recaptcha basis but i have an error. There is no 2nd line in adscaptcha and also the
{$captcha_error}
{$captcha_code}
 

Mark

Administrator
Staff member
just a heads up, I have just finished the adscaptcha integration and it will be included in 0.7 release :)
 

Mark

Administrator
Staff member
I havent used it personally, but its in 0.7 release so hopefully some users can provide some feedback.
 

Morus

www.votezone.eu , www.privateserversranking.com
I have that file already but what code we need to place in /sources/in.php as the recaptcha example is wrong. as above.
 

Morus

www.votezone.eu , www.privateserversranking.com
I managed to add AdsCaptcha to gateway instead of ReCaptcha. Below you can find a way to do it.
1. Be sure that you have adscaptchalib.php in your sources folder (should be there by default).
Code:
<?php
$ADSCAPTCHA_API = 'api.adscaptcha.com';
   
function GetCaptcha($captchaId, $publicKey) {
    global $ADSCAPTCHA_API;
 
    $dummy = rand(1, 9999999999);
    $urlGet = 'http://api.adscaptcha.com/Get.aspx';
    $urlNoScript = 'http://api.adscaptcha.com/NoScript.aspx';
    $params = "?CaptchaId="  . $captchaId .
              "&PublicKey=" . $publicKey .
              "&Dummy=" . $dummy;
   
    $result  = "<script src='" . $urlGet . $params . "' type='text/javascript'></script>\n";
    $result .= "<noscript>\n";
    $result .= "\t<iframe src='" . $urlNoScript . $params . "' width='300' height='100' frameborder='0'></iframe>\n";
    $result .= "\t<table>\n";
    $result .= "\t<tr><td>Type challenge here:</td><td><input type='text' name='adscaptcha_response_field' value='' /></td></tr>\n";
    $result .= "\t<tr><td>Paste code here:</td><td><input type='text' name='adscaptcha_challenge_field' value='' /></td></tr>\n";
    $result .= "\t</table>\n";
    $result .= "</noscript>\n";
   
    return $result;
}
 
function ValidateCaptcha($captchaId, $privateKey, $challengeValue, $responseValue, $remoteAddress) {
    $ADSCAPTCHA_API = 'api.adscaptcha.com';
    global $ADSCAPTCHA_API;
 
    $host = 'api.adscaptcha.com';
    $path = "/Validate.aspx";
   
    $params = "CaptchaId=" . $captchaId . "&PrivateKey=" . $privateKey . "&ChallengeCode=" . $challengeValue . "&UserResponse=" . $responseValue . "&RemoteAddress=" . $remoteAddress;
       
    $result = HttpPost($host, $path, $params);
 
    return $result;
}
 
function FixEncoding($str) {   
    $curr_encoding = mb_detect_encoding($str) ;
   
    if($curr_encoding == "UTF-8" && mb_check_encoding($str,"UTF-8")) {
        return $str;
    } else {
        return utf8_encode($str);
    }
}
 
function HttpPost($host, $path, $data, $port = 80) {
    $data = FixEncoding($data);
   
    $http_request  = "POST $path HTTP/1.0\r\n";
    $http_request .= "Host: api.adscaptcha.com\r\n";
    $http_request .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $http_request .= "Content-Length: " . strlen($data) . "\r\n";
    $http_request .= "\r\n";
    $http_request .= $data;
 
    $response = '';
    if (($fs = @fsockopen($host, $port, $errno, $errstr, 10)) == false) {
        die ('Could not open socket! ' . $errstr);
    }
   
    fwrite($fs, $http_request);
 
    while (!feof($fs))
        $response .= fgets($fs, 1160);
    fclose($fs);
   
    $response = explode("\r\n\r\n", $response, 2);
    return $response[1];
}
 
?>
2. You'll need to register on http://www.adscaptcha.com/Publisher/StartPage.aspx and insert your API codes from there.
3. Open sources/in.php and find:
Code:
  function in() {
    global $CONF, $DB, $FORM
change it to:
Code:
  function in() {
    global $CONF, $DB, $FORM, $TMPL;
next find:
Code:
          if ($CONF['gateway']) {
            $valid = $this->check($username);
          }
          else {
            $valid = 1;
          }
After, Add: (Insert private key, captchaId where stated)
Code:
// Adscaptcha Mod
  require_once($CONF['path'].'/sources/adscaptchalib.php');
$captchaId  = 'INSERT YOUR CAPTCHA ID';  // Set your captcha id here
$privateKey = 'INSERT YOUR PRIVATE KEY';  // Set your private key here
$challengeValue = $_POST['adscaptcha_challenge_field'];
$responseValue  = $_POST['adscaptcha_response_field'];
$remoteAddress  = $_SERVER["REMOTE_ADDR"];
 
if ("true" == ValidateCaptcha($captchaId, $privateKey, $challengeValue, $responseValue, $remoteAddress))
{
    // Corrent answer, continue with your submission process
} else {
    // Wrong answer, you may display a new AdsCaptcha and add an error message
  $TMPL['captcha_error'] = '<div class="error">Captcha was incorrect</div>';
          $this->gateway($username);
 
}
 
//
find:
Code:
  function gateway($username) {
    global $DB, $LNG, $CONF, $FORM, $TMPL;
 
    require_once("{$CONF['path']}/sources/misc/session.php");
    $session = new session;
    $TMPL['sid'] = $session->create('gateway', $username);
 
    $TMPL['username'] = $username;
add after:
Code:
  // Adscaptcha Mod
  require_once($CONF['path'].'/sources/adscaptchalib.php');
  $captchaId  = 'INSERT YOUR CAPTCHA ID';  // Set your captcha id here
  $publicKey = 'INSERT YOUR PRIVATE KEY';
$TMPL['captcha_code'] = GetCaptcha($captchaId, $publicKey);
Open skins/{your skin}/gateway.html and add code below where you want:
Code:
 {$captcha_error}
  {$captcha_code}
Now you have Adscaptcha up and runing
 

Mark

Administrator
Staff member
thanks for posting that :) we will look in the future of adding an option to the admin panel to put any of the security measures in gateway to avoid having to edit any PHP files directly.
 
B

Blink70v

Guest
Good morning.

Thank you for that link, but I have a problem to integrate it! By completing the captach and I remain on the voting page gateway.
For adscaptcha I get an error code when I copy!
 

Shawn Hagan

Member
that link took me to recapcha.. tried it anyways. i had recaptcha working on the join part. but after following the steps i get
"Gateway Page captchaid-invalid"

on my gateway page. thinking it was the fact i wasnt signed up for adscpatcha i went that route and got its info. ended up with the same..
"Gateway Page captchaid-invalid"

so i went into the admin section thinking well it wasnt in there, maybe i needed to add it there. still....
"Gateway Page captchaid-invalid"

so im lost. any help?
 

leonor

Active Member
License Active
yes with adscaptcha i have also some trouble to integrate, i wait now more then one month for aktivation. I called support and thes say
Code:
We are planning to start addinf new sites to our network by mid next week, hope to add your site
so reg for new page is not realy open.
 

Mark

Administrator
Staff member
ahh Thanks leonor this is good to know, I guess I should not have included adscaptcha in the core quite yet.
 
Top