-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·839 lines (719 loc) · 28 KB
/
setup.sh
File metadata and controls
executable file
·839 lines (719 loc) · 28 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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
#!/bin/bash
# CoreSecFrame Setup Script - Local Installation Only
# Supports local installation and database management
set -e # Exit on any error
# Set colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
# Configuration variables
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_NAME="coresecframe"
VENV_PATH="$SCRIPT_DIR/venv"
SYSTEMD_DIR="$SCRIPT_DIR/systemd"
TEMP_FILE=""
# Cleanup function for temporary files
cleanup() {
if [ -n "$TEMP_FILE" ] && [ -f "$TEMP_FILE" ]; then
rm -f "$TEMP_FILE"
fi
}
# Set trap to cleanup on exit
trap cleanup EXIT INT TERM
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_header() {
echo -e "${CYAN}$1${NC}"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
# Function to display banner
show_banner() {
clear
echo -e "${PURPLE}"
cat << "EOF"
____ ____ ______
/ __ \____ ________ / __/___ ____ / ____/________ _____ _____
/ /_/ / __ \/ ___/ _ \\_\ \/ _ \/ ___/ / /_ / ___/ __ `/ __ `/ __ \
/ ____/ /_/ / / / __/___/ __/ /___ / __/ / / / /_/ / / / / /_/ /
\_____\____/_/ \___/_____\___/____//_/ /_/ \__,_/_/ /_/\__,_/
EOF
echo -e "${NC}"
echo -e "${WHITE}Professional Cybersecurity Framework${NC}"
echo -e "${CYAN}Local Installation Setup Script v2.0${NC}"
echo ""
}
# Function to check system requirements
# Function to check system requirements
check_requirements() {
print_header "=== Checking System Requirements ==="
local missing_deps=()
local gui_missing=()
# Check Python
if ! command -v python3 &> /dev/null; then
missing_deps+=("python3")
else
python_version=$(python3 --version 2>&1 | cut -d' ' -f2)
print_status "Python version: ${python_version}"
if ! python3 -c "import sys; exit(0 if sys.version_info >= (3, 8) else 1)" 2>/dev/null; then
print_error "Python 3.8 or higher is required"
exit 1
fi
fi
# Add required system dependencies for Python development
missing_deps+=("build-essential" "python3-dev" "python3-pip" "python3-venv")
# Add dependencies for Oniux
missing_deps+=("tor" "iproute2" "cargo")
# Check tmux
if ! command -v tmux &> /dev/null; then
missing_deps+=("tmux")
else
print_status "tmux is available"
fi
# Check git
if ! command -v git &> /dev/null; then
missing_deps+=("git")
else
print_status "git is available"
fi
# ========== NUEVA SECCIÓN: GUI DEPENDENCIES ==========
print_status "Checking GUI module requirements..."
# Check Xvfb (Virtual X11 server)
if ! command -v Xvfb &> /dev/null; then
gui_missing+=("xvfb")
else
print_status "Xvfb is available"
fi
# Check x11vnc (VNC server for X11)
if ! command -v x11vnc &> /dev/null; then
gui_missing+=("x11vnc")
else
print_status "x11vnc is available"
fi
# Check X11 utilities
if ! command -v xdpyinfo &> /dev/null; then
gui_missing+=("x11-utils")
else
print_status "X11 utilities are available"
fi
# Check Fluxbox window manager
if ! command -v fluxbox &> /dev/null; then
gui_missing+=("fluxbox")
else
print_status "Fluxbox window manager is available"
fi
# Check websockify for noVNC
if ! command -v websockify &> /dev/null; then
gui_missing+=("websockify")
else
print_status "websockify is available"
fi
# Check if noVNC is available or can be installed
if [ ! -d "/usr/share/novnc" ] && [ ! -d "./novnc" ]; then
print_status "noVNC not found, will be installed automatically"
else
print_status "noVNC is available"
fi
# Install GUI dependencies if missing
if [ ${#gui_missing[@]} -ne 0 ]; then
print_warning "Missing GUI dependencies: ${gui_missing[*]}"
print_status "Installing GUI dependencies..."
if command -v apt-get &> /dev/null; then
# Debian/Ubuntu/Kali Linux
print_status "Using apt-get package manager..."
sudo apt-get update
# Map generic names to specific packages
local apt_packages=()
for dep in "${gui_missing[@]}"; do
case $dep in
"xvfb")
apt_packages+=("xvfb")
;;
"x11vnc")
apt_packages+=("x11vnc")
;;
"x11-utils")
apt_packages+=("x11-utils" "x11-xserver-utils")
;;
"fluxbox")
apt_packages+=("fluxbox")
;;
"websockify")
apt_packages+=("websockify" "python3-websockify")
;;
"build-essential")
apt_packages+=("build-essential")
;;
"python3-dev")
apt_packages+=("python3-dev")
;;
"python3-pip")
apt_packages+=("python3-pip")
;;
"python3-venv")
apt_packages+=("python3-venv")
;;
esac
done
# Add noVNC if available in repos
apt_packages+=("novnc")
# Install packages
if sudo apt-get install -y "${apt_packages[@]}"; then
print_success "GUI dependencies installed successfully"
else
print_warning "Some GUI packages may not have been installed correctly"
fi
elif command -v yum &> /dev/null; then
# RHEL/CentOS
print_status "Using yum package manager..."
local yum_packages=()
for dep in "${gui_missing[@]}"; do
case $dep in
"xvfb")
yum_packages+=("xorg-x11-server-Xvfb")
;;
"x11vnc")
yum_packages+=("x11vnc")
;;
"x11-utils")
yum_packages+=("xorg-x11-utils")
;;
"fluxbox")
yum_packages+=("fluxbox")
;;
"websockify")
yum_packages+=("python3-websockify")
;;
esac
done
sudo yum install -y "${yum_packages[@]}"
install_novnc_manual # noVNC not in RHEL repos
elif command -v dnf &> /dev/null; then
# Fedora
print_status "Using dnf package manager..."
local dnf_packages=()
for dep in "${gui_missing[@]}"; do
case $dep in
"xvfb")
dnf_packages+=("xorg-x11-server-Xvfb")
;;
"x11vnc")
dnf_packages+=("x11vnc")
;;
"x11-utils")
dnf_packages+=("xorg-x11-utils")
;;
"fluxbox")
dnf_packages+=("fluxbox")
;;
"websockify")
dnf_packages+=("python3-websockify")
;;
esac
done
sudo dnf install -y "${dnf_packages[@]}"
install_novnc_manual # Install noVNC manually
else
print_error "Cannot install GUI dependencies automatically."
print_error "Please install manually:"
echo " - Xvfb (virtual X11 server)"
echo " - x11vnc (VNC server)"
echo " - x11-utils (X11 utilities)"
echo " - fluxbox (window manager)"
echo " - websockify (noVNC proxy)"
print_warning "GUI module will be disabled without these dependencies"
fi
else
print_success "All GUI requirements satisfied"
fi
# Install noVNC if not available
if [ ! -d "/usr/share/novnc" ] && [ ! -d "./novnc" ]; then
install_novnc_manual
fi
# Install missing basic dependencies
if [ ${#missing_deps[@]} -ne 0 ]; then
print_warning "Missing basic dependencies: ${missing_deps[*]}"
print_status "Installing missing dependencies..."
if command -v apt-get &> /dev/null; then
sudo apt-get update
sudo apt-get install -y "${missing_deps[@]}"
elif command -v yum &> /dev/null; then
# For yum, cargo might need EPEL or other configurations
if [[ " ${missing_deps[*]} " =~ " cargo " ]]; then
print_warning "Cargo installation with yum might require EPEL repository or manual setup."
print_warning "Attempting to install an available 'cargo' package. If it fails, please install Rust/Cargo manually."
fi
sudo yum install -y "${missing_deps[@]}"
elif command -v dnf &> /dev/null; then
# For dnf, cargo might be in a separate group or require enabling a module
if [[ " ${missing_deps[*]} " =~ " cargo " ]]; then
print_warning "Cargo installation with dnf might require enabling a module or specific repository."
print_warning "Attempting to install an available 'cargo' package. If it fails, please install Rust/Cargo manually."
fi
sudo dnf install -y "${missing_deps[@]}"
else
print_error "Cannot install dependencies automatically. Please install: ${missing_deps[*]}"
exit 1
fi
fi
# Install Oniux if cargo was installed
if command -v cargo &> /dev/null; then
print_status "Installing Oniux..."
# Expand /tmp to 4G if it's mounted as tmpfs (RAM-based)
if mount | grep -qE '^tmpfs on /tmp '; then
print_status "Expanding /tmp tmpfs size to 4G temporarily..."
sudo mount -o remount,size=4G /tmp
fi
if cargo install --git https://gitlab.torproject.org/tpo/core/oniux --tag v0.4.0 oniux; then
print_success "Oniux installed successfully."
print_status "Updating PATH for Oniux..."
# Add to .zshrc if it exists
if [ -f "$HOME/.zshrc" ]; then
echo '' >> "$HOME/.zshrc" # Add a newline for separation
echo '# Add Oniux (installed via setup.sh) to PATH' >> "$HOME/.zshrc"
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> "$HOME/.zshrc"
print_status "Added PATH update to $HOME/.zshrc"
fi
# Add to .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
echo '' >> "$HOME/.bashrc" # Add a newline for separation
echo '# Add Oniux (installed via setup.sh) to PATH' >> "$HOME/.bashrc"
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> "$HOME/.bashrc"
print_status "Added PATH update to $HOME/.bashrc"
fi
print_warning "Oniux has been installed. Please source your .zshrc/.bashrc (e.g., 'source ~/.zshrc') or open a new terminal to use the 'oniux' command."
else
print_error "Oniux installation failed. This could be due to network issues or problems with the build process."
print_warning "Please check that Rust/Cargo is correctly installed and up to date, and that you have internet access."
print_warning "You can try running 'cargo install --git https://gitlab.torproject.org/tpo/core/oniux --tag v0.4.0 oniux' manually."
fi
else
print_warning "Cargo (Rust's package manager) was not installed or is not in PATH. Skipping Oniux installation."
print_warning "If you intended to install Oniux, please ensure cargo is installed and then run:"
print_warning " cargo install --git https://gitlab.torproject.org/tpo/core/oniux --tag v0.4.0 oniux"
print_warning " And add $HOME/.cargo/bin to your PATH in .bashrc/.zshrc"
fi
# ========== NUEVA SECCIÓN: INSTALL COMMON GUI APPS ==========
print_status "Installing common GUI applications for testing..."
if command -v apt-get &> /dev/null; then
# Install common applications that work well with the GUI module
local gui_apps=("firefox-esr" "gedit" "gnome-calculator" "xterm")
print_status "Installing GUI applications: ${gui_apps[*]}"
if sudo apt-get install -y "${gui_apps[@]}" 2>/dev/null; then
print_success "GUI applications installed successfully"
else
print_warning "Some GUI applications may not be available"
fi
fi
print_success "System requirements satisfied"
echo
}
# Function to initialize database
init_database() {
print_header "=== Database Initialization ==="
print_status "Initializing CoreSecFrame database..."
# Check if init_db.py exists
if [ -f "$SCRIPT_DIR/init_db.py" ]; then
# Use the existing init_db.py file
source "$VENV_PATH/bin/activate"
if python3 "$SCRIPT_DIR/init_db.py"; then
print_success "Database initialized successfully"
else
print_error "Database initialization failed"
return 1
fi
else
print_error "init_db.py not found in $SCRIPT_DIR"
return 1
fi
echo
}
# Function to reset database
reset_database() {
print_header "=== Database Reset ==="
print_warning "⚠️ WARNING: This will completely reset the database!"
print_warning "⚠️ All existing data including users, sessions, and logs will be PERMANENTLY deleted!"
echo
read -p "Are you absolutely sure you want to reset the database? (type 'RESET' to confirm): " confirm
if [ "$confirm" != "RESET" ]; then
print_status "Database reset cancelled."
return
fi
print_status "Resetting database..."
init_database
if [ $? -eq 0 ]; then
print_success "Database has been reset successfully!"
echo
echo -e "${YELLOW}Default credentials after reset:${NC}"
echo " Admin: admin/admin"
echo " User: user/password"
echo
else
print_error "Database reset failed"
fi
}
# Function to install noVNC manually
install_novnc_manual() {
print_status "Installing noVNC manually..."
if [ ! -d "$SCRIPT_DIR/novnc" ]; then
print_status "Downloading noVNC..."
if git clone https://github.com/novnc/noVNC.git "$SCRIPT_DIR/novnc"; then
print_success "noVNC downloaded successfully"
# Make sure it's accessible
chmod -R 755 "$SCRIPT_DIR/novnc"
# Create a symbolic link for easier access
if [ -w "/usr/local/bin" ]; then
sudo ln -sf "$SCRIPT_DIR/novnc/utils/novnc_proxy" /usr/local/bin/novnc_proxy 2>/dev/null || true
fi
print_status "noVNC installed to $SCRIPT_DIR/novnc"
# Test noVNC installation
if [ -f "$SCRIPT_DIR/novnc/utils/novnc_proxy" ]; then
print_success "noVNC proxy script is available"
else
print_warning "noVNC proxy script not found, checking for websockify..."
if command -v websockify &> /dev/null; then
print_status "websockify is available as fallback"
else
print_error "Neither noVNC proxy nor websockify found"
fi
fi
else
print_warning "Failed to download noVNC. GUI module may have limited functionality."
print_status "You can install it manually later with:"
echo " cd $SCRIPT_DIR"
echo " git clone https://github.com/novnc/noVNC.git novnc"
return 1
fi
else
print_status "noVNC already exists in $SCRIPT_DIR/novnc"
fi
return 0
}
# Function to verify GUI installation
verify_gui_installation() {
print_header "=== GUI Installation Verification ==="
local all_good=true
print_status "Verifying GUI components..."
# Check Xvfb
if command -v Xvfb &> /dev/null; then
print_success "✓ Xvfb is installed"
else
print_error "✗ Xvfb is NOT installed"
all_good=false
fi
# Check x11vnc
if command -v x11vnc &> /dev/null; then
print_success "✓ x11vnc is installed"
else
print_error "✗ x11vnc is NOT installed"
all_good=false
fi
# Check X11 utils
if command -v xdpyinfo &> /dev/null; then
print_success "✓ X11 utilities are installed"
else
print_error "✗ X11 utilities are NOT installed"
all_good=false
fi
# Check Fluxbox
if command -v fluxbox &> /dev/null; then
print_success "✓ Fluxbox window manager is installed"
else
print_warning "⚠ Fluxbox is not installed (optional but recommended)"
fi
# Check websockify
if command -v websockify &> /dev/null; then
print_success "✓ websockify is installed"
else
print_error "✗ websockify is NOT installed"
all_good=false
fi
# Check noVNC
if [ -d "/usr/share/novnc" ] || [ -d "$SCRIPT_DIR/novnc" ]; then
print_success "✓ noVNC is available"
else
print_error "✗ noVNC is NOT available"
all_good=false
fi
# Test GUI applications
print_status "Checking GUI applications..."
if command -v firefox-esr &> /dev/null || command -v firefox &> /dev/null; then
print_success "✓ Firefox browser is available"
else
print_warning "⚠ Firefox browser not found"
fi
if command -v gedit &> /dev/null; then
print_success "✓ Text editor (gedit) is available"
else
print_warning "⚠ Text editor not found"
fi
if command -v xterm &> /dev/null; then
print_success "✓ Terminal emulator (xterm) is available"
else
print_warning "⚠ Terminal emulator not found"
fi
echo
if [ "$all_good" = true ]; then
print_success "🎉 GUI module installation verification PASSED!"
print_status "You can now use the GUI module to run applications in virtual displays"
echo
print_status "Quick test commands after starting the application:"
echo " 1. Start CoreSecFrame: python run.py"
echo " 2. Initialize GUI apps: flask gui-init"
echo " 3. Access web interface: http://localhost:5000/gui"
else
print_error "❌ GUI module installation verification FAILED!"
print_status "Some required components are missing. Please install them manually."
echo
print_status "For Kali Linux/Debian/Ubuntu:"
echo " sudo apt update"
echo " sudo apt install -y xvfb x11vnc x11-utils fluxbox websockify novnc cargo"
echo " sudo apt install -y firefox-esr gedit xterm gnome-calculator"
fi
echo
}
# Function to setup noVNC service
setup_novnc_service() {
print_header "=== noVNC Web Service Setup ==="
# Detect if we are in WSL
if grep -qiE "(microsoft|wsl)" /proc/sys/kernel/osrelease 2>/dev/null; then
print_status "Detected WSL environment - Skipping noVNC systemd service setup"
return
fi
if ! command -v systemctl &> /dev/null; then
print_error "systemctl command not found. Cannot set up noVNC systemd service."
return 1
fi
print_status "Non-WSL environment detected - Proceeding with noVNC service setup"
# Create systemd directory if it doesn't exist
mkdir -p "$SYSTEMD_DIR"
# Check if websockify is available
if ! command -v websockify &> /dev/null; then
print_error "websockify not found. Please install it first:"
echo " Ubuntu/Debian: sudo apt-get install websockify"
echo " RHEL/CentOS: sudo yum install python3-websockify"
return 1
fi
# Determine noVNC path
NOVNC_PATH=""
if [ -d "/usr/share/novnc" ]; then
NOVNC_PATH="/usr/share/novnc"
elif [ -d "$SCRIPT_DIR/novnc" ]; then
NOVNC_PATH="$SCRIPT_DIR/novnc"
else
print_warning "noVNC not found. Installing it now..."
install_novnc_manual
NOVNC_PATH="$SCRIPT_DIR/novnc"
fi
print_warning "The noVNC systemd service will be configured to proxy VNC display :0 (port 5900) by default."
print_warning "If your VNC sessions use other displays/ports, you may need to adjust the noVNC client URL or start websockify manually for those specific sessions."
# Create noVNC systemd service
cat > "$SYSTEMD_DIR/novnc.service" << EOF
[Unit]
Description=noVNC Web Client
After=network.target
Wants=coresecframe.service
[Service]
Type=simple
User=$USER
Group=$USER
WorkingDirectory=$NOVNC_PATH
ExecStart=/usr/bin/websockify --web $NOVNC_PATH 6080 localhost:5900
Restart=always
RestartSec=3
Environment=HOME=/home/$USER
[Install]
WantedBy=multi-user.target
EOF
# Install and start service
if sudo cp "$SYSTEMD_DIR/novnc.service" /etc/systemd/system/; then
sudo systemctl daemon-reload
sudo systemctl enable novnc.service
sudo systemctl start novnc.service
print_success "noVNC systemd service installed and started automatically"
print_status "You can access it at: http://localhost:6080"
print_status "Manage it with:"
echo " sudo systemctl start|stop|status novnc"
else
print_error "Failed to install noVNC service"
fi
echo
}
# Function for local installation
install_local() {
print_header "=== Local Installation ==="
# Create virtual environment
print_status "Creating Python virtual environment..."
python3 -m venv "$VENV_PATH"
source "$VENV_PATH/bin/activate"
print_success "Virtual environment created and activated"
# Install dependencies
print_status "Installing Python dependencies..."
pip install --upgrade pip
pip install -r requirements.txt
print_success "Dependencies installed"
# Create required directories
print_status "Creating required directories..."
mkdir -p logs modules instance
chmod -R 755 .
chmod -R 777 logs modules instance
print_success "Directories created with proper permissions"
# Initialize database
init_database
# Verify GUI installation
verify_gui_installation
# Set up systemd service (optional)
setup_systemd_service
setup_novnc_service
print_success "Local installation completed!"
echo
print_header "=== Installation Summary ==="
echo -e "${WHITE}Application Location:${NC} $SCRIPT_DIR"
echo -e "${WHITE}Virtual Environment:${NC} $VENV_PATH"
echo -e "${WHITE}Database:${NC} SQLite (app.db)"
echo -e "${WHITE}Default Admin:${NC} admin/admin"
echo -e "${WHITE}Default User:${NC} user/password"
echo
echo -e "${CYAN}To start the application manually:${NC}"
echo " cd $SCRIPT_DIR"
echo " source venv/bin/activate"
echo " python run.py"
echo
echo -e "${CYAN}To initialize GUI applications:${NC}"
echo " flask gui-init"
echo
echo -e "${CYAN}Application will be available at:${NC} http://localhost:5000"
echo -e "${CYAN}GUI module will be available at:${NC} http://localhost:5000/gui"
echo
}
# Function to setup systemd service
setup_systemd_service() {
# Detect if we are in WSL
if grep -qiE "(microsoft|wsl)" /proc/sys/kernel/osrelease 2>/dev/null; then
print_warning "Detected WSL environment. Systemd services might not work as expected unless systemd is explicitly enabled in your WSL2 distribution."
local attempt_wsl_service_core # Use local to avoid conflicts
read -p "Still attempt to set up CoreSecFrame as a systemd service? (y/N): " attempt_wsl_service_core
if [[ ! $attempt_wsl_service_core =~ ^[Yy]$ ]]; then
print_status "Skipping systemd service setup for CoreSecFrame in WSL."
return
fi
fi
print_header "=== System Service Setup ==="
read -p "Would you like to set up CoreSecFrame to start automatically on system boot? (y/N): " auto_start
if [[ $auto_start =~ ^[Yy]$ ]]; then
if ! command -v systemctl &> /dev/null; then
print_error "systemctl command not found. Cannot set up systemd service."
return 1
fi
if [ ! -f "$SCRIPT_DIR/run.py" ]; then
print_error "$SCRIPT_DIR/run.py not found. Cannot set up service."
return 1
fi
print_status "Creating systemd service..."
# Create systemd directory
mkdir -p "$SYSTEMD_DIR"
# Create service file
cat > "$SYSTEMD_DIR/coresecframe.service" << EOF
[Unit]
Description=CoreSecFrame Web Application
After=network.target
[Service]
Type=simple
User=$USER
Group=$USER
WorkingDirectory=$SCRIPT_DIR
Environment="PATH=\$VENV_PATH/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ExecStart=$VENV_PATH/bin/python run.py
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
EOF
# Install service
sudo cp "$SYSTEMD_DIR/coresecframe.service" /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable coresecframe.service
print_success "Systemd service created and enabled"
print_status "Service commands:"
echo " Start: sudo systemctl start coresecframe"
echo " Stop: sudo systemctl stop coresecframe"
echo " Status: sudo systemctl status coresecframe"
echo " Logs: sudo journalctl -u coresecframe -f"
echo
read -p "Would you like to start the service now? (y/N): " start_now
if [[ $start_now =~ ^[Yy]$ ]]; then
sudo systemctl start coresecframe
print_success "CoreSecFrame service started!"
print_status "Service status:"
sudo systemctl status coresecframe --no-pager -l
fi
else
print_status "Skipping automatic startup setup"
fi
echo
}
# Main menu function
show_main_menu() {
while true; do
show_banner
echo -e "${WHITE}Choose an option:${NC}"
echo
echo " 1) 🖥️ Local Installation"
echo " 2) 🔄 Reset Database (DESTRUCTIVE)"
echo " 3) ❌ Exit"
echo
read -p "Enter your choice (1-3): " choice
case $choice in
1)
check_requirements
install_local
break
;;
2)
# Check if local installation exists
if [ -d "$VENV_PATH" ] && [ -f "$SCRIPT_DIR/app.db" ]; then
source "$VENV_PATH/bin/activate" 2>/dev/null || true
reset_database
else
print_error "No local installation found. Please run local installation first."
echo "Press Enter to continue..."
read
fi
;;
3)
print_status "Goodbye!"
exit 0
;;
*)
print_error "Invalid choice. Please select 1-3."
sleep 2
;;
esac
done
}
# Script entry point
main() {
# Check if running as root
if [ "$EUID" -eq 0 ]; then
print_error "Please do not run this script as root!"
exit 1
fi
# Show main menu
show_main_menu
}
# Run main function
main "$@"