]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/convert-dns-settings
2 ###############################################################################
4 # IPFire.org - A Linux-based firewall #
5 # Copyright (C) 2020 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
23 /var
/ipfire
/ethernet
/settings
24 /var
/ipfire
/dns
/settings
25 /var
/ipfire
/ppp
/settings-
*
29 # Do not convert anything if we already have some servers set
30 if [ ! -s "/var/ipfire/dns/servers" ]; then
31 # Array to store all found DNS servers.
34 # Loop through all PPP profiles
36 for file in "${FILES[@]}"; do
37 if [ -s "${file}" ]; then
39 eval $
(/usr
/local
/bin
/readhash
"${file}")
41 # Add the DNS servers to the array of SERVERS
43 for var
in DNS0 DNS1 DNS2
; do
44 SERVERS
+=( "${!var}" )
51 for server
in $
(printf "%s\n" "${SERVERS[@]}" |
sort -u); do
52 if [ -n "${server}" ]; then
53 echo "${i},${server},,enabled,"
56 done > /var
/ipfire
/dns
/servers
58 # Empty the old settings file
59 : > /var
/ipfire
/dns
/settings
61 # Disable using ISP name servers when we already have some configured
62 if [ ${i} -gt 3 ]; then
63 echo "USE_ISP_NAMESERVERS=off" \
64 >> /var
/ipfire
/dns
/settings
68 # Remove all old settings from files
70 for file in "${FILES[@]}"; do
71 # Remove DNS, DNS0, DNS1 and DNS2
72 sed -Ei "/^DNS[012]?=/d" "${file}"
75 # Set correct ownership.
76 chown nobody
:nobody
/var
/ipfire
/dns
/settings
78 # Convert old unbound settings file
79 if [ -e "/etc/sysconfig/unbound" ]; then
81 local ENABLE_SAFE_SEARCH
85 eval $
(/usr
/local
/bin
/readhash
/etc
/sysconfig
/unbound
)
88 if [ "${ENABLE_SAFE_SEARCH}" = "on" ]; then
89 echo "ENABLE_SAFE_SEARCH=${ENABLE_SAFE_SEARCH}" \
90 >> /var
/ipfire
/dns
/settings
94 if [ "${FORCE_TCP}" = "on" ]; then
95 echo "PROTO=TCP" >> /var
/ipfire
/dns
/settings
98 # Run in recursor mode
99 if [ "${USE_FORWARDERS}" = "0" ]; then
101 : > /var
/ipfire
/dns
/servers
104 rm -f "/etc/sysconfig/unbound"
107 # Set correct ownership.
108 chown nobody
:nobody
/var
/ipfire
/dns
/servers
110 # Make DHCP leases readable for nobody
111 chmod 644 /etc
/unbound
/dhcp-leases.conf