<commit_before>#!/usr/bin/env bash
# ---------------------------------------------------------------------------
# new_dns_zone.sh - Create a new DNS zone for BIND.
# Usage: dns.sh [-h|--help]
# Revision history:
# 2013-09-06    Created by new_script.sh ver. 3.0
# ---------------------------------------------------------------------------
#


#
#CONFIG
#

#This DNS Servers IP
serverip=127.0.0.1

#NS1
defaultns[1]=ns1.dnsserver.com
#NS2
defaultns[2]=ns2.dnsserver.com

#NS1IP
defaultnsip[1]=8.8.8.8
#NS2IP
defaultnsip[2]=8.8.4.4

namedconf="/etc/named.conf"
zonepath="/var/named/"

#Serial Format
serial=$(date +%s)


#
#END CONFIG
#




#
#MAGIC
#
zonepath=${zonepath%/}



#
#END MAGIC
#


#
#FUNCTIONS
#


function warning()
{
	echo "$*" >&2
}

function error()
{
	echo "$*" >&2
	exit 1
}

function yesno {
	read -n 1 -p "$1" -r REPLY
	if [[ $REPLY =~ ^[Yy]$ ]]
	then
		echo >&2
		echo "1";
	else
		echo >&2
		exit 1;
	fi
}


#
#END FUNCTIONS
#


#
#Prompts
#

echo "Warning: Script must be run with root permissions!"

#Domain Name
read -p "Domain of New Zone: " primarydomain
#Primary IP
read -p "Primary IP of New Zone: " zoneip

#RNAME Field
read -p "SOA Email Address: " rname
rname=${rname/@/.}

#MX Record Loop

#Get Mail Server Prefix
read -p "Primary MX Record Prefix (Default: mail): " mailprefix
mailprefix=${mailprefix:-mail}
#Get Mail Server IP
read -p "IP of Primary MX Record (Default: ${zoneip}): " mailip
mailip=${mailip:-${zoneip}}

#End MX Record Loop

#Start Name Server Loop

#Prompt: Default or Custom Nameservers, Default is $NS1 and $NS2, custom has $Primary IP appended to end of it, dont end with dot

#Custom Name Server 1: (Enter First Nameserver prefix)

#Start Custom NS Loop (End if = '' or if Loop Count > $NSCount - 1 )

#Increment Loop Count

#Custom Name Server x: (Enter $x Nameserver Prefix or press ENTER to continue)

#End Custom NS Loop

#If Name Server x ends with $Primary Domain

#END Name Server Loop


#Yes/No Test

if [[ $(yesno "What is your answer? [y/n]: ") ]]; then
	echo "Your Answer was Yes."
else
	echo "Your Answer was No."
fi

#End Yes/No Test


#
#TEMPORARY VARIABLES
#

displayzone=0
createzone=0
displaynamedconf=0
zonename=${primarydomain}
zonefilename=${zonename}.zone

#
#END TEMPORARY VARIABLES
#


#Zone Template

read -d '' zonetemplate << EOF
\$TTL            86400
@       IN      SOA     ${defaultns[1]}.       ${rname}. (
                        ${serial}	; serial
                        1H	; refresh
                        1M	; retry
			1W	; expiry
                        1D )	; minutes
$(for i in "${defaultns[@]}"
	do
		echo  "@       IN      NS      ${i}."
	done
)
@       IN      A       ${zoneip}
@       IN      MX      10	${mailprefix}.${primarydomain}.
mail    IN      A       ${mailip}
www     IN      CNAME   ${primarydomain}.
EOF


#named.conf Template

read -d '' namedconftemplate << EOF
zone \"${zonename}\" IN {
	type master;
	file \"${zonepath}/${zonefilename}\";
	allow-update { none; };
};
EOF



#Display Template

if [ "$displayzone" -eq 1 ]; then
	cat << EOF
#
#
#Zone File: ${zonepath}/${zonefilename}
#
#

$zonetemplate

EOF
fi


#Display named.conf Template

if [ "$displaynamedconf" -eq 1 ]; then
	cat << EOF
#
#
#${namedconf}
#
#

$namedconftemplate"

EOF
fi

#Add Zone File to BIND config

if [ "$createzone" -eq 1 ]; then
	warning "Creating Zone File and adding to BIND configuration."
	echo "$zonetemplate" > ${zonepath}/${zonefilename}
	echo "$namedconftemplate" >> $namedconf

fi
<commit_msg>Modifications to zone template<commit_after>#!/usr/bin/env bash
# ---------------------------------------------------------------------------
# new_dns_zone.sh - Create a new DNS zone for BIND.
# Usage: dns.sh [-h|--help]
# Revision history:
# 2013-09-06    Created by new_script.sh ver. 3.0
# ---------------------------------------------------------------------------
#


#
#CONFIG
#

#This DNS Servers IP
serverip=127.0.0.1

#NS1
defaultns[1]=ns1.dnsserver.com
#NS2
defaultns[2]=ns2.dnsserver.com

#NS1IP
defaultnsip[1]=8.8.8.8
#NS2IP
defaultnsip[2]=8.8.4.4

namedconf="/etc/named.conf"
zonepath="/var/named/"

#Serial Format
serial=$(date +%s)


#
#END CONFIG
#




#
#MAGIC
#
zonepath=${zonepath%/}



#
#END MAGIC
#


#
#FUNCTIONS
#


function warning()
{
	echo "$*" >&2
}

function error()
{
	echo "$*" >&2
	exit 1
}

function yesno {
	read -n 1 -p "$1" -r REPLY
	if [[ $REPLY =~ ^[Yy]$ ]]
	then
		echo >&2
		echo "1";
	else
		echo >&2
		exit 1;
	fi
}


#
#END FUNCTIONS
#


#
#Prompts
#

echo "Warning: Script must be run with root permissions!"

#Domain Name
read -p "Domain of New Zone: " primarydomain
#Primary IP
read -p "Primary IP of New Zone: " zoneip

#RNAME Field
read -p "SOA Email Address: " rname
rname=${rname/@/.}

#MX Record Loop

#Get Mail Server Prefix
read -p "Primary MX Record Prefix (Default: mail): " mailprefix
mailprefix=${mailprefix:-mail}
#Get Mail Server IP
read -p "IP of Primary MX Record (Default: ${zoneip}): " mailip
mailip=${mailip:-${zoneip}}

#End MX Record Loop

#Start Name Server Loop

#Prompt: Default or Custom Nameservers, Default is $NS1 and $NS2, custom has $Primary IP appended to end of it, dont end with dot

#Custom Name Server 1: (Enter First Nameserver prefix)

#Start Custom NS Loop (End if = '' or if Loop Count > $NSCount - 1 )

#Increment Loop Count

#Custom Name Server x: (Enter $x Nameserver Prefix or press ENTER to continue)

#End Custom NS Loop

#If Name Server x ends with $Primary Domain

#END Name Server Loop


#Yes/No Test

if [[ $(yesno "What is your answer? [y/n]: ") ]]; then
	echo "Your Answer was Yes."
else
	echo "Your Answer was No."
fi

#End Yes/No Test


#
#TEMPORARY VARIABLES
#

displayzone=0
createzone=0
displaynamedconf=0
zonename=${primarydomain}
zonefilename=${zonename}.zone
zonettl="86400"
soarefresh='1H'
soaretry='1M'
soaexpiry='1W'
soamaxcache='1D'

#
#END TEMPORARY VARIABLES
#


#Zone Template

read -d '' zonetemplate << EOF
\$TTL            ${zonettl}
@       IN      SOA     ${defaultns[1]}.       ${rname}. (
                        ${serial}	; serial
                        ${soarefresh}	; slave refresh
                        ${soaretry}	; slave retry time in case of a problem
			${soaexpiry}	; slave expiry
                        ${soamaxcache} )	; maximum caching time in case of failed lookups
$(for i in "${defaultns[@]}"
	do
		echo  "@       IN      NS      ${i}."
	done
)
@       IN      A       ${zoneip}
@       IN      MX      10	${mailprefix}.${primarydomain}.
mail    IN      A       ${mailip}
www     IN      CNAME   ${primarydomain}.
EOF


#named.conf Template

read -d '' namedconftemplate << EOF
zone \"${zonename}\" IN {
	type master;
	file \"${zonepath}/${zonefilename}\";
	allow-update { none; };
};
EOF



#Display Template

if [ "$displayzone" -eq 1 ]; then
	cat << EOF
#
#
#Zone File: ${zonepath}/${zonefilename}
#
#

$zonetemplate

EOF
fi


#Display named.conf Template

if [ "$displaynamedconf" -eq 1 ]; then
	cat << EOF
#
#
#${namedconf}
#
#

$namedconftemplate"

EOF
fi

#Add Zone File to BIND config

if [ "$createzone" -eq 1 ]; then
	warning "Creating Zone File and adding to BIND configuration."
	echo "$zonetemplate" > ${zonepath}/${zonefilename}
	echo "$namedconftemplate" >> $namedconf

fi

{'fraction_non_alphanumeric': 0.17545316175453163, 'fraction_numerical': 0.017988100179881002, 'mean_word_length': 2.510441962117533, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5189460', 'n_tokens_mistral': 2700, 'n_tokens_neox': 2556, 'n_words': 806}