Repository navigation
Expand file tree
/
Copy pathsetup.php
More file actions
142 lines (130 loc) · 6.38 KB
/
Copy pathsetup.php
File metadata and controls
142 lines (130 loc) · 6.38 KB
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
<?php
require_once __DIR__ . '/includes/bootstrap.php';
$pageTitle = 'Setup';
$forcedIp = trim((string)($config['permitted_ip'] ?? ''));
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'register') {
$passphrase = (string)($_POST['passphrase'] ?? '');
$confirm = (string)($_POST['passphrase_confirm'] ?? '');
try {
if (strlen($passphrase) < 8) {
throw new RuntimeException('Kies een wachtwoordzin van minstens 8 tekens.');
}
if ($passphrase !== $confirm) {
throw new RuntimeException('De twee wachtwoordzinnen komen niet overeen.');
}
$bunq->setPassphrase($passphrase);
$description = 'bunqBeheer @ ' . ($_SERVER['HTTP_HOST'] ?? 'localhost');
$bunq->setup($description, $forcedIp !== '' ? $forcedIp : null);
$_SESSION['bunq_passphrase'] = $passphrase;
flash_set('success', 'Verbinding met bunq is gelegd en versleuteld opgeslagen.');
header('Location: index.php');
exit;
} catch (Throwable $e) {
flash_set('error', $e->getMessage());
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'encrypt_existing') {
$passphrase = (string)($_POST['passphrase'] ?? '');
$confirm = (string)($_POST['passphrase_confirm'] ?? '');
try {
if (strlen($passphrase) < 8) {
throw new RuntimeException('Kies een wachtwoordzin van minstens 8 tekens.');
}
if ($passphrase !== $confirm) {
throw new RuntimeException('De twee wachtwoordzinnen komen niet overeen.');
}
$bunq->encryptContextWith($passphrase);
$_SESSION['bunq_passphrase'] = $passphrase;
flash_set('success', 'Bunq-context is nu versleuteld met je wachtwoordzin.');
header('Location: index.php');
exit;
} catch (Throwable $e) {
flash_set('error', $e->getMessage());
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'reset') {
$bunq->reset();
unset($_SESSION['bunq_passphrase']);
flash_set('info', 'Bestaande sessie is gewist.');
header('Location: setup.php');
exit;
}
$contextEncrypted = $bunq->isContextEncryptedOnDisk();
$hasUnencryptedContext = $bunq->contextFileExists() && !$contextEncrypted;
include __DIR__ . '/includes/header.php';
?>
<h1>Verbinding met bunq instellen</h1>
<p class="muted">
Deze stap registreert dit apparaat eenmalig bij bunq met je API-sleutel.
Sleutels en tokens worden lokaal versleuteld opgeslagen in
<code>storage/bunq-context.json</code> met een wachtwoordzin die alleen jij kent.
</p>
<div class="card">
<h2 class="card__title">Configuratie</h2>
<p class="muted">
Omgeving: <strong><?= h(($config['environment'] ?? 'production')) ?></strong><br>
API-sleutel: <strong><?= h(substr((string)($config['api_key'] ?? ''), 0, 6)) ?>…</strong><br>
Toegestaan IP: <strong><?= h($forcedIp !== '' ? $forcedIp : '*') ?></strong>
</p>
<?php if ($bunq->isConfigured() && $contextEncrypted): ?>
<p>Verbinding is al actief en versleuteld opgeslagen.</p>
<div class="actions">
<a class="btn" href="index.php">Naar de rekeningen</a>
<form method="post" style="display:inline">
<input type="hidden" name="action" value="reset">
<button class="btn btn--danger" type="submit"
onclick="return confirm('Weet je zeker dat je de bunq-sessie wilt resetten? Je moet daarna opnieuw registreren.')">
Sessie resetten
</button>
</form>
</div>
<?php elseif ($contextEncrypted && $bunq->isLocked()): ?>
<p>De opgeslagen bunq-context is versleuteld en nog vergrendeld.
Ontgrendel hem met je wachtwoordzin om door te gaan, of reset alles om opnieuw te beginnen.</p>
<div class="actions">
<a class="btn" href="unlock.php">Ontgrendelen</a>
<form method="post" style="display:inline">
<input type="hidden" name="action" value="reset">
<button class="btn btn--danger" type="submit"
onclick="return confirm('Weet je zeker dat je de bunq-sessie wilt resetten? Je moet daarna opnieuw registreren bij bunq.')">
Sessie resetten
</button>
</form>
</div>
<?php elseif ($hasUnencryptedContext && $bunq->isConfigured()): ?>
<p>Er is al een actieve bunq-sessie, maar nog niet beveiligd met een wachtwoordzin.
Kies er nu één om de opgeslagen sleutels te versleutelen.</p>
<form method="post" autocomplete="off">
<input type="hidden" name="action" value="encrypt_existing">
<div class="field">
<label for="passphrase">Wachtwoordzin</label>
<input id="passphrase" name="passphrase" type="password" required minlength="8" autocomplete="new-password">
</div>
<div class="field">
<label for="passphrase_confirm">Wachtwoordzin opnieuw</label>
<input id="passphrase_confirm" name="passphrase_confirm" type="password" required minlength="8" autocomplete="new-password">
</div>
<div class="actions">
<button class="btn" type="submit">Versleutel met deze wachtwoordzin</button>
</div>
</form>
<?php else: ?>
<p>Kies een wachtwoordzin. Deze versleutelt de bunq-sleutels op de server.
Je voert hem in bij elke nieuwe sessie. Vergeet je hem, dan moet je opnieuw registreren bij bunq.</p>
<form method="post" autocomplete="off">
<input type="hidden" name="action" value="register">
<div class="field">
<label for="passphrase">Wachtwoordzin</label>
<input id="passphrase" name="passphrase" type="password" required minlength="8" autocomplete="new-password">
</div>
<div class="field">
<label for="passphrase_confirm">Wachtwoordzin opnieuw</label>
<input id="passphrase_confirm" name="passphrase_confirm" type="password" required minlength="8" autocomplete="new-password">
</div>
<div class="actions">
<button class="btn" type="submit">Apparaat registreren bij bunq</button>
</div>
</form>
<?php endif; ?>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>