Skip to content

Commit 7159c90

Browse files
authored
Merge pull request #5 from ZeroHost-Code/beta
Beta
2 parents 6048ef2 + 988490c commit 7159c90

13 files changed

Lines changed: 1242 additions & 193 deletions

File tree

.env.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ PTERO_API_KEY=change_me
2020
# Encryption key for sensitive data — Generate with: openssl rand -hex 32
2121
ENCRYPTION_KEY=change_me_to_a_random_hex_string
2222

23-
# Cloudflare Turnstile
24-
TURNSTILE_SECRET=change_me
23+
# Cap CAPTCHA (self-hosted alternative to Turnstile)
24+
CAP_ENDPOINT=https://cap.zero-host.org/f6c8171b08/
25+
CAP_SECRET=change_me
2526

2627
# Session & Cookie
2728
COOKIE_SECRET=change_me_to_a_random_string

config/cap.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const CAP_SECRET = process.env.CAP_SECRET;
2+
const CAP_ENDPOINT = process.env.CAP_ENDPOINT;
3+
4+
if (!CAP_SECRET) {
5+
console.error('Missing CAP_SECRET environment variable');
6+
}
7+
8+
if (!CAP_ENDPOINT) {
9+
console.error('Missing CAP_ENDPOINT environment variable');
10+
}
11+
12+
async function fetchWithTimeout(url, options = {}, timeout = 10000) {
13+
const controller = new AbortController();
14+
const timer = setTimeout(() => controller.abort(), timeout);
15+
try {
16+
return await fetch(url, { ...options, signal: controller.signal });
17+
} finally {
18+
clearTimeout(timer);
19+
}
20+
}
21+
22+
export async function verifyCap(token) {
23+
if (!token) return false;
24+
try {
25+
const res = await fetchWithTimeout(`${CAP_ENDPOINT}siteverify`, {
26+
method: 'POST',
27+
headers: { 'Content-Type': 'application/json' },
28+
body: JSON.stringify({ secret: CAP_SECRET, response: token }),
29+
});
30+
const data = await res.json();
31+
return data.success === true;
32+
} catch {
33+
return false;
34+
}
35+
}

config/migrate.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const tables = {
1212
{ name: 'first_name', def: 'VARCHAR(255)' },
1313
{ name: 'last_name', def: 'VARCHAR(255)' },
1414
{ name: 'password_set', def: 'TINYINT(1) NOT NULL DEFAULT 0' },
15+
{ name: 'ptero_client_api_key', def: 'VARCHAR(255) DEFAULT NULL' },
1516
{ name: 'created_at', def: 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP' },
1617
],
1718
},
@@ -33,6 +34,16 @@ const tables = {
3334
{ name: 'created_at', def: 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP' },
3435
],
3536
},
37+
activity_log: {
38+
columns: [
39+
{ name: 'id', def: 'INT AUTO_INCREMENT PRIMARY KEY' },
40+
{ name: 'user_id', def: 'INT NOT NULL' },
41+
{ name: 'action', def: 'VARCHAR(50) NOT NULL' },
42+
{ name: 'details', def: 'VARCHAR(255) DEFAULT \'\'' },
43+
{ name: 'server_id', def: 'INT DEFAULT NULL' },
44+
{ name: 'created_at', def: 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP' },
45+
],
46+
},
3647

3748
};
3849

@@ -51,7 +62,8 @@ const constraints = [
5162
{ table: 'user_ips', sql: 'ALTER TABLE user_ips ADD INDEX idx_ip (ip_address)', name: 'idx_ip' },
5263
{ table: 'user_ips', sql: 'ALTER TABLE user_ips ADD INDEX idx_user (user_id)', name: 'idx_user' },
5364
{ table: 'user_ips', sql: 'ALTER TABLE user_ips ADD CONSTRAINT fk_user_ips_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE', name: 'fk_user_ips_user' },
54-
65+
{ table: 'activity_log', sql: 'ALTER TABLE activity_log ADD INDEX idx_activity_user (user_id)', name: 'idx_activity_user' },
66+
{ table: 'activity_log', sql: 'ALTER TABLE activity_log ADD INDEX idx_activity_created (created_at)', name: 'idx_activity_created' },
5567
];
5668

5769
export async function migrate() {

config/turnstile.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zerohost-dashboard",
3-
"version": "1.0.0",
3+
"version": "0.9.7",
44
"private": true,
55
"type": "module",
66
"scripts": {

0 commit comments

Comments
 (0)