Skip to content

Commit 558fa4a

Browse files
committed
Initial commit
1 parent f80f8d0 commit 558fa4a

File tree

11 files changed

+866
-0
lines changed

11 files changed

+866
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ethOS statistics plugin for WordPress
2+
This plugin connects to your ethOS panel and retrieves all available data about your mining rigs.
3+
4+
After installation, a new widget is available that displays the data that is retrieved from your
5+
ethOS panel, like:
6+
7+
- Total hashrate of your mining farm
8+
- Details about all mining rigs in your farm, like:
9+
- Hashrate
10+
- System uptime
11+
- Mining time
12+
- Amount of miners (GPU's)
13+
- Details of the rig's miners, like:
14+
- Hashrate
15+
- Temperature
16+
17+
To prevent your website from slow loading, caching of the panel's data is enabled by default and
18+
is set to 1 minute. You can change the caching time to fit your need or disable the caching.

ethos-stats-plugin.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Plugin Name: ethOS Statistics
4+
* Plugin URI: https://rutger.kirkels.nl
5+
* Author: Rutger Kirkels
6+
* Version: 1.0
7+
* Description: Plugin for displaying the stats of your ethOS mining rig.
8+
*/
9+
10+
11+
/**
12+
* Include all neccessary classes
13+
*/
14+
include_once __DIR__ . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "EthosStatsWidget.php";
15+
include_once __DIR__ . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "EthosStatsPanel.php";
16+
include_once __DIR__ . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "EthosStatsRig.php";
17+
include_once __DIR__ . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "EthosStatsGpu.php";
18+
19+
/*
20+
* Add actions
21+
*/
22+
add_action('widgets_init', function() {
23+
register_widget('EthosStatsWidget');
24+
});
25+
add_action('admin_menu', 'ethos_stats_settings');
26+
add_action('admin_init', 'ethos_stats_settings_init');
27+
add_action('wp_enqueue_scripts', 'plugin_styles');
28+
29+
/*
30+
* Load translations
31+
*/
32+
load_plugin_textdomain('ethosstats', false, dirname(plugin_basename(__FILE__)) . '/languages/');
33+
34+
function ethos_stats_settings() {
35+
add_options_page('ethOS Statisticsx', 'ethOS Statistics', 'manage_options', 'ethos-stats-settings', 'ethos_stats_settings_page');
36+
}
37+
38+
39+
function ethos_stats_settings_page() {
40+
?>
41+
<div class="wrap">
42+
<h1>ethOS Statistics <?php echo __('settings', 'ethosstats'); ?></h1>
43+
<form method="post" action="options.php">
44+
<?php settings_fields('ethos-stats-settings'); ?>
45+
<?php do_settings_sections('ethos_stats_settings_page');?>
46+
<?php submit_button(); ?>
47+
</form>
48+
</div>
49+
<?php
50+
}
51+
52+
function ethos_stats_settings_init() {
53+
add_settings_section('ethos_stats_main_section', ucfirst(__('default', 'ethosstats')) . ' ' . __('settings', 'ethosstats'), 'ethos_stats_settings_setup', 'ethos_stats_settings_page');
54+
55+
add_settings_field('ethos-stats-panel-id', 'ethOS ' . __('panel','ethosstats') . ' ID:', 'ethos_stats_textbox', 'ethos_stats_settings_page', 'ethos_stats_main_section', ['name' => 'PanelId', 'maxlength' => 6]);
56+
register_setting('ethos-stats-settings','ethos_stats_options');
57+
}
58+
59+
function plugin_styles() {
60+
wp_enqueue_style('EthosStatsStyles', plugins_url('/ethos-stats-plugin/style.css'));
61+
}
62+
function ethos_stats_settings_setup() {
63+
echo __('These default settings are used to connect to your panel', 'ethosstats') . '.';
64+
}
65+
66+
function ethos_stats_textbox($args) {
67+
extract($args);
68+
$optionArray = (array)get_option('ethos_stats_options');
69+
$current_value = $optionArray[$name];
70+
echo '<input type="text" name="ethos_stats_options[' . $name . ']" value="' . $current_value . '"';
71+
echo (isset($maxlength)) ? ' maxlength="' . $maxlength . '"' : '' ;
72+
echo '/>';
73+
}
74+
?>

functions.php

Whitespace-only changes.

languages/ethosstats-nl_NL.mo

1.52 KB
Binary file not shown.

languages/ethosstats-nl_NL.po

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
msgid ""
2+
msgstr ""
3+
"Project-Id-Version: EthosStats\n"
4+
"POT-Creation-Date: 2017-08-02 23:07+0200\n"
5+
"PO-Revision-Date: 2017-08-03 16:31+0200\n"
6+
"Language-Team: \n"
7+
"MIME-Version: 1.0\n"
8+
"Content-Type: text/plain; charset=UTF-8\n"
9+
"Content-Transfer-Encoding: 8bit\n"
10+
"X-Generator: Poedit 2.0.3\n"
11+
"X-Poedit-Basepath: ..\n"
12+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
13+
"X-Poedit-SourceCharset: UTF-8\n"
14+
"Last-Translator: \n"
15+
"Language: nl_NL\n"
16+
"X-Poedit-SearchPath-0: EthosStatsWidget.php\n"
17+
18+
msgid "ethOS Statistics"
19+
msgstr "ethOS Statistieken"
20+
21+
msgid "Display statistics of your ethOS mining rigs"
22+
msgstr "Toon de statistieken van je ethOS mijn-platforms"
23+
24+
msgid "Total hashrate"
25+
msgstr "Totale hashrate"
26+
27+
msgid "Produced by"
28+
msgstr "Geproduceerd door"
29+
30+
msgid "rigs"
31+
msgstr "platforms"
32+
33+
msgid "rig"
34+
msgstr "platform"
35+
36+
msgid "miners"
37+
msgstr "mijners"
38+
39+
msgid "miner"
40+
msgstr "mijner"
41+
42+
msgid "There are currently no rigs mining"
43+
msgstr "Er zijn op dit moment geen platforms aan het minen"
44+
45+
msgid "day"
46+
msgstr "dag"
47+
48+
msgid "days"
49+
msgstr "dagen"
50+
51+
msgid "hours"
52+
msgstr "uren"
53+
54+
msgid "hour"
55+
msgstr "uur"
56+
57+
msgid "minutes"
58+
msgstr "minuten"
59+
60+
msgid "minute"
61+
msgstr "minuut"
62+
63+
msgid "Show panel totals"
64+
msgstr "Toon totalen van het paneel"
65+
66+
msgid "title"
67+
msgstr "titel"
68+
69+
msgid "panel"
70+
msgstr "paneel"
71+
72+
msgid "These default settings are used to connect to your panel"
73+
msgstr "Deze standaard instellingen worden gebruikt om te verbinden met je paneel"
74+
75+
msgid "default"
76+
msgstr "standaard"
77+
78+
msgid "settings"
79+
msgstr "instellingen"

lib/EthosStatsGpu.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
/**
4+
* Created by PhpStorm.
5+
* User: rutgerkirkels
6+
* Date: 01-08-17
7+
* Time: 20:04
8+
*/
9+
class EthosStatsGpu
10+
{
11+
protected $id;
12+
protected $hash;
13+
protected $power;
14+
protected $rpm;
15+
protected $temp;
16+
17+
/**
18+
* @return mixed
19+
*/
20+
public function getId()
21+
{
22+
return $this->id;
23+
}
24+
25+
/**
26+
* @param mixed $id
27+
*/
28+
public function setId($id)
29+
{
30+
$this->id = $id;
31+
}
32+
33+
/**
34+
* @return mixed
35+
*/
36+
public function getHash()
37+
{
38+
return $this->hash;
39+
}
40+
41+
/**
42+
* @param mixed $hash
43+
*/
44+
public function setHash($hash)
45+
{
46+
$this->hash = $hash;
47+
}
48+
49+
/**
50+
* @return mixed
51+
*/
52+
public function getPower()
53+
{
54+
return $this->power;
55+
}
56+
57+
/**
58+
* @param mixed $power
59+
*/
60+
public function setPower($power)
61+
{
62+
$this->power = $power;
63+
}
64+
65+
/**
66+
* @return mixed
67+
*/
68+
public function getRpm()
69+
{
70+
return $this->rpm;
71+
}
72+
73+
/**
74+
* @param mixed $rpm
75+
*/
76+
public function setRpm($rpm)
77+
{
78+
$this->rpm = $rpm;
79+
}
80+
81+
/**
82+
* @return mixed
83+
*/
84+
public function getTemp()
85+
{
86+
return $this->temp;
87+
}
88+
89+
/**
90+
* @param mixed $temp
91+
*/
92+
public function setTemp($temp)
93+
{
94+
$this->temp = $temp;
95+
}
96+
97+
98+
}

lib/EthosStatsPanel.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
/**
4+
* Class EthosStatsPanel
5+
* Connects to the ethOS panel API and retrieves all available data. If cache time is set, the data is cached for the
6+
* set cache time.
7+
*
8+
* @author Rutger Kirkels <[email protected]>
9+
*/
10+
class EthosStatsPanel
11+
{
12+
private $panelId = null;
13+
private $rigs = [];
14+
private $totalHash = 0;
15+
protected $rigsActive = 0;
16+
protected $cacheTime = null;
17+
18+
public function __construct($panelId = null, $cacheTime = null) {
19+
$this->cacheTime = intval($cacheTime);
20+
$this->panelId = $panelId;
21+
$this->getPanelData();
22+
}
23+
24+
/**
25+
* Retrieves the panel data and stores it in the cache.
26+
*/
27+
protected function getPanelData() {
28+
if (get_transient( 'ethos_stats' ) === false) {
29+
set_transient( 'ethos_stats', $this->retrievePanelData(), $this->cacheTime );
30+
}
31+
$panelData = get_transient( 'ethos_stats' );
32+
$this->totalHash = $panelData->total_hash;
33+
foreach(get_object_vars($panelData->rigs) as $name => $rigData) {
34+
$newRig = new EthosStatsRig($name, $rigData);
35+
$this->rigs[] = $newRig;
36+
37+
}
38+
}
39+
40+
/**
41+
* @return int Number of active rigs
42+
*/
43+
public function getActiveRigsCount() {
44+
$this->rigsActive = 0;
45+
if (count($this->rigs > 0)) {
46+
foreach ($this->rigs as $rig) {
47+
if ($rig->getCondition() == 'mining' || $rig->getCondition() == 'throttle') {
48+
$this->rigsActive += 1;
49+
}
50+
}
51+
return $this->rigsActive;
52+
}
53+
return $this->rigsActive;
54+
55+
}
56+
57+
public function getRigs() {
58+
return $this->rigs;
59+
}
60+
61+
protected function retrievePanelData() {
62+
// Set the timeout
63+
$ctx = stream_context_create(array('http'=>
64+
[
65+
'timeout' => 5,
66+
]
67+
));
68+
$panelData = file_get_contents('http://' . $this->panelId . '.ethosdistro.com/?json=yes', false, $ctx);
69+
70+
// If the data couldn't be retrieved or the data is empty, FALSE is returned.
71+
if (!$panelData || $panelData === '') {
72+
return false;
73+
}
74+
75+
// Check if the panel data is JSON. If not, FALSE is returned.
76+
if (!json_decode($panelData)) {
77+
return false;
78+
}
79+
return json_decode($panelData);
80+
}
81+
/**
82+
* @return float
83+
*/
84+
public function getTotalHash(): float
85+
{
86+
return $this->totalHash;
87+
}
88+
89+
90+
}

0 commit comments

Comments
 (0)