mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 14:58:08 +00:00
Merge pull request #2540 from pi-hole/release/v4.1
Update development with final v4.1 changes
This commit is contained in:
commit
d24e0a6060
@ -790,77 +790,98 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# dhcpcd is very annoying,
|
# configure networking via dhcpcd
|
||||||
setDHCPCD() {
|
setDHCPCD() {
|
||||||
# but we can append these lines to dhcpcd.conf to enable a static IP
|
# check if the IP is already in the file
|
||||||
echo "interface ${PIHOLE_INTERFACE}
|
if grep -q "${IPV4_ADDRESS}" /etc/dhcpcd.conf; then
|
||||||
static ip_address=${IPV4_ADDRESS}
|
printf " %b Static IP already configured\\n" "${INFO}"
|
||||||
static routers=${IPv4gw}
|
# If it's not,
|
||||||
static domain_name_servers=127.0.0.1" | tee -a /etc/dhcpcd.conf >/dev/null
|
else
|
||||||
|
# we can append these lines to dhcpcd.conf to enable a static IP
|
||||||
|
echo "interface ${PIHOLE_INTERFACE}
|
||||||
|
static ip_address=${IPV4_ADDRESS}
|
||||||
|
static routers=${IPv4gw}
|
||||||
|
static domain_name_servers=127.0.0.1" | tee -a /etc/dhcpcd.conf >/dev/null
|
||||||
|
# Then use the ip command to immediately set the new address
|
||||||
|
ip addr replace dev "${PIHOLE_INTERFACE}" "${IPV4_ADDRESS}"
|
||||||
|
# Also give a warning that the user may need to reboot their system
|
||||||
|
printf " %b Set IP address to %s \\n You may need to restart after the install is complete\\n" "${TICK}" "${IPV4_ADDRESS%/*}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# configure networking ifcfg-xxxx file found at /etc/sysconfig/network-scripts/
|
||||||
|
# this function requires the full path of an ifcfg file passed as an argument
|
||||||
|
setIFCFG() {
|
||||||
|
# Local, named variables
|
||||||
|
local IFCFG_FILE
|
||||||
|
local IPADDR
|
||||||
|
local CIDR
|
||||||
|
IFCFG_FILE=$1
|
||||||
|
printf -v IPADDR "%s" "${IPV4_ADDRESS%%/*}"
|
||||||
|
# check if the desired IP is already set
|
||||||
|
if grep -Eq "${IPADDR}(\\b|\\/)" "${IFCFG_FILE}"; then
|
||||||
|
printf " %b Static IP already configured\\n" "${INFO}"
|
||||||
|
# Otherwise,
|
||||||
|
else
|
||||||
|
# Put the IP in variables without the CIDR notation
|
||||||
|
printf -v CIDR "%s" "${IPV4_ADDRESS##*/}"
|
||||||
|
# Backup existing interface configuration:
|
||||||
|
cp "${IFCFG_FILE}" "${IFCFG_FILE}".pihole.orig
|
||||||
|
# Build Interface configuration file using the GLOBAL variables we have
|
||||||
|
{
|
||||||
|
echo "# Configured via Pi-hole installer"
|
||||||
|
echo "DEVICE=$PIHOLE_INTERFACE"
|
||||||
|
echo "BOOTPROTO=none"
|
||||||
|
echo "ONBOOT=yes"
|
||||||
|
echo "IPADDR=$IPADDR"
|
||||||
|
echo "PREFIX=$CIDR"
|
||||||
|
echo "GATEWAY=$IPv4gw"
|
||||||
|
echo "DNS1=$PIHOLE_DNS_1"
|
||||||
|
echo "DNS2=$PIHOLE_DNS_2"
|
||||||
|
echo "USERCTL=no"
|
||||||
|
}> "${IFCFG_FILE}"
|
||||||
|
# Use ip to immediately set the new address
|
||||||
|
ip addr replace dev "${PIHOLE_INTERFACE}" "${IPV4_ADDRESS}"
|
||||||
|
# If NetworkMangler command line interface exists and ready to mangle,
|
||||||
|
if is_command nmcli && nmcli general status &> /dev/null; then
|
||||||
|
# Tell NetworkManagler to read our new sysconfig file
|
||||||
|
nmcli con load "${IFCFG_FILE}" > /dev/null
|
||||||
|
fi
|
||||||
|
# Show a warning that the user may need to restart
|
||||||
|
printf " %b Set IP address to %s\\n You may need to restart after the install is complete\\n" "${TICK}" "${IPV4_ADDRESS%%/*}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
setStaticIPv4() {
|
setStaticIPv4() {
|
||||||
# Local, named variables
|
# Local, named variables
|
||||||
local IFCFG_FILE
|
local IFCFG_FILE
|
||||||
local IPADDR
|
local CONNECTION_NAME
|
||||||
local CIDR
|
|
||||||
# For the Debian family, if dhcpcd.conf exists,
|
# For the Debian family, if dhcpcd.conf exists,
|
||||||
if [[ -f "/etc/dhcpcd.conf" ]]; then
|
if [[ -f "/etc/dhcpcd.conf" ]]; then
|
||||||
# check if the IP is already in the file
|
# configure networking via dhcpcd
|
||||||
if grep -q "${IPV4_ADDRESS}" /etc/dhcpcd.conf; then
|
setDHCPCD
|
||||||
printf " %b Static IP already configured\\n" "${INFO}"
|
return 0
|
||||||
# If it's not,
|
fi
|
||||||
else
|
# If a DHCPCD config file was not found, check for an ifcfg config file based on interface name
|
||||||
# set it using our function
|
if [[ -f "/etc/sysconfig/network-scripts/ifcfg-${PIHOLE_INTERFACE}" ]];then
|
||||||
setDHCPCD
|
|
||||||
# Then use the ip command to immediately set the new address
|
|
||||||
ip addr replace dev "${PIHOLE_INTERFACE}" "${IPV4_ADDRESS}"
|
|
||||||
# Also give a warning that the user may need to reboot their system
|
|
||||||
printf " %b Set IP address to %s \\n You may need to restart after the install is complete\\n" "${TICK}" "${IPV4_ADDRESS%/*}"
|
|
||||||
fi
|
|
||||||
# If it's not Debian, check if it's the Fedora family by checking for the file below
|
|
||||||
elif [[ -f "/etc/sysconfig/network-scripts/ifcfg-${PIHOLE_INTERFACE}" ]];then
|
|
||||||
# If it exists,
|
# If it exists,
|
||||||
IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${PIHOLE_INTERFACE}
|
IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${PIHOLE_INTERFACE}
|
||||||
printf -v IPADDR "%s" "${IPV4_ADDRESS%%/*}"
|
setIFCFG "${IFCFG_FILE}"
|
||||||
# check if the desired IP is already set
|
return 0
|
||||||
if grep -Eq "${IPADDR}(\\b|\\/)" "${IFCFG_FILE}"; then
|
|
||||||
printf " %b Static IP already configured\\n" "${INFO}"
|
|
||||||
# Otherwise,
|
|
||||||
else
|
|
||||||
# Put the IP in variables without the CIDR notation
|
|
||||||
printf -v CIDR "%s" "${IPV4_ADDRESS##*/}"
|
|
||||||
# Backup existing interface configuration:
|
|
||||||
cp "${IFCFG_FILE}" "${IFCFG_FILE}".pihole.orig
|
|
||||||
# Build Interface configuration file using the GLOBAL variables we have
|
|
||||||
{
|
|
||||||
echo "# Configured via Pi-hole installer"
|
|
||||||
echo "DEVICE=$PIHOLE_INTERFACE"
|
|
||||||
echo "BOOTPROTO=none"
|
|
||||||
echo "ONBOOT=yes"
|
|
||||||
echo "IPADDR=$IPADDR"
|
|
||||||
echo "PREFIX=$CIDR"
|
|
||||||
echo "GATEWAY=$IPv4gw"
|
|
||||||
echo "DNS1=$PIHOLE_DNS_1"
|
|
||||||
echo "DNS2=$PIHOLE_DNS_2"
|
|
||||||
echo "USERCTL=no"
|
|
||||||
}> "${IFCFG_FILE}"
|
|
||||||
# Use ip to immediately set the new address
|
|
||||||
ip addr replace dev "${PIHOLE_INTERFACE}" "${IPV4_ADDRESS}"
|
|
||||||
# If NetworkMangler command line interface exists and ready to mangle,
|
|
||||||
if is_command nmcli && nmcli general status &> /dev/null; then
|
|
||||||
# Tell NetworkManagler to read our new sysconfig file
|
|
||||||
nmcli con load "${IFCFG_FILE}" > /dev/null
|
|
||||||
fi
|
|
||||||
# Show a warning that the user may need to restart
|
|
||||||
printf " %b Set IP address to %s\\n You may need to restart after the install is complete\\n" "${TICK}" "${IPV4_ADDRESS%%/*}"
|
|
||||||
fi
|
|
||||||
# If all that fails,
|
|
||||||
else
|
|
||||||
# show an error and exit
|
|
||||||
printf " %b Warning: Unable to locate configuration file to set static IPv4 address\\n" "${INFO}"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
# if an ifcfg config does not exists for the interface name, try the connection name via network manager
|
||||||
|
if is_command nmcli && nmcli general status &> /dev/null; then
|
||||||
|
CONNECTION_NAME=$(nmcli dev show "${PIHOLE_INTERFACE}" | grep 'GENERAL.CONNECTION' | cut -d: -f2 | sed 's/^System//' | xargs | tr ' ' '_')
|
||||||
|
if [[ -f "/etc/sysconfig/network-scripts/ifcfg-${CONNECTION_NAME}" ]];then
|
||||||
|
# If it exists,
|
||||||
|
IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${CONNECTION_NAME}
|
||||||
|
setIFCFG "${IFCFG_FILE}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# If previous conditions failed, show an error and exit
|
||||||
|
printf " %b Warning: Unable to locate configuration file to set static IPv4 address\\n" "${INFO}"
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check an IP address to see if it is a valid one
|
# Check an IP address to see if it is a valid one
|
||||||
|
@ -206,7 +206,7 @@ gravity_SetDownloadOptions() {
|
|||||||
activeDomains[$i]="${saveLocation}"
|
activeDomains[$i]="${saveLocation}"
|
||||||
|
|
||||||
# Default user-agent (for Cloudflare's Browser Integrity Check: https://support.cloudflare.com/hc/en-us/articles/200170086-What-does-the-Browser-Integrity-Check-do-)
|
# Default user-agent (for Cloudflare's Browser Integrity Check: https://support.cloudflare.com/hc/en-us/articles/200170086-What-does-the-Browser-Integrity-Check-do-)
|
||||||
agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36"
|
agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"
|
||||||
|
|
||||||
# Provide special commands for blocklists which may need them
|
# Provide special commands for blocklists which may need them
|
||||||
case "${domain}" in
|
case "${domain}" in
|
||||||
@ -579,7 +579,7 @@ gravity_ParseBlacklistDomains() {
|
|||||||
mv "${piholeDir}/${whitelistMatter}" "${piholeDir}/${accretionDisc}"
|
mv "${piholeDir}/${whitelistMatter}" "${piholeDir}/${accretionDisc}"
|
||||||
else
|
else
|
||||||
# There was no whitelist file, so use preEventHorizon instead of whitelistMatter.
|
# There was no whitelist file, so use preEventHorizon instead of whitelistMatter.
|
||||||
mv "${piholeDir}/${preEventHorizon}" "${piholeDir}/${accretionDisc}"
|
cp "${piholeDir}/${preEventHorizon}" "${piholeDir}/${accretionDisc}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Move the file over as /etc/pihole/gravity.list so dnsmasq can use it
|
# Move the file over as /etc/pihole/gravity.list so dnsmasq can use it
|
||||||
|
Loading…
Reference in New Issue
Block a user