diff --git a/cronjobs/tickerupdate.php b/cronjobs/tickerupdate.php new file mode 100755 index 00000000..b806654d --- /dev/null +++ b/cronjobs/tickerupdate.php @@ -0,0 +1,36 @@ +#!/usr/bin/php +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"); +} + +?> diff --git a/public/include/autoloader.inc.php b/public/include/autoloader.inc.php index 0671a34e..ea16564e 100644 --- a/public/include/autoloader.inc.php +++ b/public/include/autoloader.inc.php @@ -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'); diff --git a/public/include/classes/settings.class.php b/public/include/classes/setting.class.php similarity index 57% rename from public/include/classes/settings.class.php rename to public/include/classes/setting.class.php index 3c8f9dc0..44ef8315 100644 --- a/public/include/classes/settings.class.php +++ b/public/include/classes/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); diff --git a/public/include/classes/tools.class.php b/public/include/classes/tools.class.php new file mode 100644 index 00000000..530316e6 --- /dev/null +++ b/public/include/classes/tools.class.php @@ -0,0 +1,41 @@ +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); diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index f684c2bb..f4b8b245 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -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 diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index c383dfb0..8c7891e6 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -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 diff --git a/public/templates/mmcFE/global/header.tpl b/public/templates/mmcFE/global/header.tpl index 1f08a366..19f1a788 100644 --- a/public/templates/mmcFE/global/header.tpl +++ b/public/templates/mmcFE/global/header.tpl @@ -4,6 +4,7 @@
+ diff --git a/sql/mmcfe_ng_structure.sql b/sql/mmcfe_ng_structure.sql index 6b961382..233e1308 100644 --- a/sql/mmcfe_ng_structure.sql +++ b/sql/mmcfe_ng_structure.sql @@ -3,7 +3,7 @@ -- http://www.phpmyadmin.net -- -- Host: localhost --- Generation Time: May 27, 2013 at 02:39 PM +-- Generation Time: May 29, 2013 at 11:00 AM -- Server version: 5.5.31-0ubuntu0.13.04.1 -- PHP Version: 5.4.9-4ubuntu2 @@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS `blocks` ( PRIMARY KEY (`id`), UNIQUE KEY `height` (`height`,`blockhash`), KEY `time` (`time`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Discovered blocks persisted from Litecoin Service'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Discovered blocks persisted from Litecoin Service'; -- -------------------------------------------------------- @@ -73,9 +73,10 @@ CREATE TABLE IF NOT EXISTS `blocks` ( -- CREATE TABLE IF NOT EXISTS `settings` ( - `setting` varchar(255) NOT NULL, + `name` varchar(255) NOT NULL, `value` varchar(255) DEFAULT NULL, - PRIMARY KEY (`setting`) + PRIMARY KEY (`name`), + UNIQUE KEY `setting` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -98,7 +99,7 @@ CREATE TABLE IF NOT EXISTS `shares` ( KEY `upstream_result` (`upstream_result`), KEY `our_result` (`our_result`), KEY `username` (`username`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -117,7 +118,7 @@ CREATE TABLE IF NOT EXISTS `shares_archive` ( PRIMARY KEY (`id`), UNIQUE KEY `share_id` (`share_id`), KEY `time` (`time`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Archive shares for potential later debugging purposes'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Archive shares for potential later debugging purposes'; -- -------------------------------------------------------- @@ -134,7 +135,7 @@ CREATE TABLE IF NOT EXISTS `statistics_shares` ( PRIMARY KEY (`id`), KEY `account_id` (`account_id`), KEY `block_id` (`block_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -154,7 +155,7 @@ CREATE TABLE IF NOT EXISTS `transactions` ( KEY `block_id` (`block_id`), KEY `account_id` (`account_id`), KEY `type` (`type`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -171,7 +172,7 @@ CREATE TABLE IF NOT EXISTS `workers` ( PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), KEY `account_id` (`account_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  • LTC/usd: {$GLOBAL.price|default:"n/a"}    
  • Pool Hashrate: {$GLOBAL.hashrate / 1000} MH/s    
  • Pool Sharerate: {$GLOBAL.sharerate} Shares/s    
  • Pool Workers: {$GLOBAL.workers}