commit
72207cf246
@ -3,6 +3,7 @@
|
||||
require_once(CLASS_DIR . '/debug.class.php');
|
||||
require_once(CLASS_DIR . '/bitcoin.class.php');
|
||||
require_once(CLASS_DIR . '/statscache.class.php');
|
||||
require_once(CLASS_DIR . '/bitcoinwrapper.class.php');
|
||||
require_once(INCLUDE_DIR . '/database.inc.php');
|
||||
require_once(INCLUDE_DIR . '/smarty.inc.php');
|
||||
// Load classes that need the above as dependencies
|
||||
|
||||
@ -898,6 +898,3 @@ class BitcoinClient extends jsonrpc_client {
|
||||
return $this->query("getaddressesbyaccount", $account);
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-load this class
|
||||
$bitcoin = new BitcoinClient($config['wallet']['type'], $config['wallet']['username'], $config['wallet']['password'], $config['wallet']['host']);
|
||||
|
||||
37
public/include/classes/bitcoinwrapper.class.php
Normal file
37
public/include/classes/bitcoinwrapper.class.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
class BitcoinWrapper extends BitcoinClient {
|
||||
var $type, $username, $password, $host, $memcache;
|
||||
public function __construct($type, $username, $password, $host, $memcache) {
|
||||
$this->type = $type;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
$this->host = $host;
|
||||
$this->memcache = $memcache;
|
||||
return parent::__construct($this->type, $this->username, $this->password, $this->host);
|
||||
}
|
||||
/**
|
||||
* Wrap variouns methods to add caching
|
||||
**/
|
||||
public function getblockcount() {
|
||||
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||
return $this->memcache->setCache(__FUNCTION__, parent::getblockcount());
|
||||
}
|
||||
public function getdifficulty() {
|
||||
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||
return $this->memcache->setCache(__FUNCTION__, parent::getdifficulty());
|
||||
}
|
||||
public function getestimatedtime($iCurrentPoolHashrate) {
|
||||
if ($iCurrentPoolHashrate == 0) return 0;
|
||||
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||
$dDifficulty = parent::getdifficulty();
|
||||
return $this->memcache->setCache(__FUNCTION__, $dDifficulty * pow(2,32) / $iCurrentPoolHashrate);
|
||||
}
|
||||
}
|
||||
|
||||
// Load this wrapper
|
||||
$bitcoin = new BitcoinWrapper($config['wallet']['type'], $config['wallet']['username'], $config['wallet']['password'], $config['wallet']['host'], $memcache);
|
||||
@ -225,6 +225,19 @@ class User {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check API key for authentication
|
||||
* @param key string API key hash
|
||||
* @return bool
|
||||
**/
|
||||
public function checkApiKey($key) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("SELECT api_key FROM $this->table WHERE api_key = ?");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param("s", $key) && $stmt->execute() && $stmt->bind_result($api_key) && $stmt->fetch())
|
||||
return $key === $api_key;
|
||||
return false;
|
||||
}
|
||||
|
||||
private function checkUserPassword($username, $password) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$user = array();
|
||||
|
||||
12
public/include/pages/api.inc.php
Normal file
12
public/include/pages/api.inc.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
// Check for valid API key
|
||||
$user->checkApiKey($_REQUEST['api_key']);
|
||||
|
||||
header('HTTP/1.1 400 Bad Request');
|
||||
die('400 Bad Request');
|
||||
?>
|
||||
24
public/include/pages/api/getblockcount.inc.php
Normal file
24
public/include/pages/api/getblockcount.inc.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
// Check user token
|
||||
$user->checkApiKey($_REQUEST['api_key']);
|
||||
|
||||
if ($bitcoin->can_connect() === true){
|
||||
if (!$iBlock = $memcache->get('iBlock')) {
|
||||
$iBlock = $bitcoin->query('getblockcount');
|
||||
$memcache->set('iBlock', $iBlock);
|
||||
}
|
||||
} else {
|
||||
$iBlock = 0;
|
||||
}
|
||||
|
||||
// Output JSON format
|
||||
echo json_encode(array('getblockcount' => $iBlock));
|
||||
|
||||
// Supress master template
|
||||
$supress_master = 1;
|
||||
?>
|
||||
20
public/include/pages/api/getblocksfound.inc.php
Normal file
20
public/include/pages/api/getblocksfound.inc.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
// Check user token
|
||||
$user->checkApiKey($_REQUEST['api_key']);
|
||||
|
||||
// Set a sane limit, overwrite with URL parameter
|
||||
$iLimit = 10;
|
||||
if (@$_REQUEST['limit'])
|
||||
$iLimit = $_REQUEST['limit'];
|
||||
|
||||
// Output JSON format
|
||||
echo json_encode(array('getblocksfound' => $statistics->getBlocksFound($iLimit)));
|
||||
|
||||
// Supress master template
|
||||
$supress_master = 1;
|
||||
?>
|
||||
15
public/include/pages/api/getcurrentworkers.inc.php
Normal file
15
public/include/pages/api/getcurrentworkers.inc.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
// Check user token
|
||||
$user->checkApiKey($_REQUEST['api_key']);
|
||||
|
||||
// Output JSON format
|
||||
echo json_encode(array('getcurrentworkers' => $worker->getCountAllActiveWorkers()));
|
||||
|
||||
// Supress master template
|
||||
$supress_master = 1;
|
||||
?>
|
||||
25
public/include/pages/api/getdifficulty.inc.php
Normal file
25
public/include/pages/api/getdifficulty.inc.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
// Check user token
|
||||
$user->checkApiKey($_REQUEST['api_key']);
|
||||
|
||||
// Fetch data from litecoind
|
||||
if ($bitcoin->can_connect() === true){
|
||||
if (!$dDifficulty = $memcache->get('dDifficulty')) {
|
||||
$memcache->set('dDifficulty', $dDifficulty);
|
||||
$dDifficulty = $bitcoin->query('getdifficulty');
|
||||
}
|
||||
} else {
|
||||
$iDifficulty = 1;
|
||||
}
|
||||
|
||||
// Output JSON format
|
||||
echo json_encode(array('getdifficulty' => $dDifficulty));
|
||||
|
||||
// Supress master template
|
||||
$supress_master = 1;
|
||||
?>
|
||||
18
public/include/pages/api/getestimatedtime.inc.php
Normal file
18
public/include/pages/api/getestimatedtime.inc.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
// Check user token
|
||||
$user->checkApiKey($_REQUEST['api_key']);
|
||||
|
||||
// Estimated time to find the next block
|
||||
$iCurrentPoolHashrate = $statistics->getCurrentHashrate() * 1000;
|
||||
|
||||
// Output JSON format
|
||||
echo json_encode(array('getestimatedtime' => $bitcoin->getestimatedtime($iCurrentPoolHashrate)));
|
||||
|
||||
// Supress master template
|
||||
$supress_master = 1;
|
||||
?>
|
||||
15
public/include/pages/api/getpoolhashrate.inc.php
Normal file
15
public/include/pages/api/getpoolhashrate.inc.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
// Check user token
|
||||
$user->checkApiKey($_REQUEST['api_key']);
|
||||
|
||||
// Output JSON format
|
||||
echo json_encode(array('getpoolhashrate' => $statistics->getCurrentHashrate()));
|
||||
|
||||
// Supress master template
|
||||
$supress_master = 1;
|
||||
?>
|
||||
15
public/include/pages/api/getpoolsharerate.inc.php
Normal file
15
public/include/pages/api/getpoolsharerate.inc.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
// Check user token
|
||||
$user->checkApiKey($_REQUEST['api_key']);
|
||||
|
||||
// Output JSON format
|
||||
echo json_encode(array('getpoolsharerate' => $statistics->getCurrentShareRate()));
|
||||
|
||||
// Supress master template
|
||||
$supress_master = 1;
|
||||
?>
|
||||
26
public/include/pages/api/gettimesincelastblock.inc.php
Normal file
26
public/include/pages/api/gettimesincelastblock.inc.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
// Check user token
|
||||
$user->checkApiKey($_REQUEST['api_key']);
|
||||
|
||||
// Fetch our last block found
|
||||
$aBlocksFoundData = $statistics->getBlocksFound(1);
|
||||
|
||||
// Time since last block
|
||||
$now = new DateTime( "now" );
|
||||
if (!empty($aBlocksFoundData)) {
|
||||
$dTimeSinceLast = ($now->getTimestamp() - $aBlocksFoundData[0]['time']);
|
||||
} else {
|
||||
$dTimeSinceLast = 0;
|
||||
}
|
||||
|
||||
// Output JSON format
|
||||
echo json_encode(array('gettimesincelastblock' => $dTimeSinceLast));
|
||||
|
||||
// Supress master template
|
||||
$supress_master = 1;
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user