-
Notifications
You must be signed in to change notification settings - Fork 7
/
coinhive.php
95 lines (82 loc) · 3.35 KB
/
coinhive.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
<?php
// Coinhive API URLs
$coinhive_get_balance_url="https://api.coinhive.com/user/balance";
$coinhive_withdraw_balance_url="https://api.coinhive.com/user/withdraw";
$coinhive_reset_balance_url="https://api.coinhive.com/user/reset";
$coinhive_get_payout_info_url="https://api.coinhive.com/stats/payout";
$coinhive_get_stats_site_info_url="https://api.coinhive.com/stats/site";
// Get balance of specific user
// Returns class with total, withdrawn and balance
function coinhive_get_user_balance_detail($address) {
global $coinhive_private_key;
global $coinhive_get_balance_url;
$address_html=html_escape($address);
// Setup cURL
$ch=curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($ch,CURLOPT_POST,FALSE);
curl_setopt($ch,CURLOPT_URL,$coinhive_get_balance_url."?secret=$coinhive_private_key&name=$address_html");
$result = curl_exec ($ch);
if($result=="") return 0;
$data=json_decode($result);
return $data;
//if(isset($data->balance) && $data->balance) return $data->balance;
//else return 0;
}
// Returns only balance
function coinhive_get_user_balance($address) {
$data=coinhive_get_user_balance_detail($address);
if(property_exists($data,"total") && $data->total!=0) return $data->total;
else return 0;
}
// Reset user balance
function coinhive_reset_user_balance($address) {
global $coinhive_private_key;
global $coinhive_reset_balance_url;
$address_html=html_escape($address);
// Setup cURL
$ch=curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($ch,CURLOPT_POST,TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,"secret=$coinhive_private_key&name=$address_html");
curl_setopt($ch,CURLOPT_URL,$coinhive_reset_balance_url."?secret=$coinhive_private_key&name=$address_html");
$result = curl_exec ($ch);
if($result=="") return FALSE;
$data=json_decode($result);
if($data->success=="true") return TRUE;
else return FALSE;
}
// Get payout info
// Main information here is rate per 1 Mhash
function coinhive_get_payout_info() {
global $coinhive_private_key;
global $coinhive_get_payout_info_url;
// Setup cURL
$ch=curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($ch,CURLOPT_POST,FALSE);
curl_setopt($ch,CURLOPT_URL,$coinhive_get_payout_info_url."?secret=$coinhive_private_key");
$result = curl_exec ($ch);
if($result=="") return 0;
$data=json_decode($result);
return $data;
}
// Get site info
function coinhive_get_stats_site_info() {
global $coinhive_private_key;
global $coinhive_get_stats_site_info_url;
// Setup cURL
$ch=curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($ch,CURLOPT_POST,FALSE);
curl_setopt($ch,CURLOPT_URL,$coinhive_get_stats_site_info_url."?secret=$coinhive_private_key");
$result = curl_exec ($ch);
if($result=="") return 0;
$data=json_decode($result);
return $data;
}
?>