Created
February 16, 2014 22:46
-
-
Save ss23/9041763 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Copyright (c) 2013 Land of Bitcoin http://www.landofbitcoin.com/ | |
// Feel free to modify anything or remove banners as long as you keep the footer line unchanged. | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. | |
// Donations greatly appreciated: 1MiCRoXT5gFtGZLSmW6efAx968WAKvD5xz | |
// INSTALLATION: | |
// 1. Set the config values below. | |
// 2. Upload the index.php and the Microwallet.php files. | |
// 3. Done, ready to use. You can test it with a Bitcoin address, for example with or donate address: 1MiCRoXT5gFtGZLSmW6efAx968WAKvD5xz | |
/*** CONFIG ***/ | |
$faucetName = 'GimmeFreeBtc'; | |
$faucetSlogan = 'Get some free bitcoins '; | |
$faucetSloganBigger = 'every hour!!'; | |
$faucetBackgroundColor = 'white'; | |
$faucetTextColor = '#575757'; | |
$faucetDonateBitcoinAddress = ''; | |
// How often can the users claim rewards in minutes, 180 = every 3 hours | |
$intervalInMinutes = 60; | |
// List of rewards in satoshi, 1 satoshi = 0.00000001 BTC. | |
$rewards = array( | |
100, | |
75, | |
50, | |
); | |
// Display the faucet balance or hide it? true or false | |
$displayFaucetBalance = false; | |
// Enter MySQL infos | |
$mysqlHost = 'HIDDEN'; | |
$mysqlUsername = 'HIDDEN'; | |
$mysqlPassword = 'HIDDEN'; | |
$mysqlDatabase = 'HIDDEN'; | |
// Get your Microwallet API key from here: https://www.microwallet.org/api | |
$microwalletApiKey = 'HIDDEN'; | |
// CHOOSE A CAPTCHA, you need to fill out recaptha API keys for recaptcha OR Solvemedia API keys for Solvemedia captcha, no need to fill out both. | |
// If you choose recaptcha: get your reCAPTCHA API keys from here: https://www.google.com/recaptcha/ | |
$recaptchaPublicKey = 'HIDDEN'; | |
$recaptchaPrivateKey = 'HIDDEN'; | |
// If you choose solvemedia: get your Solve Media API keys here: http://solvemedia.com/publishers/ | |
$solvemediaChallengeKey = ''; | |
$solvemediaVerificationKey = ''; | |
// The HTML is at the end of this file, scroll down, easy to customize. | |
/************************/ | |
/*** APPLICATION CODE ***/ | |
/************************/ | |
error_reporting(0); | |
if (empty($microwalletApiKey) || ((empty($recaptchaPublicKey) || empty($recaptchaPrivateKey)) && (empty($solvemediaChallengeKey) || empty($solvemediaVerificationKey)))) { | |
echo 'Missing API keys, check the settings in the index.php.'; | |
exit; | |
} | |
$db = mysqli_connect($mysqlHost, $mysqlUsername, $mysqlPassword, $mysqlDatabase); | |
if (!$db) { | |
echo 'Can\'t connect to MySQL, check the settings in the index.php. Error: ' . mysqli_connect_error(); | |
exit; | |
} | |
mysqli_set_charset($db, 'latin1'); | |
$result = mysqli_query($db, "select * from microfaucet_settings where name = 'faucet_balance'"); | |
if (!$result && mysqli_errno($db) === 1146) { | |
$query = "DROP TABLE IF EXISTS `microfaucet_settings`"; | |
mysqli_query($db, $query); | |
$query = "CREATE TABLE IF NOT EXISTS `microfaucet_settings` (`id` INT NOT NULL AUTO_INCREMENT, `name` VARCHAR(45) NOT NULL, `value` VARCHAR(45) NOT NULL, PRIMARY KEY (`id`)) ENGINE = MyISAM DEFAULT CHARACTER SET = latin1 COLLATE = latin1_swedish_ci"; | |
mysqli_query($db, $query); | |
$query = "INSERT INTO `microfaucet_settings` (`name`, `value`) VALUES ('faucet_balance', 'N/A|1')"; | |
mysqli_query($db, $query); | |
$query = "DROP TABLE IF EXISTS `microfaucet_users`"; | |
mysqli_query($db, $query); | |
$query = "CREATE TABLE IF NOT EXISTS `microfaucet_users` (`id` INT NOT NULL AUTO_INCREMENT, `username` VARCHAR(45) NOT NULL, `ip` INT NOT NULL, `claimed_at` INT NOT NULL, PRIMARY KEY (`id`), UNIQUE INDEX `username_UNIQUE` (`username` ASC)) ENGINE = MyISAM DEFAULT CHARACTER SET = latin1 COLLATE = latin1_swedish_ci"; | |
mysqli_query($db, $query); | |
header('Location: index.php'); | |
exit; | |
} | |
$time = time(); | |
if ($displayFaucetBalance) { | |
$faucetBalance = mysqli_fetch_assoc($result); | |
list($faucetBalance, $faucetBalanceFetchedAt) = explode('|', $faucetBalance['value']); | |
if ($faucetBalanceFetchedAt + 10 * 60 < $time) { | |
$faucetBalance = @file_get_contents('https://www.microwallet.org/api/v1/balance?api_key=' . rawurlencode($microwalletApiKey)); | |
$faucetBalance = json_decode($faucetBalance); | |
if ($faucetBalance && isset($faucetBalance->balance_bitcoin)) { | |
$faucetBalance = $faucetBalance->balance_bitcoin . ' BTC'; | |
} else { | |
$faucetBalance = 'N/A'; | |
} | |
$escapedValue = mysqli_real_escape_string($db, $faucetBalance . '|' . $time); | |
$query = "update microfaucet_settings set value = '$escapedValue' where name = 'faucet_balance'"; | |
mysqli_query($db, $query); | |
} | |
} | |
$result = ''; | |
$resultHtml = ''; | |
$intervalH = floor($intervalInMinutes / 60); | |
if ($intervalH) { | |
$interval = $intervalH . ' hours'; | |
} | |
$intervalM = $intervalInMinutes - $intervalH * 60; | |
if ($intervalM) { | |
$interval .= ($intervalH ? ' and ' : '') . $intervalM . ' mins'; | |
} | |
$ip = $_SERVER['REMOTE_ADDR']; | |
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
if ($recaptcha) { | |
$captchaChallange = $_POST['recaptcha_challenge_field']; | |
$captchaResponse = $_POST['recaptcha_response_field']; | |
} else { | |
$captchaChallange = $_POST['adcopy_challenge']; | |
$captchaResponse = $_POST['adcopy_response']; | |
} | |
if (!empty($_POST['username']) && !empty($captchaChallange) && !empty($captchaResponse)) { | |
if (!preg_match('/[^A-Za-z0-9\.\+\-\_\@]/', $_POST['username'])) { | |
$escapedUsername = mysqli_real_escape_string($db, $_POST['username']); | |
$escapedIp = mysqli_real_escape_string($db, ip2long($ip)); | |
$\\\\ | |
result = mysqli_query($db, "select * from microfaucet_users where username = '$escapedUsername' or ip = '$escapedIp' order by claimed_at desc"); | |
if ($result) { | |
$row = mysqli_fetch_assoc($result); | |
if ($row === null || $row['claimed_at'] <= time() - ($intervalInMinutes * 60)) { | |
if ($recaptcha) { | |
$response = @file('https://www.google.com/recaptcha/api/verify?privatekey=' . $recaptchaPrivateKey . '&challenge=' . rawurlencode($captchaChallange). '&response=' . rawurlencode($captchaResponse) . '&remoteip=' . $ip); | |
} else { | |
$response = @file('http://verify.solvemedia.com/papi/verify?privatekey=' . $solvemediaVerificationKey . '&challenge=' . rawurlencode($captchaChallange) . '&response=' . rawurlencode($captchaResponse) . '&remoteip=' . $ip); | |
} | |
if (isset($response[0]) && trim($response[0]) === 'true') { | |
$captchaSolved = true; | |
require_once 'Microwallet.php'; | |
$microwallet = new Microwallet($microwalletApiKey); | |
$amount = $rewards[mt_rand(0, count($rewards) - 1)]; | |
$result = $microwallet->send($_POST['username'], $amount); | |
$resultHtml = $result['html']; | |
if ($result['success']) { | |
$escapedClaimedAt = mysqli_real_escape_string($db, time()); | |
$result = mysqli_query($db, "insert into microfaucet_users (username, ip, claimed_at) values ('$escapedUsername', '$escapedIp', '$escapedClaimedAt')"); | |
if (!$result && mysqli_errno($db) === 1062) { | |
mysqli_query($db, "update microfaucet_users set ip = '$escapedIp', claimed_at = '$escapedClaimedAt' where username = '$escapedUsername'"); | |
} | |
} | |
} else { | |
$resultHtml = '<div class="alert alert-danger">Invalid captcha, try again!</div>'; | |
} | |
} else { | |
$waitingTime = ceil(($row['claimed_at'] - (time() - ($intervalInMinutes * 60))) / 60); | |
$resultHtml = '<div class="alert alert-danger">You have to wait ' . $waitingTime . ' minutes before claiming again!</div>'; | |
} | |
} else { | |
$resultHtml = '<div class="alert alert-danger">An error occured.</div>'; | |
} | |
} else { | |
$resultHtml = '<div class="alert alert-danger">Invalid address or username!</div>'; | |
} | |
} else { | |
$resultHtml = '<div class="alert alert-danger">Missing captcha, address or username, try again!</div>'; | |
} | |
} | |
/*******************************/ | |
/*** END OF APPLICATION CODE ***/ | |
/*******************************/ | |
/************/ | |
/*** HTML ***/ | |
/************/ | |
?> | |
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"/> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | |
<title><?php echo htmlspecialchars($faucetName); ?></title> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"> | |
<style> | |
body { | |
background: <?php echo $faucetBackgroundColor; ?>; | |
color: <?php echo $faucetTextColor; ?>; | |
} | |
.alert { | |
font-weight: bold; | |
text-align: center; | |
} | |
.faucet { | |
margin: 20px 0; | |
} | |
h5 { | |
font-weight: bold; | |
} | |
.faucetSlogan{ | |
font-size:20px; | |
} | |
.faucetSloganBigger{ | |
font-size:29px | |
} | |
/* Solvemedia captcha fix. */ | |
#adcopy-outer { | |
-moz-box-sizing: content-box; | |
-webkit-box-sizing: content-box; | |
box-sizing: content-box; | |
} | |
</style> | |
</head> | |
<body> | |
<!--BEGIN ADVERTISING RIGHT--> | |
<img src="your ad here sidebar.png"> | |
<!--END ADVERTISING RIGHT--> | |
<div class="container"> | |
<h1 class="text-center"><?php echo htmlspecialchars($faucetName); ?></h1> | |
<center> | |
<span class="text-center text-muted faucetSlogan"><?php echo htmlspecialchars($faucetSlogan); ?></span> | |
<span class="text-center text-muted faucetSloganBigger"><?php echo htmlspecialchars($faucetSloganBigger); ?></span> | |
</center> | |
<hr /> | |
<div class="row faucet"> | |
<div class="col-sm-3"> | |
<h3 class="text-center">Get the following rewards:</h3> | |
<hr /> | |
<?php foreach ($rewards as $reward): ?> | |
<h5 class="text-center"><?php echo htmlspecialchars($reward); ?> satoshi</h5> | |
<?php endforeach; ?> | |
<hr /> | |
<h5 class="text-center">Get free bitcoins every hour!</h5> | |
<hr /> | |
<!--BEGIN ADVERTISING--> | |
<!--END ADVERTISING--> | |
</div> | |
<div class="col-sm-6"> | |
<?php if (!empty($faucetDonateBitcoinAddress)): ?> | |
<h4 class="text-center">Donate bitcoins to keep the faucet alive:<br /><?php echo htmlspecialchars($faucetDonateBitcoinAddress); ?></h4> | |
<hr /> | |
<?php endif; ?> | |
<!--BEGIN ADVERTISING--> | |
<!--END ADVERTISING--> | |
<hr /> | |
<?php if ($displayFaucetBalance): ?> | |
<h4 class="text-center">Faucet balance: <?php echo htmlspecialchars($faucetBalance); ?></h4> | |
<hr /> | |
<?php endif; ?> | |
<?php echo $resultHtml; ?> | |
<?php if ($captchaSolved): ?> | |
<div class="text-center"><a class="btn btn-primary btn-lg" href="">Reload</a></div> | |
<?php else: ?> | |
<h4 class="text-center">Enter your Bitcoin address, email or <a target="_blank" href="https://www.microwallet.org/">Microwallet.org</a> username</h4> | |
<?php | |
// require sweetcaptcha php sdk, don't forget to set up your credentials first | |
require_once('sweetcaptcha.php'); | |
if (empty($_POST)) { | |
// print sweetcaptcha in your form | |
?> | |
<form action="" method="POST"> | |
<div class="form-group"> | |
<input class="form-control input-lg" type="text" name="username" id="username" value="<?php echo isset($_POST['username']) ? htmlspecialchars($_POST['username']) : ''; ?>" placeholder="Bitcoin address, email or Microwallet.org username" /> | |
</div> | |
<!-- implemet sweetcaptcha --> | |
<?php echo $sweetcaptcha->get_html() ?> | |
<!-- continue with your form --> | |
<input class="form-control input-lg btn-success" type="submit" value="Get free bitcoins!" /> | |
</form> | |
<?php | |
} else { | |
// looks like someone has submitted a form, let's validate it | |
if (isset($_POST['sckey']) and isset($_POST['scvalue']) and $sweetcaptcha->check(array('sckey' => $_POST['sckey'], 'scvalue' => $_POST['scvalue'])) == "true") { | |
// success! your form was validated | |
// do what you like next ... | |
echo "Success! carry on if you will"; | |
} | |
else { | |
// alas! the validation has failed, the user might be a spam bot or just got the result wrong | |
// handle this as you like | |
echo "Boohoo! captcha validation failed!"; | |
} | |
} | |
?> | |
<!--ADVERTISING FOOTER CODE--> | |
<img src="your ad here banner.png"> | |
<center><div><iframe scrolling="no" frameborder="0" src="http://bitcoin-ads.net/gimg.php?id=2920" style="overflow:hidden;width:728px;height:90px;"></iframe></div></center> | |
<!--ADVERTISING FOOTER CODE ENDS--> | |
<hr /> | |
</div> | |
<div class="col-sm-3"> | |
<hr /> | |
</div> | |
</div> | |
<!--footer!--> | |
<!--twitter button--> | |
<center> | |
<a href="https://twitter.com/GimmeFreeBTC" class="twitter-follow-button" data-show-count="false" data-dnt="true">Follow @GimmeFreeBTC</a></center> | |
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> | |
<!--end twitter button--> | |
<p class="text-center"> | |
Email us at <a href="mailto:gimmefreebitcoins@gmail.com">GimmeFreeBitcoins@gmail.com</a><br /> | |
Powered by <a target="_blank" href="https://www.microwallet.org/">Microwallet</a> | |
<!--end footer!--> | |
</div> | |
<!--hit counter--> | |
<span style="position:absolute;right:0px;"> | |
<script type="text/javascript" src="http://counter3.freecounterstat.com/private/counter.js?c=3b4f65239dda17159756d72245af9a60"></script> | |
</span> | |
<!--end hit counter--> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment