aboutsummaryrefslogtreecommitdiffstats
path: root/generate-dnsmasq.sh
blob: 90791b0396556681c2fcb97f1e168d8ca1aa2825 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash

set -e

if [ ! -e /var/run/qubes-service/vpn-exclude-domains ]; then
    rm -f /etc/dnsmasq.d/50-qubes-vpn-exclude.conf
    exit 0
fi

if [ ! -e /rw/config/qubes-vpn-exclude.list ]; then
    echo "# List of domains that should be excluded from the VPN proxy." \
        > /rw/config/qubes-vpn-exclude.list
fi

temp="$(mktemp)"
trap 'rm "$temp"' EXIT

cat > "$temp" <<EOF
# Autogenerated file by qubes-vpn-exclude.

# For ease of use we enable the query log.
log-queries

# We don't want to use resolv.conf as the VPN DNS should handle queries.
no-resolv
no-hosts

domain-needed
bogus-priv

cache-size=0
EOF

source /var/run/qubes/qubes-ns

domains=
while IFS= read -r domain; do
    domain="$(echo "$domain" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
    if [ -n "$domain" ] && [[ "$domain" != "#"* ]]; then
        domains="$domains/$domain"
        echo "ipset=/$domain/qubes-vpn-exclude-4,qubes-vpn-exclude-6" >> "$temp"
        for dns in $NS1 $NS2; do
            echo "server=/$domain/$dns" >> "$temp"
        done
        echo >> "$temp"
    fi
done < /rw/config/qubes-vpn-exclude.list

if [ -z "$domains" ]; then
    rm -f /etc/dnsmasq.d/50-qubes-vpn-exclude.conf
    exit 0
fi

# For all other domains that are not excluded we fall back to the DNS provided
# by the VPN.
for dns in $(cat /var/run/qubes/qubes-vpn-ns); do
    echo "server=$dns" >> "$temp"
done

cp "$temp" /etc/dnsmasq.d/50-qubes-vpn-exclude.conf

Code dump for some of my projects as well as a mirror for other random or interesting projects. You can find my site at jimmy.axenhus.com