]>
Commit | Line | Data |
---|---|---|
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 | ||
22 | main() { | |
23 | # Do not convert anything if we already have some servers set | |
24 | if [ ! -s "/var/ipfire/dns/servers" ]; then | |
25 | local DNS0 DNS1 DNS2 | |
26 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
27 | ||
28 | if [ -s "/var/ipfire/ppp/settings" ]; then | |
29 | eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) | |
30 | elif [ -s "/var/ipfire/dns/settings" ]; then | |
31 | eval $(/usr/local/bin/readhash /var/ipfire/dns/settings) | |
32 | fi | |
33 | ||
34 | local var | |
35 | local i=3 | |
36 | for var in DNS0 DNS1 DNS2; do | |
37 | if [ -n "${!var}" ]; then | |
38 | echo "${i},${!var},,enabled," | |
39 | (( i++ )) | |
40 | fi | |
41 | done > /var/ipfire/dns/servers | |
42 | ||
43 | # Empty the old settings file | |
44 | : > /var/ipfire/dns/settings | |
45 | ||
46 | # Disable using ISP name servers when we already have some configured | |
47 | if [ ${i} -gt 3 ]; then | |
48 | echo "USE_ISP_NAMESERVERS=off" \ | |
49 | >> /var/ipfire/dns/settings | |
50 | fi | |
51 | fi | |
52 | ||
53 | # Convert old unbound settings file | |
54 | if [ -e "/etc/sysconfig/unbound" ]; then | |
55 | local USE_FORWARDERS | |
56 | local ENABLE_SAFE_SEARCH | |
57 | local FORCE_TCP | |
58 | ||
59 | # Read settings | |
60 | eval $(/usr/local/bin/readhash /etc/sysconfig/unbound) | |
61 | ||
62 | # Safe Search | |
63 | if [ "${ENABLE_SAFE_SEARCH}" = "on" ]; then | |
64 | echo "ENABLE_SAFE_SEARCH=${ENABLE_SAFE_SEARCH}" \ | |
65 | >> /var/ipfire/dns/settings | |
66 | fi | |
67 | ||
68 | # Force TCP | |
69 | if [ "${FORCE_TCP}" = "on" ]; then | |
70 | echo "PROTO=TCP" >> /var/ipfire/dns/settings | |
71 | fi | |
72 | ||
73 | # Run in recursor mode | |
74 | if [ "${USE_FORWARDERS}" = "0" ]; then | |
75 | # Remove all servers | |
76 | : > /var/ipfire/dns/servers | |
77 | fi | |
78 | ||
79 | rm -f "/etc/sysconfig/unbound" | |
80 | fi | |
81 | } | |
82 | ||
83 | main "$@" || exit $? |