many many changes!

This commit is contained in:
Alter Step
2017-02-09 02:01:13 +01:00
parent e268f23c3d
commit 44908fa7de
35 changed files with 520 additions and 458 deletions
@@ -2,6 +2,7 @@
. ./common.inc
rm -f "$BLOCKED_QUERY_LOG_FILE"
rm -f "$QUERY_LOG_FILE"
rm -f "$DEBUG_LOG_FILE"
find -x "$RESOLVERS_LIST_STATE" -type f -mtime +1 -exec rm -f {} \; 2>/dev/null
@@ -1,5 +1,5 @@
CURRENT_VERSION=5
CURRENT_VERSION=6
DNSCRYPT_USR_BASE_DIR='/Library/PreferencePanes/DNSCrypt.prefPane/Contents/Resources/usr'
DNSCRYPT_VAR_BASE_DIR='/Library/Application Support/DNSCrypt'
@@ -19,6 +19,7 @@ DNSCRYPT_FILE="${CONTROL_DIR}/dnscrypt"
HANDLERS_LOCK_FILE="${DNSCRYPT_VAR_RUN_BASE_DIR}/dnscrypt-handlers.lock"
DNSCRYPT_PROXY_PLUGINS_BASE_FILE="${CONTROL_DIR}/plugin"
STATIC_RESOLVERS_FILE="${CONTROL_DIR}/static-resolvers"
BLOCKED_QUERY_LOGGING_FILE="${CONTROL_DIR}/blocked-query-logging"
DEBUG_ENABLED_FILE="${CONTROL_DIR}/debug.enabled"
@@ -27,7 +28,9 @@ CACHE_FILE="${CONTROL_DIR}/plugin-cache.enabled"
QUERY_LOGGING_FILE="${CONTROL_DIR}/plugin-query-logging.enabled"
BLOCKING_FILE="${CONTROL_DIR}/plugin-blocking.enabled"
AAAA_BLOCKING_FILE="${CONTROL_DIR}/plugin-aaaa-blocking.enabled"
FORWARDING_FILE="${CONTROL_DIR}/plugin-forwarding.enabled"
BLOCKED_QUERY_LOG_FILE="${DNSCRYPT_LOG_BASE_DIR}/dnscrypt-blocked-query.log"
QUERY_LOG_FILE="${DNSCRYPT_LOG_BASE_DIR}/dnscrypt-query.log"
DEBUG_LOG_FILE="${DNSCRYPT_LOG_BASE_DIR}/dnscrypt-osxclient-debug.log"
DEBUG_LOG_FILE_LOCK="${DEBUG_LOG_FILE}.lock"
@@ -52,10 +55,6 @@ RESOLVERS_LIST_STATE="${STATES_DIR}/resolvers-updated"
INTERFACE_PROXY="127.0.0.54"
INTERFACE_PROXY_MASK="24"
DOMAINS_EXCEPTIONS='
belkin corp domain example home host invalid lan local localdomain test freebox.fr fritz.box nowtv.com routerlogin.net l onion
'
export PATH="${DNSCRYPT_USR_BASE_DIR}/sbin:${DNSCRYPT_USR_BASE_DIR}/bin:${DNSCRYPT_USR_BASE_DIR}/scripts:$PATH"
init_interfaces() {
@@ -1,63 +0,0 @@
#! /bin/sh
RESOLVER_DIR='/etc/resolver'
. ./common.inc
[ -r "$EXCEPTIONS_FILE" ] &&
DOMAINS_EXCEPTIONS="$(cat "$EXCEPTIONS_FILE") $DOMAINS_EXCEPTIONS"
get_gw() {
route -n get default | while read line; do
case "$line" in
gateway:\ *)
echo "$line" | sed 's/ *gateway: *//'
return
;;
esac
done
}
get_dhcp_dns() {
cat "${STATES_DIR}/dhcp-dns" 2> /dev/null
}
remove_old_exceptions() {
local found
find -x "$RESOLVER_DIR" -type f -print | {
while read file; do
found='no'
for domain in $DOMAINS_EXCEPTIONS; do
[ "$file" = "${RESOLVER_DIR}/${domain}" ] && found='yes' && break
done
[ "$found" = 'no' ] || continue
fgrep -ci 'automatically generated by the dnscrypt user interface' \
$file > /dev/null 2>&1 || continue
rm -f "$file"
done
}
}
name_servers=$(./get-static-resolvers.sh || get_dhcp_dns || get_gw)
[ x"$name_servers" = 'x' ] && exit 0
default_domain=$(./get-current-default-domain.sh)
mkdir -p "$RESOLVER_DIR" || exit 1
remove_old_exceptions
name_server="$gw"
for domain in $DOMAINS_EXCEPTIONS; do
if [ x"$default_domain" != 'x' ]; then
echo "$domain" | grep -c ".*${default_domain}" > /dev/null
[ $? = 0 ] && continue
fi
echo '# automatically generated by the dnscrypt user interface' \
> "${RESOLVER_DIR}/${domain}"
for name_server in $name_servers; do
echo "nameserver ${name_server}" >> "${RESOLVER_DIR}/${domain}"
done
done
exit 0
@@ -1,13 +0,0 @@
#! /bin/sh
RESOLVER_DIR='/etc/resolver'
. ./common.inc
[ -r "$EXCEPTIONS_FILE" ] &&
DOMAINS_EXCEPTIONS="$(cat "$EXCEPTIONS_FILE") $DOMAINS_EXCEPTIONS"
for domain in $DOMAINS_EXCEPTIONS; do
rm -f "${RESOLVER_DIR}/${domain}"
done
exit 0
@@ -0,0 +1,9 @@
#! /bin/sh
. ./common.inc
if [ -e "$BLOCKED_QUERY_LOGGING_FILE" ]; then
echo 'yes'
else
echo 'no'
fi
@@ -2,9 +2,22 @@
. ./common.inc
ifs=$(ifconfig -a | \
awk '/^[^ :]*:/ { sub(/:.*$/,empty); iface=$0 } /status: active/ { print iface }')
ifs=$(echo $ifs)
get_ifs() {
ifs_save="$IFS"
IFS=''
ifconfig -a | while read line; do
nif=$(echo "$line" | egrep -i '^[^ ]+:\s+flags' | sed 's/:.*$//')
isact=$(echo "$line" | egrep -i 'status:\s*active')
if [ -n "$nif" ]; then
cif="$nif"
elif [ -n "$isact" -a -n "$cif" ]; then
echo $cif
fi
done
IFS="$ifs_save"
}
ifs=$(get_ifs)
typeset -A found
ips=""
@@ -15,3 +15,5 @@ if [ "$servers" = "" ]; then
else
echo "$servers" | sed 's/^ *//;s/ *$//' > "$STATIC_RESOLVERS_FILE"
fi
exec ./switch-exceptions-on.sh
@@ -3,4 +3,3 @@
. ./common.inc
rm -f "$AAAA_BLOCKING_FILE"
@@ -10,6 +10,9 @@ plugin_args=''
[ -s "$BLACKLIST_DOMAINS_FILE" ] && \
plugin_args="${plugin_args},--domains='${BLACKLIST_DOMAINS_FILE}'"
[ -e "$BLOCKED_QUERY_LOGGING_FILE" ] && \
plugin_args="${plugin_args},--logfile='${BLOCKED_QUERY_LOG_FILE}'"
[ -z "$plugin_args" ] && exec ./switch-blacklists-off.sh
echo "libdcplugin_example_ldns_blocking.la${plugin_args}" > \
@@ -0,0 +1,9 @@
#! /bin/sh
. ./common.inc
rm -f "$BLOCKED_QUERY_LOGGING_FILE"
exec ./switch-blacklists-on.sh
@@ -0,0 +1,7 @@
#! /bin/sh
. ./common.inc
touch "$BLOCKED_QUERY_LOGGING_FILE"
exec ./switch-blacklists-on.sh
@@ -0,0 +1,5 @@
#! /bin/sh
. ./common.inc
rm -f "$FORWARDING_FILE"
@@ -0,0 +1,39 @@
#! /bin/sh
. ./common.inc
get_gw() {
route -n get default | while read line; do
case "$line" in
gateway:\ *)
echo "$line" | sed 's/ *gateway: *//'
return
;;
esac
done
}
get_dhcp_dns() {
cat "$DHCP_DNS_FILE" 2> /dev/null | egrep -i '^[0-9a-f:.]+$'
}
[ -s "$EXCEPTIONS_FILE" ] || exec ./switch-exceptions-off.sh
domains=''
while read domain; do
domains="${domain} ${domains}"
done < "$EXCEPTIONS_FILE"
[ -z "$domains" ] && exec ./switch-exceptions-off.sh
resolvers=$(./get-static-resolvers.sh || get_dhcp_dns || get_gw)
[ -z "$resolvers" ] && exec ./switch-exceptions-off.sh
plugin_args=''
plugin_args="${plugin_args},--domains='${domains}'"
plugin_args="${plugin_args},--resolvers='${resolvers}'"
echo "libdcplugin_example_ldns_forwarding.la${plugin_args}" > \
"$FORWARDING_FILE"
touch "$PLUGINS_ENABLED_FILE"
@@ -8,8 +8,10 @@ if [ ! -s "$BLACKLIST_DOMAINS_TMP_FILE" ]; then
fi
tr -s '[:blank:]' '\n' < "$BLACKLIST_DOMAINS_TMP_FILE" | \
egrep -vi '^(apple[.]com)$' > \
egrep -i '^[*]?[.]?[^.][a-z0-9_.-]+[*]?$' > \
"${BLACKLIST_DOMAINS_TMP_FILE}~" &&
mv "${BLACKLIST_DOMAINS_TMP_FILE}~" "$BLACKLIST_DOMAINS_FILE"
rm -f "$BLACKLIST_DOMAINS_TMP_FILE"
exec ./switch-blacklists-on.sh
@@ -7,8 +7,11 @@ if [ ! -s "$BLACKLIST_IPS_TMP_FILE" ]; then
exec ./switch-blacklists-on.sh
fi
tr -s '[:blank:]' '\n' \
< "$BLACKLIST_IPS_TMP_FILE" > "${BLACKLIST_IPS_TMP_FILE}~" &&
tr -s '[:blank:]' '\n' < "$BLACKLIST_IPS_TMP_FILE" | \
egrep -i '^[0-9a-fA-F:.]+$' > \
"${BLACKLIST_IPS_TMP_FILE}~" &&
mv "${BLACKLIST_IPS_TMP_FILE}~" "$BLACKLIST_IPS_FILE"
rm -f "$BLACKLIST_IPS_TMP_FILE"
exec ./switch-blacklists-on.sh
@@ -4,9 +4,14 @@
if [ ! -s "$EXCEPTIONS_TMP_FILE" ]; then
rm -f "$EXCEPTIONS_FILE" "$EXCEPTIONS_TMP_FILE"
exit 0
exec ./switch-exceptions-off.sh
fi
tr -s '[:blank:]' '\n' < "$EXCEPTIONS_TMP_FILE" | \
sed -e 's/^ *[*]*[.]*//' -e 's/ *$//' | \
egrep -i '^\s*[0-9a-z_.-]+\s*$' > "${EXCEPTIONS_TMP_FILE}~" &&
mv "${EXCEPTIONS_TMP_FILE}~" "$EXCEPTIONS_FILE"
rm -f "$EXCEPTIONS_TMP_FILE"
exec ./switch-exceptions-on.sh