2016-11-16 20:34:43 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Pi-hole: A black hole for Internet advertisements
|
|
|
|
# Network-wide ad blocking via your Raspberry Pi
|
|
|
|
# http://pi-hole.net
|
2016-11-16 21:13:47 +00:00
|
|
|
# Web interface settings
|
2016-11-16 20:34:43 +00:00
|
|
|
#
|
|
|
|
# Pi-hole is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
2016-11-16 20:36:19 +00:00
|
|
|
args=("$@")
|
2016-11-16 20:34:43 +00:00
|
|
|
|
|
|
|
helpFunc() {
|
|
|
|
cat << EOM
|
2016-11-20 14:15:27 +00:00
|
|
|
::: Set admin options for the web interface of pihole
|
2016-11-16 20:34:43 +00:00
|
|
|
:::
|
2016-11-20 14:15:27 +00:00
|
|
|
::: Usage: pihole -a [options]
|
2016-11-16 20:34:43 +00:00
|
|
|
:::
|
|
|
|
::: Options:
|
2016-11-19 20:57:42 +00:00
|
|
|
::: -p, password Set web interface password, an empty input will remove any previously set password
|
2016-11-16 20:34:43 +00:00
|
|
|
::: -c, celsius Set Celcius temperature unit
|
|
|
|
::: -f, fahrenheit Set Fahrenheit temperature unit
|
|
|
|
::: -h, --help Show this help dialog
|
|
|
|
EOM
|
2016-12-01 23:10:06 +00:00
|
|
|
exit 0
|
2016-11-16 20:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetTemperatureUnit(){
|
|
|
|
|
|
|
|
# Remove setting from file (create backup setupVars.conf.bak)
|
2016-11-16 21:33:28 +00:00
|
|
|
sed -i.bak '/TEMPERATUREUNIT/d' /etc/pihole/setupVars.conf
|
2016-11-16 20:34:43 +00:00
|
|
|
# Save setting to file
|
|
|
|
if [[ $unit == "F" ]] ; then
|
2016-11-16 21:33:28 +00:00
|
|
|
echo "TEMPERATUREUNIT=F" >> /etc/pihole/setupVars.conf
|
2016-11-16 20:34:43 +00:00
|
|
|
else
|
2016-11-16 21:33:28 +00:00
|
|
|
echo "TEMPERATUREUNIT=C" >> /etc/pihole/setupVars.conf
|
2016-11-16 20:34:43 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SetWebPassword(){
|
|
|
|
|
|
|
|
# Remove password from file (create backup setupVars.conf.bak)
|
2016-11-16 21:33:28 +00:00
|
|
|
sed -i.bak '/WEBPASSWORD/d' /etc/pihole/setupVars.conf
|
2016-11-19 20:50:15 +00:00
|
|
|
# Set password only if there is one to be set
|
|
|
|
if (( ${#args[2]} > 0 )) ; then
|
|
|
|
# Compute password hash twice to avoid rainbow table vulnerability
|
|
|
|
hash=$(echo -n ${args[2]} | sha256sum | sed 's/\s.*$//')
|
|
|
|
hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//')
|
|
|
|
# Save hash to file
|
|
|
|
echo "WEBPASSWORD=${hash}" >> /etc/pihole/setupVars.conf
|
|
|
|
echo "New password set"
|
|
|
|
else
|
|
|
|
echo "Password removed"
|
|
|
|
fi
|
2016-11-16 20:34:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-11 15:54:27 +00:00
|
|
|
SetDNSServers(){
|
|
|
|
|
|
|
|
# Remove setting from file (create backup setupVars.conf.bak)
|
|
|
|
sed -i.bak '/PIHOLE_DNS_1/d;/PIHOLE_DNS_2/d;' /etc/pihole/setupVars.conf
|
|
|
|
# Save setting to file
|
|
|
|
echo "PIHOLE_DNS_1=${args[2]}" >> /etc/pihole/setupVars.conf
|
|
|
|
echo "PIHOLE_DNS_2=${args[3]}" >> /etc/pihole/setupVars.conf
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-11 18:30:04 +00:00
|
|
|
SetExcludeDomains(){
|
|
|
|
|
|
|
|
# Remove setting from file (create backup setupVars.conf.bak)
|
|
|
|
sed -i.bak '/API_EXCLUDE_DOMAINS/d;' /etc/pihole/setupVars.conf
|
|
|
|
# Save setting to file
|
|
|
|
echo "API_EXCLUDE_DOMAINS=${args[2]}" >> /etc/pihole/setupVars.conf
|
|
|
|
}
|
|
|
|
|
|
|
|
SetExcludeClients(){
|
|
|
|
|
|
|
|
# Remove setting from file (create backup setupVars.conf.bak)
|
|
|
|
sed -i.bak '/API_EXCLUDE_CLIENTS/d;' /etc/pihole/setupVars.conf
|
|
|
|
# Save setting to file
|
|
|
|
echo "API_EXCLUDE_CLIENTS=${args[2]}" >> /etc/pihole/setupVars.conf
|
|
|
|
}
|
|
|
|
|
2016-12-11 21:33:27 +00:00
|
|
|
Reboot(){
|
|
|
|
|
|
|
|
reboot
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-12 09:38:21 +00:00
|
|
|
RestartDNS(){
|
|
|
|
|
|
|
|
if [ -x "$(command -v systemctl)" ]; then
|
|
|
|
systemctl restart dnsmasq &> /dev/null
|
|
|
|
else
|
|
|
|
service dnsmasq restart &> /dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-12 12:15:07 +00:00
|
|
|
SetQueryLogOptions(){
|
|
|
|
|
|
|
|
# Remove setting from file (create backup setupVars.conf.bak)
|
|
|
|
sed -i.bak '/API_QUERY_LOG_SHOW/d;' /etc/pihole/setupVars.conf
|
|
|
|
# Save setting to file
|
|
|
|
echo "API_QUERY_LOG_SHOW=${args[2]}" >> /etc/pihole/setupVars.conf
|
|
|
|
}
|
|
|
|
|
2016-11-16 20:34:43 +00:00
|
|
|
for var in "$@"; do
|
|
|
|
case "${var}" in
|
|
|
|
"-p" | "password" ) SetWebPassword;;
|
|
|
|
"-c" | "celsius" ) unit="C"; SetTemperatureUnit;;
|
|
|
|
"-f" | "fahrenheit" ) unit="F"; SetTemperatureUnit;;
|
2016-12-11 15:54:27 +00:00
|
|
|
"setdns" ) SetDNSServers;;
|
2016-12-11 18:30:04 +00:00
|
|
|
"setexcludedomains" ) SetExcludeDomains;;
|
|
|
|
"setexcludeclients" ) SetExcludeClients;;
|
2016-12-11 21:33:27 +00:00
|
|
|
"reboot" ) Reboot;;
|
2016-12-12 09:38:21 +00:00
|
|
|
"restartdns" ) RestartDNS;;
|
2016-12-12 12:15:07 +00:00
|
|
|
"setquerylog" ) SetQueryLogOptions;;
|
2016-11-16 20:34:43 +00:00
|
|
|
"-h" | "--help" ) helpFunc;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [[ $# = 0 ]]; then
|
|
|
|
helpFunc
|
|
|
|
fi
|
|
|
|
|