From 533e79ba959143f0459431a486bfb85c56c72ddc Mon Sep 17 00:00:00 2001 From: luisgulo Date: Fri, 24 Oct 2025 18:01:10 +0200 Subject: Releasing code version 1.8.0 --- community_modules/winremote/winremote_detect.sh | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 community_modules/winremote/winremote_detect.sh (limited to 'community_modules/winremote/winremote_detect.sh') diff --git a/community_modules/winremote/winremote_detect.sh b/community_modules/winremote/winremote_detect.sh new file mode 100644 index 0000000..4477acd --- /dev/null +++ b/community_modules/winremote/winremote_detect.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# Module: winremote_detect +# Description: Detecta si un host Windows tiene habilitado SSH, WinRM, ambos o ninguno +# License: GPLv3 +# Author: Luis GuLo +# Version: 1.2.0 +# Dependencies: nc, curl, pwsh (opcional) + +winremote_detect_task() { + local host="$1"; shift + declare -A args + for arg in "$@"; do key="${arg%%=*}"; value="${arg#*=}"; args["$key"]="$value"; done + + local ssh_port="${args[ssh_port]:-22}" + local winrm_port="${args[winrm_port]:-5985}" + + # 🌐 Cargar traducciones + local lang="${shflow_vars[language]:-es}" + local trfile="$(dirname "${BASH_SOURCE[0]}")/winremote_detect.tr.${lang}" + declare -A tr + if [[ -f "$trfile" ]]; then while IFS='=' read -r k v; do tr["$k"]="$v"; done < "$trfile"; fi + + [[ "$host" == *@* ]] && host=$(echo "$host" | awk -F '@' '{print $2}') + + echo "$(render_msg "${tr[start]}" "host=$host")" + + local ssh_status="${tr[ssh_off]:-❌ SSH no disponible}" + local winrm_status="${tr[winrm_off]:-❌ WinRM no disponible}" + + if nc -z -w2 "$host" "$ssh_port" &>/dev/null; then + ssh_status="$(render_msg "${tr[ssh_on]}" "port=$ssh_port")" + fi + + if curl -s -o /dev/null -w "%{http_code}" --connect-timeout 2 "http://$host:$winrm_port/wsman" | grep -q "405"; then + winrm_status="$(render_msg "${tr[winrm_on]}" "port=$winrm_port")" + fi + + echo " $ssh_status" + echo " $winrm_status" + + if [[ "$ssh_status" == *βœ…* && "$winrm_status" == *βœ…* ]]; then + echo "$(render_msg "${tr[both]}" "host=$host")" + return 0 + elif [[ "$ssh_status" == *βœ…* || "$winrm_status" == *βœ…* ]]; then + echo "${tr[one]:-🟑 Uno de los protocolos estΓ‘ disponible}" + return 0 + else + echo "$(render_msg "${tr[none]}" "host=$host")" + return 1 + fi +} + +check_dependencies_winremote_detect() { + local lang="${shflow_vars[language]:-es}" + local trfile="$(dirname "${BASH_SOURCE[0]}")/winremote_detect.tr.${lang}" + declare -A tr + if [[ -f "$trfile" ]]; then while IFS='=' read -r k v; do tr["$k"]="$v"; done < "$trfile"; fi + + if ! command -v nc &> /dev/null || ! command -v curl &> /dev/null; then + echo "${tr[missing_deps]:-❌ [winremote_detect] nc o curl no estΓ‘n disponibles.}" + return 1 + fi + echo "${tr[deps_ok]:-βœ… [winremote_detect] nc y curl disponibles.}" + return 0 +} -- cgit v1.2.3