termites 1.0.41 → 1.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +5 -1
- package/lib/auth.js +28 -0
- package/lib/config.js +20 -0
- package/lib/html-page.js +1200 -0
- package/lib/icon.js +6 -0
- package/lib/pages.js +186 -0
- package/lib/server.js +452 -0
- package/package.json +1 -1
- package/server.js +2 -1951
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
"Bash(npm view snailshell)",
|
|
10
10
|
"Bash(npm view crabshell)",
|
|
11
11
|
"Bash(node:*)",
|
|
12
|
-
"Bash(curl:*)"
|
|
12
|
+
"Bash(curl:*)",
|
|
13
|
+
"Bash(echo \"重构后的函数:\" cat /Users/maple/workbench/termites/lib/*.js)",
|
|
14
|
+
"Bash(cat:*)",
|
|
15
|
+
"Bash(head -20 __NEW_LINE_d073a8ebb39fa804__ echo \"\" echo \"重构后 TermitesServer 方法:\" grep -E \"^\\\\s+\\(async\\\\s+\\)?[a-zA-Z]+\\\\\\(\" /Users/maple/workbench/termites/lib/server.js)",
|
|
16
|
+
"Bash(pkill:*)"
|
|
13
17
|
]
|
|
14
18
|
}
|
|
15
19
|
}
|
package/lib/auth.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
|
|
3
|
+
const SCRYPT_SALT_LENGTH = 16;
|
|
4
|
+
const SCRYPT_KEY_LENGTH = 64;
|
|
5
|
+
|
|
6
|
+
function hashPassword(password, salt) {
|
|
7
|
+
salt = salt || crypto.randomBytes(SCRYPT_SALT_LENGTH).toString('hex');
|
|
8
|
+
const hash = crypto.scryptSync(password, salt, SCRYPT_KEY_LENGTH).toString('hex');
|
|
9
|
+
return `${salt}:${hash}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function verifyPassword(password, storedHash) {
|
|
13
|
+
const [salt, hash] = storedHash.split(':');
|
|
14
|
+
if (!salt || !hash) return false;
|
|
15
|
+
const newHash = crypto.scryptSync(password, salt, SCRYPT_KEY_LENGTH).toString('hex');
|
|
16
|
+
return crypto.timingSafeEqual(Buffer.from(hash, 'hex'), Buffer.from(newHash, 'hex'));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parseCookies(cookieStr) {
|
|
20
|
+
const cookies = {};
|
|
21
|
+
cookieStr.split(';').forEach(pair => {
|
|
22
|
+
const [key, val] = pair.trim().split('=');
|
|
23
|
+
if (key) cookies[key] = val;
|
|
24
|
+
});
|
|
25
|
+
return cookies;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = { hashPassword, verifyPassword, parseCookies };
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
const CONFIG_FILE = path.join(os.homedir(), '.termites.json');
|
|
6
|
+
|
|
7
|
+
function loadConfig() {
|
|
8
|
+
try {
|
|
9
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
10
|
+
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
11
|
+
}
|
|
12
|
+
} catch (e) {}
|
|
13
|
+
return { passwordHash: null };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function saveConfig(config) {
|
|
17
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = { loadConfig, saveConfig, CONFIG_FILE };
|