Added webpage.sh

This commit is contained in:
DL6ER 2016-11-16 21:34:43 +01:00
parent bdad454a0d
commit db278d81e4
2 changed files with 80 additions and 1 deletions

72
advanced/Scripts/webpage.sh Executable file
View file

@ -0,0 +1,72 @@
#!/usr/bin/env bash
# Pi-hole: A black hole for Internet advertisements
# (c) 2015, 2016 by Jacob Salmela
# Network-wide ad blocking via your Raspberry Pi
# http://pi-hole.net
# Whitelists and blacklists domains
#
# 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.
#globals
basename=pihole
piholeDir=/etc/${basename}
helpFunc() {
cat << EOM
::: Set options for the web interface of pihole
:::
::: Usage: pihole -web [options]
:::
::: Options:
::: -p, password Set web interface password
::: -c, celsius Set Celcius temperature unit
::: -f, fahrenheit Set Fahrenheit temperature unit
::: -h, --help Show this help dialog
EOM
exit 1
}
args=("$@")
SetTemperatureUnit(){
# Remove setting from file (create backup setupVars.conf.bak)
sed -i.bak '/temperatureunit/d' /etc/pihole/setupVars.conf
# Save setting to file
if [[ $unit == "F" ]] ; then
echo "temperatureunit=F" >> /etc/pihole/setupVars.conf
else
echo "temperatureunit=C" >> /etc/pihole/setupVars.conf
fi
}
SetWebPassword(){
# Remove password from file (create backup setupVars.conf.bak)
sed -i.bak '/webpassword/d' /etc/pihole/setupVars.conf
# Compute password hash
hash=$(echo -n ${args[2]} | sha256sum | sed 's/\s.*$//')
# Save hash to file
echo "webpassword=${hash}" >> /etc/pihole/setupVars.conf
}
for var in "$@"; do
case "${var}" in
"-p" | "password" ) SetWebPassword;;
"-c" | "celsius" ) unit="C"; SetTemperatureUnit;;
"-f" | "fahrenheit" ) unit="F"; SetTemperatureUnit;;
"-h" | "--help" ) helpFunc;;
esac
done
shift
if [[ $# = 0 ]]; then
helpFunc
fi

9
pihole
View file

@ -22,6 +22,11 @@ if [[ ! $EUID -eq 0 ]];then
fi
fi
webpageFunc() {
/opt/pihole/webpage.sh "$@"
exit 0
}
whitelistFunc() {
"${PI_HOLE_SCRIPT_DIR}"/list.sh "$@"
exit 0
@ -180,7 +185,7 @@ helpFunc() {
::: Control all PiHole specific functions!
:::
::: Usage: pihole [options]
::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage
::: Add -h after -w (whitelist), -b (blacklist), -c (chronometer), or -web (webpage) for more information on usage
:::
::: Options:
::: -w, whitelist Whitelist domains
@ -195,6 +200,7 @@ helpFunc() {
::: -v, version Show current versions
::: -q, query Query the adlists for a specific domain
::: -l, logging Enable or Disable logging (pass 'on' or 'off')
::: -web, webpage Webpage options
::: uninstall Uninstall Pi-Hole from your system :(!
::: status Is Pi-Hole Enabled or Disabled
::: enable Enable Pi-Hole DNS Blocking
@ -228,5 +234,6 @@ case "${1}" in
"disable" ) piholeEnable 0;;
"status" ) piholeStatus "$2";;
"restartdns" ) restartDNS;;
"-web" | "webpage" ) webpageFunc "$@";;
* ) helpFunc;;
esac