Ejemplo n.º 1
0
 } else {
     $refbalance = 0;
 }
 $fb = new FaucetBOX($data["apikey"], $data["currency"], $connection_options);
 $address = trim($_POST["address"]);
 if (empty($address)) {
     $ret = array("success" => false, "message" => "Invalid address.", "html" => "<div class=\"alert alert-danger\">Invalid address.</div>");
 } else {
     if (in_array($address, $security_settings["address_ban_list"])) {
         $ret = array("success" => false, "message" => "Unknown error.", "html" => "<div class=\"alert alert-danger\">Unknown error.</div>");
     } else {
         $ret = $fb->send($address, $reward);
     }
 }
 if ($ret["success"] && $refbalance > 0) {
     $ret = $fb->sendReferralEarnings(trim($_POST["address"]), $refbalance);
 }
 if ($ret['success']) {
     setcookie('address', trim($_POST['address']), time() + 60 * 60 * 24 * 60);
     if (array_key_exists('balance', $ret)) {
         $q = $sql->prepare("UPDATE Faucetinabox_Settings SET `value` = ? WHERE `name` = 'balance'");
         if ($data['unit'] == 'satoshi') {
             $data['balance'] = $ret['balance'];
         } else {
             $data['balance'] = $ret['balance_bitcoin'];
         }
         $q->execute(array($data['balance']));
     }
     // handle refs
     // deduce balance
     $q = $sql->prepare("UPDATE Faucetinabox_Refs SET balance = balance - ? WHERE address = ?");
Ejemplo n.º 2
0
 public function index()
 {
     $this->_load_models(['ips', 'addresses', 'refs']);
     //late binding - we only need these models for this function
     //$_SESSION = $_COOKIE = [];    //empty the session and cookie  - for testing
     //pr([$_SESSION , $_COOKIE]);
     //check for referal - check the cookie then the request
     $referral = $this->fw->get('COOKIE.r') ?: $this->fw->get('REQUEST.r');
     if ($referral) {
         $this->fw->set('COOKIE.r', $referral);
         $this->refs->load(["address = ?", $referral]);
         //make sure referral is in db
         if ($this->refs->dry()) {
             //referral not in db yet
             $this->refs->address = $referral;
             $this->refs->save();
         }
     }
     //end - set up referral cookie/session/db
     //set rewards for page
     $rewards = $this->rewards();
     $this->fw->set('rewards', $rewards);
     //set captcha html for page
     $captcha = $this->{"_{$this->site_settings['default_captcha']}"}();
     $this->fw->set('captcha', $captcha);
     //check for form post - give reward (if timer/ip elegible) - timer/ip eligible should be set on page(cookie) - we just double check here for scammers
     if ($data = $this->fw->get('POST.faucet')) {
         if ($data['address']) {
             $this->fw->set('SESSION.address', $data['address']);
             //keep the address in SESSION
             //check the ip and the address for eligible before processing captcha (save bandwidth - catch scammers early)
             $this->ips->recent = "TIMESTAMPDIFF(MINUTE, last_used, CURRENT_TIMESTAMP())";
             //create virtual field
             $this->ips->load(["ip = ?", $this->fw->get('IP')]);
             $this->addresses->recent = "TIMESTAMPDIFF(MINUTE, last_used, CURRENT_TIMESTAMP())";
             //create virtual field
             $this->addresses->load(["address = ?", $data['address']]);
             //pr([$this->ips , $this->addresses]);
             if ($this->ips->recent != '' && $this->ips->recent < $this->site_settings['timer'] || $this->addresses->recent != '' && $this->addresses->recent < $this->site_settings['timer']) {
                 $time_left = $this->site_settings['timer'] - $this->ips->recent;
                 $this->fw->set('SESSION.flash', ['type' => 'warning', 'message' => "It appears your IP or address tried too soon.. please wait {$time_left} minutes..."]);
                 $this->fw->reroute("/faucet");
                 //redirect and bail
             }
             //end - server timer not ready yet - re-directed user
             $captcha_valid = $this->{"_{$this->site_settings['default_captcha']}"}(true);
             //process protected captcha function
             if ($captcha_valid) {
                 $last_used = $this->fw->TIME;
                 //generate reward
                 $total = 0;
                 $roll = number_format(mt_rand() / mt_getrandmax() * 100, 2);
                 //get percentage roll (2 decimal places)
                 foreach ($rewards as $chance) {
                     $total += $chance['chance'];
                     if ($roll <= $total) {
                         $reward = $chance['satoshi'];
                         break;
                     }
                 }
                 //end - get random reward
                 //handle payments - user/ref payments
                 $fb = new FaucetBOX($this->site_settings['api_key'], $this->site_settings['currency']);
                 //now pay the faucet user
                 $this->fb_resp = $fb->send($data['address'], $reward);
                 $msg_type = $this->fb_resp['success'] !== false ? 'success' : 'danger';
                 $message = $this->fb_resp['success'] ? "Congrats - you rolled {$roll} and won {$reward} Satoshi...<br /><a href='/faucet/more'>Get more Satoshi's here...</a>" : "OOPS - " . json_encode($this->fb_resp);
                 //now pay the referral - only if it is not 'self' fererral
                 if (!$this->refs->dry() && $this->refs->address !== $data['address']) {
                     $ref_pay = round($this->site_settings['referral'] * $reward / 100);
                     //only send payment if we have it
                     $balance = $this->site_settings['balance'] * 100000000;
                     //convert BTC balance to satoshi
                     if ($balance > $this->refs->balance + $ref_pay + $reward) {
                         $this->fb_resp = $fb->sendReferralEarnings($this->refs->address, $ref_pay);
                         $message .= $this->fb_resp['success'] ? "and we sent {$ref_pay} to your referrer too..." : "OOPS - " . json_encode($this->fb_resp);
                         $this->refs->balance > 0 ? $this->refs->balance -= $ref_pay : 0;
                         $this->refs->save();
                     } else {
                         $this->refs->balance += $ref_pay;
                         $this->refs->save();
                     }
                     $this->addresses->ref_id = $this->refs->id;
                     //make sure referrer is attahced to this addy
                 }
                 //end - pay referral
                 //update refs / ips / addresses with new timestamps
                 $this->ips->ip = $this->fw->get('IP');
                 $this->ips->last_used = date('Y-m-d H:i:s', $last_used);
                 //convert unix time to timestamp/datetime val
                 $this->ips->save();
                 $this->addresses->address = $data['address'];
                 $this->addresses->last_used = date('Y-m-d H:i:s', $last_used);
                 //convert unix time to timestamp/datetime val
                 $this->addresses->save();
                 //pr([$this->ips , $this->addresses]);
                 //set cookie timers - end_user time and server time for double check
                 $this->fw->mset(['SESSION.u' => $data['time'] + $this->site_settings['timer'] * 60 * 1000, 'SESSION.s' => $last_used + $this->site_settings['timer'] * 60 * 1000, 'SESSION.flash' => ['type' => $msg_type, 'message' => $message]]);
             } else {
                 //put bad captcha/error message here
                 $this->fw->set('SESSION.flash', ['type' => 'warning', 'message' => print_r($this->resp, true)]);
             }
         } else {
             $this->fw->set('SESSION.flash', ['type' => 'warning', 'message' => 'You must enter a valid BTC address...']);
         }
     }
     //end - faucet post
     $this->fw->set('scriptBottom', "/js/faucet.js");
 }