Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions data/caddy/caddyfile-protected
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
https://$PANEL_DOMAIN {
handle /api/* {
reverse_proxy http://remnawave:$PANEL_PORT
}

handle {
basicauth {
$ADMIN_LOGIN $ADMIN_PASSWORD_HASH
}
reverse_proxy http://remnawave:$PANEL_PORT
}
}

:443 {
tls internal
respond 204
}
112 changes: 111 additions & 1 deletion scripts/remnawave/install-caddy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source "/opt/remnasetup/scripts/common/functions.sh"
source "/opt/remnasetup/scripts/common/languages.sh"

REINSTALL_CADDY=false
NEED_PROTECTION=false

check_component() {
if [ -f "/opt/remnawave/caddy/docker-compose.yml" ] || [ -f "/opt/remnawave/caddy/Caddyfile" ]; then
Expand Down Expand Up @@ -44,13 +45,101 @@ install_docker() {
fi
}

validate_password() {
local password="$1"
local prefix="$2"

if [[ ${#password} -lt 8 ]]; then
warn "$(get_string "${prefix}_password_short")"
return 1
fi
if ! [[ "$password" =~ [A-Z] ]]; then
warn "$(get_string "${prefix}_password_uppercase")"
return 1
fi
if ! [[ "$password" =~ [a-z] ]]; then
warn "$(get_string "${prefix}_password_lowercase")"
return 1
fi
if ! [[ "$password" =~ [0-9] ]]; then
warn "$(get_string "${prefix}_password_number")"
return 1
fi
if ! [[ "$password" =~ [^a-zA-Z0-9] ]]; then
warn "$(get_string "${prefix}_password_special")"
return 1
fi
return 0
}

request_protection_data() {
while true; do
question "$(get_string "install_caddy_need_protection")"
PROTECTION="$REPLY"
if [[ "$PROTECTION" == "y" || "$PROTECTION" == "Y" ]]; then
NEED_PROTECTION=true
break
elif [[ "$PROTECTION" == "n" || "$PROTECTION" == "N" ]]; then
NEED_PROTECTION=false
break
else
warn "$(get_string "install_caddy_please_enter_yn")"
fi
done

if [[ "$NEED_PROTECTION" == true ]]; then
while true; do
question "$(get_string "install_caddy_enter_login_route")"
LOGIN_ROUTE="$REPLY"
if [[ -n "$LOGIN_ROUTE" ]]; then
LOGIN_ROUTE="${LOGIN_ROUTE#/}"
break
fi
warn "$(get_string "install_caddy_login_route_empty")"
done

while true; do
question "$(get_string "install_caddy_enter_admin_login")"
ADMIN_LOGIN="$REPLY"
if [[ -n "$ADMIN_LOGIN" ]]; then
break
fi
warn "$(get_string "install_caddy_admin_login_empty")"
done

while true; do
question "$(get_string "install_caddy_enter_admin_password")"
ADMIN_PASSWORD="$REPLY"
if validate_password "$ADMIN_PASSWORD" "install_caddy"; then
break
fi
done
fi
}

install_caddy() {
if [ "$REINSTALL_CADDY" = true ]; then
info "$(get_string "install_caddy_installing")"
mkdir -p /opt/remnawave/caddy
cd /opt/remnawave/caddy

cp "/opt/remnasetup/data/caddy/caddyfile" Caddyfile
if [[ "$NEED_PROTECTION" == true ]]; then
cp "/opt/remnasetup/data/caddy/caddyfile-protected" Caddyfile

ADMIN_PASSWORD_HASH=$(docker run --rm caddy:2.9 caddy hash-password --plaintext "$ADMIN_PASSWORD" 2>/dev/null)
if [[ -z "$ADMIN_PASSWORD_HASH" ]]; then
error "Failed to generate password hash. Falling back to standard config."
cp "/opt/remnasetup/data/caddy/caddyfile" Caddyfile
NEED_PROTECTION=false
else
sed -i "s|\$LOGIN_ROUTE|$LOGIN_ROUTE|g" Caddyfile
sed -i "s|\$ADMIN_LOGIN|$ADMIN_LOGIN|g" Caddyfile
sed -i "s|\$ADMIN_PASSWORD_HASH|$ADMIN_PASSWORD_HASH|g" Caddyfile
fi
else
cp "/opt/remnasetup/data/caddy/caddyfile" Caddyfile
fi

cp "/opt/remnasetup/data/docker/caddy-compose.yml" docker-compose.yml

if [[ -n "$PANEL_DOMAIN" ]]; then
Expand Down Expand Up @@ -112,12 +201,33 @@ main() {
SUB_PORT=""
fi

if [[ -n "$PANEL_DOMAIN" ]]; then
request_protection_data
fi

if ! check_docker; then
install_docker
fi
install_caddy

success "$(get_string "install_caddy_complete")"

if [[ "$NEED_PROTECTION" == true ]]; then
echo ""
echo -e "${MAGENTA}────────────────────────────────────────────────────────────${RESET}"
if [ "$LANGUAGE" = "en" ]; then
echo -e "${BOLD_CYAN}Panel Protection Info${RESET}"
else
echo -e "${BOLD_CYAN}Информация о защите панели${RESET}"
fi
echo -e "${MAGENTA}────────────────────────────────────────────────────────────${RESET}"
echo -e "${BOLD_GREEN}URL:${RESET} ${BLUE}https://${PANEL_DOMAIN}/${LOGIN_ROUTE}${RESET}"
echo -e "${BOLD_GREEN}Login:${RESET} ${BLUE}${ADMIN_LOGIN}${RESET}"
echo -e "${BOLD_GREEN}Password:${RESET} ${BLUE}${ADMIN_PASSWORD}${RESET}"
echo -e "${MAGENTA}────────────────────────────────────────────────────────────${RESET}"
echo ""
fi

read -n 1 -s -r -p "$(get_string "install_caddy_press_key")"
exit 0
}
Expand Down
107 changes: 104 additions & 3 deletions scripts/remnawave/install-full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source "/opt/remnasetup/scripts/common/languages.sh"

REINSTALL_PANEL=false
REINSTALL_CADDY=false
NEED_PROTECTION=false

check_component() {
local component=$1
Expand Down Expand Up @@ -94,7 +95,77 @@ generate_login() {
tr -dc 'a-zA-Z' < /dev/urandom | head -c 15
}

validate_password() {
local password="$1"
local prefix="$2"

if [[ ${#password} -lt 8 ]]; then
warn "$(get_string "${prefix}_password_short")"
return 1
fi
if ! [[ "$password" =~ [A-Z] ]]; then
warn "$(get_string "${prefix}_password_uppercase")"
return 1
fi
if ! [[ "$password" =~ [a-z] ]]; then
warn "$(get_string "${prefix}_password_lowercase")"
return 1
fi
if ! [[ "$password" =~ [0-9] ]]; then
warn "$(get_string "${prefix}_password_number")"
return 1
fi
if ! [[ "$password" =~ [^a-zA-Z0-9] ]]; then
warn "$(get_string "${prefix}_password_special")"
return 1
fi
return 0
}

request_protection_data() {
while true; do
question "$(get_string "install_full_need_protection")"
PROTECTION="$REPLY"
if [[ "$PROTECTION" == "y" || "$PROTECTION" == "Y" ]]; then
NEED_PROTECTION=true
break
elif [[ "$PROTECTION" == "n" || "$PROTECTION" == "N" ]]; then
NEED_PROTECTION=false
break
else
warn "$(get_string "install_full_please_enter_yn")"
fi
done

if [[ "$NEED_PROTECTION" == true ]]; then
while true; do
question "$(get_string "install_full_enter_login_route")"
LOGIN_ROUTE="$REPLY"
if [[ -n "$LOGIN_ROUTE" ]]; then
LOGIN_ROUTE="${LOGIN_ROUTE#/}"
break
fi
warn "$(get_string "install_full_login_route_empty")"
done

while true; do
question "$(get_string "install_full_enter_admin_login")"
ADMIN_LOGIN="$REPLY"
if [[ -n "$ADMIN_LOGIN" ]]; then
break
fi
warn "$(get_string "install_full_admin_login_empty")"
done

while true; do
question "$(get_string "install_full_enter_admin_password")"
ADMIN_PASSWORD="$REPLY"
if validate_password "$ADMIN_PASSWORD" "install_full"; then
break
fi
done
fi
}

install_components() {
if [ "$REINSTALL_PANEL" = true ]; then
Expand Down Expand Up @@ -133,11 +204,31 @@ install_components() {
fi

if [ "$REINSTALL_CADDY" = true ]; then
info "$(get_string "install_full_installing_caddy")"
if [[ "$NEED_PROTECTION" == true ]]; then
info "$(get_string "install_full_installing_caddy_with_protection")"
else
info "$(get_string "install_full_installing_caddy")"
fi
mkdir -p /opt/remnawave/caddy
cd /opt/remnawave/caddy

cp "/opt/remnasetup/data/caddy/caddyfile" Caddyfile
if [[ "$NEED_PROTECTION" == true ]]; then
cp "/opt/remnasetup/data/caddy/caddyfile-protected" Caddyfile

ADMIN_PASSWORD_HASH=$(docker run --rm caddy:2.9 caddy hash-password --plaintext "$ADMIN_PASSWORD" 2>/dev/null)
if [[ -z "$ADMIN_PASSWORD_HASH" ]]; then
error "Failed to generate password hash. Falling back to standard config."
cp "/opt/remnasetup/data/caddy/caddyfile" Caddyfile
NEED_PROTECTION=false
else
sed -i "s|\$LOGIN_ROUTE|$LOGIN_ROUTE|g" Caddyfile
sed -i "s|\$ADMIN_LOGIN|$ADMIN_LOGIN|g" Caddyfile
sed -i "s|\$ADMIN_PASSWORD_HASH|$ADMIN_PASSWORD_HASH|g" Caddyfile
fi
else
cp "/opt/remnasetup/data/caddy/caddyfile" Caddyfile
fi

cp "/opt/remnasetup/data/docker/caddy-compose.yml" docker-compose.yml

sed -i "s|\$PANEL_DOMAIN|$PANEL_DOMAIN|g" Caddyfile
Expand Down Expand Up @@ -165,7 +256,13 @@ show_panel_info() {
echo -e "${BOLD_CYAN}$(get_string "install_full_panel_info_header")${RESET}"
echo -e "${MAGENTA}────────────────────────────────────────────────────────────${RESET}"

echo -e "${BOLD_GREEN}$(get_string "install_full_panel_url")${RESET} ${BLUE}https://${PANEL_DOMAIN}${RESET}"
if [[ "$NEED_PROTECTION" == true ]]; then
echo -e "${BOLD_GREEN}$(get_string "install_full_panel_url")${RESET} ${BLUE}https://${PANEL_DOMAIN}/${LOGIN_ROUTE}${RESET}"
echo -e "${BOLD_GREEN}Login:${RESET} ${BLUE}${ADMIN_LOGIN}${RESET}"
echo -e "${BOLD_GREEN}Password:${RESET} ${BLUE}${ADMIN_PASSWORD}${RESET}"
else
echo -e "${BOLD_GREEN}$(get_string "install_full_panel_url")${RESET} ${BLUE}https://${PANEL_DOMAIN}${RESET}"
fi


echo -e "${MAGENTA}────────────────────────────────────────────────────────────${RESET}"
Expand Down Expand Up @@ -204,6 +301,10 @@ main() {
PANEL_PORT="$REPLY"
PANEL_PORT=${PANEL_PORT:-3000}

if [ "$REINSTALL_CADDY" = true ]; then
request_protection_data
fi

if ! check_docker; then
install_docker
fi
Expand Down