Browse Source

Remove Bitcoin/PayPal processing and storage

biotorrents 4 years ago
parent
commit
b1cc2083a7

+ 0
- 39
classes/bitcoinrpc.class.php View File

@@ -1,39 +0,0 @@
1
-<?php
2
-
3
-class BitcoinRpc
4
-{
5
-    public static function __callStatic($Method, $Args)
6
-    {
7
-        if (!defined('BITCOIN_RPC_URL')) {
8
-            return false;
9
-        }
10
-
11
-        $MessageID = mt_rand();
12
-        $Params = json_encode(
13
-            array(
14
-                'method' => $Method,
15
-                'params' => $Args,
16
-                'id' => $MessageID
17
-            )
18
-        );
19
-
20
-        $Request = array(
21
-            'http' => array(
22
-                'method' => 'POST',
23
-                'header' => 'Content-type: application/json',
24
-                'content' => $Params
25
-            )
26
-        );
27
-
28
-        if (!$Response = file_get_contents(BITCOIN_RPC_URL, false, stream_context_create($Request))) {
29
-            return false;
30
-        }
31
-
32
-        $Response = json_decode($Response);
33
-        if ($Response->id != $MessageID || !empty($Response->error) || empty($Response->result)) {
34
-            return false;
35
-        }
36
-        
37
-        return $Response->result;
38
-    }
39
-}

+ 0
- 7
classes/donations.class.php View File

@@ -272,13 +272,6 @@ class Donations
272 272
         G::$DB->set_query_id($QueryID);
273 273
     }
274 274
 
275
-    public static function schedule()
276
-    {
277
-        self::$IsSchedule = true;
278
-        DonationsBitcoin::find_new_donations();
279
-        self::expire_ranks();
280
-    }
281
-
282 275
     public static function expire_ranks()
283 276
     {
284 277
         $QueryID = G::$DB->get_query_id();

+ 0
- 214
classes/donationsbitcoin.class.php View File

@@ -1,214 +0,0 @@
1
-<?php
2
-
3
-class DonationsBitcoin
4
-{
5
-    /**
6
-     * Ask bitcoind for a list of all addresses that have received bitcoins
7
-     *
8
-     * @return array (BitcoinAddress => Amount, ...)
9
-     */
10
-    public static function get_received()
11
-    {
12
-        if (defined('BITCOIN_RPC_URL')) {
13
-            $Donations = BitcoinRpc::listreceivedbyaddress();
14
-        }
15
-
16
-        if (empty($Donations)) {
17
-            return [];
18
-        }
19
-
20
-        $BTCUsers = [];
21
-        foreach ($Donations as $Account) {
22
-            $BTCUsers[$Account->address] = $Account->amount;
23
-        }
24
-        return $BTCUsers;
25
-    }
26
-
27
-    /**
28
-     * Ask bitcoind for the current account balance
29
-     *
30
-     * @return float balance
31
-     */
32
-    public static function get_balance()
33
-    {
34
-        if (defined('BITCOIN_RPC_URL')) {
35
-            return BitcoinRpc::getbalance();
36
-        }
37
-    }
38
-
39
-    /**
40
-     * Get a user's existing bitcoin address or generate a new one
41
-     *
42
-     * @param int $UserID
43
-     * @param bool $GenAddress whether to create a new address if it doesn't exist
44
-     * @return false if no address exists and $GenAddress is false
45
-     *         string bitcoin address otherwise
46
-     */
47
-    public static function get_address($UserID, $GenAddress = false)
48
-    {
49
-        $UserID = (int)$UserID;
50
-        $QueryID = G::$DB->get_query_id();
51
-        G::$DB->query("
52
-        SELECT BitcoinAddress
53
-        FROM users_info
54
-          WHERE UserID = '$UserID'");
55
-
56
-        list($Addr) = G::$DB->next_record();
57
-        G::$DB->set_query_id($QueryID);
58
-
59
-        if (!empty($Addr)) {
60
-            return $Addr;
61
-        } elseif ($GenAddress) {
62
-            if (defined('BITCOIN_RPC_URL')) {
63
-                $NewAddr = BitcoinRpc::getnewaddress();
64
-            }
65
-
66
-            if (empty($NewAddr)) {
67
-                error(0);
68
-            }
69
-
70
-            $QueryID = G::$DB->get_query_id();
71
-            G::$DB->query("
72
-            UPDATE users_info
73
-            SET BitcoinAddress = '".db_string($NewAddr)."'
74
-              WHERE UserID = '$UserID'
75
-              AND BitcoinAddress IS NULL");
76
-
77
-            G::$DB->set_query_id($QueryID);
78
-            return $NewAddr;
79
-        } else {
80
-            return false;
81
-        }
82
-    }
83
-
84
-    /**
85
-     * Ask bitcoind for the total amount of bitcoins received
86
-     *
87
-     * @return float amount
88
-     */
89
-    public static function get_total_received()
90
-    {
91
-        if (defined('BITCOIN_RPC_URL')) {
92
-            $Accounts = BitcoinRpc::listreceivedbyaccount();
93
-        }
94
-
95
-        if (empty($Accounts)) {
96
-            return 0.0;
97
-        }
98
-
99
-        foreach ($Accounts as $Account) {
100
-            if ($Account->account === '') {
101
-                return $Account->amount;
102
-            }
103
-        }
104
-        return 0.0;
105
-    }
106
-
107
-    /**
108
-     * Translate bitcoin addresses to user IDs
109
-     *
110
-     * @param array $Addresses list of bitcoin addresses
111
-     * @return array (BitcoinAddress => UserID, ...)
112
-     */
113
-    public static function get_userids($Addresses)
114
-    {
115
-        if (!is_array($Addresses) || empty($Addresses)) {
116
-            return false;
117
-        }
118
-
119
-        $QueryID = G::$DB->get_query_id();
120
-        G::$DB->query("
121
-        SELECT BitcoinAddress, UserID
122
-        FROM users_info
123
-          WHERE BitcoinAddress IN ('" . implode("', '", $Addresses) . "')");
124
-
125
-        if (G::$DB->has_results()) {
126
-            $UserIDs = G::$DB->to_pair(0, 1);
127
-        } else {
128
-            $UserIDs = [];
129
-        }
130
-
131
-        G::$DB->set_query_id($QueryID);
132
-        return $UserIDs;
133
-    }
134
-
135
-    /**
136
-     * Find and process new donations since the last time this function was called.
137
-     */
138
-    public static function find_new_donations()
139
-    {
140
-        global $Debug;
141
-        if (($OldAmount = G::$Cache->get_value('btc_total_received')) === false) {
142
-            $QueryID = G::$DB->get_query_id();
143
-            G::$DB->query("
144
-            SELECT IFNULL(SUM(Amount), 0)
145
-            FROM donations_bitcoin");
146
-
147
-            list($OldAmount) = G::$DB->next_record(MYSQLI_NUM, false);
148
-            G::$DB->set_query_id($QueryID);
149
-        }
150
-
151
-        $NewAmount = self::get_total_received();
152
-        if ($NewAmount < $OldAmount) {
153
-            // This shouldn't happen. Perhaps bitcoind was restarted recently
154
-            // or the block index was removed. Either way, try again later
155
-            send_irc(DEBUG_CHAN, "Bad bitcoin donation data (is $NewAmount, was $OldAmount). If this persists, something is probably wrong.");
156
-            return false;
157
-        }
158
-
159
-        if ($NewAmount > $OldAmount) {
160
-            // I really wish we didn't have to do it like this
161
-            $QueryID = G::$DB->get_query_id();
162
-            G::$DB->query("
163
-            SELECT BitcoinAddress, SUM(Amount)
164
-            FROM donations_bitcoin
165
-              GROUP BY BitcoinAddress");
166
-
167
-            $OldDonations = G::$DB->to_pair(0, 1, false);
168
-            G::$DB->set_query_id($QueryID);
169
-            $NewDonations = self::get_received();
170
-
171
-            foreach ($NewDonations as $Address => &$Amount) {
172
-                if (isset($OldDonations[$Address])) {
173
-                    if ($Amount == $OldDonations[$Address]) { // Direct comparison should be fine as everything comes from bitcoind
174
-                        unset($NewDonations[$Address]);
175
-                        continue;
176
-                    }
177
-
178
-                    $Debug->log_var(array('old' => $OldDonations[$Address], 'new' => $Amount), "New donations from $Address");
179
-                    // PHP doesn't do fixed-point math, and json_decode has already botched the precision
180
-                    // so let's just round this off to satoshis and pray that we're on a 64 bit system
181
-                    $Amount = round($Amount - $OldDonations[$Address], 8);
182
-                }
183
-                $NewDonations[$Address] = $Amount;
184
-            }
185
-
186
-            $Debug->log_var($NewDonations, '$NewDonations');
187
-            foreach (self::get_userids(array_keys($NewDonations)) as $Address => $UserID) {
188
-                Donations::regular_donate($UserID, $NewDonations[$Address], 'Bitcoin Parser', '', 'BTC');
189
-                self::store_donation($Address, $NewDonations[$Address]);
190
-            }
191
-            G::$Cache->cache_value('btc_total_received', $NewAmount, 0);
192
-        }
193
-    }
194
-
195
-    /**
196
-     * Record a donation in the database
197
-     *
198
-     * @param string $Address bitcoin address
199
-     * @param double $Amount amount of bitcoins transferred
200
-     */
201
-    public static function store_donation($Address, $Amount)
202
-    {
203
-        if (!is_numeric($Amount) || $Amount <= 0) {
204
-            // Panic!
205
-            return false;
206
-        }
207
-
208
-        G::$DB->query("
209
-        INSERT INTO donations_bitcoin
210
-          (BitcoinAddress, Amount)
211
-        VALUES
212
-          ('$Address', $Amount)");
213
-    }
214
-}

+ 0
- 8
gazelle.sql View File

@@ -296,13 +296,6 @@ CREATE TABLE `donations` (
296 296
   KEY `Amount` (`Amount`)
297 297
 ) ENGINE=InnoDB CHARSET=utf8mb4;
298 298
 
299
-CREATE TABLE `donations_bitcoin` (
300
-  `BitcoinAddress` varchar(35) NOT NULL, -- https://en.bitcoin.it/wiki/Address
301
-  `Amount` decimal(24,8) NOT NULL,
302
-  KEY `BitcoinAddress` (`BitcoinAddress`,`Amount`)
303
-) ENGINE=InnoDB CHARSET=utf8mb4;
304
-
305 299
 -- 2020-03-09
306 300
 CREATE TABLE `donor_forum_usernames` (
307 301
   `UserID` int NOT NULL DEFAULT '0',
@@ -1429,7 +1422,6 @@ CREATE TABLE `users_info` (
1429 1422
   `ResetExpires` datetime,
1430 1423
   `JoinDate` datetime,
1431 1424
   `Inviter` int DEFAULT NULL,
1432
-  `BitcoinAddress` varchar(34) DEFAULT NULL,
1433 1425
   `WarnedTimes` int NOT NULL DEFAULT '0',
1434 1426
   `DisableAvatar` enum('0','1') NOT NULL DEFAULT '0',
1435 1427
   `DisableInvites` enum('0','1') NOT NULL DEFAULT '0',
@@ -1465,7 +1457,6 @@ CREATE TABLE `users_info` (
1465 1457
   KEY `Inviter` (`Inviter`),
1466 1458
   KEY `RatioWatchEnds` (`RatioWatchEnds`),
1467 1459
   KEY `RatioWatchDownload` (`RatioWatchDownload`),
1468
-  KEY `BitcoinAddress` (`BitcoinAddress`(4)),
1469 1460
   KEY `AuthKey` (`AuthKey`),
1470 1461
   KEY `ResetKey` (`ResetKey`)
1471 1462
 ) ENGINE=InnoDB CHARSET=utf8mb4;

+ 4
- 2
sections/donate/cancel.php View File

@@ -1,12 +1,14 @@
1 1
 <?php
2
+declare(strict_types=1);
2 3
 
3 4
 enforce_login();
4
-View::show_header('Donation Canceled');
5
-?>
5
+View::show_header('Donation Canceled'); ?>
6
+
6 7
 <div>
7 8
   <div class="header">
8 9
     <h3 id="forums">Donation Canceled</h3>
9 10
   </div>
11
+
10 12
   <div class="box">
11 13
     <p>
12 14
       It's the thought that counts.

+ 4
- 2
sections/donate/complete.php View File

@@ -1,12 +1,14 @@
1 1
 <?php
2
+declare(strict_types=1);
2 3
 
3 4
 enforce_login();
4
-View::show_header('Donation Complete');
5
-?>
5
+View::show_header('Donation Complete'); ?>
6
+
6 7
 <div>
7 8
   <div class="header">
8 9
     <h3 id="forums">Donation Complete</h3>
9 10
   </div>
11
+
10 12
   <div class="box">
11 13
     <p>
12 14
       Thank you for your donation!

+ 0
- 43
sections/donate/config.php View File

@@ -1,43 +0,0 @@
1
-<?php
2
-
3
-define('PAYPAL_ADDRESS', '');
4
-define('PAYPAL_CURRENCY', 'EUR');
5
-define('PAYPAL_SYMBOL', '&#8364;');
6
-define('PAYPAL_MINIMUM', 5);
7
-
8
-function btc_received()
9
-{
10
-}
11
-
12
-function btc_balance()
13
-{
14
-}
15
-
16
-// This will be rarely called, so let's go directly to the database
17
-function btc_address($UserID, $GenAddress = false)
18
-{
19
-    global $DB;
20
-    $UserID = (int)$UserID;
21
-    $DB->query("
22
-      SELECT BitcoinAddress
23
-      FROM users_info
24
-      WHERE UserID = '$UserID'");
25
-    list($Addr) = $DB->next_record();
26
-
27
-    if (!empty($Addr)) {
28
-        return $Addr;
29
-    } elseif ($GenAddress) {
30
-        if (empty($NewAddr)) {
31
-            error(0);
32
-        }
33
-    
34
-        $DB->query("
35
-          UPDATE users_info
36
-          SET BitcoinAddress = '".db_string($NewAddr)."'
37
-          WHERE UserID = '$UserID'
38
-            AND BitcoinAddress IS NULL");
39
-        return $NewAddr;
40
-    } else {
41
-        return false;
42
-    }
43
-}

+ 0
- 141
sections/donate/donate_gpal.php View File

@@ -1,141 +0,0 @@
1
-<?php
2
-
3
-/*
4
-// todo: Developer, add resend last donation when available AND add missing headers to Test IPN
5
-enforce_login();
6
-
7
-// Include the header
8
-if ($LoggedUser['RatioWatch']) {
9
-    error('Due to the high volume of payment disputes, we do not accept donations from users on ratio watch. Sorry.');
10
-}
11
-
12
-if (!$UserCount = $Cache->get_value('stats_user_count')) {
13
-    $DB->query("
14
-      SELECT COUNT(ID)
15
-      FROM users_main
16
-      WHERE Enabled = '1'");
17
-    list($UserCount) = $DB->next_record();
18
-    $Cache->cache_value('stats_user_count', $UserCount, 0); //inf cache
19
-}
20
-
21
-$DonorPerms = Permissions::get_permissions(DONOR);
22
-View::show_header('Donate');
23
-?>
24
-
25
-<!-- Donate -->
26
-<div>
27
-  <?php if (check_perms('site_debug')) { ?>
28
-  <div class="header">
29
-    <h2>Test IPN</h2>
30
-  </div>
31
-
32
-  <div class="box pad">
33
-    <form class="donate_form" name="test_paypal" method="post" action="donate.php">
34
-      <input type="hidden" name="action" value="ipn" />
35
-      <input type="hidden" name="auth"
36
-        value="<?=$LoggedUser['AuthKey']?>" />
37
-      <?=PAYPAL_SYMBOL?> <input type="text" name="mc_gross"
38
-        value="<?=number_format(PAYPAL_MINIMUM, 2)?>" />
39
-      <input type="hidden" name="custom"
40
-        value="<?=$LoggedUser['ID']?>" />
41
-      <input type="hidden" name="payment_status" value="Completed" />
42
-      <input type="hidden" name="mc_fee" value="0.45" />
43
-      <input type="hidden" name="business"
44
-        value="<?=PAYPAL_ADDRESS?>" />
45
-      <input type="hidden" name="txn_id" value="0" />
46
-      <input type="hidden" name="payment_type" value="instant" />
47
-      <input type="text" name="payer_email"
48
-        value="<?=$LoggedUser['Username']?>@<?=SITE_DOMAIN?>" />
49
-      <input type="hidden" name="mc_currency"
50
-        value="<?=PAYPAL_CURRENCY?>" />
51
-      <input name="test" type="submit" value="Donate" />
52
-    </form>
53
-  </div>
54
-  <?php
55
-}
56
-?>
57
-
58
-  <div class="header">
59
-    <h2>Donate</h2>
60
-  </div>
61
-  <div class="box">
62
-    <p>We accept donations to cover the costs associated with running the site and tracker. These costs come from the
63
-      rental and purchase of the hardware the site runs on (servers, components, etc.), in addition to operating
64
-      expenses (bandwidth, power, etc.).</p>
65
-    <p>Because we do not have any advertisements or sponsorships and this service is provided free of charge, we are
66
-      entirely reliant upon user donations. If you are financially able, please consider making a donation to help us
67
-      pay the bills!</p>
68
-    <p>We currently only accept one payment method: PayPal. Because of the fees they charge, there is a <strong>minimum
69
-        donation amount of <?=PAYPAL_SYMBOL?> <?=PAYPAL_MINIMUM?></strong> (Please note, this is only a minimum
70
-      amount and we greatly appreciate any extra you can afford.).</p>
71
-    <p>You don't have to be a PayPal member to make a donation, you can simply donate with your credit or debit card. If
72
-      you do not have a credit or debit card, you should be able to donate from your bank account, but you will need to
73
-      make an account with them to do this.</p>
74
-
75
-    <form class="donate_form" name="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
76
-      <input type="hidden" name="rm" value="2" />
77
-      <input type="hidden" name="cmd" value="_donations" />
78
-      <input type="hidden" name="business"
79
-        value="<?=PAYPAL_ADDRESS?>" />
80
-      <input type="hidden" name="return"
81
-        value="<?=site_url()?>donate.php?action=complete" />
82
-      <input type="hidden" name="cancel_return"
83
-        value="<?=site_url()?>donate.php?action=cancel" />
84
-      <input type="hidden" name="notify_url"
85
-        value="<?=site_url()?>donate.php?action=ipn" />
86
-      <input type="hidden" name="item_name" value="Donation" />
87
-      <input type="hidden" name="amount" value="" />
88
-      <input type="hidden" name="custom"
89
-        value="<?=$LoggedUser['ID']?>" />
90
-      <input type="hidden" name="no_shipping" value="0" />
91
-      <input type="hidden" name="no_note" value="1" />
92
-      <input type="hidden" name="currency_code"
93
-        value="<?=PAYPAL_CURRENCY?>" />
94
-      <input type="hidden" name="tax" value="0" />
95
-      <input type="hidden" name="bn" value="PP-DonationsBF" />
96
-      <input type="submit" value="PayPal Donate" />
97
-    </form>
98
-  </div>
99
-
100
-  ?>
101
-  <h3>What you will receive for a 5&euro; minimum donation</h3>
102
-  <div class="box">
103
-    <ul>
104
-      <?php if ($LoggedUser['Donor']) { ?>
105
-      <li>Even more love! (You will not get multiple hearts.)</li>
106
-      <li>A warmer, fuzzier feeling than before!</li>
107
-      <?php } else { ?>
108
-      <li>Our eternal love, as represented by the <img
109
-          src="<?=STATIC_SERVER?>common/symbols/donor.png"
110
-          alt="Donor" /> you get next to your name.</li>
111
-      <li>Two invitations to invite 2 good friends to use this tracker.</li>
112
-      <?php
113
-    if (USER_LIMIT != 0 && $UserCount >= USER_LIMIT && !check_perms('site_can_invite_always') && !isset($DonorPerms['site_can_invite_always'])) {
114
-        ?>
115
-      <li class="warning">Note: Because the user limit has been reached, you will be unable to use the invites received
116
-        until a later date.</li>
117
-      <?php
118
-    } ?>
119
-      <li>Immunity to inactivity pruning.</li>
120
-      <li>Access to an ever growing list of exclusive features, including the ability to submit requests and personal
121
-        collages.</li>
122
-      <li>A warm, fuzzy feeling.</li>
123
-
124
-      <?php } ?>
125
-    </ul>
126
-  </div>
127
-
128
-  <h3>What you will <strong>not</strong> receive</h3>
129
-  <div class="box">
130
-    <ul>
131
-      <?php if ($LoggedUser['Donor']) { ?>
132
-      <li>Two more invitations; these are one time only.</li>
133
-      <?php } ?>
134
-      <li>Immunity from the rules.</li>
135
-      <li>Additional upload credit.</li>
136
-    </ul>
137
-  </div>
138
-</div>
139
-<!-- END Donate -->
140
-<?php View::show_footer();
141
-*/

+ 0
- 7
sections/donate/index.php View File

@@ -7,17 +7,10 @@ if (!$ENV->FEATURE_DONATE) {
7 7
     error();
8 8
 }
9 9
 
10
-// Module mini-config
11
-include SERVER_ROOT.'/sections/donate/config.php';
12
-
13 10
 if (!isset($_REQUEST['action'])) {
14 11
     include SERVER_ROOT.'/sections/donate/donate.php';
15 12
 } else {
16 13
     switch ($_REQUEST['action']) {
17
-    case 'ipn': // PayPal hits this page when a donation is received
18
-      include SERVER_ROOT.'/sections/donate/ipn.php';
19
-      break;
20
-
21 14
     case 'complete':
22 15
       include SERVER_ROOT.'/sections/donate/complete.php';
23 16
       break;

+ 0
- 151
sections/donate/ipn.php View File

@@ -1,151 +0,0 @@
1
-<?php
2
-
3
-// Paypal hits this page once a donation has gone through.
4
-// This may appear to be light on the input validation, but the vast majority of that is handled through paypal confirmation
5
-// $_POST['txn_id'] centains the unique identifier if anyone ever needs it
6
-if (!is_number($_POST['custom'])) {
7
-    error(); // Seems too stupid a mistake to bother banning
8
-}
9
-
10
-$ENV = ENV::go();
11
-
12
-// Create request to return to paypal
13
-$Request = 'cmd=_notify-validate';
14
-foreach ($_POST as $Key => $Value) {
15
-    $Value = urlencode(stripslashes($Value));
16
-    $Request .= "&$Key=$Value";
17
-}
18
-
19
-// Headers
20
-$Headers = "POST /cgi-bin/webscr HTTP/1.1\r\n";
21
-$Headers .= "Host: www.paypal.com\r\n";
22
-$Headers .= "Content-Type: application/x-www-form-urlencoded\r\n";
23
-$Headers .= "Content-Length: ".strlen($Request)."\r\n";
24
-$Headers .= "Connection: close\r\n\r\n";
25
-
26
-// Socket
27
-$Socket = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
28
-
29
-// Send and process reply
30
-fwrite($Socket, $Headers.$Request);
31
-$Result = '';
32
-
33
-while (!feof($Socket)) {
34
-    $Result .= fgets($Socket, 1024);
35
-}
36
-
37
-if (strpos($Result, 'VERIFIED') !== false || check_perms('site_debug')) {
38
-    if ($_POST['mc_gross'] >= PAYPAL_MINIMUM) {
39
-        if ($_POST['mc_currency'] == PAYPAL_CURRENCY) {
40
-            if ($_POST['business'] == PAYPAL_ADDRESS) {
41
-                if (($_POST['payment_status'] == 'Completed') || ($_POST['payment_status'] == 'Pending')) {
42
-                    $DB->query('
43
-                      SELECT Donor
44
-                      FROM users_info
45
-                      WHERE UserID = \''.$_POST['custom'].'\'');
46
-
47
-                    list($Donor) = $DB->next_record();
48
-                    if ($Donor == 0) {
49
-                        //First time donor
50
-                        $DB->query('
51
-                          UPDATE users_main
52
-                          SET Invites = Invites + \''.DONOR_INVITES.'\'
53
-                          WHERE ID = \''.$_POST['custom'].'\'');
54
-
55
-                        $DB->query('
56
-                          UPDATE users_info
57
-                          SET Donor = \'1\'
58
-                          WHERE UserID = \''.$_POST['custom'].'\'');
59
-
60
-                        $DB->query('
61
-                          SELECT Invites
62
-                          FROM users_main
63
-                          WHERE ID = \''.$_POST['custom'].'\'');
64
-
65
-                        list($Invites) = $DB->next_record();
66
-                        $Cache->begin_transaction('user_info_'.$_POST['custom']);
67
-                        $Cache->update_row(false, array('Donor' => 1));
68
-                        $Cache->commit_transaction(0);
69
-                        $Cache->begin_transaction('user_info_heavy_'.$_POST['custom']);
70
-                        $Cache->update_row(false, array('Invites' => $Invites));
71
-                        $Cache->commit_transaction(0);
72
-                        Misc::send_pm($_POST['custom'], 0, 'Thank you for your donation', 'Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Because this is your first time donating, you have now been awarded Donor status as represented by the <3 found on your profile and next to your username where it appears. This has entitled you to a additional site features which you can now explore, and has granted you '.DONOR_INVITES." invitations to share with others. Thank you for supporting $ENV->SITE_NAME.");
73
-                    } else {
74
-                        // Repeat donor
75
-                        Misc::send_pm($_POST['custom'], 0, 'Thank you for your donation', 'Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Your continued support is highly appreciated and helps to make this place possible.');
76
-                    }
77
-                }
78
-            }
79
-        }
80
-    } else {
81
-        if ($_POST['mc_gross'] > 0) {
82
-            // Donation less than minimum
83
-            Misc::send_pm($_POST['custom'], 0, 'Thank you for your donation', 'Your donation from '.$_POST['payer_email'].' of '.$_POST['mc_gross'].' '.PAYPAL_CURRENCY.' has been successfully processed. Unfortunately however this donation was less than the specified minimum donation of '.PAYPAL_MINIMUM.' '.PAYPAL_CURRENCY.' and while we are grateful, no special privileges have been awarded to you.');
84
-        } else {
85
-            // Failed pending donation
86
-            $Message = "User ".site_url()."user.php?id=".$_POST['custom']." had donation of $TotalDonated ".PAYPAL_CURRENCY." at $DonationTime UTC from ".$_POST['payer_email'].' returned.';
87
-            $DB->query('
88
-              SELECT SUM(Amount), MIN(Time)
89
-              FROM donations
90
-              WHERE UserID = \''.$_POST['custom'].'\';');
91
-
92
-            list($TotalDonated, $DonationTime) = $DB->next_record();
93
-            if ($TotalDonated + $_POST['mc_gross'] == 0) {
94
-                $DB->query("
95
-                  SELECT Invites
96
-                  FROM users_main
97
-                  WHERE ID = '".$_POST['custom']."'");
98
-
99
-                list($Invites) = $DB->next_record();
100
-                if (($Invites - DONOR_INVITES) >= 0) {
101
-                    $NewInvites = $Invites - DONOR_INVITES;
102
-                } else {
103
-                    $NewInvites = 0;
104
-                    $Message .= ' They had already used at least one of their donation gained invites.';
105
-                }
106
-
107
-                $DB->query("
108
-                  UPDATE users_main
109
-                  SET Invites = $NewInvites
110
-                  WHERE ID = '".$_POST['custom']."'");
111
-
112
-                $DB->query('
113
-                  UPDATE users_info
114
-                  SET Donor = \'0\'
115
-                  WHERE UserID = \''.$_POST['custom'].'\'');
116
-
117
-                $Cache->begin_transaction('user_info_'.$_POST['custom']);
118
-                $Cache->update_row(false, array('Donor' => 0));
119
-                $Cache->commit_transaction(0);
120
-                $Cache->begin_transaction('user_info_heavy_'.$_POST['custom']);
121
-                $Cache->update_row(false, array('Invites' => $Invites));
122
-                $Cache->commit_transaction(0);
123
-                Misc::send_pm($_POST['custom'], 0, 'Notice of donation failure', 'PapPal has just notified us that the donation you sent from '.$_POST['payer_email'].' of '.$TotalDonated.' '.PAYPAL_CURRENCY.' at '.$DonationTime.' UTC has been revoked. Because of this your special privileges have been revoked, and your invites removed.');
124
-                send_irc(STAFF_CHAN, $Message);
125
-            }
126
-        }
127
-    }
128
-
129
-    $DB->query("
130
-      UPDATE users_info
131
-      SET AdminComment = CONCAT('".sqltime()." - User donated ".db_string($_POST['mc_gross'])." ".db_string(PAYPAL_CURRENCY)." from ".db_string($_POST['payer_email']).".\n',AdminComment)
132
-      WHERE UserID = '".$_POST['custom']."'");
133
-
134
-    $DB->query("
135
-      INSERT INTO donations
136
-        (UserID, Amount, Email, Time)
137
-      VALUES
138
-        ('".$_POST['custom']."', '".db_string($_POST['mc_gross'])."', '".db_string($_POST['payer_email'])."', NOW())");
139
-} else {
140
-    $DB->query("
141
-      INSERT INTO ip_bans
142
-        (FromIP, ToIP, Reason)
143
-      VALUES
144
-        ('".Tools::ip_to_unsigned($_SERVER['REMOTE_ADDR'])."', '".ip2long($_SERVER['REMOTE_ADDR'])."', 'Attempted to exploit donation system.')");
145
-}
146
-
147
-fclose($Socket);
148
-if (check_perms('site_debug')) {
149
-    include SERVER_ROOT.'/sections/donate/donate.php';
150
-}
151
-$Cache->cache_value('debug_donate', array($Result, $_POST), 0);

+ 0
- 3
sections/schedule/daily/donations.php View File

@@ -1,3 +0,0 @@
1
-<?php
2
-
3
-Donations::schedule();

+ 0
- 56
sections/tools/finances/bitcoin_balance.php View File

@@ -1,56 +0,0 @@
1
-<?
2
-if (!check_perms('admin_donor_log')) {
3
-  error(403);
4
-}
5
-$Title = "Bitcoin Donation Balance";
6
-View::show_header($Title);
7
-
8
-$Balance = DonationsBitcoin::get_balance() . ' BTC';
9
-?>
10
-<div class="header">
11
-  <h2><?=$Title?></h2>
12
-</div>
13
-<div>
14
-  <div class="header">
15
-    <h3><?=$Balance?></h3>
16
-  </div>
17
-<?
18
-if (empty($_GET['list'])) {
19
-?>
20
-  <a href="?action=<?=$_REQUEST['action']?>&amp;list=1" class="brackets">Show donor list</a>
21
-<?
22
-} else {
23
-  $BitcoinAddresses = DonationsBitcoin::get_received();
24
-  $DB->query("
25
-    SELECT i.UserID, i.BitcoinAddress
26
-    FROM users_info AS i
27
-      JOIN users_main AS m ON m.ID = i.UserID
28
-    WHERE BitcoinAddress != ''
29
-    ORDER BY m.Username ASC");
30
-?>
31
-  <table>
32
-  <tr class="colhead">
33
-    <th>Username</th>
34
-    <th>Receiving Bitcoin Address</th>
35
-    <th>Amount</th>
36
-  </tr>
37
-<?
38
-  while (list($UserID, $BitcoinAddress) = $DB->next_record(MYSQLI_NUM, false)) {
39
-    if (!isset($BitcoinAddresses[$BitcoinAddress])) {
40
-      continue;
41
-    }
42
-?>
43
-  <tr>
44
-    <td><?=Users::format_username($UserID, true, false, false, false)?></td>
45
-    <td><tt><?=$BitcoinAddress?></tt></td>
46
-    <td><?=$BitcoinAddresses[$BitcoinAddress]?> BTC</td>
47
-  </tr>
48
-<?
49
-  }
50
-?>
51
-  </table>
52
-<?
53
-}
54
-?>
55
-</div>
56
-<? View::show_footer(); ?>

+ 0
- 72
sections/tools/finances/bitcoin_unproc.php View File

@@ -1,72 +0,0 @@
1
-<?
2
-if (!check_perms('users_mod')) {
3
-  error(403);
4
-}
5
-$Title = "Unprocessed Bitcoin Donations";
6
-View::show_header($Title);
7
-
8
-// Find all donors
9
-$AllDonations = DonationsBitcoin::get_received();
10
-
11
-$DB->query("
12
-  SELECT BitcoinAddress, SUM(Amount)
13
-  FROM donations_bitcoin
14
-  GROUP BY BitcoinAddress");
15
-$OldDonations = G::$DB->to_pair(0, 1, false);
16
-?>
17
-<div>
18
-  <div class="header">
19
-    <h2><?=$Title?></h2>
20
-  </div>
21
-  <div class="box">
22
-    <div class="pad"><strong>Do not process these donations manually!</strong> The Bitcoin parser <em>will</em> get them sooner or later (poke a developer if something seems broken).</div>
23
-  </div>
24
-<?
25
-$NewDonations = [];
26
-$TotalUnproc = 0;
27
-foreach ($AllDonations as $Address => $Amount) {
28
-  if (isset($OldDonations[$Address])) {
29
-    if ($Amount == $OldDonations[$Address]) { // Direct comparison should be fine as everything comes from bitcoind
30
-      continue;
31
-    }
32
-    $Debug->log_var(array('old' => $OldDonations[$Address], 'new' => $Amount), "New donations from $Address");
33
-    // PHP doesn't do fixed-point math, and json_decode has already botched the precision
34
-    // so let's just round this off to satoshis and pray that we're on a 64 bit system
35
-    $Amount = round($Amount - $OldDonations[$Address], 8);
36
-  }
37
-  $TotalUnproc += $Amount;
38
-  $NewDonations[$Address] = $Amount;
39
-}
40
-?>
41
-  <table class="border" width="100%">
42
-    <tr class="colhead">
43
-      <td>Bitcoin Address</td>
44
-      <td>User</td>
45
-      <td>Unprocessed Amount (Total: <?=$TotalUnproc ?: '0'?>)</td>
46
-      <td>Total Amount</td>
47
-      <td>Donor Rank</td>
48
-      <td>Special Rank</td>
49
-    </tr>
50
-<?
51
-if (!empty($NewDonations)) {
52
-  foreach (DonationsBitcoin::get_userids(array_keys($NewDonations)) as $Address => $UserID) {
53
-    $DonationEUR = Donations::currency_exchange($NewDonations[$Address], 'BTC');
54
-?>
55
-    <tr>
56
-      <td><?=$Address?></td>
57
-      <td><?=Users::format_username($UserID, true, false, false)?></td>
58
-      <td><?=$NewDonations[$Address]?> (<?="$DonationEUR EUR"?>)</td>
59
-      <td><?=$AllDonations[$Address]?></td>
60
-      <td><?=(int)Donations::get_rank($UserID)?></td>
61
-      <td><?=(int)Donations::get_special_rank($UserID)?></td>
62
-    </tr>
63
-<?php }
64
-} else { ?>
65
-    <tr>
66
-      <td colspan="7">No unprocessed Bitcoin donations</td>
67
-    </tr>
68
-<? } ?>
69
-  </table>
70
-</div>
71
-<?
72
-View::show_footer();

+ 0
- 2
sections/tools/finances/donation_log.php View File

@@ -5,8 +5,6 @@ if (!check_perms('admin_donor_log')) {
5 5
     error(403);
6 6
 }
7 7
 
8
-include(SERVER_ROOT.'/sections/donate/config.php');
9
-
10 8
 define('DONATIONS_PER_PAGE', 50);
11 9
 list($Page, $Limit) = Format::page_limit(DONATIONS_PER_PAGE);
12 10
 

+ 0
- 8
sections/tools/index.php View File

@@ -381,14 +381,6 @@ switch ($_REQUEST['action']) {
381 381
     include SERVER_ROOT.'/sections/tools/finances/donation_log.php';
382 382
     break;
383 383
 
384
-  case 'bitcoin_unproc':
385
-    include SERVER_ROOT.'/sections/tools/finances/bitcoin_unproc.php';
386
-    break;
387
-
388
-  case 'bitcoin_balance':
389
-    include SERVER_ROOT.'/sections/tools/finances/bitcoin_balance.php';
390
-    break;
391
-
392 384
   case 'donor_rewards':
393 385
     include SERVER_ROOT.'/sections/tools/finances/donor_rewards.php';
394 386
     break;

+ 0
- 2
sections/tools/tools.php View File

@@ -100,8 +100,6 @@ View::show_header('Staff Tools');
100 100
 
101 101
   // begin Finances category
102 102
   $ToolsHTML = "";
103
-  create_row("Bitcoin donations (balance)", "tools.php?action=bitcoin_balance", check_perms("admin_donor_log"));
104
-  create_row("Bitcoin donations (unprocessed)", "tools.php?action=bitcoin_unproc", check_perms("admin_donor_log"));
105 103
   create_row("Donation log", "tools.php?action=donation_log", check_perms("admin_donor_log"));
106 104
   create_row("Donor rewards", "tools.php?action=donor_rewards", check_perms("users_mod"));
107 105
 

Loading…
Cancel
Save