feat: SSH STCP key generation and frp tunnel registration
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -19,19 +19,33 @@ const DEFAULTS = {
|
||||
heartbeat_interval: 30, // 秒
|
||||
/** 云端已激活:用于启动/重连时立即点亮 alarm(pwr),不等首包 connected */
|
||||
activated: false,
|
||||
ssh_secret_key: null,
|
||||
};
|
||||
|
||||
function _generateSshSecretKey() {
|
||||
const bytes = require('crypto').randomBytes(16);
|
||||
return 'sk-' + bytes.toString('hex');
|
||||
}
|
||||
|
||||
function load() {
|
||||
let cfg;
|
||||
try {
|
||||
if (fs.existsSync(CONFIG_FILE)) {
|
||||
const raw = fs.readFileSync(CONFIG_FILE, 'utf8');
|
||||
return Object.assign({}, DEFAULTS, JSON.parse(raw));
|
||||
cfg = Object.assign({}, DEFAULTS, JSON.parse(raw));
|
||||
}
|
||||
} catch (e) {
|
||||
const log = require('./logger');
|
||||
log.error('config', '读取配置失败,使用默认值:', e.message);
|
||||
}
|
||||
return Object.assign({}, DEFAULTS);
|
||||
if (!cfg) cfg = Object.assign({}, DEFAULTS);
|
||||
|
||||
if (!cfg.ssh_secret_key) {
|
||||
cfg.ssh_secret_key = _generateSshSecretKey();
|
||||
save(cfg);
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
function save(data) {
|
||||
|
||||
Reference in New Issue
Block a user