You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pi-hole/advanced/Scripts/webpage.sh

86 lines
2.3 KiB

8 years ago
#!/usr/bin/env bash
# Pi-hole: A black hole for Internet advertisements
# Network-wide ad blocking via your Raspberry Pi
# http://pi-hole.net
# Web interface settings
8 years ago
#
# 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.
8 years ago
args=("$@")
8 years ago
helpFunc() {
cat << EOM
::: Set admin options for the web interface of pihole
8 years ago
:::
::: Usage: pihole -a [options]
8 years ago
:::
::: Options:
::: -p, password Set web interface password, an empty input will remove any previously set password
8 years ago
::: -c, celsius Set Celcius temperature unit
::: -f, fahrenheit Set Fahrenheit temperature unit
::: -h, --help Show this help dialog
EOM
exit 0
8 years ago
}
SetTemperatureUnit(){
# Remove setting from file (create backup setupVars.conf.bak)
sed -i.bak '/TEMPERATUREUNIT/d' /etc/pihole/setupVars.conf
8 years ago
# Save setting to file
if [[ $unit == "F" ]] ; then
echo "TEMPERATUREUNIT=F" >> /etc/pihole/setupVars.conf
8 years ago
else
echo "TEMPERATUREUNIT=C" >> /etc/pihole/setupVars.conf
8 years ago
fi
}
SetWebPassword(){
# Remove password from file (create backup setupVars.conf.bak)
sed -i.bak '/WEBPASSWORD/d' /etc/pihole/setupVars.conf
# 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
8 years ago
}
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
}
8 years ago
for var in "$@"; do
case "${var}" in
"-p" | "password" ) SetWebPassword;;
"-c" | "celsius" ) unit="C"; SetTemperatureUnit;;
"-f" | "fahrenheit" ) unit="F"; SetTemperatureUnit;;
"setdns" ) SetDNSServers;;
8 years ago
"-h" | "--help" ) helpFunc;;
esac
done
shift
if [[ $# = 0 ]]; then
helpFunc
fi