forked from hattori-dev/monero-lazy-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
162 lines (150 loc) · 5.17 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
$result="";
$workers = array();
$jsVar=array();
$strJSON = file_get_contents("config.json");
$configData = json_decode($strJSON, true);
$workers = $configData["workers"];
$refresh = $configData["refresh"] * 1000;
foreach($workers as $tempW)
{
array_push($jsVar, "['"
. $tempW['id']. "','"
. $tempW['ip']. "','"
. $tempW['port'] . "','"
. $tempW['soft']. "','"
. $tempW['alert'] . "','"
. $tempW['xmrigtoken'] . "','"
. $tempW['stakuser'] . "','"
. $tempW['stakpass']
. "'] ");
}
$tempStr=implode(",", $jsVar);
$jsVarWorkers="[" . $tempStr . "]";
?>
<!DOCTYPE html>
<html>
<head>
<title>Monero Lazy Monitor</title>
<link rel='stylesheet' href='style.css' />
<meta name='viewport' content='width=device-width' />
<script>
function showThread(tItem, alertlimit, cssClass)
{
var color="";
var value="";
var result="";
//XMR-STAK returns null and XMRIG returns zero, so I change null to zero
if(tItem[2]==null) tItem[2]=0;
if(tItem[1]==null) tItem[1]=0;
if(tItem[0]==null) tItem[0]=0;
if (((tItem[2]==0) || (tItem[1]==0) || (tItem[0]==0)) && ((tItem[2]!=0) || (tItem[1]!=0) || (tItem[0]!=0))) {
color="orange";
if(tItem[1]!=0) value=tItem[1];
if(tItem[2]!=0) value=tItem[2];
//result = "<span class='thread" + color + "'>" + tItem[index] + "</span>";
} else {
if((tItem[2]<=alertlimit) || (tItem[0]=="ERROR!")) {
color="red";
value = tItem[2];
} else {
color="";
value= tItem[2];
//result = "<span class='" + cssClass + " " + color + "'>" + value + "</span>";
}
}
result = "<span class='" + cssClass + " " + color + "'>" + value + "</span>";
return result;
}
function HATTORI(item)
{
var xmlhttp = new XMLHttpRequest();
document.getElementById("rd" + item[0]).innerHTML = "<td class='threadData'><span class='threadData'>...loading...</span></td>"
//document.getElementById("S" + item[0]).innerHTML = "<span>" +item[0] + " (" + item[3] + ")</span> | <span class='highestHashrate'>...loading...</span>";
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var bb = this.responseText;
//alert(bb);
if((item[3]=="xmrig")||(item[3]=="stak")){
var myObj = JSON.parse(bb);
var rtHTML = " "; //rowTitle
var rdHTML = " "; //rowData
rtHTML += "<td class='workerID' id='S"+ item[0]+"'>";
rtHTML += "<div style='float: left;'>";
rtHTML += "<span><a href='http://" + item[1] + ":" + item[2] + (item[3]=="stak" ? "/h" : "")+ "'>" + item[0] + "</a> (" + item[3] + ") ";
rtHTML += showThread(myObj.hashrate["total"], -1, "totalHashrate");
//rtHTML += "<span class='totalHashrate'>" + myObj.hashrate["total"][2] + "</span>";
rtHTML += "<span class='highestHashrate'>(" + myObj.hashrate["highest"] + ")</span>";
rtHTML += "</div>";
rtHTML += "<div style='float: right;'><span><a href='config.php?action=NONE&oldid=" + item[0] + "'>EDIT</a></span></div>";
rtHTML += "</td>";
rdHTML += "<td class='threadData'><div>";
var threads = myObj.hashrate["threads"];
if(threads) threads.forEach(function(threadItem) {
rdHTML += showThread(threadItem, item[4], "thread");
});
rdHTML += "</div></td>";
}else{
iHTML = bb;
}
document.getElementById("rt" + item[0]).innerHTML = rtHTML;
document.getElementById("rd" + item[0]).innerHTML = rdHTML;
}
};
urlStr = "semi-proxy.php?id=" + item[0]
+ "&ip=" + item[1]
+ "&port=" + item[2]
+ "&soft=" + item[3]
+ "&xmrigtoken=" + item[5]
+ "&stakuser=" + item[6]
+ "&stakpass=" + item[7]
;
xmlhttp.open("GET", urlStr, true);
xmlhttp.send();
}
function NINJA()
{
var workers = <?php echo $jsVarWorkers; ?> ;
workers.forEach(HATTORI);
}
function refresh() {
NINJA();
setTimeout(refresh, <?php echo $refresh; ?>);
}
setTimeout(refresh, <?php echo $refresh; ?>);
</script>
</head>
<body onload="NINJA()">
<div class='mainwrapper'>
<table>
<tr class="rowTitle">
<th><div style="float: left;">
<span>WorkerID (soft)</span>
<span class="totalHashrate">Total</span>
<span class="highestHashrate">(Highest)</span>
</div>
<div style="float: right;"><span><a href="config.php?action=ADD">ADD NEW</a></span></div>
</th>
</tr>
<?php
foreach($workers as $worker) {
echo "<tr class='rowTitle' id='rt" . $worker["id"] . "'>";
echo "<td class='workerID' id='S" . $worker["id"] . "'>";
echo "<div style='float: left;'>";
echo " <span><a href='http://" . $worker['ip'] . ":" . $worker['port'] . ($worker['soft']=="stak" ? "/h": "") . "'>" . $worker["id"] . "</a> (". $worker["soft"]. ")</span>";
echo " <span class='totalHashrate'> 0 </span>";
echo " <span class='highestHashrate'>( 0 )</span>";
echo "</div>";
echo "<div style='float: right;'><span><a href='config.php?action=NONE&oldid=" . $worker["id"] . "'>EDIT</a></span></div>";
echo "</td>";
echo "</tr>";
echo "<tr class='rowData' id='rd" . $worker["id"]. "'>";
//echo "<td class='totalHashrate'> 0 </td>";
echo "<td class='threadData'><div> </div></td>";
echo "</tr>";
}
?>
</table>
</div>
</body>
</html>