bash - Default credentials detected. Security update required

This commit is contained in:
mhsanaei 2024-10-24 21:17:00 +02:00
parent bd6402562e
commit 14435db0d8
No known key found for this signature in database
GPG key ID: 4DACC0663B5986F5

View file

@ -139,26 +139,32 @@ gen_random_string() {
}
config_after_install() {
local goto_custom_settings=false
local existing_username=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'username: .+' | awk '{print $2}')
local existing_password=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'password: .+' | awk '{print $2}')
local existing_webBasePath=$(/usr/local/x-ui/x-ui setting -show true | grep -Eo 'webBasePath: .+' | awk '{print $2}')
# Check if username and password exist
if [[ -n "$existing_username" && -n "$existing_password" ]]; then
# If webBasePath is missing, generate a new one
if [[ ${#existing_webBasePath} -lt 4 ]]; then
if [[ "$existing_username" == "admin" && "$existing_password" == "admin" ]]; then
echo -e "${yellow}Default credentials detected. Security update required...${plain}"
goto_custom_settings=true
elif [[ ${#existing_webBasePath} -lt 4 ]]; then
local config_webBasePath=$(gen_random_string 15)
echo -e "${yellow}WebBasePath is missing or too short. Generating a new one...${plain}"
/usr/local/x-ui/x-ui setting -webBasePath "${config_webBasePath}"
echo -e "${green}New WebBasePath: ${config_webBasePath}${plain}"
/usr/local/x-ui/x-ui migrate
return 0
else
echo -e "${green}Username, Password, and WebBasePath are already set. Exiting...${plain}"
fi
echo -e "${green}Username, Password, and WebBasePath are properly set. Exiting...${plain}"
/usr/local/x-ui/x-ui migrate
return 0
fi
else
goto_custom_settings=true
fi
if [[ "$goto_custom_settings" == "true" ]]; then
read -p "Would you like to customize the Panel Port settings? (If not, random settings will be applied) [y/n]: " config_confirm
local config_webBasePath=$(gen_random_string 15)
@ -201,7 +207,7 @@ config_after_install() {
echo -e "${yellow}If you forgot your login info, you can type 'x-ui settings' to check after installation${plain}"
else
echo -e "${yellow}This is your upgrade, keeping old settings. If you forgot your login info, you can type 'x-ui settings' to check${plain}"
fi
fi
fi