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
|
||||||
|
|
59
pihole
59
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!"
|
||||||
|
@ -187,23 +216,23 @@ fi
|
||||||
|
|
||||||
# Handle redirecting to specific functions based on arguments
|
# Handle redirecting to specific functions based on arguments
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"-w" | "whitelist" ) whitelistFunc "$@";;
|
"-w" | "whitelist" ) whitelistFunc "$@";;
|
||||||
"-b" | "blacklist" ) blacklistFunc "$@";;
|
"-b" | "blacklist" ) blacklistFunc "$@";;
|
||||||
"-d" | "debug" ) debugFunc;;
|
"-d" | "debug" ) debugFunc;;
|
||||||
"-f" | "flush" ) flushFunc;;
|
"-f" | "flush" ) flushFunc;;
|
||||||
"-up" | "updatePihole" ) updatePiholeFunc;;
|
"-up" | "updatePihole" ) updatePiholeFunc;;
|
||||||
"-r" | "reconfigure" ) reconfigurePiholeFunc;;
|
"-r" | "reconfigure" ) reconfigurePiholeFunc;;
|
||||||
"-g" | "updateGravity" ) updateGravityFunc "$@";;
|
"-g" | "updateGravity" ) updateGravityFunc "$@";;
|
||||||
"-s" | "setupLCD" ) setupLCDFunction;;
|
"-s" | "setupLCD" ) setupLCDFunction;;
|
||||||
"-c" | "chronometer" ) chronometerFunc "$@";;
|
"-c" | "chronometer" ) chronometerFunc "$@";;
|
||||||
"-h" | "help" ) helpFunc;;
|
"-h" | "help" ) helpFunc;;
|
||||||
"-v" | "version" ) versionFunc "$@";;
|
"-v" | "version" ) versionFunc "$@";;
|
||||||
"-q" | "query" ) queryFunc "$@";;
|
"-q" | "query" ) queryFunc "$@";;
|
||||||
"uninstall" ) uninstallFunc;;
|
"uninstall" ) uninstallFunc;;
|
||||||
"enable" ) piholeEnable 1;;
|
"enable" ) piholeEnable 1;;
|
||||||
"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