Completion reverse + commande extraction de zone
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |0|0|0|0|:clap:
gitea/ansible-roles/pipeline/head This commit looks good

This commit is contained in:
William Hirigoyen 2024-01-12 12:18:35 +01:00
parent bf07ef74c3
commit 0fc53dea73
3 changed files with 26 additions and 8 deletions

View file

@ -0,0 +1,16 @@
#!/usr/bin/env bash
_bind_reload_reverse_dynamic_completion() {
ipv4_list_command='grep -v -h -E '"'"'//'"'"'^[[:blank:]]*//'"'"'//'"'"' /etc/bind/named.conf* | grep -B1 "type master" | grep zone | grep arpa | grep -v ip6 | awk '"'"'//'"'"'{gsub(/"/, "", $2); gsub(/.in-addr.arpa/, "", $2); print $2}'"'"'//'"'"' | sort | uniq | awk -F"." '"'"'//'"'"'{ for (i=NF; i>1; i--) printf("%s.",$i); print $1 }'"'"'//'"'"' | sort -n'
ipv6_list_command='grep -v -h -E '"'"'//'"'"'^[[:blank:]]*//'"'"'//'"'"' /etc/bind/named.conf* | grep -B1 "type master" | grep zone | grep arpa | grep ip6 | awk '"'"'//'"'"'{gsub(/"/, "", $2); gsub(/.ip6.arpa/, "", $2); print $2}'"'"'//'"'"' | sort | uniq | rev | awk -F"." '"'"'//'"'"'{ printf("%s", $1); for (i=2; i<NF+1; i++) { if ((i-1)%4 != 0) printf("%s",$i); else printf(".%s",$i); } printf("\n") }'"'"'//'"'"' | sort -n'
local cur;
cur=${COMP_WORDS[COMP_CWORD]};
COMPREPLY=();
COMPREPLY=( $( compgen -W "${ipv4_list_command}; ${ipv6_list_command}" -- $cur ) );
}
complete -F _bind_reload_reverse_dynamic_completion bind-reload-reverse

View file

@ -1,11 +1,14 @@
#!/bin/bash
#
# Script utilitaire pour tester et recharger facilement une zone dans Bind
# Supporte le rechargement des reverses.
#
usage() {
echo "Usage: bind-reload-zone <DOMAIN>"
echo " bind-reload-zone -h|--help"
echo "Usage: bind-reload-reverse <SUBNET>"
echo " bind-reload-reverse -h|--help"
}
if [ $# -ne 1 ] ; then
@ -27,6 +30,12 @@ while :; do
shift
done
# TODO :
# - check if zone exists
# - look for zone file
#grep -v -h -E '[[:blank:]]*//' /etc/bind/named.conf.* | awk '/zone[^\n]*{/ { in_zone=1; level=0; name=$2; gsub(/"/, "", name) } { if (in_zone) { if ($0 ~ "{") level++; else if ($0 ~ "}") level--; if (!level) in_zone=0; if (name=="nrouvierephotographie.com") print $0 } }'
if ! [ -f "/etc/bind/db.${zone}" ]; then
>&2 echo "Error: zone for ${zone} not found."
usage

View file

@ -4,14 +4,7 @@ _bind_reload_zone_dynamic_completion() {
local cur;
cur=${COMP_WORDS[COMP_CWORD]};
COMPREPLY=();
COMPREPLY=( $( compgen -W '$(grep -v -h '"'"'//'"'"' /etc/bind/named.conf* | grep -B1 "type master" | grep zone | grep -v arpa | awk '"'"'{gsub(/"/, "", $2); print $2}'"'"' | sort | uniq)' -- $cur ) );
# reverse ipv4 :
#grep -v -h '//' /etc/bind/named.conf* | grep -B1 "type master" | grep zone | grep arpa | grep -v ip6 | awk '{gsub(/"/, "", $2); gsub(/.in-addr.arpa/, "", $2); print $2}' | sort | uniq | awk -F'.' '{ for (i=NF; i>1; i--) printf("%s.",$i); print $1 }'
# reveres ipv6 : je bloque sur l'inversion 4 par 4
#grep -v -h '//' /etc/bind/named.conf* | grep -B1 "type master" | grep zone | grep arpa | grep ip6 | awk '{gsub(/"/, "", $2); gsub(/.ip6.arpa/, "", $2); print $2}' | sort | uniq | awk -F'.' '{ for (i=NF; i>1; i--) { if ($i % 4 == 0) printf("%s.",$i); else printf("%s",$i); } print $1 }'
COMPREPLY=( $( compgen -W '$(grep -v -h -E '"'"'^[[:blank:]]*//'"'"' /etc/bind/named.conf* | grep -B1 "type master" | grep zone | grep -v arpa | awk '"'"'{gsub(/"/, "", $2); print $2}'"'"' | sort | uniq)' -- $cur ) );
}
complete -F _bind_reload_zone_dynamic_completion bind-reload-zone