mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-04 20:13:17 +00:00
move functions to pihole as they could be useful other places
This commit is contained in:
parent
caf65bb54c
commit
cb8bfa06e7
2 changed files with 47 additions and 18 deletions
|
@ -33,7 +33,7 @@ IPv4_address=$(echo "${IPv4_address}" | cut -d"/" -f1)
|
|||
|
||||
CalcBlockedDomains() {
|
||||
if [ -e "${gravity}" ]; then
|
||||
blockedDomainsTotal=$(wc -l "${gravityraw}" | awk '{print $1}')
|
||||
blockedDomainsTotal=$(pihole stats list)
|
||||
else
|
||||
blockedDomainsTotal="Err."
|
||||
fi
|
||||
|
@ -41,7 +41,7 @@ CalcBlockedDomains() {
|
|||
|
||||
CalcQueriesToday() {
|
||||
if [ -e "${piLog}" ];then
|
||||
queriesToday=$(cat "${piLog}" | grep "${today}" | cut -d" " -f5 | grep query | wc -l)
|
||||
queriesToday=$(pihole stats hits)
|
||||
else
|
||||
queriesToday="Err."
|
||||
fi
|
||||
|
@ -49,7 +49,7 @@ CalcQueriesToday() {
|
|||
|
||||
CalcblockedToday() {
|
||||
if [ -e "${piLog}" ] && [ -e "${gravity}" ];then
|
||||
blockedToday=$(grep "${gravity}" "${piLog}" | grep "${today}" | grep -v read | wc -l)
|
||||
blockedToday=$(pihole stats blocked)
|
||||
else
|
||||
blockedToday="Err."
|
||||
fi
|
||||
|
|
31
pihole
31
pihole
|
@ -154,6 +154,35 @@ piholeStatus() {
|
|||
fi
|
||||
}
|
||||
|
||||
statsBlockedDomains() {
|
||||
local blockedDomainsTotal=$(wc -l /etc/pihole/list.preEventHorizon | awk '{print $1}')
|
||||
echo ${blockedDomainsTotal}
|
||||
}
|
||||
|
||||
statsQueriesToday() {
|
||||
local queriesToday=$(cat /var/log/pihole.log | cut -d" " -f5 | grep query | wc -l)
|
||||
echo ${queriesToday}
|
||||
}
|
||||
|
||||
statsBlockedToday() {
|
||||
local blockedToday=$(grep /etc/pihole/gravity.list /var/log/pihole.log | grep -v read | wc -l)
|
||||
echo ${blockedToday}
|
||||
}
|
||||
|
||||
stats() {
|
||||
shift
|
||||
if [[ $1 == "list" ]] ; then
|
||||
statsBlockedDomains
|
||||
elif [[ $1 == "hits" ]] ; then
|
||||
statsQueriesToday
|
||||
elif [[ $1 == "blocked" ]] ; then
|
||||
statsBlockedToday
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
helpFunc() {
|
||||
echo "::: Control all PiHole specific functions!"
|
||||
|
@ -204,6 +233,6 @@ case "$1" in
|
|||
"disable" ) piholeEnable 0;;
|
||||
"status" ) piholeStatus "$2";;
|
||||
"restartdns" ) restartDNS;;
|
||||
|
||||
"stats" ) stats "$@";;
|
||||
* ) helpFunc;;
|
||||
esac
|
||||
|
|
Loading…
Reference in a new issue