-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·188 lines (165 loc) · 5.05 KB
/
run.sh
File metadata and controls
executable file
·188 lines (165 loc) · 5.05 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
#!/bin/bash
set -Eeuo pipefail
# Networking & Cybersecurity Automation Toolkit
# Main control script
# /run.sh
# Root check
if [[ $EUID -ne 0 ]]; then
echo ""
echo " [!] This script must be run with sudo or as root."
echo " [>] Run: sudo $0"
echo ""
exit 1
fi
# Project root
export PROJECT_ROOT="$(cd "$(dirname "$0")" && pwd)"
# Source dependencies
source "$PROJECT_ROOT/config/settings.conf"
source "$PROJECT_ROOT/lib/colors.sh"
source "$PROJECT_ROOT/lib/functions.sh"
source "$PROJECT_ROOT/modules/run_modules.sh"
source "$PROJECT_ROOT/network_lab/network_lab.sh"
source "$PROJECT_ROOT/dashboard/start_dashboard.sh"
# Directory setup
MODULES_DIR="$PROJECT_ROOT/modules"
LOG_DIR="$PROJECT_ROOT/logs"
OUTPUT_DIR="$PROJECT_ROOT/output"
DASHBOARD_DIR="$PROJECT_ROOT/dashboard"
mkdir -p "$LOG_DIR" "$OUTPUT_DIR"
touch "$LOG_DIR/main.log"
# MAIN MENU
show_main_menu() {
local W=50
local border
border=$(printf '%*s' "$W" '' | tr ' ' '=')
echo -e "${BORDER}${border}${NC}"
printf "${BORDER}|${NC} ${TITLE}%-$((W-4))s${NC} ${BORDER}|${NC}\n" "MAIN MENU"
echo -e "${BORDER}${border}${NC}"
echo
echo -e " ${LABEL}SETUP${NC}"
echo -e " ${GREEN} 1.${NC} Install / Verify Networking Tools"
echo
echo -e " ${LABEL}SECURITY${NC}"
echo -e " ${GREEN} 2.${NC} Run Security Modules"
echo
echo -e " ${LABEL}MONITORING${NC}"
echo -e " ${GREEN} 3.${NC} View Dashboard"
echo -e " ${GREEN} 7.${NC} Stop Dashboard"
echo
echo -e " ${LABEL}SYSTEM${NC}"
echo -e " ${GREEN} 4.${NC} Clean Logs & Output"
echo -e " ${GREEN} 5.${NC} System Information"
echo
echo -e " ${LABEL}NETWORK LAB${NC}"
echo -e " ${GREEN} 6.${NC} Network Lab"
echo
echo -e " ${RED} 0.${NC} Exit"
echo
echo -e "${BORDER}${border}${NC}"
}
install_dependencies() {
clear
show_banner
echo -e " ${LABEL}Dependency Installer${NC}"
echo
if [[ -f "$PROJECT_ROOT/install.sh" ]]; then
echo -e " ${AMBER}[+] Running dependency installer...${NC}"
echo
bash "$PROJECT_ROOT/install.sh" || log_error "Installer failed"
echo
log_success "Dependency installation completed."
else
log_error "install.sh not found in project root."
fi
echo
read -rp "$(echo -e " ${MUTED}Press Enter to continue...${NC} ")"
}
# CLEAN DATA
clean_data() {
clear
show_banner
echo -e " ${FAILURE}[!] WARNING: This will permanently delete all logs and output files!"
echo
read -rp "$(echo -e " ${WARNING}[?] Are you sure? [yes/no]: ${NC}")" confirm
if [[ "$confirm" == "yes" ]]; then
rm -rf -- "${LOG_DIR:?}/"* "${OUTPUT_DIR:?}/"*
log_success "Cleaned successfully."
else
log_info "Operation cancelled."
fi
echo
read -rp "$(echo -e " ${MUTED}Press Enter to continue...${NC} ")"
}
# SYSTEM INFO
show_system_info() {
clear
show_banner
echo -e " ${AMBER}Host${NC}"
kv " Operating System" "$(detect_os)"
kv " Hostname" "$(hostname)"
kv " User" "$(whoami)"
kv " Date" "$(date '+%Y-%m-%d %H:%M:%S')"
kv " Uptime" "$(uptime -p 2>/dev/null || uptime)"
echo
echo -e " ${AMBER}Toolkit${NC}"
kv " Log files" "$(find "$LOG_DIR" -type f 2>/dev/null -printf '.' | wc -c)"
kv " Output files" "$(find "$OUTPUT_DIR" -type f 2>/dev/null | wc -l)"
kv " Modules" "$(find "$MODULES_DIR" -name '*.sh' ! -name 'run_modules.sh' | wc -l)"
echo
if [[ -f "$PID_FILE" ]]; then
pid=$(cat "$PID_FILE")
if kill -0 "$pid" 2>/dev/null; then
kv " Dashboard" "${SUCCESS}Running${NC} (PID: ${pid})"
else
kv " Dashboard" "${FAILURE}Not running (stale PID)"
fi
else
kv " Dashboard" "${MUTED}Not running${NC}"
fi
echo
read -rp "$(echo -e " ${MUTED}Press Enter to continue...${NC} ")"
}
# CLEANUP
cleanup() {
echo
log_info "Toolkit shutting down..."
}
trap cleanup EXIT INT TERM
# MAIN LOOP
main() {
while true; do
clear
show_banner
show_main_menu
read -rp "$(echo -e " ${PROMPT}[?] Enter your choice: ${NC}")" choice
echo
case $choice in
1) install_dependencies ;;
2)
while true; do
show_modules_menu
read -rp "$(echo -e " ${PROMPT}[?] Enter your choice: ${NC}")" module_choice
[[ "$module_choice" == "0" ]] && break
run_modules "$module_choice"
done
;;
3) start_dashboard_main ;;
4) clean_data ;;
5) show_system_info ;;
6) network_lab ;;
7) stop_dashboard ;;
0)
clear
show_banner
echo -e " ${SUCCESS}[+] Thank you for using the Networking & Cybersecurity Toolkit!"
echo
exit 0
;;
*)
log_error "Invalid choice. Please try again."
sleep 1
;;
esac
done
}
main