This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathinfo.php
201 lines (199 loc) · 7.91 KB
/
info.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
<html>
<head>
<title>Bittorium webwallet</title>
<link rel="shortcut icon" href="images/logo.png">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="header">
<div class="logo"><img src="/images/logo.png"></div>
<div class="pagetitle">Bittorium Web Wallet</div>
</div>
<div class="page">
<?php
require("config.php");
require("lib/daemon.php");
require("lib/database.php");
require("lib/validate.php");
require("lib/users.php");
try {
open_database();
} catch (Exception $e) {
echo '<span class="error">Caught exception while opening database: ', $e->getMessage(), "</span></div></body></html>";
exit();
}
try {
check_database();
} catch (Exception $e) {
echo '<span class="error">Caught exception while reading database: ', $e->getMessage(), "</span></div></body></html>";
exit();
}
// Check if user has logged in or not?
require("lib/login.php");
//
$address = "";
if (logged_in()) {
$spendKey = $_COOKIE['spendKey'];
if (!validate_spendkey($spendKey)) {
echo "<span class='error'>Invalid spend key!</span></div></body></html>";
exit();
}
$address = get_address($spendKey);
$params = Array();
$params['address'] = $address;
$getBalance = walletrpc_post("getBalance", $params);
$availableBalance = $getBalance->availableBalance;
$lockedBalance = $getBalance->lockedAmount;
require("lib/menu.php");
echo "<div id='wallet'>Address: ", $address, "</div><br>";
echo "<div id='qr'><img src='qr.php'></div>";
echo "<div id='content'>";
if (isset($_POST['threshold'])) {
$threshold = $_POST['threshold'];
if (!validate_int($threshold) || intval($threshold) < 100) {
echo "<span class='error'>Fusion threshold is invalid! Should be integer number and at least 100!</span></div></div></body></html>";
exit();
}
$params = Array();
$sourceAddresses = Array();
$sourceAddresses[] = $address;
$params['addresses'] = $sourceAddresses;
$params['destinationAddress'] = $address;
$params['threshold'] = intval($threshold);
$params['anonymity'] = 0;
$result = walletrpc_post('sendFusionTransaction', $params);
// var_dump($result);
if (array_key_exists('transactionHash', $result)) {
echo "Fusion transaction sent with hash ", $result->transactionHash, ".<br>";
} else {
echo "<span class='error'>Sending fusion transaction failed!</span><br>";
}
} else if (isset($_POST['oldEmail']) && !isset($_POST['newEmail'])) {
// Verify that oldEmail matches e-mail address associated with spendKey...
$oldEmail = $_POST['oldEmail'];
$email = get_email_with_spendkey($spendKey);
if ($oldEmail != $email) {
echo "<span class='error'>E-mail address doesn't match with address registered with account!</span></div></div></body></html>";
exit();
}
if (isset($_POST['authCode'])) {
$authCode = $_POST['authCode'];
$authCode2 = get_authcode($spendKey);
if ($authCode != $authCode2) {
echo "<span class='error'>Invalid authentication code!</span></div></div></body></html>";
exit();
}
echo "<form action='info.php' method='post'>";
echo "<input type='hidden' name='oldEmail' value='".$email."'>";
echo "Enter new e-mail address: <input type='email' name='newEmail' placeholder='@' required><br>";
echo "<input type='submit' name='submit' class='btn' value='Verify'>";
echo "</form></div></div></body></html>";
exit();
} else {
$authCode = generate_authcode($spendKey);
if ($authCode === false) {
echo "<span class='error'>Database error!</span></div></div></body></html>";
exit();
}
send_change_email_old($email, $authCode);
echo "<form action='info.php' method='post'>";
echo "<input type='hidden' name='oldEmail' value='".$email."'>";
echo "Enter authentication code: <input type='text' name='authCode' pattern='[0-9]{6}' placeholder='000000' required><br>";
echo "<input type='submit' name='submit' class='btn' value='Verify'>";
echo "</form></div></div></body></html>";
exit();
}
} else if (isset($_POST['oldEmail']) && isset($_POST['newEmail'])) {
$oldEmail = $_POST['oldEmail'];
$newEmail = $_POST['newEmail'];
$email = get_email_with_spendkey($spendKey);
if ($oldEmail != $email) {
echo "<span class='error'>E-mail address doesn't match with address registered with account!</span></div></div></body></html>";
exit();
}
if (!validate_email($newEmail)) {
echo "<span class='error'>New e-mail address is not valid!</span></div></div></body></html>";
exit();
}
if (isset($_POST['authCode'])) {
$authCode = $_POST['authCode'];
$authCode2 = get_authcode($spendKey);
if ($authCode != $authCode2) {
echo "<span class='error'>Invalid authentication code!</span></div></div></body></html>";
exit();
}
$result = set_email_with_spendkey($spendKey, $newEmail);
if ($result === false) {
echo "<span class='error'>E-mail change failed!</span></div></div></body></html>";
exit();
}
echo "E-mail address changed!<br>";
echo "<a href='info.php'>Return</a></div></div></body></html>";
exit();
} else {
$authCode = generate_authcode($spendKey);
send_change_email_new($oldEmail, $newEmail, $authCode);
echo "<form action='info.php' method='post'>";
echo "<input type='hidden' name='oldEmail' value='".$oldEmail."'>";
echo "<input type='hidden' name='newEmail' value='".$newEmail."'>";
echo "Enter authentication code: <input type='text' name='authCode' pattern='[0-9]{6}' placeholder='000000' required><br>";
echo "<input type='submit' name='submit' class='btn' value='Verify'>";
echo "</form></div></div></body></html>";
exit();
}
} else {
echo "<h3>Wallet optimization</h3>";
// Threshold should be largest multiple of 10 that is smaller than or equal to 1/12 of available balance
$threshold = 100;
while ($threshold < ($availableBalance / 120)) {
$threshold *= 10;
}
$params = Array();
$params['threshold'] = $threshold;
$sourceAddresses = Array();
$sourceAddresses[] = $address;
$params['addresses'] = $sourceAddresses;
$result = walletrpc_post('estimateFusion', $params);
if (array_key_exists('fusionReadyCount', $result)) {
echo $result->fusionReadyCount, " output(s) ready for fusion transaction.<br>";
}
if (array_key_exists('totalOutputCount', $result)) {
echo $result->totalOutputCount, " output(s) found in wallet.<br>";
}
if ($result->fusionReadyCount > 0) {
echo "<form action='info.php' method='post'>";
echo "<input type='hidden' name='threshold' value='", $threshold, "'>";
echo "<input type='submit' name='optimize' class='btn' value='Optimize wallet'>";
echo "</form>";
echo "<br>";
}
}
echo "<br><h3>Wallet recovery</h3>";
$params = Array();
$params['address'] = $address;
$result = walletrpc_post('getMnemonicSeed', $params);
$getViewKey = walletrpc_post('getViewKey');
$viewKey = $getViewKey->viewSecretKey;
if ($result === NULL) {
echo "<span class='error'>Internal server error, contact web wallet admin!</span></div></div></body></html>";
exit();
}
echo "<table id='info'>";
if (array_key_exists('mnemonicSeed', $result)) {
echo "<tr><th>Mnemonic seed:</th><td>", $result->mnemonicSeed, "</td></tr>";
}
echo "<tr><th>View key:</th><td>", $viewKey, "</td></tr>";
echo "<tr><th>Spend key:</th><td>", $spendKey, "</td></tr>";
echo "</table>";
echo "<br><h3>E-mail change</h3>";
echo "<form action='info.php' method='post'>";
echo "Enter old e-mail address: <input type='email' name='oldEmail' placeholder='youremail@domain.com' required><br>";
echo "<input type='submit' name='submit' class='btn' value='Verify'>";
echo "</form>";
echo "</div>";
}
?>
</div>
</body>
</html>