fix update geo + log details fail2ban

This commit is contained in:
mhsanaei 2024-11-04 10:33:07 +01:00
parent adb08a60cf
commit 0fc935e996
No known key found for this signature in database
GPG Key ID: D875CD086CF668A0

101
x-ui.sh
View File

@ -164,7 +164,7 @@ update() {
bash <(curl -Ls https://raw.githubusercontent.com/MHSanaei/3x-ui/main/install.sh) bash <(curl -Ls https://raw.githubusercontent.com/MHSanaei/3x-ui/main/install.sh)
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
LOGI "Update is complete, Panel has automatically restarted " LOGI "Update is complete, Panel has automatically restarted "
exit 0 before_show_menu
fi fi
} }
@ -185,7 +185,7 @@ update_menu() {
if [[ $? == 0 ]]; then if [[ $? == 0 ]]; then
echo -e "${green}Update successful. The panel has automatically restarted.${plain}" echo -e "${green}Update successful. The panel has automatically restarted.${plain}"
exit 0 before_show_menu
else else
echo -e "${red}Failed to update the menu.${plain}" echo -e "${red}Failed to update the menu.${plain}"
return 1 return 1
@ -294,8 +294,8 @@ reset_config() {
return 0 return 0
fi fi
/usr/local/x-ui/x-ui setting -reset /usr/local/x-ui/x-ui setting -reset
echo -e "All panel settings have been reset to default, Please restart the panel now, and use the default ${green}2053${plain} Port to Access the web Panel" echo -e "All panel settings have been reset to default."
confirm_restart restart
} }
check_config() { check_config() {
@ -423,7 +423,7 @@ show_log() {
case "$choice" in case "$choice" in
0) 0)
return show_menu
;; ;;
1) 1)
journalctl -u x-ui -e --no-pager -f -p debug journalctl -u x-ui -e --no-pager -f -p debug
@ -438,21 +438,41 @@ show_log() {
restart restart
;; ;;
*) *)
echo "Invalid choice" echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
show_log
;; ;;
esac esac
} }
show_banlog() { show_banlog() {
if test -f "${iplimit_banned_log_path}"; then local system_log="/var/log/fail2ban.log"
echo -e "${green}Checking ban logs...${plain}\n"
if ! systemctl is-active --quiet fail2ban; then
echo -e "${red}Fail2ban service is not running!${plain}\n"
return 1
fi
if [[ -f "$system_log" ]]; then
echo -e "${green}Recent system ban activities from fail2ban.log:${plain}"
grep "3x-ipl" "$system_log" | grep -E "Ban|Unban" | tail -n 10 || echo -e "${yellow}No recent system ban activities found${plain}"
echo ""
fi
if [[ -f "${iplimit_banned_log_path}" ]]; then
echo -e "${green}3X-IPL ban log entries:${plain}"
if [[ -s "${iplimit_banned_log_path}" ]]; then if [[ -s "${iplimit_banned_log_path}" ]]; then
cat ${iplimit_banned_log_path} grep -v "INIT" "${iplimit_banned_log_path}" | tail -n 10 || echo -e "${yellow}No ban entries found${plain}"
else else
echo -e "${red}Log file is empty.${plain}\n" echo -e "${yellow}Ban log file is empty${plain}"
fi fi
else else
echo -e "${red}Log file not found. Please Install Fail2ban and IP Limit first.${plain}\n" echo -e "${red}Ban log file not found at: ${iplimit_banned_log_path}${plain}"
fi fi
echo -e "\n${green}Current jail status:${plain}"
fail2ban-client status 3x-ipl || echo -e "${yellow}Unable to get jail status${plain}"
} }
bbr_menu() { bbr_menu() {
@ -466,11 +486,16 @@ bbr_menu() {
;; ;;
1) 1)
enable_bbr enable_bbr
bbr_menu
;; ;;
2) 2)
disable_bbr disable_bbr
bbr_menu
;;
*)
echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
bbr_menu
;; ;;
*) echo "Invalid choice" ;;
esac esac
} }
@ -478,7 +503,7 @@ disable_bbr() {
if ! grep -q "net.core.default_qdisc=fq" /etc/sysctl.conf || ! grep -q "net.ipv4.tcp_congestion_control=bbr" /etc/sysctl.conf; then if ! grep -q "net.core.default_qdisc=fq" /etc/sysctl.conf || ! grep -q "net.ipv4.tcp_congestion_control=bbr" /etc/sysctl.conf; then
echo -e "${yellow}BBR is not currently enabled.${plain}" echo -e "${yellow}BBR is not currently enabled.${plain}"
exit 0 before_show_menu
fi fi
# Replace BBR with CUBIC configurations # Replace BBR with CUBIC configurations
@ -499,7 +524,7 @@ disable_bbr() {
enable_bbr() { enable_bbr() {
if grep -q "net.core.default_qdisc=fq" /etc/sysctl.conf && grep -q "net.ipv4.tcp_congestion_control=bbr" /etc/sysctl.conf; then if grep -q "net.core.default_qdisc=fq" /etc/sysctl.conf && grep -q "net.ipv4.tcp_congestion_control=bbr" /etc/sysctl.conf; then
echo -e "${green}BBR is already enabled!${plain}" echo -e "${green}BBR is already enabled!${plain}"
exit 0 before_show_menu
fi fi
# Check the OS and install necessary packages # Check the OS and install necessary packages
@ -545,7 +570,8 @@ update_shell() {
before_show_menu before_show_menu
else else
chmod +x /usr/bin/x-ui chmod +x /usr/bin/x-ui
LOGI "Upgrade script succeeded, Please rerun the script" && exit 0 LOGI "Upgrade script succeeded, Please rerun the script"
before_show_menu
fi fi
} }
@ -657,17 +683,24 @@ firewall_menu() {
;; ;;
1) 1)
open_ports open_ports
firewall_menu
;; ;;
2) 2)
sudo ufw status sudo ufw status
firewall_menu
;; ;;
3) 3)
delete_ports delete_ports
firewall_menu
;; ;;
4) 4)
sudo ufw disable sudo ufw disable
firewall_menu
;;
*)
echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
firewall_menu
;; ;;
*) echo "Invalid choice" ;;
esac esac
} }
@ -786,21 +819,25 @@ update_geo() {
wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat wget -N https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
echo -e "${green}Loyalsoldier datasets have been updated successfully!${plain}" echo -e "${green}Loyalsoldier datasets have been updated successfully!${plain}"
restart
;; ;;
2) 2)
rm -f geoip_IR.dat geosite_IR.dat rm -f geoip_IR.dat geosite_IR.dat
wget -O geoip_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat wget -O geoip_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat
wget -O geosite_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat wget -O geosite_IR.dat -N https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat
echo -e "${green}chocolate4u datasets have been updated successfully!${plain}" echo -e "${green}chocolate4u datasets have been updated successfully!${plain}"
restart
;; ;;
3) 3)
rm -f geoip_VN.dat geosite_VN.dat rm -f geoip_VN.dat geosite_VN.dat
wget -O geoip_VN.dat -N https://github.com/vuong2023/vn-v2ray-rules/releases/latest/download/geoip.dat wget -O geoip_VN.dat -N https://github.com/vuong2023/vn-v2ray-rules/releases/latest/download/geoip.dat
wget -O geosite_VN.dat -N https://github.com/vuong2023/vn-v2ray-rules/releases/latest/download/geosite.dat wget -O geosite_VN.dat -N https://github.com/vuong2023/vn-v2ray-rules/releases/latest/download/geosite.dat
echo -e "${green}vuong2023 datasets have been updated successfully!${plain}" echo -e "${green}vuong2023 datasets have been updated successfully!${plain}"
restart
;; ;;
*) *)
echo "Invalid option selected! No updates made." echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
update_geo
;; ;;
esac esac
@ -844,6 +881,7 @@ ssl_cert_issue_main() {
;; ;;
1) 1)
ssl_cert_issue ssl_cert_issue
ssl_cert_issue_main
;; ;;
2) 2)
local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
@ -860,6 +898,7 @@ ssl_cert_issue_main() {
echo "Invalid domain entered." echo "Invalid domain entered."
fi fi
fi fi
ssl_cert_issue_main
;; ;;
3) 3)
local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
@ -876,6 +915,7 @@ ssl_cert_issue_main() {
echo "Invalid domain entered." echo "Invalid domain entered."
fi fi
fi fi
ssl_cert_issue_main
;; ;;
4) 4)
local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
@ -895,6 +935,7 @@ ssl_cert_issue_main() {
fi fi
done done
fi fi
ssl_cert_issue_main
;; ;;
5) 5)
local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) local domains=$(find /root/cert/ -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
@ -922,10 +963,12 @@ ssl_cert_issue_main() {
echo "Invalid domain entered." echo "Invalid domain entered."
fi fi
fi fi
ssl_cert_issue_main
;; ;;
*) *)
echo "Invalid choice" echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
ssl_cert_issue_main
;; ;;
esac esac
} }
@ -1297,20 +1340,28 @@ iplimit_main() {
;; ;;
4) 4)
show_banlog show_banlog
iplimit_main
;; ;;
5) 5)
tail -f /var/log/fail2ban.log tail -f /var/log/fail2ban.log
iplimit_main
;; ;;
6) 6)
service fail2ban status service fail2ban status
iplimit_main
;; ;;
7) 7)
systemctl restart fail2ban systemctl restart fail2ban
iplimit_main
;; ;;
8) 8)
remove_iplimit remove_iplimit
iplimit_main
;;
*)
echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
iplimit_main
;; ;;
*) echo "Invalid choice" ;;
esac esac
} }
@ -1391,7 +1442,7 @@ install_iplimit() {
remove_iplimit() { remove_iplimit() {
echo -e "${green}\t1.${plain} Only remove IP Limit configurations" echo -e "${green}\t1.${plain} Only remove IP Limit configurations"
echo -e "${green}\t2.${plain} Uninstall Fail2ban and IP Limit" echo -e "${green}\t2.${plain} Uninstall Fail2ban and IP Limit"
echo -e "${green}\t0.${plain} Abort" echo -e "${green}\t0.${plain} Back to Main Menu"
read -p "Choose an option: " num read -p "Choose an option: " num
case "$num" in case "$num" in
1) 1)
@ -1431,8 +1482,7 @@ remove_iplimit() {
before_show_menu before_show_menu
;; ;;
0) 0)
echo -e "${yellow}Cancelled.${plain}\n" show_menu
iplimit_main
;; ;;
*) *)
echo -e "${red}Invalid option. Please select a valid number.${plain}\n" echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
@ -1454,7 +1504,7 @@ SSH_port_forwarding() {
if [[ -n "$existing_cert" && -n "$existing_key" ]]; then if [[ -n "$existing_cert" && -n "$existing_key" ]]; then
echo -e "${green}Panel is secure with SSL.${plain}" echo -e "${green}Panel is secure with SSL.${plain}"
return 0 before_show_menu
fi fi
if [[ -z "$existing_cert" && -z "$existing_key" && (-z "$existing_listenIP" || "$existing_listenIP" == "0.0.0.0") ]]; then if [[ -z "$existing_cert" && -z "$existing_key" && (-z "$existing_listenIP" || "$existing_listenIP" == "0.0.0.0") ]]; then
echo -e "\n${red}Warning: No Cert and Key found! The panel is not secure.${plain}" echo -e "\n${red}Warning: No Cert and Key found! The panel is not secure.${plain}"
@ -1474,7 +1524,7 @@ SSH_port_forwarding() {
echo -e "\nChoose an option:" echo -e "\nChoose an option:"
echo -e "${green}1.${plain} Set listen IP" echo -e "${green}1.${plain} Set listen IP"
echo -e "${green}2.${plain} Clear listen IP" echo -e "${green}2.${plain} Clear listen IP"
echo -e "${green}0.${plain} Abort" echo -e "${green}0.${plain} Back to Main Menu"
read -p "Choose an option: " num read -p "Choose an option: " num
case "$num" in case "$num" in
@ -1509,10 +1559,11 @@ SSH_port_forwarding() {
restart restart
;; ;;
0) 0)
echo "Operation aborted." show_menu
;; ;;
*) *)
echo "Invalid option. Exiting." echo -e "${red}Invalid option. Please select a valid number.${plain}\n"
SSH_port_forwarding
;; ;;
esac esac
} }