ZhaoShanGeng
commited on
Commit
·
e6c8f63
1
Parent(s):
f076c2a
fix: 安全增强 - 移除默认凭据,使用完全随机生成
Browse files- .env.example +6 -5
- config.json +1 -1
- scripts/build.js +8 -11
- src/config/config.js +6 -8
.env.example
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
# 敏感配置(只在 .env 中配置)
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
# 可选配置
|
| 8 |
# PROXY=http://127.0.0.1:7890
|
| 9 |
-
SYSTEM_INSTRUCTION
|
| 10 |
# IMAGE_BASE_URL=http://your-domain.com
|
|
|
|
| 1 |
# 敏感配置(只在 .env 中配置)
|
| 2 |
+
# 如果不配置以下三项,系统会自动生成随机凭据并在启动时显示
|
| 3 |
+
# API_KEY=your-api-key
|
| 4 |
+
# ADMIN_USERNAME=your-username
|
| 5 |
+
# ADMIN_PASSWORD=your-password
|
| 6 |
+
# JWT_SECRET=your-jwt-secret
|
| 7 |
|
| 8 |
# 可选配置
|
| 9 |
# PROXY=http://127.0.0.1:7890
|
| 10 |
+
# SYSTEM_INSTRUCTION=你的系统提示词
|
| 11 |
# IMAGE_BASE_URL=http://your-domain.com
|
config.json
CHANGED
|
@@ -32,7 +32,7 @@
|
|
| 32 |
"retryTimes": 3,
|
| 33 |
"skipProjectIdFetch": false,
|
| 34 |
"useNativeAxios": false,
|
| 35 |
-
"useContextSystemPrompt":
|
| 36 |
"passSignatureToClient": false
|
| 37 |
}
|
| 38 |
}
|
|
|
|
| 32 |
"retryTimes": 3,
|
| 33 |
"skipProjectIdFetch": false,
|
| 34 |
"useNativeAxios": false,
|
| 35 |
+
"useContextSystemPrompt": true,
|
| 36 |
"passSignatureToClient": false
|
| 37 |
}
|
| 38 |
}
|
scripts/build.js
CHANGED
|
@@ -240,15 +240,12 @@ try {
|
|
| 240 |
}
|
| 241 |
}
|
| 242 |
|
| 243 |
-
//
|
| 244 |
-
const
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
fs.copyFileSync(srcPath, destPath);
|
| 250 |
-
console.log(` ✓ Copied ${file}`);
|
| 251 |
-
}
|
| 252 |
}
|
| 253 |
|
| 254 |
console.log('');
|
|
@@ -256,8 +253,8 @@ try {
|
|
| 256 |
console.log('');
|
| 257 |
console.log('📋 Usage:');
|
| 258 |
console.log(' 1. Copy the dist folder to your target machine');
|
| 259 |
-
console.log(' 2.
|
| 260 |
-
console.log(' 3.
|
| 261 |
console.log('');
|
| 262 |
|
| 263 |
} catch (error) {
|
|
|
|
| 240 |
}
|
| 241 |
}
|
| 242 |
|
| 243 |
+
// 复制配置文件模板(只复制 config.json)
|
| 244 |
+
const configSrcPath = path.join(rootDir, 'config.json');
|
| 245 |
+
const configDestPath = path.join(distDir, 'config.json');
|
| 246 |
+
if (fs.existsSync(configSrcPath)) {
|
| 247 |
+
fs.copyFileSync(configSrcPath, configDestPath);
|
| 248 |
+
console.log(' ✓ Copied config.json');
|
|
|
|
|
|
|
|
|
|
| 249 |
}
|
| 250 |
|
| 251 |
console.log('');
|
|
|
|
| 253 |
console.log('');
|
| 254 |
console.log('📋 Usage:');
|
| 255 |
console.log(' 1. Copy the dist folder to your target machine');
|
| 256 |
+
console.log(' 2. Run the executable (will auto-generate random credentials if not configured)');
|
| 257 |
+
console.log(' 3. Optionally create .env file to customize settings');
|
| 258 |
console.log('');
|
| 259 |
|
| 260 |
} catch (error) {
|
src/config/config.js
CHANGED
|
@@ -36,8 +36,8 @@ function getAdminCredentials() {
|
|
| 36 |
// 生成随机凭据(只生成一次)
|
| 37 |
if (!generatedCredentials) {
|
| 38 |
generatedCredentials = {
|
| 39 |
-
username: username ||
|
| 40 |
-
password: password || crypto.randomBytes(
|
| 41 |
jwtSecret: jwtSecret || crypto.randomBytes(32).toString('hex')
|
| 42 |
};
|
| 43 |
|
|
@@ -61,14 +61,12 @@ function getAdminCredentials() {
|
|
| 61 |
return generatedCredentials;
|
| 62 |
}
|
| 63 |
|
| 64 |
-
const { envPath, configJsonPath
|
| 65 |
|
| 66 |
-
// 确保 .env
|
| 67 |
if (!fs.existsSync(envPath)) {
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
log.info('✓ 已从 .env.example 创建 .env 文件');
|
| 71 |
-
}
|
| 72 |
}
|
| 73 |
|
| 74 |
// 加载 config.json
|
|
|
|
| 36 |
// 生成随机凭据(只生成一次)
|
| 37 |
if (!generatedCredentials) {
|
| 38 |
generatedCredentials = {
|
| 39 |
+
username: username || crypto.randomBytes(8).toString('hex'),
|
| 40 |
+
password: password || crypto.randomBytes(16).toString('base64').replace(/[+/=]/g, ''),
|
| 41 |
jwtSecret: jwtSecret || crypto.randomBytes(32).toString('hex')
|
| 42 |
};
|
| 43 |
|
|
|
|
| 61 |
return generatedCredentials;
|
| 62 |
}
|
| 63 |
|
| 64 |
+
const { envPath, configJsonPath } = getConfigPaths();
|
| 65 |
|
| 66 |
+
// 确保 .env 存在(如果缺失则创建空白文件,方便用户后续配置)
|
| 67 |
if (!fs.existsSync(envPath)) {
|
| 68 |
+
fs.writeFileSync(envPath, '# 环境变量配置文件\n# 参考 .env.example 了解可用配置项\n', 'utf8');
|
| 69 |
+
log.info('✓ 已创建空白 .env 文件,请根据需要配置环境变量');
|
|
|
|
|
|
|
| 70 |
}
|
| 71 |
|
| 72 |
// 加载 config.json
|