-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommon.php
307 lines (250 loc) · 6.81 KB
/
common.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
<?php
require_once 'jsonRPCClient.php';
define('CHIPSPERBTC', 100);
$sessionsalt = 'ikeeelyoumfkr';
$admin_email_addy = '[email protected]';
$mail_headers =
'From: BitPoker <[email protected]>' . "\r\n" .
'X-Mailer: BitPoker' . "\r\n" .
'Reply-To: ' . $admin_email_addy . "\r\n" .
'Errors-To: ' . $admin_email_addy;
function mail_payout($email, $user, $amount, $wallet, $txid)
{
global $mail_headers;
$message = "Hello,\n\nThis is a BTC withdrawal notification from https://www.bitpoker.com for $user.\n\n$amount BTC has just been sent to your Bitcoin wallet $wallet\n\nYou can track this payout on blockexplorer.com using the transaction ID $txid as per below:\n\nhttp://blockexplorer.com/tx/$txid\n\nThanks for playing!\n\n--\nbitpoker.com";
mail($email, "[BitPoker] Withdrawal Notification", $message, $mail_headers);
}
function mail_manual_payout($email, $user, $amount, $wallet)
{
global $mail_headers;
global $admin_email_addy;
$message = "Hello,\n\nThis is a notice that you have a pending BTC withdrawal from https://www.bitpoker.com for $user.\n\nA withdrawal of $amount BTC is now queued for manual processing and will be sent within 24 hours to address $wallet\n\nThanks for playing!\n\n--\nbitpoker.com";
$time = date("Y-m-d H:i:s +0000");
mail($email, "[BitPoker] Pending Withdrawal Notification", $message, $mail_headers);
mail($admin_email_addy, '[BitPoker] MANUAL PAYOUT REQUEST', "USER=$user\nAMOUNT=$amount\nWALLET=$wallet\nTIME=$time", $mail_headers);
}
function mail_error($msg)
{
global $admin_email_addy;
global $mail_headers;
mail($admin_email_addy, '[BitPoker] ERROR', $msg, $mail_headers);
}
function drawmenu()
{
echo '<ul id="a">';
if(isset($_SESSION['username']))
{
echo <<< DONE
<li class="mb1"><a href="index">Home</a></li>
<li class="mb1"><a href="tables">Play</a></li>
<li class="mb1"><a href="withdraw">Deposit/Withdraw</a></li>
<li class="mb1"><a href="rules">Rules</a></li>
<li class="mb1"><a href="contact">Contact</a></li>
<li class="mb1"><a href="logout">Log Out</a></li>
DONE;
}
else
{
echo <<< DONE
<li class="mb2"><a href="index">Home</a></li>
<li class="mb2"><a href="register">Register</a></li>
<li class="mb2"><a href="rules">Rules</a></li>
<li class="mb2"><a href="contact">Contact</a></li>
DONE;
}
echo '</ul>';
}
function hash_password($password, $nonce) {
$site_key = 'bozak187jewsdidwtc';
return hash_hmac('sha512', $password . $nonce, $site_key);
}
function generateSalt($max = 15) {
$characterList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$i = 0;
$salt = "";
do {
$salt .= $characterList{mt_rand(0,strlen($characterList)-1)};
$i++;
} while ($i <= $max);
return $salt;
}
function connectBitcoin()
{
$bitcoin = new jsonRPCClient('http://zomfgwtfbbq:[email protected]:8332/');
return $bitcoin;
}
function connectDB()
{
$con = mysql_connect("localhost","poker","12qwerty56qwaszx");
if($con)
{
mysql_select_db("poker", $con);
}
return $con;
}
function getBTCBalance($user=null)
{
if(is_null($user) && !isset($_SESSION['username']))
{
return null;
}
if(is_null($user))
{
$user = $_SESSION['username'];
}
if($user == '')
{
$bal = null;
$bitcoin = connectBitcoin();
try {
$bal = ($bitcoin->getbalance($user));
} catch (Exception $e) {
return null;
}
return BTCRound($bal);
}
$con = connectDB();
if(!$con)
{
return null;
}
$result = mysql_query("SELECT balanceBank from users WHERE username = '$user'", $con);
if(mysql_num_rows($result) == 1)
{
$row = mysql_fetch_array($result);
return (BTCRound($row['balanceBank'] / 100000000));
}
else
{
return null;
}
}
function BTCRound($value)
{
return floor(($value) * 1e8 + .5) * .00000001;
}
function chipRound($value)
{
// return round($value * 1e8);
return floor(($value) * 1e6 + .5) * .000001;
}
function getBalance()
{/*
$bitcoin = connectBitcoin();
$bal = null;
try {
$bal = ($bitcoin->getbalance($_SESSION['username']))*CHIPSPERBTC;
} catch (Exception $e) {
return null;
}*/
return floor(chipRound(getBTCBalance()*CHIPSPERBTC));
}
function getFlooredBalance()
{
return /*floor*/(getBalance());
}
/***********************************************************************************/
function SHA512_encode($str)
{
return base64_encode(bin2hex(hash('sha512',$str)));
}
function validate_session()
{
global $sessionsalt;
if(!isset($_SESSION)) {
session_start();}
if (!isset($_SESSION['SERVER_GENERATED_SID']))
{
reset_session();
}
if(isset($_SESSION['MOSSAD187']) && $_SESSION['MOSSAD187'] !== SHA512_encode($_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT'].$sessionsalt))
{
reset_session();
}
++$_SESSION['loads'];
if(isset($_SESSION['username']))
{
$u = $_SESSION['username'];
$s = session_id();
$con = connectDB();
if(!$con)
{
reset_session();
}
else
{
$ok = false;
if ($query = mysql_query("SELECT EXISTS(SELECT 1 FROM users WHERE username = '$u' AND session = '$s' LIMIT 1)", $con))
{
$result = mysql_fetch_row($query);
$ok = (bool)($result[0]);
}
else
{
$ok = false;
}
if(!$ok)
{
reset_session();
}
else
{
mysql_query("UPDATE users set lastactive=NOW() where username='$u'", $con);
}
}
}
}
/******************************************************************************/
function allow_session()
{
if(!isset($_SESSION['username']))
{
return false;
}
$user = $_SESSION['username'];
$ses = session_id();
$con = connectDB();
if(!$con)
{
return false;
}
$result = mysql_query("UPDATE users set session='$ses' where username='$user'", $con);
if(!$result) { return false; }
return true;
}
function reset_session()
{
global $sessionsalt;
/* if(isset($_COOKIE[session_name()]))
{
// Kill the cookie assocated to the session.
if (ini_get("session.use_cookies"))
{
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]);
}
}
session_start();
//Destroy the session itself.
session_regenerate_id();
//session_destroy();
unset($_SESSION);
$_SESSION = array();
session_destroy();
session_start();*/
if(!isset($_SESSION)) {
session_start();}
//session_regenerate_id();
//session_destroy();
unset($_SESSION);
session_destroy();
session_start();
session_regenerate_id();
$_SESSION['SERVER_GENERATED_SID'] = true;
$_SESSION['MOSSAD187'] = SHA512_encode($_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT'].$sessionsalt);
// Set number of loads to 0 in the session
$_SESSION['loads'] = 0;
}
?>