From 34047162d8b4dda5c1443fe5720183e4a80a5d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 5 Jan 2023 19:55:55 +0100 Subject: [PATCH 01/10] Tweak visuals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- padd.sh | 133 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 99 insertions(+), 34 deletions(-) diff --git a/padd.sh b/padd.sh index 9a1db47b..9fd3076d 100755 --- a/padd.sh +++ b/padd.sh @@ -146,17 +146,16 @@ GetSummaryInformation() { cache_deletes=$(echo "$cache_info" | grep "cache-live-freed" | grep -Eo "[0-9.]+$") cache_inserts=$(echo "$cache_info"| grep "cache-inserted" | grep -Eo "[0-9.]+$") - latest_blocked=$(GetFTLData recentBlocked) + latest_blocked_raw=$(GetFTLData recentBlocked) - top_blocked=$(GetFTLData "top-ads (1)" | awk '{print $3}') + top_blocked_raw=$(GetFTLData "top-ads (1)" | awk '{print $3}') - top_domain=$(GetFTLData "top-domains (1)" | awk '{print $3}') + top_domain_raw=$(GetFTLData "top-domains (1)" | awk '{print $3}') top_client_raw=$(GetFTLData "top-clients (1)" | awk '{print $4}') if [ -z "${top_client_raw}" ]; then - top_client=$(GetFTLData "top-clients (1)" | awk '{print $3}') - else - top_client="${top_client_raw}" + # if no hostname was supplied, use IP + top_client_raw=$(GetFTLData "top-clients (1)" | awk '{print $3}') fi } @@ -572,40 +571,106 @@ GetPADDInformation() { } GenerateSizeDependendOutput() { - if [ "$1" = "pico" ] || [ "$1" = "nano" ] || [ "$1" = "micro" ]; then + if [ "$1" = "pico" ] || [ "$1" = "nano" ]; then + ads_blocked_bar=$(BarGenerator "$ads_percentage_today" 9 "color") + + elif [ "$1" = "micro" ]; then ads_blocked_bar=$(BarGenerator "$ads_percentage_today" 10 "color") + elif [ "$1" = "mini" ]; then ads_blocked_bar=$(BarGenerator "$ads_percentage_today" 20 "color") - if [ ${#latest_blocked} -gt 30 ]; then - latest_blocked=$(echo "$latest_blocked" | cut -c1-27)"..." + if [ ${#latest_blocked_raw} -gt 29 ]; then + latest_blocked=$(echo "$latest_blocked_raw" | cut -c1-26)"..." + else + latest_blocked=${latest_blocked_raw} fi - if [ ${#top_blocked} -gt 30 ]; then - top_blocked=$(echo "$top_blocked" | cut -c1-27)"..." + if [ ${#top_blocked_raw} -gt 29 ]; then + top_blocked=$(echo "$top_blocked_raw" | cut -c1-26)"..." + else + top_blocked=${top_blocked_raw} fi + elif [ "$1" = "tiny" ]; then ads_blocked_bar=$(BarGenerator "$ads_percentage_today" 30 "color") - if [ ${#latest_blocked} -gt 38 ]; then - latest_blocked=$(echo "$latest_blocked" | cut -c1-38)"..." + if [ ${#latest_blocked_raw} -gt 41 ]; then + latest_blocked=$(echo "$latest_blocked_raw" | cut -c1-38)"..." + else + latest_blocked=${latest_blocked_raw} fi - if [ ${#top_blocked} -gt 38 ]; then - top_blocked=$(echo "$top_blocked" | cut -c1-38)"..." + if [ ${#top_blocked_raw} -gt 41 ]; then + top_blocked=$(echo "$top_blocked_raw" | cut -c1-38)"..." + else + top_blocked=${top_blocked_raw} fi - if [ ${#top_domain} -gt 38 ]; then - top_domain=$(echo "$top_domain" | cut -c1-38)"..." + if [ ${#top_domain_raw} -gt 41 ]; then + top_domain=$(echo "$top_domain_raw" | cut -c1-38)"..." + else + top_domain=${top_domain_raw} fi - if [ ${#top_client} -gt 38 ]; then - top_client=$(echo "$top_client" | cut -c1-38)"..." + if [ ${#top_client_raw} -gt 41 ]; then + top_client=$(echo "$top_client_raw" | cut -c1-38)"..." + else + top_client=${top_client_raw} fi + elif [ "$1" = "regular" ] || [ "$1" = "slim" ]; then ads_blocked_bar=$(BarGenerator "$ads_percentage_today" 40 "color") - else + + if [ ${#latest_blocked_raw} -gt 48 ]; then + latest_blocked=$(echo "$latest_blocked_raw" | cut -c1-45)"..." + else + latest_blocked=${latest_blocked_raw} + fi + + if [ ${#top_blocked_raw} -gt 48 ]; then + top_blocked=$(echo "$top_blocked_raw" | cut -c1-45)"..." + else + top_blocked=${top_blocked_raw} + fi + + if [ ${#top_domain_raw} -gt 48 ]; then + top_domain=$(echo "$top_domain_raw" | cut -c1-45)"..." + else + top_domain=${top_domain_raw} + fi + + if [ ${#top_client_raw} -gt 48 ]; then + top_client=$(echo "$top_client_raw" | cut -c1-45)"..." + else + top_client=${top_client_raw} + fi + + elif [ "$1" = "mega" ]; then ads_blocked_bar=$(BarGenerator "$ads_percentage_today" 30 "color") + if [ ${#latest_blocked_raw} -gt 68 ]; then + latest_blocked=$(echo "$latest_blocked_raw" | cut -c1-65)"..." + else + latest_blocked=${latest_blocked_raw} + fi + + if [ ${#top_blocked_raw} -gt 68 ]; then + top_blocked=$(echo "$top_blocked_raw" | cut -c1-65)"..." + else + top_blocked=${top_blocked_raw} + fi + + if [ ${#top_domain_raw} -gt 68 ]; then + top_domain=$(echo "$top_domain_raw" | cut -c1-65)"..." + else + top_domain=${top_domain_raw} + fi + + if [ ${#top_client_raw} -gt 68 ]; then + top_client=$(echo "$top_client_raw" | cut -c1-65)"..." + else + top_client=${top_client_raw} + fi fi # System uptime @@ -751,7 +816,7 @@ PrintDashboard() { # nano is a screen at least 24x12 (columns x lines) moveXOffset; printf "%s${clear_line}\n" "n${padd_text} ${mini_status}" moveXOffset; printf "%s${clear_line}\n" "${bold_text}PI-HOLE ================${reset_text}" - moveXOffset; printf "%s${clear_line}\n" " DNS: ${dns_check_box} FTL: ${ftl_check_box}" + moveXOffset; printf "%s${clear_line}\n" " DNS: ${dns_check_box} FTL: ${ftl_check_box}" moveXOffset; printf "%s${clear_line}\n" " Blk: [${ads_blocked_bar}] ${ads_percentage_today}%" moveXOffset; printf "%s${clear_line}\n" " Blk: ${ads_blocked_today} / ${dns_queries_today}" moveXOffset; printf "%s${clear_line}\n" "${bold_text}NETWORK ================${reset_text}" @@ -808,9 +873,9 @@ PrintDashboard() { # tiny is a screen at least 53x20 (columns x lines) moveXOffset; printf "%s${clear_line}\n" "${padd_text}${dim_text}tiny${reset_text} Pi-hole® ${core_version_heatmap}${CORE_VERSION}${reset_text}, Web ${web_version_heatmap}${WEB_VERSION}${reset_text}, FTL ${ftl_version_heatmap}${FTL_VERSION}${reset_text}" moveXOffset; printf "%s${clear_line}\n" " PADD ${padd_version_heatmap}${padd_version}${reset_text} ${tiny_status}${reset_text}" - moveXOffset; printf "%s${clear_line}\n" "${bold_text}PI-HOLE ============================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}PI-HOLE =============================================${reset_text}" moveXOffset; printf " %-10s${dns_heatmap}%-16s${reset_text} %-8s${ftl_heatmap}%-10s${reset_text}${clear_line}\n" "DNS:" "${dns_status}" "FTL:" "${ftl_status}" - moveXOffset; printf "%s${clear_line}\n" "${bold_text}STATS ==============================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}STATS ===============================================${reset_text}" moveXOffset; printf " %-10s%-29s${clear_line}\n" "Blocking:" "${domains_being_blocked} domains" moveXOffset; printf " %-10s[%-30s] %-5s${clear_line}\n" "Pi-holed:" "${ads_blocked_bar}" "${ads_percentage_today}%" moveXOffset; printf " %-10s%-39s${clear_line}\n" "Pi-holed:" "${ads_blocked_today} out of ${dns_queries_today}" @@ -820,7 +885,7 @@ PrintDashboard() { moveXOffset; printf " %-10s%-39s${clear_line}\n" "Top Dmn:" "${top_domain}" moveXOffset; printf " %-10s%-39s${clear_line}\n" "Top Clnt:" "${top_client}" fi - moveXOffset; printf "%s${clear_line}\n" "${bold_text}NETWORK ============================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}NETWORK =============================================${reset_text}" moveXOffset; printf " %-10s%-16s %-8s%-16s${clear_line}\n" "Hostname:" "${full_hostname}" "IP: " "${pi_ip4_addr}" moveXOffset; printf " %-10s%-16s %-4s%-7s %-4s%-5s${clear_line}\n" "Interfce:" "${iface_name}" "TX:" "${tx_bytes}" "RX:" "${rx_bytes}" moveXOffset; printf " %-10s%-16s %-8s${dnssec_heatmap}%-16s${reset_text}${clear_line}\n" "DNS:" "${dns_information}" "DNSSEC:" "${dnssec_status}" @@ -828,7 +893,7 @@ PrintDashboard() { moveXOffset; printf " %-10s${dhcp_heatmap}%-16s${reset_text} %-8s${dhcp_ipv6_heatmap}%-10s${reset_text}${clear_line}\n" "DHCP:" "${dhcp_status}" "IPv6:" ${dhcp_ipv6_status} moveXOffset; printf "%s${clear_line}\n" "${dhcp_info}" fi - moveXOffset; printf "%s${clear_line}\n" "${bold_text}SYSTEM =============================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}SYSTEM ==============================================${reset_text}" moveXOffset; printf " %-10s%-29s${clear_line}\n" "Uptime:" "${system_uptime}" moveXOffset; printf " %-10s${temp_heatmap}%-17s${reset_text} %-8s${cpu_load_1_heatmap}%-4s${reset_text}, ${cpu_load_5_heatmap}%-4s${reset_text}, ${cpu_load_15_heatmap}%-4s${reset_text}${clear_line}\n" "CPU Temp:" "${temperature}" "Load:" "${cpu_load_1}" "${cpu_load_5}" "${cpu_load_15}" moveXOffset; printf " %-10s[${memory_heatmap}%-7s${reset_text}] %-6s %-8s[${cpu_load_1_heatmap}%-7s${reset_text}] %-5s${clear_line}" "Memory:" "${memory_bar}" "${memory_percent}%" "CPU:" "${cpu_bar}" "${cpu_percent}%" @@ -845,9 +910,9 @@ PrintDashboard() { moveXOffset; printf "%s${clear_line}\n" "${padd_logo_3}PADD ${padd_version_heatmap}${padd_version}${reset_text} ${full_status}${reset_text}" moveXOffset; printf "%s${clear_line}\n" "" fi - moveXOffset; printf "%s${clear_line}\n" "${bold_text}PI-HOLE ===================================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}PI-HOLE ====================================================${reset_text}" moveXOffset; printf " %-10s${dns_heatmap}%-19s${reset_text} %-10s${ftl_heatmap}%-19s${reset_text}${clear_line}\n" "DNS:" "${dns_status}" "FTL:" "${ftl_status}" - moveXOffset; printf "%s${clear_line}\n" "${bold_text}STATS =====================================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}STATS ======================================================${reset_text}" moveXOffset; printf " %-10s%-49s${clear_line}\n" "Blocking:" "${domains_being_blocked} domains" moveXOffset; printf " %-10s[%-40s] %-5s${clear_line}\n" "Pi-holed:" "${ads_blocked_bar}" "${ads_percentage_today}%" moveXOffset; printf " %-10s%-49s${clear_line}\n" "Pi-holed:" "${ads_blocked_today} out of ${dns_queries_today} queries" @@ -857,7 +922,7 @@ PrintDashboard() { moveXOffset; printf " %-10s%-39s${clear_line}\n" "Top Dmn:" "${top_domain}" moveXOffset; printf " %-10s%-39s${clear_line}\n" "Top Clnt:" "${top_client}" fi - moveXOffset; printf "%s${clear_line}\n" "${bold_text}NETWORK ===================================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}NETWORK ====================================================${reset_text}" moveXOffset; printf " %-10s%-15s %-4s%-17s%-6s%s${clear_line}\n" "Hostname:" "${full_hostname}" "IP:" "${pi_ip4_addr}" "IPv6:" "${ipv6_check_box}" moveXOffset; printf " %-10s%-15s %-4s%-17s%-4s%s${clear_line}\n" "Interfce:" "${iface_name}" "TX:" "${tx_bytes}" "RX:" "${rx_bytes}" moveXOffset; printf " %-10s%-15s %-10s${dnssec_heatmap}%-19s${reset_text}${clear_line}\n" "DNS:" "${dns_information}" "DNSSEC:" "${dnssec_status}" @@ -865,7 +930,7 @@ PrintDashboard() { moveXOffset; printf " %-10s${dhcp_heatmap}%-15s${reset_text} %-10s${dhcp_ipv6_heatmap}%-19s${reset_text}${clear_line}\n" "DHCP:" "${dhcp_status}" "IPv6:" ${dhcp_ipv6_status} moveXOffset; printf "%s${clear_line}\n" "${dhcp_info}" fi - moveXOffset; printf "%s${clear_line}\n" "${bold_text}SYSTEM ====================================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}SYSTEM =====================================================${reset_text}" moveXOffset; printf " %-10s%-39s${clear_line}\n" "Uptime:" "${system_uptime}" moveXOffset; printf " %-10s${temp_heatmap}%-21s${reset_text}%-10s${cpu_load_1_heatmap}%-4s${reset_text}, ${cpu_load_5_heatmap}%-4s${reset_text}, ${cpu_load_15_heatmap}%-4s${reset_text}${clear_line}\n" "CPU Temp:" "${temperature}" "CPU Load:" "${cpu_load_1}" "${cpu_load_5}" "${cpu_load_15}" moveXOffset; printf " %-10s[${memory_heatmap}%-10s${reset_text}] %-6s %-10s[${cpu_load_1_heatmap}%-10s${reset_text}] %-5s${clear_line}" "Memory:" "${memory_bar}" "${memory_percent}%" "CPU Load:" "${cpu_bar}" "${cpu_percent}%" @@ -875,25 +940,25 @@ PrintDashboard() { moveXOffset; printf "%s${clear_line}\n" "${padd_logo_retro_2} Pi-hole® ${core_version_heatmap}${CORE_VERSION}${reset_text}, Web ${web_version_heatmap}${WEB_VERSION}${reset_text}, FTL ${ftl_version_heatmap}${FTL_VERSION}${reset_text}, PADD ${padd_version_heatmap}${padd_version}${reset_text}" moveXOffset; printf "%s${clear_line}\n" "${padd_logo_retro_3} ${dns_check_box} DNS ${ftl_check_box} FTL ${mega_status}${reset_text}" moveXOffset; printf "%s${clear_line}\n" "" - moveXOffset; printf "%s${clear_line}\n" "${bold_text}STATS =========================================================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}STATS ==========================================================================${reset_text}" moveXOffset; printf " %-10s%-19s %-10s[%-40s] %-5s${clear_line}\n" "Blocking:" "${domains_being_blocked} domains" "Piholed:" "${ads_blocked_bar}" "${ads_percentage_today}%" moveXOffset; printf " %-10s%-30s%-29s${clear_line}\n" "Clients:" "${clients}" " ${ads_blocked_today} out of ${dns_queries_today} queries" moveXOffset; printf " %-10s%-39s${clear_line}\n" "Latest:" "${latest_blocked}" moveXOffset; printf " %-10s%-39s${clear_line}\n" "Top Ad:" "${top_blocked}" moveXOffset; printf " %-10s%-39s${clear_line}\n" "Top Dmn:" "${top_domain}" moveXOffset; printf " %-10s%-39s${clear_line}\n" "Top Clnt:" "${top_client}" - moveXOffset; printf "%s${clear_line}\n" "${bold_text}FTL ===========================================================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}FTL ============================================================================${reset_text}" moveXOffset; printf " %-10s%-9s %-10s%-9s %-10s%-9s${clear_line}\n" "PID:" "${ftlPID}" "CPU Use:" "${ftl_cpu}" "Mem. Use:" "${ftl_mem_percentage}" moveXOffset; printf " %-10s%-69s${clear_line}\n" "DNSCache:" "${cache_inserts} insertions, ${cache_deletes} deletions, ${cache_size} total entries" - moveXOffset; printf "%s${clear_line}\n" "${bold_text}NETWORK =======================================================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}NETWORK ========================================================================${reset_text}" moveXOffset; printf " %-10s%-19s${clear_line}\n" "Hostname:" "${full_hostname}" moveXOffset; printf " %-10s%-15s %-4s%-9s %-4s%-9s${clear_line}\n" "Interfce:" "${iface_name}" "TX:" "${tx_bytes}" "RX:" "${rx_bytes}" moveXOffset; printf " %-6s%-19s %-10s%-29s${clear_line}\n" "IPv4:" "${pi_ip4_addr}" "IPv6:" "${pi_ip6_addr}" - moveXOffset; printf "%s${clear_line}\n" "${bold_text}DNS ==========================DHCP=============================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}DNS ==========================DHCP==============================================${reset_text}" moveXOffset; printf " %-10s%-19s %-6s${dhcp_heatmap}%-19s${reset_text}${clear_line}\n" "Servers:" "${dns_information}" "DHCP:" "${dhcp_status}" moveXOffset; printf " %-10s${dnssec_heatmap}%-19s${reset_text} %-10s${dhcp_ipv6_heatmap}%-9s${reset_text}${clear_line}\n" "DNSSEC:" "${dnssec_status}" "IPv6 Spt:" "${dhcp_ipv6_status}" moveXOffset; printf " %-10s${conditional_forwarding_heatmap}%-19s${reset_text}%s${clear_line}\n" "CdFwding:" "${conditional_forwarding_status}" "${dhcp_info}" - moveXOffset; printf "%s${clear_line}\n" "${bold_text}SYSTEM ========================================================================${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${bold_text}SYSTEM =========================================================================${reset_text}" moveXOffset; printf " %-10s%-39s${clear_line}\n" "Device:" "${sys_model}" moveXOffset; printf " %-10s%-39s %-10s[${memory_heatmap}%-10s${reset_text}] %-6s${clear_line}\n" "Uptime:" "${system_uptime}" "Memory:" "${memory_bar}" "${memory_percent}%" moveXOffset; printf " %-10s${temp_heatmap}%-10s${reset_text} %-10s${cpu_load_1_heatmap}%-4s${reset_text}, ${cpu_load_5_heatmap}%-4s${reset_text}, ${cpu_load_15_heatmap}%-7s${reset_text} %-10s[${memory_heatmap}%-10s${reset_text}] %-6s${clear_line}" "CPU Temp:" "${temperature}" "CPU Load:" "${cpu_load_1}" "${cpu_load_5}" "${cpu_load_15}" "CPU Load:" "${cpu_bar}" "${cpu_percent}%" From c6781f1a2efae7beda2895c22d795496e721f388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 5 Jan 2023 21:16:59 +0100 Subject: [PATCH 02/10] Use dedicated function to shorten strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- padd.sh | 110 +++++++++++++++++--------------------------------------- 1 file changed, 33 insertions(+), 77 deletions(-) diff --git a/padd.sh b/padd.sh index 9fd3076d..15ce25ce 100755 --- a/padd.sh +++ b/padd.sh @@ -580,97 +580,34 @@ GenerateSizeDependendOutput() { elif [ "$1" = "mini" ]; then ads_blocked_bar=$(BarGenerator "$ads_percentage_today" 20 "color") - if [ ${#latest_blocked_raw} -gt 29 ]; then - latest_blocked=$(echo "$latest_blocked_raw" | cut -c1-26)"..." - else - latest_blocked=${latest_blocked_raw} - fi - - if [ ${#top_blocked_raw} -gt 29 ]; then - top_blocked=$(echo "$top_blocked_raw" | cut -c1-26)"..." - else - top_blocked=${top_blocked_raw} - fi + latest_blocked=$(truncateString "$latest_blocked_raw" 29) + top_blocked=$(truncateString "$top_blocked_raw" 29) elif [ "$1" = "tiny" ]; then ads_blocked_bar=$(BarGenerator "$ads_percentage_today" 30 "color") - if [ ${#latest_blocked_raw} -gt 41 ]; then - latest_blocked=$(echo "$latest_blocked_raw" | cut -c1-38)"..." - else - latest_blocked=${latest_blocked_raw} - fi - - if [ ${#top_blocked_raw} -gt 41 ]; then - top_blocked=$(echo "$top_blocked_raw" | cut -c1-38)"..." - else - top_blocked=${top_blocked_raw} - fi - - if [ ${#top_domain_raw} -gt 41 ]; then - top_domain=$(echo "$top_domain_raw" | cut -c1-38)"..." - else - top_domain=${top_domain_raw} - fi - - if [ ${#top_client_raw} -gt 41 ]; then - top_client=$(echo "$top_client_raw" | cut -c1-38)"..." - else - top_client=${top_client_raw} - fi + latest_blocked=$(truncateString "$latest_blocked_raw" 41) + top_blocked=$(truncateString "$top_blocked_raw" 41) + top_domain=$(truncateString "$top_domain_raw" 41) + top_client=$(truncateString "$top_client_raw" 41) elif [ "$1" = "regular" ] || [ "$1" = "slim" ]; then ads_blocked_bar=$(BarGenerator "$ads_percentage_today" 40 "color") - if [ ${#latest_blocked_raw} -gt 48 ]; then - latest_blocked=$(echo "$latest_blocked_raw" | cut -c1-45)"..." - else - latest_blocked=${latest_blocked_raw} - fi + latest_blocked=$(truncateString "$latest_blocked_raw" 48) + top_blocked=$(truncateString "$top_blocked_raw" 48) + top_domain=$(truncateString "$top_domain_raw" 48) + top_client=$(truncateString "$top_client_raw" 48) - if [ ${#top_blocked_raw} -gt 48 ]; then - top_blocked=$(echo "$top_blocked_raw" | cut -c1-45)"..." - else - top_blocked=${top_blocked_raw} - fi - - if [ ${#top_domain_raw} -gt 48 ]; then - top_domain=$(echo "$top_domain_raw" | cut -c1-45)"..." - else - top_domain=${top_domain_raw} - fi - - if [ ${#top_client_raw} -gt 48 ]; then - top_client=$(echo "$top_client_raw" | cut -c1-45)"..." - else - top_client=${top_client_raw} - fi elif [ "$1" = "mega" ]; then ads_blocked_bar=$(BarGenerator "$ads_percentage_today" 30 "color") - if [ ${#latest_blocked_raw} -gt 68 ]; then - latest_blocked=$(echo "$latest_blocked_raw" | cut -c1-65)"..." - else - latest_blocked=${latest_blocked_raw} - fi - - if [ ${#top_blocked_raw} -gt 68 ]; then - top_blocked=$(echo "$top_blocked_raw" | cut -c1-65)"..." - else - top_blocked=${top_blocked_raw} - fi - if [ ${#top_domain_raw} -gt 68 ]; then - top_domain=$(echo "$top_domain_raw" | cut -c1-65)"..." - else - top_domain=${top_domain_raw} - fi + latest_blocked=$(truncateString "$latest_blocked_raw" 68) + top_blocked=$(truncateString "$top_blocked_raw" 68) + top_domain=$(truncateString "$top_domain_raw" 68) + top_client=$(truncateString "$top_client_raw" 68) - if [ ${#top_client_raw} -gt 68 ]; then - top_client=$(echo "$top_client_raw" | cut -c1-65)"..." - else - top_client=${top_client_raw} - fi fi # System uptime @@ -1204,6 +1141,25 @@ filterModel() { echo "$1" | awk -v list="$FILTERLIST" '{IGNORECASE=1; gsub(list,"")}; {$1=$1}1' } +# Truncates a given string and appends three '...' +# takes two parameters +# $1: string to truncate +# $2: max length of the string +truncateString() { + local truncatedString length shorted + + length=${#1} + shorted=$(($2-3)) + if [ "${length}" -gt "$2" ]; then + truncatedString=$(echo "$1" | cut -c1-$shorted)"..." + echo "${truncatedString}" + else + echo "$1" + fi +} + + + ########################################## MAIN FUNCTIONS ########################################## OutputJSON() { From 49647f5c8c8e851bc025ead30fac91284cdacc10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 6 Jan 2023 09:50:23 +0100 Subject: [PATCH 03/10] Add comments explaining the command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- padd.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/padd.sh b/padd.sh index 15ce25ce..6432edc2 100755 --- a/padd.sh +++ b/padd.sh @@ -1149,12 +1149,14 @@ truncateString() { local truncatedString length shorted length=${#1} - shorted=$(($2-3)) + shorted=$(($2-3)) # shorten max allowed length by 3 to make room for the dots if [ "${length}" -gt "$2" ]; then - truncatedString=$(echo "$1" | cut -c1-$shorted)"..." - echo "${truncatedString}" + # if length of the string is larger then the specified max length + # cut every char from the string exceeding length $shorted and add three dots + truncatedString=$(echo "$1" | cut -c1-$shorted)"..." + echo "${truncatedString}" else - echo "$1" + echo "$1" fi } From a2a8655f307570c8df1fb73064f12da522950b1c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 7 Jan 2023 10:01:05 +0000 Subject: [PATCH 04/10] Bump actions/checkout from 3.2.0 to 3.3.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.2.0 to 3.3.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.2.0...v3.3.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/codespell.yml | 2 +- .github/workflows/editorconfig-checker.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index c3708d15..84c2f49e 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v3.3.0 - name: Spell-Checking uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/editorconfig-checker.yml b/.github/workflows/editorconfig-checker.yml index d0986800..63cafd38 100644 --- a/.github/workflows/editorconfig-checker.yml +++ b/.github/workflows/editorconfig-checker.yml @@ -9,6 +9,6 @@ jobs: name: editorconfig-checker runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.2.0 + - uses: actions/checkout@v3.3.0 - uses: editorconfig-checker/action-editorconfig-checker@main # current tag v1.0.0 is really out-of-date - run: editorconfig-checker diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index 889f9622..89b6323f 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -11,7 +11,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v3.3.0 - name: Opening pull request run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' env: From 6b3c2d09783b9e8557d4bac8f210eb7df484ebed Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 7 Apr 2022 14:17:33 -0700 Subject: [PATCH 05/10] Use padd.sh URLs --- README.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3d94af6d..531d3aae 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,18 @@ PADD (formerly Chronometer2) is a more expansive version of the original chronom ***Note:** PADD has been adopted by the Pi-hole team, thanks to JPMCK for creating this helpful tool! ## Setup PADD - -*More in-depth information about setting up PADD can be found in this repo’s [wiki](https://github.com/jpmck/PADD/wiki/Setup).* +*More in-depth information about setting up PADD can be found in this repo’s [wiki](https://github.com/pi-hole/PADD/wiki/Setup).* - Get a copy of PADD by running: ```bash cd ~ -wget -N https://raw.githubusercontent.com/pi-hole/PADD/master/padd.sh +wget -O padd.sh https://install.padd.sh +``` +or +```bash +cd ~ +curl -sSL https://install.padd.sh -o padd.sh ``` - Make PADD executable by running @@ -46,18 +50,20 @@ cd ~ ; echo "if [ \"\$TERM\" == \"linux\" ] ; then\n while :\n do\n ./padd. - Reboot your Pi-Hole by running `sudo reboot`. PADD should now run when your Pi-Hole has completed booting. ## Updating PADD - -- Just run - +- Just run the same commands you used to install ```bash cd ~ -wget -N https://raw.githubusercontent.com/pi-hole/PADD/master/padd.sh +wget -O padd.sh https://install.padd.sh +``` +```bash +cd ~ +curl -sSL https://install.padd.sh -o padd.sh ``` - -**Note: if you are already running Chronometer2 v1.3.1 or below, you’ll need to follow [these instructions](https://github.com/jpmck/PADD/wiki/Updating-from-Chronometer2)!** ## Running Pi-hole in a Docker Container If you're running Pi-hole in the official Docker Container, `padd.sh` is pre-installed and named `padd`. It can be used with the following command: ```bash docker exec -it padd [padd_options] ``` +## FAQ +*Answers to frequently asked questions can be found in this repo’s [wiki](https://github.com/pi-hole/PADD/wiki/FAQ).* From bf58e12b52d7466890d3766b2a536f4f9825e2d7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 18 Apr 2022 10:20:11 -0700 Subject: [PATCH 06/10] Remove FAQ entry. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 531d3aae..b98aab51 100644 --- a/README.md +++ b/README.md @@ -65,5 +65,3 @@ If you're running Pi-hole in the official Docker Container, `padd.sh` is pre-ins ```bash docker exec -it padd [padd_options] ``` -## FAQ -*Answers to frequently asked questions can be found in this repo’s [wiki](https://github.com/pi-hole/PADD/wiki/FAQ).* From 191a2053a08cf1e8fe3d1a1b452283826c7ed94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 17 Jan 2023 23:11:06 +0100 Subject: [PATCH 07/10] Export LOCALE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- padd.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/padd.sh b/padd.sh index 6432edc2..018b90da 100755 --- a/padd.sh +++ b/padd.sh @@ -9,11 +9,8 @@ # A more advanced version of the chronometer provided with Pihole # SETS LOCALE -# Issue 5: https://github.com/jpmck/PADD/issues/5 -# Updated to en_US to support -# export LC_ALL=en_US.UTF-8 > /dev/null 2>&1 || export LC_ALL=en_GB.UTF-8 > /dev/null 2>&1 || export LC_ALL=C.UTF-8 > /dev/null 2>&1 -LC_ALL=C -LC_NUMERIC=C +export LC_ALL=C +export LC_NUMERIC=C ############################################ VARIABLES ############################################# From b364df625d90cbfd7a62e8b59b42be8d0ec5ef79 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 1 Jan 2023 15:42:01 +0000 Subject: [PATCH 08/10] If it is detected that PADD is running inside the official docker container (DOCKER_VERSION is set) then do not check or display if there are any updates to PADD Signed-off-by: Adam Warner --- padd.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/padd.sh b/padd.sh index 018b90da..c107465d 100755 --- a/padd.sh +++ b/padd.sh @@ -433,6 +433,11 @@ GetVersionInformation() { out_of_date_flag=false + # If PADD is running inside docker, immediately return without checking for updated component versions + if [ -n "${DOCKER_VERSION}" ]; then + return + fi + # Gather CORE version information... # Extract vx.xx or vx.xx.xxx version CORE_VERSION="$(echo "${CORE_VERSION}" | grep -oE '^v[0-9]+([.][0-9]+){1,2}')" @@ -546,6 +551,10 @@ GetVersionInformation() { } GetPADDInformation() { + # If PADD is running inside docker, immediately return without checking for an update + if [ -n "${DOCKER_VERSION}" ]; then + return + fi # PADD version information... padd_version_latest="$(curl --silent https://api.github.com/repos/pi-hole/PADD/releases/latest | grep '"tag_name":' | awk -F \" '{print $4}')" From 6c68f371c76d62d33b5e8c683940db73c3724a1a Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 18 Jan 2023 17:17:57 +0000 Subject: [PATCH 09/10] Only show Docker Version on startup and header of main page. (Except PADD in mega) Change sys_model from "Docker tag blah" to "container" Signed-off-by: Adam Warner --- padd.sh | 57 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/padd.sh b/padd.sh index c107465d..564034e1 100755 --- a/padd.sh +++ b/padd.sh @@ -246,7 +246,7 @@ GetSystemInformation() { sys_model=$(tr -d '\0' < /tmp/sysinfo/model) elif [ -n "${DOCKER_VERSION}" ]; then # Docker image. DOCKER_VERSION is read from /etc/pihole/versions - sys_model="Docker tag ${DOCKER_VERSION}" + sys_model="Container" fi # Cleaning device model from useless OEM information @@ -435,6 +435,15 @@ GetVersionInformation() { # If PADD is running inside docker, immediately return without checking for updated component versions if [ -n "${DOCKER_VERSION}" ]; then + docker_version_converted="$(VersionConverter "${DOCKER_VERSION}")" + docker_version_latest_converted="$(VersionConverter "${GITHUB_DOCKER_VERSION}")" + + if [ "${docker_version_converted}" -lt "${docker_version_latest_converted}" ]; then + out_of_date_flag="true" + docker_version_heatmap=${red_text} + else + docker_version_heatmap=${green_text} + fi return fi @@ -710,6 +719,12 @@ SetStatusMessage() { ############################################# PRINTERS ############################################# PrintLogo() { + if [ -n "${DOCKER_VERSION}" ]; then + version_info="Docker ${docker_version_heatmap}${DOCKER_VERSION}${reset_text}" + else + version_info="Pi-hole® ${core_version_heatmap}${CORE_VERSION}${reset_text}, Web ${web_version_heatmap}${WEB_VERSION}${reset_text}, FTL ${ftl_version_heatmap}${FTL_VERSION}" + fi + # Screen size checks if [ "$1" = "pico" ]; then printf "%s${clear_line}\n" "p${padd_text} ${pico_status}" @@ -720,23 +735,28 @@ PrintLogo() { elif [ "$1" = "mini" ]; then printf "%s${clear_line}\n${clear_line}\n" "${padd_text}${dim_text}mini${reset_text} ${mini_status}" elif [ "$1" = "tiny" ]; then - printf "%s${clear_line}\n" "${padd_text}${dim_text}tiny${reset_text} Pi-hole® ${core_version_heatmap}${CORE_VERSION}${reset_text}, Web ${web_version_heatmap}${WEB_VERSION}${reset_text}, FTL ${ftl_version_heatmap}${FTL_VERSION}${reset_text}" + printf "%s${clear_line}\n" "${padd_text}${dim_text}tiny${reset_text} ${version_info}${reset_text}" printf "%s${clear_line}\n" " PADD ${padd_version_heatmap}${padd_version}${reset_text} ${tiny_status}${reset_text}" elif [ "$1" = "slim" ]; then printf "%s${clear_line}\n${clear_line}\n" "${padd_text}${dim_text}slim${reset_text} ${full_status}" elif [ "$1" = "regular" ] || [ "$1" = "slim" ]; then printf "%s${clear_line}\n" "${padd_logo_1}" - printf "%s${clear_line}\n" "${padd_logo_2}Pi-hole® ${core_version_heatmap}${CORE_VERSION}${reset_text}, Web ${web_version_heatmap}${WEB_VERSION}${reset_text}, FTL ${ftl_version_heatmap}${FTL_VERSION}${reset_text}" + printf "%s${clear_line}\n" "${padd_logo_2}${version_info}${reset_text}" printf "%s${clear_line}\n${clear_line}\n" "${padd_logo_3}PADD ${padd_version_heatmap}${padd_version}${reset_text} ${full_status}${reset_text}" # normal or not defined else printf "%s${clear_line}\n" "${padd_logo_retro_1}" - printf "%s${clear_line}\n" "${padd_logo_retro_2} Pi-hole® ${core_version_heatmap}${CORE_VERSION}${reset_text}, Web ${web_version_heatmap}${WEB_VERSION}${reset_text}, FTL ${ftl_version_heatmap}${FTL_VERSION}${reset_text}, PADD ${padd_version_heatmap}${padd_version}${reset_text}" + printf "%s${clear_line}\n" "${padd_logo_retro_2} ${version_info}, PADD ${padd_version_heatmap}${padd_version}${reset_text}" printf "%s${clear_line}\n${clear_line}\n" "${padd_logo_retro_3} ${dns_check_box} DNS ${ftl_check_box} FTL ${mega_status}${reset_text}" fi } PrintDashboard() { + if [ -n "${DOCKER_VERSION}" ]; then + version_info="Docker ${docker_version_heatmap}${DOCKER_VERSION}${reset_text}" + else + version_info="Pi-hole® ${core_version_heatmap}${CORE_VERSION}${reset_text}, Web ${web_version_heatmap}${WEB_VERSION}${reset_text}, FTL ${ftl_version_heatmap}${FTL_VERSION}" + fi # Move cursor to (0,0). printf '\e[H' @@ -814,7 +834,7 @@ PrintDashboard() { moveXOffset; printf "%s${clear_line}" " Memory: [${memory_heatmap}${memory_bar}${reset_text}] ${memory_percent}%" elif [ "$1" = "tiny" ]; then # tiny is a screen at least 53x20 (columns x lines) - moveXOffset; printf "%s${clear_line}\n" "${padd_text}${dim_text}tiny${reset_text} Pi-hole® ${core_version_heatmap}${CORE_VERSION}${reset_text}, Web ${web_version_heatmap}${WEB_VERSION}${reset_text}, FTL ${ftl_version_heatmap}${FTL_VERSION}${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${padd_text}${dim_text}tiny${reset_text} ${version_info}${reset_text}" moveXOffset; printf "%s${clear_line}\n" " PADD ${padd_version_heatmap}${padd_version}${reset_text} ${tiny_status}${reset_text}" moveXOffset; printf "%s${clear_line}\n" "${bold_text}PI-HOLE =============================================${reset_text}" moveXOffset; printf " %-10s${dns_heatmap}%-16s${reset_text} %-8s${ftl_heatmap}%-10s${reset_text}${clear_line}\n" "DNS:" "${dns_status}" "FTL:" "${ftl_status}" @@ -844,12 +864,12 @@ PrintDashboard() { # slim is a screen with at least 60 columns and exactly 21 lines # regular is a screen at least 60x22 (columns x lines) if [ "$1" = "slim" ]; then - moveXOffset; printf "%s${clear_line}\n" "${padd_text}${dim_text}slim${reset_text} Pi-hole® ${core_version_heatmap}${CORE_VERSION}${reset_text}, Web ${web_version_heatmap}${WEB_VERSION}${reset_text}, FTL ${ftl_version_heatmap}${FTL_VERSION}${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${padd_text}${dim_text}slim${reset_text} ${version_info}${reset_text}" moveXOffset; printf "%s${clear_line}\n" " PADD ${padd_version_heatmap}${padd_version}${reset_text} ${full_status}${reset_text}" moveXOffset; printf "%s${clear_line}\n" "" else moveXOffset; printf "%s${clear_line}\n" "${padd_logo_1}" - moveXOffset; printf "%s${clear_line}\n" "${padd_logo_2}Pi-hole® ${core_version_heatmap}${CORE_VERSION}${reset_text}, Web ${web_version_heatmap}${WEB_VERSION}${reset_text}, FTL ${ftl_version_heatmap}${FTL_VERSION}${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${padd_logo_2}${version_info}${reset_text}" moveXOffset; printf "%s${clear_line}\n" "${padd_logo_3}PADD ${padd_version_heatmap}${padd_version}${reset_text} ${full_status}${reset_text}" moveXOffset; printf "%s${clear_line}\n" "" fi @@ -880,7 +900,7 @@ PrintDashboard() { else # ${padd_size} = mega # mega is a screen with at least 80 columns and 26 lines moveXOffset; printf "%s${clear_line}\n" "${padd_logo_retro_1}" - moveXOffset; printf "%s${clear_line}\n" "${padd_logo_retro_2} Pi-hole® ${core_version_heatmap}${CORE_VERSION}${reset_text}, Web ${web_version_heatmap}${WEB_VERSION}${reset_text}, FTL ${ftl_version_heatmap}${FTL_VERSION}${reset_text}, PADD ${padd_version_heatmap}${padd_version}${reset_text}" + moveXOffset; printf "%s${clear_line}\n" "${padd_logo_retro_2} ${version_info}, PADD ${padd_version_heatmap}${padd_version}${reset_text}" moveXOffset; printf "%s${clear_line}\n" "${padd_logo_retro_3} ${dns_check_box} DNS ${ftl_check_box} FTL ${mega_status}${reset_text}" moveXOffset; printf "%s${clear_line}\n" "" moveXOffset; printf "%s${clear_line}\n" "${bold_text}STATS ==========================================================================${reset_text}" @@ -1232,9 +1252,12 @@ StartupRoutine(){ moveXOffset; echo "- Gathering version info." GetVersionInformation GetPADDInformation - moveXOffset; echo " - Core $CORE_VERSION, Web $WEB_VERSION" - moveXOffset; echo " - FTL $FTL_VERSION, PADD $padd_version" - + if [ -n "${DOCKER_VERSION}" ]; then + moveXOffset; echo " - Docker Tag ${DOCKER_VERSION}" + else + moveXOffset; echo " - Core $CORE_VERSION, Web $WEB_VERSION" + moveXOffset; echo " - FTL $FTL_VERSION, PADD $padd_version" + fi else moveXOffset; printf "%b" "${padd_logo_retro_1}\n" @@ -1257,10 +1280,14 @@ StartupRoutine(){ moveXOffset; echo "- Gathering version information..." GetVersionInformation GetPADDInformation - moveXOffset; echo " - Pi-hole Core $CORE_VERSION" - moveXOffset; echo " - Web Admin $WEB_VERSION" - moveXOffset; echo " - FTL $FTL_VERSION" - moveXOffset; echo " - PADD $padd_version" + if [ -n "${DOCKER_VERSION}" ]; then + moveXOffset; echo " - Docker Tag ${DOCKER_VERSION}" + else + moveXOffset; echo " - Pi-hole Core $CORE_VERSION" + moveXOffset; echo " - Web Admin $WEB_VERSION" + moveXOffset; echo " - FTL $FTL_VERSION" + moveXOffset; echo " - PADD $padd_version" + fi fi moveXOffset; printf "%s" "- Starting in " From f9dcca7997f64292db8b5bb92c1ddbcdb97132b9 Mon Sep 17 00:00:00 2001 From: pralor-bot Date: Tue, 17 Jan 2023 22:17:11 +0000 Subject: [PATCH 10/10] Bump version to v3.10.1 --- padd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/padd.sh b/padd.sh index 564034e1..bbae894c 100755 --- a/padd.sh +++ b/padd.sh @@ -15,7 +15,7 @@ export LC_NUMERIC=C ############################################ VARIABLES ############################################# # VERSION -padd_version="v3.10.0" +padd_version="v3.10.1" # LastChecks LastCheckVersionInformation=$(date +%s)