Skip to content

Commit

Permalink
Updated to v1.4
Browse files Browse the repository at this point in the history
* Added functionality to remove miners from the list
* Added JSON validation functionality to warn when saving incorrect configurations
* Added username display into the miner list
* Added "Auto refresh" toggle button for automatic miner list refreshing
* Added robots.txt file to stop search engines from indexing the web panel
* Added directory listing block in .htaccess for better privacy
* Added previously ignored "Logs" folder back
* Changed "Default" configuraiton into "Default ethminer" and "Default xmrig" configurations to allow different default configurations for the two different miners
* Fixed possible database "corruption" when null hashrates were submitted
* Fixed broken miner searching and sorting
  • Loading branch information
UnamSanctam committed Jan 9, 2022
1 parent 167b1d5 commit 534d3f2
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 16 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
### v1.4 (09/01/2022)
* Added functionality to remove miners from the list
* Added JSON validation functionality to warn when saving incorrect configurations
* Added username display into the miner list
* Added "Auto refresh" toggle button for automatic miner list refreshing
* Added robots.txt file to stop search engines from indexing the web panel
* Added directory listing block in .htaccess for better privacy
* Added previously ignored "Logs" folder back
* Changed "Default" configuraiton into "Default ethminer" and "Default xmrig" configurations to allow different default configurations for the two different miners
* Fixed possible database "corruption" when null hashrates were submitted
* Fixed broken miner searching and sorting
### v1.3 (09/11/2021)
* Added Unique ID generation on the panel side instead of the miner side
* Changed all file calls to be relative to allow easier deployment of the panel in subfolders
Expand Down
13 changes: 12 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.3
# UnamWebPanel v1.4

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 @@ -28,6 +28,17 @@ You can find the wiki [here](https://github.com/UnamSanctam/SilentCryptoMiner/wi

## Changelog

### v1.4 (09/01/2022)
* Added functionality to remove miners from the list
* Added JSON validation functionality to warn when saving incorrect configurations
* Added username display into the miner list
* Added "Auto refresh" toggle button for automatic miner list refreshing
* Added robots.txt file to stop search engines from indexing the web panel
* Added directory listing block in .htaccess for better privacy
* Added previously ignored "Logs" folder back
* Changed "Default" configuraiton into "Default ethminer" and "Default xmrig" configurations to allow different default configurations for the two different miners
* Fixed possible database "corruption" when null hashrates were submitted
* Fixed broken miner searching and sorting
### v1.3 (09/11/2021)
* Added Unique ID generation on the panel side instead of the miner side
* Changed all file calls to be relative to allow easier deployment of the panel in subfolders
Expand Down
4 changes: 3 additions & 1 deletion UnamWebPanel/.htaccess
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DirectoryIndex index.php
<Files "unamwebpanel.db">
Require all denied
</Files>
</Files>
Options -Indexes
1 change: 1 addition & 0 deletions UnamWebPanel/__UNAM_LIB/Logs/dummy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is a dummy file whose raison d'être is to ensure that the folder that this file is located in does not get ignored.
16 changes: 11 additions & 5 deletions UnamWebPanel/api/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@
if(!empty(getParam('method'))) {
switch (getParam('method')) {
case 'config-add':
$base->unam_checkCondition(!checkJSON(getParam('data')), "{$larr['Invalid']} JSON.");
$base->tableModify(getConn(), 'insert', 'configs', 'cf', ['name', 'data'], []);
$base->unam_echoSuccess("{$larr['Configuration']} {$larr['has_been_added']}.");
break;
case 'config-remove':
$base->unam_checkCondition(getParam('index') == 1, $larr['cannot_remove_default']);
$base->tableModify(getConn(), 'delete', 'configs', 'cf', [], ['configID']);
$base->unam_echoSuccess("{$larr['Configuration']} {$larr['has_been_removed']}.");
break;
case 'config-update':
$base->unam_checkCondition(!checkJSON(getParam('data')), "{$larr['Invalid']} JSON.");
$base->tableModify(getConn(), 'update', 'configs', 'cf', ['data'], ['configID']);
$base->unam_echoSuccess("{$larr['Configuration']} {$larr['has_been_updated']}.");
break;
case 'config-remove':
$base->unam_checkCondition(getParam('index') == 1 || getParam('index') == 2, $larr['cannot_remove_default']);
$base->tableModify(getConn(), 'delete', 'configs', 'cf', [], ['configID']);
$base->unam_echoSuccess("{$larr['Configuration']} {$larr['has_been_removed']}.");
break;
case 'miner-config':
$base->tableModify(getConn(), 'update', 'miners', 'ms', ['config'], ['minerID']);
$base->unam_echoSuccess("{$larr['Miner']} {$larr['has_been_updated']}.");
break;
case 'miner-remove':
$base->tableModify(getConn(), 'delete', 'miners', 'ms', [], ['minerID']);
$base->unam_echoSuccess("{$larr['Miner']} {$larr['has_been_removed']}.");
break;
}
}
2 changes: 1 addition & 1 deletion UnamWebPanel/api/endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function getData($key){
if ($miner) {
$base->unam_dbUpdate(getConn(), 'miners', $fields, ['ms_uqhash' => $uqhash, 'ms_type'=>$type]);
} else {
$base->unam_dbInsert(getConn(), 'miners', array_merge(['ms_uqhash'=>$uqhash, 'ms_type'=>$type], $fields));
$base->unam_dbInsert(getConn(), 'miners', array_merge(['ms_uqhash'=>$uqhash, 'ms_type'=>$type, 'ms_config'=>($type == 'xmrig' ? 1 : 2)], $fields));
}

$config = $base->unam_dbSelect(getConn(), 'configs', 'cf_data', ['cf_configID' => $miner['ms_config'] ?? 0]);
Expand Down
58 changes: 58 additions & 0 deletions UnamWebPanel/assets/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,62 @@

.dark-mode .external-page-logo a {
color: #fff;
}

.select-miner-config {
width: 50% !important;
display: inline;
}

.round-switch {
position: relative;
display: inline-block;
width: 40px;
height: 22px;
}

.round-switch input {
opacity: 0;
width: 0;
height: 0;
}

.round-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
border-radius: 34px;
-webkit-transition: .4s;
transition: .4s;
}

.round-slider:before {
position: absolute;
content: "";
height: 14px;
width: 14px;
left: 4px;
bottom: 4px;
background-color: white;
border-radius: 50%;
-webkit-transition: .4s;
transition: .4s;
}

input:checked + .round-slider {
background-color: #2196F3;
}

input:focus + .round-slider {
box-shadow: 0 0 1px #2196F3;
}

input:checked + .round-slider:before {
-webkit-transform: translateX(18px);
-ms-transform: translateX(18px);
transform: translateX(18px);
}
14 changes: 13 additions & 1 deletion UnamWebPanel/assets/php/datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'db_column'=>'status',
'display'=>$larr['Status'],
'formatting'=>function($d, $s){
return unamtMinerStatus(isset($s['ms_lastConnection']) && ((strtotime(date("Y-m-d H:i:s")) - strtotime($s['ms_lastConnection'])) > 300) ? 5 : $d);
return unamtMinerStatus(isset($s['ms_lastConnection']) && ((strtotime(date("Y-m-d H:i:s")) - strtotime($s['ms_lastConnection'])) > 300) ? 6 : $d);
}
],
'algorithm'=>[
Expand Down Expand Up @@ -63,6 +63,10 @@
'db_column'=>'password',
'display'=>$larr['Password']
],
'username'=>[
'db_column'=>'username',
'display'=>$larr['Username']
],
'computername'=>[
'db_column'=>'computername',
'display'=>$larr['computer_name']
Expand Down Expand Up @@ -102,6 +106,14 @@
}
return unamtSelect('','config', $configoptions, ['classes'=>'select-miner-config', 'extras'=>"data-method='miner-config' data-index='{$s[0]}'"]);
}
],
'actions'=>[
'db_column'=>'minerID',
'display'=>$larr['Actions'],
'formatting'=>function($d, $s){
global $larr;
return unamtAjaxButton("{$larr['Remove']} {$larr['Miner']}",'miner-remove', $d, ['classes'=>'btn-danger']);
}
]
],
'db_filters_prefix'=>'ms_',
Expand Down
8 changes: 8 additions & 0 deletions UnamWebPanel/assets/php/session-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ function getMinerConfigurations(){
}
return $minerconfigs;
}

function checkJSON($input) {
json_decode($input, true);
if(json_last_error() != JSON_ERROR_NONE) {
return false;
}
return true;
}
20 changes: 18 additions & 2 deletions UnamWebPanel/assets/php/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ function unamtHidden($name, $value){
return "<input type='hidden' name='{$name}' value='{$value}'>";
}

function unamtToggleSwitch($checked, $options=[]){
global $cf;
$options = array_merge(['classes'=>''], $options);
return "<label class='round-switch'>
<input type='checkbox' class='{$options['classes']}' {$cf($checked ? 'checked' : '')}>
<span class='round-slider'></span>
</label>";
}

function unamtDatatable($id, $columnarray, $options=[]){
global $cf;
$options = array_merge(['editmethod'=>'', 'edit_columns'=>'', 'edit_format'=>'', 'minmode'=>'false', 'extradata'=>'{}', 'filters'=>'{}', 'classes'=>'', 'extra'=>''], $options);
Expand Down Expand Up @@ -182,6 +191,8 @@ function unamtMinerStatus($status){
case 4:
return "<span class='text-status-yellow'>{$larr['Paused']} ({$larr['Stealth']})</span>";
case 5:
return "<span class='text-status-yellow'>{$larr['not_enough_free_vram']}</span>";
case 6:
return "<span class='text-status-red'>{$larr['Offline']}</span>";
default:
return "<span class='text-status-red'>{$larr['Unknown']}</span>";
Expand All @@ -197,6 +208,11 @@ function unamtFormatHashrate($num)
return round($num, 1)." {$units[$i]}";
}

function templateRefreshDatatables(){
global $larr;
return $larr['auto_refresh'].' '.unamtToggleSwitch(false, ['classes'=>'refresh-datatables']);
}

function templateLanguageSelect(){
global $langID;
return unamtSelect('', 'language',
Expand Down Expand Up @@ -242,7 +258,7 @@ function templateExternalPage($title, $content, $options=[]){
}

function templateDatatableX($datatable, $options=[]){
global $larr;
global $larr, $cf;
require_once 'datatables.php';
$table = &$datatables['tables'][$datatable];
$etable = $table;
Expand All @@ -258,7 +274,7 @@ function templateDatatableX($datatable, $options=[]){
}
$icount++;
}
return unamtCard(12, $etable['html_header'], 'custom-tables',
return unamtCard(12, $etable['html_header']." <div class='card-tools'>{$cf(templateRefreshDatatables())}</div>", 'custom-tables',
unamtDatatable($datatable, array_column($etable['columns'], 'display'), array_merge(['edit_columns'=>$tabledata['edit_columns'] ?? '', 'edit_format'=>$tabledata['edit_format'] ?? ''], $options))
);
}
3 changes: 3 additions & 0 deletions UnamWebPanel/class/class.ssp.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ private static function filter ( $request, $options, &$bindings ) {
for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) {
$requestColumn = $request['columns'][$i];
$columnIdx = array_search( $requestColumn['data'], $columns );
if(!$columnIdx){
$columnIdx = $i;
}
$column = $columns[ $columnIdx ];

if ( $requestColumn['searchable'] == 'true') {
Expand Down
6 changes: 3 additions & 3 deletions UnamWebPanel/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
$config['password'] = 'UnamSanctam';

/*
* If your web server uses Apache then there is no need to
* change the db file location since the .htaccess file
* If your web server uses Apache or IIS then there is no need to
* change the db file location since the .htaccess or web.config file
* will protect the database file from being accessed.
*
* You can test if you are vulnerable by trying to access
Expand All @@ -22,6 +22,6 @@

$config['languages'] = ['en', 'sv'];

$config['unam_version'] = "1.3";
$config['unam_version'] = "1.4";

global $config;
12 changes: 12 additions & 0 deletions UnamWebPanel/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
let showLoader = false;
let datatables = [];

let refreshTimer;

$(document).ready(function()
{
loadPageContentAjax(this, 'GET', openLoadUrl, {'id': paramID});
Expand Down Expand Up @@ -124,6 +126,16 @@
successMessage(data.successmsg);
}
}, function(error){ errorMessage(error); });
}).on("click touch", '.refresh-datatables', function(e)
{
if($(this).is(':checked')){
refreshTimer = setInterval(function(){
reloadDatatables();
console.log("reloaded");
},10000);
}else{
clearInterval(refreshTimer);
}
});

function datatableTemplate(table, _data={}, minmode=false, _columnDefs=[]){
Expand Down
2 changes: 1 addition & 1 deletion UnamWebPanel/internalPages/configurationsAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function getConfigValue($key) {
unamtFormGroup(unamtTextarea("{$larr['Configuration']} JSON", 'data', getConfigValue('cf_data'), ['extras'=>''])).
unamtRow(
unamtFormGroup(unamtSubmit($larr['Save']), ['classes'=>'col']).
unamtFormGroup(unamtAjaxButton($larr['Remove'], 'config-remove', $configID, ['classes'=>($configID == 1 ? 'disabled ' : '').' col btn-danger ajax-action-reload']), ['classes'=>'col'])
unamtFormGroup(unamtAjaxButton($larr['Remove'], 'config-remove', $configID, ['classes'=>($configID == 1 || $configID == 2 ? 'disabled ' : '').' col btn-danger ajax-action-reload']), ['classes'=>'col'])
)
)
)
Expand Down
4 changes: 3 additions & 1 deletion UnamWebPanel/lang/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,7 @@
'Stealth'=>['en' => 'Stealth', 'sv' => 'Stealth'],
'Offline'=>['en' => 'Offline', 'sv' => 'Offline'],
'Idle'=>['en' => 'Idle', 'sv' => 'Inaktiv'],
'Type'=>['en' => 'Type', 'sv' => 'Typ']
'Type'=>['en' => 'Type', 'sv' => 'Typ'],
'not_enough_free_vram'=>['en' => 'Not enough free VRAM', 'sv' => 'För lite ledigt VRAM'],
'auto_refresh'=>['en' => 'Auto Refresh', 'sv' => 'Auto Refresh']
];
2 changes: 2 additions & 0 deletions UnamWebPanel/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow: /

0 comments on commit 534d3f2

Please sign in to comment.