Skip to content

Commit

Permalink
bash - Reset Web Base Path
Browse files Browse the repository at this point in the history
  • Loading branch information
MHSanaei committed Jun 24, 2024
1 parent 3ef4ab4 commit f481ab9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 38 deletions.
8 changes: 7 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ install_base() {
esac
}

gen_random_string() {
local length="$1"
local random_string=$(LC_ALL=C tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w "$length" | head -n 1)
echo "$random_string"
}

# This function will be called when user installed x-ui out of security
config_after_install() {
echo -e "${yellow}Install/update finished! For security it's recommended to modify panel settings ${plain}"
Expand All @@ -146,7 +152,7 @@ config_after_install() {
if [[ ! -f "/etc/x-ui/x-ui.db" ]]; then
local usernameTemp=$(head -c 6 /dev/urandom | base64)
local passwordTemp=$(head -c 6 /dev/urandom | base64)
local webBasePathTemp=$(head -c 6 /dev/urandom | base64)
local webBasePathTemp=$(gen_random_string 10)
/usr/local/x-ui/x-ui setting -username ${usernameTemp} -password ${passwordTemp} -webBasePath ${webBasePathTemp}
echo -e "This is a fresh installation, will generate random login info for security concerns:"
echo -e "###############################################"
Expand Down
103 changes: 66 additions & 37 deletions x-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,31 @@ reset_user() {
confirm_restart
}

gen_random_string() {
local length="$1"
local random_string=$(LC_ALL=C tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w "$length" | head -n 1)
echo "$random_string"
}

reset_webbasepath() {
echo -e "${yellow}Resetting Web Base Path${plain}"

# Prompt user to set a new web base path
read -rp "Please set the new web base path [default is a random path]: " config_webBasePath

# If user input is empty, generate a random path
if [[ -z $config_webBasePath ]]; then
config_webBasePath=$(gen_random_string 10)
fi

# Apply the new web base path setting
/usr/local/x-ui/x-ui setting -webBasePath "${config_webBasePath}" >/dev/null 2>&1

# Display confirmation message
echo -e "Web base path has been reset to: ${green} ${config_webBasePath} ${plain}"
echo -e "${green} Please use the new web base path to access the panel. ${plain}"
}

reset_config() {
confirm "Are you sure you want to reset all panel settings, Account data will not be lost, Username and password will not change" "n"
if [[ $? != 0 ]]; then
Expand Down Expand Up @@ -1282,31 +1307,32 @@ show_menu() {
${green}4.${plain} Uninstall
————————————————
${green}5.${plain} Reset Username & Password & Secret Token
${green}6.${plain} Reset Settings
${green}7.${plain} Change Port
${green}8.${plain} View Current Settings
${green}6.${plain} Reset Web Base Path
${green}7.${plain} Reset Settings
${green}8.${plain} Change Port
${green}9.${plain} View Current Settings
————————————————
${green}9.${plain} Start
${green}10.${plain} Stop
${green}11.${plain} Restart
${green}12.${plain} Check Status
${green}13.${plain} Check Logs
${green}10.${plain} Start
${green}11.${plain} Stop
${green}12.${plain} Restart
${green}13.${plain} Check Status
${green}14.${plain} Check Logs
————————————————
${green}14.${plain} Enable Autostart
${green}15.${plain} Disable Autostart
${green}15.${plain} Enable Autostart
${green}16.${plain} Disable Autostart
————————————————
${green}16.${plain} SSL Certificate Management
${green}17.${plain} Cloudflare SSL Certificate
${green}18.${plain} IP Limit Management
${green}19.${plain} WARP Management
${green}20.${plain} Firewall Management
${green}17.${plain} SSL Certificate Management
${green}18.${plain} Cloudflare SSL Certificate
${green}19.${plain} IP Limit Management
${green}20.${plain} WARP Management
${green}21.${plain} Firewall Management
————————————————
${green}21.${plain} Enable BBR
${green}22.${plain} Update Geo Files
${green}23.${plain} Speedtest by Ookla
${green}22.${plain} Enable BBR
${green}23.${plain} Update Geo Files
${green}24.${plain} Speedtest by Ookla
"
show_status
echo && read -p "Please enter your selection [0-23]: " num
echo && read -p "Please enter your selection [0-24]: " num

case "${num}" in
0)
Expand All @@ -1328,61 +1354,64 @@ show_menu() {
check_install && reset_user
;;
6)
check_install && reset_config
check_install && reset_webbasepath
;;
7)
check_install && set_port
check_install && reset_config
;;
8)
check_install && check_config
check_install && set_port
;;
9)
check_install && start
check_install && check_config
;;
10)
check_install && stop
check_install && start
;;
11)
check_install && restart
check_install && stop
;;
12)
check_install && status
check_install && restart
;;
13)
check_install && show_log
check_install && status
;;
14)
check_install && enable
check_install && show_log
;;
15)
check_install && disable
check_install && enable
;;
16)
ssl_cert_issue_main
check_install && disable
;;
17)
ssl_cert_issue_CF
ssl_cert_issue_main
;;
18)
iplimit_main
ssl_cert_issue_CF
;;
19)
warp_cloudflare
iplimit_main
;;
20)
firewall_menu
warp_cloudflare
;;
21)
bbr_menu
firewall_menu
;;
22)
update_geo
bbr_menu
;;
23)
update_geo
;;
24)
run_speedtest
;;
*)
LOGE "Please enter the correct number [0-23]"
LOGE "Please enter the correct number [0-24]"
;;
esac
}
Expand Down

0 comments on commit f481ab9

Please sign in to comment.