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() {
|
CalcBlockedDomains() {
|
||||||
if [ -e "${gravity}" ]; then
|
if [ -e "${gravity}" ]; then
|
||||||
blockedDomainsTotal=$(wc -l "${gravityraw}" | awk '{print $1}')
|
blockedDomainsTotal=$(pihole stats list)
|
||||||
else
|
else
|
||||||
blockedDomainsTotal="Err."
|
blockedDomainsTotal="Err."
|
||||||
fi
|
fi
|
||||||
|
@ -41,7 +41,7 @@ CalcBlockedDomains() {
|
||||||
|
|
||||||
CalcQueriesToday() {
|
CalcQueriesToday() {
|
||||||
if [ -e "${piLog}" ];then
|
if [ -e "${piLog}" ];then
|
||||||
queriesToday=$(cat "${piLog}" | grep "${today}" | cut -d" " -f5 | grep query | wc -l)
|
queriesToday=$(pihole stats hits)
|
||||||
else
|
else
|
||||||
queriesToday="Err."
|
queriesToday="Err."
|
||||||
fi
|
fi
|
||||||
|
@ -49,7 +49,7 @@ CalcQueriesToday() {
|
||||||
|
|
||||||
CalcblockedToday() {
|
CalcblockedToday() {
|
||||||
if [ -e "${piLog}" ] && [ -e "${gravity}" ];then
|
if [ -e "${piLog}" ] && [ -e "${gravity}" ];then
|
||||||
blockedToday=$(grep "${gravity}" "${piLog}" | grep "${today}" | grep -v read | wc -l)
|
blockedToday=$(pihole stats blocked)
|
||||||
else
|
else
|
||||||
blockedToday="Err."
|
blockedToday="Err."
|
||||||
fi
|
fi
|
||||||
|
|
31
pihole
31
pihole
|
@ -154,6 +154,35 @@ piholeStatus() {
|
||||||
fi
|
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() {
|
helpFunc() {
|
||||||
echo "::: Control all PiHole specific functions!"
|
echo "::: Control all PiHole specific functions!"
|
||||||
|
@ -204,6 +233,6 @@ case "$1" in
|
||||||
"disable" ) piholeEnable 0;;
|
"disable" ) piholeEnable 0;;
|
||||||
"status" ) piholeStatus "$2";;
|
"status" ) piholeStatus "$2";;
|
||||||
"restartdns" ) restartDNS;;
|
"restartdns" ) restartDNS;;
|
||||||
|
"stats" ) stats "$@";;
|
||||||
* ) helpFunc;;
|
* ) helpFunc;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue