]>
git.ipfire.org Git - people/pmueller/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 # Do not convert anything if we already have some servers set
24 if [ ! -s "/var/ipfire/dns/servers" ]; then
25 # Array to store all found DNS servers.
28 # Try to get the DNS servers from ethernet settings file.
30 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
32 # Add the grabbed DNS servers to the servers array.
33 SERVERS
+=($DNS1 $DNS2)
35 # Check if the ppp settings file is not empty.
36 if [ -s "/var/ipfire/ppp/settings" ]; then
37 # Loop though all profile files.
38 for file in /var
/ipfire
/ppp
/settings
*; do
40 eval $
(/usr
/local
/bin
/readhash
$file)
42 # Add the DNS servers to the array of SERVERS.
43 for var
in DNS1 DNS2
; do
44 local server
="${!var}"
46 # Check if the servers array is empty.
47 if [ ${#SERVERS[@]} -eq 0 ]; then
48 # Allways add the first found nameserver to the array.
51 # Check if the current server is allready part ot the array.
52 if [[ ! "${SERVERS[@]}" =~
"${server}" ]]; then
53 # Add the server to the array.
59 # Remove DNS1 and DNS2 settings from profile file.
60 sed -i "/^DNS[12]=/d" $file
62 # Unset the local variables for the next round.
66 elif [ -s "/var/ipfire/dns/settings" ]; then
67 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/dns
/settings
)
72 for server
in "${SERVERS[@]}"; do
73 echo "${i},${server},,enabled,"
75 done > /var
/ipfire
/dns
/servers
77 # Empty the old settings file
78 : > /var
/ipfire
/dns
/settings
80 # Disable using ISP name servers when we already have some configured
81 if [ ${i} -gt 3 ]; then
82 echo "USE_ISP_NAMESERVERS=off" \
83 >> /var
/ipfire
/dns
/settings
87 # Set correct ownership.
88 chown nobody
:nobody
/var
/ipfire
/dns
/settings
90 # Convert old unbound settings file
91 if [ -e "/etc/sysconfig/unbound" ]; then
93 local ENABLE_SAFE_SEARCH
97 eval $
(/usr
/local
/bin
/readhash
/etc
/sysconfig
/unbound
)
100 if [ "${ENABLE_SAFE_SEARCH}" = "on" ]; then
101 echo "ENABLE_SAFE_SEARCH=${ENABLE_SAFE_SEARCH}" \
102 >> /var
/ipfire
/dns
/settings
106 if [ "${FORCE_TCP}" = "on" ]; then
107 echo "PROTO=TCP" >> /var
/ipfire
/dns
/settings
110 # Run in recursor mode
111 if [ "${USE_FORWARDERS}" = "0" ]; then
113 : > /var
/ipfire
/dns
/servers
116 rm -f "/etc/sysconfig/unbound"
119 # Set correct ownership.
120 chown nobody
:nobody
/var
/ipfire
/dns
/servers
122 # Make DHCP leases readable for nobody
123 chown
644 /etc
/unbound
/dhcp-leases.conf