Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37762038
en ru br
Репозитории ALT
S:0.9.6-alt2
5.1: 0.7-alt1.M51.1
4.1: 0.4-alt0.M41.3
4.0: 0.1-alt13
www.altlinux.org/Changes

Группа :: Система/Настройка/Прочее
Пакет: alterator-bind

 Главная   Изменения   Спек   Патчи   Исходники   Загрузить   Gear   Bugs and FR  Repocop 

alterator-bind-0.9.3/000075500000000000000000000000001212454776200144425ustar00rootroot00000000000000alterator-bind-0.9.3/Makefile000064400000000000000000000014141212454776200161020ustar00rootroot00000000000000NAME=bind
SHELL_LIBS=bind-sh-functions ddns-sh-functions

all:
install: install-lib install-sbin install-hook install-module

include /usr/share/alterator/build/module.mak

install-lib:
for i in $(SHELL_LIBS); do install -Dpm644 bin/$$i $(bindir)/$$i; done

install-sbin:
for i in sbin/*; do install -Dpm755 $$i $(sbindir)/$${i##*/}; done

install-hook:
install -Dpm755 hook/ddns-hook-hostname $(sysconfdir)/hooks/hostname.d/10-ddns
install -Dpm755 hook/ddns-hook-net-eth $(libexecdir)/alterator/hooks/net-eth.d/10-ddns
install -Dpm755 hook/ddns-hook-dhcp $(libexecdir)/alterator/hooks/dhcp.d/10-ddns
install -Dpm755 hook/dhcp-hook-hostname $(sysconfdir)/hooks/hostname.d/10-dhcp
install -Dpm755 hook/dhcp-hook-net-domain $(libexecdir)/alterator/hooks/net-domain.d/10-dhcp
alterator-bind-0.9.3/README000064400000000000000000000024061212454776200153240ustar00rootroot00000000000000==DNS==

hooks:
* (TODO) net-domain.d -- call on master/slave changes (nothing, change state)
* (TODO) trust.d -- call on slave initialization (reset slave)
* hostname.d -- call on hostname changes (lightweight hostname rename, reset master)
* net-eth.d -- call on network settings changes (reset master)
* dhcp.d -- call on dhcp administration

low level:
* ddns-hook-reset -- reset to default settings --> call dhcp-reset-static
* ddns-add-host -- add host binding to dns
* ddns-del-host -- remove host binding from dns
* ddns-check-name -- check name (to use in dhcp)

==DHCP==

hooks:
* net-domain.d -- call on master/slave changes (update state)
* hostname.d -- call on master/slave changes (update search)
* resolv.conf.d -- call on resolv.conf updates (update search)

low level:
* dhcp-update-config -- regenerate config and call dhcp condreload
* dhcp-print-config -- hook for dhcp config resetter
* dhcp-reset-static -- reset static bindings
* dhcp-reset-state -- reset master/slave settings
* dhcp-reset-search -- reset search settings

alterator-dhcp modes: dhcp only, dhcp+ddns

dhcp+ddns:
* use dhcp-print-config
* use ddns-add-host/ddns-del-host
* hide in UI search and DNS

ROADMAP:
* slave п╢п╩я▐ п©я─я▐п╪я▀я┘ п╥п╬п╫
* п╥п╟п©п╦я│я▄ я┌п╦п©п╟ "п╥п╬п╫п╟"
alterator-bind-0.9.3/applications/000075500000000000000000000000001212454776200171305ustar00rootroot00000000000000alterator-bind-0.9.3/applications/bind.desktop000064400000000000000000000003221212454776200214340ustar00rootroot00000000000000[Desktop Entry]
Encoding=UTF-8
Type=Application
Categories=X-Alterator-Servers
Icon=dhcp
Terminal=false
Name=DNS server
X-Alterator-URI=/bind
X-Alterator-UI=html
X-Alterator-Help=bind
Name[ru]=DNS-я│п╣я─п╡п╣я─
alterator-bind-0.9.3/backend3/000075500000000000000000000000001212454776200161145ustar00rootroot00000000000000alterator-bind-0.9.3/backend3/bind000075500000000000000000000163451212454776200167670ustar00rootroot00000000000000#!/bin/sh

alterator_api_version=1
ipv4_dhcp_config_file=/etc/alterator/dhcp/general
ipv6_dhcp_config_file=/etc/alterator/dhcp6/general

. alterator-sh-functions
. ddns-sh-functions

## domain

list_ddns_domain()
{
ddns_list_domain|write_enum
}

## ns

read_ddns_ns()
{
local zone="$1";shift
local ns="$(ddns_domain_list_ns "$zone"|grep -v "ns.$zone"|tr '\n' ' ')"
echo "${ns% }"
}

write_ddns_ns()
{
local zone="$1";shift
local hostlist="$1";shift

local nslist="ns.$zone $hostlist"

[ -n "$nslist" ] || return 0

local state1="$(mktemp -t alterator-bind.XXXXXX)"
local state2="$(mktemp -t alterator-bind.XXXXXX)"

ddns_domain_list_ns "$zone"|sort >"$state1"
echo "$nslist"|tr ' ' '\n'|sed '/^[[:space:]]*$/d'|sort >"$state2"

comm -13 "$state1" "$state2"|
while read host; do
ddns_domain_add_ns "$zone" "$host"
done

comm -23 "$state1" "$state2"|
while read host;do
ddns_domain_del_ns "$zone" "$host"
done

rm -f -- "$state1" "$state2"
}

## network

__ipv4addr_simple_regexp='^[[:digit:]\./]+$'
__ipv6addr_simple_regexp='^[[:xdigit:]:/]+$'

read_ddns_network()
{
local zone="$1";shift
local ddns_network="$(ddns_domain_list_net "$zone" 4 |tr '\n' ';')"

ddns_network="$ddns_network$(ddns_domain_list_net "$zone" 6 |tr '\n' ';')"
echo "${ddns_network%;}"
}


write_ddns_network()
{
local zone="$1";shift

local state1="$(mktemp -t alterator-bind.XXXXXX)"
local state2="$(mktemp -t alterator-bind.XXXXXX)"
local ip= ipv= addr_regexp=

for ipv in 4 6; do
eval "addr_regexp=\$__ipv${ipv}addr_simple_regexp"
ddns_domain_list_net "$zone" "$ipv"|sort >"$state1"
[ -z "$1" ] || echo "$1" |tr ';' '\n'| egrep -o "$addr_regexp" | sort >"$state2"

comm -13 "$state1" "$state2"|
while read ip; do
ddns_domain_add_net "$zone" "$ip" "$ipv"
done

local dhcp_ip= addr_is_in_subnet= is_valid_ip=
if [ "$ipv" = 4 ]; then
dhcp_ip="$(shell_config_get "$ipv4_dhcp_config_file" ip_start)"
addr_is_in_subnet=ipv4_ip_subnet
is_valid_ip=valid_ipv4addr
else
dhcp_ip="$(shell_config_get "$ipv6_dhcp_config_file" ip_start)"
addr_is_in_subnet=ipv6addr_is_in_subnet
is_valid_ip=valid_ipv6addr
fi
if $is_valid_ip "$dhcp_ip"; then
comm -23 "$state1" "$state2"|
while read ip;do
[ -n "$dhcp_ip" ] && [ "$zone" = "$(ddns_system_zone)" ] && $addr_is_in_subnet "$dhcp_ip" "$ip" ||
ddns_domain_del_net "$zone" "$ip" "$ipv"
done
fi
done

rm -f -- "$state1" "$state2"
}

list_ddns_network()
{
local ip
local iface
local ipv4_dhcp_iface="$(shell_config_get "$ipv4_dhcp_config_file" iface)"
local ipv6_dhcp_iface="$(shell_config_get "$ipv6_dhcp_config_file" iface)"

ddns_net_list_all 4|
while read ip iface; do
local comment="$iface ($ip)"
[ "$iface" != "$ipv4_dhcp_iface" ] || comment="$comment `_ "managed by DHCP server"`"
write_enum_item "$ip" "$comment"
done

ddns_net_list_all 6|
while read ip iface; do
local comment="$iface ($ip)"
[ "$iface" != "$ipv6_dhcp_iface" ] || comment="$comment `_ "managed by DHCP server"`"
write_enum_item "$ip" "$comment"
done
}

list_ddns_host()
{
local zone="$1";shift
local ip
local name
local ipv

for ipv in 4 6; do
ddns_domain_list_host "$zone" "$ipv"|
while read ip name; do
write_table_item ip "$ip" host "$name" name "${ip}:${name}"
done
done
}

del_ddns_host()
{
local zone="$1";shift
local IFS=';'
local host ip ipv i

[ -z "$1" ] ||
for i in $1;do
host="${i##*:}"
ip="${i%:*}"
ipv="$(get_ip_version "$ip")"
[ -n "$ipv" ] || return 1

ddns_domain_is_reserved_host "$host" || ddns_domain_del_host "$zone" "$ip" "$host" "$ipv"
done
}

on_message()
{
local ipv=

case "$in_action" in
type)
write_type_item ddns_master ip-address-list
write_type_item ddns_ns hostname-list
write_type_item ddns_mx hostname-list
write_type_item new_ddns_ip ip-address
write_type_item new_ddns_host system-computer-name
write_type_item new_ddns_domain hostname
;;
list)
case "$in__objects" in
ddns_type)
write_enum_item "master" "`_ "master"`"
write_enum_item "slave" "`_ "slave"`"
;;
ddns_network) list_ddns_network ;;
ddns_host) [ -z "$in_ddns_domain" ] || list_ddns_host "$in_ddns_domain";;
ddns_domain) list_ddns_domain ;;
esac
;;
read)
[ -n "$in_ddns_domain" ] || return
write_string_param ddns_network "$(read_ddns_network "$in_ddns_domain")"
write_string_param ddns_ns "$(read_ddns_ns "$in_ddns_domain")"
write_string_param ddns_mx "$(ddns_domain_read_mx "$in_ddns_domain")"
write_string_param ddns_type "$(ddns_domain_read_type "$in_ddns_domain")"
write_string_param ddns_master "$(ddns_domain_read_master "$in_ddns_domain")"
! ddns_key_exist "$in_ddns_domain-transfer-key"
write_string_param ddns_has_key "$?"
;;
write)
[ -n "$in_ddns_domain" -a -n "$in_ddns_type" ] || return
case "$in_ddns_type" in
master)
write_ddns_network "$in_ddns_domain" "$in_ddns_network"
write_ddns_ns "$in_ddns_domain" "$in_ddns_ns"
ddns_domain_write_mx "$in_ddns_domain" "$in_ddns_mx"
;;
slave)
if [ -z "$in_ddns_master" ];then
write_error "`_ "You should define as minimum one master server for slave domain"`"
elif ! ddns_key_exist "$in_ddns_domain-transfer-key"; then
write_error "`_ "No domain key found"`"
else
ddns_domain_write_master "$in_ddns_domain" "$in_ddns_master"
fi
;;
esac
service_control bind condreload
;;
create)
[ -n "$in_new_ddns_domain" -a -n "$in_new_ddns_type" ] || return
if ddns_domain_exists "$in_new_ddns_domain";then
write_error "`_ "Same domain already exists"`"
return
else
ddns_create_domain "$in_new_ddns_domain" "$in_new_ddns_type"
service_control bind condreload
fi
;;
destroy)
[ -n "$in_ddns_domain" ] || return
if [ "$in_ddns_domain" = "$(ddns_system_zone)" ];then
write_error "`_ "Unable to destroy system domain"`"
return
else
ddns_destroy_domain "$in_ddns_domain"
service_control bind condreload
fi
;;
add)
[ -n "$in_ddns_domain" -a -n "$in_new_ddns_host" -a -n "$in_new_ddns_ip" ] || return

local zone="$in_ddns_domain"
local new_host="$in_new_ddns_host"
local new_ip="$in_new_ddns_ip"
ipv="$(get_ip_version "$new_ip")"

if ddns_domain_has_host "$zone" "$new_ip" "$new_host" "$ipv";then
write_error "`_ "Same binding of host to IP address already exists"`"
return
elif ddns_domain_is_reserved_host "$new_host";then
write_error "`_ "This hostname is registered for internal purposes"`"
return
else
ddns_domain_add_host "$zone" "$new_ip" "$new_host" "$ipv"
fi
;;
del)
[ -n "$in_ddns_domain" -a -n "$in_ddns_host" ] || return
del_ddns_host "$in_ddns_domain" "$in_ddns_host"
;;
read_key)
[ -n "$in_ddns_domain" ] || return
ddns_print_key "$in_ddns_domain-transfer-key"|write_blob_param ddns_key
;;
write_key)
[ -n "$in_ddns_domain" -a -n "$in_ddns_key_file" ] || return
if ddns_check_key "$in_ddns_domain-transfer-key" "$in_ddns_key_file"; then
ddns_replace_key "$in_ddns_domain-transfer-key" "$in_ddns_key_file"
else
write_error "`_ "Invalid domain key"`"
fi
esac
}

message_loop
alterator-bind-0.9.3/bin/000075500000000000000000000000001212454776200152125ustar00rootroot00000000000000alterator-bind-0.9.3/bin/bind-sh-functions000064400000000000000000000074131212454776200204740ustar00rootroot00000000000000#!/bin/sh -efu

. shell-quote

bind_root_dir=/var/lib/bind
bind_local_conf_file="$bind_root_dir/etc/local.conf"

### basic file processing

# usage: bind_local_conf_include path
# include additional file into bind local conf
bind_local_conf_include()
{
local path="$1";shift
local qpath;
quote_sed_regexp_variable qpath "$path"

grep -qs "include[[:space:]]\+\"$qpath\"[[:space:]]*;[[:space:]]*\$" "$bind_local_conf_file" ||
printf 'include "%s";\n' "$path" >>"$bind_local_conf_file"
}

# usage: bind_local_conf_exclude path
# exclude additional file from bind local conf
bind_local_conf_exclude()
{
local path
quote_sed_regexp_variable path "$1";shift

sed "/include[[:space:]]\+\"$path\"[[:space:]]*;[[:space:]]*\$/d" -i "$bind_local_conf_file"
}

### zone options

# usage: bind_domain_exists <domain-name>
# check are zone record exists in bind options
bind_domain_exists()
{
local domain
quote_sed_regexp_variable domain "$1"

for f in `find "$bind_root_dir/etc" -type f -name '*.conf'`; do
grep -qs "^[[:space:]]*zone[[:space:]]\+\"$domain\"[[:space:]]\+{[[:space:]]*\$" "$f" && return 0
done
return 1
}

# usage: bind_domain_list <file>
# list available domains in bind options
bind_domain_list()
{
local file="$1";shift

sed -n \
-e 's/^[[:space:]]*zone[[:space:]]\+\"\([.a-zA-Z0-9_-]\+\)\"[[:space:]]\+{[[:space:]]*$/\1/p' \
"$bind_root_dir/$file"
}

# usage: bind_domain_add <file> <domain-name> < OPTIONS
# add domain definition to file
# zone options readed from standard input
bind_domain_add()
{
local file="$1";shift
local domain="$1";shift

bind_domain_exists "$domain" && return 0

bind_local_conf_include "$file"

local path="$bind_root_dir/$file"
printf 'zone "%s" {\n' "$domain" >>"$path"
cat>>"$path"
printf '};\n'>>"$path"
}


# usage: bind_domain_del <file> <domain-name>
# remove domain definition from file
bind_domain_del()
{
local file="$bind_root_dir/$1";shift

local domain
quote_sed_regexp_variable domain "$1"
sed -e "/^[[:space:]]*zone[[:space:]]\+\"$domain\"[[:space:]]\+{[[:space:]]*\$/,/^[[:space:]]*};[[:space:]]*\$/d" \
-i "$file"
}

# usage: bind_domain_get <file> <domain-name> <param>
# read domain parameter's value
bind_domain_get()
{
local file="$bind_root_dir/$1";shift
local domain param
quote_sed_regexp_variable domain "$1";shift
quote_sed_regexp_variable param "$1";shift

sed -n \
-e "/^[[:space:]]*zone[[:space:]]\+\"$domain\"[[:space:]]\+{[[:space:]]*\$/,/^[[:space:]]*};[[:space:]]*\$/ s/^[[:space:]]*$param[[:space:]]\+\(.*\)[[:space:]]*;\$/\1/p" \
"$file"
}


# usage: bind_domain_set <file> <domain-name> <param> <value>
# write domain parameter's value
bind_domain_set()
{
local file="$bind_root_dir/$1";shift
local domain param
quote_sed_regexp_variable domain "$1";shift
quote_sed_regexp_variable param "$1";shift
local value="$1";shift

sed -e "/^[[:space:]]*zone[[:space:]]\+\"$domain\"[[:space:]]\+{[[:space:]]*\$/,/^[[:space:]]*};[[:space:]]*\$/ s/^\([[:space:]]*\)$param[[:space:]]\+.*/\1$param $value;/" \
-i "$file"
}

### zone content

# usage: bind_domain_add <file> <domain-name> < CONTENT
# add zone definition to file
# zone content readed from standard input
# TODO: automatically write filename into appropriate domain definition
bind_zone_add()
{
local path="$bind_root_dir/zone/$1";shift

install -d -m770 -o root -g named -- "${path%/*}"
[ -s "$path" ] || cat >"$path"
chown named:named "$path"
}

bind_zone_del()
{
local path="$bind_root_dir/zone/$1";shift

rm -f -- "$path" "$path.jnl"
}

# usage: bind_serial_init
# return initial value of serial
bind_serial_first()
{
date +%s
}

# usage: bind_serial_next
# return next value for current serial
bind_serial_next()
{
date +%s
}
alterator-bind-0.9.3/bin/ddns-sh-functions000064400000000000000000000613021212454776200205050ustar00rootroot00000000000000#!/bin/sh

### static variables
ddns_domain_file=/etc/ddns.conf
ddns_domain_dir=ddns
ddns_key="ddns-key"
ddns_ttl=86400

ddns_std_namelist="ldap" #hostname should be first

. alterator-net-functions
. bind-sh-functions
. alterator-service-functions

### system name
ddns_system_name()
{
local ddns_hostname="$(hostname)"
echo "${ddns_hostname%%.*}"
}

ddns_system_zone()
{
local ddns_hostname="$(hostname)"
echo "${ddns_hostname#*.}"
}

### shared secret key

# usage: ddns_key_exist <name>
# check for existance of shared secret key
ddns_key_exist()
{
local name="$1";shift
[ -s "$bind_root_dir/etc/$name.conf" ]
}

# usage: ddns_create_key <name> [<nsupdate>]
# create shared secret key
# if optional parameter <nsupdate> is equal to 1 then an additional keys for nsupdate will be created
ddns_create_key()
{
local name="$1";shift
local nsupdate="${1:-}"
cd "$bind_root_dir/etc"

ddns_key_exist "$name" && return 0

local key="$(/usr/sbin/dnssec-keygen -r /dev/urandom -a HMAC-MD5 -b 512 -n USER "$name")"
local secret="$(sed -n 's/Key:[[:space:]]\+\([^[:space:]]\+\)/\1/p' "$key.private")"

cd - >/dev/null

cat>"$bind_root_dir/etc/$name.conf"<<EOF
key $name {
algorithm hmac-md5;
secret "$secret";
};
EOF
chmod 0644 "$bind_root_dir/etc/$name.conf"
chown root:named "$bind_root_dir/etc/$name.conf"

[ "$nsupdate" = "1" ] || rm -f -- "$bind_root_dir/etc/K$name.+157+"*

bind_local_conf_include /etc/$name.conf
}

# usage: ddns_destroy_key <name>
# destroy shared secret key
ddns_destroy_key()
{
local name="$1";shift
cd "$bind_root_dir/etc"

rm -f -- "$bind_root_dir/etc/K$name.+157+"*
rm -f -- "$bind_root_dir/etc/$name.conf"

bind_local_conf_exclude /etc/$name.conf
}

# usage: ddns_print_key <name>
# print shared secret key
ddns_print_key()
{
local name="$1";shift
cat "$bind_root_dir/etc/$name.conf"
}

# usage: ddns_check_key <name> <file>
# validate <file> as shared secret key for name <name>
ddns_check_key()
{
local name
quote_sed_regexp_variable name "$1";shift
local file="$1";shift
grep -qs "^[[:space:]]*key[[:space:]]\+$name[[:space:]]\+{[[:space:]]*\$" "$file"
}

# usage: ddns_replace_key <name> <file>
# replace shared secret file with a new one
ddns_replace_key()
{
local name="$1";shift
local file="$1";shift

[ -s "$file" ] || return 0

install -pm 640 --owner root --group named "$file" "$bind_root_dir/etc/$name.conf"
bind_local_conf_include /etc/$name.conf
}

### update zone information

# usage: ddns_update <command...>
# call nsupdate with appropriate key and action
ddns_record_update()
{
nsupdate -k "$bind_root_dir/etc/K$ddns_key.+157+"*.private<<EOF
server localhost
update $@
send
EOF
}

### networks

# usage: ddns_net_foreach ip_version proc args
# call procedure for each available static network in system
ddns_net_foreach()
{
local v="$1";shift
local prog="$1";shift

list_iface|
while read iface; do
local ip="$(read_iface_current_addr "/etc/net/ifaces/$iface" "$v")"
[ -n "$ip" ] || continue
"$prog" "$ip" "$@" "$v"
done
}

# usage: ddns_net_list_all <ip_version>
# list all available networks
ddns_net_list_all()
{
local v="$1";shift
list_iface|
while read iface; do
local ip="$(read_iface_current_addr "/etc/net/ifaces/$iface" "$v")"
[ -n "$ip" ] || continue
printf '%s\t%s\n' "$ip" "$iface"
done
}


### reverse zones, each reverse zone can contain multiple reverse domains

# usage: ddns_reverse_zone_add_ns <reverse-zone> <domain>
# add ns entry of specified domain to reverse zone
ddns_reverse_zone_add_ns()
{
local rzone="$1";shift
local zone="$1";shift

ddns_record_update add $rzone $ddns_ttl NS ns.$zone
}

# usage: ddns_reverse_zone_del_ns <reverse-zone> <domain>
# remove ns entry of specified domain from reverse zone
ddns_reverse_zone_del_ns()
{
local rzone="$1";shift
local zone="$1";shift

ddns_record_update delete $rzone NS ns.$zone
}

# usage: ddns_reverse_zone_list_ns <reverse-zone>
# list domains supported by reverse zone (using ns records)
ddns_reverse_zone_list_ns()
{
local rzone="$1";shift

local sdig @localhost ns "$rzone" +short|
sed \
-e 's/^ns\.//'\
-e 's/\.$//'
}

# usage: ddns_reverse_zone_list_ptr <reverse-zone>
# return list of ptr supported by reverse zone
ddns_reverse_zone_list_ptr()
{
local rzone="$1";shift
dig -t AXFR @localhost "$rzone"|
sed -r -n \
"s/^([.a-zA-Z0-9_-]+\.)(ip6|in-addr)\.arpa\.[[:space:]]+[0-9]+[[:space:]]+IN[[:space:]]+PTR[[:space:]]+([.a-zA-Z0-9_-]+)\./\1\2.arpa\t\3/p"
}

# usage: ddns_reverse_zone_add_ptr <reverse-ip.in-addr-arpa> <host>
# add ptr into reverse zone
ddns_reverse_zone_add_ptr()
{
local rzone="$1";shift
local rname="$1";shift

ddns_record_update add $rzone $ddns_ttl PTR $rname
}

# usage: ddns_reverse_zone_del_ptr <reverse-ip.in-addr-arpa> <host>
# remove ptr from reverse zone
ddns_reverse_zone_del_ptr()
{
local rzone="$1";shift
local rname="$1";shift

ddns_record_update delete $rzone PTR $rname
}

# usage: ddns_reverse_zone_sync_soa <reverse-zone>
ddns_reverse_zone_sync_soa()
{
local rzone="$1";shift
local rest_zone="$(ddns_reverse_zone_list_ns "$rzone"|tail -n1)"
local new_tail="$(dig -t SOA @localhost "$rzone" +short|awk '{printf "%s %s %s %s %s\n",($3+1),$4,$5,$6,$7;}')"
ddns_record_update add $rzone $ddns_ttl SOA ns.$rest_zone root.$rest_zone $new_tail
}

### forward zones

# usage: ddns_forward_zone_add_a <ip> <host.domain>
# add A record to zone
ddns_forward_zone_add_a()
{
local ip="$1";shift
local host="$1";shift

ddns_record_update add $host $ddns_ttl A $ip
}

# usage: ddns_forward_zone_del_a <ip> <host.domain>
ddns_forward_zone_del_a()
{
local ip="$1";shift
local host="$1";shift

ddns_record_update delete $host A $ip
}

# usage: ddns_forward_zone_has_a <ip> <host.domain>
ddns_forward_zone_has_a()
{
local ip="$1";shift
local host="$1";shift

dig @localhost a "$host" +short|fgrep -wqs "$ip"
}

# usage: ddns_forward_zone_list_a <domain>
# list available a records from forward zone
ddns_forward_zone_list_a()
{
local zone="$1";shift

dig -t AXFR @localhost "$zone"|
sed -n \
-e 's/^\([.a-zA-Z0-9_-]\+\)\.[[:space:]]\+[0-9]\+[[:space:]]\+IN[[:space:]]\+A[[:space:]]\+\([0-9.]\+\)/\2\t\1/p'
}

# usage: ddns_forward_zone_add_aaaa <ipv6> <host.domain>
# add AAAA record to zone
ddns_forward_zone_add_aaaa()
{
local ip="$1";shift
local host="$1";shift

ddns_record_update add $host $ddns_ttl AAAA $ip
}

# usage: ddns_forward_zone_del_aaaa <ipv6> <host.domain>
ddns_forward_zone_del_aaaa()
{
local ip="$1";shift
local host="$1";shift

ddns_record_update delete $host AAAA $ip
}

# usage: ddns_forward_zone_has_aaaa <ipv6> <host.domain>
ddns_forward_zone_has_aaaa()
{
local ip="$1";shift
local host="$1";shift

dig @localhost aaaa "$host" +short|fgrep -wqs "$ip"
}

# usage: ddns_forward_zone_list_aaaa <domain>
# list available aaaa records from forward zone
ddns_forward_zone_list_aaaa()
{
local zone="$1";shift

dig -t AXFR @localhost "$zone"|
sed -n \
-e 's/^\([.a-zA-Z0-9_-]\+\)\.[[:space:]]\+[0-9]\+[[:space:]]\+IN[[:space:]]\+AAAA[[:space:]]\+\([[:xdigit:]:]\+\)/\2\t\1/p'
}

# usage: ddns_reverse_zone_add_ns <zone> <host>
# add NS entry of specified domain to forward zone
ddns_forward_zone_add_ns()
{
local zone="$1";shift
local host="$1";shift

ddns_record_update add $zone $ddns_ttl NS $host
}

# usage: ddns_reverse_zone_del_ns <zone> <host>
# remove ns entry of specified domain from forward zone
ddns_forward_zone_del_ns()
{
local zone="$1";shift
local host="$1";shift

ddns_record_update delete $zone NS $host
}

# usage: ddns_reverse_zone_list_ns <zone>
# list ns entries of specified domain (according forward zone)
ddns_forward_zone_list_ns()
{
local zone="$1";shift
dig @localhost ns "$zone" +short|
sed -e 's/\.$//'
}

# usage: ddns_forward_zone_list_mx <zone>
# list available mx records (with weights)
ddns_forward_zone_read_mx()
{
local zone="$1";shift
dig -t MX @localhost "$zone" +short|
sort -k1,1 -n|
sed -e 's/\.$//'
}

# usage: ddns_forward_zone_write_mx <zone>
# replace mx entries with a new one
# read list from stdin, each line constains weight and name
ddns_forward_zone_write_mx()
{
local zone="$1";shift
ddns_forward_zone_read_mx "$zone"|
while read weight host;do
ddns_record_update delete $zone MX $weight $host
done

while read weight host; do
ddns_record_update add $zone $ddns_ttl MX $weight $host
done
}

### reverse domains, each reverse domain can contain multiple reverse zones

# usage: __reverse_ip <ip> <ip_version>
# reverse ip address, helper for reverse zone processing
__reverse_ip()
{
local ip="$1"
local v="$2"
local out=
if [ "$v" = 4 ]; then
local IFS='.'
set $ip
out="$4.$3.$2.$1"
else
local i=
local tmp="$(ipv6addr_expand "$ip" | sed -r 's/([[:xdigit:]]):?/\1 /g')"
for i in $tmp; do
out="$i${out:+.}$out"
done
fi

echo "$out"
}

# usage: ddns_reverse_domain_add_host <zone> <ip> <name> <ip_version>
# add host<->ip binding to reverse zone of dynamic dns domain
ddns_reverse_domain_add_host()
{
local zone="$1";shift
local ip="$1";shift
local name="$1";shift
local ipv="$1";shift
local rzone= rev_map=

[ "$ipv" = 4 ] && rev_map=in-addr || rev_map=ip6
rzone="$(__reverse_ip "$ip" "$ipv").$rev_map.arpa"

if [ "$name" = "." ];then
name="$zone"
else
name="$name.$zone"
fi

ddns_reverse_zone_add_ptr "$rzone" "$name"
}

# usage: ddns_reverse_domain_del_host <zone> <ip> <name> <ip_version>
# remove host<->ip binding from reverse zone of dynamic dns domain
ddns_reverse_domain_del_host()
{
local zone="$1";shift
local ip="$1";shift
local name="$1";shift
local ipv="$1";shift
local rzone= rev_map=

[ "$ipv" = 4 ] && rev_map=in-addr || rev_map=ip6
rzone="$(__reverse_ip "$ip" "$ipv").$rev_map.arpa"

if [ "$name" = "." ];then
name="$zone"
else
name="$name.$zone"
fi

ddns_reverse_zone_del_ptr "$rzone" "$name"
}

__ipv6_revdns()
{
local ip="${1%/*}"
local prefix="${1#*/}"
local pos n t net_head ip_s hex_mask s tmp out i

[ $prefix -gt 0 -a $prefix -lt 128 ] || return 1
ip="$(ipv6addr_expand $ip)"
pos=$(($prefix / 16))
t="$(($pos * 4 + $pos))"
net_head="${ip:0:$t}"
ip_s="${ip#$net_head}"
ip_s="${ip_s%%:*}"
n=$(($prefix % 16))
hex_mask="$((0xffff >> $n))"
s=$((0x$ip_s & $hex_mask))
tmp="$(printf "%s%04x" "$net_head" "$s" | sed -r 's/([[:xdigit:]]):?/\1 /g')"
for i in $tmp; do
out="$i${out:+.}$out"
done

echo "$out"
}

# usage: ddns_reverse_domain_add_net <zone> <ip-address/mask> <ip_version>
# add network to reverse zone of dynamic dns domain
ddns_reverse_domain_add_net()
{
local zone="$1";shift
local ip="$1";shift
local ipv="$1";shift
local rev_ip="$(__reverse_ip "${ip%%/*}" "$ipv")"
local tail_ip=
local rev_zone=
local ddns_rzone=
local system_name="$(ddns_system_name)"
local revdns_list=
local rev_map=

if [ "$ipv" = 4 ]; then
revdns_list="$(revdns $ip)"
rev_map='in-addr'
else
revdns_list="$(__ipv6_revdns "$ip")"
rev_map='ip6'
fi

for rev_zone in $revdns_list;do
ddns_rzone="$rev_zone.$rev_map.arpa"
tail_ip="${rev_ip%.$rev_zone}"

if bind_domain_exists "$ddns_rzone";then
# add an additional ns entry and binding to hostname to existing reverse zone
ddns_reverse_zone_add_ns "$ddns_rzone" "$zone"
[ "$tail_ip" = "$rev_ip" ] || ddns_reverse_domain_add_host "$zone" "${ip%%/*}" "$system_name" "$ipv"
else
# create new reverse zone
bind_domain_add "$ddns_domain_file" "$ddns_rzone"<<EOF
type master;
file "$ddns_domain_dir/$ddns_rzone";
allow-update { key $ddns_key; };
EOF

local ddns_ns_record="ns.$zone."
local ddns_user_record="root.$zone."

bind_zone_add "$ddns_domain_dir/$ddns_rzone"<<EOF
\$TTL 1D
@ IN SOA $ddns_ns_record $ddns_user_record ($(bind_serial_first) 12H 1H 1W 1H)
IN NS $ddns_ns_record
$([ "$tail_ip" = "$rev_ip" ] || printf '%s\t\t\tPTR\t%s.' "$tail_ip" "$system_name.$zone")
EOF
fi
done
}

# usage: ddns_reverse_domain_del_net <zone> <ip-address/mask> <ip_version>
# remove network from reverse zone of dynamic dns domain
ddns_reverse_domain_del_net()
{
local zone="$1";shift
local ip="$1";shift
local ipv="$1";shift
local ddns_rzone=
local revdns_list=
local rev_map=

if [ "$ipv" = 4 ]; then
revdns_list="$(revdns $ip)"
rev_map='in-addr'
else
revdns_list="$(__ipv6_revdns "$ip")"
rev_map='ip6'
fi

for rev_zone in $revdns_list;do
ddns_rzone="$ddns_rzone.$rev_map.arpa"

local rzone_count="$(ddns_reverse_zone_list_ns "$ddns_rzone"|wc -l)"
if [ "$rzone_count" = "1" ];then
# no more domains in this reverse zone, free resource
bind_domain_del "$ddns_domain_file" "$ddns_rzone"
bind_zone_del "$ddns_domain_dir/$ddns_rzone"
else
# remove appropriate domain from this zone

local rptr=
local rname=
#clear pointers for our domain
ddns_reverse_zone_list_ptr "$ddns_rzone"|
while read rptr rname; do
[ "${rname%%.$zone}" = "$rname" ] ||
ddns_reverse_zone_del_ptr "$rptr" "$rname"
done

# remove ns
ddns_reverse_zone_del_ns "$ddns_rzone" "$zone"

# update soa, soa should be equal to rest ns
ddns_reverse_zone_sync_soa "$ddns_rzone"
fi
done
}

# usage: ddns_calc_master_ip <ip_version>
ddns_calc_master_ip()
{
local ipv="$1"; shift
local ip=''
for iface in $(list_static_iface); do
ip="$(read_iface_addr "/etc/net/ifaces/$iface" "$ipv")"
[ -n "$ip" ] && break
done
# look for nonstatic interface if no static found
if [ -z "$ip" ]; then
for iface in $(list_iface); do
ip="$(read_iface_current_addr "/etc/net/ifaces/$iface" "$ipv")"
[ -n "$ip" ] && break
done
fi
echo "$ip"
}

### forward domains, each forward domain contain one forward zone

# usage: ddns_create_forward_domain <zone> <type>
# create new forward zone of dynamic dns domain
# type is equal to master or slave
ddns_create_forward_domain()
{
local zone="$1";shift
local type="$1";shift

case "$type" in
master)
ddns_create_key "$zone-transfer-key"
bind_domain_add "$ddns_domain_file" "$zone"<<EOF
type master;
file "$ddns_domain_dir/$zone";
allow-update { key $ddns_key; };
allow-transfer { localhost; key $zone-transfer-key; };
notify yes;
EOF

local ddns_ns_record="ns.$zone."
local ddns_user_record="root.$zone."
local system_name="$(ddns_system_name)"
local system_ipv4="$(ddns_calc_master_ip 4)"
local system_ipv6="$(ddns_calc_master_ip 6)"
system_ipv4="${system_ipv4%%/*}"
system_ipv6="${system_ipv6%%/*}"
bind_zone_add "$ddns_domain_dir/$zone"<<EOF
\$TTL 1D
@ IN SOA $ddns_ns_record $ddns_user_record ($(bind_serial_first) 12H 1H 1W 1H)
IN NS $ddns_ns_record
;
$([ -n "$system_ipv4" ] && echo "ns A $system_ipv4")
$([ -n "$system_ipv6" ] && echo "ns AAAA $system_ipv6")
_kerberos._udp SRV 0 0 88 $system_name
_kerberos._tcp SRV 0 0 88 $system_name
_kerberos-adm._tcp SRV 0 0 749 $system_name
_kerberos TXT $(echo $zone| tr '[[:lower:]]' '[[:upper:]]')
EOF
;;
slave)
control bind-slave enabled
bind_domain_add "$ddns_domain_file" "$zone"<<EOF
type slave;
file "slave/$zone";
allow-transfer { localhost; key $zone-transfer-key; };
masters { };
EOF
;;
esac
}

# usage: ddns_destroy_forward_domain <zone>
# destroy forward zone of dynamic dns domain
ddns_destroy_forward_domain()
{
local zone="$1";shift

ddns_destroy_key "$zone-transfer-key";
bind_domain_del "$ddns_domain_file" "$zone"
bind_zone_del "$ddns_domain_dir/$zone"
bind_zone_del "slave/$zone"
}

# usage: ddns_list_forward_domain
# list available forward domains
ddns_list_forward_domain()
{
bind_domain_list "$ddns_domain_file"|egrep -v '\.(in-addr|ip6)\.arpa$'
}

# usage: ddns_forward_domain_list_host <zone> <ip_version>
# return list of hosts of dynamic dns domain (forward zone)
ddns_forward_domain_list_host()
{
local zone="$1";shift
local ipv="$1";shift

if [ "$ipv" = 4 ]; then
ddns_forward_zone_list_a "$zone"
else
ddns_forward_zone_list_aaaa "$zone"
fi | sed -e "s/\.$zone//" \
-e "s/$zone/./"
}

__full_name()
{
local zone="$1";shift
local name="$1";shift

if [ "$name" = "." ];then
echo "$zone"
else
echo "$name.$zone"
fi
}

# usage: ddns_forward_domain_del_host <zone> <ip> <host> <ip_version>
# remove host<->ip binding from dynamic dns domain (forward zone)
ddns_forward_domain_del_host()
{
local zone="$1";shift
local ip="$1";shift
local host="$1";shift
local ipv="$1";shift
local name="$(__full_name "$zone" "$host")";shift

if [ "$ipv" = 4 ]; then
ddns_forward_zone_del_a "$ip" "$name"
else
ddns_forward_zone_del_aaaa "$ip" "$name"
fi
}

# usage: ddns_forward_domain_add_host <zone> <ip> <host> <ip_version>
# add host<->ip binding into dynamic dns domain (forward zone)
ddns_forward_domain_add_host()
{
local zone="$1";shift
local ip="$1";shift
local host="$1";shift
local ipv="$1";shift
local name="$(__full_name "$zone" "$host")";shift

if [ "$ipv" = 4 ]; then
ddns_forward_zone_add_a "$ip" "$name"
else
ddns_forward_zone_add_aaaa "$ip" "$name"
fi
}

# usage: ddns_forward_domain_has_host <ip> <host> <ip_version>
# check that some ip<->host binding exists
ddns_forward_domain_has_host()
{
local zone="$1";shift
local ip="$1";shift
local host="$1";shift
local ipv="$1";shift
local name="$(__full_name "$zone" "$host")";shift

[ "$ipv" = 4 ] &&
ddns_forward_zone_has_a "$ip" "$name" ||
ddns_forward_zone_has_aaaa "$ip" "$name"
}

# usage: ddns_forward_domain_add_net <zone> <ip-address/mask> <ip_version>
# add network to forward zone of dynamic dns domain,
# add map standard zone names to this ip address
ddns_forward_domain_add_net()
{
local zone="$1";shift
local ip="$1";shift
local ipv="$1";shift
local simple_ip="${ip%%/*}"

for name in '.' "$(ddns_system_name)" $ddns_std_namelist; do
ddns_forward_domain_add_host "$zone" "$simple_ip" "$name" "$ipv"
done
}

# usage: ddns_forward_domain_del_net <zone> <ip-address/mask> <ip_version>
# remove network to forward zone of dynamic dns domain,
# see zone and remove mappings to ip addresses from this network
ddns_forward_domain_del_net()
{
local zone="$1";shift
local ip="$1";shift
local ipv="$1";shift

local name
local address

ddns_forward_domain_list_host "$zone" "$ipv" |
while read address name; do
if [ "$ipv" = 4 ]; then
ipv4_ip_subnet "$address" "$ip" || continue
else
ipv6addr_is_in_subnet "$address" "$ip" || continue
fi
ddns_forward_domain_del_host "$zone" "$address" "$name" "$ipv"
done
}

### joint reverse and forward domains

# usage: ddns_domain_del_net <zone> <ip-address/mask> <ip_version>
# remove network both from forward and reverse zones
ddns_domain_del_net()
{
local zone="$1";shift
local ip="$1";shift
local ipv="$1";shift

ddns_forward_domain_del_net "$zone" "$ip" "$ipv"
ddns_reverse_domain_del_net "$zone" "$ip" "$ipv"
}

# usage: ddns_domain_add_net <zone> <ip-address/mask> <ip_version>
# add network both to forward and reverse zones
ddns_domain_add_net()
{
local zone="$1";shift
local ip="$1";shift
local ipv="$1";shift

ddns_forward_domain_add_net "$zone" "$ip" "$ipv"
ddns_reverse_domain_add_net "$zone" "$ip" "$ipv"
}

__check_forward()
{
local ip="$1";shift
local zone="$1";shift
local ipv="$1";shift
ddns_forward_domain_has_host "$zone" "${ip%%/*}" "." "$ipv" && echo "$ip" 2>/dev/null
}

ddns_domain_list_net()
{
local zone="$1";shift
local ipv="$1";shift

ddns_net_foreach "$ipv" __check_forward "$zone"
}

# usage: ddns_domain_list_host <zone> <ip_version>
# get domain contents
ddns_domain_list_host()
{
local zone="$1";shift
local ipv="$1";shift

ddns_forward_domain_list_host "$zone" "$ipv"
}

# usage: ddns_domain_has_host <zone> <ip> <host> <ip_version>
# check for host existance
ddns_domain_has_host()
{
local zone="$1";shift

ddns_forward_domain_has_host "$zone" "$@"
}

# usage: ddns_domain_is_reserved_host host
# check for reserved host names
ddns_domain_is_reserved_host()
{
local name="$1";shift
local namelist=" . $ddns_std_namelist localhost $(ddns_system_name) "

[ -z "${namelist##* $name *}" ]
}

__valid_ip()
{
local zone="$1";shift
local ip="$1";shift
local ipv="$1";shift
local rip="$(__reverse_ip "$ip" "$ipv")"
local net=
local rzone=
local rev_map=

[ "$ipv" = 4 ] && rev_map=in-addr || rev_map=ip6
# check for appropriate domain in all available reverse networks
for rzone in "$bind_root_dir/zone/$ddns_domain_dir/"*.$rev_map.arpa; do
rzone="${rzone##*/}"
net="${rzone%%.$rev_map.arpa}"
[ "${rip%%$net}" != "$rip" ] || continue
ddns_reverse_zone_list_ns "$rzone"|fgrep -wqs "$zone" && return 0
done

return 1
}


# usage: ddns_domain_add_host <zone> <ip> <host> <ip_version>
# add ip<->hostname binding
ddns_domain_add_host()
{
local zone="$1";shift
local ip="$1";shift
local name="$1";shift
local ipv="$1";shift

! __valid_ip "$zone" "$ip" "$ipv" || ddns_reverse_domain_add_host "$zone" "$ip" "$name" "$ipv"
ddns_forward_domain_add_host "$zone" "$ip" "$name" "$ipv"
}

# usage: ddns_domain_del_host <zone> <ip> <host> <ip_version>
# add ip<->hostname binding
ddns_domain_del_host()
{
local zone="$1";shift
local ip="$1";shift
local name="$1";shift
local ipv="$1";shift

ddns_reverse_domain_del_host "$zone" "$ip" "$name" "$ipv" || :
ddns_forward_domain_del_host "$zone" "$ip" "$name" "$ipv"
}

__add_reverse()
{
local ip="$1";shift
local zone="$1";shift
local ipv="$1";shift
ddns_reverse_domain_add_net "$zone" "$ip" "$ipv"
}

__add_forward()
{
local ip="$1";shift
local zone="$1";shift
local ipv="$1";shift
ddns_forward_domain_add_net "$zone" "$ip" "$ipv"
}

# usage: ddns_create_domain <zone> <type> [<fill-reverse>]
# create specified domain,
# type is equal to master or slave
# if optional parameter is equal to 1 then appropriate reverse zones will be also created
ddns_create_domain()
{
local zone="$1";shift
local type="$1";shift
local fill_reverse="${1:-}"

ddns_key_exist "$ddns_key" || ddns_create_key "$ddns_key" 1
ddns_create_forward_domain "$zone" "$type"
if [ "$type" = "master" -a "$fill_reverse" = "1" ] ;then
ddns_net_foreach 4 __add_reverse "$zone"
ddns_net_foreach 6 __add_reverse "$zone"
fi
service_control bind condreload # update forward zone info
if [ "$type" = "master" ] ;then
ddns_forward_domain_add_net "$zone" "$(ddns_calc_master_ip 4)" 4
ddns_forward_domain_add_net "$zone" "$(ddns_calc_master_ip 6)" 6
fi
}

# usage: ddns_destroy_domain <zone>
# destroy specified domain and release all it's resources
ddns_destroy_domain()
{
local zone="$1";shift
local net= ipv=

for ipv in 4 6; do
# release networks
ddns_domain_list_net "$zone" "$ipv"|
while read net;do
ddns_reverse_domain_del_net "$zone" "$net" "$ipv"
ddns_forward_domain_del_net "$zone" "$net" "$ipv"
done
done
# destroy forward zone
ddns_destroy_forward_domain "$zone"
}

ddns_domain_exists()
{
bind_domain_exists "$1"
}

ddns_list_domain()
{
ddns_list_forward_domain
}

ddns_domain_list_ns()
{
local zone="$1";shift
ddns_forward_zone_list_ns "$zone"
}

ddns_domain_add_ns()
{
ddns_forward_zone_add_ns "$@"
}

ddns_domain_del_ns()
{
ddns_forward_zone_del_ns "$@"
}

ddns_domain_read_mx()
{
local zone="$1";shift
local mx="$(ddns_forward_zone_read_mx "$zone"|sed 's/^[[:space:]]*[0-9]\+[[:space:]]\+//'|tr '\n' ' ')"
echo "${mx% }"
}

ddns_domain_write_mx()
{
local zone="$1";shift
local hostlist="$1";shift
local weight=10;

echo "$hostlist"|
tr ' ' '\n'|
sed '/^[[:space:]]*$/d'|
while read host; do
printf '%s %s\n' "$weight" "$host"
weight=$(($weight + 10))
done|
ddns_forward_zone_write_mx "$zone"
}

# usage: ddns_domain_read_type <zone>
# read domain type (master or slave)
ddns_domain_read_type()
{
local zone="$1";shift
bind_domain_get "$ddns_domain_file" "$zone" type
}

# usage: ddns_domain_read_master <zone>
# read masters of slave domain
# function returns space separated values
ddns_domain_read_master()
{
local zone="$1";shift

bind_domain_get "$ddns_domain_file" "$zone" masters|
sed -e 's/^[[:space:]]*{[[:space:]]*//' \
-e 's/[[:space:]]*}[[:space:]]*$//' \
-e "s/[[:space:]]\+key[[:space:]]\+[^[:space:]]\+[[:space:]]*;[[:space:]]*/ /g"
}

# usage: ddns_domain_write_master <zone> <slave-list>
# write masters of slave domain
# <slave-list> is a space separated host list
ddns_domain_write_master()
{
local zone="$1";shift
local value="$1";shift

local str="{"
for i in $value;do
str="$str $i key $zone-transfer-key;"
done
str="$str }"

bind_domain_set "$ddns_domain_file" "$zone" masters "$str"
}
alterator-bind-0.9.3/hook/000075500000000000000000000000001212454776200154025ustar00rootroot00000000000000alterator-bind-0.9.3/hook/ddns-hook-dhcp000075500000000000000000000004471212454776200201370ustar00rootroot00000000000000#!/bin/sh

. ddns-sh-functions

need_reload=

for ipv in 4 6; do
new_ip="$(read_iface_addr /etc/net/ifaces/$new_iface $ipv)"
[ -n "$new_ip" ] || continue

ddns_domain_add_net "$(ddns_system_zone)" "$new_ip" "$ipv"
need_reload=1
done

[ -z "$need_reload" ] || service_control bind condreload
alterator-bind-0.9.3/hook/ddns-hook-hostname000075500000000000000000000011601212454776200210300ustar00rootroot00000000000000#!/bin/sh -eu

. ddns-sh-functions

old_hostname="$1"
new_hostname="$2"

old_domain="${old_hostname#*.}"
new_domain="${new_hostname#*.}"

rename_hostname()
{
local ip="$1"
local ipv="$2"
ddns_list_domain|
while read zone;do
ddns_domain_del_host "$zone" "${ip%%/*}" "${old_hostname%%.*}" "$ipv"
ddns_domain_add_host "$zone" "${ip%%/*}" "${new_hostname%%.*}" "$ipv"
done
}

if [ "$old_domain" = "$new_domain" ];then
echo "rename hostname binding..." >&2
ddns_net_foreach 4 rename_hostname
ddns_net_foreach 6 rename_hostname
else
echo "recreate domain..." >&2
/usr/sbin/ddns-hook-reset
fi
alterator-bind-0.9.3/hook/ddns-hook-net-eth000075500000000000000000000034471212454776200205700ustar00rootroot00000000000000#!/bin/sh -eu

. ddns-sh-functions

del_net()
{
local ipv="$1";shift
local ip="$1";shift
local zone

echo "remove network $ip" >&2
ddns_list_domain|
while read zone; do
ddns_domain_del_net "$zone" "$ip" "$ipv"
done
}

change_net()
{
local ipv="$1";shift
local old_configuration="$1";shift
local new_configuration="$1";shift
local old_ip="$1";shift
local new_ip="$1";shift

[ "$old_configuration" = "static" ] || return 0

if [ "$new_configuration" = "dhcp" -o "$new_configuration" = "ipv4ll" ];then
del_net "$ipv" "$old_ip"
elif [ "$old_ip" != "$new_ip" ];then
local addr_is_in_subnet=
if [ "$ipv" = 4 ]; then
addr_is_in_subnet=ipv4_ip_subnet
else
addr_is_in_subnet=ipv6addr_is_in_subnet
fi
if [ "${old_ip##*/}" == "${new_ip##*/}" ] && $addr_is_in_subnet "${new_ip%%/*}" "$old_ip"; then
ddns_list_domain|
while read zone;do
ddns_domain_list_host "$zone" "$ipv"|
while read ip host; do
[ "$ip" = "${old_ip%%/*}" ] || continue
echo "rename host $host:${old_ip%%/*} -> ${new_ip%%/*}" >&2
ddns_domain_del_host "$zone" "${old_ip%%/*}" "$host" "$ipv"
ddns_domain_add_host "$zone" "${new_ip%%/*}" "$host" "$ipv"
done
done
else
del_net "$ipv" "$old_ip"
fi
fi
}

old_ipv4="$(echo "$old_ipv4addresses" | head -1)"
new_ipv4="$(echo "$new_ipv4addresses" | head -1)"
old_ipv6="$(echo "$old_ipv6addresses" | head -1)"
new_ipv6="$(echo "$new_ipv6addresses" | head -1)"

if [ "$new_config_ipv4" = no ]; then
del_net 4 "$old_ipv4"
else
change_net 4 "$old_ipv4configuration" "$new_ipv4configuration" "$old_ipv4" "$new_ipv4"
fi
if [ "$new_config_ipv6" = no ]; then
del_net 6 "$old_ipv6"
else
change_net 6 "$old_ipv6configuration" "$new_ipv6configuration" "$old_ipv6" "$new_ipv6"
fi

#restart as it should bind on new IP
service_control bind restart
alterator-bind-0.9.3/hook/dhcp-hook-hostname000075500000000000000000000004741212454776200210250ustar00rootroot00000000000000#!/bin/sh -efu

old_hostname="$1"
new_hostname="$2"

old_domain="${old_hostname#*.}"
new_domain="${new_hostname#*.}"

. alterator-dhcp-functions
. ddns-sh-functions

dhcp_config_set client_search "$(ddns_system_zone)" 4
dhcp_update_config 4
dhcp_config_set client_search "$(ddns_system_zone)" 6
dhcp_update_config 6
alterator-bind-0.9.3/hook/dhcp-hook-net-domain000075500000000000000000000020141212454776200212320ustar00rootroot00000000000000#!/bin/sh -efu

system_config_file=/etc/sysconfig/system
menu_config_file=/etc/alterator/menu/module-skip-list
ipv4_dhcpd_conf=/etc/dhcp/dhcpd.conf
ipv6_dhcpd_conf=/etc/dhcp/dhcpd6.conf

. shell-quote
. alterator-dhcp-functions
[ ! -s "$system_config_file" ] || . "$system_config_file"

chomp()
{
local out="${1# }"
echo "${out% }"
}

menu_skip_list()
{
local v=$(shell_config_get "$menu_config_file" MODULE_SKIP_LIST)
string_quote_remove "$v"
}

menu_skip_add()
{
grep -qs "^$1\$" "$menu_config_file" ||
echo "$1" >> "$menu_config_file"
}

menu_skip_del()
{
sed "/^$(quote_sed_regexp "$1")\$/d" -i "$menu_config_file"
}

if [ "${SERVER_ROLE:-}" = "master" ];then
#menu_skip_del dhcp

dhcp_daemon_on 4

[ -s "$ipv6_dhcpd_conf" ] &&
dhcp_daemon_on 6
else
#menu_skip_add dhcp
dhcp_daemon_off 4
dhcp_daemon_off 6
fi

#redirect client dns to local dns
dhcp_config_set client_dns '*' 4
dhcp_update_config 4

if [ -s "$ipv6_dhcpd_conf" ]; then
dhcp_config_set client_dns '*' 6
dhcp_update_config 6
fi
alterator-bind-0.9.3/sbin/000075500000000000000000000000001212454776200153755ustar00rootroot00000000000000alterator-bind-0.9.3/sbin/ddns-add-host000075500000000000000000000001231212454776200177500ustar00rootroot00000000000000#!/bin/sh -u

. ddns-sh-functions

ddns_domain_add_host "$(ddns_system_zone)" "$@"
alterator-bind-0.9.3/sbin/ddns-check-name000075500000000000000000000006151212454776200202460ustar00rootroot00000000000000#!/bin/sh -eu

. ddns-sh-functions

name="$1";shift

check_ns()
{
local system_zone="$(ddns_system_zone)"
local rc=1
host -t ns "$system_zone" localhost|
sed -n -e 's/.*[[:space:]]\+name[[:space:]]\+server[[:space:]]\+//p' |
sed -e "s/.$system_zone.//"|grep -qs "^$name\$" || rc=0
return "$rc"
}

check_std()
{
! ddns_domain_is_reserved_host "$name"
}

check_std && check_ns
alterator-bind-0.9.3/sbin/ddns-del-host000075500000000000000000000001231212454776200177640ustar00rootroot00000000000000#!/bin/sh -u

. ddns-sh-functions

ddns_domain_del_host "$(ddns_system_zone)" "$@"
alterator-bind-0.9.3/sbin/ddns-hook-reset000075500000000000000000000013361212454776200203340ustar00rootroot00000000000000#!/bin/sh -u

. ddns-sh-functions

echo -n '' > $bind_root_dir/$ddns_domain_file
service_control bind restart

### dynamic variables
resolvconfzone_file="$bind_root_dir/etc/resolvconf-zones.conf"

#clear resolvconf zones information
if [ -f "$resolvconfzone_file" ];then
echo "Cleaning up resolvconf zones..." >&2
>"$resolvconfzone_file"
fi

#remove previous zone definitions
rm -f -- "$bind_root_dir/$ddns_domain_file"
rm -f -- "$bind_root_dir/zone/$ddns_domain_dir"/*

ddns_create_domain "$(ddns_system_zone)" "master" "1"

/usr/sbin/dhcp-reset-static

#update resolvconf zones information
if [ -f "$resolvconfzone_file" ];then
echo "Update resolvconf zones..." >&2
resolvconf -u
fi

service_control bind condreload
alterator-bind-0.9.3/sbin/dhcp-print-config000075500000000000000000000011411212454776200206330ustar00rootroot00000000000000#!/bin/sh

. ddns-sh-functions

ipv="${1:-4}"

if [ "$ipv" = 4 ]; then
drop_filter="ip6\.arpa"
primary="primary 127.0.0.1"
else
drop_filter="in-addr\.arpa"
primary="primary6 ::1"
fi

printf 'ddns-update-style interim;\n'
printf 'ddns-updates on;\n'
printf 'ddns-domainname "%s";\n' "$(ddns_system_zone)"
printf 'include "%s";\n\n' "$bind_root_dir/etc/$ddns_key.conf"
find "$bind_root_dir/zone/$ddns_domain_dir" -type f|
grep -v '\.jnl$'|
grep -v "$drop_filter$"|
while read zone;do
printf 'zone %s. {\n' "${zone##*/}"
printf "\t$primary;\n"
printf '\tkey ddns-key;\n'
printf '}\n\n'
done
alterator-bind-0.9.3/sbin/dhcp-reset-static000075500000000000000000000002371212454776200206500ustar00rootroot00000000000000#!/bin/sh -efu

. alterator-dhcp-functions

rm -f -- /etc/alterator/dhcp/static
dhcp_update_config 4
rm -f -- /etc/alterator/dhcp6/static
dhcp_update_config 6
alterator-bind-0.9.3/ui/000075500000000000000000000000001212454776200150575ustar00rootroot00000000000000alterator-bind-0.9.3/ui/bind/000075500000000000000000000000001212454776200157735ustar00rootroot00000000000000alterator-bind-0.9.3/ui/bind/ajax.scm000064400000000000000000000101771212454776200174300ustar00rootroot00000000000000(define-module (ui bind ajax)
:use-module (alterator ajax)
:use-module (alterator effect)
:use-module (alterator woo)
:export (init))

(define (ui-host-list)
(form-update-enum
"ddns_host"
(woo-list "/bind/ddns_host" 'ddns_domain (form-value "ddns_domain"))))


(define (ui-host-add)
(catch/message
(lambda()
(let ((new_ddns_ip (form-value "new_ddns_ip"))
(new_ddns_host (form-value "new_ddns_host")))
(and (string? new_ddns_ip)
(string? new_ddns_host)
(begin
(woo "add" "/bind"
'language (form-value "language")
'ddns_domain (form-value "ddns_domain")
'new_ddns_ip (form-value "new_ddns_ip")
'new_ddns_host (form-value "new_ddns_host"))
(form-update-value "new_ddns_ip" "")
(form-update-value "new_ddns_host" "")
(ui-host-list)))))))

(define (ui-host-del)
(catch/message
(lambda()
(let ((ddns_host (form-value "ddns_host")))
(and (string? ddns_host)
(begin
(woo "del" "/bind"
'language (form-value "language")
'ddns_domain (form-value "ddns_domain")
'ddns_host ddns_host)
(ui-host-list)))))))

(define *parameter-list* '("ddns_type" "ddns_has_key" "ddns_master" "ddns_ns" "ddns_mx" "ddns_network"))

(define (ui-write)
(catch/message
(lambda()
(apply woo-write "/bind"
'language (form-value "language")
'ddns_domain (form-value "ddns_domain")
(form-value-list *parameter-list*))
(ui-read))))

(define (ui-read)
(form-update-value-list
*parameter-list*
(woo-read-first "/bind" 'ddns_domain (form-value "ddns_domain")))
(form-update-value "ddns_key_state"
(if (string= (form-value "ddns_has_key") "0")
(_ "not loaded yet!")
(_ "activated")))
(update-effect)
(ui-host-list))

(define (ui-list . name)
(let* ((data (woo-list "/bind/ddns_domain"))
(ddns_domain (or (and (pair? name) (car name))
(and (pair? data) (woo-get-option (car data) 'name)))))
(form-update-enum "ddns_domain" data)
(cond
((string? ddns_domain)
(form-update-value "ddns_domain" ddns_domain)
(ui-read)))))

(define (ui-create)
(catch/message
(lambda()
(let ((new_ddns_domain (form-value "new_ddns_domain")))
(woo "create" "/bind"
'language (form-value "language")
'new_ddns_type (form-value "new_ddns_type")
'new_ddns_domain new_ddns_domain)
(form-update-value "new_ddns_domain" "")
(ui-list new_ddns_domain)))))

(define (ui-destroy)
(catch/message
(lambda()
(let ((ddns_domain (form-value "ddns_domain")))
(cond ((and (string? ddns_domain)
(form-confirm (string-append (_ "Are you really want to destroy domain ")
(form-value "ddns_domain")
"?")))
(woo "destroy" "/bind"
'language (form-value "language")
'ddns_domain ddns_domain)
(ui-list)))))))

(define (ui-download)
(form-replace "/bind/key" 'ddns_domain (form-value "ddns_domain")))

(define (ui-upload)
(call-with-form-file
"ddns_key"
(lambda(path)
(catch/message
(lambda()
(woo "write_key" "/bind" 'ddns_key_file path 'ddns_domain (form-value "ddns_domain") 'language (form-value "language"))
(ui-read))))))

(define (init)

(form-update-enum "new_ddns_type" (woo-list "/bind/ddns_type" 'language (form-value "language")))
(form-update-enum "ddns_network" (woo-list "/bind/ddns_network" 'language (form-value "language")))
(ui-list)

(effect-show "ddns_master_field" "ddns_type" "master")
(effect-show "ddns_slave_field" "ddns_type" "slave")
(init-effect)

(form-bind "ddns_domain" "change" ui-read)

(form-bind "ddns_download_button" "click" ui-download)
(form-bind-upload "ddns_upload_button" "click" "ddns_key" ui-upload)

(form-bind "ddns_apply_button" "click" ui-write)
(form-bind "ddns_reset_button" "click" ui-read)

(form-bind "ddns_create_button" "click" ui-create)
(form-bind "ddns_destroy_button" "click" ui-destroy)

(form-bind "ddns_add_button" "click" ui-host-add)
(form-bind "ddns_del_button" "click" ui-host-del))
alterator-bind-0.9.3/ui/bind/index.html000064400000000000000000000114451212454776200177750ustar00rootroot00000000000000<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<!-- tcp connections module -->
<html wf="none">
<body>
<form method="POST">
<input type="hidden" name="ddns_type"/>
<input type="hidden" name="ddns_has_key"/>
<table>
<tr>
<td colspan="2">
<span translate="_" nameref="new_ddns_domain">New domain:</span>&nbsp;<input type="text" class="text" name="new_ddns_domain"/>&nbsp;<select name="new_ddns_type"/>
&nbsp;
<input type="button" class="btn" name="ddns_create_button" value="Create"/>
</td>
</tr>
<tr>
<td colspan="2"><hr/></td>
</tr>
</table>
<table>
<tr>
<td style="text-align:right;padding-right:3px"><span translate="_">Existing domains:</span></td>
<td><select name="ddns_domain"/></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
</table>
<table>
<tr name="ddns_master_field">
<td style="text-align:right;padding-right:3px"><span translate="_" nameref="ddns_ns">Slave servers:</span></td>
<td>
<input type="text" class="text" name="ddns_ns" size="40"/>
<br/>
<small><span translate="_">(whitespace separated list of hostnames)</span></small>
</td>
</tr>
<tr name="ddns_slave_field">
<td style="text-align:right;padding-right:3px"><span translate="_" nameref="ddns_master">Master servers:</span></td>
<td>
<input type="text" class="text" name="ddns_master" size="40"/>
<br/>
<small><span translate="_">(whitespace separated list of ip addresses)</span></small>
</td>
</tr>
<tr name="ddns_master_field">
<td style="text-align:right;padding-right:3px"><span translate="_" nameref="ddns_mx">Mail servers:</span></td>
<td>
<input type="text" class="text" name="ddns_mx" size="40"/>
<br/>
<small><span translate="_">(whitespace separated list of hostnames in priority descend order)</span></small>
</td>
</tr>
<tr name="ddns_master_field">
<td style="text-align:right;padding-right:3px"><span translate="_">Domain key:</span></td>
<td><input type="button" class="btn" name="ddns_download_button" value="Download..."/></td>
</tr>
<tr name="ddns_slave_field">
<td style="text-align:right;padding-right:3px"><span translate="_">Domain key:</span></td>
<td>
<span class="alterator-label" name="ddns_key_state"/>
</td>
</tr>
<tr name="ddns_slave_field">
<td>&nbsp;</td>
<td>
<input type="file" name="ddns_key"/>
<input type="button" class="btn" name="ddns_upload_button" value="Upload a new domain key"/>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr name="ddns_master_field">
<td style="text-align:right;padding-right:3px"><span translate="_">Networks:</span></td>
<td><table class="alterator-checklistbox" name="ddns_network"/></td>
</tr>
<tr name="ddns_master_field">
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<input type="button" class="btn" name="ddns_apply_button" value="Change settings"/>
&nbsp;
<input type="button" class="btn" name="ddns_reset_button" value="Reset"/>
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" class="btn" name="ddns_destroy_button" value="Remove domain"/>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:left">&nbsp;</td>
</tr>
<tr>
<td colspan="2" style="text-align:left"><span translate="_">Hosts:</span></td>
</tr>
<tr>
<td colspan="2" style="text-align:left">
<div style="width: 100%; max-height:200px;overflow:auto">
<table class="alterator-listbox multi-select" name="ddns_host">
<thead>
<tr>
<th><span translate="_">Host</span></th>
<th><span translate="_">IP address</span></th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="alterator-label" name="host"/></td>
<td><span class="alterator-label" name="ip"/></td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr name="ddns_master_field">
<td colspan="2" style="padding-top:5px"><input type="button" class="btn" name="ddns_del_button" value="Remove selected"/></td>
</tr>
<tr name="ddns_master_field">
<td colspan="2" style="text-align:left">&nbsp;</td>
</tr>
<tr name="ddns_master_field">
<td colspan="2">
<span translate="_" nameref="new_ddns_host">Host:</span>
<input type="text" class="text" name="new_ddns_host" size="10"/>
<span translate="_" nameref="new_ddns_ip">IP address:</span>
<input type="text" class="text" name="new_ddns_ip" size="15"/>
&nbsp;
<input type="button" class="btn" name="ddns_add_button" value="Add"/>
</td>
</tr>
</table>
</form>
</body>
</html>
alterator-bind-0.9.3/ui/bind/key/000075500000000000000000000000001212454776200165635ustar00rootroot00000000000000alterator-bind-0.9.3/ui/bind/key/ajax.scm000064400000000000000000000006661212454776200202220ustar00rootroot00000000000000(define-module (ui bind key ajax)
:use-module (alterator algo)
:use-module (alterator ajax)
:use-module (alterator woo)
:export (ui))

(define (ui)
(let ((domain (form-value "ddns_domain")))
(and (string? domain)
(ui-blob "ddns_key"
(cond-car (woo "read_key" "/bind" 'ddns_domain domain))
"text/plain"
(string-append domain "-transfer-key.conf")))))
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin