]>
git.ipfire.org Git - people/mfischer/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
26 /var
/ipfire
/ppp
/settings-
*
30 # Do not convert anything if we already have some servers set
31 if [ ! -s "/var/ipfire/dns/servers" ]; then
32 # Array to store all found DNS servers.
35 # Loop through all PPP profiles
37 for file in "${FILES[@]}"; do
38 if [ -s "${file}" ]; then
40 eval $
(/usr
/local
/bin
/readhash
"${file}")
42 # Add the DNS servers to the array of SERVERS
44 for var
in DNS0 DNS1 DNS2
; do
45 SERVERS
+=( "${!var}" )
52 for server
in $
(printf "%s\n" "${SERVERS[@]}" |
sort -u); do
53 if [ -n "${server}" ]; then
54 echo "${i},${server},,enabled,"
57 done > /var
/ipfire
/dns
/servers
59 # Empty the old settings file
60 : > /var
/ipfire
/dns
/settings
62 # Enable using ISP name servers when no servers are configured
63 if [ ${i} -eq 3 ]; then
64 echo "USE_ISP_NAMESERVERS=on" \
65 >> /var
/ipfire
/dns
/settings
69 # Remove all old settings from files
71 for file in "${FILES[@]}"; do
72 # Remove DNS, DNS0, DNS1 and DNS2
73 sed -Ei "/^DNS[012]?=/d" "${file}"
76 # Set correct ownership.
77 chown nobody
:nobody
/var
/ipfire
/dns
/settings
79 # Convert old unbound settings file
80 if [ -e "/etc/sysconfig/unbound" ]; then
82 local ENABLE_SAFE_SEARCH
86 eval $
(/usr
/local
/bin
/readhash
/etc
/sysconfig
/unbound
)
89 if [ "${ENABLE_SAFE_SEARCH}" = "on" ]; then
90 echo "ENABLE_SAFE_SEARCH=${ENABLE_SAFE_SEARCH}" \
91 >> /var
/ipfire
/dns
/settings
95 if [ "${FORCE_TCP}" = "on" ]; then
96 echo "PROTO=TCP" >> /var
/ipfire
/dns
/settings
99 # Run in recursor mode
100 if [ "${USE_FORWARDERS}" = "0" ]; then
102 : > /var
/ipfire
/dns
/servers
105 rm -f "/etc/sysconfig/unbound"
108 # Set correct ownership.
109 chown nobody
:nobody
/var
/ipfire
/dns
/servers
111 # Make DHCP leases readable for nobody
112 chmod 644 /etc
/unbound
/dhcp-leases.conf