#!/usr/bin/env bash # # $Id: zefwd,v 1.1 2025/06/15 23:36:24 snw Exp $ # ChivaNet BIND zone edit script # # # Author: Serena Willis # Copyright (C) 2013, 2025 Coherent Logic Development LLC # # # This file is part of ze. # # ze is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # ze is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with ze. If not, see . # # $Log: zefwd,v $ # Revision 1.1 2025/06/15 23:36:24 snw # Initial revision # # # SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC # SPDX-License-Identifier: AGPL-3.0-or-later # source /etc/defaults/ze.conf [[ -z "${EDITOR}" ]] && EDITOR="emacs -nw" SHNAME=`basename $0` if [ ${EUID} -ne 0 ] then echo "${SHNAME} must be run as root." exit fi if [ $1 = "" ] then echo "usage: $0 zone" exit fi if [ ${SHNAME} = "zefwd" ] then ZONEFILE="/etc/namedb/$1.db" ZONEBASE="$1.db" RNDC_DOMAIN=$1 elif [ ${SHNAME} = "zerev" ] then ZONEFILE="/etc/namedb/rev.${1}.in-addr.arpa" ZONEBASE="rev.${1}.in-addr.arpa" RNDC_DOMAIN="${1}.IN-ADDR.ARPA" fi TMPFILE="/tmp/${ZONEBASE}" if [ ! -f ${ZONEFILE} ] then echo "${ZONEFILE} does not exist." exit fi if [ -f ${TMPFILE} ] then echo "${ZONEFILE} already being edited." exit fi ORIG_SERIAL=`cat ${ZONEFILE} | sed '3q;d' | tr -d '[[:space:]]'` cp ${ZONEFILE} ${TMPFILE} cd /etc/namedb ${EDITOR} ${TMPFILE} NEW_SERIAL=`cat ${TMPFILE} | sed '3q;d' | tr -d '[[:space:]]'` if [ ${NEW_SERIAL} -le ${ORIG_SERIAL} ] then echo "Serial number in zonefile ${ZONEFILE} must be greater than ${ORIG_SERIAL}." rm -f ${TMPFILE} exit else echo "Serial number changed: ${ORIG_SERIAL} -> ${NEW_SERIAL}" fi mv ${TMPFILE} ${ZONEFILE} rm -f ${TMPFILE} git add ${ZONEFILE} read -p "Enter a comment explaining this edit: " COMMIT_CMNT LOGIN_NAME=`logname` echo "Committing to version control..." git commit -m "${LOGIN_NAME}: ${COMMIT_CMNT}" git push origin master echo "Reloading BIND configuration..." /etc/rc.d/named reload echo "Requesting retransfer from ${SLAVE_SERVER}..." ssh ${SLAVE_USER}@${SLAVE_SERVER} "sudo /usr/sbin/rndc retransfer ${RNDC_DOMAIN}"