3x-ui/x-ui.sh

284 lines
9.9 KiB
Bash
Raw Normal View History

2023-02-09 19:18:06 +00:00
#!/bin/bash
# x-ui.sh - 3X-UI Panel Management Script (Entrypoint)
# This is the main entrypoint that sources modular library files
# Export LIB_DIR for use by library files
2026-01-18 18:51:40 +00:00
LIB_DIR="${LIB_DIR:=/usr/local/x-ui/lib}"
export LIB_DIR
# Source all library files
source "${LIB_DIR}/common.sh"
source "${LIB_DIR}/service.sh"
source "${LIB_DIR}/ssl.sh"
source "${LIB_DIR}/settings.sh"
source "${LIB_DIR}/firewall.sh"
source "${LIB_DIR}/iplimit.sh"
source "${LIB_DIR}/bbr.sh"
source "${LIB_DIR}/geo.sh"
source "${LIB_DIR}/install.sh"
source "${LIB_DIR}/extras.sh"
# Print OS info
echo "The OS release is: $release"
2023-02-09 19:18:06 +00:00
#=============================================================================
# Menu Functions (kept in entrypoint to avoid circular dependencies)
#=============================================================================
confirm_restart() {
confirm "Restart the panel, Attention: Restarting the panel will also restart xray" "y"
if [[ $? == 0 ]]; then
2025-12-27 23:03:33 +00:00
restart
else
2024-11-04 09:33:07 +00:00
show_menu
2025-08-15 11:33:31 +00:00
fi
}
before_show_menu() {
echo && echo -n -e "${yellow}Press enter to return to the main menu: ${plain}" && read -r temp
show_menu
}
2023-02-09 19:18:06 +00:00
show_usage() {
echo -e "┌────────────────────────────────────────────────────────────────┐
${blue}x-ui control menu usages (subcommands):${plain}
│ │
${blue}x-ui${plain} - Admin Management Script │
${blue}x-ui start${plain} - Start │
${blue}x-ui stop${plain} - Stop │
${blue}x-ui restart${plain} - Restart │
${blue}x-ui status${plain} - Current Status │
${blue}x-ui settings${plain} - Current Settings │
${blue}x-ui enable${plain} - Enable Autostart on OS Startup │
${blue}x-ui disable${plain} - Disable Autostart on OS Startup │
${blue}x-ui log${plain} - Check logs │
${blue}x-ui banlog${plain} - Check Fail2ban ban logs │
${blue}x-ui update${plain} - Update │
${blue}x-ui update-all-geofiles${plain} - Update all geo files │
${blue}x-ui legacy${plain} - Legacy version │
${blue}x-ui install${plain} - Install │
${blue}x-ui uninstall${plain} - Uninstall │
└────────────────────────────────────────────────────────────────┘"
2023-02-09 19:18:06 +00:00
}
2026-01-18 15:10:17 +00:00
update_geo() {
echo -e "${green}\t1.${plain} Loyalsoldier (geoip.dat, geosite.dat)"
echo -e "${green}\t2.${plain} chocolate4u (geoip_IR.dat, geosite_IR.dat)"
echo -e "${green}\t3.${plain} runetfreedom (geoip_RU.dat, geosite_RU.dat)"
echo -e "${green}\t4.${plain} All"
echo -e "${green}\t0.${plain} Back to Main Menu"
read -rp "Choose an option: " choice
case "$choice" in
0)
show_menu
;;
1)
update_geofiles "main" "${xui_folder}"/bin
echo -e "${green}Loyalsoldier datasets have been updated successfully!${plain}"
restart
;;
2)
update_geofiles "IR" "${xui_folder}"/bin
echo -e "${green}chocolate4u datasets have been updated successfully!${plain}"
restart
;;
3)
update_geofiles "RU" "${xui_folder}"/bin
echo -e "${green}runetfreedom datasets have been updated successfully!${plain}"
restart
;;
4)
update_all_geofiles "${xui_folder}"/bin
echo -e "${green}All geo files have been updated successfully!${plain}"
restart
;;
*)
echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
update_geo
;;
esac
before_show_menu
}
2023-02-09 19:18:06 +00:00
show_menu() {
echo -e "
╔────────────────────────────────────────────────╗
${green}3X-UI Panel Management Script${plain}
${green}0.${plain} Exit Script │
│────────────────────────────────────────────────│
${green}1.${plain} Install │
${green}2.${plain} Update │
${green}3.${plain} Update Menu │
${green}4.${plain} Legacy Version │
${green}5.${plain} Uninstall │
│────────────────────────────────────────────────│
${green}6.${plain} Reset Username & Password │
${green}7.${plain} Reset Web Base Path │
${green}8.${plain} Reset Settings │
${green}9.${plain} Change Port │
${green}10.${plain} View Current Settings │
│────────────────────────────────────────────────│
${green}11.${plain} Start │
${green}12.${plain} Stop │
${green}13.${plain} Restart │
${green}14.${plain} Check Status │
${green}15.${plain} Logs Management │
│────────────────────────────────────────────────│
${green}16.${plain} Enable Autostart │
${green}17.${plain} Disable Autostart │
│────────────────────────────────────────────────│
${green}18.${plain} SSL Certificate Management │
${green}19.${plain} Cloudflare SSL Certificate │
${green}20.${plain} IP Limit Management │
${green}21.${plain} Firewall Management │
${green}22.${plain} SSH Port Forwarding Management │
│────────────────────────────────────────────────│
${green}23.${plain} Enable BBR │
${green}24.${plain} Update Geo Files │
${green}25.${plain} Speedtest by Ookla │
╚────────────────────────────────────────────────╝
"
2023-02-09 19:18:06 +00:00
show_status
echo && read -rp "Please enter your selection [0-25]: " num
2023-02-09 19:18:06 +00:00
case "${num}" in
0)
exit 0
;;
1)
check_uninstall && install
;;
2)
check_install && update
;;
3)
2024-06-24 13:22:05 +00:00
check_install && update_menu
2023-02-09 19:18:06 +00:00
;;
4)
2024-10-31 00:18:37 +00:00
check_install && legacy_version
2023-02-09 19:18:06 +00:00
;;
5)
2024-06-24 13:22:05 +00:00
check_install && uninstall
2023-02-09 19:18:06 +00:00
;;
6)
2024-06-24 13:22:05 +00:00
check_install && reset_user
2023-02-09 19:18:06 +00:00
;;
7)
2024-06-24 13:22:05 +00:00
check_install && reset_webbasepath
2023-02-09 19:18:06 +00:00
;;
8)
2024-06-24 13:22:05 +00:00
check_install && reset_config
2023-02-09 19:18:06 +00:00
;;
9)
2024-06-24 13:22:05 +00:00
check_install && set_port
2023-02-09 19:18:06 +00:00
;;
10)
2024-06-24 13:22:05 +00:00
check_install && check_config
2023-02-09 19:18:06 +00:00
;;
11)
2024-06-24 13:22:05 +00:00
check_install && start
2023-02-09 19:18:06 +00:00
;;
12)
2024-06-24 13:22:05 +00:00
check_install && stop
2023-02-09 19:18:06 +00:00
;;
13)
2024-06-24 13:22:05 +00:00
check_install && restart
2023-02-09 19:18:06 +00:00
;;
14)
2024-06-24 13:22:05 +00:00
check_install && status
2023-02-09 19:18:06 +00:00
;;
15)
2024-06-24 13:22:05 +00:00
check_install && show_log
2023-02-09 19:18:06 +00:00
;;
16)
2024-06-24 13:22:05 +00:00
check_install && enable
2023-02-09 19:18:06 +00:00
;;
17)
2024-06-24 13:22:05 +00:00
check_install && disable
;;
18)
2024-06-24 13:22:05 +00:00
ssl_cert_issue_main
;;
19)
2024-06-24 13:22:05 +00:00
ssl_cert_issue_CF
;;
2023-05-13 15:36:16 +00:00
20)
2024-06-24 13:22:05 +00:00
iplimit_main
;;
2024-01-27 09:26:10 +00:00
21)
2024-06-24 13:22:05 +00:00
firewall_menu
2024-01-01 20:09:21 +00:00
;;
2024-09-09 07:48:48 +00:00
22)
SSH_port_forwarding
2024-06-24 12:43:39 +00:00
;;
2024-09-09 07:48:48 +00:00
23)
bbr_menu
2024-06-24 13:22:05 +00:00
;;
2024-09-09 07:48:48 +00:00
24)
update_geo
;;
25)
2023-06-24 21:37:34 +00:00
run_speedtest
2024-01-20 13:58:44 +00:00
;;
2023-02-09 19:18:06 +00:00
*)
LOGE "Please enter the correct number [0-25]"
2023-02-09 19:18:06 +00:00
;;
esac
}
#=============================================================================
# CLI Argument Handling
#=============================================================================
if [[ $# -gt 0 ]]; then
2023-02-09 19:18:06 +00:00
case $1 in
"start")
check_install 0 && start 0
;;
"stop")
check_install 0 && stop 0
;;
"restart")
check_install 0 && restart 0
;;
"status")
check_install 0 && status 0
;;
2024-06-24 11:47:13 +00:00
"settings")
check_install 0 && check_config 0
;;
2023-02-09 19:18:06 +00:00
"enable")
check_install 0 && enable 0
;;
"disable")
check_install 0 && disable 0
;;
"log")
check_install 0 && show_log 0
;;
"banlog")
check_install 0 && show_banlog 0
;;
2023-02-09 19:18:06 +00:00
"update")
check_install 0 && update 0
;;
2024-10-31 00:18:37 +00:00
"legacy")
check_install 0 && legacy_version 0
2024-06-24 11:47:13 +00:00
;;
2023-02-09 19:18:06 +00:00
"install")
check_uninstall 0 && install 0
;;
"uninstall")
check_install 0 && uninstall 0
;;
"update-all-geofiles")
2026-01-18 15:10:17 +00:00
check_install 0 && update_all_geofiles "${xui_folder}"/bin 0 && restart 0
;;
2023-02-09 19:18:06 +00:00
*) show_usage ;;
esac
else
show_menu
fi