mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 10:43:55 +00:00
Merge pull request #976 from pi-hole/websettingspage
Add necessary backend for the new "Settings" page of the web UI
This commit is contained in:
commit
c340668870
1 changed files with 112 additions and 0 deletions
|
@ -57,11 +57,123 @@ SetWebPassword(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# Replace within actual dnsmasq config file
|
||||||
|
sed -i '/server=/d;' /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
echo "server=${args[2]}" >> /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
echo "server=${args[3]}" >> /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
|
||||||
|
# Restart dnsmasq to load new configuration
|
||||||
|
RestartDNS
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
Reboot(){
|
||||||
|
|
||||||
|
nohup bash -c "sleep 5; reboot" &> /dev/null </dev/null &
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
RestartDNS(){
|
||||||
|
|
||||||
|
if [ -x "$(command -v systemctl)" ]; then
|
||||||
|
systemctl restart dnsmasq &> /dev/null
|
||||||
|
else
|
||||||
|
service dnsmasq restart &> /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
EnableDHCP(){
|
||||||
|
|
||||||
|
# Remove setting from file (create backup setupVars.conf.bak)
|
||||||
|
sed -i.bak '/DHCP_/d;' /etc/pihole/setupVars.conf
|
||||||
|
echo "DHCP_ACTIVE=true" >> /etc/pihole/setupVars.conf
|
||||||
|
echo "DHCP_START=${args[2]}" >> /etc/pihole/setupVars.conf
|
||||||
|
echo "DHCP_END=${args[3]}" >> /etc/pihole/setupVars.conf
|
||||||
|
echo "DHCP_ROUTER=${args[4]}" >> /etc/pihole/setupVars.conf
|
||||||
|
|
||||||
|
# Remove setting from file
|
||||||
|
sed -i '/dhcp-/d;' /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
# Save setting to file
|
||||||
|
echo "dhcp-range=${args[2]},${args[3]},infinite" >> /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
echo "dhcp-option=option:router,${args[4]}" >> /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
# Changes the behaviour from strict RFC compliance so that DHCP requests on unknown leases from unknown hosts are not ignored. This allows new hosts to get a lease without a tedious timeout under all circumstances. It also allows dnsmasq to rebuild its lease database without each client needing to reacquire a lease, if the database is lost.
|
||||||
|
echo "dhcp-authoritative" >> /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
# Use the specified file to store DHCP lease information
|
||||||
|
echo "dhcp-leasefile=/etc/pihole/dhcp.leases" >> /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
# Suppress logging of the routine operation of these protocols. Errors and problems will still be logged, though.
|
||||||
|
echo "quiet-dhcp" >> /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
echo "quiet-dhcp6" >> /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
|
||||||
|
RestartDNS
|
||||||
|
}
|
||||||
|
|
||||||
|
DisableDHCP(){
|
||||||
|
|
||||||
|
# Remove setting from file (create backup setupVars.conf.bak)
|
||||||
|
sed -i.bak '/DHCP_ACTIVE/d;' /etc/pihole/setupVars.conf
|
||||||
|
echo "DHCP_ACTIVE=false" >> /etc/pihole/setupVars.conf
|
||||||
|
|
||||||
|
# Remove setting from file
|
||||||
|
sed -i '/dhcp-/d;' /etc/dnsmasq.d/01-pihole.conf
|
||||||
|
|
||||||
|
RestartDNS
|
||||||
|
}
|
||||||
|
|
||||||
|
SetWebUILayout(){
|
||||||
|
|
||||||
|
# Remove setting from file (create backup setupVars.conf.bak)
|
||||||
|
sed -i.bak '/WEBUIBOXEDLAYOUT/d;' /etc/pihole/setupVars.conf
|
||||||
|
echo "WEBUIBOXEDLAYOUT=${args[2]}" >> /etc/pihole/setupVars.conf
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
for var in "$@"; do
|
for var in "$@"; do
|
||||||
case "${var}" in
|
case "${var}" in
|
||||||
"-p" | "password" ) SetWebPassword;;
|
"-p" | "password" ) SetWebPassword;;
|
||||||
"-c" | "celsius" ) unit="C"; SetTemperatureUnit;;
|
"-c" | "celsius" ) unit="C"; SetTemperatureUnit;;
|
||||||
"-f" | "fahrenheit" ) unit="F"; SetTemperatureUnit;;
|
"-f" | "fahrenheit" ) unit="F"; SetTemperatureUnit;;
|
||||||
|
"setdns" ) SetDNSServers;;
|
||||||
|
"setexcludedomains" ) SetExcludeDomains;;
|
||||||
|
"setexcludeclients" ) SetExcludeClients;;
|
||||||
|
"reboot" ) Reboot;;
|
||||||
|
"restartdns" ) RestartDNS;;
|
||||||
|
"setquerylog" ) SetQueryLogOptions;;
|
||||||
|
"enabledhcp" ) EnableDHCP;;
|
||||||
|
"disabledhcp" ) DisableDHCP;;
|
||||||
|
"layout" ) SetWebUILayout;;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-h" | "--help" ) helpFunc;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue