#!/bin/bash # set -e # variables DNSMASQ_DIR="/var/lib/llxcfg-dnsmasq" HOSTS_DIR="$DNSMASQ_DIR/hosts" CONF_DIR="$DNSMASQ_DIR/config" DB_HOSTS="${HOSTS_DIR}/hosts-reg" DB_HOSTS_UNREG="${HOSTS_DIR}/hosts-unreg" DB_SRV_ALIAS="$CONF_DIR/cname-server" DB_HOST_ALIAS="$CONF_DIR/cname-hosts" DB_EXTRA_NS="$CONF_DIR/extra-ns" DB_DHCP="$DNSMASQ_DIR/macs/all-hosts" DNS_CAP_HOSTS="$HOSTS_DIR/cap.hosts" DNS_CAP_CONF="/etc/dnsmasq.d/cap.conf" ALL_ALIAS="" VAR_LIST="SRV_DOMAIN DNS_EXTRA_NS SRV_BITMASK SRV_IP SRV_FQDN CAP_NET_ADDRESS CAP_NET_DOMAIN CAP_NET_CAPNAME" LLX_GETVAR="/usr/sbin/llxcfg-showvars" # libreria LIB_FILE="/usr/share/lliurex/lliurex-srv-common/lliurex-netfuncs.sh" [ -e "$LIB_FILE" ] || exit 1 . $LIB_FILE dbgen_hosts_alias(){ HOST_NUM=1 HOST_MAX=`get_dhcp_host_max` while [ $HOST_NUM -le $HOST_MAX ] ; do HOST_ALIAS="$(get_dhcp_host_alias $HOST_NUM)" if [ "$HOST_ALIAS" ] ; then HOST_NAME="`get_dhcp_host_name ${HOST_NUM}`" HOST_IP="$(get_dhcp_host_address {HOST_NUM})" for alias in ${HOST_ALIAS}; do if ! echo " $HOST_NAME $ALL_ALIAS " |grep -q " $alias " ; then echo "cname=${alias},$HOST_NAME" ALL_ALIAS="$ALL_ALIAS $alias" fi done fi HOST_NUM=$((${HOST_NUM}+1)) done } get_extra_ns(){ [ "$DNS_EXTRA_NS" ] || return 0 echo "$DNS_EXTRA_NS" |tr " " "\n" |sed -e "/^$/d;s%^%server=%" } gen_cap_hosts(){ n=1 while [ $n -le 254 ] ; do echo -e "${CAP_NET_ADDRESS%.*}.$n\tnode-$n.$CAP_NET_CAPNAME.$CAP_NET_DOMAIN" n=$(($n + 1)) done return 0 } ######## # main # ######## # lee DNS_DOMAIN y DNS_EXTERNAL_NS y VHOST_NAMES [ -x ${LLX_GETVAR} ] && eval `${LLX_GETVAR} ${VAR_LIST}` SRV_ALIASES="$(get_dhcp_host_alias 0)" ALL_ALIAS="$SRV_ALIASES" # generate upstream server list get_extra_ns |skel-install "$DB_EXTRA_NS" # generate server-alias db (cname-server) echo "$SRV_ALIASES" |tr " " "\n" |sed "/^[[:blank:]]*$/d;s%$%.$SRV_DOMAIN%;/^$SRV_FQDN$/d;s%^%cname=%;s%$%,$SRV_FQDN%" |skel-install "${DB_SRV_ALIAS}" # generate hosts aliases db (cname-hosts) get_dhcp_dnsmasq_alias_list |skel-install "$DB_HOST_ALIAS" #generate hosts db get_dhcp_dnsmasq_list |skel-install "$DB_HOSTS" #generate unreg hosts db get_noreg_dnsmasq_list |skel-install "$DB_HOSTS_UNREG" #generate dhcp if [ ! -e "$DB_DHCP" ]; then get_dhcp_dnsmasq_mac_list |skel-install "$DB_DHCP" fi # generate cap domain info [ "$CAP_NET_ADDRESS" ] || exit 0 [ "$CAP_NET_DOMAIN" ] || exit 0 [ "$CAP_NET_CAPNAME" ] || exit 0 { echo "domain=$CAP_NET_CAPNAME.$CAP_NET_DOMAIN,${CAP_NET_ADDRESS%.*}.1,${CAP_NET_ADDRESS%.*}.254" ; echo "local=/$CAP_NET_CAPNAME.$CAP_NET_DOMAIN/" ; } |skel-install "$DNS_CAP_CONF" gen_cap_hosts |skel-install "$DNS_CAP_HOSTS" exit 0