Full dashboard implementation: API, UI, and sharing scripts

This commit is contained in:
2026-03-25 11:35:54 +09:00
parent 28709a3457
commit 47cd2bf5b2
4 changed files with 5457 additions and 80 deletions

View File

@@ -1,77 +1,7 @@
@echo off
setlocal EnableExtensions
set "PROJECT_DIR=/home/hyein/project"
set "API_PORT=4000"
set "LOCAL_URL=http://localhost:4000/PTC/"
set "SHARE_URL="
set "LAN_IP="
set "CURRENT_SOURCE="
net session >nul 2>&1
if not "%errorlevel%"=="0" (
echo 관리자 권한으로 다시 실행해 공유 설정까지 적용합니다...
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
exit /b
)
for /f "usebackq delims=" %%i in (`wsl.exe bash -lc "if [ -f /home/hyein/project/server/ptc_source_path.txt ]; then cat /home/hyein/project/server/ptc_source_path.txt; else echo /home/hyein/project/PTC(2023-2026.02).xlsx; fi"`) do (
set "CURRENT_SOURCE=%%i"
)
echo PTC 서버 시작 중...
echo 원본 파일: %CURRENT_SOURCE%
wsl.exe bash -lc "pkill -f '/home/hyein/project/server/ptc_api_server.py' >/dev/null 2>&1 || true; nohup python3 /home/hyein/project/server/ptc_api_server.py >/tmp/ptc_api.log 2>&1 & sleep 3"
if errorlevel 1 (
echo WSL에서 서버 시작 명령 실행에 실패했습니다.
echo WSL이 실행 가능한지 확인해 주세요.
pause
exit /b 1
)
echo 로컬 서버 상태 확인 중...
wsl.exe bash -lc "curl -fsS http://127.0.0.1:4000/api/health >/tmp/ptc_api_health.json && curl -fsSI http://127.0.0.1:4000/PTC/ >/tmp/ptc_web_health.txt"
if errorlevel 1 (
echo 로컬 서버 확인에 실패했습니다.
echo 아래 로그를 확인해 주세요.
wsl.exe bash -lc "tail -n 80 /tmp/ptc_api.log"
pause
exit /b 1
)
echo 브라우저를 엽니다...
start "" "%LOCAL_URL%"
echo.
echo 로컬 실행 완료
echo 메인 화면: %LOCAL_URL%
echo.
echo 사내망 공유용 Windows IP 확인 중...
for /f "usebackq delims=" %%i in (`powershell -NoProfile -Command "$ip = Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.254.*' -and $_.PrefixOrigin -ne 'WellKnown' } | Select-Object -ExpandProperty IPAddress -First 1; if ($ip) { $ip }"`) do (
set "LAN_IP=%%i"
)
echo WSL IP 확인 중...
for /f "usebackq delims=" %%i in (`wsl.exe bash -lc "hostname -I | awk '{print $1}'"`) do (
set "WSL_IP=%%i"
)
if "%LAN_IP%"=="" goto :share_done
if "%WSL_IP%"=="" goto :share_done
echo 사내망 공유 설정 중...
netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=%API_PORT% >nul 2>&1
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=%API_PORT% connectaddress=%WSL_IP% connectport=%API_PORT% >nul 2>&1
netsh advfirewall firewall delete rule name="PTC 4000" >nul 2>&1
netsh advfirewall firewall add rule name="PTC 4000" dir=in action=allow protocol=TCP localport=%API_PORT% >nul 2>&1
:share_done
if not "%LAN_IP%"=="" (
set "SHARE_URL=http://%LAN_IP%:%API_PORT%/PTC/"
echo 사내망 접속 주소: %SHARE_URL%
echo %SHARE_URL%| clip
echo 공유 주소를 클립보드에 복사했습니다.
)
pause
setlocal
pushd "%~dp0" >nul 2>&1
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0start_ptc_share.ps1"
set "EXIT_CODE=%ERRORLEVEL%"
popd >nul 2>&1
exit /b %EXIT_CODE%

View File

@@ -0,0 +1,91 @@
$ErrorActionPreference = "Stop"
function Test-IsAdmin {
$currentIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentIdentity)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
if (-not (Test-IsAdmin)) {
Start-Process -FilePath "powershell.exe" -Verb RunAs -ArgumentList @(
"-NoProfile",
"-ExecutionPolicy", "Bypass",
"-File", "`"$PSCommandPath`""
)
exit 0
}
$projectDir = "/home/hyein/project"
$apiPort = 4000
$localUrl = "http://localhost:$apiPort/PTC/"
$preferredLanIp = "172.16.40.36"
$defaultSource = "/home/hyein/project/PTC(2023-2026.02).xlsx"
$sourceConfigPath = "/home/hyein/project/server/ptc_source_path.txt"
function Invoke-WslBash([string]$command) {
$output = & wsl.exe bash -lc $command 2>&1
$exitCode = $LASTEXITCODE
return [PSCustomObject]@{
Output = @($output)
ExitCode = $exitCode
}
}
$currentSourceResult = Invoke-WslBash "cat '$sourceConfigPath' 2>/dev/null || printf '%s\n' '$defaultSource'"
$currentSource = ($currentSourceResult.Output | Select-Object -First 1).Trim()
if ([string]::IsNullOrWhiteSpace($currentSource)) {
$currentSource = $defaultSource
}
Write-Host "Starting PTC server..."
Write-Host "Source file: $currentSource"
$startResult = Invoke-WslBash "pkill -f '/home/hyein/project/server/ptc_api_server.py' >/dev/null 2>&1 || true; nohup python3 /home/hyein/project/server/ptc_api_server.py >/tmp/ptc_api.log 2>&1 & sleep 3"
if ($startResult.ExitCode -ne 0) {
Write-Host "Failed to start the server in WSL." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
$healthResult = Invoke-WslBash "curl -fsS http://127.0.0.1:$apiPort/api/health >/tmp/ptc_api_health.json && curl -fsSI http://127.0.0.1:$apiPort/PTC/ >/tmp/ptc_web_health.txt"
if ($healthResult.ExitCode -ne 0) {
Write-Host "Local server check failed. Recent server log:" -ForegroundColor Red
$logResult = Invoke-WslBash "tail -n 80 /tmp/ptc_api.log"
$logResult.Output | ForEach-Object { Write-Host $_ }
Read-Host "Press Enter to exit"
exit 1
}
Start-Process $localUrl
Write-Host ""
Write-Host "Local URL: $localUrl"
$lanIp = Get-NetIPAddress -AddressFamily IPv4 |
Where-Object {
$_.IPAddress -notlike '127.*' -and
$_.IPAddress -notlike '169.254.*' -and
$_.PrefixOrigin -ne 'WellKnown'
} |
Select-Object -ExpandProperty IPAddress -First 1
$wslIpResult = Invoke-WslBash "hostname -I | awk '{print \$1}'"
$wslIp = ($wslIpResult.Output | Select-Object -First 1).Trim()
if (-not [string]::IsNullOrWhiteSpace($lanIp) -and -not [string]::IsNullOrWhiteSpace($wslIp)) {
Write-Host "Configuring LAN sharing..."
& netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=$apiPort | Out-Null
& netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=$apiPort connectaddress=$wslIp connectport=$apiPort | Out-Null
& netsh advfirewall firewall delete rule name="PTC 4000" | Out-Null
& netsh advfirewall firewall add rule name="PTC 4000" dir=in action=allow protocol=TCP localport=$apiPort | Out-Null
$shareIp = if ([string]::IsNullOrWhiteSpace($preferredLanIp)) { $lanIp } else { $preferredLanIp }
$shareUrl = "http://$shareIp:$apiPort/PTC/"
Write-Host "LAN URL: $shareUrl"
Set-Clipboard -Value $shareUrl
Write-Host "The share URL has been copied to the clipboard."
}
else {
Write-Host "LAN sharing was skipped because Windows IP or WSL IP could not be detected."
}
Read-Host "Press Enter to close"