Skip to content

Commit

Permalink
Web GUI / Pools: add 'Enable/disable algo @ pool' buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
UselessGuru committed May 13, 2021
1 parent bae0a80 commit a97dfa2
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 31 deletions.
108 changes: 81 additions & 27 deletions Includes/API.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Function Start-APIServer {
}
}

$APIVersion = "0.3.8.5"
$APIVersion = "0.3.9.1"

If ($Config.APILogFile) { "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss"): API ($APIVersion) started." | Out-File $Config.APILogFile -Encoding UTF8 -Force }

Expand Down Expand Up @@ -273,6 +273,86 @@ Function Start-APIServer {
$Data = "<pre>$Data</pre>"
Break
}
"/functions/pool/disable" {
If ($Parameters.Pools) {
$PoolsConfig = Get-Content -Path $Variables.PoolsConfigFile -ErrorAction Ignore | ConvertFrom-Json
$Pools = Compare-Object -PassThru -IncludeEqual -ExcludeDifferent @($Variables.Pools | Select-Object) @(($Parameters.Pools | ConvertFrom-Json -ErrorAction SilentlyContinue) | Select-Object) -Property Name, Algorithm | ForEach-Object { $_.Name -replace "24hr$" -replace "Coins$"; $_ } | Sort-Object Name, Algorithm -Unique | Where-Object { $_.Algorithm }
$Pools | ForEach-Object {
$PoolName = $_.Name
$Algorithm = $_.Algorithm
If ($PoolsConfig.$PoolName) { $PoolConfig = $PoolsConfig.$PoolName } Else { $PoolConfig = [PSCustomObject]@{ } }

[System.Collections.ArrayList]$AlgorithmList = @(($PoolConfig.Algorithm -replace " ") -split ',')
$AlgorithmList.Remove("+$Algorithm")
If (-not ($AlgorithmList -match "\+.+") -and $AlgorithmList -notcontains "-$Algorithm") {
$AlgorithmList += "-$Algorithm"
}

If ($AlgorithmList) { $PoolConfig | Add-Member Algorithm (($AlgorithmList | Sort-Object) -join ',' -replace "^,+") -Force } Else { $PoolConfig.PSObject.Properties.Remove('Algorithm') }
If ($PoolConfig | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name) { $PoolsConfig | Add-Member $PoolName $PoolConfig -Force } Else { $PoolsConfig.PSObject.Properties.Remove($PoolName) }

$Data += "`n$Algorithm@$PoolName"
$Reason = "Algorithm disabled (``-$($_.Algorithm)`` in $PoolName pool config)"
$_.Reason = @(($_.Reason -NE $Reason) | Select-Object)
$_.Reason += $Reason
$_.Available = $false
}
If ($Pools.Count -gt 0) {
# Write PoolsConfig
$PoolsConfig | Get-SortedObject | ConvertTo-Json -Depth 10 | Set-Content -Path $Variables.PoolsConfigFile -Force -ErrorAction Ignore

$Message = "$($Pools.Count) $(If ($Pools.Count -eq 1) { "pool" } Else { "pools" }) disabled."
Write-Message -Level Verbose "Web GUI: $Message" -Console
$Data += "`n`n$Message"
}
$Data = "<pre>$Data</pre>"
Break
}
}
"/functions/pool/enable" {
If ($Parameters.Pools) {
$PoolsConfig = Get-Content -Path $Variables.PoolsConfigFile -ErrorAction Ignore | ConvertFrom-Json
$Pools = Compare-Object -PassThru -IncludeEqual -ExcludeDifferent @($Variables.Pools | Select-Object) @(($Parameters.Pools | ConvertFrom-Json -ErrorAction SilentlyContinue) | Select-Object) -Property Name, Algorithm
$Pools | ForEach-Object {
$PoolName = $_.Name
$Algorithm = $_.Algorithm

$Reason = "Algorithm disabled (``-$($Algorithm)`` in $PoolName pool config)"

$_.Reason = @(($_.Reason -NE $Reason) | Select-Object)
$_.Available = -not [Bool]$_.Reason.Count
}

$Pools = $Pools | ForEach-Object { $_.Name -replace "24hr$" -replace "Coins$"; $_ } | Sort-Object Name, Algorithm -Unique | Where-Object { $_.Algorithm }
$Pools | ForEach-Object {
$PoolName = $_.Name
$Algorithm = $_.Algorithm
If ($PoolsConfig.$PoolName) { $PoolConfig = $PoolsConfig.$PoolName } Else { $PoolConfig = [PSCustomObject]@{ } }

[System.Collections.ArrayList]$AlgorithmList = @(($PoolConfig.Algorithm -replace " ") -split ',')
$AlgorithmList.Remove("-$Algorithm")
If ($AlgorithmList -match "\+.+" -and $AlgorithmList -notcontains "+$Algorithm") {
$AlgorithmList += "+$Algorithm"
}

If ($AlgorithmList) { $PoolConfig | Add-Member Algorithm (($AlgorithmList | Sort-Object) -join ',' -replace "^,+") -Force } Else { $PoolConfig.PSObject.Properties.Remove('Algorithm') }
If ($PoolConfig | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name) { $PoolsConfig | Add-Member $PoolName $PoolConfig -Force } Else { $PoolsConfig.PSObject.Properties.Remove($PoolName) }

$Data += "`n$Algorithm@$PoolName"
$Reason = "Algorithm disabled (``-$($_.Algorithm)`` in $PoolName pool config)"
}
If ($Pools.Count -gt 0) {
# Write PoolsConfig
$PoolsConfig | Get-SortedObject | ConvertTo-Json -Depth 10 | Set-Content -Path $Variables.PoolsConfigFile -Force -ErrorAction Ignore

$Message = "$($Pools.Count) $(If ($Pools.Count -eq 1) { "pool" } Else { "pools" }) enabled."
Write-Message -Level Verbose "Web GUI: $Message" -Console
$Data += "`n`n$Message"
}
$Data = "<pre>$Data</pre>"
Break
}
}
"/functions/stat/get" {
If ($null -eq $Parameters.Value) {
$TempStats = @($Stats.Keys | Where-Object { $_ -like "*$($Parameters.Type)" } | ForEach-Object { $Stats.$_ })
Expand All @@ -291,32 +371,6 @@ Function Start-APIServer {
Break
}
"/functions/stat/remove" {
If ($Parameters.Pools) {
$Pools = Compare-Object -PassThru -IncludeEqual -ExcludeDifferent @($Variables.Pools | Select-Object) @(($Parameters.Pools | ConvertFrom-Json -ErrorAction SilentlyContinue) | Select-Object) -Property Name, Algorithm
$Pools | Sort-Object Name | ForEach-Object {
If ($_.Name -like "*Coins") {
$StatName = "$($_.Name)_$($_.Algorithm)-$($_.Currency)"
}
Else {
$StatName = "$($_.Name)_$($_.Algorithm)"
}
$Data += "`n$($StatName) [$($_.Region)]"
Remove-Stat -Name "$($StatName)_Profit"
$_.Reason = [String[]]@()
$_.Available = $true
$_.Price = $_.Price_Bias = $_.StablePrice = $_.MarginOfError = $_.EstimateFactor = [Double]::Nan
}
If ($Pools.Count -gt 0) {
$Message = "Pool data reset for $($Pools.Count) $(If ($Pools.Count -eq 1) { "pool" } Else { "pools" })."
Write-Message -Level Verbose "Web GUI: $Message" -Console
$Data += "`n`n$Message"
}
Else {
$Data = "`nNo matching stats found."
}
$Data = "<pre>$Data</pre>"
Break
}
If ($Parameters.Miners -and $Parameters.Type -eq "HashRate") {
$Miners = Compare-Object -PassThru -IncludeEqual -ExcludeDifferent @($Variables.Miners | Select-Object) @(($Parameters.Miners | ConvertFrom-Json -ErrorAction SilentlyContinue) | Select-Object) -Property Name, Algorithm
$Miners | Sort-Object Name, Algorithm | ForEach-Object {
Expand Down
4 changes: 3 additions & 1 deletion Web/APIdocs.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<html>

<body>
<h1>NemosMiner API (version 0.3.8.5)</h1>
<h1>NemosMiner API (version 0.3.9.1)</h1>

API data is available at http://localhost:[API port]/&lt;resource&gt.
(The default API port is 3999)
Expand Down Expand Up @@ -233,6 +233,8 @@ <h3>Functions</h3>
<p>/functions/log/clear</p>
<p>/functions/stat/get</p>
<p>/functions/stat/remove</p>
<p>/functions/pool/enable</p>
<p>/functions/pool/disable</p>
<p>/functions/switchinglog/clear</p>
<p>/functions/variables/get</p>
<p>/functions/watchdogtimers/remove</p>
Expand Down
38 changes: 38 additions & 0 deletions Web/pools.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ <h1 id="title" class="h2" data-navbaractive="navallpools">All Pools</h1>

<div id="toolbar">
<button id="reset-data" class="btn btn-warning">Reset pool stat data</button>
<button id="enable" class="btn btn-success">Enable algorithm @ pool</button>
<button id="disable" class="btn btn-danger">Disable algorithm @ pool</button>
</div>

<table id="pools" class="table"
Expand Down Expand Up @@ -93,6 +95,42 @@ <h1 id="title" class="h2" data-navbaractive="navallpools">All Pools</h1>
}
});

$('#enable').click(function () {
var $data = $table.bootstrapTable('getSelections');
if ($data.length >= 1) {
$data = JSON.stringify($data.map($element => ({Name: $element.Name, Algorithm: $element.Algorithm})));
if ($data.length >= $querysize) {
alert('Too many objects selected, cannot proceed.\nUnselect some objects and try again.\n\n(Query size: ' + $data.length + '/' + $querysize + ')');
}
else {
$command = '/functions/pool/enable?Pools=' + encodeURIComponent($data);
$('.modal-body').load($command, function() {
$('.modal-title').text($('#enable').text());
$('#myModal').modal({show:true});
});
$table.bootstrapTable('refresh');
}
}
});

$('#disable').click(function () {
var $data = $table.bootstrapTable('getSelections');
if ($data.length >= 1) {
$data = JSON.stringify($data.map($element => ({Name: $element.Name, Algorithm: $element.Algorithm})));
if ($data.length >= $querysize) {
alert('Too many objects selected, cannot proceed.\nUnselect some objects and try again.\n\n(Query size: ' + $data.length + '/' + $querysize + ')');
}
else {
$command = '/functions/pool/disable?Pools=' + encodeURIComponent($data);
$('.modal-body').load($command, function() {
$('.modal-title').text($('#disable').text());
$('#myModal').modal({show:true});
});
$table.bootstrapTable('refresh');
}
}
});

</script>

<!-- End of page scripts -->
Expand Down
26 changes: 23 additions & 3 deletions Web/poolsbest.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ <h1 id="title" class="h2" data-navbaractive="navpoolsbest">Best Pools</h1>

<div id="toolbar">
<button id="reset-data" class="btn btn-warning">Reset pool stat data</button>
<button id="enable" class="btn btn-success">Enable algorithm @ pool</button>
<button id="disable" class="btn btn-danger">Disable algorithm @ pool</button>
</div>

<table id="pools" class="table"
Expand Down Expand Up @@ -72,17 +74,35 @@ <h1 id="title" class="h2" data-navbaractive="navpoolsbest">Best Pools</h1>
height: (($(window).height()) - $('h1').outerHeight(true) - 185) * 0.985 - 20,
})

$('#reset-data').click(function () {
$('#enable').click(function () {
var $data = $table.bootstrapTable('getSelections');
if ($data.length >= 1) {
$data = JSON.stringify($data.map($element => ({Name: $element.Name, Algorithm: $element.Algorithm})));
if ($data.length >= $querysize) {
alert('Too many objects selected, cannot proceed.\nUnselect some objects and try again.\n\n(Query size: ' + $data.length + '/' + $querysize + ')');
}
else {
$command = '/functions/stat/remove?Pools=' + encodeURIComponent($data);
$command = '/functions/pool/enable?Pools=' + encodeURIComponent($data);
$('.modal-body').load($command, function() {
$('.modal-title').text($('#reset-data').text());
$('.modal-title').text($('#enable').text());
$('#myModal').modal({show:true});
});
$table.bootstrapTable('refresh');
}
}
});

$('#disable').click(function () {
var $data = $table.bootstrapTable('getSelections');
if ($data.length >= 1) {
$data = JSON.stringify($data.map($element => ({Name: $element.Name, Algorithm: $element.Algorithm})));
if ($data.length >= $querysize) {
alert('Too many objects selected, cannot proceed.\nUnselect some objects and try again.\n\n(Query size: ' + $data.length + '/' + $querysize + ')');
}
else {
$command = '/functions/pool/disable?Pools=' + encodeURIComponent($data);
$('.modal-body').load($command, function() {
$('.modal-title').text($('#disable').text());
$('#myModal').modal({show:true});
});
$table.bootstrapTable('refresh');
Expand Down
38 changes: 38 additions & 0 deletions Web/poolsunavailable.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ <h1 id="title" class="h2" data-navbaractive="navpoolsunavailable">Unavailable Po
<div id="toolbar">
<button id="reset-data" class="btn btn-warning">Reset pool stat data</button>
<button id="remove-watchdog" class="btn btn-primary">Remove watchdog</button>
<button id="enable" class="btn btn-success">Enable algorithm @ pool</button>
<button id="disable" class="btn btn-danger">Disable algorithm @ pool</button>
</div>

<table id="pools" class="table"
Expand Down Expand Up @@ -110,6 +112,42 @@ <h1 id="title" class="h2" data-navbaractive="navpoolsunavailable">Unavailable Po
}
});

$('#enable').click(function () {
var $data = $table.bootstrapTable('getSelections');
if ($data.length >= 1) {
$data = JSON.stringify($data.map($element => ({Name: $element.Name, Algorithm: $element.Algorithm})));
if ($data.length >= $querysize) {
alert('Too many objects selected, cannot proceed.\nUnselect some objects and try again.\n\n(Query size: ' + $data.length + '/' + $querysize + ')');
}
else {
$command = '/functions/pool/enable?Pools=' + encodeURIComponent($data);
$('.modal-body').load($command, function() {
$('.modal-title').text($('#enable').text());
$('#myModal').modal({show:true});
});
$table.bootstrapTable('refresh');
}
}
});

$('#disable').click(function () {
var $data = $table.bootstrapTable('getSelections');
if ($data.length >= 1) {
$data = JSON.stringify($data.map($element => ({Name: $element.Name, Algorithm: $element.Algorithm})));
if ($data.length >= $querysize) {
alert('Too many objects selected, cannot proceed.\nUnselect some objects and try again.\n\n(Query size: ' + $data.length + '/' + $querysize + ')');
}
else {
$command = '/functions/pool/disable?Pools=' + encodeURIComponent($data);
$('.modal-body').load($command, function() {
$('.modal-title').text($('#disable').text());
$('#myModal').modal({show:true});
});
$table.bootstrapTable('refresh');
}
}
});

</script>

<!-- End of page scripts -->
Expand Down

0 comments on commit a97dfa2

Please sign in to comment.