-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.html
More file actions
267 lines (235 loc) · 16.1 KB
/
backup.html
File metadata and controls
267 lines (235 loc) · 16.1 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vault | LinkStack</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;800&display=swap');
body { font-family: 'Plus Jakarta Sans', sans-serif; }
.action-card { transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); cursor: pointer; border: 2px solid transparent; }
.action-card.active { border-color: #4f46e5; background: #f5f3ff; }
.config-panel { display: none; }
.config-panel.active { display: block; animation: slideUp 0.4s ease; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.modal-overlay { background: rgba(15, 23, 42, 0.9); backdrop-filter: blur(12px); }
.pfp-ring { padding: 2px; background: linear-gradient(to bottom right, #4f46e5, #ec4899); }
.api-banner { background: linear-gradient(90deg, #4f46e5, #7c3aed); }
</style>
</head>
<body class="bg-slate-50 text-slate-900 antialiased min-h-screen">
<div onclick="location.href='/blog/vaultapi.html'" class="api-banner w-full py-3 px-4 text-white text-center cursor-pointer hover:opacity-90 transition-all sticky top-0 z-[60] flex items-center justify-center gap-2 group">
<span class="text-xs font-black uppercase tracking-widest bg-white/20 px-2 py-0.5 rounded">API Retired</span>
<p class="text-sm font-bold">The LinkStack Vault API has been retired, but you can still backup your data. <span class="underline decoration-white/30 group-hover:decoration-white transition">Learn More →</span></p>
</div>
<nav class="fixed top-11 w-full z-50 bg-white/80 backdrop-blur-md border-b border-slate-200 py-4 px-8 flex justify-between items-center">
<div class="flex items-center gap-2 font-black text-2xl text-indigo-600 cursor-pointer" onclick="location.href='/dashboard'">
<i data-feather="layers"></i><span>LinkStack<span class="text-slate-400">.vault</span></span>
</div>
<div id="user-display" class="hidden flex items-center gap-4">
<div class="text-right hidden sm:block">
<p class="text-[10px] font-black text-slate-400 uppercase leading-none">Logged in as</p>
<p id="user-handle" class="font-bold text-slate-900">@username</p>
</div>
<div class="relative group">
<div class="w-10 h-10 rounded-full pfp-ring cursor-pointer">
<img id="user-pfp" src="" class="w-full h-full object-cover rounded-full bg-slate-200 border-2 border-white" alt="Profile">
</div>
<div class="absolute right-0 mt-2 w-48 bg-white rounded-2xl shadow-xl border border-slate-100 py-2 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 translate-y-2 group-hover:translate-y-0">
<a href="/dashboard" class="flex items-center gap-3 px-4 py-2 text-sm font-bold text-slate-600 hover:bg-slate-50">
<i data-feather="home" class="w-4 h-4"></i> Dashboard
</a>
<hr class="my-2 border-slate-50">
<button onclick="handleLogout()" class="w-full flex items-center gap-3 px-4 py-2 text-sm font-bold text-red-500 hover:bg-red-50">
<i data-feather="log-out" class="w-4 h-4"></i> Logout
</button>
</div>
</div>
</div>
</nav>
<main id="main-content" class="max-w-4xl mx-auto pt-52 px-6 pb-24 opacity-0 transition-opacity duration-500">
<header class="mb-12 text-center">
<h1 class="text-4xl font-black tracking-tight mb-2">Encrypted Vault</h1>
<p class="text-slate-500 font-medium text-lg">Industrial-grade backups for your digital identity.</p>
</header>
<div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-12">
<div onclick="selectMode('export')" id="card-export" class="action-card p-10 bg-white rounded-[3rem] shadow-xl shadow-slate-200/40">
<div class="w-14 h-14 bg-indigo-50 text-indigo-600 rounded-3xl flex items-center justify-center mb-8"><i data-feather="lock"></i></div>
<h3 class="font-black text-2xl mb-2">Protected Export</h3>
<p class="text-slate-400 font-medium">Encrypt your stack with AES-GCM.</p>
</div>
<div onclick="selectMode('restore')" id="card-restore" class="action-card p-10 bg-white rounded-[3rem] shadow-xl shadow-slate-200/40">
<div class="w-14 h-14 bg-red-50 text-red-600 rounded-3xl flex items-center justify-center mb-8"><i data-feather="unlock"></i></div>
<h3 class="font-black text-2xl mb-2">Local Restore</h3>
<p class="text-slate-400 font-medium">Decrypt and recover specific data.</p>
</div>
</div>
<div id="panel-export" class="config-panel p-10 bg-white rounded-[3rem] shadow-2xl border-2 border-slate-50">
<h2 class="text-2xl font-black mb-6">Backup Security</h2>
<div class="space-y-4 max-w-md">
<input type="password" id="export-pass" placeholder="Create backup password..." class="w-full px-6 py-4 bg-slate-50 border border-slate-100 rounded-2xl font-bold outline-none focus:ring-4 ring-indigo-500/10 transition">
<button onclick="performProtectedExport()" id="export-btn" class="w-full py-5 bg-indigo-600 text-white font-black rounded-2xl shadow-xl hover:bg-indigo-700 transition flex items-center justify-center gap-3">
<i data-feather="download-cloud"></i> Secure Download
</button>
</div>
</div>
<div id="panel-restore" class="config-panel p-10 bg-white rounded-[3rem] shadow-2xl border-2 border-red-50">
<h2 class="text-2xl font-black mb-6">Restore from File</h2>
<div class="p-16 border-4 border-dashed border-slate-100 rounded-[3rem] text-center">
<input type="file" id="restore-input" class="hidden" accept=".linkstackbackup" onchange="initiateRestore(event)">
<button onclick="document.getElementById('restore-input').click()" class="px-12 py-5 bg-slate-900 text-white font-black rounded-2xl hover:bg-black transition">Upload .linkstackbackup</button>
</div>
</div>
<div id="status-log" class="mt-8 hidden p-6 bg-slate-900 rounded-[2rem] font-mono text-[11px] text-indigo-400 space-y-1"></div>
</main>
<div id="auth-modal" class="fixed inset-0 z-[200] hidden modal-overlay flex items-center justify-center p-6">
<div class="bg-white w-full max-w-md rounded-[3rem] p-10 shadow-2xl">
<div class="text-center mb-8">
<div class="w-16 h-16 bg-indigo-600 text-white rounded-2xl flex items-center justify-center mx-auto mb-4">
<i data-feather="layers" class="w-8 h-8"></i>
</div>
<h2 class="text-3xl font-black tracking-tight">Access Restricted</h2>
<p class="text-slate-400 font-medium">Please sign in to manage your vault</p>
</div>
<button onclick="loginWithGithub()" class="w-full py-4 bg-slate-900 text-white font-black rounded-2xl flex items-center justify-center gap-3 hover:bg-black transition mb-6">
<i data-feather="github"></i> Continue with GitHub
</button>
<div class="space-y-3">
<input type="email" id="auth-email" placeholder="Email" class="w-full px-6 py-4 bg-slate-50 border border-slate-100 rounded-2xl outline-none focus:ring-4 ring-indigo-500/10 transition">
<input type="password" id="auth-password" placeholder="Password" class="w-full px-6 py-4 bg-slate-50 border border-slate-100 rounded-2xl outline-none focus:ring-4 ring-indigo-500/10 transition">
<button onclick="loginWithEmail()" class="w-full py-4 bg-indigo-600 text-white font-black rounded-2xl shadow-lg hover:bg-indigo-700 transition">Sign In</button>
</div>
</div>
</div>
<div id="restore-modal" class="fixed inset-0 z-[100] hidden modal-overlay flex items-center justify-center p-6">
<div class="bg-white w-full max-w-lg rounded-[3rem] p-10">
<h2 class="text-3xl font-black mb-6" id="modal-title">Unlock Vault</h2>
<div id="password-step" class="space-y-4">
<input type="password" id="restore-pass" placeholder="Enter backup password..." class="w-full px-6 py-4 bg-slate-50 border border-slate-100 rounded-2xl font-bold outline-none">
<button onclick="decryptAndProceed()" class="w-full py-4 bg-indigo-600 text-white font-black rounded-2xl">Decrypt File</button>
</div>
<div id="options-step" class="hidden space-y-4">
<div class="space-y-2 mb-8">
<label class="flex items-center p-4 bg-slate-50 rounded-2xl cursor-pointer"><input type="checkbox" id="opt-profile" checked class="mr-3 w-5 h-5 rounded"> <span class="font-bold">Profile Info</span></label>
<label class="flex items-center p-4 bg-slate-50 rounded-2xl cursor-pointer"><input type="checkbox" id="opt-links" checked class="mr-3 w-5 h-5 rounded"> <span class="font-bold">Links & Socials</span></label>
</div>
<button onclick="executeFinalRestore()" class="w-full py-4 bg-red-600 text-white font-black rounded-2xl shadow-xl shadow-red-100">Restore Selected</button>
</div>
</div>
</div>
<script type="module">
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.39.8';
const SB_URL = 'https://xcicvuqdoztxhidwdmlc.supabase.co';
const SB_KEY = 'sb_publishable_DeSw5UHzjV444ZF6eMkB0g_taV-dynR';
const supabase = createClient(SB_URL, SB_KEY);
let currentUser = null;
let encryptedBlob = null;
let activeDecryptedData = null;
async function init() {
const { data: { session } } = await supabase.auth.getSession();
if (!session) {
document.getElementById('auth-modal').classList.remove('hidden');
} else {
currentUser = session.user;
await loadUserProfile();
document.getElementById('main-content').classList.remove('opacity-0');
}
feather.replace();
}
async function loadUserProfile() {
const { data: profile } = await supabase.from('profiles').select('*').eq('id', currentUser.id).single();
if (profile) {
document.getElementById('user-handle').innerText = `@${profile.handle || 'user'}`;
document.getElementById('user-pfp').src = profile.avatar_url || `https://api.dicebear.com/7.x/initials/svg?seed=${profile.handle}`;
document.getElementById('user-display').classList.remove('hidden');
}
}
window.handleLogout = async () => {
await supabase.auth.signOut();
location.reload();
};
window.loginWithGithub = async () => {
await supabase.auth.signInWithOAuth({ provider: 'github', options: { redirectTo: window.location.href } });
};
window.loginWithEmail = async () => {
const email = document.getElementById('auth-email').value;
const password = document.getElementById('auth-password').value;
const { error } = await supabase.auth.signInWithPassword({ email, password });
if (error) alert(error.message);
else location.reload();
};
window.selectMode = (m) => {
document.querySelectorAll('.action-card').forEach(c => c.classList.remove('active'));
document.querySelectorAll('.config-panel').forEach(p => p.classList.remove('active'));
document.getElementById(`card-${m}`).classList.add('active');
document.getElementById(`panel-${m}`).classList.add('active');
};
async function deriveKey(password, salt) {
const enc = new TextEncoder();
const keyMaterial = await crypto.subtle.importKey("raw", enc.encode(password), "PBKDF2", false, ["deriveKey"]);
return crypto.subtle.deriveKey({ name: "PBKDF2", salt, iterations: 100000, hash: "SHA-256" }, keyMaterial, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
}
window.performProtectedExport = async () => {
const pass = document.getElementById('export-pass').value;
if (!pass) return alert("Security required. Set a password.");
const btn = document.getElementById('export-btn');
btn.innerHTML = '<i data-feather="loader" class="w-4 h-4 animate-spin"></i> Encrypting...';
feather.replace();
const { data: profile } = await supabase.from('profiles').select('*').eq('id', currentUser.id).single();
const { data: links } = await supabase.from('links').select('*').eq('user_id', currentUser.id);
const data = JSON.stringify({ profile, links, signature: "LINKSTACK_SECURE" });
const salt = crypto.getRandomValues(new Uint8Array(16));
const iv = crypto.getRandomValues(new Uint8Array(12));
const key = await deriveKey(pass, salt);
const encrypted = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, new TextEncoder().encode(data));
const finalBlob = new Blob([salt, iv, new Uint8Array(encrypted)], { type: 'application/octet-stream' });
const a = document.createElement('a');
a.href = URL.createObjectURL(finalBlob);
a.download = `${profile.handle || 'backup'}.linkstackbackup`;
a.click();
log("Vault exported successfully.");
btn.innerHTML = '<i data-feather="check"></i> Downloaded';
feather.replace();
};
window.initiateRestore = async (e) => {
const file = e.target.files[0];
encryptedBlob = await file.arrayBuffer();
document.getElementById('restore-modal').classList.remove('hidden');
};
window.decryptAndProceed = async () => {
const pass = document.getElementById('restore-pass').value;
try {
const salt = encryptedBlob.slice(0, 16);
const iv = encryptedBlob.slice(16, 28);
const data = encryptedBlob.slice(28);
const key = await deriveKey(pass, salt);
const decrypted = await crypto.subtle.decrypt({ name: "AES-GCM", iv: new Uint8Array(iv) }, key, data);
activeDecryptedData = JSON.parse(new TextDecoder().decode(decrypted));
document.getElementById('password-step').classList.add('hidden');
document.getElementById('options-step').classList.remove('hidden');
document.getElementById('modal-title').innerText = "Finalize Restore";
} catch (e) { alert("Invalid password."); }
};
window.executeFinalRestore = async () => {
if (document.getElementById('opt-links').checked) {
await supabase.from('links').delete().eq('user_id', currentUser.id);
const newLinks = activeDecryptedData.links.map(({id, created_at, ...rest}) => ({...rest, user_id: currentUser.id}));
await supabase.from('links').insert(newLinks);
}
if (document.getElementById('opt-profile').checked) {
const p = activeDecryptedData.profile;
await supabase.from('profiles').update({ bio: p.bio, display_name: p.display_name, theme: p.theme }).eq('id', currentUser.id);
}
window.location.href = '/dashboard';
};
function log(msg) {
const l = document.getElementById('status-log');
l.classList.remove('hidden');
l.innerHTML += `<div>>> ${msg}</div>`;
}
init();
</script>
</body>
</html>