diff --git a/install_ssh_tunnel.sh b/install_ssh_tunnel.sh index 082f488..ea5fe02 100644 --- a/install_ssh_tunnel.sh +++ b/install_ssh_tunnel.sh @@ -762,13 +762,15 @@ manage_tunnels() { count=0 declare -A tunnels - for conf in /etc/ssh_tunnel/*.conf 2>/dev/null; do - if [ -f "$conf" ]; then - ((count++)) - tunnels[$count]="$conf" - tunnel_name=$(basename "$conf" .conf) - echo -e "${CYAN}[$count]${NC} $tunnel_name" + # Исправленный цикл без синтаксической ошибки + for conf in /etc/ssh_tunnel/*.conf; do + if [ ! -f "$conf" ]; then + continue fi + ((count++)) + tunnels[$count]="$conf" + tunnel_name=$(basename "$conf" .conf) + echo -e "${CYAN}[$count]${NC} $tunnel_name" done if [ $count -eq 0 ]; then @@ -793,12 +795,13 @@ manage_tunnels() { ;; r|R) echo -e "${CYAN}Перезапуск всех туннелей...${NC}" - for conf in /etc/ssh_tunnel/*.conf 2>/dev/null; do - if [ -f "$conf" ]; then - tunnel_name=$(basename "$conf" .conf) - systemctl restart "ssh-tunnel-${tunnel_name}.service" 2>/dev/null - echo -e " ${GREEN}✓${NC} $tunnel_name перезапущен" + for conf in /etc/ssh_tunnel/*.conf; do + if [ ! -f "$conf" ]; then + continue fi + tunnel_name=$(basename "$conf" .conf) + systemctl restart "ssh-tunnel-${tunnel_name}.service" 2>/dev/null + echo -e " ${GREEN}✓${NC} $tunnel_name перезапущен" done read -p "Нажмите Enter для продолжения..." ;; @@ -917,24 +920,26 @@ setup_autostart() { case $action in 1) - for conf in /etc/ssh_tunnel/*.conf 2>/dev/null; do - if [ -f "$conf" ]; then - tunnel_name=$(basename "$conf" .conf) - systemctl enable "ssh-tunnel-${tunnel_name}.service" 2>/dev/null && \ - echo -e "${GREEN}✓ Автозапуск включен для $tunnel_name${NC}" || \ - echo -e "${RED}✗ Ошибка для $tunnel_name${NC}" + for conf in /etc/ssh_tunnel/*.conf; do + if [ ! -f "$conf" ]; then + continue fi + tunnel_name=$(basename "$conf" .conf) + systemctl enable "ssh-tunnel-${tunnel_name}.service" 2>/dev/null && \ + echo -e "${GREEN}✓ Автозапуск включен для $tunnel_name${NC}" || \ + echo -e "${RED}✗ Ошибка для $tunnel_name${NC}" done read -p "Нажмите Enter для продолжения..." ;; 2) - for conf in /etc/ssh_tunnel/*.conf 2>/dev/null; do - if [ -f "$conf" ]; then - tunnel_name=$(basename "$conf" .conf) - systemctl disable "ssh-tunnel-${tunnel_name}.service" 2>/dev/null && \ - echo -e "${YELLOW}✗ Автозапуск выключен для $tunnel_name${NC}" || \ - echo -e "${RED}✗ Ошибка для $tunnel_name${NC}" + for conf in /etc/ssh_tunnel/*.conf; do + if [ ! -f "$conf" ]; then + continue fi + tunnel_name=$(basename "$conf" .conf) + systemctl disable "ssh-tunnel-${tunnel_name}.service" 2>/dev/null && \ + echo -e "${YELLOW}✗ Автозапуск выключен для $tunnel_name${NC}" || \ + echo -e "${RED}✗ Ошибка для $tunnel_name${NC}" done read -p "Нажмите Enter для продолжения..." ;; @@ -975,7 +980,10 @@ view_logs() { case $choice in 1) echo -e "${CYAN}Доступные логи:${NC}" - ls $LOG_DIR/*.log 2>/dev/null | while read log; do + for log in $LOG_DIR/*.log; do + if [ ! -f "$log" ]; then + continue + fi echo " $(basename $log)" done echo "" @@ -989,11 +997,12 @@ view_logs() { ;; 2) echo -e "${CYAN}Все логи туннелей:${NC}" - for log in $LOG_DIR/*.log 2>/dev/null; do - if [ -f "$log" ]; then - echo -e "\n${YELLOW}=== $(basename $log) ===${NC}" - tail -5 "$log" + for log in $LOG_DIR/*.log; do + if [ ! -f "$log" ]; then + continue fi + echo -e "\n${YELLOW}=== $(basename $log) ===${NC}" + tail -5 "$log" done read -p "Нажмите Enter для продолжения..." ;; @@ -1044,16 +1053,17 @@ test_connections() { ;; 2) echo -e "${CYAN}Тест портов туннелей:${NC}" - for conf in /etc/ssh_tunnel/*.conf 2>/dev/null; do - if [ -f "$conf" ]; then - source "$conf" 2>/dev/null - tunnel_name=$(basename "$conf" .conf) - echo -n " $tunnel_name (локальный $LOCAL_PORT): " - if timeout 2 nc -z localhost "$LOCAL_PORT" 2>/dev/null; then - echo -e "${GREEN}✓ Открыт${NC}" - else - echo -e "${RED}✗ Закрыт${NC}" - fi + for conf in /etc/ssh_tunnel/*.conf; do + if [ ! -f "$conf" ]; then + continue + fi + source "$conf" 2>/dev/null + tunnel_name=$(basename "$conf" .conf) + echo -n " $tunnel_name (локальный $LOCAL_PORT): " + if timeout 2 nc -z localhost "$LOCAL_PORT" 2>/dev/null; then + echo -e "${GREEN}✓ Открыт${NC}" + else + echo -e "${RED}✗ Закрыт${NC}" fi done ;;