toolbox.sh

This commit is contained in:
2025-12-13 18:46:13 +00:00
parent 7217bd894b
commit 1439a02b4e

179
toolbox.sh Normal file
View File

@@ -0,0 +1,179 @@
#!/bin/bash
# ===============================
# Colors
# ===============================
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
CYAN="\033[0;36m"
NC="\033[0m"
LOGFILE="$HOME/toolbox.log"
# ===============================
# Logging function
# ===============================
log_action() {
local msg="$1"
echo "$(date '+%Y-%m-%d %H:%M:%S') - $msg" >> "$LOGFILE"
}
# ===============================
# Functions / Tools
# ===============================
sys_info() {
echo -e "${CYAN}=== CPU ===${NC}"
lscpu | grep "Model name"
echo -e "${CYAN}=== Memory ===${NC}"
free -h
echo -e "${CYAN}=== Disk ===${NC}"
df -h
read -p "Press Enter to go back..."
}
check_site() {
while true; do
echo -n -e "${YELLOW}Enter website URL (or 'b' to go back): ${NC}"
read name
[[ "$name" == "b" ]] && break
if curl -s --head "$name" | grep "200 OK" > /dev/null; then
echo -e "${GREEN}Site is UP${NC}"
log_action "Website check: $name - UP"
else
echo -e "${RED}Site is DOWN${NC}"
log_action "Website check: $name - DOWN"
fi
done
}
list_processes() {
echo -e "${CYAN}=== Top Processes by CPU ===${NC}"
ps aux --sort=-%cpu | head -10
read -p "Press Enter to go back..."
}
disk_usage() {
echo -e "${CYAN}=== Disk Usage ===${NC}"
df -h
read -p "Press Enter to go back..."
}
network_info() {
echo -e "${CYAN}=== IP Addresses ===${NC}"
ip a
echo -e "${CYAN}=== Open Ports (TCP) ===${NC}"
sudo netstat -tulnp 2>/dev/null
read -p "Press Enter to go back..."
}
ping_test() {
echo -n -e "${YELLOW}Enter IP or hostname to ping (b to go back): ${NC}"
read target
[[ "$target" == "b" ]] && return
ping -c 4 "$target"
read -p "Press Enter to go back..."
}
list_users() {
echo -e "${CYAN}=== System Users ===${NC}"
cut -d: -f1 /etc/passwd
read -p "Press Enter to go back..."
}
add_user() {
echo -n -e "${YELLOW}Enter new username (b to go back): ${NC}"
read username
[[ "$username" == "b" ]] && return
if sudo adduser "$username"; then
echo -e "${GREEN}User $username added successfully${NC}"
log_action "Added user: $username"
else
echo -e "${RED}Failed to add user $username${NC}"
log_action "Failed to add user: $username"
fi
read -p "Press Enter to continue..."
}
service_manager() {
while true; do
clear
echo -e "${CYAN}=== Service Manager ===${NC}"
echo "1) Start service"
echo "2) Stop service"
echo "3) Restart service"
echo "4) Show running services"
echo "5) Back to main menu"
read -p "Enter choice [1-5]: " svc_choice
if ! [[ "$svc_choice" =~ ^[1-5]$ ]]; then
echo -e "${RED}Invalid choice${NC}"
sleep 1
continue
fi
case $svc_choice in
1|2|3)
read -p "Enter service name: " svc
action=$( [ "$svc_choice" == 1 ] && echo start || [ "$svc_choice" == 2 ] && echo stop || echo restart )
if sudo systemctl "$action" "$svc"; then
echo -e "${GREEN}Service $svc $action successfully${NC}"
log_action "Service $svc action $action succeeded"
else
echo -e "${RED}Service $svc $action failed${NC}"
log_action "Service $svc action $action failed"
fi
read -p "Press Enter to continue..."
;;
4)
echo -e "${CYAN}=== Running Services ===${NC}"
systemctl list-units --type=service --state=running | head -20
read -p "Press Enter to continue..."
;;
5)
break
;;
esac
done
}
# ===============================
# Main Menu
# ===============================
while true; do
clear
echo -e "${CYAN}=== ADMIN TOOLBOX MENU ===${NC}"
echo -e "${YELLOW}1) System Info${NC}"
echo -e "${YELLOW}2) Check Website Status${NC}"
echo -e "${YELLOW}3) List Top Processes${NC}"
echo -e "${YELLOW}4) Disk Usage${NC}"
echo -e "${YELLOW}5) Network Info${NC}"
echo -e "${YELLOW}6) Ping Test${NC}"
echo -e "${YELLOW}7) List Users${NC}"
echo -e "${YELLOW}8) Add User${NC}"
echo -e "${YELLOW}9) Service Manager${NC}"
echo -e "${YELLOW}10) Exit${NC}"
echo
read -p "Enter your choice [1-10]: " choice
# Input validation
if ! [[ "$choice" =~ ^[1-9]$|^10$ ]]; then
echo -e "${RED}Invalid input! Enter 1-10.${NC}"
sleep 1
continue
fi
case $choice in
1) sys_info ;;
2) check_site ;;
3) list_processes ;;
4) disk_usage ;;
5) network_info ;;
6) ping_test ;;
7) list_users ;;
8) add_user ;;
9) service_manager ;;
10) echo -e "${GREEN}Goodbye!${NC}"; exit 0 ;;
esac
done