-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
62 lines (46 loc) · 1.4 KB
/
server.js
File metadata and controls
62 lines (46 loc) · 1.4 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
require("dotenv").config();
const express = require("express");
const crypto = require("crypto");
const cors = require("cors");
const helmet = require("helmet");
const app = express();
app.use(express.json());
app.use(cors());
app.use(helmet());
const keyDatabase = {};
// Generate key
function generateKey() {
const raw = crypto.randomBytes(5).toString("hex").toUpperCase();
return `HCYB-${raw}`;
}
// Telegram hook placeholder
app.post("/webhook", (req, res) => {
const key = generateKey();
keyDatabase[key] = {
deviceId: null,
expiresAt: Date.now() + 30 * 60 * 1000
};
console.log("KEY GENERATED:", key);
res.sendStatus(200);
});
// Verify + bind device
app.post("/api/verify-key", (req, res) => {
const { key, deviceId } = req.body;
const record = keyDatabase[key];
if (!record) return res.json({ valid: false });
if (Date.now() > record.expiresAt)
return res.json({ valid: false, msg: "expired" });
if (!record.deviceId) {
record.deviceId = deviceId;
return res.json({ valid: true, msg: "bound" });
}
if (record.deviceId !== deviceId)
return res.json({ valid: false, msg: "device mismatch" });
return res.json({ valid: true });
});
// version endpoint
app.get("/api/version", (req, res) => {
res.json({ version: "1.0.0" });
});
const PORT = 3000;
app.listen(PORT, () => console.log("Server running"));