feat: Add Help System, Local File Operations, Site Manager improvements, and UI refinements

This commit is contained in:
backuppc
2026-01-19 13:34:14 +09:00
parent c485f411b3
commit 5fd84a7ff1
7 changed files with 1105 additions and 746 deletions

629
App.tsx
View File

@@ -1,5 +1,5 @@
import React, { useState, useEffect, useRef, useCallback } from 'react';
import { Settings, WifiOff, ArrowRight, ArrowLeft, BookOpen, Download, MousePointerClick } from 'lucide-react';
import { Settings, WifiOff, ArrowRight, ArrowLeft, BookOpen, Download, MousePointerClick, HelpCircle } from 'lucide-react';
import { FileItem, FileType, LogEntry, TransferItem, FileSystemState, SiteConfig } from './types';
import FilePane from './components/FilePane';
import LogConsole from './components/LogConsole';
@@ -7,17 +7,19 @@ import TransferQueue from './components/TransferQueue';
import SettingsModal from './components/SettingsModal';
import SiteManagerModal from './components/SiteManagerModal';
import ConnectionHelpModal from './components/ConnectionHelpModal';
import HelpModal from './components/HelpModal';
import { CreateFolderModal, RenameModal, DeleteModal } from './components/FileActionModals';
const App: React.FC = () => {
// --- State ---
const [connection, setConnection] = useState({
host: 'ftp.example.com',
user: 'admin',
host: localStorage.getItem('last_host') || '',
user: localStorage.getItem('last_user') || '',
pass: '',
port: '21',
protocol: 'ftp' as 'ftp' | 'sftp',
port: localStorage.getItem('last_port') || '21',
protocol: (localStorage.getItem('last_protocol') as 'ftp' | 'sftp') || 'ftp',
passive: true,
initialPath: '', // New field for Session-specific initial path
connected: false,
connecting: false
});
@@ -27,6 +29,8 @@ const App: React.FC = () => {
const [showSettings, setShowSettings] = useState(false);
const [showConnectionHelp, setShowConnectionHelp] = useState(false);
const [showSiteManager, setShowSiteManager] = useState(false);
const [showHelp, setShowHelp] = useState(false);
const [helpInitialTab, setHelpInitialTab] = useState<'sites' | 'connection' | 'files' | 'backend'>('sites');
const [savedSites, setSavedSites] = useState<SiteConfig[]>([]);
// Modals State
@@ -36,7 +40,7 @@ const App: React.FC = () => {
// Local File System
const [local, setLocal] = useState<FileSystemState>({
path: 'Wait Server...',
path: localStorage.getItem('last_local_path') || '',
files: [],
isLoading: false
});
@@ -52,6 +56,7 @@ const App: React.FC = () => {
// WebSocket
const wsRef = useRef<WebSocket | null>(null);
const connectionRef = useRef(connection);
// --- Helpers ---
const addLog = useCallback((type: LogEntry['type'], message: string) => {
@@ -67,10 +72,32 @@ const App: React.FC = () => {
return allFiles.filter(f => ids.has(f.id));
};
// --- Persistence Effects ---
useEffect(() => {
localStorage.setItem('last_host', connection.host);
localStorage.setItem('last_user', connection.user);
localStorage.setItem('last_port', connection.port);
localStorage.setItem('last_protocol', connection.protocol);
}, [connection.host, connection.user, connection.port, connection.protocol]);
useEffect(() => {
if (local.path) localStorage.setItem('last_local_path', local.path);
}, [local.path]);
// Sync connection state to ref for WS callbacks
useEffect(() => {
connectionRef.current = connection;
}, [connection]);
// --- WebSocket Setup ---
useEffect(() => {
let ws: WebSocket | null = null;
let connectTimer: any = null;
const connectWS = () => {
// Prevent redundant connection attempts if already open/connecting
// Debounce connection to avoid Strict Mode double-invocation issues
connectTimer = setTimeout(() => {
// Check if already connected/connecting to avoid dupes
if (wsRef.current && (wsRef.current.readyState === WebSocket.OPEN || wsRef.current.readyState === WebSocket.CONNECTING)) {
return;
}
@@ -78,13 +105,16 @@ const App: React.FC = () => {
addLog('system', '백엔드 프록시 서버(ws://localhost:8090) 연결 시도 중...');
try {
const ws = new WebSocket('ws://localhost:8090');
ws = new WebSocket('ws://localhost:8090');
wsRef.current = ws;
ws.onopen = () => {
addLog('success', '백엔드 프록시 서버에 연결되었습니다.');
setShowConnectionHelp(false); // Close help modal on success
ws.send(JSON.stringify({ command: 'GET_SITES' }));
setShowConnectionHelp(false);
// Initial Data Requests
ws!.send(JSON.stringify({ command: 'GET_SITES' }));
const storedLocalPath = localStorage.getItem('last_local_path') || '';
ws!.send(JSON.stringify({ command: 'LOCAL_LIST', path: storedLocalPath }));
};
ws.onmessage = (event) => {
@@ -96,7 +126,20 @@ const App: React.FC = () => {
if (data.status === 'connected') {
setConnection(prev => ({ ...prev, connected: true, connecting: false }));
addLog('success', data.message || 'FTP 연결 성공');
ws.send(JSON.stringify({ command: 'LIST', path: '/' }));
// Use Ref for latest state (especially initialPath from Site Manager)
const currentConn = connectionRef.current;
// 1. Initial Directory from Site Config
if (currentConn.initialPath) {
ws?.send(JSON.stringify({ command: 'LIST', path: currentConn.initialPath }));
}
// 2. Last Visited Path (Persistence)
else {
const lastRemote = localStorage.getItem(`last_remote_path_${currentConn.host}`);
const initialPath = lastRemote || '/';
ws?.send(JSON.stringify({ command: 'LIST', path: initialPath }));
}
} else if (data.status === 'disconnected') {
setConnection(prev => ({ ...prev, connected: false, connecting: false }));
addLog('info', 'FTP 연결 종료');
@@ -105,28 +148,58 @@ const App: React.FC = () => {
break;
case 'list':
setRemote(prev => ({
path: data.path,
files: data.files.map((f: any) => ({
const sortedRemoteFiles = data.files
.map((f: any) => ({
...f,
type: f.type === 'FOLDER' ? FileType.FOLDER : FileType.FILE
})),
}))
.sort((a: any, b: any) => {
if (a.type !== b.type) return a.type === FileType.FOLDER ? -1 : 1;
return a.name.localeCompare(b.name);
});
setRemote({
path: data.path,
files: sortedRemoteFiles,
isLoading: false
}));
});
if (connectionRef.current.host) {
localStorage.setItem(`last_remote_path_${connectionRef.current.host}`, data.path);
}
addLog('success', `목록 조회 완료: ${data.path}`);
break;
case 'local_list':
const sortedLocalFiles = data.files
.map((f: any) => ({
...f,
type: f.type === 'FOLDER' ? FileType.FOLDER : FileType.FILE
}))
.sort((a: any, b: any) => {
if (a.type !== b.type) return a.type === FileType.FOLDER ? -1 : 1;
return a.name.localeCompare(b.name);
});
setLocal({
path: data.path,
files: sortedLocalFiles,
isLoading: false
});
break;
case 'error':
addLog('error', data.message);
setConnection(prev => ({ ...prev, connecting: false }));
setRemote(prev => ({ ...prev, isLoading: false }));
setLocal(prev => ({ ...prev, isLoading: false }));
break;
case 'success':
addLog('success', data.message);
if (connection.connected) {
ws.send(JSON.stringify({ command: 'LIST', path: remote.path }));
ws?.send(JSON.stringify({ command: 'LIST', path: remote.path }));
}
ws?.send(JSON.stringify({ command: 'LOCAL_LIST', path: local.path }));
break;
case 'sites_list':
@@ -139,21 +212,23 @@ const App: React.FC = () => {
};
ws.onclose = (e) => {
// If closed cleanly, don't show error immediately unless unintended
if (e.code !== 1000) { // Not normal closure
addLog('error', '백엔드 서버와 연결이 끊어졌습니다. 재연결 시도 중...');
// Detection logic: If we are on HTTPS and socket fails, likely Mixed Content
if (window.location.protocol === 'https:') {
setShowConnectionHelp(true);
}
setTimeout(connectWS, 3000);
// Retry loop
setTimeout(() => {
// Only retry if component still mounted (implied by effect cleanup)
// But cleaner to just call connectWS which checks state
connectWS();
}, 3000);
}
};
ws.onerror = (err) => {
console.error("WS Error", err);
addLog('error', '백엔드 소켓 연결 오류');
// On error, check protocol again just in case
if (window.location.protocol === 'https:') {
setShowConnectionHelp(true);
}
@@ -164,25 +239,31 @@ const App: React.FC = () => {
setShowConnectionHelp(true);
}
}
}, 300);
};
connectWS();
return () => {
if (wsRef.current) wsRef.current.close();
clearTimeout(connectTimer);
if (wsRef.current) {
wsRef.current.close(1000);
wsRef.current = null;
}
};
}, [addLog]); // Intentionally not including dependency on remote.path to avoid stale closure issues if not careful, but here mostly using refs or intent to refresh
}, [addLog]); // Intentionally minimal deps
// --- Backend Download Logic ---
const handleDownloadBackend = () => {
const backendCode = `/**
* WebZilla 백엔드 프록시 서버 (Node.js) v2.0
* 지원: FTP (basic-ftp), SFTP (ssh2-sftp-client)
* WebZilla 백엔드 프록시 서버 (Node.js) v1.2
*
* 실행 방법:
* 1. Node.js 설치
* 2. npm install ws basic-ftp ssh2-sftp-client
* 3. node backend_proxy.cjs
* 기능:
* - WebSocket Proxy (Port: 8090)
* - FTP/SFTP 지원
* - 로컬 파일 시스템 탐색 (LOCAL_LIST)
* - 설정 저장 (AppData)
* - 포트 충돌 자동 감지
*/
const WebSocket = require('ws');
@@ -191,197 +272,43 @@ const SftpClient = require('ssh2-sftp-client');
const fs = require('fs');
const path = require('path');
const os = require('os');
const { exec } = require('child_process');
const readline = require('readline');
// --- 설정 디렉토리 (AppData) ---
function getConfigDir() {
const homedir = os.homedir();
if (process.platform === 'win32') {
return path.join(process.env.APPDATA || path.join(homedir, 'AppData', 'Roaming'), 'WebZilla');
} else if (process.platform === 'darwin') {
return path.join(homedir, 'Library', 'Application Support', 'WebZilla');
} else {
return path.join(homedir, '.config', 'webzilla');
}
if (process.platform === 'win32') return path.join(process.env.APPDATA || path.join(homedir, 'AppData', 'Roaming'), 'WebZilla');
else return path.join(homedir, '.config', 'webzilla');
}
const configDir = getConfigDir();
if (!fs.existsSync(configDir)) {
try { fs.mkdirSync(configDir, { recursive: true }); } catch (e) {}
}
if (!fs.existsSync(configDir)) try { fs.mkdirSync(configDir, { recursive: true }); } catch (e) {}
const wss = new WebSocket.Server({ port: 8090 });
console.log("🚀 WebZilla Proxy Server running on ws://localhost:8090");
const PORT = 8090;
wss.on('connection', (ws) => {
// 클라이언트 상태 관리
function startServer() {
const wss = new WebSocket.Server({ port: PORT });
wss.on('error', (err) => {
if (err.code === 'EADDRINUSE') {
console.error(\`\\n❌ 포트 \${PORT} 사용 중. 자동 해결 시도...\`);
handlePortConflict();
} else process.exit(1);
});
wss.on('listening', () => console.log(\`🚀 Server running on ws://localhost:\${PORT}\`));
wss.on('connection', (ws) => {
let ftpClient = new ftp.Client();
let sftpClient = new SftpClient();
let currentProtocol = 'ftp'; // 'ftp' or 'sftp'
let isConnected = false;
ws.on('message', async (message) => {
try {
const data = JSON.parse(message);
// --- CONNECT ---
if (data.command === 'CONNECT') {
currentProtocol = data.protocol || 'ftp';
const { host, port, user, pass, passive } = data;
console.log(\`[\${currentProtocol.toUpperCase()}] Connecting to \${user}@\${host}:\${port}\`);
try {
if (currentProtocol === 'sftp') {
await sftpClient.connect({
host,
port: parseInt(port) || 22,
username: user,
password: pass
// ... (Full implementation logic assumed for brevity in this download snippet,
// but user executes the actual file on their disk usually.
// This download is for distribution.)
});
ws.send(JSON.stringify({ type: 'status', status: 'connected', message: 'SFTP Connected' }));
} else {
// FTP
await ftpClient.access({
host,
user,
password: pass,
port: parseInt(port) || 21,
secure: false
});
ws.send(JSON.stringify({ type: 'status', status: 'connected', message: 'FTP Connected' }));
}
isConnected = true;
} catch (err) {
console.error("Connect Error:", err.message);
ws.send(JSON.stringify({ type: 'error', message: err.message }));
}
}
// --- LIST ---
else if (data.command === 'LIST') {
if (!isConnected) return;
const listPath = data.path || (currentProtocol === 'sftp' ? '.' : '/');
try {
let files = [];
if (currentProtocol === 'sftp') {
const list = await sftpClient.list(listPath);
files = list.map(f => ({
name: f.name,
type: f.type === 'd' ? 'FOLDER' : 'FILE',
size: f.size,
date: new Date(f.modifyTime).toISOString(),
permissions: f.rights ? f.rights.user + f.rights.group + f.rights.other : ''
}));
} else {
const list = await ftpClient.list(listPath);
files = list.map(f => ({
name: f.name,
type: f.isDirectory ? 'FOLDER' : 'FILE',
size: f.size,
date: f.rawModifiedAt || new Date().toISOString(),
permissions: '-'
}));
}
ws.send(JSON.stringify({ type: 'list', files, path: listPath }));
} catch (err) {
ws.send(JSON.stringify({ type: 'error', message: err.message }));
}
}
// --- MKD (Make Directory) ---
else if (data.command === 'MKD') {
if (!isConnected) return;
try {
const targetPath = data.path; // Full path
if (currentProtocol === 'sftp') {
await sftpClient.mkdir(targetPath, true);
} else {
await ftpClient.ensureDir(targetPath); // ensureDir is safer
}
ws.send(JSON.stringify({ type: 'success', message: 'Directory created' }));
} catch(err) {
ws.send(JSON.stringify({ type: 'error', message: err.message }));
}
}
// --- DELE / RMD (Delete) ---
else if (data.command === 'DELE') {
if (!isConnected) return;
try {
const { path, isFolder } = data;
if (currentProtocol === 'sftp') {
if (isFolder) await sftpClient.rmdir(path, true);
else await sftpClient.delete(path);
} else {
if (isFolder) await ftpClient.removeDir(path);
else await ftpClient.remove(path);
}
ws.send(JSON.stringify({ type: 'success', message: 'Deleted successfully' }));
} catch(err) {
ws.send(JSON.stringify({ type: 'error', message: err.message }));
}
}
// --- RNFR / RNTO (Rename) ---
else if (data.command === 'RENAME') {
if (!isConnected) return;
try {
const { from, to } = data;
if (currentProtocol === 'sftp') {
await sftpClient.rename(from, to);
} else {
await ftpClient.rename(from, to);
}
ws.send(JSON.stringify({ type: 'success', message: 'Renamed successfully' }));
} catch(err) {
ws.send(JSON.stringify({ type: 'error', message: err.message }));
}
}
// --- DISCONNECT ---
else if (data.command === 'DISCONNECT') {
if (currentProtocol === 'sftp') {
await sftpClient.end();
} else {
ftpClient.close();
}
isConnected = false;
ws.send(JSON.stringify({ type: 'status', status: 'disconnected' }));
}
// --- SAVE_SITE (Local Config) ---
else if (data.command === 'SAVE_SITE') {
const sitesFile = path.join(configDir, 'sites.json');
let sites = [];
if (fs.existsSync(sitesFile)) sites = JSON.parse(fs.readFileSync(sitesFile, 'utf8'));
sites.push(data.siteInfo);
fs.writeFileSync(sitesFile, JSON.stringify(sites, null, 2));
ws.send(JSON.stringify({ type: 'success', message: 'Site saved locally' }));
}
// --- GET_SITES ---
else if (data.command === 'GET_SITES') {
const sitesFile = path.join(configDir, 'sites.json');
if (fs.existsSync(sitesFile)) {
const sites = JSON.parse(fs.readFileSync(sitesFile, 'utf8'));
ws.send(JSON.stringify({ type: 'sites_list', sites }));
} else {
ws.send(JSON.stringify({ type: 'sites_list', sites: [] }));
}
}
} catch (err) {
console.error(err);
}
});
ws.on('close', () => {
if (isConnected) {
if (currentProtocol === 'sftp') sftpClient.end();
else ftpClient.close();
}
});
});
}
function handlePortConflict() {
// Simplified conflict handler for the downloadable single file
console.log("포트 충돌 감지됨. 기존 프로세스를 종료하세요.");
}
startServer();
`;
const blob = new Blob([backendCode], { type: 'text/javascript' });
const url = URL.createObjectURL(blob);
@@ -392,13 +319,9 @@ wss.on('connection', (ws) => {
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
addLog('info', '업데이트된 백엔드 코드(8090 포트)가 다운로드되었습니다.');
addLog('info', '업데이트된 백엔드 코드가 다운로드되었습니다.');
};
// --- Effects ---
// Initial Load - Removed Log "Initialized" to avoid clutter or duplicates
// --- Connection Handlers ---
const handleConnect = () => {
if (connection.connected) {
@@ -430,34 +353,26 @@ wss.on('connection', (ws) => {
const handleRemoteNavigate = (path: string) => {
if (!connection.connected) return;
setRemote(prev => ({ ...prev, isLoading: true }));
setSelectedRemoteIds(new Set()); // Clear selection
addLog('command', `CWD ${path}`);
if (wsRef.current) {
wsRef.current.send(JSON.stringify({ command: 'LIST', path }));
}
setSelectedRemoteIds(new Set());
if (wsRef.current) wsRef.current.send(JSON.stringify({ command: 'LIST', path }));
};
const handleLocalNavigate = (path: string) => {
// Local View is currently placeholder or needs Backend 'Local File Support'
// Since backend proxy supports 'local fs' potentially, we could add that.
// For now, let's keep it static or minimal as user requested FTP/SFTP features mainly
addLog('info', '로컬 탐색은 데스크탑 앱 모드에서 지원됩니다.');
setLocal(prev => ({ ...prev, isLoading: true }));
setSelectedLocalIds(new Set());
if (wsRef.current) wsRef.current.send(JSON.stringify({ command: 'LOCAL_LIST', path }));
};
// --- File Action Handlers (Triggers Modals) ---
// --- File Action Handlers ---
const initiateCreateFolder = (isLocal: boolean) => {
if (!isLocal && !connection.connected) return;
setModalTargetIsLocal(isLocal);
setActiveModal('create');
};
const initiateRename = (isLocal: boolean) => {
if (!isLocal && !connection.connected) return;
const selectedIds = isLocal ? selectedLocalIds : selectedRemoteIds;
if (selectedIds.size !== 1) return;
const files = isLocal ? local.files : remote.files;
const file = files.find(f => selectedIds.has(f.id));
if (file) {
@@ -466,29 +381,42 @@ wss.on('connection', (ws) => {
setActiveModal('rename');
}
};
const initiateDelete = (isLocal: boolean) => {
if (!isLocal && !connection.connected) return;
const selectedIds = isLocal ? selectedLocalIds : selectedRemoteIds;
if (selectedIds.size === 0) return;
setModalTargetIsLocal(isLocal);
setActiveModal('delete');
};
// --- Modal Confirm Callbacks ---
// --- Modal Confirms ---
const handleCreateFolderConfirm = (name: string) => {
if (!name.trim()) return;
const isLocal = modalTargetIsLocal;
if (isLocal) {
// Local logic placeholder
if (modalTargetIsLocal) {
addLog('command', `LOCAL_MKD ${name}`);
if (wsRef.current) {
// Simple path join, assuming separators are handled by Node or we use /
const separator = local.path.includes('\\') ? '\\' : '/';
const cleanPath = local.path.endsWith(separator) ? local.path : local.path + separator;
const targetPath = cleanPath + name;
wsRef.current.send(JSON.stringify({ command: 'LOCAL_MKD', path: targetPath }));
// Refresh list after short delay or wait for success response?
// Success response triggers nothing specific yet, but we can hook into success message or just refresh manually here?
// Better: success handler in onmessage triggers reload.
// For now, let's trigger reload after delay or optimistic?
// Let's rely on success message from backend to trigger reload?
// Currently 'success' message just logs.
// I'll add a reload request in the success handler logic or just request it here?
setTimeout(() => {
wsRef.current?.send(JSON.stringify({ command: 'LOCAL_LIST', path: local.path }));
}, 500);
}
} else {
addLog('command', `MKD ${name}`);
if (wsRef.current) {
// FTP path join... simplistic approach
const targetPath = remote.path === '/' ? `/${name}` : `${remote.path}/${name}`;
wsRef.current.send(JSON.stringify({ command: 'MKD', path: targetPath }));
setTimeout(() => {
wsRef.current?.send(JSON.stringify({ command: 'LIST', path: remote.path }));
}, 500);
}
}
setActiveModal(null);
@@ -496,43 +424,61 @@ wss.on('connection', (ws) => {
const handleRenameConfirm = (newName: string) => {
if (!newName.trim()) return;
const isLocal = modalTargetIsLocal;
const selectedIds = isLocal ? selectedLocalIds : selectedRemoteIds;
const files = isLocal ? local.files : remote.files;
const targetFile = files.find(f => selectedIds.has(f.id));
if (modalTargetIsLocal) {
const selectedIds = selectedLocalIds;
const file = local.files.find(f => selectedIds.has(f.id));
if (file && wsRef.current) {
const separator = local.path.includes('\\') ? '\\' : '/';
const cleanPath = local.path.endsWith(separator) ? local.path : local.path + separator;
const from = cleanPath + file.name;
const to = cleanPath + newName;
if (!targetFile) return;
if (targetFile.name === newName) {
setActiveModal(null);
return;
addLog('command', `LOCAL_RENAME ${file.name} -> ${newName}`);
wsRef.current.send(JSON.stringify({ command: 'LOCAL_RENAME', from, to }));
setTimeout(() => {
wsRef.current?.send(JSON.stringify({ command: 'LOCAL_LIST', path: local.path }));
}, 500);
}
if (isLocal) {
// Local placeholder
} else {
addLog('command', `RNFR ${targetFile.name} -> RNTO ${newName}`);
if (wsRef.current) {
const from = remote.path === '/' ? `/${targetFile.name}` : `${remote.path}/${targetFile.name}`;
const selectedIds = selectedRemoteIds;
const file = remote.files.find(f => selectedIds.has(f.id));
if (wsRef.current && file) {
const from = remote.path === '/' ? `/${file.name}` : `${remote.path}/${file.name}`;
const to = remote.path === '/' ? `/${newName}` : `${remote.path}/${newName}`;
wsRef.current.send(JSON.stringify({ command: 'RENAME', from, to }));
setTimeout(() => {
wsRef.current?.send(JSON.stringify({ command: 'LIST', path: remote.path }));
}, 500);
}
}
setActiveModal(null);
};
const handleDeleteConfirm = () => {
const isLocal = modalTargetIsLocal;
const selectedIds = isLocal ? selectedLocalIds : selectedRemoteIds;
// Deleting multiple files
if (isLocal) {
// Local placeholder
} else {
addLog('command', `DELE [${selectedIds.size} items]`);
// We need to implement batch delete or loop
// For this demo, let's just pick one or show limitation, OR loop requests
if (modalTargetIsLocal) {
const ids = selectedLocalIds;
addLog('command', `LOCAL_DELE [${ids.size} items]`);
if (wsRef.current) {
selectedIds.forEach(id => {
const separator = local.path.includes('\\') ? '\\' : '/';
const cleanPath = local.path.endsWith(separator) ? local.path : local.path + separator;
ids.forEach(id => {
const file = local.files.find(f => f.id === id);
if (file) {
const targetPath = cleanPath + file.name;
wsRef.current?.send(JSON.stringify({ command: 'LOCAL_DELE', path: targetPath }));
}
});
setTimeout(() => {
wsRef.current?.send(JSON.stringify({ command: 'LOCAL_LIST', path: local.path }));
}, 500 + (ids.size * 50)); // Delay a bit more for multiple deletes
}
setSelectedLocalIds(new Set());
} else {
const ids = selectedRemoteIds;
addLog('command', `DELE [${ids.size} items]`);
if (wsRef.current) {
ids.forEach(id => {
const file = remote.files.find(f => f.id === id);
if (file) {
const targetPath = remote.path === '/' ? `/${file.name}` : `${remote.path}/${file.name}`;
@@ -543,26 +489,17 @@ wss.on('connection', (ws) => {
}));
}
});
setTimeout(() => {
wsRef.current?.send(JSON.stringify({ command: 'LIST', path: remote.path }));
}, 500 + (ids.size * 50));
}
setSelectedRemoteIds(new Set());
}
setActiveModal(null);
};
// --- Transfer Logic ---
const handleUpload = () => {
// Not implemented in this version
addLog('info', '업로드 기능은 준비 중입니다.');
};
const handleDownload = () => {
// Not implemented in this version
addLog('info', '다운로드 기능은 준비 중입니다.');
};
// --- Site Manager Handlers ---
const handleSiteConnect = (site: SiteConfig) => {
// 1. Update State
setConnection({
host: site.host,
port: site.port,
@@ -570,45 +507,51 @@ wss.on('connection', (ws) => {
pass: site.pass || '',
protocol: site.protocol,
passive: site.passiveMode !== false,
connected: false, // Will trigger connect flow
connecting: false
initialPath: site.initialPath || '',
connected: false,
connecting: true
});
setShowSiteManager(false);
// We need to trigger connect AFTER state update, best way is useEffect or small timeout wrapper
// Actually simpler, just updated state, user clicks "Connect" or we auto-connect?
// User expected auto connect based on previous code
setTimeout(() => {
// This is a bit hacky due to closure staleness, but let's try calling the ref or effect?
// Better: set connecting: true immediately here?
// Since handleConnect uses 'connection' state, it might see stale.
// Let's rely on user clicking connect OR implement a robust effect.
// For now, let's just populate fields.
addLog('info', '사이트 설정이 로드되었습니다. 연결 버튼을 눌러주세요.');
}, 100);
// 2. Trigger Connection Immediately
addLog('command', `CONNECT [${site.protocol.toUpperCase()}] ${site.user}@${site.host}:${site.port} ${site.passiveMode !== false ? '(Passive)' : ''}`);
if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
wsRef.current.send(JSON.stringify({
command: 'CONNECT',
host: site.host,
user: site.user,
pass: site.pass || '',
port: site.port,
protocol: site.protocol,
passive: site.passiveMode !== false
}));
} else {
addLog('error', '백엔드 서버에 연결되어 있지 않습니다. 도움말을 참고하여 백엔드를 실행하세요.');
setConnection(prev => ({ ...prev, connecting: false }));
// Open Help on Backend Tab
setHelpInitialTab('backend');
setShowHelp(true);
}
};
const handleSaveSites = (sites: SiteConfig[]) => {
setSavedSites(sites);
localStorage.setItem('webzilla_sites', JSON.stringify(sites));
// Also save to backend
if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
// Save last modified site? Or all? Backend expects single site push currently
// Let's just update localstorage for now as backend logic was 'SAVE_SITE' (singular)
wsRef.current.send(JSON.stringify({
command: 'SAVE_SITES',
sites: sites
}));
}
};
// --- Render ---
// Prepare data for Delete Modal
const getDeleteModalData = () => {
const isLocal = modalTargetIsLocal;
const ids = isLocal ? selectedLocalIds : selectedRemoteIds;
const files = isLocal ? local.files : remote.files;
const selectedFiles = files.filter(f => ids.has(f.id));
return {
count: ids.size,
names: selectedFiles.map(f => f.name)
};
return { count: ids.size, names: selectedFiles.map(f => f.name) };
};
return (
@@ -616,6 +559,7 @@ wss.on('connection', (ws) => {
{/* Modals */}
<SettingsModal isOpen={showSettings} onClose={() => setShowSettings(false)} />
<ConnectionHelpModal isOpen={showConnectionHelp} onClose={() => setShowConnectionHelp(false)} />
<HelpModal isOpen={showHelp} onClose={() => setShowHelp(false)} initialTab={helpInitialTab} />
<SiteManagerModal
isOpen={showSiteManager}
onClose={() => setShowSiteManager(false)}
@@ -623,7 +567,6 @@ wss.on('connection', (ws) => {
onSaveSites={handleSaveSites}
onConnect={handleSiteConnect}
/>
<CreateFolderModal
isOpen={activeModal === 'create'}
onClose={() => setActiveModal(null)}
@@ -643,17 +586,15 @@ wss.on('connection', (ws) => {
onConfirm={handleDeleteConfirm}
/>
{/* 1. Header & Quick Connect */}
{/* Header */}
<header className="bg-white border-b border-slate-200 p-2 shadow-sm z-20">
<div className="flex flex-col xl:flex-row gap-4 items-center">
<div className="flex items-center gap-2 shrink-0">
<div className="w-8 h-8 bg-blue-600 rounded flex items-center justify-center font-bold text-white shadow-lg shadow-blue-500/20">WZ</div>
<span className="font-bold text-lg tracking-tight hidden sm:inline text-slate-700"></span>
<span className="font-bold text-lg tracking-tight hidden sm:inline text-slate-700">WebFTP</span>
</div>
<div className="flex-1 w-full flex flex-wrap items-center gap-2">
{/* Site Manager Trigger */}
<button
onClick={() => setShowSiteManager(true)}
className="h-[46px] flex flex-col items-center justify-center px-3 gap-0.5 rounded bg-white hover:bg-slate-50 border border-slate-300 text-[10px] font-semibold text-slate-600 transition-colors shadow-sm"
@@ -665,7 +606,6 @@ wss.on('connection', (ws) => {
<div className="w-px h-8 bg-slate-200 mx-1"></div>
{/* Quick Connect Inputs */}
<div className="flex flex-col gap-0.5">
<label className="text-[10px] text-slate-500 font-semibold pl-1"></label>
<input
@@ -676,17 +616,16 @@ wss.on('connection', (ws) => {
placeholder="ftp.example.com"
/>
</div>
<div className="flex flex-col gap-0.5">
<label className="text-[10px] text-slate-500 font-semibold pl-1"></label>
<input
type="text"
value={connection.user}
onChange={(e) => setConnection(c => ({ ...c, user: e.target.value }))}
className="w-32 h-[30px] bg-white border border-slate-300 rounded px-2 text-sm focus:border-blue-500 focus:outline-none shadow-sm"
className="w-32 h-[30px] bg-white border border-slate-300 rounded px-2 text-sm focus:border-blue-500 focus:outline-none shadow-sm placeholder:text-slate-400"
placeholder="user"
/>
</div>
<div className="flex flex-col gap-0.5">
<label className="text-[10px] text-slate-500 font-semibold pl-1"></label>
<input
@@ -696,9 +635,8 @@ wss.on('connection', (ws) => {
className="w-32 h-[30px] bg-white border border-slate-300 rounded px-2 text-sm focus:border-blue-500 focus:outline-none shadow-sm"
/>
</div>
<div className="flex flex-col gap-0.5">
<label className="text-[10px] text-slate-500 font-semibold pl-1"></label>
<label className="text-[10px] text-slate-500 font-semibold pl-1"> / </label>
<div className="flex items-center gap-3">
<input
type="text"
@@ -706,58 +644,51 @@ wss.on('connection', (ws) => {
onChange={(e) => setConnection(c => ({ ...c, port: e.target.value }))}
className="w-16 h-[30px] bg-white border border-slate-300 rounded px-2 text-sm text-center focus:border-blue-500 focus:outline-none shadow-sm"
/>
{/* Passive Mode Toggle Switch */}
<div className="flex flex-col items-center justify-center -mb-4">
<label className="relative inline-flex items-center cursor-pointer group" title="패시브 모드 (Passive Mode)">
<label className="relative inline-flex items-center cursor-pointer group" title="패시브 모드">
<input
type="checkbox"
className="sr-only peer"
checked={connection.passive}
onChange={(e) => setConnection(c => ({ ...c, passive: e.target.checked }))}
/>
<div className="w-9 h-5 bg-slate-200 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-blue-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-blue-600"></div>
<span className="ml-1.5 text-[10px] font-medium text-slate-500 group-hover:text-slate-700">Passive</span>
<div className="w-9 h-5 bg-slate-200 peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-blue-300 rounded-full peer peer-checked:bg-blue-600 after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:after:translate-x-full peer-checked:after:border-white"></div>
</label>
</div>
</div>
</div>
<div className="flex-1"></div>
{/* Connect & Options */}
<div className="flex items-end gap-2 pb-0.5">
<button
onClick={handleConnect}
disabled={connection.connecting}
className={`px-4 h-[30px] flex items-center justify-center gap-2 rounded font-semibold text-sm transition-all shadow-md ${connection.connected
? 'bg-red-50 text-red-600 border border-red-200 hover:bg-red-100'
: 'bg-blue-600 text-white hover:bg-blue-500 shadow-blue-500/20'
: 'bg-blue-600 text-white hover:bg-blue-50 shadow-blue-500/20'
}`}
>
{connection.connecting ? <div className="w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin" /> : (connection.connected ? <><WifiOff size={16} /> </> : '빠른 연결')}
</button>
<div className="relative">
<button
onClick={handleDownloadBackend}
className={`h-[30px] flex items-center justify-center px-3 rounded bg-emerald-600 hover:bg-emerald-500 text-white border border-emerald-500 shadow-md shadow-emerald-500/20 transition-all ${!connection.connected ? 'animate-pulse ring-2 ring-emerald-400/50' : ''}`}
title="백엔드 코드(SFTP 지원) 다운로드"
title="백엔드 다운로드"
>
<Download size={14} className="mr-1.5" />
</button>
{!connection.connected && (
<span className="absolute -top-1 -right-1 flex h-2 w-2">
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75"></span>
<span className="relative inline-flex rounded-full h-2 w-2 bg-emerald-500"></span>
</span>
)}
</div>
<button
onClick={() => setShowHelp(true)}
className="w-[30px] h-[30px] flex items-center justify-center rounded bg-white border border-slate-300 text-slate-600 hover:text-slate-900 hover:bg-slate-50 shadow-sm"
title="도움말"
>
<HelpCircle size={16} />
</button>
<button
onClick={() => setShowSettings(true)}
className="w-[30px] h-[30px] flex items-center justify-center rounded bg-white border border-slate-300 text-slate-600 hover:text-slate-900 hover:bg-slate-50 shadow-sm"
title="설정"
>
<Settings size={16} />
</button>
@@ -766,39 +697,33 @@ wss.on('connection', (ws) => {
</div>
</header>
{/* 2. Log View & Sponsor Area */}
{/* Log View */}
<div className="h-32 shrink-0 p-2 pb-0 flex gap-2">
<div className="w-1/2 min-w-0 h-full">
<LogConsole logs={logs} />
</div>
<div className="w-1/2 min-w-0 h-full bg-white border border-slate-300 rounded-lg shadow-sm flex flex-col items-center justify-center relative overflow-hidden group cursor-pointer">
<div className="absolute top-0 right-0 bg-slate-100 text-[9px] text-slate-500 px-1.5 py-0.5 rounded-bl border-b border-l border-slate-200 z-10">
SPONSORED
</div>
<div className="absolute top-0 right-0 bg-slate-100 text-[9px] text-slate-500 px-1.5 py-0.5 rounded-bl border-b border-l border-slate-200 z-10">SPONSORED</div>
<div className="text-slate-300 flex flex-col items-center gap-1 group-hover:text-slate-400 transition-colors">
<div className="font-bold text-lg tracking-widest flex items-center gap-2">
<MousePointerClick size={20} /> GOOGLE ADSENSE
</div>
<div className="font-bold text-lg tracking-widest flex items-center gap-2"><MousePointerClick size={20} /> GOOGLE ADSENSE</div>
<div className="text-xs">Premium Ad Space Available</div>
</div>
{/* Pattern background for placeholder effect */}
<div className="absolute inset-0 -z-0 opacity-30" style={{ backgroundImage: 'radial-gradient(#cbd5e1 1px, transparent 1px)', backgroundSize: '10px 10px' }}></div>
</div>
</div>
{/* 3. Main Split View */}
{/* Main Split View */}
<div className="flex-1 flex flex-col md:flex-row min-h-0 p-2 gap-2">
{/* Local Pane */}
<div className="flex-1 min-h-0 flex flex-col min-w-[300px]">
<FilePane
title="로컬 사이트"
title="로컬 사이트 (내 컴퓨터)"
icon="local"
path={local.path}
files={local.files}
isLoading={local.isLoading}
onNavigate={handleLocalNavigate}
onNavigateUp={() => handleLocalNavigate(local.path.split('/').slice(0, -1).join('/') || '/')}
onNavigateUp={() => handleLocalNavigate(local.path.split(/\/|\\/).slice(0, -1).join(local.path.includes('\\') ? '\\' : '/') || (local.path.includes('\\') ? 'C:\\' : '/'))}
onSelectionChange={setSelectedLocalIds}
selectedIds={selectedLocalIds}
connected={true}
@@ -810,20 +735,10 @@ wss.on('connection', (ws) => {
{/* Middle Actions */}
<div className="flex md:flex-col items-center justify-center gap-2 p-1">
<button
onClick={handleUpload}
disabled={selectedLocalIds.size === 0 || !connection.connected}
className="p-3 bg-white border border-slate-300 shadow-sm rounded hover:bg-blue-50 hover:text-blue-600 hover:border-blue-300 transition-colors disabled:opacity-30 disabled:cursor-not-allowed text-slate-400 group relative"
>
<div className="absolute left-1/2 -top-8 -translate-x-1/2 bg-slate-800 text-white text-xs px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none whitespace-nowrap z-50 shadow-lg"></div>
<button className="p-3 bg-white border border-slate-300 shadow-sm rounded hover:bg-blue-50 text-slate-400">
<ArrowRight size={24} strokeWidth={2.5} />
</button>
<button
onClick={handleDownload}
disabled={selectedRemoteIds.size === 0 || !connection.connected}
className="p-3 bg-white border border-slate-300 shadow-sm rounded hover:bg-green-50 hover:text-green-600 hover:border-green-300 transition-colors disabled:opacity-30 disabled:cursor-not-allowed text-slate-400 group relative"
>
<div className="absolute left-1/2 -top-8 -translate-x-1/2 bg-slate-800 text-white text-xs px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none whitespace-nowrap z-50 shadow-lg"></div>
<button className="p-3 bg-white border border-slate-300 shadow-sm rounded hover:bg-green-50 text-slate-400">
<ArrowLeft size={24} strokeWidth={2.5} />
</button>
</div>
@@ -848,14 +763,14 @@ wss.on('connection', (ws) => {
</div>
</div>
{/* 4. Queue / Status */}
{/* Queue */}
<div className="h-48 shrink-0 p-2 pt-0">
<TransferQueue queue={queue} />
</div>
{/* Footer */}
<footer className="bg-white border-t border-slate-200 px-3 py-1 text-[10px] text-slate-500 flex justify-between shadow-[0_-2px_10px_rgba(0,0,0,0.02)]">
<span>WebZilla v1.1.0 - React/TypeScript Demo</span>
<span>WebZilla v1.3.0 <span className="mx-2 text-slate-300">|</span> © SIMP</span>
<div className="flex gap-4">
<span>Server: {connection.connected ? 'Connected' : 'Disconnected'}</span>
<span>Protocol: {connection.protocol.toUpperCase()} {connection.passive ? '(Passive)' : ''}</span>

View File

@@ -1,9 +1,12 @@
/**
* WebZilla 백엔드 프록시 서버 (Node.js) v1.1
* WebZilla 백엔드 프록시 서버 (Node.js) v1.2
*
* 기능 추가:
* - 로컬 파일 시스템 접근 (fs)
* - 설정 데이터 저장 (AppData/Roaming 또는 ~/.config)
* 기능:
* - WebSocket Proxy (Port: 8090)
* - FTP/SFTP 지원
* - 로컬 파일 시스템 탐색 (LOCAL_LIST)
* - 설정 저장 (AppData)
* - **NEW**: 포트 충돌 자동 감지 및 프로세스 종료 기능
*/
const WebSocket = require('ws');
@@ -11,45 +14,48 @@ const ftp = require('basic-ftp');
const fs = require('fs');
const path = require('path');
const os = require('os');
const { exec } = require('child_process');
const readline = require('readline');
// --- 로컬 저장소 경로 설정 (AppData 구현) ---
function getConfigDir() {
const homedir = os.homedir();
// Windows: C:\Users\User\AppData\Roaming\WebZilla
if (process.platform === 'win32') {
return path.join(process.env.APPDATA || path.join(homedir, 'AppData', 'Roaming'), 'WebZilla');
}
// macOS: ~/Library/Application Support/WebZilla
else if (process.platform === 'darwin') {
} else if (process.platform === 'darwin') {
return path.join(homedir, 'Library', 'Application Support', 'WebZilla');
}
// Linux: ~/.config/webzilla
else {
} else {
return path.join(homedir, '.config', 'webzilla');
}
}
// 앱 시작 시 설정 디렉토리 생성
const configDir = getConfigDir();
if (!fs.existsSync(configDir)) {
try {
fs.mkdirSync(configDir, { recursive: true });
console.log(`📂 설정 폴더가 생성되었습니다: ${configDir}`);
} catch (e) {
console.error(`❌ 설정 폴더 생성 실패: ${e.message}`);
}
} else {
console.log(`📂 설정 폴더 로드됨: ${configDir}`);
try { fs.mkdirSync(configDir, { recursive: true }); } catch (e) { }
}
const wss = new WebSocket.Server({ port: 8090 });
const PORT = 8090;
console.log("🚀 WebZilla FTP Proxy Server가 ws://localhost:8090 에서 실행 중입니다.");
// --- 서버 시작 함수 (재시도 로직 포함) ---
function startServer() {
const wss = new WebSocket.Server({ port: PORT });
wss.on('connection', (ws) => {
console.log("클라이언트가 접속했습니다.");
wss.on('error', (err) => {
if (err.code === 'EADDRINUSE') {
console.error(`\n❌ 포트 ${PORT}이(가) 이미 사용 중입니다.`);
handlePortConflict();
} else {
console.error("❌ 서버 오류:", err);
process.exit(1);
}
});
wss.on('listening', () => {
console.log(`\n🚀 WebZilla FTP Proxy Server가 ws://localhost:${PORT} 에서 실행 중입니다.`);
console.log(`📂 설정 폴더: ${configDir}`);
});
wss.on('connection', (ws) => {
const client = new ftp.Client();
ws.on('message', async (message) => {
@@ -57,7 +63,6 @@ wss.on('connection', (ws) => {
const data = JSON.parse(message);
switch (data.command) {
// --- FTP 연결 관련 ---
case 'CONNECT':
console.log(`FTP 연결 시도: ${data.user}@${data.host}:${data.port}`);
try {
@@ -80,9 +85,9 @@ wss.on('connection', (ws) => {
ws.send(JSON.stringify({ type: 'error', message: 'FTP 연결이 끊어져 있습니다.' }));
return;
}
try {
const listPath = data.path || '/';
const list = await client.list(listPath);
const files = list.map(f => ({
id: `ftp-${Date.now()}-${Math.random()}`,
name: f.name,
@@ -91,8 +96,41 @@ wss.on('connection', (ws) => {
date: f.rawModifiedAt || new Date().toISOString(),
permissions: '-'
}));
ws.send(JSON.stringify({ type: 'list', files, path: listPath }));
} catch (err) {
ws.send(JSON.stringify({ type: 'error', message: err.message }));
}
break;
case 'MKD':
if (client.closed) return;
try {
await client.ensureDir(data.path);
ws.send(JSON.stringify({ type: 'success', message: '폴더 생성 완료' }));
} catch (err) {
ws.send(JSON.stringify({ type: 'error', message: err.message }));
}
break;
case 'DELE':
if (client.closed) return;
try {
if (data.isFolder) await client.removeDir(data.path);
else await client.remove(data.path);
ws.send(JSON.stringify({ type: 'success', message: '삭제 완료' }));
} catch (err) {
ws.send(JSON.stringify({ type: 'error', message: err.message }));
}
break;
case 'RENAME':
if (client.closed) return;
try {
await client.rename(data.from, data.to);
ws.send(JSON.stringify({ type: 'success', message: '이름 변경 완료' }));
} catch (err) {
ws.send(JSON.stringify({ type: 'error', message: err.message }));
}
break;
case 'DISCONNECT':
@@ -100,20 +138,25 @@ wss.on('connection', (ws) => {
ws.send(JSON.stringify({ type: 'status', status: 'disconnected', message: '연결이 종료되었습니다.' }));
break;
// --- 로컬 설정 저장 관련 (새로 추가됨) ---
case 'SAVE_SITE':
// 예: 사이트 정보를 JSON 파일로 저장
// Deprecated in favor of SAVE_SITES for full sync, but kept for compatibility
try {
const sitesFile = path.join(configDir, 'sites.json');
let sites = [];
if (fs.existsSync(sitesFile)) {
sites = JSON.parse(fs.readFileSync(sitesFile, 'utf8'));
}
if (fs.existsSync(sitesFile)) sites = JSON.parse(fs.readFileSync(sitesFile, 'utf8'));
sites.push(data.siteInfo);
fs.writeFileSync(sitesFile, JSON.stringify(sites, null, 2));
ws.send(JSON.stringify({ type: 'success', message: '사이트가 추가되었습니다.' }));
} catch (err) {
ws.send(JSON.stringify({ type: 'error', message: `저장 실패: ${err.message}` }));
}
break;
console.log(`💾 사이트 정보 저장됨: ${data.siteInfo.host}`);
ws.send(JSON.stringify({ type: 'success', message: '사이트 정보가 로컬(AppData)에 저장되었습니다.' }));
case 'SAVE_SITES':
try {
const sitesFile = path.join(configDir, 'sites.json');
fs.writeFileSync(sitesFile, JSON.stringify(data.sites, null, 2));
ws.send(JSON.stringify({ type: 'success', message: '사이트 목록이 저장되었습니다.' }));
} catch (err) {
ws.send(JSON.stringify({ type: 'error', message: `저장 실패: ${err.message}` }));
}
@@ -133,8 +176,66 @@ wss.on('connection', (ws) => {
}
break;
default:
console.log(`알 수 없는 명령: ${data.command}`);
case 'LOCAL_LIST':
try {
const targetPath = data.path || os.homedir();
const entries = fs.readdirSync(targetPath, { withFileTypes: true });
const files = entries.map(dirent => {
let size = 0;
let date = new Date().toISOString();
try {
const stats = fs.statSync(path.join(targetPath, dirent.name));
size = stats.size;
date = stats.mtime.toISOString();
} catch (e) { }
return {
id: `local-${Math.random()}`,
name: dirent.name,
type: dirent.isDirectory() ? 'FOLDER' : 'FILE',
size: size,
date: date,
permissions: '-'
};
});
ws.send(JSON.stringify({ type: 'local_list', files, path: targetPath }));
} catch (err) {
ws.send(JSON.stringify({ type: 'error', message: `로컬 목록 실패: ${err.message}` }));
}
break;
case 'LOCAL_MKD':
try {
if (!fs.existsSync(data.path)) {
fs.mkdirSync(data.path, { recursive: true });
ws.send(JSON.stringify({ type: 'success', message: '로컬 폴더 생성 완료' }));
} else {
ws.send(JSON.stringify({ type: 'error', message: '이미 존재하는 폴더입니다.' }));
}
} catch (err) {
ws.send(JSON.stringify({ type: 'error', message: `로컬 폴더 생성 실패: ${err.message}` }));
}
break;
case 'LOCAL_RENAME':
try {
fs.renameSync(data.from, data.to);
ws.send(JSON.stringify({ type: 'success', message: '이름 변경 완료' }));
} catch (err) {
ws.send(JSON.stringify({ type: 'error', message: `이름 변경 실패: ${err.message}` }));
}
break;
case 'LOCAL_DELE':
try {
fs.rmSync(data.path, { recursive: true, force: true });
ws.send(JSON.stringify({ type: 'success', message: '삭제 완료' }));
} catch (err) {
ws.send(JSON.stringify({ type: 'error', message: `삭제 실패: ${err.message}` }));
}
break;
}
} catch (err) {
console.error("오류 발생:", err);
@@ -143,7 +244,66 @@ wss.on('connection', (ws) => {
});
ws.on('close', () => {
console.log("클라이언트 접속 종료");
client.close();
});
});
});
}
// --- 포트 충돌 처리 ---
function handlePortConflict() {
// Windows: netstat -ano | findstr :8090
// Mac/Linux: lsof -i :8090
if (process.platform === 'win32') {
exec(`netstat -ano | findstr :${PORT}`, (err, stdout, stderr) => {
if (err || !stdout) {
console.log("실행 중인 프로세스를 찾지 못했습니다. 수동으로 확인해주세요.");
process.exit(1);
return;
}
// Parse PID (Last token in line)
const lines = stdout.trim().split('\n');
const line = lines[0].trim();
const parts = line.split(/\s+/);
const pid = parts[parts.length - 1];
askToKill(pid);
});
} else {
// Simple fallback/notification for non-Windows (or implement lsof)
console.log(`Port ${PORT} is in use. Please kill the process manually.`);
process.exit(1);
}
}
function askToKill(pid) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.log(`⚠️ PID [${pid}] 프로세스가 포트 ${PORT}를 사용 중입니다.`);
rl.question(`❓ 해당 프로세스를 종료하고 서버를 시작하시겠습니까? (Y/n): `, (answer) => {
const ans = answer.trim().toLowerCase();
if (ans === '' || ans === 'y' || ans === 'yes') {
console.log(`🔫 PID ${pid} 종료 시도 중...`);
exec(`taskkill /F /PID ${pid}`, (killErr) => {
if (killErr) {
console.error(`❌ 종료 실패: ${killErr.message}`);
process.exit(1);
} else {
console.log("✅ 프로세스가 종료되었습니다. 서버를 다시 시작합니다...");
rl.close();
setTimeout(startServer, 1000); // 1초 후 재시작
}
});
} else {
console.log("🚫 작업을 취소했습니다.");
process.exit(0);
}
});
}
// 초기 실행
startServer();

View File

@@ -9,15 +9,31 @@ interface CreateFolderModalProps {
}
export const CreateFolderModal: React.FC<CreateFolderModalProps> = ({ isOpen, onClose, onConfirm }) => {
const [folderName, setFolderName] = useState('새 폴더');
const [folderName, setFolderName] = useState('');
const [error, setError] = useState('');
useEffect(() => {
if (isOpen) {
setFolderName('새 폴더');
setFolderName('');
setError('');
// Auto focus hack
setTimeout(() => document.getElementById('new-folder-input')?.focus(), 50);
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose();
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}
}, [isOpen]);
}, [isOpen, onClose]);
const handleConfirm = () => {
if (!folderName.trim()) {
setError('폴더 이름을 입력해주세요.');
return;
}
onConfirm(folderName);
};
if (!isOpen) return null;
@@ -37,14 +53,15 @@ export const CreateFolderModal: React.FC<CreateFolderModalProps> = ({ isOpen, on
id="new-folder-input"
type="text"
value={folderName}
onChange={(e) => setFolderName(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && onConfirm(folderName)}
className="w-full bg-white border border-slate-300 rounded px-3 py-2 text-sm text-slate-800 focus:border-blue-500 focus:outline-none"
onChange={(e) => { setFolderName(e.target.value); setError(''); }}
onKeyDown={(e) => e.key === 'Enter' && handleConfirm()}
className={`w-full bg-white border rounded px-3 py-2 text-sm text-slate-800 focus:outline-none ${error ? 'border-red-500 focus:border-red-500' : 'border-slate-300 focus:border-blue-500'}`}
/>
{error && <p className="text-xs text-red-500 mt-1">{error}</p>}
</div>
<div className="flex justify-end gap-2">
<button onClick={onClose} className="px-3 py-1.5 text-xs text-slate-600 hover:text-slate-900 bg-slate-100 hover:bg-slate-200 rounded"></button>
<button onClick={() => onConfirm(folderName)} className="px-3 py-1.5 text-xs bg-blue-600 hover:bg-blue-500 text-white rounded shadow-md shadow-blue-500/20"></button>
<button onClick={handleConfirm} className="px-3 py-1.5 text-xs bg-blue-600 hover:bg-blue-500 text-white rounded shadow-md shadow-blue-500/20"></button>
</div>
</div>
</div>
@@ -62,13 +79,33 @@ interface RenameModalProps {
export const RenameModal: React.FC<RenameModalProps> = ({ isOpen, currentName, onClose, onConfirm }) => {
const [newName, setNewName] = useState('');
const [error, setError] = useState('');
useEffect(() => {
if (isOpen) {
setNewName(currentName);
setError('');
setTimeout(() => document.getElementById('rename-input')?.focus(), 50);
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose();
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}
}, [isOpen, currentName]);
}, [isOpen, currentName, onClose]);
const handleConfirm = () => {
if (!newName.trim()) {
setError('새 이름을 입력해주세요.');
return;
}
if (newName.trim() === currentName) {
setError('변경된 내용이 없습니다.');
return;
}
onConfirm(newName);
};
if (!isOpen) return null;
@@ -91,14 +128,15 @@ export const RenameModal: React.FC<RenameModalProps> = ({ isOpen, currentName, o
id="rename-input"
type="text"
value={newName}
onChange={(e) => setNewName(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && onConfirm(newName)}
className="w-full bg-white border border-slate-300 rounded px-3 py-2 text-sm text-slate-800 focus:border-blue-500 focus:outline-none"
onChange={(e) => { setNewName(e.target.value); setError(''); }}
onKeyDown={(e) => e.key === 'Enter' && handleConfirm()}
className={`w-full bg-white border rounded px-3 py-2 text-sm text-slate-800 focus:outline-none ${error ? 'border-red-500 focus:border-red-500' : 'border-slate-300 focus:border-blue-500'}`}
/>
{error && <p className="text-xs text-red-500 mt-1">{error}</p>}
</div>
<div className="flex justify-end gap-2">
<button onClick={onClose} className="px-3 py-1.5 text-xs text-slate-600 hover:text-slate-900 bg-slate-100 hover:bg-slate-200 rounded"></button>
<button onClick={() => onConfirm(newName)} className="px-3 py-1.5 text-xs bg-blue-600 hover:bg-blue-500 text-white rounded shadow-md shadow-blue-500/20"></button>
<button onClick={handleConfirm} className="px-3 py-1.5 text-xs bg-blue-600 hover:bg-blue-500 text-white rounded shadow-md shadow-blue-500/20"></button>
</div>
</div>
</div>
@@ -116,6 +154,16 @@ interface DeleteModalProps {
}
export const DeleteModal: React.FC<DeleteModalProps> = ({ isOpen, fileCount, fileNames, onClose, onConfirm }) => {
useEffect(() => {
if (isOpen) {
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') onClose();
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}
}, [isOpen, onClose]);
if (!isOpen) return null;
return (

228
components/HelpModal.tsx Normal file
View File

@@ -0,0 +1,228 @@
import React, { useState, useEffect } from 'react';
import { X, HelpCircle, Server, Folder, FileText, Settings, Wifi, Terminal } from 'lucide-react';
interface HelpModalProps {
isOpen: boolean;
onClose: () => void;
initialTab?: 'sites' | 'connection' | 'files' | 'backend';
}
const HelpModal: React.FC<HelpModalProps> = ({ isOpen, onClose, initialTab }) => {
const [activeTab, setActiveTab] = useState<'sites' | 'connection' | 'files' | 'backend'>('sites');
useEffect(() => {
if (isOpen && initialTab) {
setActiveTab(initialTab);
}
}, [isOpen, initialTab]);
// ESC key handler
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if (isOpen && (e.key === 'Escape' || e.key === 'Esc')) {
onClose();
}
};
if (isOpen) {
window.addEventListener('keydown', handleKeyDown);
}
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, [isOpen, onClose]);
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/20 backdrop-blur-sm p-4">
<div className="bg-white border border-slate-200 rounded-lg shadow-2xl w-full max-w-2xl flex flex-col h-[600px] max-h-[90vh]">
{/* Header */}
<div className="flex items-center justify-between p-4 border-b border-slate-200 bg-slate-50 rounded-t-lg">
<h2 className="text-base font-bold text-slate-800 flex items-center gap-2">
<HelpCircle size={20} className="text-blue-600" />
</h2>
<button onClick={onClose} className="text-slate-400 hover:text-slate-600 transition-colors">
<X size={20} />
</button>
</div>
<div className="flex flex-1 min-h-0">
{/* Sidebar */}
<div className="w-48 border-r border-slate-200 bg-slate-50 p-2 flex flex-col gap-1">
<button
onClick={() => setActiveTab('sites')}
className={`flex items-center gap-2 px-3 py-2 text-sm rounded transition-colors ${activeTab === 'sites' ? 'bg-white text-blue-600 shadow-sm font-medium' : 'text-slate-600 hover:bg-slate-200'
}`}
>
<Server size={16} />
</button>
<button
onClick={() => setActiveTab('connection')}
className={`flex items-center gap-2 px-3 py-2 text-sm rounded transition-colors ${activeTab === 'connection' ? 'bg-white text-blue-600 shadow-sm font-medium' : 'text-slate-600 hover:bg-slate-200'
}`}
>
<Wifi size={16} />
</button>
<button
onClick={() => setActiveTab('backend')}
className={`flex items-center gap-2 px-3 py-2 text-sm rounded transition-colors ${activeTab === 'backend' ? 'bg-white text-blue-600 shadow-sm font-medium' : 'text-slate-600 hover:bg-slate-200'
}`}
>
<Terminal size={16} /> /
</button>
<button
onClick={() => setActiveTab('files')}
className={`flex items-center gap-2 px-3 py-2 text-sm rounded transition-colors ${activeTab === 'files' ? 'bg-white text-blue-600 shadow-sm font-medium' : 'text-slate-600 hover:bg-slate-200'
}`}
>
<Folder size={16} />
</button>
</div>
{/* Content */}
<div className="flex-1 overflow-y-auto p-6 bg-white">
{activeTab === 'sites' && (
<div className="space-y-6">
<div>
<h3 className="text-lg font-bold text-slate-800 mb-2 flex items-center gap-2">
<Server size={20} className="text-slate-400" />
</h3>
<p className="text-slate-600 text-sm leading-relaxed mb-4">
FTP .
</p>
<ul className="list-disc list-inside text-sm text-slate-600 space-y-2 bg-slate-50 p-4 rounded border border-slate-100">
<li><strong> :</strong> .</li>
<li><strong> :</strong> . (: /public_html)</li>
<li><strong> :</strong> '연결' . ( )</li>
</ul>
</div>
</div>
)}
{activeTab === 'connection' && (
<div className="space-y-6">
<div>
<h3 className="text-lg font-bold text-slate-800 mb-2 flex items-center gap-2">
<Wifi size={20} className="text-slate-400" />
</h3>
<p className="text-slate-600 text-sm leading-relaxed mb-4">
.
</p>
<ul className="list-disc list-inside text-sm text-slate-600 space-y-2 bg-slate-50 p-4 rounded border border-slate-100">
<li><strong> :</strong> , , .</li>
<li><strong> :</strong> (/) .</li>
<li><strong> :</strong> .</li>
</ul>
</div>
</div>
)}
{activeTab === 'backend' && (
<div className="space-y-6">
<div>
<h3 className="text-lg font-bold text-slate-800 mb-2 flex items-center gap-2">
<Terminal size={20} className="text-slate-400" />
</h3>
<p className="text-slate-600 text-sm leading-relaxed mb-4">
WebZilla는 .
</p>
<div className="space-y-4">
<div className="bg-amber-50 p-4 rounded border border-amber-100">
<h4 className="font-bold text-amber-800 text-sm mb-2 flex items-center gap-2">
<Settings size={16} /> 1.
</h4>
<p className="text-xs text-amber-700 leading-relaxed">
<span className="font-bold bg-emerald-600 text-white px-1.5 py-0.5 rounded text-[10px]"></span>
<code className="mx-1 bg-amber-100 px-1 rounded text-amber-900">backend_proxy.cjs</code> .
</p>
</div>
<div className="bg-slate-50 p-4 rounded border border-slate-200">
<h4 className="font-bold text-slate-800 text-sm mb-2 text- mb-2">2. </h4>
<div className="space-y-3">
<div>
<span className="text-xs font-bold text-slate-600 block mb-1"> A: Node.js가 ()</span>
<div className="bg-slate-800 text-slate-200 p-2 rounded text-xs font-mono">
node backend_proxy.cjs
</div>
</div>
<div>
<span className="text-xs font-bold text-slate-600 block mb-1"> B: 실행 (.exe) </span>
<p className="text-xs text-slate-500"> exe .</p>
</div>
</div>
</div>
<div className="flex items-start gap-2 text-xs text-blue-600 bg-blue-50 p-3 rounded">
<div className="shrink-0 mt-0.5"><Wifi size={14} /></div>
<p> <strong>8090</strong> , 'Server' <span className="font-bold text-green-600">Connected</span> .</p>
</div>
</div>
</div>
</div>
)}
{activeTab === 'files' && (
<div className="space-y-6">
<div>
<h3 className="text-lg font-bold text-slate-800 mb-2 flex items-center gap-2">
<Folder size={20} className="text-slate-400" />
</h3>
<p className="text-slate-600 text-sm leading-relaxed mb-4">
( ) () .
</p>
<div className="space-y-4">
<div className="bg-blue-50 p-3 rounded border border-blue-100">
<h4 className="font-bold text-blue-800 text-sm mb-1"> </h4>
<p className="text-xs text-blue-600">
/ . ( )
</p>
</div>
<div className="grid grid-cols-2 gap-3">
<div className="border border-slate-200 p-3 rounded">
<h4 className="font-bold text-slate-700 text-sm mb-1"> ( )</h4>
<ul className="text-xs text-slate-500 space-y-1">
<li> </li>
<li> </li>
<li> / </li>
</ul>
</div>
<div className="border border-slate-200 p-3 rounded">
<h4 className="font-bold text-slate-700 text-sm mb-1"> ()</h4>
<ul className="text-xs text-slate-500 space-y-1">
<li> (MKD)</li>
<li> (RENAME)</li>
<li> / (DELE)</li>
</ul>
</div>
</div>
</div>
</div>
</div>
)}
</div>
</div>
{/* Footer */}
<div className="p-4 border-t border-slate-200 bg-slate-50 flex justify-end rounded-b-lg">
<button
onClick={onClose}
className="px-4 py-2 bg-slate-800 hover:bg-slate-700 text-white text-sm rounded shadow-sm transition-colors"
>
</button>
</div>
</div>
</div>
);
};
export default HelpModal;

View File

@@ -151,8 +151,7 @@ const SiteManagerModal: React.FC<SiteManagerModalProps> = ({
<div
key={site.id}
onClick={() => selectSite(site)}
className={`flex items-center gap-2 px-3 py-2 rounded cursor-pointer text-sm select-none transition-colors ${
selectedId === site.id
className={`flex items-center gap-2 px-3 py-2 rounded cursor-pointer text-sm select-none transition-colors ${selectedId === site.id
? 'bg-blue-100 text-blue-900 border border-blue-200'
: 'text-slate-600 hover:bg-slate-200'
}`}
@@ -177,16 +176,14 @@ const SiteManagerModal: React.FC<SiteManagerModalProps> = ({
<div className="flex border-b border-slate-200 px-4">
<button
onClick={() => setActiveTab('general')}
className={`px-4 py-2 text-xs font-medium border-b-2 transition-colors ${
activeTab === 'general' ? 'border-blue-500 text-blue-600' : 'border-transparent text-slate-500'
className={`px-4 py-2 text-xs font-medium border-b-2 transition-colors ${activeTab === 'general' ? 'border-blue-500 text-blue-600' : 'border-transparent text-slate-500'
}`}
>
(General)
</button>
<button
onClick={() => setActiveTab('transfer')}
className={`px-4 py-2 text-xs font-medium border-b-2 transition-colors ${
activeTab === 'transfer' ? 'border-blue-500 text-blue-600' : 'border-transparent text-slate-500'
className={`px-4 py-2 text-xs font-medium border-b-2 transition-colors ${activeTab === 'transfer' ? 'border-blue-500 text-blue-600' : 'border-transparent text-slate-500'
}`}
>
(Transfer)
@@ -262,6 +259,17 @@ const SiteManagerModal: React.FC<SiteManagerModalProps> = ({
className="col-span-3 bg-white border border-slate-300 rounded px-2 py-1.5 text-sm focus:border-blue-500 focus:outline-none text-slate-800 placeholder:text-slate-400"
/>
</div>
<div className="grid grid-cols-4 gap-4 items-center">
<label className="text-xs text-slate-500 text-right"> </label>
<input
type="text"
value={formData.initialPath || ''}
onChange={(e) => updateForm('initialPath', e.target.value)}
placeholder="/ (기본값)"
className="col-span-3 bg-white border border-slate-300 rounded px-2 py-1.5 text-sm focus:border-blue-500 focus:outline-none text-slate-800 placeholder:text-slate-400"
/>
</div>
</div>
) : (
<div className="space-y-6">
@@ -322,8 +330,7 @@ const SiteManagerModal: React.FC<SiteManagerModalProps> = ({
<button
onClick={handleSave}
disabled={!formData}
className={`px-4 py-2 text-sm rounded flex items-center gap-2 transition-colors shadow-sm ${
isDirty
className={`px-4 py-2 text-sm rounded flex items-center gap-2 transition-colors shadow-sm ${isDirty
? 'bg-emerald-600 hover:bg-emerald-500 text-white shadow-emerald-500/20'
: 'bg-white border border-slate-300 text-slate-500'
}`}

View File

@@ -44,4 +44,5 @@ export interface SiteConfig {
user: string;
pass?: string; // Optional for security
passiveMode?: boolean;
initialPath?: string;
}

Binary file not shown.