Fix overwritten i18n #161

Merged
ZacharyZcR merged 29 commits from main into dev-1.6.0 2025-09-05 17:41:21 +00:00
32 changed files with 4181 additions and 1366 deletions

View File

@@ -0,0 +1,20 @@
{
"permissions": {
"allow": [
"Read(/C:\\Users\\29037\\WebstormProjects\\Termix\\docker/**)",
"Bash(git fetch:*)",
"Bash(git pull:*)",
"Bash(git checkout:*)",
"Bash(git add:*)",
"Bash(grep:*)",
"Bash(git push:*)",
"Bash(git branch:*)",
"Bash(npm run build:*)",
"Bash(npm install)",
"Bash(npm run electron:build:*)",
"Bash(npm uninstall:*)"
],
"deny": [],
"ask": []
}
}

3
.env
View File

@@ -1 +1,2 @@
VERSION=1.5.0
VERSION=1.6.0
VITE_API_HOST=localhost

1
.gitignore vendored
View File

@@ -23,3 +23,4 @@ dist-ssr
*.sln
*.sw?
/db/
/release/

50
electron-builder.json Normal file
View File

@@ -0,0 +1,50 @@
{
"appId": "com.termix.app",
"productName": "Termix",
"directories": {
"output": "release"
},
"files": [
"dist/**/*",
"electron/**/*"
],
"extraMetadata": {
"main": "electron/main-simple.cjs"
},
"mac": {
"category": "public.app-category.developer-tools",
"icon": "public/icon.icns",
"hardenedRuntime": true,
"gatekeeperAssess": false,
"entitlements": "build/entitlements.mac.plist",
"entitlementsInherit": "build/entitlements.mac.plist",
"target": [
{
"target": "dmg",
"arch": ["x64", "arm64"]
},
{
"target": "zip",
"arch": ["x64", "arm64"]
}
]
},
"win": {
"target": "nsis",
"icon": "public/icon.ico"
},
"nsis": {
"oneClick": false,
"allowToChangeInstallationDirectory": true,
"artifactName": "${productName}-Setup-${version}.${ext}"
},
"linux": {
"category": "Development",
"target": [
{
"target": "AppImage",
"arch": ["x64"]
}
]
}
}

177
electron/main-simple.cjs Normal file
View File

@@ -0,0 +1,177 @@
const { app, BrowserWindow, Menu, shell, ipcMain } = require('electron');
const path = require('path');
const { spawn } = require('child_process');
// 全局变量
let mainWindow = null;
let backendProcess = null;
// 开发环境检测
const isDev = process.env.NODE_ENV === 'development' || !app.isPackaged;
// 启动后端服务
function startBackendServer() {
if (backendProcess) {
console.log('Backend server already running');
return;
}
const backendPath = path.join(__dirname, '../dist/backend/starter.js');
console.log('Starting backend server from:', backendPath);
backendProcess = spawn('node', [backendPath], {
stdio: ['ignore', 'pipe', 'pipe'],
detached: false
});
backendProcess.stdout.on('data', (data) => {
console.log('Backend:', data.toString());
});
backendProcess.stderr.on('data', (data) => {
console.error('Backend Error:', data.toString());
});
backendProcess.on('close', (code) => {
console.log(`Backend process exited with code ${code}`);
backendProcess = null;
});
}
// 停止后端服务
function stopBackendServer() {
if (backendProcess) {
console.log('Stopping backend server...');
backendProcess.kill();
backendProcess = null;
}
}
// 防止多开
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
}
// 创建主窗口
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
minWidth: 800,
minHeight: 600,
title: 'Termix',
icon: path.join(__dirname, '..', 'public', 'icon.png'),
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload-simple.cjs'),
webSecurity: !isDev
},
show: false,
});
// 创建应用菜单(包含开发者工具快捷键)
const template = [
{
label: 'View',
submenu: [
{
label: 'Toggle Developer Tools',
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
click: () => {
mainWindow.webContents.toggleDevTools();
}
},
{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click: () => {
mainWindow.webContents.reload();
}
}
]
}
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
// 加载应用
if (isDev) {
// 开发环境:连接到 Vite 开发服务器
mainWindow.loadURL('http://localhost:5173');
mainWindow.webContents.openDevTools();
} else {
// 生产环境:加载构建后的文件
mainWindow.loadFile(path.join(__dirname, '..', 'dist', 'index.html'));
// 生产环境也启用开发者工具以便调试
mainWindow.webContents.openDevTools();
}
// 窗口准备好后显示
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
// 处理窗口关闭事件
mainWindow.on('closed', () => {
mainWindow = null;
});
// 处理外部链接
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: 'deny' };
});
}
// IPC 通信处理
ipcMain.handle('get-app-version', () => {
return app.getVersion();
});
ipcMain.handle('get-platform', () => {
return process.platform;
});
// 应用事件处理
app.whenReady().then(() => {
// 在生产环境启动后端服务
if (!isDev) {
startBackendServer();
}
createWindow();
});
app.on('window-all-closed', () => {
stopBackendServer();
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
} else if (mainWindow) {
mainWindow.show();
}
});
// 处理未捕获的异常
process.on('uncaughtException', (error) => {
console.error('Uncaught Exception:', error);
});
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
});

467
electron/main.cjs Normal file
View File

@@ -0,0 +1,467 @@
const { app, BrowserWindow, Menu, Tray, shell, ipcMain, dialog } = require('electron');
const path = require('path');
const { spawn } = require('child_process');
const fs = require('fs');
// 动态导入可能有 ESM 问题的模块
let portfinder;
let Store;
let autoUpdater;
try {
portfinder = require('portfinder');
Store = require('electron-store');
const updaterModule = require('electron-updater');
autoUpdater = updaterModule.autoUpdater;
} catch (error) {
console.error('Error loading modules:', error);
// 提供后备方案
portfinder = {
getPortPromise: async () => 18080 + Math.floor(Math.random() * 100)
};
Store = class {
constructor() { this.data = {}; }
get(key, defaultValue) { return this.data[key] || defaultValue; }
set(key, value) { this.data[key] = value; }
};
}
// 初始化配置存储
const store = new Store();
// 全局变量
let mainWindow = null;
let backendProcess = null;
let tray = null;
let backendPort = null;
let isQuitting = false;
// 开发环境检测
const isDev = process.env.NODE_ENV === 'development' || !app.isPackaged;
// 防止多开
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on('second-instance', () => {
// 如果用户试图运行第二个实例,我们应该聚焦我们的窗口
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
}
// 后端进程管理类
class BackendManager {
constructor() {
this.process = null;
this.port = null;
this.retryCount = 0;
this.maxRetries = 3;
this.isStarting = false;
this.healthCheckInterval = null;
}
async findAvailablePort() {
portfinder.basePort = store.get('backend.port', 18080);
try {
const port = await portfinder.getPortPromise();
this.port = port;
return port;
} catch (error) {
console.error('Error finding available port:', error);
throw error;
}
}
async start() {
if (this.isStarting || this.process) {
console.log('Backend already starting or running');
return;
}
this.isStarting = true;
try {
// 查找可用端口
await this.findAvailablePort();
console.log(`Starting backend on port ${this.port}`);
// 确定后端可执行文件路径
let backendPath;
if (isDev) {
// 开发环境:使用 node 运行构建后的 JS
backendPath = path.join(__dirname, '..', 'dist', 'backend', 'starter.js');
} else {
// 生产环境:使用打包后的后端
backendPath = path.join(process.resourcesPath, 'backend', 'starter.js');
}
// 确保后端文件存在
if (!fs.existsSync(backendPath)) {
throw new Error(`Backend file not found at ${backendPath}`);
}
// 设置环境变量
const env = {
...process.env,
PORT: this.port.toString(),
NODE_ENV: isDev ? 'development' : 'production',
DATA_PATH: app.getPath('userData'),
DB_PATH: path.join(app.getPath('userData'), 'database.db'),
};
// 启动后端进程
if (isDev) {
this.process = spawn('node', [backendPath], {
env,
cwd: path.join(__dirname, '..'),
stdio: ['ignore', 'pipe', 'pipe']
});
} else {
this.process = spawn('node', [backendPath], {
env,
cwd: process.resourcesPath,
stdio: ['ignore', 'pipe', 'pipe']
});
}
// 监听后端输出
this.process.stdout.on('data', (data) => {
console.log(`Backend stdout: ${data}`);
// 向渲染进程发送日志
if (mainWindow) {
mainWindow.webContents.send('backend-log', data.toString());
}
});
this.process.stderr.on('data', (data) => {
console.error(`Backend stderr: ${data}`);
if (mainWindow) {
mainWindow.webContents.send('backend-error', data.toString());
}
});
// 监听后端进程退出
this.process.on('exit', (code) => {
console.log(`Backend process exited with code ${code}`);
this.process = null;
this.isStarting = false;
// 如果不是正在退出且退出码不为0尝试重启
if (!isQuitting && code !== 0 && this.retryCount < this.maxRetries) {
this.retryCount++;
console.log(`Attempting to restart backend (retry ${this.retryCount}/${this.maxRetries})`);
setTimeout(() => this.start(), 2000);
}
});
// 等待后端启动
await this.waitForBackend();
// 启动健康检查
this.startHealthCheck();
// 更新全局端口变量
backendPort = this.port;
// 通知渲染进程
if (mainWindow) {
mainWindow.webContents.send('backend-started', { port: this.port });
}
this.isStarting = false;
this.retryCount = 0;
return this.port;
} catch (error) {
console.error('Failed to start backend:', error);
this.isStarting = false;
throw error;
}
}
async waitForBackend() {
const maxWaitTime = 30000; // 30秒
const checkInterval = 500; // 每500ms检查一次
const startTime = Date.now();
while (Date.now() - startTime < maxWaitTime) {
try {
// 尝试连接后端健康检查端点
const response = await fetch(`http://127.0.0.1:${this.port}/health`);
if (response.ok) {
console.log('Backend is ready');
return;
}
} catch (error) {
// 继续等待
}
await new Promise(resolve => setTimeout(resolve, checkInterval));
}
throw new Error('Backend failed to start within timeout period');
}
startHealthCheck() {
if (this.healthCheckInterval) {
clearInterval(this.healthCheckInterval);
}
this.healthCheckInterval = setInterval(async () => {
if (!this.process) return;
try {
const response = await fetch(`http://127.0.0.1:${this.port}/health`);
if (!response.ok) {
console.error('Backend health check failed');
// 可以在这里触发重启逻辑
}
} catch (error) {
console.error('Backend health check error:', error);
}
}, 10000); // 每10秒检查一次
}
stop() {
return new Promise((resolve) => {
if (this.healthCheckInterval) {
clearInterval(this.healthCheckInterval);
this.healthCheckInterval = null;
}
if (!this.process) {
resolve();
return;
}
console.log('Stopping backend process...');
// 设置超时强制杀死
const killTimeout = setTimeout(() => {
if (this.process) {
console.log('Force killing backend process');
this.process.kill('SIGKILL');
}
}, 5000);
this.process.on('exit', () => {
clearTimeout(killTimeout);
this.process = null;
console.log('Backend process stopped');
resolve();
});
// 优雅关闭
this.process.kill('SIGTERM');
});
}
}
// 创建后端管理器实例
const backendManager = new BackendManager();
// 创建主窗口
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
minWidth: 800,
minHeight: 600,
title: 'Termix',
icon: path.join(__dirname, '..', 'public', 'icon.png'),
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.cjs'),
webSecurity: !isDev
},
show: false, // 先不显示,等加载完成
});
// 移除默认菜单栏Windows/Linux
if (process.platform !== 'darwin') {
mainWindow.setMenuBarVisibility(false);
}
// 加载应用
if (isDev) {
// 开发环境:连接到 Vite 开发服务器
mainWindow.loadURL('http://localhost:5173');
mainWindow.webContents.openDevTools();
} else {
// 生产环境:加载构建后的文件
mainWindow.loadFile(path.join(__dirname, '..', 'dist', 'index.html'));
}
// 窗口准备好后显示
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
// 处理窗口关闭事件
mainWindow.on('close', (event) => {
if (!isQuitting && process.platform === 'darwin') {
// macOS隐藏窗口而不是退出
event.preventDefault();
mainWindow.hide();
} else if (!isQuitting && store.get('minimizeToTray', true)) {
// Windows/Linux最小化到托盘
event.preventDefault();
mainWindow.hide();
}
});
mainWindow.on('closed', () => {
mainWindow = null;
});
// 处理外部链接
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: 'deny' };
});
}
// 创建系统托盘
function createTray() {
if (process.platform === 'darwin') return; // macOS 不需要托盘
const iconPath = path.join(__dirname, '..', 'public', 'icon.png');
tray = new Tray(iconPath);
const contextMenu = Menu.buildFromTemplate([
{
label: '显示',
click: () => {
if (mainWindow) {
mainWindow.show();
mainWindow.focus();
}
}
},
{ type: 'separator' },
{
label: '退出',
click: () => {
isQuitting = true;
app.quit();
}
}
]);
tray.setToolTip('Termix');
tray.setContextMenu(contextMenu);
// 双击托盘图标显示窗口
tray.on('double-click', () => {
if (mainWindow) {
mainWindow.show();
mainWindow.focus();
}
});
}
// IPC 通信处理
ipcMain.handle('get-backend-port', () => {
return backendPort;
});
ipcMain.handle('get-app-version', () => {
return app.getVersion();
});
ipcMain.handle('get-platform', () => {
return process.platform;
});
ipcMain.handle('restart-backend', async () => {
try {
await backendManager.stop();
await backendManager.start();
return { success: true, port: backendManager.port };
} catch (error) {
return { success: false, error: error.message };
}
});
ipcMain.handle('show-save-dialog', async (event, options) => {
const result = await dialog.showSaveDialog(mainWindow, options);
return result;
});
ipcMain.handle('show-open-dialog', async (event, options) => {
const result = await dialog.showOpenDialog(mainWindow, options);
return result;
});
// 自动更新
if (!isDev && autoUpdater) {
try {
autoUpdater.checkForUpdatesAndNotify();
autoUpdater.on('update-available', () => {
if (mainWindow) {
mainWindow.webContents.send('update-available');
}
});
autoUpdater.on('update-downloaded', () => {
if (mainWindow) {
mainWindow.webContents.send('update-downloaded');
}
});
} catch (error) {
console.log('Auto-updater not available:', error);
}
}
// 应用事件处理
app.whenReady().then(async () => {
try {
// 启动后端
await backendManager.start();
// 创建窗口
createWindow();
// 创建托盘
createTray();
} catch (error) {
console.error('Failed to initialize application:', error);
dialog.showErrorBox('启动失败', `无法启动应用: ${error.message}`);
app.quit();
}
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
} else if (mainWindow) {
mainWindow.show();
}
});
app.on('before-quit', async () => {
isQuitting = true;
await backendManager.stop();
});
// 处理未捕获的异常
process.on('uncaughtException', (error) => {
console.error('Uncaught Exception:', error);
dialog.showErrorBox('未捕获的异常', error.message);
});
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
});

View File

@@ -0,0 +1,18 @@
const { contextBridge, ipcRenderer } = require('electron');
// 暴露简化的 API 给渲染进程
contextBridge.exposeInMainWorld('electronAPI', {
// 获取应用版本
getAppVersion: () => ipcRenderer.invoke('get-app-version'),
// 获取平台信息
getPlatform: () => ipcRenderer.invoke('get-platform'),
// 环境检测
isElectron: true,
isDev: process.env.NODE_ENV === 'development',
});
// 添加一个标识,让渲染进程知道这是 Electron 环境
// 在上下文隔离环境中,使用 contextBridge 暴露
contextBridge.exposeInMainWorld('IS_ELECTRON', true);

54
electron/preload.cjs Normal file
View File

@@ -0,0 +1,54 @@
const { contextBridge, ipcRenderer } = require('electron');
// 暴露安全的 API 给渲染进程
contextBridge.exposeInMainWorld('electronAPI', {
// 获取后端端口
getBackendPort: () => ipcRenderer.invoke('get-backend-port'),
// 获取应用版本
getAppVersion: () => ipcRenderer.invoke('get-app-version'),
// 获取平台信息
getPlatform: () => ipcRenderer.invoke('get-platform'),
// 重启后端
restartBackend: () => ipcRenderer.invoke('restart-backend'),
// 文件对话框
showSaveDialog: (options) => ipcRenderer.invoke('show-save-dialog', options),
showOpenDialog: (options) => ipcRenderer.invoke('show-open-dialog', options),
// 监听后端事件
onBackendStarted: (callback) => {
ipcRenderer.on('backend-started', (event, data) => callback(data));
},
onBackendLog: (callback) => {
ipcRenderer.on('backend-log', (event, data) => callback(data));
},
onBackendError: (callback) => {
ipcRenderer.on('backend-error', (event, data) => callback(data));
},
// 监听更新事件
onUpdateAvailable: (callback) => {
ipcRenderer.on('update-available', () => callback());
},
onUpdateDownloaded: (callback) => {
ipcRenderer.on('update-downloaded', () => callback());
},
// 移除事件监听器
removeAllListeners: (channel) => {
ipcRenderer.removeAllListeners(channel);
},
// 环境检测
isElectron: true,
isDev: process.env.NODE_ENV === 'development',
});
// 添加一个标识,让渲染进程知道这是 Electron 环境
window.IS_ELECTRON = true;

4127
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,29 @@
{
"name": "termix",
"private": true,
"version": "0.0.0",
"version": "1.6.0",
"description": "Open-source server management platform with SSH terminal access, tunnel management, and file editing",
"author": {
"name": "LukeGus",
"email": "support@termix.site"
},
"type": "module",
"main": "electron/main-simple.cjs",
"scripts": {
"dev": "vite",
"build": "vite build",
"build": "vite build && npm run build:backend",
"build:frontend": "vite build",
"build:backend": "tsc -p tsconfig.node.json",
"dev:backend": "tsc -p tsconfig.node.json && node ./dist/backend/starter.js",
"lint": "eslint .",
"preview": "vite preview"
"preview": "vite preview",
"electron": "electron .",
"electron:dev": "npm run build:backend && NODE_ENV=development electron .",
"electron:package": "npm run build && electron-packager . Termix --platform=win32 --arch=x64 --out=release --overwrite --ignore=\"^/src|^/public|^/node_modules|^/repo-images\" --prune=true --icon=public/favicon.ico",
"electron:package:win": "npm run build && electron-packager . Termix --platform=win32 --arch=x64 --out=release --overwrite --ignore=\"^/src|^/public|^/node_modules|^/repo-images\" --prune=true --icon=public/favicon.ico",
"electron:package:mac": "npm run build && electron-packager . Termix --platform=darwin --arch=universal --out=release --overwrite --ignore=\"^/src|^/public|^/node_modules|^/repo-images\" --prune=true --icon=public/icon.png",
"electron:package:linux": "npm run build && electron-packager . Termix --platform=linux --arch=x64 --out=release --overwrite --ignore=\"^/src|^/public|^/node_modules|^/repo-images\" --prune=true --icon=public/icon.png",
"electron:package:all": "npm run build && npm run electron:package:win && npm run electron:package:mac && npm run electron:package:linux"
},
"dependencies": {
"@hookform/resolvers": "^5.1.1",
@@ -30,11 +44,6 @@
"@radix-ui/react-switch": "^1.2.5",
"@radix-ui/react-tabs": "^1.1.12",
"@radix-ui/react-tooltip": "^1.2.8",
"@tailwindcss/vite": "^4.1.11",
"@types/bcryptjs": "^2.4.6",
"@types/multer": "^2.0.0",
"@types/qrcode": "^1.5.5",
"@types/speakeasy": "^2.0.10",
"@uiw/codemirror-extensions-hyper-link": "^4.24.1",
"@uiw/codemirror-extensions-langs": "^4.24.1",
"@uiw/codemirror-themes": "^4.24.1",
@@ -74,33 +83,41 @@
"react-i18next": "^15.7.3",
"react-resizable-panels": "^3.0.3",
"react-responsive": "^10.0.1",
"react-simple-keyboard": "^3.8.120",
"react-xtermjs": "^1.0.10",
"sonner": "^2.0.7",
"speakeasy": "^2.0.0",
"ssh2": "^1.16.0",
"tailwind-merge": "^3.3.1",
"tailwindcss": "^4.1.11",
"validator": "^13.15.15",
"ws": "^8.18.3",
"zod": "^4.0.5"
},
"devDependencies": {
"@eslint/js": "^9.34.0",
"@tailwindcss/vite": "^4.1.12",
"@types/bcryptjs": "^2.4.6",
"@types/better-sqlite3": "^7.6.13",
"@types/cors": "^2.8.19",
"@types/express": "^5.0.3",
"@types/jsonwebtoken": "^9.0.10",
"@types/multer": "^2.0.0",
"@types/node": "^24.3.0",
"@types/qrcode": "^1.5.5",
"@types/react": "^19.1.8",
"@types/react-dom": "^19.1.6",
"@types/speakeasy": "^2.0.10",
"@types/ssh2": "^1.15.5",
"@types/ws": "^8.18.1",
"@vitejs/plugin-react-swc": "^3.10.2",
"autoprefixer": "^10.4.21",
"electron": "^31.7.0",
"electron-packager": "^17.1.2",
"eslint": "^9.34.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.20",
"globals": "^16.3.0",
"tailwindcss": "^4.1.12",
"ts-node": "^10.9.2",
"tw-animate-css": "^1.3.5",
"typescript": "~5.9.2",

BIN
public/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

View File

@@ -223,6 +223,7 @@
"port": "端口",
"name": "名称",
"username": "用户名",
"hostName": "主机名",
"folder": "文件夹",
"tags": "标签",
"passwordRequired": "使用密码认证时需要密码",

View File

@@ -146,7 +146,7 @@ app.get('/version', async (req, res) => {
const localVersion = process.env.VERSION;
if (!localVersion) {
return res.status(401).send('Local Version Not Set');
return res.status(404).send('Local Version Not Set');
}
try {
@@ -235,6 +235,16 @@ app.get('/releases/rss', async (req, res) => {
}
});
// Health check endpoint for Electron backend manager
app.get('/health', (req, res) => {
res.status(200).json({
status: 'ok',
timestamp: new Date().toISOString(),
service: 'database-api',
port: PORT
});
});
app.use('/users', userRoutes);
app.use('/ssh', sshRoutes);
app.use('/alerts', alertRoutes);

View File

@@ -17,7 +17,7 @@ export const users = sqliteTable('users', {
identifier_path: text('identifier_path'),
name_path: text('name_path'),
scopes: text().default("openid email profile"),
totp_secret: text('totp_secret'),
totp_enabled: integer('totp_enabled', {mode: 'boolean'}).notNull().default(false),
totp_backup_codes: text('totp_backup_codes'),

View File

@@ -1314,11 +1314,10 @@ router.delete('/delete-user', authenticateJWT, async (req, res) => {
await db.delete(fileManagerRecent).where(eq(fileManagerRecent.userId, targetUserId));
await db.delete(fileManagerPinned).where(eq(fileManagerPinned.userId, targetUserId));
await db.delete(fileManagerShortcuts).where(eq(fileManagerShortcuts.userId, targetUserId));
await db.delete(dismissedAlerts).where(eq(dismissedAlerts.userId, targetUserId));
await db.delete(sshData).where(eq(sshData.userId, targetUserId));
// Note: All user-related data has been deleted above
// The tables config_editor_* and shared_hosts don't exist in the current schema
} catch (cleanupError) {

View File

@@ -1,6 +1,6 @@
import { Children, ReactElement, cloneElement, isValidElement } from 'react';
import { ButtonProps } from '@/components/ui/button';
import { type ButtonProps } from '@/components/ui/button';
import { cn } from '@/lib/utils';
interface ButtonGroupProps {

View File

@@ -35,16 +35,19 @@ const buttonVariants = cva(
}
)
export interface ButtonProps
extends React.ComponentProps<"button">,
VariantProps<typeof buttonVariants> {
asChild?: boolean
}
function Button({
className,
variant,
size,
asChild = false,
...props
}: React.ComponentProps<"button"> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}) {
}: ButtonProps) {
const Comp = asChild ? Slot : "button"
return (
@@ -56,4 +59,4 @@ function Button({
)
}
export { Button, buttonVariants }
export { Button, buttonVariants, type ButtonProps }

View File

@@ -1,6 +1,6 @@
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, VariantProps } from "class-variance-authority"
import { cva, type VariantProps } from "class-variance-authority"
import { PanelLeftIcon } from "lucide-react"
import { useIsMobile } from "@/hooks/use-mobile"

View File

@@ -1,5 +1,5 @@
import { useTheme } from "next-themes"
import { Toaster as Sonner, ToasterProps } from "sonner"
import { Toaster as Sonner, type ToasterProps } from "sonner"
const Toaster = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme()

View File

@@ -25,7 +25,7 @@ i18n
// Backend options
backend: {
loadPath: '/locales/{{lng}}/translation.json',
loadPath: './locales/{{lng}}/translation.json',
},
interpolation: {

View File

@@ -21,14 +21,12 @@ function useWindowWidth() {
const newWidth = window.innerWidth;
const newIsMobile = newWidth < 768;
const now = Date.now();
// If we've already switched once, don't switch again for a very long time
if (hasSwitchedOnce.current && (now - lastSwitchTime.current) < 10000) {
setWidth(newWidth);
return;
}
// Only switch if we're actually crossing the threshold AND enough time has passed
if (newIsMobile !== isCurrentlyMobile.current && (now - lastSwitchTime.current) > 5000) {
lastSwitchTime.current = now;
isCurrentlyMobile.current = newIsMobile;
@@ -38,7 +36,7 @@ function useWindowWidth() {
} else {
setWidth(newWidth);
}
}, 2000); // Even longer debounce
}, 2000);
};
window.addEventListener("resize", handleResize);
@@ -54,8 +52,12 @@ function useWindowWidth() {
function RootApp() {
const width = useWindowWidth();
const isMobile = width < 768;
// Use a stable key to prevent unnecessary remounting
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
if (isElectron) {
return <DesktopApp />;
}
return isMobile ? <MobileApp key="mobile" /> : <DesktopApp key="desktop" />;
}

21
src/types/electron.d.ts vendored Normal file
View File

@@ -0,0 +1,21 @@
interface ElectronAPI {
getBackendPort: () => Promise<number>;
getAppVersion: () => Promise<string>;
getPlatform: () => Promise<string>;
restartBackend: () => Promise<{ success: boolean; port?: number; error?: string }>;
showSaveDialog: (options: any) => Promise<any>;
showOpenDialog: (options: any) => Promise<any>;
onBackendStarted: (callback: (data: { port: number }) => void) => void;
onBackendLog: (callback: (data: string) => void) => void;
onBackendError: (callback: (data: string) => void) => void;
onUpdateAvailable: (callback: () => void) => void;
onUpdateDownloaded: (callback: () => void) => void;
removeAllListeners: (channel: string) => void;
isElectron: boolean;
isDev: boolean;
}
interface Window {
electronAPI?: ElectronAPI;
IS_ELECTRON?: boolean;
}

View File

@@ -206,7 +206,7 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
className="bg-[#18181b] text-white rounded-lg border-2 border-[#303032] overflow-hidden">
<div className="h-full w-full flex flex-col">
<div className="flex items-center justify-between px-3 pt-2 pb-2">
<h1 className="font-bold text-lg">{t('admin.title')}</h1>
<h1 className="font-bold text-lg">Admin Settings</h1>
</div>
<Separator className="p-0.25 w-full"/>
@@ -223,7 +223,7 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
</TabsTrigger>
<TabsTrigger value="users" className="flex items-center gap-2">
<Users className="h-4 w-4"/>
{t('admin.users')}
Users
</TabsTrigger>
<TabsTrigger value="admins" className="flex items-center gap-2">
<Shield className="h-4 w-4"/>
@@ -244,8 +244,9 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
<TabsContent value="oidc" className="space-y-6">
<div className="space-y-4">
<h3 className="text-lg font-semibold">{t('admin.externalAuthentication')}</h3>
<p className="text-sm text-muted-foreground">{t('admin.configureExternalProvider')}</p>
<h3 className="text-lg font-semibold">External Authentication (OIDC)</h3>
<p className="text-sm text-muted-foreground">Configure external identity provider for
OIDC/OAuth2 authentication.</p>
{oidcError && (
<Alert variant="destructive">
@@ -256,50 +257,50 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
<form onSubmit={handleOIDCConfigSubmit} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="client_id">{t('admin.clientId')}</Label>
<Label htmlFor="client_id">Client ID</Label>
<Input id="client_id" value={oidcConfig.client_id}
onChange={(e) => handleOIDCConfigChange('client_id', e.target.value)}
placeholder={t('placeholders.clientId')} required/>
placeholder="your-client-id" required/>
</div>
<div className="space-y-2">
<Label htmlFor="client_secret">{t('admin.clientSecret')}</Label>
<Label htmlFor="client_secret">Client Secret</Label>
<Input id="client_secret" type="password" value={oidcConfig.client_secret}
onChange={(e) => handleOIDCConfigChange('client_secret', e.target.value)}
placeholder={t('placeholders.clientSecret')} required/>
placeholder="your-client-secret" required/>
</div>
<div className="space-y-2">
<Label htmlFor="authorization_url">{t('admin.authorizationUrl')}</Label>
<Label htmlFor="authorization_url">Authorization URL</Label>
<Input id="authorization_url" value={oidcConfig.authorization_url}
onChange={(e) => handleOIDCConfigChange('authorization_url', e.target.value)}
placeholder={t('placeholders.authUrl')}
placeholder="https://your-provider.com/application/o/authorize/"
required/>
</div>
<div className="space-y-2">
<Label htmlFor="issuer_url">{t('admin.issuerUrl')}</Label>
<Label htmlFor="issuer_url">Issuer URL</Label>
<Input id="issuer_url" value={oidcConfig.issuer_url}
onChange={(e) => handleOIDCConfigChange('issuer_url', e.target.value)}
placeholder={t('placeholders.redirectUrl')} required/>
placeholder="https://your-provider.com/application/o/termix/" required/>
</div>
<div className="space-y-2">
<Label htmlFor="token_url">{t('admin.tokenUrl')}</Label>
<Label htmlFor="token_url">Token URL</Label>
<Input id="token_url" value={oidcConfig.token_url}
onChange={(e) => handleOIDCConfigChange('token_url', e.target.value)}
placeholder={t('placeholders.tokenUrl')} required/>
placeholder="https://your-provider.com/application/o/token/" required/>
</div>
<div className="space-y-2">
<Label htmlFor="identifier_path">{t('admin.userIdentifierPath')}</Label>
<Label htmlFor="identifier_path">User Identifier Path</Label>
<Input id="identifier_path" value={oidcConfig.identifier_path}
onChange={(e) => handleOIDCConfigChange('identifier_path', e.target.value)}
placeholder={t('placeholders.userIdField')} required/>
placeholder="sub" required/>
</div>
<div className="space-y-2">
<Label htmlFor="name_path">{t('admin.displayNamePath')}</Label>
<Label htmlFor="name_path">Display Name Path</Label>
<Input id="name_path" value={oidcConfig.name_path}
onChange={(e) => handleOIDCConfigChange('name_path', e.target.value)}
placeholder={t('placeholders.usernameField')} required/>
placeholder="name" required/>
</div>
<div className="space-y-2">
<Label htmlFor="scopes">{t('admin.scopes')}</Label>
<Label htmlFor="scopes">Scopes</Label>
<Input id="scopes" value={oidcConfig.scopes}
onChange={(e) => handleOIDCConfigChange('scopes', e.target.value)}
placeholder={t('placeholders.scopes')} required/>
@@ -310,9 +311,15 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
onChange={(e) => handleOIDCConfigChange('userinfo_url', e.target.value)}
placeholder="https://your-provider.com/application/o/userinfo/"/>
</div>
<div className="space-y-2">
<Label htmlFor="userinfo_url">{t('admin.overrideUserInfoUrl')}</Label>
<Input id="userinfo_url" value={oidcConfig.userinfo_url}
onChange={(e) => handleOIDCConfigChange('userinfo_url', e.target.value)}
placeholder="https://your-provider.com/application/o/userinfo/"/>
</div>
<div className="flex gap-2 pt-2">
<Button type="submit" className="flex-1"
disabled={oidcLoading}>{oidcLoading ? t('admin.saving') : t('admin.saveConfiguration')}</Button>
disabled={oidcLoading}>{oidcLoading ? "Saving..." : "Save Configuration"}</Button>
<Button type="button" variant="outline" onClick={() => setOidcConfig({
client_id: '',
client_secret: '',
@@ -332,20 +339,20 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
<TabsContent value="users" className="space-y-6">
<div className="space-y-4">
<div className="flex items-center justify-between">
<h3 className="text-lg font-semibold">{t('admin.userManagement')}</h3>
<h3 className="text-lg font-semibold">User Management</h3>
<Button onClick={fetchUsers} disabled={usersLoading} variant="outline"
size="sm">{usersLoading ? t('admin.loading') : t('admin.refresh')}</Button>
size="sm">{usersLoading ? "Loading..." : "Refresh"}</Button>
</div>
{usersLoading ? (
<div className="text-center py-8 text-muted-foreground">{t('admin.loadingUsers')}</div>
<div className="text-center py-8 text-muted-foreground">Loading users...</div>
) : (
<div className="border rounded-md overflow-hidden">
<Table>
<TableHeader>
<TableRow>
<TableHead className="px-4">{t('admin.username')}</TableHead>
<TableHead className="px-4">{t('admin.type')}</TableHead>
<TableHead className="px-4">{t('admin.actions')}</TableHead>
<TableHead className="px-4">Username</TableHead>
<TableHead className="px-4">Type</TableHead>
<TableHead className="px-4">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
@@ -355,11 +362,11 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
{user.username}
{user.is_admin && (
<span
className="ml-2 inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-muted/50 text-muted-foreground border border-border">{t('admin.adminBadge')}</span>
className="ml-2 inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-muted/50 text-muted-foreground border border-border">Admin</span>
)}
</TableCell>
<TableCell
className="px-4">{user.is_oidc ? t('admin.external') : t('admin.local')}</TableCell>
className="px-4">{user.is_oidc ? "External" : "Local"}</TableCell>
<TableCell className="px-4">
<Button variant="ghost" size="sm"
onClick={() => handleDeleteUser(user.username)}
@@ -379,18 +386,18 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
<TabsContent value="admins" className="space-y-6">
<div className="space-y-6">
<h3 className="text-lg font-semibold">{t('admin.adminManagement')}</h3>
<h3 className="text-lg font-semibold">Admin Management</h3>
<div className="space-y-4 p-6 border rounded-md bg-muted/50">
<h4 className="font-medium">{t('admin.makeUserAdmin')}</h4>
<h4 className="font-medium">Make User Admin</h4>
<form onSubmit={handleMakeUserAdmin} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="new-admin-username">{t('admin.username')}</Label>
<Label htmlFor="new-admin-username">Username</Label>
<div className="flex gap-2">
<Input id="new-admin-username" value={newAdminUsername}
onChange={(e) => setNewAdminUsername(e.target.value)}
placeholder={t('admin.enterUsernameToMakeAdmin')} required/>
<Button type="submit"
disabled={makeAdminLoading || !newAdminUsername.trim()}>{makeAdminLoading ? t('admin.adding') : t('admin.makeAdmin')}</Button>
disabled={makeAdminLoading || !newAdminUsername.trim()}>{makeAdminLoading ? "Adding..." : "Make Admin"}</Button>
</div>
</div>
{makeAdminError && (
@@ -404,14 +411,14 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
</div>
<div className="space-y-4">
<h4 className="font-medium">{t('admin.currentAdmins')}</h4>
<h4 className="font-medium">Current Admins</h4>
<div className="border rounded-md overflow-hidden">
<Table>
<TableHeader>
<TableRow>
<TableHead className="px-4">{t('admin.username')}</TableHead>
<TableHead className="px-4">{t('admin.type')}</TableHead>
<TableHead className="px-4">{t('admin.actions')}</TableHead>
<TableHead className="px-4">Username</TableHead>
<TableHead className="px-4">Type</TableHead>
<TableHead className="px-4">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
@@ -423,13 +430,13 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
className="ml-2 inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-muted/50 text-muted-foreground border border-border">{t('admin.adminBadge')}</span>
</TableCell>
<TableCell
className="px-4">{admin.is_oidc ? t('admin.external') : t('admin.local')}</TableCell>
className="px-4">{admin.is_oidc ? "External" : "Local"}</TableCell>
<TableCell className="px-4">
<Button variant="ghost" size="sm"
onClick={() => handleRemoveAdminStatus(admin.username)}
className="text-orange-600 hover:text-orange-700 hover:bg-orange-50">
<Shield className="h-4 w-4"/>
{t('admin.removeAdminButton')}
Remove Admin
</Button>
</TableCell>
</TableRow>

View File

@@ -279,9 +279,13 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
const isDev = process.env.NODE_ENV === 'development' &&
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
const wsUrl = isDev
? 'ws://localhost:8082'
: isElectron
? 'ws://127.0.0.1:8082'
: `${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${window.location.host}/ssh/websocket/`;
const ws = new WebSocket(wsUrl);
@@ -357,7 +361,7 @@ style.innerHTML = `
/* Load NerdFonts locally */
@font-face {
font-family: 'JetBrains Mono Nerd Font';
src: url('/fonts/JetBrainsMonoNerdFont-Regular.ttf') format('truetype');
src: url('./fonts/JetBrainsMonoNerdFont-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
font-display: swap;
@@ -365,7 +369,7 @@ style.innerHTML = `
@font-face {
font-family: 'JetBrains Mono Nerd Font';
src: url('/fonts/JetBrainsMonoNerdFont-Bold.ttf') format('truetype');
src: url('./fonts/JetBrainsMonoNerdFont-Bold.ttf') format('truetype');
font-weight: bold;
font-style: normal;
font-display: swap;
@@ -373,7 +377,7 @@ style.innerHTML = `
@font-face {
font-family: 'JetBrains Mono Nerd Font';
src: url('/fonts/JetBrainsMonoNerdFont-Italic.ttf') format('truetype');
src: url('./fonts/JetBrainsMonoNerdFont-Italic.ttf') format('truetype');
font-weight: normal;
font-style: italic;
font-display: swap;

View File

@@ -17,14 +17,10 @@ import {
verifyPasswordResetCode,
completePasswordReset,
getOIDCAuthorizeUrl,
verifyTOTPLogin
verifyTOTPLogin,
setCookie
} from "../../main-axios.ts";
function setCookie(name: string, value: string, days = 7) {
const expires = new Date(Date.now() + days * 864e5).toUTCString();
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`;
}
function getCookie(name: string) {
return document.cookie.split('; ').reduce((r, v) => {
const parts = v.split('=');

View File

@@ -19,7 +19,6 @@ interface PasswordResetProps {
}
export function PasswordReset({userInfo}: PasswordResetProps) {
const {t} = useTranslation();
const [error, setError] = useState<string | null>(null);
const [resetStep, setResetStep] = useState<"initiate" | "verify" | "newPassword">("initiate");
@@ -28,6 +27,7 @@ export function PasswordReset({userInfo}: PasswordResetProps) {
const [confirmPassword, setConfirmPassword] = useState("");
const [tempToken, setTempToken] = useState("");
const [resetLoading, setResetLoading] = useState(false);
const {t} = useTranslation();
async function handleInitiatePasswordReset() {
setError(null);
@@ -168,7 +168,7 @@ export function PasswordReset({userInfo}: PasswordResetProps) {
setResetCode("");
}}
>
{t('common.back')}
Back
</Button>
</div>
</>
@@ -225,14 +225,14 @@ export function PasswordReset({userInfo}: PasswordResetProps) {
setConfirmPassword("");
}}
>
{t('common.back')}
Back
</Button>
</div>
</>
)}
{error && (
<Alert variant="destructive" className="mt-4">
<AlertTitle>{t('common.error')}</AlertTitle>
<AlertTitle>Error</AlertTitle>
<AlertDescription>{error}</AlertDescription>
</Alert>
)}

View File

@@ -108,6 +108,17 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
return () => window.removeEventListener('resize', handleWindowResize);
}, []);
useEffect(() => {
if (!terminal) return;
const textarea = (terminal as any)._core?._textarea as HTMLTextAreaElement | undefined;
if (textarea) {
textarea.setAttribute("readonly", "true");
textarea.setAttribute("inputmode", "none");
textarea.style.caretColor = "transparent";
}
}, [terminal]);
function handleWindowResize() {
if (!isVisibleRef.current) return;
fitAddonRef.current?.fit();
@@ -168,7 +179,7 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
scrollback: 10000,
fontSize: 14,
fontFamily: '"JetBrains Mono Nerd Font", "MesloLGS NF", "FiraCode Nerd Font", "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace',
theme: {background: '#18181b', foreground: '#f7f7f7'},
theme: {background: '#09090b', foreground: '#f7f7f7'},
allowTransparency: true,
convertEol: true,
windowsMode: false,
@@ -209,7 +220,6 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
if (terminal) scheduleNotify(terminal.cols, terminal.rows);
hardRefresh();
setVisible(true);
terminal.focus();
}, 100);
return () => {
@@ -229,7 +239,7 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
scrollback: 10000,
fontSize: 14,
fontFamily: '"JetBrains Mono Nerd Font", "MesloLGS NF", "FiraCode Nerd Font", "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace',
theme: {background: '#18181b', foreground: '#f7f7f7'},
theme: {background: '#09090b', foreground: '#f7f7f7'},
allowTransparency: true,
convertEol: true,
windowsMode: false,
@@ -274,7 +284,6 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
if (terminal) scheduleNotify(terminal.cols, terminal.rows);
hardRefresh();
setVisible(true);
terminal.focus();
}, 0);
const cols = terminal.cols;
@@ -282,9 +291,13 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
const isDev = process.env.NODE_ENV === 'development' &&
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
const wsUrl = isDev
? 'ws://localhost:8082'
: isElectron
? 'ws://127.0.0.1:8082'
: `${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${window.location.host}/ssh/websocket/`;
const ws = new WebSocket(wsUrl);
@@ -309,7 +322,6 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
fitAddonRef.current?.fit();
if (terminal) scheduleNotify(terminal.cols, terminal.rows);
hardRefresh();
terminal.focus();
}, 0);
}
}, [isVisible, terminal]);
@@ -320,9 +332,6 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
fitAddonRef.current?.fit();
if (terminal) scheduleNotify(terminal.cols, terminal.rows);
hardRefresh();
if (terminal && isVisible) {
terminal.focus();
}
}, 0);
}, [isVisible, terminal]);
@@ -331,9 +340,6 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
ref={xtermRef}
className="h-full w-full m-1"
style={{opacity: visible && isVisible ? 1 : 0, overflow: 'hidden'}}
onClick={() => {
terminal.focus();
}}
/>
);
});
@@ -345,7 +351,7 @@ style.innerHTML = `
/* Load NerdFonts locally */
@font-face {
font-family: 'JetBrains Mono Nerd Font';
src: url('/fonts/JetBrainsMonoNerdFont-Regular.ttf') format('truetype');
src: url('./fonts/JetBrainsMonoNerdFont-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
font-display: swap;
@@ -353,7 +359,7 @@ style.innerHTML = `
@font-face {
font-family: 'JetBrains Mono Nerd Font';
src: url('/fonts/JetBrainsMonoNerdFont-Bold.ttf') format('truetype');
src: url('./fonts/JetBrainsMonoNerdFont-Bold.ttf') format('truetype');
font-weight: bold;
font-style: normal;
font-display: swap;
@@ -361,7 +367,7 @@ style.innerHTML = `
@font-face {
font-family: 'JetBrains Mono Nerd Font';
src: url('/fonts/JetBrainsMonoNerdFont-Italic.ttf') format('truetype');
src: url('./fonts/JetBrainsMonoNerdFont-Italic.ttf') format('truetype');
font-weight: normal;
font-style: italic;
font-display: swap;
@@ -399,7 +405,7 @@ style.innerHTML = `
font-feature-settings: "liga" 1, "calt" 1;
}
.xterm .xterm-screen .xterm-char[data-char-code^="\\uE"] {
.xterm .xterm-screen .xterm-char[data-char-code^="\uE000"] {
font-family: 'JetBrains Mono Nerd Font', 'MesloLGS NF', 'FiraCode Nerd Font' !important;
}
`;

View File

@@ -0,0 +1,181 @@
import React, {useState} from "react";
import Keyboard from "react-simple-keyboard";
import "react-simple-keyboard/build/css/index.css";
import "./kb-dark-theme.css";
interface TerminalKeyboardProps {
onSendInput: (input: string) => void;
}
export function TerminalKeyboard({onSendInput}: TerminalKeyboardProps) {
const [layoutName, setLayoutName] = useState("default");
const [isCtrl, setIsCtrl] = useState(false);
const [isAlt, setIsAlt] = useState(false);
const onKeyPress = async (button: string) => {
if (button === "{shift}") {
setLayoutName("shift");
return;
}
if (button === "{unshift}") {
setLayoutName("default");
return;
}
if (button === "{more}") {
setLayoutName("more");
return;
}
if (button === "{less}") {
setLayoutName("default");
return;
}
if (button === "{hide}") {
setLayoutName("hide");
return;
}
if (button === "{unhide}") {
setLayoutName("default");
return;
}
if (button === "{ctrl}") {
setIsCtrl(prev => !prev);
return;
}
if (button === "{alt}") {
setIsAlt(prev => !prev);
return;
}
if (button === "{paste}") {
if (navigator.clipboard?.readText) {
try {
const text = await navigator.clipboard.readText();
if (text) {
onSendInput(text);
}
} catch (err) {
}
}
return;
}
let input = button;
const specialKeyMap: { [key: string]: string } = {
"{esc}": "\x1b", "{enter}": "\r", "{tab}": "\t", "{backspace}": "\x7f",
"{arrowUp}": "\x1b[A", "{arrowDown}": "\x1b[B", "{arrowRight}": "\x1b[C", "{arrowLeft}": "\x1b[D",
"{home}": "\x1b[H", "{end}": "\x1b[F", "{pgUp}": "\x1b[5~", "{pgDn}": "\x1b[6~",
"F1": "\x1bOP", "F2": "\x1bOQ", "F3": "\x1bOR", "F4": "\x1bOS",
"F5": "\x1b[15~", "F6": "\x1b[17~", "F7": "\x1b[18~", "F8": "\x1b[19~",
"F9": "\x1b[20~", "F10": "\x1b[21~", "F11": "\x1b[23~", "F12": "\x1b[24~",
"{space}": " "
};
if (specialKeyMap[input]) {
input = specialKeyMap[input];
}
if (isCtrl) {
if (input.length === 1) {
const charCode = input.toUpperCase().charCodeAt(0);
if (charCode >= 64 && charCode <= 95) {
input = String.fromCharCode(charCode - 64);
}
}
}
if (isAlt) {
input = `\x1b${input}`;
}
onSendInput(input);
};
const buttonTheme = [
{
class: "hg-space-big",
buttons: "{space}",
},
{
class: "hg-space-medium",
buttons: "{enter} {backspace}",
},
{
class: "hg-space-small",
buttons: "{hide} {less} {more}",
}
];
if (isCtrl) {
buttonTheme.push({class: "key-active", buttons: "{ctrl}"});
}
if (isAlt) {
buttonTheme.push({class: "key-active", buttons: "{alt}"});
}
return (
<div className="">
<Keyboard
layout={{
default: [
"{esc} {tab} {ctrl} {alt} {arrowLeft} {arrowRight} {arrowUp} {arrowDown}",
"q w e r t y u i o p",
"a s d f g h j k l",
"{shift} z x c v b n m {backspace}",
"{hide} {more} {space} {enter}",
],
shift: [
"{esc} {tab} {ctrl} {alt} {arrowLeft} {arrowRight} {arrowUp} {arrowDown}",
"Q W E R T Y U I O P",
"A S D F G H J K L",
"{unshift} Z X C V B N M {backspace}",
"{hide} {more} {space} {enter}",
],
more: [
"{esc} {tab} {ctrl} {alt} {end} {home} {pgUp} {pgDn}",
"1 2 3 4 5 6 7 8 9 0",
"! @ # $ % ^ & * ( ) _ +",
"[ ] { } | \\ ; : ' \" , . / < >",
"F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12",
"{arrowLeft} {arrowRight} {arrowUp} {arrowDown} {paste} {backspace}",
"{hide} {less} {space} {enter}",
],
hide: [
"{unhide}"
]
}}
layoutName={layoutName}
onKeyPress={onKeyPress}
display={{
"{shift}": "up",
"{unshift}": "dn",
"{backspace}": "back",
"{more}": "more",
"{less}": "less",
"{space}": "space",
"{enter}": "enter",
"{arrowLeft}": "←",
"{arrowRight}": "→",
"{arrowUp}": "↑",
"{arrowDown}": "↓",
"{hide}": "hide",
"{unhide}": "unhide",
"{esc}": "esc",
"{tab}": "tab",
"{ctrl}": "ctrl",
"{alt}": "alt",
"{paste}": "paste",
"{end}": "end",
"{home}": "home",
"{pgUp}": "pgUp",
"{pgDn}": "pgDn",
}}
theme={"hg-theme-default dark-theme"}
useTouchEvents={true}
buttonTheme={buttonTheme}
/>
</div>
);
}

View File

@@ -0,0 +1,40 @@
.simple-keyboard.dark-theme {
background-color: rgb(24, 24, 27);
border-radius: 0;
}
.simple-keyboard.dark-theme .hg-button {
height: 50px;
display: flex;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0.5);
color: #bfbfbf;
border-bottom-color: rgb(122, 122, 122);
}
.simple-keyboard.dark-theme .hg-button:active {
background: rgba(83, 83, 83, 0.5);
color: #bfbfbf;
}
#root .simple-keyboard.dark-theme + .simple-keyboard-preview {
background: rgba(83, 83, 83, 0.5);
}
.dark-theme .hg-button.key-active {
background: rgba(126, 126, 126, 0.5);
color: white;
}
.hg-space-big {
width: 100px;
}
.hg-space-medium {
width: 60px;
}
.hg-space-small {
width: 1px;
}

View File

@@ -1,14 +1,57 @@
import {useRef, FC} from "react";
import {Terminal} from "@/ui/Mobile/Apps/Terminal/Terminal.tsx";
import {TerminalKeyboard} from "@/ui/Mobile/Apps/Terminal/TerminalKeyboard.tsx";
export const MobileApp: FC = () => {
const terminalRef = useRef<any>(null);
function handleKeyboardInput(input: string) {
if (!terminalRef.current?.sendInput) return;
const keyMap: Record<string, string> = {
"{backspace}": "\x7f",
"{space}": " ",
"{tab}": "\t",
"{enter}": "\r",
"{escape}": "\x1b",
"{arrowUp}": "\x1b[A",
"{arrowDown}": "\x1b[B",
"{arrowRight}": "\x1b[C",
"{arrowLeft}": "\x1b[D",
"{delete}": "\x1b[3~",
"{home}": "\x1b[H",
"{end}": "\x1b[F",
"{pageUp}": "\x1b[5~",
"{pageDown}": "\x1b[6~",
};
if (input in keyMap) {
terminalRef.current.sendInput(keyMap[input]);
} else {
terminalRef.current.sendInput(input);
}
}
export function MobileApp() {
return (
<div className="h-screen w-screen bg-[#18181b]">
<Terminal hostConfig={{
ip: "n/a",
port: 22,
username: "n/a",
password: "n/a"
}} isVisible={true}/>
<div className="h-screen w-screen flex flex-col bg-[#09090b] overflow-y-hidden overflow-x-hidden">
<div className="flex-1 min-h-0">
<Terminal
ref={terminalRef}
hostConfig={{
ip: "192.210.197.55",
port: 22,
username: "bugattiguy527",
password: "bugatti$123"
}}
isVisible={true}
/>
</div>
<TerminalKeyboard
onSendInput={handleKeyboardInput}
/>
<div className="w-full h-[80px] bg-[#18181BFF]">
</div>
</div>
)
}
}

View File

@@ -158,15 +158,28 @@ interface OIDCAuthorize {
// UTILITY FUNCTIONS
// ============================================================================
function setCookie(name: string, value: string, days = 7): void {
const expires = new Date(Date.now() + days * 864e5).toUTCString();
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`;
export function setCookie(name: string, value: string, days = 7): void {
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
if (isElectron) {
localStorage.setItem(name, value);
} else {
const expires = new Date(Date.now() + days * 864e5).toUTCString();
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`;
}
}
function getCookie(name: string): string | undefined {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop()?.split(';').shift();
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
if (isElectron) {
const token = localStorage.getItem(name) || undefined;
return token;
} else {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
const token = parts.length === 2 ? parts.pop()?.split(';').shift() : undefined;
return token;
}
}
function createApiInstance(baseURL: string): AxiosInstance {
@@ -180,6 +193,8 @@ function createApiInstance(baseURL: string): AxiosInstance {
const token = getCookie('jwt');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
} else {
console.log('No token found, Authorization header not set');
}
return config;
});
@@ -201,34 +216,64 @@ function createApiInstance(baseURL: string): AxiosInstance {
// API INSTANCES
// ============================================================================
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
const isDev = process.env.NODE_ENV === 'development' &&
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
let apiHost = import.meta.env.VITE_API_HOST || 'localhost';
let apiPort = 8081;
if (isElectron) {
apiPort = 8081;
}
function getApiUrl(path: string, defaultPort: number): string {
if (isElectron) {
return `http://127.0.0.1:${defaultPort}${path}`;
} else if (isDev) {
return `http://${apiHost}:${defaultPort}${path}`;
} else {
return path;
}
}
// Multi-port backend architecture (original design)
// SSH Host Management API (port 8081)
export const sshHostApi = createApiInstance(
isDev ? 'http://localhost:8081/ssh' : '/ssh'
export let sshHostApi = createApiInstance(
getApiUrl('/ssh', 8081)
);
// Tunnel Management API (port 8083)
export const tunnelApi = createApiInstance(
isDev ? 'http://localhost:8083/ssh' : '/ssh'
export let tunnelApi = createApiInstance(
getApiUrl('/ssh', 8083)
);
// File Manager Operations API (port 8084) - SSH file operations
export const fileManagerApi = createApiInstance(
isDev ? 'http://localhost:8084/ssh/file_manager' : '/ssh/file_manager'
export let fileManagerApi = createApiInstance(
getApiUrl('/ssh/file_manager', 8084)
);
// Server Statistics API (port 8085)
export const statsApi = createApiInstance(
isDev ? 'http://localhost:8085' : ''
export let statsApi = createApiInstance(
getApiUrl('', 8085)
);
// Authentication API (port 8081) - includes users, alerts, version, releases
export const authApi = createApiInstance(
isDev ? 'http://localhost:8081' : ''
export let authApi = createApiInstance(
getApiUrl('', 8081)
);
// Function to update API instances with new port (for Electron)
function updateApiPorts(port: number) {
apiPort = port;
sshHostApi = createApiInstance(`http://127.0.0.1:${port}/ssh`);
tunnelApi = createApiInstance(`http://127.0.0.1:${port}/ssh`);
fileManagerApi = createApiInstance(`http://127.0.0.1:${port}/ssh/file_manager`);
statsApi = createApiInstance(`http://127.0.0.1:${port}`);
authApi = createApiInstance(`http://127.0.0.1:${port}`);
}
// ============================================================================
// ERROR HANDLING
// ============================================================================
@@ -945,7 +990,7 @@ export async function generateBackupCodes(password?: string, totp_code?: string)
export async function getUserAlerts(userId: string): Promise<{ alerts: any[] }> {
try {
const apiInstance = createApiInstance(isDev ? 'http://localhost:8081' : '');
const apiInstance = createApiInstance(isDev ? `http://${apiHost}:8081` : '');
const response = await apiInstance.get(`/alerts/user/${userId}`);
return response.data;
} catch (error) {
@@ -956,7 +1001,7 @@ export async function getUserAlerts(userId: string): Promise<{ alerts: any[] }>
export async function dismissAlert(userId: string, alertId: string): Promise<any> {
try {
// Use the general API instance since alerts endpoint is at root level
const apiInstance = createApiInstance(isDev ? 'http://localhost:8081' : '');
const apiInstance = createApiInstance(isDev ? `http://${apiHost}:8081` : '');
const response = await apiInstance.post('/alerts/dismiss', { userId, alertId });
return response.data;
} catch (error) {
@@ -970,9 +1015,7 @@ export async function dismissAlert(userId: string, alertId: string): Promise<any
export async function getReleasesRSS(perPage: number = 100): Promise<any> {
try {
// Use the general API instance since releases endpoint is at root level
const apiInstance = createApiInstance(isDev ? 'http://localhost:8081' : '');
const response = await apiInstance.get(`/releases/rss?per_page=${perPage}`);
const response = await authApi.get(`/releases/rss?per_page=${perPage}`);
return response.data;
} catch (error) {
handleApiError(error, 'fetch releases RSS');
@@ -981,9 +1024,7 @@ export async function getReleasesRSS(perPage: number = 100): Promise<any> {
export async function getVersionInfo(): Promise<any> {
try {
// Use the general API instance since version endpoint is at root level
const apiInstance = createApiInstance(isDev ? 'http://localhost:8081' : '');
const response = await apiInstance.get('/version/');
const response = await authApi.get('/version/');
return response.data;
} catch (error) {
handleApiError(error, 'fetch version info');

View File

@@ -11,4 +11,5 @@ export default defineConfig({
"@": path.resolve(__dirname, "./src"),
},
},
base: './', // 使用相对路径,适配 Electron
})