Re-adding LTC/usd to website ministats header
* Use tickerupdate.php cron to update setting value * Added new configuration variables for ticket updates * Added some missing configuration vars for some URLs
This commit is contained in:
parent
44851cf82b
commit
cdfb074076
36
cronjobs/tickerupdate.php
Executable file
36
cronjobs/tickerupdate.php
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
Copyright:: 2013, Sebastian Grewe
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
// Include all settings and classes
|
||||
require_once('shared.inc.php');
|
||||
|
||||
// Include additional file not set in autoloader
|
||||
require_once(BASEPATH . CLASS_DIR . '/tools.class.php');
|
||||
|
||||
verbose("Running ticket updates\n");
|
||||
if ($aData = $tools->getApi($config['price']['url'], $config['price']['target'])) {
|
||||
if (!$setting->setValue('price', $aData['ticker']['avg']))
|
||||
verbose("ERR Table update failed");
|
||||
} else {
|
||||
verbose("ERR Failed download JSON data from " . $config['price']['url'].$config['price']['target'] . "\n");
|
||||
}
|
||||
|
||||
?>
|
||||
@ -13,4 +13,4 @@ require_once(CLASS_DIR . '/share.class.php');
|
||||
require_once(CLASS_DIR . '/worker.class.php');
|
||||
require_once(CLASS_DIR . '/statistics.class.php');
|
||||
require_once(CLASS_DIR . '/transaction.class.php');
|
||||
require_once(CLASS_DIR . '/settings.class.php');
|
||||
require_once(CLASS_DIR . '/setting.class.php');
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
class Settings {
|
||||
class Setting {
|
||||
public function __construct($debug, $mysqli, $salt) {
|
||||
$this->debug = $debug;
|
||||
$this->mysqli = $mysqli;
|
||||
@ -13,7 +13,7 @@ class Settings {
|
||||
}
|
||||
|
||||
public function getValue($name) {
|
||||
$query = $this->mysqli->prepare("SELECT value FROM $this->table WHERE setting=? LIMIT 1");
|
||||
$query = $this->mysqli->prepare("SELECT value FROM $this->table WHERE name=? LIMIT 1");
|
||||
if ($query) {
|
||||
$query->bind_param('s', $name);
|
||||
$query->execute();
|
||||
@ -26,6 +26,19 @@ class Settings {
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function setValue($name, $value) {
|
||||
$stmt = $this->mysqli->prepare("
|
||||
INSERT INTO $this->table (name, value)
|
||||
VALUES (?, ?)
|
||||
ON DUPLICATE KEY UPDATE value = ?
|
||||
");
|
||||
if ($stmt && $stmt->bind_param('sss', $name, $value, $value) && $stmt->execute())
|
||||
return true;
|
||||
$this->debug->append("Failed to set $name to $value");
|
||||
echo $this->mysqli->error;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$settings = new Settings($debug, $mysqli, SALT);
|
||||
$setting = new Setting($debug, $mysqli, SALT);
|
||||
41
public/include/classes/tools.class.php
Normal file
41
public/include/classes/tools.class.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
// Make sure we are called from index.php
|
||||
if (!defined('SECURITY'))
|
||||
die('Hacking attempt');
|
||||
|
||||
class Tools {
|
||||
public function __construct($debug) {
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch JSON data from an API
|
||||
* @param url string API URL
|
||||
* @param target string API method
|
||||
* @param auth array Optional authentication data to be sent with
|
||||
* @return dec array JSON decoded PHP array
|
||||
**/
|
||||
public function getApi($url, $target, $auth=NULL) {
|
||||
static $ch = null;
|
||||
static $ch = null;
|
||||
if (is_null($ch)) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; BTCE PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_URL, $url . $target);
|
||||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
||||
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
|
||||
// run the query
|
||||
$res = curl_exec($ch);
|
||||
if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
|
||||
$dec = json_decode($res, true);
|
||||
if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
|
||||
return $dec;
|
||||
}
|
||||
}
|
||||
|
||||
$tools = new Tools($debug);
|
||||
@ -21,11 +21,17 @@ define('DEBUG', 0);
|
||||
define('SALT', 'PLEASEMAKEMESOMETHINGRANDOM');
|
||||
|
||||
$config = array(
|
||||
'price' => array(
|
||||
'url' => 'https://btc-e.com/api/2',
|
||||
'target' => '/ltc_usd/ticker'
|
||||
),
|
||||
'website' => array(
|
||||
'name' => 'The Pool',
|
||||
'slogan' => 'Resistance is futile',
|
||||
'email' => 'test@example.com', // Mail address used for notifications
|
||||
),
|
||||
'blockexplorer' => 'http://explorer.litecoin.net/search?q=', // URL for block searches, prefixed to each block number
|
||||
'chaininfo' => 'http://allchains.info', // Link to Allchains for Difficulty information
|
||||
'fees' => 0,
|
||||
'difficulty' => '31', // Target difficulty for this pool as set in pushpoold json
|
||||
'reward' => '50', // Reward for finding blocks, fixed value but changes someday
|
||||
|
||||
@ -23,8 +23,9 @@ $aGlobal = array(
|
||||
'fees' => $config['fees'],
|
||||
'confirmations' => $config['confirmations'],
|
||||
'reward' => $config['reward'],
|
||||
'blockexplorer' => 'http://explorer.litecoin.net/search?q=',
|
||||
'chaininfo' => 'http://allchains.info'
|
||||
'price' => $setting->getValue('price'),
|
||||
'blockexplorer' => $config['blockexplorer'],
|
||||
'chaininfo' => $config['chaininfo']
|
||||
);
|
||||
|
||||
// We don't want these session infos cached
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
<div id="ministats">
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td><li>LTC/usd: {$GLOBAL.price} </li></td>
|
||||
<td><li>Pool Hashrate: {$GLOBAL.hashrate / 1000} MH/s </li></td>
|
||||
<td><li>Pool Sharerate: {$GLOBAL.sharerate} Shares/s </li></td>
|
||||
<td><li>Pool Workers: {$GLOBAL.workers} </li></td>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user