]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/convert-dns-settings
e9d4de86baac587a81b180f9165895b4cb70f25c
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 current server is allready part
48 for element
in "${SERVERS[@]}"; do
49 [[ $element == $server ]] && continue
55 # Remove DNS1 and DNS2 settings from profile file.
56 sed -i "/^DNS[12]?=/d" $file
59 elif [ -s "/var/ipfire/dns/settings" ]; then
60 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/dns
/settings
)
65 for server
in "${SERVERS[@]}"; do
66 echo "${i},${server},,enabled,"
68 done > /var
/ipfire
/dns
/servers
70 # Empty the old settings file
71 : > /var
/ipfire
/dns
/settings
73 # Disable using ISP name servers when we already have some configured
74 if [ ${i} -gt 3 ]; then
75 echo "USE_ISP_NAMESERVERS=off" \
76 >> /var
/ipfire
/dns
/settings
80 # Set correct ownership.
81 chown nobody
:nobody
/var
/ipfire
/dns
/settings
83 # Convert old unbound settings file
84 if [ -e "/etc/sysconfig/unbound" ]; then
86 local ENABLE_SAFE_SEARCH
90 eval $
(/usr
/local
/bin
/readhash
/etc
/sysconfig
/unbound
)
93 if [ "${ENABLE_SAFE_SEARCH}" = "on" ]; then
94 echo "ENABLE_SAFE_SEARCH=${ENABLE_SAFE_SEARCH}" \
95 >> /var
/ipfire
/dns
/settings
99 if [ "${FORCE_TCP}" = "on" ]; then
100 echo "PROTO=TCP" >> /var
/ipfire
/dns
/settings
103 # Run in recursor mode
104 if [ "${USE_FORWARDERS}" = "0" ]; then
106 : > /var
/ipfire
/dns
/servers
109 rm -f "/etc/sysconfig/unbound"
112 # Set correct ownership.
113 chown nobody
:nobody
/var
/ipfire
/dns
/servers
115 # Make DHCP leases readable for nobody
116 chown
644 /etc
/unbound
/dhcp-leases.conf