]> git.ipfire.org Git - ipfire-2.x.git/blame - src/scripts/convert-dns-settings
convert-dns-settings: Remove DNS variable from PPP profiles
[ipfire-2.x.git] / src / scripts / convert-dns-settings
CommitLineData
ecbf6676
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A Linux-based firewall #
5# Copyright (C) 2020 IPFire Team <info@ipfire.org> #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
22main() {
23 # Do not convert anything if we already have some servers set
24 if [ ! -s "/var/ipfire/dns/servers" ]; then
dcc655ef 25 # Array to store all found DNS servers.
5d6ccc7a
AF
26 local SERVERS=()
27
28 # Loop through all PPP profiles
29 local file
30 for file in /var/ipfire/ethernet/settings /var/ipfire/dns/settings /var/ipfire/ppp/settings-*; do
31 if [ -s "${file}" ]; then
32 local DNS0 DNS1 DNS2
33 eval $(/usr/local/bin/readhash "${file}")
34
35 # Add the DNS servers to the array of SERVERS
36 local var
37 for var in DNS0 DNS1 DNS2; do
38 SERVERS+=( "${!var}" )
dcc655ef
SS
39 done
40
3ee6ac9d
AF
41 # Remove DNS, DNS0, DNS1 and DNS2 settings from profile file
42 sed -Ei "/^DNS[012]?=/d" "${file}"
5d6ccc7a
AF
43 fi
44 done
ecbf6676 45
dcc655ef 46 local server
ecbf6676 47 local i=3
5d6ccc7a
AF
48 for server in $(printf "%s\n" "${SERVERS[@]}" | sort -u); do
49 if [ -n "${server}" ]; then
50 echo "${i},${server},,enabled,"
51 (( i++ ))
52 fi
ecbf6676
MT
53 done > /var/ipfire/dns/servers
54
55 # Empty the old settings file
56 : > /var/ipfire/dns/settings
57
58 # Disable using ISP name servers when we already have some configured
59 if [ ${i} -gt 3 ]; then
60 echo "USE_ISP_NAMESERVERS=off" \
61 >> /var/ipfire/dns/settings
62 fi
63 fi
64
c73baee1
SS
65 # Set correct ownership.
66 chown nobody:nobody /var/ipfire/dns/settings
67
ecbf6676
MT
68 # Convert old unbound settings file
69 if [ -e "/etc/sysconfig/unbound" ]; then
70 local USE_FORWARDERS
71 local ENABLE_SAFE_SEARCH
72 local FORCE_TCP
73
74 # Read settings
75 eval $(/usr/local/bin/readhash /etc/sysconfig/unbound)
76
77 # Safe Search
78 if [ "${ENABLE_SAFE_SEARCH}" = "on" ]; then
79 echo "ENABLE_SAFE_SEARCH=${ENABLE_SAFE_SEARCH}" \
80 >> /var/ipfire/dns/settings
81 fi
82
83 # Force TCP
84 if [ "${FORCE_TCP}" = "on" ]; then
85 echo "PROTO=TCP" >> /var/ipfire/dns/settings
86 fi
87
88 # Run in recursor mode
89 if [ "${USE_FORWARDERS}" = "0" ]; then
90 # Remove all servers
91 : > /var/ipfire/dns/servers
92 fi
93
94 rm -f "/etc/sysconfig/unbound"
95 fi
c73baee1
SS
96
97 # Set correct ownership.
98 chown nobody:nobody /var/ipfire/dns/servers
7be4822f
MT
99
100 # Make DHCP leases readable for nobody
d3236de2 101 chmod 644 /etc/unbound/dhcp-leases.conf
ecbf6676
MT
102}
103
104main "$@" || exit $?