mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-23 21:30:17 +00:00
Use ss instead of lsof (#4518)
* Use ss instead of lsof for pihole status checks Signed-off-by: DL6ER <dl6er@dl6er.de> * Use ss FILTER instead of piping into bash Signed-off-by: DL6ER <dl6er@dl6er.de> * Use ss in debug log generation Signed-off-by: DL6ER <dl6er@dl6er.de> * Remove lsof from dependencies Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
7807a93e10
commit
5823f5e254
3 changed files with 21 additions and 23 deletions
|
@ -733,11 +733,11 @@ compare_port_to_service_assigned() {
|
|||
|
||||
# If the service is a Pi-hole service, highlight it in green
|
||||
if [[ "${service_name}" == "${expected_service}" ]]; then
|
||||
log_write "[${COL_GREEN}${port}${COL_NC}] is in use by ${COL_GREEN}${service_name}${COL_NC}"
|
||||
log_write "${TICK} ${COL_GREEN}${port}${COL_NC} is in use by ${COL_GREEN}${service_name}${COL_NC}"
|
||||
# Otherwise,
|
||||
else
|
||||
# Show the service name in red since it's non-standard
|
||||
log_write "[${COL_RED}${port}${COL_NC}] is in use by ${COL_RED}${service_name}${COL_NC} (${FAQ_HARDWARE_REQUIREMENTS_PORTS})"
|
||||
log_write "${CROSS} ${COL_RED}${port}${COL_NC} is in use by ${COL_RED}${service_name}${COL_NC} (${FAQ_HARDWARE_REQUIREMENTS_PORTS})"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -753,32 +753,28 @@ check_required_ports() {
|
|||
# Sort the addresses and remove duplicates
|
||||
while IFS= read -r line; do
|
||||
ports_in_use+=( "$line" )
|
||||
done < <( lsof -iTCP -sTCP:LISTEN -P -n +c 10 )
|
||||
done < <( ss --listening --numeric --tcp --udp --processes --oneline --no-header )
|
||||
|
||||
# Now that we have the values stored,
|
||||
for i in "${!ports_in_use[@]}"; do
|
||||
# loop through them and assign some local variables
|
||||
local service_name
|
||||
service_name=$(echo "${ports_in_use[$i]}" | awk '{print $1}')
|
||||
service_name=$(echo "${ports_in_use[$i]}" | awk '{gsub(/users:\(\("/,"",$7);gsub(/".*/,"",$7);print $7}')
|
||||
local protocol_type
|
||||
protocol_type=$(echo "${ports_in_use[$i]}" | awk '{print $5}')
|
||||
protocol_type=$(echo "${ports_in_use[$i]}" | awk '{print $1}')
|
||||
local port_number
|
||||
port_number="$(echo "${ports_in_use[$i]}" | awk '{print $9}')"
|
||||
port_number="$(echo "${ports_in_use[$i]}" | awk '{print $5}')" # | awk '{gsub(/^.*:/,"",$5);print $5}')
|
||||
|
||||
# Skip the line if it's the titles of the columns the lsof command produces
|
||||
if [[ "${service_name}" == COMMAND ]]; then
|
||||
continue
|
||||
fi
|
||||
# Use a case statement to determine if the right services are using the right ports
|
||||
case "$(echo "$port_number" | rev | cut -d: -f1 | rev)" in
|
||||
53) compare_port_to_service_assigned "${resolver}" "${service_name}" 53
|
||||
case "$(echo "${port_number}" | rev | cut -d: -f1 | rev)" in
|
||||
53) compare_port_to_service_assigned "${resolver}" "${service_name}" "${protocol_type}:${port_number}"
|
||||
;;
|
||||
80) compare_port_to_service_assigned "${web_server}" "${service_name}" 80
|
||||
80) compare_port_to_service_assigned "${web_server}" "${service_name}" "${protocol_type}:${port_number}"
|
||||
;;
|
||||
4711) compare_port_to_service_assigned "${ftl}" "${service_name}" 4711
|
||||
4711) compare_port_to_service_assigned "${ftl}" "${service_name}" "${protocol_type}:${port_number}"
|
||||
;;
|
||||
# If it's not a default port that Pi-hole needs, just print it out for the user to see
|
||||
*) log_write "${port_number} ${service_name} (${protocol_type})";
|
||||
*) log_write " ${protocol_type}:${port_number} is in use by ${service_name:=<unknown>}";
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ package_manager_detect() {
|
|||
# Packages required to run this install script (stored as an array)
|
||||
INSTALLER_DEPS=(git iproute2 whiptail ca-certificates)
|
||||
# Packages required to run Pi-hole (stored as an array)
|
||||
PIHOLE_DEPS=(cron curl iputils-ping lsof psmisc sudo unzip idn2 sqlite3 libcap2-bin dns-root-data libcap2 netcat)
|
||||
PIHOLE_DEPS=(cron curl iputils-ping psmisc sudo unzip idn2 sqlite3 libcap2-bin dns-root-data libcap2 netcat)
|
||||
# Packages required for the Web admin interface (stored as an array)
|
||||
# It's useful to separate this from Pi-hole, since the two repos are also setup separately
|
||||
PIHOLE_WEB_DEPS=(lighttpd "${phpVer}-common" "${phpVer}-cgi" "${phpVer}-sqlite3" "${phpVer}-xml" "${phpVer}-intl")
|
||||
|
@ -332,7 +332,7 @@ package_manager_detect() {
|
|||
PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l"
|
||||
OS_CHECK_DEPS=(grep bind-utils)
|
||||
INSTALLER_DEPS=(git iproute newt procps-ng which chkconfig ca-certificates)
|
||||
PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc sqlite libcap lsof nmap-ncat)
|
||||
PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc sqlite libcap nmap-ncat)
|
||||
PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php-common php-cli php-pdo php-xml php-json php-intl)
|
||||
LIGHTTPD_USER="lighttpd"
|
||||
LIGHTTPD_GROUP="lighttpd"
|
||||
|
|
14
pihole
14
pihole
|
@ -283,26 +283,29 @@ Options:
|
|||
}
|
||||
|
||||
analyze_ports() {
|
||||
local lv4 lv6 port=${1}
|
||||
# FTL is listening at least on at least one port when this
|
||||
# function is getting called
|
||||
# Check individual address family/protocol combinations
|
||||
# For a healthy Pi-hole, they should all be up (nothing printed)
|
||||
if grep -q "IPv4.*UDP" <<< "${1}"; then
|
||||
lv4="$(ss --ipv4 --listening --numeric --tcp --udp src :${port})"
|
||||
if grep -q "udp " <<< "${lv4}"; then
|
||||
echo -e " ${TICK} UDP (IPv4)"
|
||||
else
|
||||
echo -e " ${CROSS} UDP (IPv4)"
|
||||
fi
|
||||
if grep -q "IPv4.*TCP" <<< "${1}"; then
|
||||
if grep -q "tcp " <<< "${lv4}"; then
|
||||
echo -e " ${TICK} TCP (IPv4)"
|
||||
else
|
||||
echo -e " ${CROSS} TCP (IPv4)"
|
||||
fi
|
||||
if grep -q "IPv6.*UDP" <<< "${1}"; then
|
||||
lv6="$(ss --ipv6 --listening --numeric --tcp --udp src :${port})"
|
||||
if grep -q "udp " <<< "${lv6}"; then
|
||||
echo -e " ${TICK} UDP (IPv6)"
|
||||
else
|
||||
echo -e " ${CROSS} UDP (IPv6)"
|
||||
fi
|
||||
if grep -q "IPv6.*TCP" <<< "${1}"; then
|
||||
if grep -q "tcp " <<< "${lv6}"; then
|
||||
echo -e " ${TICK} TCP (IPv6)"
|
||||
else
|
||||
echo -e " ${CROSS} TCP (IPv6)"
|
||||
|
@ -324,7 +327,6 @@ statusFunc() {
|
|||
else
|
||||
#get the port pihole-FTL is listening on by using FTL's telnet API
|
||||
port="$(echo ">dns-port >quit" | nc 127.0.0.1 4711)"
|
||||
listening="$(lsof -Pni:${port})"
|
||||
if [[ "${port}" == "0" ]]; then
|
||||
case "${1}" in
|
||||
"web") echo "-1";;
|
||||
|
@ -334,7 +336,7 @@ statusFunc() {
|
|||
else
|
||||
if [[ "${1}" != "web" ]]; then
|
||||
echo -e " ${TICK} FTL is listening on port ${port}"
|
||||
analyze_ports "${listening}"
|
||||
analyze_ports "${port}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue