mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-22 15:20:14 +00:00
Merge branch 'development' into development-v6-merge-development (resolved conflicts)
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
commit
f193edd428
6 changed files with 446 additions and 415 deletions
|
@ -27,7 +27,7 @@ colfile="/opt/pihole/COL_TABLE"
|
|||
# Source api functions
|
||||
. "${PI_HOLE_INSTALL_DIR}/api.sh"
|
||||
|
||||
Help(){
|
||||
Help() {
|
||||
echo "Usage: pihole -q [option] <domain>
|
||||
Example: 'pihole -q --partial domain.com'
|
||||
Query the adlists for a specified domain
|
||||
|
@ -36,11 +36,10 @@ Options:
|
|||
--partial Search the adlists for partially matching domains
|
||||
--all Return all query matches within the adlists
|
||||
-h, --help Show this help dialog"
|
||||
exit 0
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
GenerateOutput(){
|
||||
GenerateOutput() {
|
||||
local data gravity_data lists_data num_gravity num_lists search_type_str
|
||||
local gravity_data_csv lists_data_csv line current_domain
|
||||
data="${1}"
|
||||
|
@ -52,13 +51,13 @@ GenerateOutput(){
|
|||
gravity_data=$(printf %s "${data}" | jq '.search.gravity | group_by(.address) | map({ address: (.[0].address), domains: [.[] | .domain] })')
|
||||
|
||||
# number of objects in each json
|
||||
num_gravity=$(printf %s "${gravity_data}" | jq length )
|
||||
num_lists=$(printf %s "${lists_data}" | jq length )
|
||||
num_gravity=$(printf %s "${gravity_data}" | jq length)
|
||||
num_lists=$(printf %s "${lists_data}" | jq length)
|
||||
|
||||
if [ "${partial}" = true ]; then
|
||||
search_type_str="partially"
|
||||
search_type_str="partially"
|
||||
else
|
||||
search_type_str="exactly"
|
||||
search_type_str="exactly"
|
||||
fi
|
||||
|
||||
# Results from allow/deny list
|
||||
|
@ -66,7 +65,7 @@ GenerateOutput(){
|
|||
if [ "${num_lists}" -gt 0 ]; then
|
||||
# Convert the data to a csv, each line is a "domain,type" string
|
||||
# not using jq's @csv here as it quotes each value individually
|
||||
lists_data_csv=$(printf %s "${lists_data}" | jq --raw-output '.[] | [.domain, .type] | join(",")' )
|
||||
lists_data_csv=$(printf %s "${lists_data}" | jq --raw-output '.[] | [.domain, .type] | join(",")')
|
||||
|
||||
# Generate output for each csv line, separating line in a domain and type substring at the ','
|
||||
echo "${lists_data_csv}" | while read -r line; do
|
||||
|
@ -79,7 +78,7 @@ GenerateOutput(){
|
|||
if [ "${num_gravity}" -gt 0 ]; then
|
||||
# Convert the data to a csv, each line is a "URL,domain,domain,...." string
|
||||
# not using jq's @csv here as it quotes each value individually
|
||||
gravity_data_csv=$(printf %s "${gravity_data}" | jq --raw-output '.[] | [.address, .domains[]] | join(",")' )
|
||||
gravity_data_csv=$(printf %s "${gravity_data}" | jq --raw-output '.[] | [.address, .domains[]] | join(",")')
|
||||
|
||||
# Generate line-by-line output for each csv line
|
||||
echo "${gravity_data_csv}" | while read -r line; do
|
||||
|
@ -90,7 +89,7 @@ GenerateOutput(){
|
|||
# cut off URL, leaving "domain,domain,...."
|
||||
line=${line#*,}
|
||||
# print each domain and remove it from the string until nothing is left
|
||||
while [ ${#line} -gt 0 ]; do
|
||||
while [ ${#line} -gt 0 ]; do
|
||||
current_domain=${line%%,*}
|
||||
printf ' - %s\n' "${COL_GREEN}${current_domain}${COL_NC}"
|
||||
# we need to remove the current_domain and the comma in two steps because
|
||||
|
@ -103,17 +102,17 @@ GenerateOutput(){
|
|||
fi
|
||||
}
|
||||
|
||||
Main(){
|
||||
Main() {
|
||||
local data
|
||||
|
||||
if [ -z "${domain}" ]; then
|
||||
echo "No domain specified"; exit 1
|
||||
echo "No domain specified"
|
||||
exit 1
|
||||
fi
|
||||
# domains are lowercased and converted to punycode by FTL since
|
||||
# https://github.com/pi-hole/FTL/pull/1715
|
||||
# no need to do it here
|
||||
|
||||
|
||||
# Test if the authentication endpoint is available
|
||||
TestAPIAvailability
|
||||
|
||||
|
@ -137,13 +136,13 @@ Main(){
|
|||
|
||||
# Process all options (if present)
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
"-h" | "--help" ) Help;;
|
||||
"--partial" ) partial="true";;
|
||||
"--all" ) max_results=10000;; # hard-coded FTL limit
|
||||
* ) domain=$1;;
|
||||
esac
|
||||
shift
|
||||
case "$1" in
|
||||
"-h" | "--help") Help ;;
|
||||
"--partial") partial="true" ;;
|
||||
"--all") max_results=10000 ;; # hard-coded FTL limit
|
||||
*) domain=$1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
Main "${domain}"
|
||||
|
|
|
@ -10,32 +10,31 @@
|
|||
|
||||
function get_local_branch() {
|
||||
# Return active branch
|
||||
cd "${1}" 2> /dev/null || return 1
|
||||
cd "${1}" 2>/dev/null || return 1
|
||||
git rev-parse --abbrev-ref HEAD || return 1
|
||||
}
|
||||
|
||||
function get_local_version() {
|
||||
# Return active version
|
||||
cd "${1}" 2> /dev/null || return 1
|
||||
git describe --tags --always 2> /dev/null || return 1
|
||||
cd "${1}" 2>/dev/null || return 1
|
||||
git describe --tags --always 2>/dev/null || return 1
|
||||
}
|
||||
|
||||
function get_local_hash() {
|
||||
cd "${1}" 2> /dev/null || return 1
|
||||
cd "${1}" 2>/dev/null || return 1
|
||||
git rev-parse --short=8 HEAD || return 1
|
||||
}
|
||||
|
||||
function get_remote_version() {
|
||||
# if ${2} is = "master" we need to use the "latest" endpoint, otherwise, we simply return null
|
||||
if [[ "${2}" == "master" ]]; then
|
||||
curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1
|
||||
curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2>/dev/null | jq --raw-output .tag_name || return 1
|
||||
else
|
||||
echo "null"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function get_remote_hash(){
|
||||
function get_remote_hash() {
|
||||
git ls-remote "https://github.com/pi-hole/${1}" --tags "${2}" | awk '{print substr($0, 1,8);}' || return 1
|
||||
}
|
||||
|
||||
|
@ -57,16 +56,15 @@ chmod 644 "${VERSION_FILE}"
|
|||
DOCKER_TAG=$(cat /pihole.docker.tag 2>/dev/null)
|
||||
regex='^([0-9]+\.){1,2}(\*|[0-9]+)(-.*)?$|(^nightly$)|(^dev.*$)'
|
||||
if [[ ! "${DOCKER_TAG}" =~ $regex ]]; then
|
||||
# DOCKER_TAG does not match the pattern (see https://regex101.com/r/RsENuz/1), so unset it.
|
||||
unset DOCKER_TAG
|
||||
# DOCKER_TAG does not match the pattern (see https://regex101.com/r/RsENuz/1), so unset it.
|
||||
unset DOCKER_TAG
|
||||
fi
|
||||
|
||||
# used in cronjob
|
||||
if [[ "$1" == "reboot" ]]; then
|
||||
sleep 30
|
||||
sleep 30
|
||||
fi
|
||||
|
||||
|
||||
# get Core versions
|
||||
|
||||
CORE_VERSION="$(get_local_version /etc/.pihole)"
|
||||
|
@ -84,7 +82,6 @@ addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSI
|
|||
GITHUB_CORE_HASH="$(get_remote_hash pi-hole "${CORE_BRANCH}")"
|
||||
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}"
|
||||
|
||||
|
||||
# get Web versions
|
||||
|
||||
WEB_VERSION="$(get_local_version /var/www/html/admin)"
|
||||
|
@ -119,7 +116,6 @@ addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION
|
|||
GITHUB_FTL_HASH="$(get_remote_hash FTL "${FTL_BRANCH}")"
|
||||
addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_HASH" "${GITHUB_FTL_HASH}"
|
||||
|
||||
|
||||
# get Docker versions
|
||||
|
||||
if [[ "${DOCKER_TAG}" ]]; then
|
||||
|
|
|
@ -31,7 +31,7 @@ main() {
|
|||
|
||||
# Automatically show detailed information if
|
||||
# at least one of the components is not on master branch
|
||||
if [ ! "${CORE_BRANCH}" = "master" ] || [ ! "${WEB_BRANCH}" = "master" ] || [ ! "${FTL_BRANCH}" = "master" ] ; then
|
||||
if [ ! "${CORE_BRANCH}" = "master" ] || [ ! "${WEB_BRANCH}" = "master" ] || [ ! "${FTL_BRANCH}" = "master" ]; then
|
||||
details=true
|
||||
fi
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue