#!/bin/sh to_subnet() { pref=$1 case "$pref" in *.*.*.*) echo $pref/32;; *.*.*) echo $pref.0/24;; *.*) echo $pref.0.0/16;; *) echo $pref.0.0.0/8;; esac } gen_stub_zones() { local zonefile ip local fwdtype="stub" if [ -n "$FORWARDONLY" ]; then fwdtype="forward" fi for zonefile in "$root"/etc/dnscache/servers/*; do local zone=${zonefile##*/} if [ "$zone" = "@" ] || [ "$zone" = '*' ]; then continue fi echo "${fwdtype}-zone:" echo -e "\tname: ${zone}" for ip in $(cat $zonefile); do echo -e "\t${fwdtype}-addr: $ip" done echo "" done } root=${root:-/} while getopts "r:" opt; do case "$opt" in 'r') root="$OPTARG";; esac done confd="$root"/etc/conf.d/dnscache if [ -r "$confd" ]; then . "$confd" fi interface="$IP" outgoing_interface="$IPSEND" echo $IPSEND echo $IP echo $FORWARDONLY for i in "$root"/etc/dnscache/ip/*; do [ -f "$i" ] || continue access_control="$access_control $(to_subnet ${i##*/})" done echo -e "\tinterface: $IP\n" echo -e "\toutgoing-interface: $IPSEND\n" for i in $access_control; do echo -e "\taccess-control: $i allow" done echo "" gen_stub_zones