#!/bin/bash # set -e # variables BEGIN_LLIUREX="#--LLXCFG_INI--#" END_LLIUREX="#--LLXCFG_END--#" COMMENT_LLIUREX="####--COMMENT-BY-LLXCFG--####" INCLUDE_LLIUREX_CONF="include \"/etc/bind/named.conf.lliurex\";" SKEL_ROOT="./skel" BIND_DIR="/etc/bind" CONF_DIR="dns/bind" DB_SRV_ALIAS="${BIND_DIR}/db.aula.srv-alias" DB_HOSTS="${BIND_DIR}/db.aula.hosts" DB_HOSTS_REVERSE="${BIND_DIR}/db.aula.hosts.reverse" DB_HOSTS_UNREG="${BIND_DIR}/db.aula.hosts-unreg" DB_HOSTS_UNREG_REVERSE="${BIND_DIR}/db.aula.hosts-unreg.reverse" DB_SRV_REVERSE="${BIND_DIR}/db.aula.server.reverse" CONF_LOCAL="${BIND_DIR}/named.conf.local" ALL_ALIAS="" VAR_LIST="SRV_DOMAIN DNS_EXTERNAL_NS SRV_BITMASK SRV_IP" 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 gen_conf_local(){ llxcfg-cpkg plainview "$CONF_LOCAL" || exit 1 cat << EOF // $BEGIN_LLIUREX // Please, do not remove next line $INCLUDE_LLIUREX_CONF // $END_LLIUREX EOF } dbgen_server_alias(){ for a in $SRV_ALIASES ; do [ "$a" != "server" ] && echo -e "$a\tIN\tCNAME\tserver" done } dbgen_server_reverse(){ echo -e "$(ip_reverse "${SRV_IP}" ${REVERSE_BYTES})\tIN\tPTR\tserver.${SRV_DOMAIN}." } dbgen_hosts(){ HOST_NUM=1 HOST_MAX=`get_dhcp_host_max` HOST_IP_LIST="`get_dhcp_host_address 1 ${HOST_MAX}`" for HOST_IP in ${HOST_IP_LIST}; do HOST_NAME="`get_dhcp_host_name ${HOST_NUM}`" echo -e "$(ip_reverse "${HOST_IP}" ${REVERSE_BYTES})\tIN\tPTR\t${HOST_NAME}.${SRV_DOMAIN}." >> "${SKEL_ROOT}/${DB_HOSTS_REVERSE}" echo -e "${HOST_NAME}\tIN\tA\t${HOST_IP}" >> "${SKEL_ROOT}/${DB_HOSTS}" HOST_ALIAS="`get_dhcp_host_alias ${HOST_NUM}`" for alias in ${HOST_ALIAS}; do if ! echo " $HOST_NAME $ALL_ALIAS " |grep -q " $alias " ; then echo -e "${alias}\tIN\tCNAME\t${HOST_NAME}" >> "${SKEL_ROOT}/${DB_HOSTS}" ALL_ALIAS="$ALL_ALIAS $alias" fi done HOST_NUM=$((${HOST_NUM}+1)) done } dbgen_hosts_unreg(){ HOST_LIST=`get_noreg_host_list` for h in ${HOST_LIST}; do HOST_NAME="`echo ${h} |cut -f 1 -d ,`" HOST_IP="`echo ${h} |cut -f 2 -d ,`" echo -e "${HOST_NAME}\tIN\tA\t${HOST_IP}" >> "${SKEL_ROOT}/${DB_HOSTS_UNREG}" echo -e "$(ip_reverse "${HOST_IP}" ${REVERSE_BYTES})\tIN\tPTR\t${HOST_NAME}.${SRV_DOMAIN}." >> "${SKEL_ROOT}/${DB_HOSTS_UNREG_REVERSE}" done } ######## # 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" # calculate num of bytes for reverse resolution REVERSE_BYTES=$((4 - $SRV_BITMASK/8)) # search required lliurex line in named.conf.local if [ ! -f "$CONF_LOCAL" ] || ! grep -q "^${INCLUDE_LLIUREX_CONF}$" "$CONF_LOCAL" ; then gen_conf_local |skel-install "${CONF_LOCAL}" fi # generate template files from llxcfg conffiles for f in $(llxcfg-config list "$CONF_DIR") ; do llxcfg-config read "$CONF_DIR/$f" | skel-install -t "${BIND_DIR}/${f}" done # generate server-alias db dbgen_server_alias |skel-install "${DB_SRV_ALIAS}" # generate server-reverse db dbgen_server_reverse |skel-install "${DB_SRV_REVERSE}" #generate hosts db :> "${SKEL_ROOT}/${DB_HOSTS}" :> "${SKEL_ROOT}/${DB_HOSTS_REVERSE}" dbgen_hosts #generate unreg hosts db :> "${SKEL_ROOT}/${DB_HOSTS_UNREG}" :> "${SKEL_ROOT}/${DB_HOSTS_UNREG_REVERSE}" dbgen_hosts_unreg exit 0