59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
const { Client } = require('ssh2');
|
|
|
|
const config = {
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
};
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', async () => {
|
|
console.log('SSH连接成功');
|
|
|
|
try {
|
|
console.log('\n=== 检查当前证书 ===');
|
|
await executeCommand('ls -la /www/server/panel/vhost/cert/hs.yifenbao.cn/');
|
|
|
|
console.log('\n=== 检查备份目录 ===');
|
|
await executeCommand('ls -la /www/backup/file_history/www/server/nginx/conf/ 2>/dev/null || echo "无备份"');
|
|
|
|
console.log('\n=== 通过宝塔面板重新申请证书 ===');
|
|
await executeCommand('bt 1');
|
|
|
|
console.log('\n=== 测试4001端口直连H5 ===');
|
|
await executeCommand('curl -s http://hs.yifenbao.cn:4001/h5/ | head -10');
|
|
|
|
console.log('\n=== 测试4001端口直连管理端 ===');
|
|
await executeCommand('curl -s http://hs.yifenbao.cn:4001/admin/ | head -10');
|
|
|
|
} catch (error) {
|
|
console.error('恢复失败:', error.message);
|
|
} finally {
|
|
conn.end();
|
|
}
|
|
});
|
|
|
|
function executeCommand(cmd) {
|
|
return new Promise((resolve) => {
|
|
conn.exec(cmd, (err, stream) => {
|
|
if (err) {
|
|
console.error('命令执行错误:', err.message);
|
|
resolve();
|
|
return;
|
|
}
|
|
|
|
stream.stdout.on('data', (data) => process.stdout.write(data));
|
|
stream.stderr.on('data', (data) => process.stdout.write(data));
|
|
|
|
stream.on('close', () => resolve());
|
|
});
|
|
});
|
|
}
|
|
|
|
conn.on('error', (err) => {
|
|
console.error('SSH连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect(config); |