-
Notifications
You must be signed in to change notification settings - Fork 10
/
donatecheck.php
276 lines (274 loc) · 16.8 KB
/
donatecheck.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
<?php
/**
* ------- U-232 Codename Trinity ----------*
* ---------------------------------------------*
* -------- @authors U-232 Team --------------*
* ---------------------------------------------*
* ----- @site https://u-232.duckdns.org/ ----*
* ---------------------------------------------*
* ----- @copyright 2020 U-232 Team ----------*
* ---------------------------------------------*
* ------------ @version V6 ------------------*
*/
require_once(__DIR__.DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
require_once(CACHE_DIR.'paypal_settings.php');
dbconn();
//$payment_status = "Completed";//Only uncomment if using sandbox mode
$donate_goods = [
$TRINITY20['paypal_config']['gb_donated_1'] => [
'to_add' => [
'uploaded' => $TRINITY20['paypal_config']['up_amt_1'] * 1_073_741_824,
'invites' => $TRINITY20['paypal_config']['inv_amt_1'],
'seedbonus' => $TRINITY20['paypal_config']['kp_amt_1'],
'total_donated' => $TRINITY20['paypal_config']['gb_donated_1'],
],
'to_update' => [
'donated' => $TRINITY20['paypal_config']['gb_donated_1'],
'warned' => 0,
'downloadpos' => 1,
'uploadpos' => 1,
'leechwarn' => 0,
'hit_and_run_total' => 0,
'hnrwarn' => '\'no\'',
'enabled' => '\'yes\'',
'class' => 'IF(class < '.UC_VIP.', '.UC_VIP.', class), vipclass_before = IF(class < '.UC_VIP.', class, 0)',
'donoruntil' => sprintf('IF(donoruntil > 0,donoruntil + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['duntil_dur_1'], $TRINITY20['paypal_config']['duntil_dur_1']),
'vip_until' => sprintf('IF(vip_until > 0,vip_until + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['vip_dur_1'], $TRINITY20['paypal_config']['vip_dur_1']),
'free_switch' => sprintf('IF(free_switch > 0,free_switch + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['free_dur_1'], $TRINITY20['paypal_config']['free_dur_1']),
'immunity' => sprintf('IF(immunity > 0,immunity + (%d * 604800), '.TIME_NOW.' + (%d * 604800))', $TRINITY20['paypal_config']['imm_dur_1'],
$TRINITY20['paypal_config']['imm_dur_1']),
'donor' => '\'yes\'',
'modcomment' => "CONCAT('".get_date(TIME_NOW, 'DATE',
1)." - User donated ".$TRINITY20['paypal_config']['gb_donated_1']." ".$TRINITY20['paypal_config']['currency']."\n',modcomment)",
],
],
$TRINITY20['paypal_config']['gb_donated_2'] => [
'to_add' => [
'uploaded' => $TRINITY20['paypal_config']['up_amt_2'] * 1_073_741_824,
'invites' => $TRINITY20['paypal_config']['inv_amt_2'],
'seedbonus' => $TRINITY20['paypal_config']['kp_amt_2'],
'total_donated' => $TRINITY20['paypal_config']['gb_donated_2'],
],
'to_update' => [
'donated' => $TRINITY20['paypal_config']['gb_donated_2'],
'warned' => 0,
'downloadpos' => 1,
'uploadpos' => 1,
'leechwarn' => 0,
'hit_and_run_total' => 0,
'hnrwarn' => '\'no\'',
'enabled' => '\'yes\'',
'class' => 'IF(class < '.UC_VIP.', '.UC_VIP.', class), vipclass_before = IF(class < '.UC_VIP.', class, 0)',
'donoruntil' => sprintf('IF(donoruntil > 0,donoruntil + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['duntil_dur_2'], $TRINITY20['paypal_config']['duntil_dur_2']),
'vip_until' => sprintf('IF(vip_until > 0,vip_until + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['vip_dur_2'], $TRINITY20['paypal_config']['vip_dur_2']),
'free_switch' => sprintf('IF(free_switch > 0,free_switch + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['free_dur_2'], $TRINITY20['paypal_config']['free_dur_2']),
'immunity' => sprintf('IF(immunity > 0,immunity + (%d * 604800), '.TIME_NOW.' + (%d * 604800))', $TRINITY20['paypal_config']['imm_dur_2'],
$TRINITY20['paypal_config']['imm_dur_2']),
'donor' => '\'yes\'',
'modcomment' => "CONCAT('".get_date(TIME_NOW, 'DATE',
1)." - User donated ".$TRINITY20['paypal_config']['gb_donated_2']." ".$TRINITY20['paypal_config']['currency']."\n',modcomment)",
],
],
$TRINITY20['paypal_config']['gb_donated_3'] => [
'to_add' => [
'uploaded' => $TRINITY20['paypal_config']['up_amt_3'] * 1_073_741_824,
'invites' => $TRINITY20['paypal_config']['inv_amt_3'],
'seedbonus' => $TRINITY20['paypal_config']['kp_amt_3'],
'total_donated' => $TRINITY20['paypal_config']['gb_donated_3'],
],
'to_update' => [
'donated' => $TRINITY20['paypal_config']['gb_donated_3'],
'warned' => 0,
'downloadpos' => 1,
'uploadpos' => 1,
'leechwarn' => 0,
'hit_and_run_total' => 0,
'hnrwarn' => '\'no\'',
'enabled' => '\'yes\'',
'class' => 'IF(class < '.UC_VIP.', '.UC_VIP.', class), vipclass_before = IF(class < '.UC_VIP.', class, 0)',
'donoruntil' => sprintf('IF(donoruntil > 0,donoruntil + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['duntil_dur_3'], $TRINITY20['paypal_config']['duntil_dur_3']),
'vip_until' => sprintf('IF(vip_until > 0,vip_until + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['vip_dur_3'], $TRINITY20['paypal_config']['vip_dur_3']),
'free_switch' => sprintf('IF(free_switch > 0,free_switch + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['free_dur_3'], $TRINITY20['paypal_config']['free_dur_3']),
'immunity' => sprintf('IF(immunity > 0,immunity + (%d * 604800), '.TIME_NOW.' + (%d * 604800))', $TRINITY20['paypal_config']['imm_dur_3'],
$TRINITY20['paypal_config']['imm_dur_3']),
'donor' => '\'yes\'',
'modcomment' => "CONCAT('".get_date(TIME_NOW, 'DATE',
1)." - User donated ".$TRINITY20['paypal_config']['gb_donated_3']." ".$TRINITY20['paypal_config']['currency']."\n',modcomment)",
],
],
$TRINITY20['paypal_config']['gb_donated_4'] => [
'to_add' => [
'uploaded' => $TRINITY20['paypal_config']['up_amt_4'] * 1_073_741_824,
'invites' => $TRINITY20['paypal_config']['inv_amt_4'],
'seedbonus' => $TRINITY20['paypal_config']['kp_amt_4'],
'total_donated' => $TRINITY20['paypal_config']['gb_donated_4'],
],
'to_update' => [
'donated' => $TRINITY20['paypal_config']['gb_donated_4'],
'warned' => 0,
'downloadpos' => 1,
'uploadpos' => 1,
'leechwarn' => 0,
'hit_and_run_total' => 0,
'hnrwarn' => '\'no\'',
'enabled' => '\'yes\'',
'class' => 'IF(class < '.UC_VIP.', '.UC_VIP.', class), vipclass_before = IF(class < '.UC_VIP.', class, 0)',
'donoruntil' => sprintf('IF(donoruntil > 0,donoruntil + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['duntil_dur_4'], $TRINITY20['paypal_config']['duntil_dur_4']),
'vip_until' => sprintf('IF(vip_until > 0,vip_until + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['vip_dur_4'], $TRINITY20['paypal_config']['vip_dur_4']),
'free_switch' => sprintf('IF(free_switch > 0,free_switch + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['free_dur_4'], $TRINITY20['paypal_config']['free_dur_4']),
'immunity' => sprintf('IF(immunity > 0,immunity + (%d * 604800), '.TIME_NOW.' + (%d * 604800))', $TRINITY20['paypal_config']['imm_dur_4'],
$TRINITY20['paypal_config']['imm_dur_4']),
'donor' => '\'yes\'',
'modcomment' => "CONCAT('".get_date(TIME_NOW, 'DATE',
1)." - User donated ".$TRINITY20['paypal_config']['gb_donated_4']." ".$TRINITY20['paypal_config']['currency']."\n',modcomment)",
],
],
$TRINITY20['paypal_config']['gb_donated_5'] => [
'to_add' => [
'uploaded' => $TRINITY20['paypal_config']['up_amt_5'] * 1_073_741_824,
'invites' => $TRINITY20['paypal_config']['inv_amt_5'],
'seedbonus' => $TRINITY20['paypal_config']['kp_amt_5'],
'total_donated' => $TRINITY20['paypal_config']['gb_donated_5'],
],
'to_update' => [
'donated' => $TRINITY20['paypal_config']['gb_donated_5'],
'warned' => 0,
'downloadpos' => 1,
'uploadpos' => 1,
'leechwarn' => 0,
'hit_and_run_total' => 0,
'hnrwarn' => '\'no\'',
'enabled' => '\'yes\'',
'class' => 'IF(class < '.UC_VIP.', '.UC_VIP.', class), vipclass_before = IF(class < '.UC_VIP.', class, 0)',
'donoruntil' => sprintf('IF(donoruntil > 0,donoruntil + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['duntil_dur_5'], $TRINITY20['paypal_config']['duntil_dur_5']),
'vip_until' => sprintf('IF(vip_until > 0,vip_until + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['vip_dur_5'], $TRINITY20['paypal_config']['vip_dur_5']),
'free_switch' => sprintf('IF(free_switch > 0,free_switch + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['free_dur_5'], $TRINITY20['paypal_config']['free_dur_5']),
'immunity' => sprintf('IF(immunity > 0,immunity + (%d * 604800), '.TIME_NOW.' + (%d * 604800))', $TRINITY20['paypal_config']['imm_dur_5'],
$TRINITY20['paypal_config']['imm_dur_5']),
'donor' => '\'yes\'',
'modcomment' => "CONCAT('".get_date(TIME_NOW, 'DATE',
1)." - User donated ".$TRINITY20['paypal_config']['gb_donated_5']." ".$TRINITY20['paypal_config']['currency']."\n',modcomment)",
],
],
$TRINITY20['paypal_config']['gb_donated_6'] => [
'to_add' => [
'uploaded' => $TRINITY20['paypal_config']['up_amt_6'] * 1_073_741_824,
'invites' => $TRINITY20['paypal_config']['inv_amt_6'],
'seedbonus' => $TRINITY20['paypal_config']['kp_amt_6'],
'total_donated' => $TRINITY20['paypal_config']['gb_donated_6'],
],
'to_update' => [
'donated' => $TRINITY20['paypal_config']['gb_donated_6'],
'warned' => 0,
'downloadpos' => 1,
'uploadpos' => 1,
'leechwarn' => 0,
'hit_and_run_total' => 0,
'hnrwarn' => '\'no\'',
'enabled' => '\'yes\'',
'class' => 'IF(class < '.UC_VIP.', '.UC_VIP.', class), vipclass_before = IF(class < '.UC_VIP.', class, 0)',
'donoruntil' => sprintf('IF(donoruntil > 0,donoruntil + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['duntil_dur_6'], $TRINITY20['paypal_config']['duntil_dur_6']),
'vip_until' => sprintf('IF(vip_until > 0,vip_until + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['vip_dur_6'], $TRINITY20['paypal_config']['vip_dur_6']),
'free_switch' => sprintf('IF(free_switch > 0,free_switch + (%d * 604800), '.TIME_NOW.' + (%d * 604800))',
$TRINITY20['paypal_config']['free_dur_6'], $TRINITY20['paypal_config']['free_dur_6']),
'immunity' => sprintf('IF(immunity > 0,immunity + (%d * 604800), '.TIME_NOW.' + (%d * 604800))', $TRINITY20['paypal_config']['imm_dur_6'],
$TRINITY20['paypal_config']['imm_dur_6']),
'donor' => '\'yes\'',
'modcomment' => "CONCAT('".get_date(TIME_NOW, 'DATE',
1)." - User donated ".$TRINITY20['paypal_config']['gb_donated_6']." ".$TRINITY20['paypal_config']['currency']."\n',modcomment)",
],
],
];
function mk_update_query($amount, $user_id)
{
global $donate_goods;
$query = [];
foreach ($donate_goods[$amount]['to_add'] as $field => $value) {
$query[] = sprintf('%s = %s + %d', $field, $field, $value);
}
foreach ($donate_goods[$amount]['to_update'] as $field => $value) {
$query[] = sprintf('%s = %s', $field, $value);
}
return sprintf('update users set %s where id = %d', implode(', ', $query), $user_id);
}
function paypallog($txt)
{
file_put_contents(ROOT_DIR.'/logs/paypal.txt', "\n[".date('h:m D-M-Y')."]\n".$txt, FILE_APPEND);
}
if (count($_POST) == 0) {
paypallog('There is no _POST from paypal');
}
$request = 'cmd=_notify-validate';
foreach ($_POST as $p_key => $p_value) {
$request .= '&'.$p_key.'='.urlencode(stripslashes($p_value));
}
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($request)."\r\n\r\n";
if ($hand = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30)) {
fwrite($hand, $header.$request);
$paypal_data = '';
while (!feof($hand)) {
$paypal_data .= fgets($hand, 128);
}
$vars['uid'] = isset($_POST['custom']) ? (int)$_POST['custom'] : 0;
$vars['amount'] = isset($_POST['mc_gross']) ? (int)$_POST['mc_gross'] : 0;
$vars['memo'] = isset($_POST['memo']) ? htmlsafechars($_POST['memo']) : '';
if (stripos($paypal_data, 'VERIFIED') !== false) {
($user_query = sql_query(sprintf('SELECT COUNT(id) FROM users WHERE id = %d', $vars['uid']))) || paypallog($mysqli->error);
if ($user_query->num_rows == 1) {
//update the user and add the goodies
sql_query(mk_update_query($vars['amount'], $vars['uid'])) || paypallog($mysqli->error);
//instead of updating the cache delete it :P
$cache->delete($cache_keys['my_userid'].$vars['uid']);
$cache->delete($cache_keys['user'].$vars['uid']);
$cache->delete($cache_keys['user_stats'].$vars['uid']);
$cache->delete($cache_keys['user_statss'].$vars['uid']);
//update total funds
sql_query(sprintf('INSERT INTO funds(cash,user,added) VALUES (%d,%d,%d)', $vars['amount'], $vars['uid'],
TIME_NOW)) || paypallog($mysqli->error);
//clear the cache for the funds
$cache->delete($cache_keys['ttl_funds']);
$msg[] = '('.$vars['uid'].',0,'.sqlesc('Donation - processed').','.sqlesc("Your donation was processed by paypal and our system\nWe remind you that you donated ".$vars['amount'].$TRINITY20['paypal_config']['currency']."\nIf you forgot what you'll get check the donation page again\nStaff from ".$TRINITY20['site_name']." is grateful for your donation\nIf you have any question's feel free to contact someone from staff").','.TIME_NOW.')';
$msg[] = '('.$TRINITY20['paypal_config']['staff'].',0,'.sqlesc('Donation - made').','.sqlesc("This [url=".$TRINITY20['baseurl']."/userdetails.php?id=".(int)$vars['uid']."]user[/url] - donated ".$vars['amount'].$TRINITY20['paypal_config']['currency'].(empty($vars['memo']) ? '' : "\nUser sent a message with his donation:\n[b]".$vars['memo']."[/b]")).','.TIME_NOW.')';
} else {
paypallog('Could not find user with id = '.$vars['uid']);
}
} elseif (stripos($paypal_data, 'INVALID') !== false) {
//something went wrong log data
paypallog('Paypal didn\'t like the transaction and it rejected it. _POST = '.print_r($_POST, 1));
//make some nice messages to let everyone know about the problem
$msg[] = '('.$vars['uid'].',0,'.sqlesc('Donation - problem').','.sqlesc("We are sorry to announce you that paypal rejected the donation please contact the staff\n".$TRINITY20['site_name']."'s staff").','.TIME_NOW.')';
$msg[] = '('.$TRINITY20['paypal_config']['staff'].',0,'.sqlesc('Donation - problem').','.sqlesc("This [url=".$TRINITY20['baseurl']."/userdetails.php?id=".(int)$vars['uid']."]user[/url] - donated but there was a problem with paypal. Check paypal log!").','.TIME_NOW.')';
}
sql_query('INSERT INTO messages(receiver,sender,subject,msg,added) VALUES '.implode(',', $msg)) || paypallog($mysqli->error);
//clear memcache for staff
$cache->delete($cache_keys['inbox_new'].$TRINITY20['paypal_config']['staff']);
$cache->delete($cache_keys['inbox_new_sb'].$TRINITY20['paypal_config']['staff']);
//and for the user that donated
$cache->delete($cache_keys['inbox_new'].$vars['uid']);
$cache->delete($cache_keys['inbox_new_sb'].$vars['uid']);
$cache->delete('shoutbox_');
fclose($hand);
} else {
paypallog('Can\'t open hand');
}
?>