Closed lubepi closed 3 years ago
I made a quick workaround just for the Sockets. In case someone needs it, just replace:
_check_net_status() {
local -r net_iface="${1}"
local -r server_ip="${2}"
local -r server_ip6="$(LC_ALL=C
ip -br -6 addr show dev "${net_iface}" |
awk '{sub(/\/[0-9]+/,"",$3); print $3}')"
local active=0
local -r empty="Found no active connections"
_log "INFO: Check connections for: ${net_iface}"
# For each socket see if it is stated active using ss command.
for nsocket in ${NSOCKETNUMBERS//,/ }; do
local lines; lines="$(LC_ALL=C
ss -n |
awk -v regex="^[[]?(::ffff:)?(${server_ip}|${server_ip6})[]]?:${nsocket}$" \
-v ignore_self="${NSOCKETIGNORESELF}" \
-v server_ip="${server_ip}" \
"(ignore_self == \"false\") ? \
\$2 ~ /^ESTAB$/ && \$5 ~ regex : \
\$2 ~ /^ESTAB$/ && \$5 ~ regex && \$6 !~ server_ip && \$6 !~ server_ip6")"
[ "${DEBUG}" == "true" ] &&
_log "DEBUG: Port ${nsocket}: ${lines:-"${empty}"}"
# No active connection found.
[ -z "${lines}" ] && continue
local no_lines; no_lines="$(wc -l <<< "${lines}")"
((active+="${no_lines}"))
local conips; conips="$(
awk '{gsub(/^([[]::ffff:)?/,"",$6);
gsub(/^([[])?/,"",$6);
gsub(/[]]?:[0-9]+$/,"",$6); print $6}' <<< "${lines}" |
sort -t . -k 3,3n -k 4,4n | uniq)"
# Set portprotocol - Only default ports are defined here.
local portprotocol
case "${nsocket}" in
80|8080) portprotocol="HTTP" ;;
22) portprotocol="SSH" ;;
21) portprotocol="FTP" ;;
139|445) portprotocol="SMB/CIFS" ;;
443) portprotocol="HTTPS" ;;
548) portprotocol="AFP" ;;
873) portprotocol="RSYNC" ;;
3306) portprotocol="MYSQL" ;;
3689) portprotocol="DAAP" ;;
6991) portprotocol="BITTORRENT" ;;
9091) portprotocol="BITTORRENT_WEBIF" ;;
32400) portprotocol="PLEXMEDIASERVER" ;;
49152) portprotocol="UPNP" ;;
51413) portprotocol="BITTORRENT" ;;
*) portprotocol="unknown" ;;
esac
_log "INFO: Found ${no_lines} active connection on port ${nsocket} (${portprotocol}) from: ${conips//$'\n'/, }"
done
_log "INFO: Found ${active} active socket(s) on ${net_iface}, from port(s): ${NSOCKETNUMBERS}"
# Return the number of active sockets found.
return "${active}"
}
@lubepi would it be possible for you to test: https://github.com/OpenMediaVault-Plugin-Developers/openmediavault-autoshutdown/pull/96
Is there no Support for IPv6? If I ssh over IPv6 it says "Found 0 active Sockets ..." in the log files. But if I ssh over IPv4 it says "Found 1 active Socket".