-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathusers.php
279 lines (242 loc) · 10.5 KB
/
users.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
<?php
if (isset($_POST['verify_user']) || isset($_POST['unverify_user']))
if (isset($_POST['csrf_token'])) {
if ($_SESSION['csrf_token'] != $_POST['csrf_token'])
throw new Error("csrf","csrf token mismatch!");
}
else
throw new Error("csrf","csrf token missing!");
function show_verify_user_form()
{
handle_verify_user_request();
echo "<div class='content_box'>\n";
echo " <h3>" . _("Verify User") . "</h3>\n";
echo " <form action='' class='indent_form' method='post'>\n";
echo " <input type='hidden' name='verify_user' value='true' />\n";
echo " <input type='hidden' name='csrf_token' value=\"" . $_SESSION['csrf_token'] . "\" />\n";
echo " <label for='uid'>" . _("User ID") . "</label>\n";
echo " <input id='uid' type='text' name='uid' />\n";
echo " <input type='submit' value='Verify User' />\n";
echo " </form>\n";
echo "<div class='content_box'>\n";
echo " <h3>" . _("Unverify User") . "</h3>\n";
echo " <form action='' class='indent_form' method='post'>\n";
echo " <input type='hidden' name='unverify_user' value='true' />\n";
echo " <input type='hidden' name='csrf_token' value=\"" . $_SESSION['csrf_token'] . "\" />\n";
echo " <label for='uid'>" . _("User ID") . "</label>\n";
echo " <input id='uid' type='text' name='uid' />\n";
echo " <input type='submit' value='Unverify User' />\n";
echo " </form>\n";
echo "</div>\n";
}
function handle_verify_user_request()
{
if (isset($_POST['unverify_user'])) {
echo "<div class='content_box'>\n";
echo " <h3>" . _("Results") . "</h3>\n";
$uid = post('uid');
try {
$verified = get_verified_for_user($uid);
if (!$verified)
echo "<p>User $uid was not already verified. Any more?</p>\n";
else {
if (unverify_user($uid) == 1)
echo "<p>Unverified user $uid. Any more?</p>\n";
else
throw new Error("Unknown Error", "This shouldn't happen. Please report it.");
}
} catch (Exception $e) {
echo "<p>{$e->getMessage()}. Try again?</p>\n";
}
} else if (isset($_POST['verify_user'])) {
echo "<div class='content_box'>\n";
echo " <h3>" . _("Results") . "</h3>\n";
$uid = post('uid');
try {
$verified = get_verified_for_user($uid);
if ($verified)
echo "<p>User $uid was already verified. Any more?</p>\n";
else {
if (verify_user($uid) == 1)
echo "<p>Verified user $uid. Any more?</p>\n";
else
throw new Error("Unknown Error", "This shouldn't happen. Please report it.");
}
} catch (Exception $e) {
echo "<p>{$e->getMessage()}. Try again?</p>\n";
}
}
}
function show_users_header()
{
echo "<tr>";
echo "<th></th>";
// echo "<th></th>";
echo "<th colspan='3' style='text-align: center;'>" . CURRENCY . "</th>";
echo "<th colspan='3' style='text-align: center;'>BTC</th>";
echo "</tr>\n";
echo "<tr>";
echo "<th>" . _("UID") . "</th>";
// echo "<th>" . _("OID") . "</th>";
echo "<th class='right'>" . _("On Hand") . "</th>";
echo "<th class='right'>" . _("In Book") . "</th>";
echo "<th class='right'>" . _("Total") . "</th>";
echo "<th class='right'>" . _("On Hand") . "</th>";
echo "<th class='right'>" . _("In Book") . "</th>";
echo "<th class='right'>" . _("Total") . "</th>";
// echo "<th>" . _("Registered") . "</th>";
echo "</tr>\n";
}
function show_users()
{
$omit_zero_balances = true;
$omit_very_low_balances = true;
echo "<div class='content_box'>\n";
echo "<h3>" . _("Users") . "</h3>\n";
$query = "
SELECT
u.uid, oidlogin, is_admin, timest, a.amount as fiat, b.amount as btc
FROM
users as u
JOIN
purses as a
ON
a.uid = u.uid AND a.type = '" . CURRENCY . "'
JOIN
purses as b
ON
b.uid = u.uid AND b.type = 'BTC'
ORDER BY
is_admin DESC, u.uid;
";
$result = do_query($query);
$fiat_total = $c_fiat_total = $t_fiat_total = '0';
$btc_total = $c_btc_total = $t_btc_total = '0';
$first = true;
$count_users = $count_funded_users = $count_low_balance_users = $count_shown_users = 0;
// omit users who don't have more than just least-significant-digit amounts of anything
$tiny_fiat = pow(10, 8 - FIAT_PRECISION) * 10;
$tiny_btc = pow(10, 8 - BTC_PRECISION) * 10;
while ($row = mysql_fetch_assoc($result)) {
$uid = $row['uid'];
$oidlogin = $row['oidlogin'];
$is_admin = $row['is_admin'];
$timest = $row['timest'];
$fiat = $row['fiat'];
$btc = $row['btc'];
$committed = fetch_committed_balances($uid);
$c_fiat = $committed[CURRENCY];
$c_btc = $committed['BTC'];
$t_fiat = gmp_add($fiat, $c_fiat);
$t_btc = gmp_add($btc, $c_btc);
if ($uid == '1')
$uid = "fees";
else
$count_users++;
if ($omit_zero_balances && $fiat == 0 && $c_fiat == 0 && $btc == 0 && $c_btc == 0)
continue;
if ($first) {
$first = false;
echo "<table class='display_data'>\n";
show_users_header();
}
$fiat_total = gmp_add($fiat_total, $fiat);
$c_fiat_total = gmp_add($c_fiat_total, $c_fiat);
$t_fiat_total = gmp_add($t_fiat_total, $t_fiat);
$btc_total = gmp_add($btc_total, $btc);
$c_btc_total = gmp_add($c_btc_total, $c_btc);
$t_btc_total = gmp_add($t_btc_total, $t_btc);
if ($uid != 'fees') {
$count_funded_users++;
if ($fiat < $tiny_fiat &&
$c_fiat < $tiny_fiat &&
$btc < $tiny_btc &&
$c_btc < $tiny_btc) {
$count_low_balance_users++;
if ($omit_very_low_balances)
continue;
}
$count_shown_users++;
}
if ($uid == 'fees')
$url = "?page=commission";
else
$url = "?page=statement&user=$uid";
if ($is_admin)
active_table_row('me', $url);
else
active_table_row('active', $url);
echo "<td>$uid</td>";
// echo "<td>$oidlogin</td>";
echo "<td class='right'>", internal_to_numstr($fiat, FIAT_PRECISION), "</td>";
echo "<td class='right'>", internal_to_numstr($c_fiat, FIAT_PRECISION), "</td>";
echo "<td class='right'>", internal_to_numstr($t_fiat, FIAT_PRECISION), "</td>";
echo "<td class='right'>", internal_to_numstr($btc, BTC_PRECISION), "</td>";
echo "<td class='right'>", internal_to_numstr($c_btc, BTC_PRECISION), "</td>";
echo "<td class='right'>", internal_to_numstr($t_btc, BTC_PRECISION), "</td>";
// echo "<td>$timest</td>";
echo "</tr>\n";
if (!($count_shown_users % RESHOW_COLUMN_HEADINGS_AFTER_ROWS))
show_users_header();
}
if (!$first) {
echo "<tr><td></td><td class='right'>--------</td><td class='right'>--------</td><td class='right'>--------</td><td class='right'>--------</td><td class='right'>--------</td><td class='right'>--------</td></tr>\n";
active_table_row('me', "?page=statement&user=all");
echo "<td></td>";
echo "<td class='right'>", internal_to_numstr($fiat_total, FIAT_PRECISION), "</td>";
echo "<td class='right'>", internal_to_numstr($c_fiat_total, FIAT_PRECISION), "</td>";
echo "<td class='right'>", internal_to_numstr($t_fiat_total, FIAT_PRECISION), "</td>";
echo "<td class='right'>", internal_to_numstr($btc_total, BTC_PRECISION), "</td>";
echo "<td class='right'>", internal_to_numstr($c_btc_total, BTC_PRECISION), "</td>";
echo "<td class='right'>", internal_to_numstr($t_btc_total, BTC_PRECISION), "</td>";
echo "</tr>\n";
echo "</table>\n";
echo "<p>" . _("Admins are shown in bold type, and at the top of the table.") . "</p>\n";
}
echo "<p>" . sprintf(_("There are %s users with funds, and %s in total."),
$count_funded_users,
$count_users) . "</p>\n";
if ($omit_very_low_balances && $count_low_balance_users)
echo "<p>" . sprintf(_("%d user(s) have very low balances, and aren't shown above."),
$count_low_balance_users) . "</p>\n";
$balance0 = bitcoin_get_balance('*', 0);
$balance1 = bitcoin_get_balance('*', 1);
$balance = bitcoin_get_balance('', 0);
$unconfirmed = gmp_sub($balance0, $balance1);
echo "<p>" . sprintf(_("The Bitcoin wallet has %s BTC"), internal_to_numstr($balance0, BTC_PRECISION));
if (gmp_cmp($unconfirmed, 0) != 0)
printf(_(", %s BTC of which currently has 0 confirmations"), internal_to_numstr($unconfirmed, BTC_PRECISION));
echo ".<br/></p>\n";
if ($balance0 == $balance)
$balance = $balance0;
else {
$pending = gmp_sub($balance0, $balance);
echo "<p>" . sprintf(_("The main wallet account has %s BTC; other accounts have %s BTC awaiting confirmations."),
internal_to_numstr($balance, BTC_PRECISION),
internal_to_numstr($pending, BTC_PRECISION)) . "</p>";
}
// take off the amount that's waiting to be withdrawn. it's in the wallet, but not in user accounts
$pending_withdrawal = btc_pending_withdrawal();
$balance = gmp_sub($balance, $pending_withdrawal);
if ($pending_withdrawal)
echo "<p>" . sprintf(_("There are pending BTC withdrawals worth %s BTC, which will reduce the wallet balance to %s BTC."),
internal_to_numstr($pending_withdrawal, BTC_PRECISION),
internal_to_numstr($balance, BTC_PRECISION)) . "</p>";
$diff = gmp_sub($t_btc_total, $balance);
$cmp = gmp_cmp($diff, 0);
if ($cmp == 0)
echo "<p>" . _("That's the exact right amount.") . "</p>\n";
else if ($cmp > 0)
echo "<p>" .
sprintf(_("That's %s BTC less than is on deposit."), internal_to_numstr($diff, BTC_PRECISION)) .
"</p>\n";
else
echo "<p>" .
sprintf(_("That's %s BTC more than is on deposit"), internal_to_numstr(gmp_mul("-1", $diff), BTC_PRECISION)) .
"</p>\n";
echo "</div>\n";
}
if (REQUIRE_IDENTIFICATION)
show_verify_user_form();
show_users();
?>