Skip to content

Instantly share code, notes, and snippets.

@y8s
Last active September 11, 2024 16:20
Show Gist options
  • Save y8s/3b983f54a3679eccbaf452759278a785 to your computer and use it in GitHub Desktop.
Save y8s/3b983f54a3679eccbaf452759278a785 to your computer and use it in GitHub Desktop.
pihole-timeout.sh
#!/bin/bash
# Simple script to change admin login timeout in pihole version 5.17 and up.
# Note that some versions of pihole used 'loginpage.php' instead of 'login.php'
# make the script executeable by typing:
# chmod +x pihole-timeout.sh
# run it by typing:
# sudo ./pihole-timeout.sh
# Check if user is using sudo or is root:
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo ""
echo -e "Please run script with \033[0;1msudo "$0"\033[0m or as root."
echo ""
exit $?
fi
# Allow custom user input, defaulting to 30:
read -p "Enter admin login timeout in days (default is 7): " -i 30 -e timeoutdays
# Set up variables with old and new lines (and variables for timeout)
origpassstring='time() + 60 \* 60 \* 24 \* 7' # original string in password.php
newpassstring="time() + 60 \* 60 \* 24 \* $timeoutdays" # replacement string for password.php
origloginstring="Remember me for 7 days" # original string in login.php
newloginstring="Remember me for $timeoutdays days" # replacement string for login.php
# do the replacements and save a backup with the extension .bak
sed -i.bak 's/'"$origpassstring"'/'"$newpassstring"'/g' /var/www/html/admin/scripts/pi-hole/php/password.php
sed -i.bak 's/'"$origloginstring"'/'"$newloginstring"'/g' /var/www/html/admin/login.php
echo "User will remain logged in for" $timeoutdays "days." # visual feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment