├── functions ├── logs │ └── sent ├── .htaccess ├── classes │ ├── coinbase │ │ ├── Coinbase │ │ │ ├── ApiException.php │ │ │ ├── ConnectionException.php │ │ │ ├── TokensExpiredException.php │ │ │ ├── Authentication.php │ │ │ ├── SimpleApiKeyAuthentication.php │ │ │ ├── Exception.php │ │ │ ├── OAuthAuthentication.php │ │ │ ├── ApiKeyAuthentication.php │ │ │ ├── Requestor.php │ │ │ ├── ca-coinbase.crt │ │ │ ├── OAuth.php │ │ │ ├── Rpc.php │ │ │ └── Coinbase.php │ │ └── Coinbase.php │ ├── coinbaseapi.php │ ├── template.php │ ├── selectapi.php │ ├── log.php │ ├── coinarea.php │ └── configuration.php ├── footer.php ├── header.php ├── loader.php └── recaptchalib.php ├── assets └── style.css ├── README.md ├── terms.php ├── index.php └── LICENSE /functions/logs/sent: -------------------------------------------------------------------------------- 1 | 0 -------------------------------------------------------------------------------- /functions/.htaccess: -------------------------------------------------------------------------------- 1 | Order deny,allow 2 | Deny from all 3 | -------------------------------------------------------------------------------- /functions/classes/coinbase/Coinbase/ApiException.php: -------------------------------------------------------------------------------- 1 | _apiKey = $apiKey; 10 | } 11 | 12 | public function getData() 13 | { 14 | $data = new stdClass(); 15 | $data->apiKey = $this->_apiKey; 16 | return $data; 17 | } 18 | } -------------------------------------------------------------------------------- /assets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | width: 800px; 3 | margin: auto; 4 | } 5 | 6 | h1 { 7 | margin-top: 0px; 8 | margin-left: 5px; 9 | } 10 | 11 | h1 a { 12 | color: black; 13 | text-decoration: none; 14 | } 15 | 16 | #content { 17 | border: 1px solid black; 18 | margin: 5px; 19 | } 20 | 21 | #footer { 22 | border: 1px dotted black; 23 | text-align:center; 24 | margin:5px; 25 | } 26 | 27 | .errormsg { 28 | border: 1px solid red; 29 | background-color: #FFFFF; 30 | color: red; 31 | margin: 5px; 32 | padding: 5px; 33 | } -------------------------------------------------------------------------------- /functions/classes/coinbase/Coinbase/Exception.php: -------------------------------------------------------------------------------- 1 | http_code = $http_code; 9 | $this->response = $response; 10 | } 11 | 12 | public function getResponse() 13 | { 14 | return $this->response; 15 | } 16 | 17 | public function getHttpCode() 18 | { 19 | return $this->http_code; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /functions/classes/coinbase/Coinbase/OAuthAuthentication.php: -------------------------------------------------------------------------------- 1 | _oauth = $oauth; 11 | $this->_tokens = $tokens; 12 | } 13 | 14 | public function getData() 15 | { 16 | $data = new stdClass(); 17 | $data->oauth = $this->_oauth; 18 | $data->tokens = $this->_tokens; 19 | return $data; 20 | } 21 | } -------------------------------------------------------------------------------- /functions/footer.php: -------------------------------------------------------------------------------- 1 | load('configuration'); 7 | ?> 8 | 9 | 11 | 12 | -------------------------------------------------------------------------------- /functions/classes/coinbase/Coinbase/ApiKeyAuthentication.php: -------------------------------------------------------------------------------- 1 | _apiKey = $apiKey; 11 | $this->_apiKeySecret = $apiKeySecret; 12 | } 13 | 14 | public function getData() 15 | { 16 | $data = new stdClass(); 17 | $data->apiKey = $this->_apiKey; 18 | $data->apiKeySecret = $this->_apiKeySecret; 19 | return $data; 20 | } 21 | } -------------------------------------------------------------------------------- /functions/classes/coinbaseapi.php: -------------------------------------------------------------------------------- 1 | load('configuration'); 9 | require_once('functions/classes/coinbase/Coinbase.php'); 10 | $this->provider = Coinbase::withApiKey($config->api_key(), $config->api_secret()); 11 | } 12 | 13 | function __call($method, $args) { 14 | // Temp fix for an issue, for some reason this gets nested in an array. 15 | $args = $args[0]; 16 | return $this->provider->$method($args[0], $args[1]); 17 | } 18 | 19 | } 20 | ?> -------------------------------------------------------------------------------- /functions/header.php: -------------------------------------------------------------------------------- 1 | load('template'); 6 | $config = $loader->load('configuration'); 7 | ?> 8 | 9 | 10 | 11 | <?php 12 | $curtitle = $template->getTitle(true); 13 | echo $config->faucet_name().' - '.$curtitle; 14 | ?> 15 | 16 | 17 |
18 |

faucet_name(); ?>

19 | -------------------------------------------------------------------------------- /functions/loader.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /functions/classes/coinbase/Coinbase/Requestor.php: -------------------------------------------------------------------------------- 1 | $statusCode, "body" => $response ); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /functions/classes/coinbase/Coinbase.php: -------------------------------------------------------------------------------- 1 | header() to easily display the header. 5 | // Other than that it allows for the page title to function, which is useful too. 6 | class template { 7 | 8 | function __construct() { 9 | require_once('functions/loader.php'); 10 | $loader = new loader(); 11 | $config = $loader->load('configuration'); 12 | if ($config->debug_mode()) { 13 | // Show warnings and errors. 14 | error_reporting(E_ERROR | E_WARNING); 15 | } else { 16 | // Hide all errors, warnings, notices, etc from view of public. 17 | error_reporting(0); 18 | } 19 | } 20 | 21 | function header() { 22 | require_once('functions/header.php'); 23 | } 24 | 25 | function footer() { 26 | require_once('functions/footer.php'); 27 | } 28 | 29 | function getTitle($string) { 30 | $titles = array('index.php' => 'Home', 31 | 'terms.php' => 'Terms of Service'); 32 | $raw = explode('/', $_SERVER['PHP_SELF']); 33 | $script = $raw[count($raw)-1]; 34 | if ($string) { 35 | return $titles[$script]; 36 | } else { 37 | return $titles; 38 | } 39 | } 40 | 41 | } 42 | ?> 43 | -------------------------------------------------------------------------------- /functions/classes/selectapi.php: -------------------------------------------------------------------------------- 1 | load('configuration'); 29 | switch($config->api_provider()) { 30 | 31 | case 'coinbase': 32 | $this->provider = $loader->load('coinbaseapi'); 33 | break; 34 | 35 | default: 36 | echo '
The API provided is not valid, please set up a valid API provider in the configuration.
'; 37 | $this->provider = new fakeapi(); 38 | break; 39 | 40 | } 41 | } 42 | 43 | // This calls the provider set in __construct and lets the actual API class handle it. 44 | function __call($method, $args) { 45 | return $this->provider->$method($args); 46 | } 47 | 48 | } 49 | ?> -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Starter Faucet 2 | ============= 3 | 4 | Starter Faucet is an open-source faucet coin giveaway script. It aims to allow people to set up faucets with ease and allow them to be easily maintained and used. 5 | 6 | Getting Started 7 | ============= 8 | 9 | To get started and set up Starter Faucet all you have to do is to first upload all of the files, then you have to edit "configuration.php" which can be found inside the functions/classes. Once you open that file read what to put where. Also make sure that you give the site a good test before making it live, and keeping all of that information secure. 10 | 11 | Requirements 12 | ============= 13 | 14 | * API Key (Coinbase) 15 | * Webhost which supports PHP 16 | * (Optional but recommended) reCAPTCHA private / public key 17 | 18 | Updates 19 | ============= 20 | 21 | There are still some ideas I have but I am not sure when or if they will be included, any issues or suggestions feel free to make a request here. 22 | 23 | Plans 24 | ============= 25 | 26 | I am not sure when (or even if I will) next update this project, but I do have some plans which could be possible in the future. 27 | 28 | * More API Providers, this is something which is a high priority, especially if it enables additional cryptocurrencies. 29 | * Allow a leaderboard of top donations, this would allow the top donators to be listed automatically. 30 | 31 | About the project 32 | ============= 33 | 34 | Starter Faucet is open source, this means that anyone can review the code, fork their own changes, and / or merge them into the master branch. The license is GPL 2, more information can be found in the LICENSE file which can be used to see what is allowed to be used with the script. I will keep a best effort to keep the code updated, bug free, add new features and provide basic support. 35 | 36 | It was also made to be fully function without using any database software, which elimiates a lot of hassle of setting up tables, users, permissions, etc. But you still have to do a few configuration options (located: functions/classes/configuration.php). 37 | 38 | Thanks, hope you enjoy using Starter Faucet! -------------------------------------------------------------------------------- /functions/classes/log.php: -------------------------------------------------------------------------------- 1 | load('configuration'); 14 | $this->logpath = $config->log_path(); 15 | } 16 | 17 | function saveLog($name, $value) { 18 | file_put_contents($this->logpath.$name, $value); 19 | } 20 | 21 | function getLog($name) { 22 | // This prevents some trickery, such as trying to put "../" or similar. 23 | // Although it should be impossible to send this a value (as it gets the IP). 24 | if (substr($value, 0, 1) != '.') { 25 | if (file_exists($this->logpath.$name)) { 26 | return file_get_contents($this->logpath.$name); 27 | } 28 | } 29 | return false; 30 | } 31 | 32 | // This checks the IP to the wait period in place, to make sure they are not trying to make requests too quick. 33 | // It checks to see if the file exists or if the time in the file is more than the current wait period. 34 | function checkIP() { 35 | $time = time(); 36 | require_once('functions/loader.php'); 37 | $loader = new loader(); 38 | $config = $loader->load('configuration'); 39 | $ip = $_SERVER[$config->ip_forward()]; 40 | $log = $this->getLog($ip); 41 | // This checks to see if the log with the wait_period is within time. 42 | // Or if the log does not exist (meaning the IP address has never recieved funds from us. 43 | if (empty($log) || $log + $config->wait_period() < $time) { 44 | return true; 45 | } 46 | } 47 | 48 | // This saves in the logs to say that the user has received their funds at this time. 49 | function logIP() { 50 | $time = time(); 51 | require_once('functions/loader.php'); 52 | $loader = new loader(); 53 | $config = $loader->load('configuration'); 54 | $ip = $_SERVER[$config->ip_forward()]; 55 | $this->saveLog($ip, $time); 56 | } 57 | } 58 | ?> -------------------------------------------------------------------------------- /functions/classes/coinarea.php: -------------------------------------------------------------------------------- 1 | load('configuration'); 14 | $this->key = $config->api_key(); 15 | $this->coin = $config->coin_code(); 16 | } 17 | 18 | // This function is made to allow calling of the API easier. 19 | // It handles formatting the correct array data with correct key names. 20 | // It does not have all of the API functions supported by CoinArea, but that does not matter. 21 | // For one we are only using these two, and second if you wanted to use the others it can! 22 | // Okay, so it can also use coin_info (as it requires no args) and also generate_address (but without address or label support). 23 | function __call($method, $args) { 24 | switch($method) { 25 | case 'get_balance': 26 | $data = array('address' => $args[0]); 27 | break; 28 | 29 | case 'send_funds': 30 | $data = array('address' => $args[0], 'amount' => $args[1]); 31 | break; 32 | } 33 | 34 | return $this->sendRequest($method, $data); 35 | } 36 | 37 | // This sends the request to the CoinArea API, it supports both Curl (preferred) and GET using file_get_contents. 38 | function sendRequest($method, $data) { 39 | $url = 'http://www.coinarea.org/api/v1/'.$method; 40 | // Add the API key and coin code into the request. 41 | $data = array_merge(array('key' => $this->key, 'coin' => $this->coin), $data); 42 | // Check to see if Curl is enabled. 43 | if (function_exists('curl_version')) { 44 | $json = json_encode($data); 45 | $ch = curl_init($url); 46 | curl_setopt($ch, CURLOPT_POST, true); 47 | curl_setopt($ch, CURLOPT_POSTFIELDS, $json); 48 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 49 | curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: '.strlen($json))); 50 | $result = curl_exec($ch); 51 | curl_close($ch); 52 | return json_decode($result, true); 53 | // Curl is not enabled, we will just use file_get_contents GET request. 54 | } else { 55 | $urlquery = $url.'?'.http_build_query($data); 56 | $result = file_get_contents($urlquery); 57 | return json_decode($result, true); 58 | } 59 | } 60 | 61 | } 62 | ?> 63 | -------------------------------------------------------------------------------- /functions/classes/coinbase/Coinbase/ca-coinbase.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDtzCCAp+gAwIBAgIQDOfg5RfYRv6P5WD8G/AwOTANBgkqhkiG9w0BAQUFADBl 3 | MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 4 | d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJv 5 | b3QgQ0EwHhcNMDYxMTEwMDAwMDAwWhcNMzExMTEwMDAwMDAwWjBlMQswCQYDVQQG 6 | EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNl 7 | cnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgQ0EwggEi 8 | MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCtDhXO5EOAXLGH87dg+XESpa7c 9 | JpSIqvTO9SA5KFhgDPiA2qkVlTJhPLWxKISKityfCgyDF3qPkKyK53lTXDGEKvYP 10 | mDI2dsze3Tyoou9q+yHyUmHfnyDXH+Kx2f4YZNISW1/5WBg1vEfNoTb5a3/UsDg+ 11 | wRvDjDPZ2C8Y/igPs6eD1sNuRMBhNZYW/lmci3Zt1/GiSw0r/wty2p5g0I6QNcZ4 12 | VYcgoc/lbQrISXwxmDNsIumH0DJaoroTghHtORedmTpyoeb6pNnVFzF1roV9Iq4/ 13 | AUaG9ih5yLHa5FcXxH4cDrC0kqZWs72yl+2qp/C3xag/lRbQ/6GW6whfGHdPAgMB 14 | AAGjYzBhMA4GA1UdDwEB/wQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQW 15 | BBRF66Kv9JLLgjEtUYunpyGd823IDzAfBgNVHSMEGDAWgBRF66Kv9JLLgjEtUYun 16 | pyGd823IDzANBgkqhkiG9w0BAQUFAAOCAQEAog683+Lt8ONyc3pklL/3cmbYMuRC 17 | dWKuh+vy1dneVrOfzM4UKLkNl2BcEkxY5NM9g0lFWJc1aRqoR+pWxnmrEthngYTf 18 | fwk8lOa4JiwgvT2zKIn3X/8i4peEH+ll74fg38FnSbNd67IJKusm7Xi+fT8r87cm 19 | NW1fiQG2SVufAQWbqz0lwcy2f8Lxb4bG+mRo64EtlOtCt/qMHt1i8b5QZ7dsvfPx 20 | H2sMNgcWfzd8qVttevESRmCD1ycEvkvOl77DZypoEd+A5wwzZr8TDRRu838fYxAe 21 | +o0bJW1sj6W3YQGx0qMmoRBxna3iw/nDmVG3KwcIzi7mULKn+gpFL6Lw8g== 22 | -----END CERTIFICATE----- 23 | -----BEGIN CERTIFICATE----- 24 | MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh 25 | MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 26 | d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD 27 | QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT 28 | MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j 29 | b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG 30 | 9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB 31 | CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97 32 | nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt 33 | 43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P 34 | T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4 35 | gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO 36 | BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR 37 | TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw 38 | DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr 39 | hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg 40 | 06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF 41 | PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls 42 | YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk 43 | CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4= 44 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /terms.php: -------------------------------------------------------------------------------- 1 | load('template'); 8 | $config = $loader->load('configuration'); 9 | $template->header(); 10 | ?> 11 |

Using Our Service

12 |

You agree that using our service is free of charge, and it costs nothing. faucet_name(); ?> is supported revenue such as donations or advertisements. 13 | We will never require you to pay to receive funds in your wallet, and nobody will ever ask you to part with any money. 14 | Due to the nature of this service and it being free we cannot guarentee uptime or be outage free.

15 |

Providing Donations

16 |

When you provide a donation you are gifting money to the service, these funds go into the faucets pool which allows other members to receive free coins. 17 | All donations are non-reversable and are a one time payment, however donations may be returned in certain circumstances by the sole decision of faucet_name(); ?>.

18 |

Our service is to improve coin_name(); ?>

19 |

Our goal is to provide the coin_name(); ?> community with free coins to allow newbies to get started. 20 | While we do not discourage anyone using our service we have a wait period after receiving funds, this is prevent users from withdrawing all of their funds to their account.

21 |

Open Source

22 |

The code used by faucet_name(); ?> is open source, this means that nothing is hidden and anybody can review the code. 23 | The code was created by BlameByte, and the 24 | source code is called Starter Faucet. Feel free to modify it as you please

25 |

Stored information

26 |

We store minimal information about you, the only information we store is your IP address. We store this purely to prevent multiple transactions and other abuses of our services.

27 |

Proxies, VPNs, or other IP changing actions

28 |

Please do not use any service or website as an attempt to abuse faucet_name(); ?>, not only are you hurting us you are also hurting coin_name(); ?>. 29 | The reason how is that we provide a service to allow people to receive coin_name(); ?> which enables newbies to get started.

30 | footer(); 32 | ?> -------------------------------------------------------------------------------- /functions/classes/coinbase/Coinbase/OAuth.php: -------------------------------------------------------------------------------- 1 | _clientId = $clientId; 12 | $this->_clientSecret = $clientSecret; 13 | $this->_redirectUri = $redirectUri; 14 | } 15 | 16 | public function createAuthorizeUrl($scope) 17 | { 18 | $url = "https://coinbase.com/oauth/authorize?response_type=code" . 19 | "&client_id=" . urlencode($this->_clientId) . 20 | "&redirect_uri=" . urlencode($this->_redirectUri) . 21 | "&scope=" . $scope; 22 | 23 | foreach(func_get_args() as $key => $scope) 24 | { 25 | if(0 == $key) { 26 | // First scope was already appended 27 | } else { 28 | $url .= "+" . urlencode($scope); 29 | } 30 | } 31 | 32 | return $url; 33 | } 34 | 35 | public function refreshTokens($oldTokens) 36 | { 37 | return $this->getTokens($oldTokens["refresh_token"], "refresh_token"); 38 | } 39 | 40 | public function getTokens($code, $grantType='authorization_code') 41 | { 42 | $postFields["grant_type"] = $grantType; 43 | $postFields["redirect_uri"] = $this->_redirectUri; 44 | $postFields["client_id"] = $this->_clientId; 45 | $postFields["client_secret"] = $this->_clientSecret; 46 | 47 | if("refresh_token" === $grantType) { 48 | $postFields["refresh_token"] = $code; 49 | } else { 50 | $postFields["code"] = $code; 51 | } 52 | 53 | $curl = curl_init(); 54 | curl_setopt($curl, CURLOPT_POST, 1); 55 | curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postFields)); 56 | curl_setopt($curl, CURLOPT_URL, 'https://coinbase.com/oauth/token'); 57 | curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/ca-coinbase.crt'); 58 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 59 | curl_setopt($curl, CURLOPT_HTTPHEADER, array('User-Agent: CoinbasePHP/v1')); 60 | 61 | $response = curl_exec($curl); 62 | $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 63 | 64 | if($response === false) { 65 | $error = curl_errno($curl); 66 | $message = curl_error($curl); 67 | curl_close($curl); 68 | throw new Coinbase_ConnectionException("Could not get tokens - network error " . $message . " (" . $error . ")"); 69 | } 70 | if($statusCode !== 200) { 71 | throw new Coinbase_ApiException("Could not get tokens - code " . $statusCode, $statusCode, $response); 72 | } 73 | curl_close($curl); 74 | 75 | try { 76 | $json = json_decode($response); 77 | } catch (Exception $e) { 78 | throw new Coinbase_ConnectionException("Could not get tokens - JSON error", $statusCode, $response); 79 | } 80 | 81 | return array( 82 | "access_token" => $json->access_token, 83 | "refresh_token" => $json->refresh_token, 84 | "expire_time" => time() + 7200 ); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | load('selectapi'); 8 | $template = $loader->load('template'); 9 | $config = $loader->load('configuration'); 10 | $log = $loader->load('log'); 11 | $balance = $api->getBalance(); 12 | if (isset($_GET['next'])) { 13 | $useraddr = $_POST['address']; 14 | $terms = $_POST['terms']; 15 | if (!empty($terms) && !empty($terms)) { 16 | if ($config->enable_captcha()) { 17 | require_once('functions/recaptchalib.php'); 18 | $resp = recaptcha_check_answer($config->recaptcha_private_key(), $_SERVER['REMOTE_ADDR'], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); 19 | if ($resp->is_valid) { 20 | $continue = true; 21 | } 22 | } else { 23 | $continue = true; 24 | } 25 | if ($continue) { 26 | $amount = $config->faucet_amount(); 27 | if ($balance >= $amount) { 28 | if ($log->checkIP()) { 29 | $send = $api->sendMoney($useraddr, $amount); 30 | if ($send->success) { 31 | $sent = $log->getLog('sent'); 32 | // This updates the log to show how much is sent. 33 | $log->saveLog('sent', $sent + $amount); 34 | // Update the log to put the wait period in place. 35 | $this->logIP(); 36 | // Unset the variables to clear the form. 37 | unset($useraddr); 38 | unset($amount); 39 | $msg = 'Successful, you should see the funds in your wallet shortly.'; 40 | } else { 41 | $msg = 'Your funds were unable to be sent, please try again later.'; 42 | } 43 | } else { 44 | $msg = 'Please wait more time to request more funds.'; 45 | } 46 | } else { 47 | $msg = 'There are currently not enough funds in the faucet.'; 48 | } 49 | } else { 50 | $msg = 'The captcha is incorrect, please try again.'; 51 | } 52 | } else { 53 | $msg = 'Please fill out the address and agree to the terms of service.'; 54 | } 55 | } 56 | $template->header(); 57 | if (isset($msg)) { 58 | echo '
'.$msg.'
'; 59 | } 60 | echo '
61 | '; 62 | if ($config->show_balance()) { 63 | echo ''; 64 | if (empty($balance) || is_nan($balance)) { 65 | $balance = 'Unknown'; 66 | } 67 | echo ''; 68 | } else { 69 | echo ''; 70 | } 71 | if (!empty($_POST['terms'])) { 72 | $checked = ' checked="checked"'; 73 | } 74 | echo ' 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | '; 83 | if ($config->enable_captcha()) { 84 | require_once('functions/recaptchalib.php'); 85 | echo ' 86 | 87 | 88 | '; 89 | } 90 | echo ' 91 | 92 | 93 | 94 | 95 |
'.$config->coin_name().' Balance:'.$balance.' '.$config->coin_code().'
'.$config->coin_name().' Address:
Terms of Service
'.recaptcha_get_html($config->recaptcha_public_key()).'
'; 96 | $template->footer(); 97 | ?> 98 | -------------------------------------------------------------------------------- /functions/classes/coinbase/Coinbase/Rpc.php: -------------------------------------------------------------------------------- 1 | _requestor = $requestor; 11 | $this->_authentication = $authentication; 12 | } 13 | 14 | public function request($method, $url, $params) 15 | { 16 | // Create query string 17 | $queryString = http_build_query($params); 18 | $url = Coinbase::API_BASE . $url; 19 | 20 | // Initialize CURL 21 | $curl = curl_init(); 22 | $curlOpts = array(); 23 | 24 | // HTTP method 25 | $method = strtolower($method); 26 | if ($method == 'get') { 27 | $curlOpts[CURLOPT_HTTPGET] = 1; 28 | if ($queryString) { 29 | $url .= "?" . $queryString; 30 | } 31 | } else if ($method == 'post') { 32 | $curlOpts[CURLOPT_POST] = 1; 33 | $curlOpts[CURLOPT_POSTFIELDS] = $queryString; 34 | } else if ($method == 'delete') { 35 | $curlOpts[CURLOPT_CUSTOMREQUEST] = "DELETE"; 36 | if ($queryString) { 37 | $url .= "?" . $queryString; 38 | } 39 | } else if ($method == 'put') { 40 | $curlOpts[CURLOPT_CUSTOMREQUEST] = "PUT"; 41 | $curlOpts[CURLOPT_POSTFIELDS] = $queryString; 42 | } 43 | 44 | // Headers 45 | $headers = array('User-Agent: CoinbasePHP/v1'); 46 | 47 | $auth = $this->_authentication->getData(); 48 | 49 | // Get the authentication class and parse its payload into the HTTP header. 50 | $authenticationClass = get_class($this->_authentication); 51 | switch ($authenticationClass) { 52 | case 'Coinbase_OAuthAuthentication': 53 | // Use OAuth 54 | if(time() > $auth->tokens["expire_time"]) { 55 | throw new Coinbase_TokensExpiredException("The OAuth tokens are expired. Use refreshTokens to refresh them"); 56 | } 57 | 58 | $headers[] = 'Authorization: Bearer ' . $auth->tokens["access_token"]; 59 | break; 60 | 61 | case 'Coinbase_ApiKeyAuthentication': 62 | // Use HMAC API key 63 | $microseconds = sprintf('%0.0f',round(microtime(true) * 1000000)); 64 | 65 | $dataToHash = $microseconds . $url; 66 | if (array_key_exists(CURLOPT_POSTFIELDS, $curlOpts)) { 67 | $dataToHash .= $curlOpts[CURLOPT_POSTFIELDS]; 68 | } 69 | $signature = hash_hmac("sha256", $dataToHash, $auth->apiKeySecret); 70 | 71 | $headers[] = "ACCESS_KEY: {$auth->apiKey}"; 72 | $headers[] = "ACCESS_SIGNATURE: $signature"; 73 | $headers[] = "ACCESS_NONCE: $microseconds"; 74 | break; 75 | 76 | case 'Coinbase_SimpleApiKeyAuthentication': 77 | // Use Simple API key 78 | // Warning! This authentication mechanism is deprecated 79 | $headers[] = 'Authorization: api_key ' . $auth->apiKey; 80 | break; 81 | 82 | default: 83 | throw new Coinbase_ApiException("Invalid authentication mechanism"); 84 | break; 85 | } 86 | 87 | // CURL options 88 | $curlOpts[CURLOPT_URL] = $url; 89 | $curlOpts[CURLOPT_HTTPHEADER] = $headers; 90 | $curlOpts[CURLOPT_CAINFO] = dirname(__FILE__) . '/ca-coinbase.crt'; 91 | $curlOpts[CURLOPT_RETURNTRANSFER] = true; 92 | 93 | // Do request 94 | curl_setopt_array($curl, $curlOpts); 95 | $response = $this->_requestor->doCurlRequest($curl); 96 | 97 | // Decode response 98 | try { 99 | $json = json_decode($response['body']); 100 | } catch (Exception $e) { 101 | throw new Coinbase_ConnectionException("Invalid response body", $response['statusCode'], $response['body']); 102 | } 103 | if($json === null) { 104 | throw new Coinbase_ApiException("Invalid response body", $response['statusCode'], $response['body']); 105 | } 106 | if(isset($json->error)) { 107 | throw new Coinbase_ApiException($json->error, $response['statusCode'], $response['body']); 108 | } else if(isset($json->errors)) { 109 | //throw new Coinbase_ApiException(implode($json->errors, ', '), $response['statusCode'], $response['body']); 110 | } 111 | 112 | return $json; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /functions/classes/configuration.php: -------------------------------------------------------------------------------- 1 | api_key() for example. 7 | // It is possible to use getConfig and achieve the same, but using the call function makes it feel more like variables. 8 | // Using call: $config->coin_code(); 9 | // Using getConfig: $config->getConfig('coin_code'); 10 | function __call($method, $args) { 11 | return $this->getConfig($method); 12 | } 13 | 14 | function getConfig($name) { 15 | $configs = array( 16 | // This is where you set which API you want to use, please note that some providers only support certain coins. 17 | // Also remember that we are not liable for any third-party API here, and there is no "official" API provider. 18 | // Which ever you choose you must make sure that you sign up for an account and get an API key to make it work. 19 | // Coinbase.com is a BTC API to use it please input "coinbase", sign up for an API key here: https://coinbase.com/account/api 20 | // Please note that for coinbase when setting up the API key select the HMAC SHA256 option, and the permissions: balance, send. 21 | 'api_provider' => 'API_PROVIDER', 22 | 23 | // Here is where your API key goes, this allow the faucet to send funds and get the balance of the funds in your account. 24 | // If you are using Coinbase API, make sure you put the api secret below, and select: balance, addresses, send. 25 | 'api_key' => 'API_KEY_HERE', 26 | 27 | // This is where you put the API secret, currently this is only required if you use Coinbase. 28 | // If you are not using Coinbase, then just leave this field alone as it is not required. 29 | 'api_secret' => 'API_SECRET_HERE', 30 | 31 | // This is where the name of the coin goes, this value is only displayed to the user and does have to be the exact name. 32 | // For example, we could put "bitcoin", "Bit coin", "bitcoins", or even "mBit". 33 | 'coin_name' => 'Bitcoin', 34 | 35 | // This is the coin currency code. It no longer is required to be correctly formatted. It will be displayed after the balance to indicate. 36 | // This means that you can put it to be similar to the coin_name, for example "bitcoins". 37 | 'coin_code' => 'BTC', 38 | 39 | // This has been disabled for and will no longer be used for now, the reason being is that most sites do not track balance by address. 40 | // This is an optional field, it limits the faucet to use only that address for getting the balance and sending payments. 41 | // It will only send funds which is in that address, this option is recommended and the donation address should be the same. 42 | // It is optional so if you do not want to use it just leave blank, so it looks like: 'faucet_address' => '', 43 | //'faucet_address' => 'FAUCET_ADDRESS', 44 | 45 | // This is the address where you will accept donations into, it does not have to be a CoinArea address. 46 | // It is recommended to use the same address as the address above to avoid the faucet running out of funds. 47 | // You may however choose to receive the funds in another wallet / address, and then transfer the funds to the faucet. 48 | 'donate_address' => 'DONATION_ADDRESS', 49 | 50 | // Here is where you name your faucet, do not try to make it too long as it sets the title and may cause some text to take multiple lines. 51 | // Also the title in the browser will be for example "Starter Faucet - Home" so the "Home" part is added and you do not have to include it. 52 | 'faucet_name' => 'Starter Faucet', 53 | 54 | // This is the amount the faucet will pay the user in the coin provided above, you will probably want to change this especially if you change the coin. 55 | // Remember that you may have to pay a fee to the coin network on funds sent, so take that into consideration when setting the amount below. 56 | 'faucet_amount' => 0.0001, 57 | 58 | // This is the time in seconds which you have to wait until you can enter the same address again to get paid. 59 | // It is required to put a wait time to prevent the same user from attempting to take the entire faucet's pool. 60 | // The default value is 24 hours, which is expressed as 24 (hours) * 60 (minutes) * 60 (seconds). 61 | // To change this value for example to 6 hours, all you would have to do is change 24 to 6 making it 6 * 60 * 60 62 | // If you do not want users to be able to request funds again, then just set it to 0: 'wait_period' => 0, 63 | 'wait_period' => 24 * 60 * 60, 64 | 65 | // If this is enabled the it shows the users the balance left in the faucet, it can be used for both good and bad. 66 | // It can be useful in situations where people see the funds running out and donating to keep the faucet going. 67 | // But at the same time it could be used by someone to see if it is worth trying to exploit the faucet. 68 | // It should be fine to leave enabled, more of preference as it does not pose a security risk by itself. 69 | 'show_balance' => true, 70 | 71 | // This allows you to choose if you want a captcha image to display before they can claim their free coins. 72 | // A captcha is basically an image which is something easy for humans but difficult for robots / automatic bots. 73 | // This is usually a good idea to prevent bots from automatically taking funds from a faucet. 74 | // To use this the recaptcha private and public keys must be correct (otherwise it may be impossible to use the faucet). 75 | 'enable_captcha' => false, 76 | 77 | // This is not required unless you have the captcha enabled you can change the settings above. 78 | // To get a recaptcha private key go here - https://www.google.com/recaptcha/admin/create 79 | // Make sure that you put the public key here and NOT the private key. 80 | 'recaptcha_public_key' => 'RECAPTCHA_PUBLIC_KEY_HERE', 81 | 82 | // This is not required unless you have the captcha enabled you can change the settings above. 83 | // To get a recaptcha private key go here - https://www.google.com/recaptcha/admin/create 84 | // Make sure that you put the private key here and NOT the public key. 85 | 'recaptcha_private_key' => 'RECAPTCHA_PRIVATE_KEY_HERE', 86 | 87 | // This should only be turned on if it is not open to the public or as the name suggests if you are troubleshooting an issue. 88 | // If you are making the site live for others to use this should be disabled, this displays data potentially useful to an attacker. 89 | // It is useful to turn this on in case you are having issues with the script, but not if others are going to be able to view the site. 90 | // It simply displays error imformation and other debugging 91 | 'debug_mode' => true, 92 | 93 | // This is an advanced field, and REMOTE_ADDR should work for most people unless you have a proxy or similar in front. 94 | // This allows you to get the real IP of the visitor, failure to get the real IP means that you will capture the proxy IP. 95 | // That causes problems as it allows people to get multiple rewards without the wait period and others to get nothing. 96 | // If you use CloudFlare then use "HTTP_CF_CONNECTING_IP", if you use CloudFlare this is not an optional step, it is required. 97 | // If you use a load balancer or similar such as nginx proxy, then try using "HTTP_X_FORWARDED_FOR". 98 | // Do not change this value if you are not using a proxy otherwise it will allow users to spoof their IP. 99 | 'ip_forward' => 'REMOTE_ADDR', 100 | 101 | // This is where the logs are stored such as to log the IP address of the user to prevent them from claiming over and over again. 102 | // This should be set to 664 (chmod or uncheck read-only if windows) so it can write, delete, modify. 103 | // The default path should be fine under most certainstances, it is recommended that you use .htaccess to disallow access. 104 | // You can also choose an absolute path or move it out of the public files, but it should be fine here. 105 | 'log_path' => 'functions/logs/' 106 | ); 107 | return $configs[$name]; 108 | } 109 | } 110 | ?> -------------------------------------------------------------------------------- /functions/recaptchalib.php: -------------------------------------------------------------------------------- 1 | $value ) 50 | $req .= $key . '=' . urlencode( stripslashes($value) ) . '&'; 51 | 52 | // Cut the last '&' 53 | $req=substr($req,0,strlen($req)-1); 54 | return $req; 55 | } 56 | 57 | 58 | 59 | /** 60 | * Submits an HTTP POST to a reCAPTCHA server 61 | * @param string $host 62 | * @param string $path 63 | * @param array $data 64 | * @param int port 65 | * @return array response 66 | */ 67 | function _recaptcha_http_post($host, $path, $data, $port = 80) { 68 | 69 | $req = _recaptcha_qsencode ($data); 70 | 71 | $http_request = "POST $path HTTP/1.0\r\n"; 72 | $http_request .= "Host: $host\r\n"; 73 | $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; 74 | $http_request .= "Content-Length: " . strlen($req) . "\r\n"; 75 | $http_request .= "User-Agent: reCAPTCHA/PHP\r\n"; 76 | $http_request .= "\r\n"; 77 | $http_request .= $req; 78 | 79 | $response = ''; 80 | if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) { 81 | die ('Could not open socket'); 82 | } 83 | 84 | fwrite($fs, $http_request); 85 | 86 | while ( !feof($fs) ) 87 | $response .= fgets($fs, 1160); // One TCP-IP packet 88 | fclose($fs); 89 | $response = explode("\r\n\r\n", $response, 2); 90 | 91 | return $response; 92 | } 93 | 94 | 95 | 96 | /** 97 | * Gets the challenge HTML (javascript and non-javascript version). 98 | * This is called from the browser, and the resulting reCAPTCHA HTML widget 99 | * is embedded within the HTML form it was called from. 100 | * @param string $pubkey A public key for reCAPTCHA 101 | * @param string $error The error given by reCAPTCHA (optional, default is null) 102 | * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false) 103 | 104 | * @return string - The HTML to be embedded in the user's form. 105 | */ 106 | function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false) 107 | { 108 | if ($pubkey == null || $pubkey == '') { 109 | die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create"); 110 | } 111 | 112 | if ($use_ssl) { 113 | $server = RECAPTCHA_API_SECURE_SERVER; 114 | } else { 115 | $server = RECAPTCHA_API_SERVER; 116 | } 117 | 118 | $errorpart = ""; 119 | if ($error) { 120 | $errorpart = "&error=" . $error; 121 | } 122 | return ' 123 | 124 | '; 129 | } 130 | 131 | 132 | 133 | 134 | /** 135 | * A ReCaptchaResponse is returned from recaptcha_check_answer() 136 | */ 137 | class ReCaptchaResponse { 138 | var $is_valid; 139 | var $error; 140 | } 141 | 142 | 143 | /** 144 | * Calls an HTTP POST function to verify if the user's guess was correct 145 | * @param string $privkey 146 | * @param string $remoteip 147 | * @param string $challenge 148 | * @param string $response 149 | * @param array $extra_params an array of extra variables to post to the server 150 | * @return ReCaptchaResponse 151 | */ 152 | function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array()) 153 | { 154 | if ($privkey == null || $privkey == '') { 155 | die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create"); 156 | } 157 | 158 | if ($remoteip == null || $remoteip == '') { 159 | die ("For security reasons, you must pass the remote ip to reCAPTCHA"); 160 | } 161 | 162 | 163 | 164 | //discard spam submissions 165 | if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) { 166 | $recaptcha_response = new ReCaptchaResponse(); 167 | $recaptcha_response->is_valid = false; 168 | $recaptcha_response->error = 'incorrect-captcha-sol'; 169 | return $recaptcha_response; 170 | } 171 | 172 | $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", 173 | array ( 174 | 'privatekey' => $privkey, 175 | 'remoteip' => $remoteip, 176 | 'challenge' => $challenge, 177 | 'response' => $response 178 | ) + $extra_params 179 | ); 180 | 181 | $answers = explode ("\n", $response [1]); 182 | $recaptcha_response = new ReCaptchaResponse(); 183 | 184 | if (trim ($answers [0]) == 'true') { 185 | $recaptcha_response->is_valid = true; 186 | } 187 | else { 188 | $recaptcha_response->is_valid = false; 189 | $recaptcha_response->error = $answers [1]; 190 | } 191 | return $recaptcha_response; 192 | 193 | } 194 | 195 | /** 196 | * gets a URL where the user can sign up for reCAPTCHA. If your application 197 | * has a configuration page where you enter a key, you should provide a link 198 | * using this function. 199 | * @param string $domain The domain where the page is hosted 200 | * @param string $appname The name of your application 201 | */ 202 | function recaptcha_get_signup_url ($domain = null, $appname = null) { 203 | return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname)); 204 | } 205 | 206 | function _recaptcha_aes_pad($val) { 207 | $block_size = 16; 208 | $numpad = $block_size - (strlen ($val) % $block_size); 209 | return str_pad($val, strlen ($val) + $numpad, chr($numpad)); 210 | } 211 | 212 | /* Mailhide related code */ 213 | 214 | function _recaptcha_aes_encrypt($val,$ky) { 215 | if (! function_exists ("mcrypt_encrypt")) { 216 | die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed."); 217 | } 218 | $mode=MCRYPT_MODE_CBC; 219 | $enc=MCRYPT_RIJNDAEL_128; 220 | $val=_recaptcha_aes_pad($val); 221 | return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); 222 | } 223 | 224 | 225 | function _recaptcha_mailhide_urlbase64 ($x) { 226 | return strtr(base64_encode ($x), '+/', '-_'); 227 | } 228 | 229 | /* gets the reCAPTCHA Mailhide url for a given email, public key and private key */ 230 | function recaptcha_mailhide_url($pubkey, $privkey, $email) { 231 | if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) { 232 | die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " . 233 | "you can do so at http://www.google.com/recaptcha/mailhide/apikey"); 234 | } 235 | 236 | 237 | $ky = pack('H*', $privkey); 238 | $cryptmail = _recaptcha_aes_encrypt ($email, $ky); 239 | 240 | return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail); 241 | } 242 | 243 | /** 244 | * gets the parts of the email to expose to the user. 245 | * eg, given johndoe@example,com return ["john", "example.com"]. 246 | * the email is then displayed as john...@example.com 247 | */ 248 | function _recaptcha_mailhide_email_parts ($email) { 249 | $arr = preg_split("/@/", $email ); 250 | 251 | if (strlen ($arr[0]) <= 4) { 252 | $arr[0] = substr ($arr[0], 0, 1); 253 | } else if (strlen ($arr[0]) <= 6) { 254 | $arr[0] = substr ($arr[0], 0, 3); 255 | } else { 256 | $arr[0] = substr ($arr[0], 0, 4); 257 | } 258 | return $arr; 259 | } 260 | 261 | /** 262 | * Gets html to display an email address given a public an private key. 263 | * to get a key, go to: 264 | * 265 | * http://www.google.com/recaptcha/mailhide/apikey 266 | */ 267 | function recaptcha_mailhide_html($pubkey, $privkey, $email) { 268 | $emailparts = _recaptcha_mailhide_email_parts ($email); 269 | $url = recaptcha_mailhide_url ($pubkey, $privkey, $email); 270 | 271 | return htmlentities($emailparts[0]) . "...@" . htmlentities ($emailparts [1]); 273 | 274 | } 275 | 276 | 277 | ?> 278 | -------------------------------------------------------------------------------- /functions/classes/coinbase/Coinbase/Coinbase.php: -------------------------------------------------------------------------------- 1 | _authentication = $authentication; 31 | } else { 32 | // Here, $authentication was not a valid authentication object, so 33 | // analyze the constructor parameters and return the correct object. 34 | // This should be considered deprecated, but it's here for backward compatibility. 35 | // In older versions of this library, the first parameter of this constructor 36 | // can be either an API key string or an OAuth object. 37 | if ($tokens !== null) { 38 | $this->_authentication = new Coinbase_OAuthAuthentication($authentication, $tokens); 39 | } else if ($authentication !== null && is_string($authentication)) { 40 | $apiKey = $authentication; 41 | if ($apiKeySecret === null) { 42 | // Simple API key 43 | $this->_authentication = new Coinbase_SimpleApiKeyAuthentication($apiKey); 44 | } else { 45 | $this->_authentication = new Coinbase_ApiKeyAuthentication($apiKey, $apiKeySecret); 46 | } 47 | } else { 48 | throw new Coinbase_ApiException('Could not determine API authentication scheme'); 49 | } 50 | } 51 | 52 | $this->_rpc = new Coinbase_Rpc(new Coinbase_Requestor(), $this->_authentication); 53 | } 54 | 55 | // Used for unit testing only 56 | public function setRequestor($requestor) 57 | { 58 | $this->_rpc = new Coinbase_Rpc($requestor, $this->_authentication); 59 | return $this; 60 | } 61 | 62 | public function get($path, $params=array()) 63 | { 64 | return $this->_rpc->request("GET", $path, $params); 65 | } 66 | 67 | public function post($path, $params=array()) 68 | { 69 | return $this->_rpc->request("POST", $path, $params); 70 | } 71 | 72 | public function delete($path, $params=array()) 73 | { 74 | return $this->_rpc->request("DELETE", $path, $params); 75 | } 76 | 77 | public function put($path, $params=array()) 78 | { 79 | return $this->_rpc->request("PUT", $path, $params); 80 | } 81 | 82 | private function getPaginatedResource($resource, $listElement, $unwrapElement, $page=0, $params=array()) 83 | { 84 | $result = $this->get($resource, array_merge(array( "page" => $page ), $params)); 85 | $elements = array(); 86 | foreach($result->{$listElement} as $element) { 87 | $elements[] = $element->{$unwrapElement}; // Remove one layer of nesting 88 | } 89 | 90 | $returnValue = new stdClass(); 91 | $returnValue->total_count = $result->total_count; 92 | $returnValue->num_pages = $result->num_pages; 93 | $returnValue->current_page = $result->current_page; 94 | $returnValue->{$listElement} = $elements; 95 | return $returnValue; 96 | } 97 | 98 | public function getBalance() 99 | { 100 | return $this->get("account/balance", array())->amount; 101 | } 102 | 103 | public function getReceiveAddress() 104 | { 105 | return $this->get("account/receive_address", array())->address; 106 | } 107 | 108 | public function getAllAddresses($query=null, $page=0, $limit=null) 109 | { 110 | $params = array(); 111 | if ($query !== null) { 112 | $params['query'] = $query; 113 | } 114 | if ($limit !== null) { 115 | $params['limit'] = $limit; 116 | } 117 | return $this->getPaginatedResource("addresses", "addresses", "address", $page, $params); 118 | } 119 | 120 | public function generateReceiveAddress($callback=null, $label=null) 121 | { 122 | $params = array(); 123 | if($callback !== null) { 124 | $params['address[callback_url]'] = $callback; 125 | } 126 | if($label !== null) { 127 | $params['address[label]'] = $label; 128 | } 129 | return $this->post("account/generate_receive_address", $params)->address; 130 | } 131 | 132 | public function sendMoney($to, $amount, $notes=null, $userFee=null, $amountCurrency=null) 133 | { 134 | $params = array( "transaction[to]" => $to ); 135 | 136 | if($amountCurrency !== null) { 137 | $params["transaction[amount_string]"] = $amount; 138 | $params["transaction[amount_currency_iso]"] = $amountCurrency; 139 | } else { 140 | $params["transaction[amount]"] = $amount; 141 | } 142 | 143 | if($notes !== null) { 144 | $params["transaction[notes]"] = $notes; 145 | } 146 | 147 | if($userFee !== null) { 148 | $params["transaction[user_fee]"] = $userFee; 149 | } 150 | 151 | return $this->post("transactions/send_money", $params); 152 | } 153 | 154 | public function requestMoney($from, $amount, $notes=null, $amountCurrency=null) 155 | { 156 | $params = array( "transaction[from]" => $from ); 157 | 158 | if($amountCurrency !== null) { 159 | $params["transaction[amount_string]"] = $amount; 160 | $params["transaction[amount_currency_iso]"] = $amountCurrency; 161 | } else { 162 | $params["transaction[amount]"] = $amount; 163 | } 164 | 165 | if($notes !== null) { 166 | $params["transaction[notes]"] = $notes; 167 | } 168 | 169 | return $this->post("transactions/request_money", $params); 170 | } 171 | 172 | public function resendRequest($id) 173 | { 174 | return $this->put("transactions/" . $id . "/resend_request", array()); 175 | } 176 | 177 | public function cancelRequest($id) 178 | { 179 | return $this->delete("transactions/" . $id . "/cancel_request", array()); 180 | } 181 | 182 | public function completeRequest($id) 183 | { 184 | return $this->put("transactions/" . $id . "/complete_request", array()); 185 | } 186 | 187 | public function createButton($name, $price, $currency, $custom=null, $options=array()) 188 | { 189 | 190 | $params = array( 191 | "name" => $name, 192 | "price_string" => $price, 193 | "price_currency_iso" => $currency 194 | ); 195 | if($custom !== null) { 196 | $params['custom'] = $custom; 197 | } 198 | foreach($options as $option => $value) { 199 | $params[$option] = $value; 200 | } 201 | 202 | return $this->createButtonWithOptions($params); 203 | } 204 | 205 | public function createButtonWithOptions($options=array()) 206 | { 207 | 208 | $response = $this->post("buttons", array( "button" => $options )); 209 | 210 | if(!$response->success) { 211 | return $response; 212 | } 213 | 214 | $returnValue = new stdClass(); 215 | $returnValue->button = $response->button; 216 | $returnValue->embedHtml = "
button->code . "\">
"; 217 | $returnValue->success = true; 218 | return $returnValue; 219 | } 220 | 221 | public function createOrderFromButtonCode($buttonCode) 222 | { 223 | return $this->post("buttons/" . $buttonCode . "/create_order"); 224 | } 225 | 226 | public function createUser($email, $password) 227 | { 228 | return $this->post("users", array( 229 | "user[email]" => $email, 230 | "user[password]" => $password, 231 | )); 232 | } 233 | 234 | public function buy($amount, $agreeBtcAmountVaries=false) 235 | { 236 | return $this->post("buys", array( 237 | "qty" => $amount, 238 | "agree_btc_amount_varies " => $agreeBtcAmountVaries, 239 | )); 240 | } 241 | 242 | public function sell($amount) 243 | { 244 | return $this->post("sells", array( 245 | "qty" => $amount, 246 | )); 247 | } 248 | 249 | public function getContacts($query=null, $page=0, $limit=null) 250 | { 251 | $params = array( 252 | "page" => $page, 253 | ); 254 | if ($query !== null) { 255 | $params['query'] = $query; 256 | } 257 | if ($limit !== null) { 258 | $params['limit'] = $limit; 259 | } 260 | 261 | $result = $this->get("contacts", $params); 262 | $contacts = array(); 263 | foreach($result->contacts as $contact) { 264 | if(trim($contact->contact->email) != false) { // Check string not empty 265 | $contacts[] = $contact->contact->email; 266 | } 267 | } 268 | 269 | $returnValue = new stdClass(); 270 | $returnValue->total_count = $result->total_count; 271 | $returnValue->num_pages = $result->num_pages; 272 | $returnValue->current_page = $result->current_page; 273 | $returnValue->contacts = $contacts; 274 | return $returnValue; 275 | } 276 | 277 | public function getCurrencies() 278 | { 279 | $response = $this->get("currencies", array()); 280 | $result = array(); 281 | foreach ($response as $currency) { 282 | $currency_class = new stdClass(); 283 | $currency_class->name = $currency[0]; 284 | $currency_class->iso = $currency[1]; 285 | $result[] = $currency_class; 286 | } 287 | return $result; 288 | } 289 | 290 | public function getExchangeRate($from=null, $to=null) 291 | { 292 | $response = $this->get("currencies/exchange_rates", array()); 293 | 294 | if ($from !== null && $to !== null) { 295 | return $response->{"{$from}_to_{$to}"}; 296 | } else { 297 | return $response; 298 | } 299 | } 300 | 301 | public function getTransactions($page=0) 302 | { 303 | return $this->getPaginatedResource("transactions", "transactions", "transaction", $page); 304 | } 305 | 306 | public function getOrders($page=0) 307 | { 308 | return $this->getPaginatedResource("orders", "orders", "order", $page); 309 | } 310 | 311 | public function getTransfers($page=0) 312 | { 313 | return $this->getPaginatedResource("transfers", "transfers", "transfer", $page); 314 | } 315 | 316 | public function getBuyPrice($qty=1) 317 | { 318 | return $this->get("prices/buy", array( "qty" => $qty ))->amount; 319 | } 320 | 321 | public function getSellPrice($qty=1) 322 | { 323 | return $this->get("prices/sell", array( "qty" => $qty ))->amount; 324 | } 325 | 326 | public function getTransaction($id) 327 | { 328 | return $this->get("transactions/" . $id, array())->transaction; 329 | } 330 | 331 | public function getOrder($id) 332 | { 333 | return $this->get("orders/" . $id, array())->order; 334 | } 335 | } 336 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------