This page does not exist. Create it.

#!/bin/sh

dnsmasq_dbus() {
  method="${1}"
  shift
  dbus-send --system --dest=uk.org.thekelleys.dnsmasq /uk/org/thekelleys/dnsmasq uk.org.thekelleys.${method} "${@}"
}

dnsmasq_clear() {
  dnsmasq_dbus ClearCache
}

dnsmasq_started() {
  #signal sender=:1.2507 -> dest=(null destination) path=/uk/org/thekelleys/dnsmasq; interface=uk.org.thekelleys.dnsmasq; member=Up
  false
}

inet_atoi() {
  OFS=${IFS}
  IFS=.
  set -- ${1}
  num="0x$(printf "%02x" $1 $2 $3 $4)"
  unset IFS
  [ "${OFS}" ] && IFS="${OIFS}"
  printf "%u" "${num}"
}

server_up() {
  ping -c1 -w1 "${1}" > /dev/null 2>&1 || return 1
  return 0
}

config() {
 cat <<EOF
####
#server/server:zone/zone
8.8.8.8/8.8.4.4:
172.16.44.1:cyberleo.net
10.11.12.13:cashnetusa.com/quickquid.co.uk/applyadvanceamerica.com/dollarsdirect.com.au/dollarsdirect.ca/casham.com
EOF
}

dnsmasq_config() {
  sed -e 's/#.*$//; /^[ ]*$/d' | while read line
  do
   servers="${line%%:*}"
   zones="${line##*:}"
   [ "${zones}" ] && zones="$(echo "/${zones}" | sed -e 's#/# string:#g')"

   servers="$(
     OIFS="${IFS}"
     IFS="/"
     for server in ${servers}
     do
       server_up "${server}" || continue
       printf " uint32:%u" "$(inet_atoi "${server}")"
       [ "${zones}" ] && printf "%s" "${zones}"
     done
     unset IFS
     [ "${OIFS}" ] && IFS="${OIFS}"
   )"

   printf "%s" "${servers}"
  done
}

dnsmasq_set() {
  dnsmasq_dbus SetServers $(config | dnsmasq_config)
  dnsmasq_clear
}

dnsmasq_set