move functions to pihole as they could be useful other places

This commit is contained in:
Tommy Huff 2016-10-21 20:05:37 -04:00
parent caf65bb54c
commit cb8bfa06e7
2 changed files with 47 additions and 18 deletions

View file

@ -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

59
pihole
View file

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