Skip to content

Commit cb461c0

Browse files
ChristianGriegerChristianGrieger
ChristianGrieger
authored and
ChristianGrieger
committed
Its now possible to choose between reCaptcha and the soon coming reCaptchabv2 + fixed some bugs
1 parent e2d0607 commit cb461c0

17 files changed

+65
-30
lines changed

Diff for: config.php

100644100755
+6-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@
4444
// "both": check both the IP and coins address in the payout history.
4545
"user_check" => "both",
4646

47-
"captcha" => "recaptcha",
47+
"use_captcha" => true, // require the user to enter a captcha
48+
49+
"captcha" => "recaptcha", // valid options: recaptcha, recaptcha2
50+
51+
"captcha_https" => false, // use https (only for recaptcha2) valid options: true, false
4852

4953
// enter your private and public reCAPTCHA key here:
50-
"captcha_config" => array(
54+
"captcha_config" => array(
5155
"private_key" => "privatekey",
5256
"public_key" => "publickey"
5357
),

Diff for: cron/run.php

100644100755
File mode changed.

Diff for: css/bootstrap.min.css

100644100755
File mode changed.

Diff for: css/default.css

100644100755
File mode changed.

Diff for: faucet.sql

100644100755
File mode changed.

Diff for: index.php

100644100755
File mode changed.

Diff for: js/bootstrap.min.js

100644100755
File mode changed.

Diff for: lib/index.php

100644100755
File mode changed.

Diff for: lib/jsonRPCClient.php

100644100755
File mode changed.

Diff for: lib/proxy_filter/config.php

100644100755
File mode changed.

Diff for: lib/proxy_filter/cron/tor.php

100644100755
File mode changed.

Diff for: lib/proxy_filter/proxy_filter.php

100644100755
File mode changed.

Diff for: lib/recaptchalib.php

100644100755
File mode changed.

Diff for: lib/recaptchalib2.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/*
3+
* Cryptocurrency faucet script
4+
* You are completely free to use/modify this script in any way. Credit is not required.
5+
*/
6+
7+
// this is a re-implementation of recaptchalib.php so it can easily be swapped out.
8+
9+
$this->add_head('<script src="http'.($this->config("captcha_https")?'s':'').'://www.google.com/recaptcha/api.js"></script>');
10+
11+
function recaptcha_check_answer($secret,$response_code,$use_https = false)
12+
{
13+
$response = file_get_contents('http'.($use_https?'s':'').'://www.google.com/recaptcha/api/siteverify?secret='.urlencode($secret).'&response='.urlencode($response_code));
14+
if ($response)
15+
{
16+
$response = json_decode($response,true);
17+
return (@$response["success"] === true);
18+
}
19+
return false;
20+
}
21+
22+
function recaptcha_get_html($sitekey)
23+
{
24+
return '<div class="g-recaptcha" data-sitekey="'.htmlentities($sitekey).'"></div>';
25+
}
26+
?>

Diff for: lib/simple_faucet.php

+25-10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class simple_faucet
1616

1717
protected $balance = 0;
1818

19+
protected $header = '';
20+
1921

2022
public function __construct($config)
2123
{
@@ -66,6 +68,8 @@ public function __construct($config)
6668

6769
if ($this->config["captcha"] == "recaptcha")
6870
require_once('./lib/recaptchalib.php');
71+
elseif ($this->config["captcha"] == "recaptcha2")
72+
require_once('./lib/recaptchalib2.php');
6973

7074
if (isset($config["rpc_user"],$config["rpc_password"],$config["rpc_host"],$config["rpc_port"],$config["mysql_user"],$config["mysql_password"],$config["mysql_host"],$config["mysql_database"]))
7175
{
@@ -190,6 +194,11 @@ public function __construct($config)
190194
$this->status = SF_STATUS_FAUCET_INCOMPLETE; // missing some settings
191195
}
192196

197+
public function add_head($h)
198+
{
199+
$this->header .= $h;
200+
}
201+
193202
public function render()
194203
{
195204
if (!file_exists("./templates/".$this->config["template"].".template.php"))
@@ -200,14 +209,15 @@ public function render()
200209

201210
$self = $this;
202211
$db = $this->db;
212+
$header = $this->header;
203213
$status = $this->status;
204214
$config = $this->config;
205215
$balance = $this->balance;
206216
$payout_amount = $this->payout_amount;
207217
$payout_address = $this->payout_address;
208218
$promo_payout_amount = $this->promo_payout_amount;
209219

210-
$template = preg_replace_callback("/\{\{([a-zA-Z-0-9\ \_]+?)\}\}/",function($match) use ($self,$db,$status,$config,$balance,$payout_amount,$payout_address,$promo_payout_amount)
220+
$template = preg_replace_callback("/\{\{([a-zA-Z-0-9\ \_]+?)\}\}/",function($match) use ($self,$db,$header,$status,$config,$balance,$payout_amount,$payout_address,$promo_payout_amount)
211221
{
212222
switch (strtolower($match[1]))
213223
{
@@ -219,8 +229,10 @@ public function render()
219229
case "title":
220230
return isset($config[strtolower($match[1])]) ? $config[strtolower($match[1])] : $match[1];
221231

232+
case "head":
233+
return $header;
222234

223-
case"coinname":
235+
case "coinname":
224236
return $config["coinname"];
225237

226238
case "balance":
@@ -282,13 +294,12 @@ public function render()
282294
// CAPTCHA:
283295

284296
case "captcha":
285-
if ($config["captcha"] == "recaptcha")
286-
return recaptcha_get_html(@$config["captcha_config"]["public_key"]);
287-
return isset($_SESSION['captcha']) ? '<img src="'.$_SESSION['captcha']["image_src"].'" alt="[captcha]"/>' : '';
288-
//return isset($_SESSION['captcha']) ? '<img src="'.htmlentities($_SESSION['captcha']["image_src"]).'" alt="[captcha]"/>' : '';
289-
290-
case "captcha_url":
291-
return isset($_SESSION['captcha']) ? $_SESSION['captcha']["image_src"] : '';
297+
if ($config["use_captcha"])
298+
{
299+
if ($config["captcha"] == "recaptcha" || $config["captcha"] == "recaptcha2")
300+
return recaptcha_get_html(@$config["captcha_config"]["public_key"]);
301+
}
302+
return '';
292303

293304
default:
294305
return $match[1];
@@ -331,12 +342,16 @@ public function payout_aggregate($function = "AVG")
331342

332343
protected function valid_captcha()
333344
{
345+
if (!$this->config["use_captcha"])
346+
return true;
334347
if ($this->config["captcha"] == "recaptcha")
335348
{
336349
$resp = @recaptcha_check_answer($this->config["captcha_config"]["private_key"],$_SERVER["REMOTE_ADDR"],@$_POST["recaptcha_challenge_field"],@$_POST["recaptcha_response_field"]);
337350
return $resp->is_valid; // $resp->error;
338351
}
339-
return @$_POST["captcha_code"] == @$_SESSION['captcha']['code'];
352+
else
353+
return recaptcha_check_answer($this->config["captcha_config"]["private_key"],@$_POST["g-recaptcha-response"],$this->config["captcha_https"]);
354+
return false;
340355
}
341356

342357
protected function stage_payment($address,$amount)

Diff for: templates/default.template.php

100644100755
+8-18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
2020
<![endif]-->
2121

22+
{{HEAD}}
23+
2224
<title>{{TITLE}}</title>
2325

2426
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
@@ -44,26 +46,14 @@
4446
</div>
4547
<div class="panel-body">
4648
<span>Balance:</span>
47-
<span class="highlight">{{BALANCE}}</span> {{COINNAME}}<br>
48-
Already paid:<span class="highlight" >
49-
<?php
50-
mysql_connect($this->config['mysql_host'],$this->config['mysql_user'],$this->config['mysql_password']);
51-
mysql_select_db($this->config['mysql_database']);
52-
$erg = mysql_query ("SELECT SUM(payout_amount + promo_payout_amount) as anzahl FROM sf_payouts");
53-
$result = mysql_fetch_array($erg);
54-
$result = $result["anzahl"];
55-
$result = round($result,8);
56-
echo $result;
57-
?>
58-
59-
60-
</span> with <span class="highlight" >{{NUMBER_OF_PAYOUTS}}</span> payouts<br><br>
49+
<span class="highlight">{{BALANCE}}</span> {{COINNAME}}<br/>
50+
Already paid:<span class="highlight" >{{TOTAL_PAYOUT}}</span> with <span class="highlight" >{{NUMBER_OF_PAYOUTS}}</span> payouts<br/><br/>
6151

62-
How many payments are currently staged: <span class="highlight" >{{STAGED_PAYMENT_COUNT}}</span> payments.<br>
52+
How many payments are currently staged: <span class="highlight" >{{STAGED_PAYMENT_COUNT}}</span> payments.<br/>
6353

64-
How many payments are left before they are executed: <span class="highlight" >{{STAGED_PAYMENTS_LEFT}}</span> payments.<br>
54+
How many payments are left before they are executed: <span class="highlight" >{{STAGED_PAYMENTS_LEFT}}</span> payments.<br/>
6555

66-
Payments will be done after <span class="highlight" >{{STAGED_PAYMENT_THRESHOLD}}</span> staged payments or automated hourly.<br><br>
56+
Payments will be done after <span class="highlight" >{{STAGED_PAYMENT_THRESHOLD}}</span> staged payments or automated hourly.<br/><br/>
6757
You can get free {{COINNAME}} every hour.
6858
</div>
6959
</div>
@@ -136,7 +126,7 @@
136126
<h3 class="panel-title">Status</h3>
137127
</div>
138128
<div class="panel-body">
139-
Success! You have been awarded with {{PAYOUT_AMOUNT}} {{COINNAME}}!<br>
129+
Success! You have been awarded with {{PAYOUT_AMOUNT}} {{COINNAME}}!<br/>
140130
Additionally, you received a bonus of {{PROMO_PAYOUT_AMOUNT}} {{COINNAME}}!
141131
</div>
142132
</div>

Diff for: templates/index.php

100644100755
File mode changed.

0 commit comments

Comments
 (0)