Repository navigation
Expand file tree
/
Copy pathuwp
More file actions
executable file
·570 lines (478 loc) · 14.9 KB
/
Copy pathuwp
File metadata and controls
executable file
·570 lines (478 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
#!/bin/bash
#
# UnrealIRCd Web Panel - Build & Management Script
# Usage: ./uwp <command>
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKEND_DIR="$SCRIPT_DIR/backend"
FRONTEND_DIR="$SCRIPT_DIR/frontend"
BINARY_NAME="webpanel"
PID_FILE="$BACKEND_DIR/data/webpanel.pid"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# ASCII art logo encoded as decimal values
UNREALLOGO_CHARS=(
32 95 32 32 32 95 32 32 32 32 32
32 32 32 32 32 32 32 32 32 32 32
32 32 32 32 32 32 95 95 95 95 95
95 95 95 95 95 95 95 32 32 95 95
95 95 95 32 32 32 32 32 95 32
10 124 32 124 32 124 32 124 32 32 32
32 32 32 32 32 32 32 32 32 32 32
32 32 32 32 32 32 124 32 124 95 32
32 32 95 124 32 95 95 95 32 92 47
32 32 95 95 32 92 32 32 32 124 32
124 10 124 32 124 32 124 32 124 95 32
95 95 32 32 95 32 95 95 32 95 95
95 32 32 95 95 32 95 124 32 124 32
124 32 124 32 124 32 124 95 47 32 47
124 32 47 32 32 92 47 32 95 95 124
32 124 10 124 32 124 32 124 32 124 32
39 95 32 92 124 32 39 95 95 47 32
95 32 92 47 32 95 96 32 124 32 124
32 124 32 124 32 124 32 32 32 32 47
32 124 32 124 32 32 32 32 47 32 95
96 32 124 10 124 32 124 95 124 32 124
32 124 32 124 32 124 32 124 32 124 32
32 95 95 47 32 40 95 124 32 124 32
124 95 124 32 124 95 124 32 124 92 32
92 32 124 32 92 95 95 47 92 32 40
95 124 32 124 10 32 92 95 95 95 47
124 95 124 32 124 95 124 95 124 32 32
92 95 95 95 124 92 95 95 44 95 124
95 124 92 95 95 95 47 92 95 124 32
92 95 124 32 92 95 95 95 95 47 92
95 95 44 95 124 10
)
print_logo() {
local output=""
for code in "${UNREALLOGO_CHARS[@]}"; do
if [ "$code" -eq 0 ]; then
break
fi
if [ "$code" -eq 10 ]; then
echo "$output"
output=""
else
output+=$(printf "\\$(printf '%03o' "$code")")
fi
done
# Print any remaining output
if [ -n "$output" ]; then
echo "$output"
fi
}
print_icon() {
echo -e "${BLUE} ▒▒▒▒▒▒▒▒▒▒▒▒ "
echo " ▒▒▒▓▓▓▓▓▓▓▓▓▓▒▒░ "
echo " ▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒ "
echo "▒▒▓▓▓▓▒░▒▓▓▓▒▒▒▓▓▓▒░ UnrealIRCd"
echo "▒▓▓▓▓▓▒░▒▓▓▓░░▒▓▓▓▓▒ \"Serving thousands of"
echo "▒▓▓▓▓▒░░▒▓▓▒░░▓▓▓▓▓▒ networks since 1999\""
echo "▒▓▓▓▓▒░░▓▓▓▒░▒▓▓▓▓▓▒"
echo "▒▒▓▓▓▒░░░░░░▒▓▓▓▓▓▒▒"
echo " ▒▒▓▓▓▒▒▒▒▒▒▓▓▓▓▓▒▒ "
echo " ▒▒▒▓▓▓▓▓▓▓▓▓▓▒▒░ "
echo " ▒▒▒▒▒▒▒▒▒▒▒░ "
echo -e "${NC}"
}
print_header() {
echo -e "${BLUE}"
print_icon
echo "Web Panel v2.0"
echo "Brought to you by Valware"
echo -e "${NC}"
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
print_info() {
echo -e "${YELLOW}→ $1${NC}"
}
check_dependencies() {
local missing=0
if ! command -v go &> /dev/null; then
print_error "Go is not installed"
missing=1
fi
if ! command -v node &> /dev/null; then
print_error "Node.js is not installed"
missing=1
fi
if ! command -v npm &> /dev/null; then
print_error "npm is not installed"
missing=1
fi
if ! command -v jq &> /dev/null; then
print_error "jq is not installed"
missing=1
fi
if [ $missing -eq 1 ]; then
echo ""
print_error "Please install missing dependencies and try again"
exit 1
fi
print_success "All dependencies found"
}
build_frontend() {
print_info "Building frontend..."
cd "$FRONTEND_DIR"
# Install dependencies if node_modules doesn't exist or package.json changed
if [ ! -d "node_modules" ] || [ "package.json" -nt "node_modules" ]; then
print_info "Installing frontend dependencies..."
npm install
fi
# Build frontend
npm run build
# Copy built files to backend
print_info "Copying frontend build to backend..."
rm -rf "$BACKEND_DIR/frontend"
cp -r "$FRONTEND_DIR/dist" "$BACKEND_DIR/frontend"
print_success "Frontend built successfully"
}
build_backend() {
print_info "Building backend..."
cd "$BACKEND_DIR"
# Download dependencies if needed
if [ ! -d "vendor" ] && [ -f "go.mod" ]; then
print_info "Downloading Go dependencies..."
go mod download
fi
# Build binary
go build -o "$BINARY_NAME" ./cmd/server/
print_success "Backend built successfully"
}
build_all() {
print_header
check_dependencies
echo ""
build_frontend
echo ""
build_backend
echo ""
print_success "Build complete! Run './uwp start' to start the server"
}
start_server() {
cd "$BACKEND_DIR"
# Kill any orphaned webpanel processes
pkill -f "./webpanel" 2>/dev/null || true
sleep 1
if [ -f "$PID_FILE" ]; then
local pid=$(cat "$PID_FILE")
if ps -p "$pid" > /dev/null 2>&1; then
print_error "Server is already running (PID: $pid)"
echo "Use './uwp stop' to stop it first, or './uwp restart' to restart"
exit 1
else
rm -f "$PID_FILE"
fi
fi
if [ ! -f "$BINARY_NAME" ]; then
print_error "Binary not found. Please run './uwp build' first"
exit 1
fi
print_info "Starting UnrealIRCd Web Panel..."
# Create data directory if it doesn't exist
mkdir -p "$BACKEND_DIR/data"
# Start server in foreground first to show startup messages
print_info "Initializing server (showing startup logs)..."
"./$BINARY_NAME" 2>&1 &
local fg_pid=$!
# Wait for startup messages (let it run for a few seconds)
sleep 3
# Check if server is still running and appears to have started successfully
if ps -p "$fg_pid" > /dev/null 2>&1; then
# Server is running, now background it with logging
print_info "Server initialized, switching to background mode..."
# Start server in background with logging
nohup "./$BINARY_NAME" >> "$BACKEND_DIR/data/webpanel.log" 2>&1 &
local bg_pid=$!
echo $bg_pid > "$PID_FILE"
# Kill the foreground instance
kill $fg_pid 2>/dev/null || true
sleep 1
if ps -p "$bg_pid" > /dev/null 2>&1; then
print_success "Server running in background (PID: $bg_pid)"
echo ""
echo "Web panel is now available at: http://localhost:8080"
echo "Full logs: $BACKEND_DIR/data/webpanel.log"
else
print_error "Failed to background server"
rm -f "$PID_FILE"
exit 1
fi
else
# Server exited during startup
wait $fg_pid 2>/dev/null
local exit_code=$?
if [ $exit_code -eq 0 ]; then
print_success "Server started and completed initialization"
echo "Web panel is now available at: http://localhost:8080"
echo "Check logs: $BACKEND_DIR/data/webpanel.log"
else
print_error "Server failed to start (exit code: $exit_code)"
echo "Check logs: $BACKEND_DIR/data/webpanel.log"
exit 1
fi
fi
}
stop_server() {
if [ ! -f "$PID_FILE" ]; then
print_info "Server is not running (no PID file found)"
return 0
fi
local pid=$(cat "$PID_FILE")
if ! ps -p "$pid" > /dev/null 2>&1; then
print_info "Server is not running (stale PID file)"
rm -f "$PID_FILE"
return 0
fi
print_info "Stopping server (PID: $pid)..."
kill "$pid" 2>/dev/null || true
# Wait for graceful shutdown
local count=0
while ps -p "$pid" > /dev/null 2>&1 && [ $count -lt 10 ]; do
sleep 1
count=$((count + 1))
done
# Force kill if still running
if ps -p "$pid" > /dev/null 2>&1; then
print_info "Force stopping server..."
kill -9 "$pid" 2>/dev/null || true
fi
rm -f "$PID_FILE"
print_success "Server stopped"
}
restart_server() {
stop_server
echo ""
start_server
}
server_status() {
if [ ! -f "$PID_FILE" ]; then
echo "Server is not running"
return 1
fi
local pid=$(cat "$PID_FILE")
if ps -p "$pid" > /dev/null 2>&1; then
echo -e "${GREEN}Server is running${NC} (PID: $pid)"
return 0
else
echo "Server is not running (stale PID file)"
rm -f "$PID_FILE"
return 1
fi
}
show_logs() {
local log_file="$BACKEND_DIR/data/webpanel.log"
if [ ! -f "$log_file" ]; then
print_error "Log file not found"
exit 1
fi
if [ "$1" == "-f" ] || [ "$1" == "--follow" ]; then
tail -f "$log_file"
else
tail -100 "$log_file"
fi
}
run_dev() {
print_header
print_info "Starting development mode..."
echo ""
# Start backend
print_info "Starting backend..."
cd "$BACKEND_DIR"
if [ ! -f "$BINARY_NAME" ]; then
build_backend
fi
"./$BINARY_NAME" &
local backend_pid=$!
sleep 2
# Start frontend dev server
print_info "Starting frontend dev server..."
cd "$FRONTEND_DIR"
npm run dev &
local frontend_pid=$!
echo ""
print_success "Development servers started"
echo "Backend: http://localhost:8080"
echo "Frontend: http://localhost:5173"
echo ""
echo "Press Ctrl+C to stop both servers"
# Trap Ctrl+C to clean up
trap "kill $backend_pid $frontend_pid 2>/dev/null; exit 0" SIGINT SIGTERM
wait
}
clean() {
print_info "Cleaning build artifacts..."
# Clean backend
rm -f "$BACKEND_DIR/$BINARY_NAME"
rm -rf "$BACKEND_DIR/frontend"
# Clean frontend
rm -rf "$FRONTEND_DIR/dist"
rm -rf "$FRONTEND_DIR/node_modules/.vite"
print_success "Clean complete"
}
upgrade_app() {
print_info "Checking for updates..."
# Get latest release from GitHub
local latest_release=$(curl -s https://api.github.com/repos/ValwareIRC/unrealircd-webpanel-2/releases | jq -r '.[0].tag_name' 2>/dev/null)
if [ -z "$latest_release" ] || [ "$latest_release" == "null" ]; then
print_error "Failed to fetch latest release from GitHub"
exit 1
fi
# Get current version
local current_version
if [ -f "VERSION" ]; then
current_version=$(cat VERSION)
else
current_version=$(git describe --tags --abbrev=0 2>/dev/null || echo "unknown")
fi
print_info "Current version: $current_version"
print_info "Latest version: $latest_release"
if [ "$current_version" == "$latest_release" ]; then
print_success "You are already running the latest version"
exit 0
fi
# Prompt for upgrade
echo "A new version is available: $latest_release"
read -p "Do you want to upgrade? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "Upgrade cancelled"
exit 0
fi
# Create backup
print_info "Creating backup..."
local backup_file="backup-$(date +%Y%m%d-%H%M%S).zip"
zip -r "$backup_file" . -x "node_modules/*" "backend/vendor/*" "*.log" "data/*" "temp_upgrade/*" "upgrade.tar.gz" 2>/dev/null
if [ $? -ne 0 ]; then
print_error "Failed to create backup"
exit 1
fi
print_success "Backup created: $backup_file"
# Download the release
print_info "Downloading latest release..."
local download_url="https://github.com/ValwareIRC/unrealircd-webpanel-2/releases/download/$latest_release/unrealircd-webpanel-$latest_release.tar.gz"
curl -L -o "upgrade.tar.gz" "$download_url"
if [ $? -ne 0 ]; then
print_error "Failed to download release"
exit 1
fi
# Extract to temp
print_info "Extracting..."
mkdir -p temp_upgrade
tar -xzf upgrade.tar.gz -C temp_upgrade --strip-components=1 2>/dev/null || tar -xzf upgrade.tar.gz -C temp_upgrade
if [ $? -ne 0 ]; then
print_error "Failed to extract"
rm -rf temp_upgrade upgrade.tar.gz
exit 1
fi
# Stop server if running
if [ -f "$PID_FILE" ]; then
print_info "Stopping server for upgrade..."
stop_server
fi
# Apply upgrade: copy files, but preserve config and data
print_info "Applying upgrade..."
# Copy binaries and scripts
cp temp_upgrade/webpanel backend/ 2>/dev/null || true
cp temp_upgrade/uwp . 2>/dev/null || true
# Copy frontend
rm -rf frontend
cp -r temp_upgrade/frontend . 2>/dev/null || true
# Copy config.example if not exists
if [ ! -f config.json ]; then
cp temp_upgrade/config.example.json config.json 2>/dev/null || true
fi
# Clean up
rm -rf temp_upgrade upgrade.tar.gz
# Update VERSION file
echo "$latest_release" > VERSION
print_success "Upgrade completed to $latest_release"
# Restart server
print_info "Restarting server..."
start_server
}
show_help() {
print_header
echo "Usage: ./uwp <command>"
echo ""
echo "Commands:"
echo " build Build both frontend and backend"
echo " build-fe Build frontend only"
echo " build-be Build backend only"
echo " start Start the web panel server"
echo " stop Stop the web panel server"
echo " restart Restart the web panel server"
echo " status Check if server is running"
echo " logs Show recent logs (add -f to follow)"
echo " dev Start development mode (both frontend & backend)"
echo " clean Remove build artifacts"
echo " upgrade Check for and apply updates"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " ./uwp build # Build everything"
echo " ./uwp start # Start the server"
echo " ./uwp logs -f # Follow logs"
echo " ./uwp restart # Restart the server"
}
# Main command handler
case "${1:-}" in
build)
build_all
;;
build-fe|build-frontend)
print_header
build_frontend
;;
build-be|build-backend)
print_header
build_backend
;;
start)
start_server
;;
stop)
stop_server
;;
restart)
restart_server
;;
status)
server_status
;;
logs)
show_logs "$2"
;;
dev)
run_dev
;;
clean)
clean
;;
upgrade)
upgrade_app
;;
help|--help|-h)
show_help
;;
"")
show_help
;;
*)
print_error "Unknown command: $1"
echo ""
show_help
exit 1
;;
esac