-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathstats.php~
executable file
·507 lines (452 loc) · 20.7 KB
/
stats.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
<?php
// Load Linkage Variables //
$dir = dirname(__FILE__);
$req = $dir."/req/";
$functions = $req."functions.php";
//Include hashing functions
include($functions);
//Include bitcoind functions
include($bitcoind);
//Open a bitcoind connection
$bitcoinController = new BitcoinClient($rpcType, $rpcUsername, $rpcPassword, $rpcHost);
//Set user details for userInfo box
$rawCookie = "";
if(isSet($_COOKIE[$cookieName])){
$rawCookie = $_COOKIE[$cookieName];
}
$getCredientials = new getCredientials;
$loginValid = $getCredientials->checkLogin($rawCookie);
?>
<?php
//Include the header & slogan
include($header);
////////////////////////////
?>
<div class="art-sheet">
<div class="art-sheet-tl"></div>
<div class="art-sheet-tr"></div>
<div class="art-sheet-bl"></div>
<div class="art-sheet-br"></div>
<div class="art-sheet-tc"></div>
<div class="art-sheet-bc"></div>
<div class="art-sheet-cl"></div>
<div class="art-sheet-cr"></div>
<div class="art-sheet-cc"></div>
<div class="art-sheet-body">
<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell art-content">
<div class="art-post">
<div class="art-post-body">
<div class="art-post-inner art-article">
<div class="art-postcontent">
<div class="blogContainer">
<!--Server status-->
<div class="serverStatus">
<?php
//Get total shares
$totalSharesQ = mysql_query("SELECT `shares_this_round` FROM `websiteSettings` LIMIT 0,1");
$totalSharesObj = mysql_fetch_object($totalSharesQ);
$totalShares = $totalSharesObj->shares_this_round;
//GET SERVER LOADS
$loadresult = @exec('uptime');
preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$loadresult,$avgs);
//GET SERVER UPTIME
$uptime = explode(' up ', $loadresult);
$uptime = explode(',', $uptime[1]);
$uptime = $uptime[0].', '.$uptime[1];
//Set variables for serverload average and Updtime
$serverLoadAverage = round((($avgs[1]+$avgs[2]+$avgs[3])/3), 2)*100;
$uptimeData = $uptime;
if($serverLoadAverage < 100){
$type = "highServerLoad";
$loadText = "High";
}
if($serverLoadAverage < 50){
$type = "medServerLoad";
$loadText = "Medium";
}
if($serverLoadAverage < 20){
$type = "lowServerLoad";
$loadText = "Low";
}
echo "IP:".$ip." Port:".$port."<br/>";
echo "Shares this round:".$totalShares."<br/>";
?>
</div>
<hr size="1" width="100%"/>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tdbody>
<tr>
<td>
<!--Top shares-->
<div class="topshares-stats" style="width:100%;float:left;">
<div class="blogHeader">
<h1 class="blogHeader">
Top shares last round
</h1>
</div>
<div class="blogContent">
<table width="100%" cellpadding="0" cellspacing="0">
<tdbody>
<tr>
<td>
<b># Rank</b>
</td>
<td>
<b>Display Name</b>
</td>
<td>
<b>Shares</b>
</td>
</tr>
<?php
//Get the top 10 share submitters
//go through list of workers and get top shares
$i = 0;
$getWorkerList = mysql_query("SELECT `userId`, `shares` FROM `stats_topSharers` ORDER BY `shares` DESC LIMIT 0,10");
while($worker = mysql_fetch_array($getWorkerList)){
$i++;
//Get username
$usernameQ = mysql_query("SELECT `username` FROM `websiteUsers` WHERE `id` = '".$worker["userId"]."' LIMIT 0,1")or die(mysql_error());
$username = mysql_fetch_object($usernameQ);
?>
<tr>
<td>
<?php echo $i;?>
</td>
<td>
<?php echo $username->username;?>
</td>
<td>
<?php echo $worker["shares"];?>
</td>
</tr>
<?php
}
?>
</tdbody>
</table>
</div>
</div>
</td>
<td>
<div class="topshares-stats" style="width:100%;">
<div class="blogHeader">
<h1 class="blogHeader">
Top Hashers this round
</h1>
</div>
<div class="blogContent">
<table width="100%" cellpadding="0" cellspacing="0">
<tdbody>
<tr>
<td>
# Rank
</td>
<td>
<b>Display Name</b>
</td>
<td>
<b>Mhash</b>
</td>
</tr>
<?php
//Get the top 10 share submitters
//go through list of workers and get top shares
$i = 0;
$getWorkerList = mysql_query("SELECT `userId`, `totalHashes` FROM `stats_topHashers` ORDER BY `totalHashes` DESC LIMIT 0,10")or die(mysql_error());
while($worker = mysql_fetch_array($getWorkerList)){
$i++;
//Get username
$usernameQ = mysql_query("SELECT `username` FROM `websiteUsers` WHERE `id` = '".$worker["userId"]."' LIMIT 0,1")or die(mysql_error());
$username = mysql_fetch_object($usernameQ);
?>
<tr>
<td>
<?php echo $i;?>
</td>
<td>
<?php echo $username->username;?>
</td>
<td>
<?php echo $worker["totalHashes"];?>
</td>
</tr>
<?php
}
?>
</tdbody>
</table>
</div>
</div>
</td>
</tr>
</tdbody>
</table>
<!--Block awaiting confirmations-->
<div class="blogHeader">
<h1 class="blogHeader">
Block's Awaiting Confirmation
</h1>
</div>
<div class="blogContent">
<table width="100%" cellpadding="0" cellspacing="0">
<tdbody>
<tr>
<td>
<b>Block #</b>
</td>
<td>
<b>Total Confirmations</b>
</td>
<td>
<b>Time found</b>
</td>
<td>
<b>Total Amount of your reward</b>
</td>
</tr>
<?php
$getCredientials->getStats();
$currentAdminFee = getAdminFee();
//Retireve all blocks awaiting confirmation
$getBlocksQ = mysql_query("SELECT `blockNumber`, `timestamp`, `confirms`, `orphan` FROM `networkBlocks` WHERE `txid` != '' ORDER BY `timestamp` DESC LIMIT 0,120");
$numBlocksFound = mysql_num_rows($getBlocksQ);
//If their are blocks found, display the Blocks found/ETA next block graph
if($numBlocksFound > 0){
//List blocks information
while($block = mysql_fetch_array($getBlocksQ)){
if($loginValid){
//Calculate the amount of the reward this user will get this block/round if logged in
//Get pool round total
$roundTotalQ = mysql_query("SELECT `id` FROM `shares_history` WHERE `blockNumber` = ".$block["blockNumber"]." AND `our_result` = 'Y'")or die(mysql_error());
$roundTotal = mysql_num_rows($roundTotalQ);
//Get user round total
$roundUserTotalQ = mysql_query("SELECT `id` FROM `shares_history` WHERE `blockNumber` = ".$block["blockNumber"]." AND `our_result` = 'Y' AND `username` LIKE '".$getCredientials->username.".%'")or die(mysql_error());
$roundUserTotal = mysql_num_rows($roundUserTotalQ);
//Get percentage of reward
$reward = 0;
if($roundUserTotal > 0 && $roundTotal > 0){
$reward = $roundUserTotal/$roundTotal;
}else{
}
//Subtract Admin percentage fee
$reward = round($reward*(50-(50*($currentAdminFee*0.01))), 8);
}else{
//Tell the user they are not logged in and must be logged into to view potential reward
$reward = "Login to see your reward this round";
}
?>
<!--Start block information-->
<tr<?php if($block["orphan"] == 1){ echo ' class="statsOrphanRow"';}else{ echo ' class="statsGoodRow"';}?>>
<td>
<?php echo $block["blockNumber"];?>
</td>
<td>
<?php echo $block["confirms"];?>
</td>
<td>
<?php echo date("m/d g:i a", $block["timestamp"]);?>
</td>
<td>
<?php
if($block["orphan"] == 1){
echo "Invalid/Orphan (".$reward.")";
}else if($block["orphan"] == 0){
echo $reward;
}
?>
</td>
</tr>
<!--End Block Information-->
<?php
}
}
if($numBlocksFound == 0){
?>
<tr>
<td>
N/A
</td>
<td>
Zero
</td>
<td>
0.00
</td>
<td>
Start Your Miners!
</td>
</tr>
<?php
}
?>
</tdbody>
</table>
</div>
</div>
<br/><br/>
<!--Blocks confirmeation table END-->
<div class="blogContainer">
<div class="blogHeader">
<h1 class="blogHeader">
Graph of Blocks found
</h1>
</div>
<div class="blogContent">
<div>
<?php
//Open a bitcoind connection
//Get current block number
try{
$currentBlockNumber = $bitcoinController->getblocknumber();
}catch(Exception $e){
$currentBlockNumber = -1;
}
//Get blocks found
$blocksFoundQ = mysql_query("SELECT `blockNumber`, `timestamp` FROM `networkBlocks` WHERE `txid` != '' ORDER BY `blockNumber` ASC");
$numBlocksFound = mysql_num_rows($blocksFoundQ);
//If any blocks have been found
if($numBlocksFound > 0){
//Display blocks that have been found with the corrisponding timestamp
$blockArray = "";
$timeArray = "";
$i=0;
//Tmp vars
$totalDifference = 0;
$lastDifference = 0;
$lastBlockNumber = 0;
while($block = mysql_fetch_array($blocksFoundQ)){
//Loop through every block found and add it to the array of data to output on the stats graph
if($i > 0){
$blockArray .=",";
$timeArray .=",";
}
$i++;
$blockArray .="{y: ".$block["blockNumber"].",
marker: {
symbol: 'url(/images/graphIcons/blockFound.png)'
}
}";
$timeArray .= "'".date("m/d/Y g:i:s a", $block["timestamp"])."'";
if(!$lastDifference){
$lastDifference = $block["timestamp"];
}
if($lastDifference){
$totalDifference += ($block["timestamp"]-$lastDifference);
$lastDifference = $block["timestamp"];
}
$lastBlockNumber = $block["blockNumber"];
}
//Prevent division by zero && calculate eta till next block
if($i > 0 && $totalDifference > 0){
$averageDifference = ($totalDifference/$i);
$estimatedFindTimestamp = $lastDifference+$averageDifference;
//Get esimated block number by
//averaging out the amount of time between blocks found, and then adding the estimated time till that block will be found
$estimatedBlockNumber = round($lastBlockNumber+(($averageDifference/60)/10));
}
//Add current time here if its before estimated block finding
if($estimatedFindTimestamp > time()){
//Add currentime time
$timeArray .=",'".date("m/d/y g:i:s a", time())."'";
$blockArray .=",{
y: ".$currentBlockNumber.",
marker: {
symbol: 'url(/images/graphIcons/currentTime.png)'
}
}";
}
//Add expected block found ( only if there is an expected block calculation )
if($estimatedBlockNumber > 0){
$timeArray .= ",'".date("m/d/Y g:i:s a", $estimatedFindTimestamp)."'";
$blockArray .=",{
y: ".$estimatedBlockNumber.",
marker: {
symbol: 'url(/images/graphIcons/estimatedBlockFound.png)'
}
}";
}
//Add current time here if it is after the estimated block finding
if($estimatedFindTimestamp < time() ){
//Add currentime time
$timeArray .=",'".date("m/d/y g:i:s a", time())."'";
$blockArray .=",{
y: ".$currentBlockNumber.",
marker: {
symbol: 'url(/images/graphIcons/currentTime.png)'
}
}";
}
}else{
//No blocks have been found yet, show this in the graph
$blocksFoundTitle = '(No Blocks have been found yet)';
$timeArray = "'".date("m/d g:i", time())."'";
$blockArray = "{
y: ".$currentBlockNumber.",
marker: {
symbol: 'url(/images/graphIcons/currentTime.png)'
}
}";
}
?>
<script type="text/javascript">
var chart1; // globally available
$(document).ready(function() {
chart1 = new Highcharts.Chart({
chart: {
renderTo: 'blocksFound',
defaultSeriesType: 'spline',
width:750,
height:250
},
title: {
text: '<?php if(!isSet($blocksFoundTitle)){
echo 'Overall Blocks Found';
}else if(isSet($blocksFoundTitle)){
echo $blocksFoundTitle;
}
?>'
},
xAxis: {
categories: [<?php echo $timeArray;?>]
},
yAxis: {
title: {
text: 'Block Number'
}
},
series: [{
name: 'Longest Block Chain',
data: [
<?php echo $blockArray; ?>
]
}]
});
});
</script>
<div id="blocksFound" align="center">
<h3>No blocks found yet</h3>
</div><br/><br/>
</div>
</div>
<img src="/images/graphIcons/blockFound.png"/> = Block Found<br/>
<img src="/images/graphIcons/currentTime.png"/> = Current network block<br/>
<img src="/images/graphIcons/estimatedBlockFound.png"/> = ETA till next block is found
<br/><br/>
</div>
<div class="cleared"></div>
</div>
<div class="cleared"></div>
</div>
</div>
<div class="cleared"></div>
</div>
</div>
</div>
<?php
//Include Footer
////////////////////
include($footer);
?>