2016-11-16 20:34:43 +00:00
|
|
|
#!/usr/bin/env bash
|
2017-09-14 14:24:29 +00:00
|
|
|
# shellcheck disable=SC1090
|
2022-03-16 20:46:15 +00:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
|
2017-09-14 14:24:29 +00:00
|
|
|
|
2016-11-16 20:34:43 +00:00
|
|
|
# Pi-hole: A black hole for Internet advertisements
|
2017-02-22 17:55:20 +00:00
|
|
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
|
|
# Network-wide ad blocking via your own hardware.
|
|
|
|
#
|
2016-11-16 21:13:47 +00:00
|
|
|
# Web interface settings
|
2016-11-16 20:34:43 +00:00
|
|
|
#
|
2017-02-22 17:55:20 +00:00
|
|
|
# This file is copyright under the latest version of the EUPL.
|
|
|
|
# Please see LICENSE file for your rights under this license.
|
|
|
|
|
2023-02-11 12:51:55 +00:00
|
|
|
# TODO - this entire file might be able to be removed in v6
|
|
|
|
|
2016-12-28 02:14:47 +00:00
|
|
|
readonly dnsmasqconfig="/etc/dnsmasq.d/01-pihole.conf"
|
|
|
|
readonly dhcpconfig="/etc/dnsmasq.d/02-pihole-dhcp.conf"
|
2018-04-04 11:12:39 +00:00
|
|
|
readonly FTLconf="/etc/pihole/pihole-FTL.conf"
|
2017-01-25 09:33:25 +00:00
|
|
|
# 03 -> wildcards
|
|
|
|
readonly dhcpstaticconfig="/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
|
2019-10-27 00:07:08 +00:00
|
|
|
readonly dnscustomfile="/etc/pihole/custom.list"
|
2020-05-12 19:02:29 +00:00
|
|
|
readonly dnscustomcnamefile="/etc/dnsmasq.d/05-pihole-custom-cname.conf"
|
2016-12-28 02:14:47 +00:00
|
|
|
|
2019-04-28 19:39:06 +00:00
|
|
|
readonly gravityDBfile="/etc/pihole/gravity.db"
|
|
|
|
|
2020-06-13 19:57:57 +00:00
|
|
|
|
2023-05-07 11:21:23 +00:00
|
|
|
readonly setupVars="/etc/pihole/setupVars.conf"
|
|
|
|
readonly PI_HOLE_BIN_DIR="/usr/local/bin"
|
|
|
|
|
|
|
|
# Root of the web server
|
|
|
|
readonly webroot="/var/www/html"
|
|
|
|
|
|
|
|
# Source utils script
|
2022-04-12 16:13:50 +00:00
|
|
|
utilsfile="/opt/pihole/utils.sh"
|
2022-03-16 17:42:01 +00:00
|
|
|
source "${utilsfile}"
|
|
|
|
|
2017-06-21 11:49:05 +00:00
|
|
|
coltable="/opt/pihole/COL_TABLE"
|
|
|
|
if [[ -f ${coltable} ]]; then
|
2018-07-20 20:57:15 +00:00
|
|
|
source ${coltable}
|
2017-06-21 11:49:05 +00:00
|
|
|
fi
|
|
|
|
|
2016-11-16 20:34:43 +00:00
|
|
|
helpFunc() {
|
2018-07-20 20:57:15 +00:00
|
|
|
echo "Usage: pihole -a [options]
|
2017-05-14 01:11:44 +00:00
|
|
|
Example: pihole -a -p password
|
2023-05-28 06:57:14 +00:00
|
|
|
Set options for the API/Web interface
|
2017-05-14 01:11:44 +00:00
|
|
|
|
|
|
|
Options:
|
2023-05-28 06:57:14 +00:00
|
|
|
-p, password Set API/Web interface password
|
|
|
|
-h, --help Show this help dialog"
|
2018-07-20 20:57:15 +00:00
|
|
|
exit 0
|
2016-11-16 20:34:43 +00:00
|
|
|
}
|
|
|
|
|
2023-05-28 06:57:14 +00:00
|
|
|
# TODO: We can probably remove the reliance on this function too, just tell people to pihole-FTL --config webserver.api.password "password"
|
2017-05-14 01:11:44 +00:00
|
|
|
SetWebPassword() {
|
2018-07-20 20:57:15 +00:00
|
|
|
if (( ${#args[2]} > 0 )) ; then
|
|
|
|
readonly PASSWORD="${args[2]}"
|
|
|
|
readonly CONFIRM="${PASSWORD}"
|
|
|
|
else
|
|
|
|
# Prevents a bug if the user presses Ctrl+C and it continues to hide the text typed.
|
|
|
|
# So we reset the terminal via stty if the user does press Ctrl+C
|
2023-05-28 06:57:14 +00:00
|
|
|
trap '{ echo -e "\nNot changed" ; stty sane ; exit 1; }' INT
|
2018-10-26 18:17:49 +00:00
|
|
|
read -s -r -p "Enter New Password (Blank for no password): " PASSWORD
|
2018-07-20 20:57:15 +00:00
|
|
|
echo ""
|
2017-05-04 09:43:48 +00:00
|
|
|
|
2021-11-25 06:41:40 +00:00
|
|
|
if [ "${PASSWORD}" == "" ]; then
|
2023-02-03 18:55:55 +00:00
|
|
|
setFTLConfigValue "webserver.api.pwhash" "" >/dev/null
|
2021-11-25 06:41:40 +00:00
|
|
|
echo -e " ${TICK} Password Removed"
|
|
|
|
exit 0
|
|
|
|
fi
|
2017-05-04 09:43:48 +00:00
|
|
|
|
2021-11-25 06:41:40 +00:00
|
|
|
read -s -r -p "Confirm Password: " CONFIRM
|
|
|
|
echo ""
|
2018-07-20 20:57:15 +00:00
|
|
|
fi
|
2017-03-27 17:37:19 +00:00
|
|
|
|
2018-07-20 20:57:15 +00:00
|
|
|
if [ "${PASSWORD}" == "${CONFIRM}" ] ; then
|
2023-02-11 12:51:55 +00:00
|
|
|
# pihole-FTL will automatically hash the password
|
|
|
|
setFTLConfigValue "webserver.api.password" "${PASSWORD}" >/dev/null
|
2018-07-20 20:57:15 +00:00
|
|
|
echo -e " ${TICK} New password set"
|
|
|
|
else
|
|
|
|
echo -e " ${CROSS} Passwords don't match. Your password has not been changed"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-11-16 20:34:43 +00:00
|
|
|
}
|
|
|
|
|
2016-12-28 16:25:14 +00:00
|
|
|
main() {
|
2018-07-20 20:57:15 +00:00
|
|
|
args=("$@")
|
|
|
|
|
|
|
|
case "${args[1]}" in
|
|
|
|
"-p" | "password" ) SetWebPassword;;
|
|
|
|
"-h" | "--help" ) helpFunc;;
|
|
|
|
* ) helpFunc;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
shift
|
|
|
|
|
|
|
|
if [[ $# = 0 ]]; then
|
|
|
|
helpFunc
|
|
|
|
fi
|
2016-12-28 16:25:14 +00:00
|
|
|
}
|