Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37852964
en ru br
ALT Linux repos
S:0.9.6-alt1
5.0: 0.6-alt4
4.1: 0.3-alt1.M41.8
4.0: 0.1-alt4.M40.1

Group :: System/Configuration/Other
RPM: alterator-dhcp

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

alterator-dhcp-0.9.3/000075500000000000000000000000001212455022700144325ustar00rootroot00000000000000alterator-dhcp-0.9.3/Makefile000064400000000000000000000012541212455022700160740ustar00rootroot00000000000000NAME=dhcp

all:
clean:
install: install-module install-data

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

install-data:
install -d $(sysconfdir)/alterator/dhcp
touch $(sysconfdir)/alterator/dhcp/general
touch $(sysconfdir)/alterator/dhcp/static
install -d $(sysconfdir)/alterator/dhcp6
touch $(sysconfdir)/alterator/dhcp6/general
touch $(sysconfdir)/alterator/dhcp6/static
install -Dpm755 bin/alterator-dhcp-reset $(bindir)/alterator-dhcp-reset
install -Dpm644 bin/alterator-dhcp-functions $(bindir)/alterator-dhcp-functions
install -Dpm 755 alterator-dhcp.hook $(libexecdir)/alterator/hooks/net-eth.d/alterator-dhcp
install -dpm 755 $(libexecdir)/alterator/hooks/dhcp.d/
alterator-dhcp-0.9.3/alterator-dhcp.hook000075500000000000000000000024371212455022700202360ustar00rootroot00000000000000#!/bin/sh

ipv4_general_conf=/etc/alterator/dhcp/general
ipv4_static_conf=/etc/alterator/dhcp/static
ipv6_general_conf=/etc/alterator/dhcp6/general
ipv6_static_conf=/etc/alterator/dhcp6/static

. alterator-service-functions
. shell-config

dhcpd_stop()
{
local dhcp_daemon="$1";shift
local general_conf="$1"; shift
local static_conf="$1"; shift

rm -f -- "$general_conf" "$static_conf"
service_control "$dhcp_daemon" condstop
}


ipv4_dhcp_iface="$(shell_config_get "$ipv4_general_conf" iface)"
ipv6_dhcp_iface="$(shell_config_get "$ipv6_general_conf" iface)"

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 [ -n "$ipv4_dhcp_iface" -a "$ipv4_dhcp_iface" = "$1" ]; then
if [ "$new_config_ipv4" = no -o \
"$new_ipv4configuration" = "dhcp" -o \
"$new_ipv4configuration" = "ipv4ll" -o \
"$old_ipv4" != "$new_ipv4" ]; then
dhcpd_stop dhcpd "$ipv4_general_conf" "$ipv4_static_conf"
fi
fi

if [ -n "$ipv6_dhcp_iface" -a "$ipv6_dhcp_iface" = "$1" ]; then
if [ "$new_config_ipv6" = no -o \
"$new_ipv6configuration" = "dhcp" -o \
"$old_ipv6" != "$new_ipv6" ]; then
dhcpd_stop dhcpd6 "$ipv6_general_conf" "$ipv6_static_conf"
fi
fi
alterator-dhcp-0.9.3/applications/000075500000000000000000000000001212455022700171205ustar00rootroot00000000000000alterator-dhcp-0.9.3/applications/dhcp.desktop000064400000000000000000000004111212455022700214250ustar00rootroot00000000000000[Desktop Entry]
Encoding=UTF-8
Type=Application
Categories=X-Alterator-Servers
Icon=dhcp
Terminal=false
Name=DHCP server
X-Alterator-URI=/dhcp
X-Alterator-UI=html
X-Alterator-Help=dhcp
Name[ru]=DHCP-сервер
Name[uk]=DHCP-сервер
Name[pt_BR]=Servidor DHCP
alterator-dhcp-0.9.3/backend3/000075500000000000000000000000001212455022700161045ustar00rootroot00000000000000alterator-dhcp-0.9.3/backend3/dhcp000075500000000000000000000231661212455022700167600ustar00rootroot00000000000000#!/bin/sh

alterator_api_version=1

. alterator-sh-functions
. alterator-net-functions
. alterator-dhcp-functions

. shell-quote

static_conf_ipv4="/etc/alterator/dhcp/static"
static_conf_ipv6="/etc/alterator/dhcp6/static"
ddns_add_tool="/usr/sbin/ddns-add-host"
ddns_del_tool="/usr/sbin/ddns-del-host"
ddns_check_tool="/usr/sbin/ddns-check-name"
hooks_dir=/usr/lib/alterator/hooks/dhcp.d
_radvd=/usr/sbin/radvd

### helpers
get_static_conf()
{
[ "$1" = 6 ] &&
echo "$static_conf_ipv6" ||
echo "$static_conf_ipv4"
}

### ddns bindings
ddns_add()
{
[ -x "$ddns_add_tool" ] || return
"$ddns_add_tool" "$1" "$2" "$3"
}

ddns_del()
{
[ -x "$ddns_del_tool" ] || return
"$ddns_del_tool" "$1" "$2" "$3"
}

### static bindings

static_list()
{
local ipv="$1"; shift
local static_conf="$(get_static_conf "$ipv")"

[ ! -s "$static_conf" ] || cat "$static_conf"
}

static_del()
{
local del_mac="$1"; shift
local ipv="$1"; shift
local static_conf="$(get_static_conf "$ipv")"
local IFS=' '
grep "^$(quote_sed_regexp "$del_mac")[[:space:]]" "$static_conf"|
(read mac ip hname;
[ -z "$ip" -o -z "$hname" ] || ddns_del "$ip" "$hname" "$ipv")

sed "/^$(quote_sed_regexp "$del_mac")[[:space:]]/ d" -i "$static_conf"
}

static_has()
{
local mac="$1"; shift
local ipv="$1"; shift
local static_conf="$(get_static_conf "$ipv")"
grep -qs "^$(quote_sed_regexp "$mac")[[:space:]]" "$static_conf"
}

static_check_name()
{
[ -z "$1" ] ||
[ ! -x "$ddns_check_tool" ] ||
"$ddns_check_tool" "$1"
}

#TODO: check ip range
static_add()
{
local mac="$1";shift
local ip="$1";shift
local hname="$1";shift
local ipv="$1";shift
local static_conf="$(get_static_conf "$ipv")"
printf '%s %s %s\n' "$mac" "$ip" "$hname">>"$static_conf"
dhcp_lease_remove "$ip" "$ipv"
[ -z "$ip" -o -z "$hname" ] || ddns_add "$ip" "$hname" "$ipv"
}

static_rename()
{
local mac="$1";shift
local ip="$1";shift
local hname="$1";shift
local ipv="$1";shift
static_del "$mac" "$ipv"
static_add "$mac" "$ip" "$hname" "$ipv"
}

### dynamic bindings
write_date()
{
run_localized date -d "$1 GMT"
}

check_dhcpd_conf()
{
local ipv="$1";shift
local iface="$(dhcp_config_get iface "$ipv")"
local ip_start="$(dhcp_config_get ip_start "$ipv")"
local ip_end="$(dhcp_config_get ip_end "$ipv")"

if [ -z "$in_iface" ]; then
write_error "`_ "You should define network interface"`"
return 1
elif [ -z "$in_ip_start" -o -z "$in_ip_end" ]; then
write_error "`_ "You should define address range"`"
return 1
else
return 0
fi
}

do_static_del()
{
local ipv="$1";shift
local IFS=";"
for i in $in_static_name; do static_del "$i" "$ipv"; done
}

do_lease_fix()
{
local ipv="$1";shift
local IFS=";"
local ip= mac= hname=

for i in $in_lease_name; do
ip="${i%%_*}"
mac="${i##${ip}_}"
mac="${mac%%_*}"
hname="${i##${ip}_${mac}_}"

static_check_name "$hname" || continue

static_has "$mac" "$ipv" || static_add "$mac" "$ip" "$hname" "$ipv"
done
}

check_range()
{
local first="$1";shift
local second="$1";shift
local net="$1";shift
local ipv="$1";shift
local addr_is_in_subnet=

[ "$ipv" = 6 ] &&
addr_is_in_subnet=ipv6addr_is_in_subnet ||
addr_is_in_subnet=ipv4_ip_subnet

[ -n "$first" ] &&
[ -n "$second" ] &&
$addr_is_in_subnet "$first" "$net" &&
$addr_is_in_subnet "$second" "$net"
}

read_static()
{
local inmac="$1";shift
local ipv="$1";shift
local static_conf="$(get_static_conf "$ipv")"

grep "^$inmac[[:space:]]" "$static_conf"|
(read mac ip hname;
write_string_param mac "$mac"
write_string_param new_static_ip "$ip"
write_string_param new_static_hname "$hname")
}

on_message()
{
case "$in_action" in
type)
write_type_item ip_start ip-address
write_type_item ip_end ip-address
write_type_item client_dns dhcp-dns-address
write_type_item client_search hostname
write_type_item client_gw ipv4-address
write_type_item new_static_ip ip-address
write_type_item new_static_hname system-computer-name
write_type_item new_static_mac dhcp-mac-address
;;
list)
case "$in__objects" in
ipv)
write_enum_item "4" "`_ "IPv4"`"
write_enum_item "6" "`_ "IPv6"`"
;;
avail_lease)
dhcp_lease_list "$in_ipv"|
while IFS='_' read -r ip mac expired hname; do
static_has "$mac" "$in_ipv"||
write_table_item \
name "${ip}_${mac}_${hname}" \
lease_ip "$ip" \
lease_mac "$mac" \
lease_hname "$hname" \
lease_expired "$(write_date "$expired")"
done
;;
avail_static)
static_list "$in_ipv"|
while read mac ip hname; do
write_table_item \
name "$mac" \
static_mac "$mac" \
static_ip "$ip" \
static_hname "$hname"
done
;;
avail_iface)
if [ "$in_ipv" = 4 ]; then
list_static_iface 4|
while read name; do
local ip="$(read_iface_addr "/etc/net/ifaces/$name" 4)"
printf "%s %s\n" $name "$(netname "$ip")"
done |
while read name network_name ip_start ip_end; do
write_enum_item "$name" "$name ($ip_start - $ip_end)"
done
else
list_static_iface 6|
while read name; do
local ip="$(read_iface_addr "/etc/net/ifaces/$name" 6)"
write_enum_item "$name" "$name ("$(ipv6_network "$ip")")"
done
fi
;;
avail_time)
write_enum_item 3600 "`_ "1 hour"`"
write_enum_item 7200 "`_ "2 hours"`"
write_enum_item 14400 "`_ "4 hours"`"
write_enum_item 28800 "`_ "8 hours"`"
write_enum_item 43200 "`_ "12 hours"`"
write_enum_item 86400 "`_ "1 day"`"
write_enum_item 604800 "`_ "1 week"`"
write_enum_item 1209600 "`_ "2 weeks"`"
write_enum_item 18748800 "`_ "1 month"`"
;;
esac
;;
read)
case "$in__objects" in
/)
! dhcp_daemon_status "$in_ipv"
write_bool_param daemon "$?"

local iface="$(dhcp_config_get iface "$in_ipv")"
[ -n "$iface" ] || iface="$(list_static_iface "$in_ipv"|head -n1)"

local ip="$(read_iface_addr "/etc/net/ifaces/$iface" "$in_ipv")"
local ip_start="$(dhcp_config_get ip_start "$in_ipv")"
local ip_end="$(dhcp_config_get ip_end "$in_ipv")"

if [ -z "$ip" ] ||
! check_range "$ip_start" "$ip_end" "$ip" "$in_ipv";then
ip_start=
ip_end=
fi

write_string_param ip_start "$ip_start"
write_string_param ip_end "$ip_end"

write_string_param iface "$iface"
write_string_param client_time "$(dhcp_config_get client_time "$in_ipv")"
write_string_param client_dns "$(dhcp_config_get client_dns "$in_ipv")"
[ "$in_ipv" = 6 ] || write_string_param client_gw "$(dhcp_config_get client_gw 4)"
write_string_param client_search "$(dhcp_config_get client_search "$in_ipv")"

role=$(shell_config_get /etc/sysconfig/system SERVER_ROLE)
[ ! -x "$ddns_check_tool" ] || [ "$role" != 'master' ]
write_bool_param has_ddns "$?"
;;
static)
read_static "$in_mac" "$in_ipv"
;;
esac
;;
write)
case "$in__objects" in
/)
if [ "$in_ipv" = 6 ]; then
[ -x "$_radvd" ] ||
write_error "`_ "Radvd is not installed! DHCPv6 can't work properly"`"
fi

if [ -n "$in_general" -a -n "$in_iface" ];then
local old_iface="$(dhcp_config_get iface "$in_ipv")" # previous value of iface
local new_iface="$in_iface" # new value of iface
local ip="$(read_iface_addr "/etc/net/ifaces/$new_iface" "$in_ipv")"

if ! check_range "$in_ip_start" "$in_ip_end" "$ip" "$in_ipv";then
write_error "`_ "Invalid address range"`"
return 1
fi

dhcp_config_set ip_start "$in_ip_start" "$in_ipv"
dhcp_config_set ip_end "$in_ip_end" "$in_ipv"

dhcp_config_set iface "$new_iface" "$in_ipv"
dhcp_config_set client_time "$in_client_time" "$in_ipv"
dhcp_config_set client_dns "$in_client_dns" "$in_ipv"
[ "$in_ipv" = 6 ] || dhcp_config_set client_gw "$in_client_gw" "$in_ipv"
dhcp_config_set client_search "$in_client_search" "$in_ipv"

#note: update config before daemon start to create initial config
dhcp_update_config "$in_ipv"
if test_bool "$in_daemon"; then
dhcp_daemon_on "$in_ipv"
else
dhcp_daemon_off "$in_ipv"
fi

#postinstall hook
if [ "$old_iface" != "$new_iface" ];then
export old_iface new_iface
run-parts "$hooks_dir"
fi
elif ! check_dhcpd_conf "$in_ipv"; then #check general conf before any other actions
return
elif [ -n "$in_static_del" -a -n "$in_static_name" ];then
do_static_del "$in_ipv"
dhcp_update_config "$in_ipv"
elif [ -n "$in_static_add" -a -n "$in_new_static_ip" -a -n "$in_new_static_mac" ]; then
if static_has "$in_new_static_mac" "$in_ipv"; then
write_error "`_ "Same entry already exists"`"
return
elif ! static_check_name "$in_new_static_hname";then
write_error "`_ "This computer name is registered for internal purposes"`"
return
else
static_add "$in_new_static_mac" "$in_new_static_ip" "$in_new_static_hname" "$in_ipv"
fi
dhcp_update_config "$in_ipv"
elif [ -n "$in_lease_fix" -a -n "$in_lease_name" ]; then
do_lease_fix "$in_ipv"
dhcp_update_config "$in_ipv"
fi
;;
static)
[ -n "$in_mac" ] || return
if ! static_check_name "$in_new_static_hname"; then
write_error "`_ "This computer name is registered for internal purposes"`"
return
else
[ -z "$in_new_static_ip" ] ||
static_rename "$in_mac" "$in_new_static_ip" "$in_new_static_hname" "$in_ipv"
fi

dhcp_update_config "$in_ipv"
;;
esac
;;
esac
}

message_loop
alterator-dhcp-0.9.3/bin/000075500000000000000000000000001212455022700152025ustar00rootroot00000000000000alterator-dhcp-0.9.3/bin/alterator-dhcp-functions000075500000000000000000000065571212455022700220640ustar00rootroot00000000000000#!/bin/sh -efu

dhcp_generalconf_file="/etc/alterator/dhcp/general"
dhcp6_generalconf_file="/etc/alterator/dhcp6/general"
dhcp_lease_file="/var/lib/dhcp/dhcpd/state/dhcpd.leases"
dhcp6_lease_file="/var/lib/dhcp/dhcpd6/state/dhcpd6.leases"
_radvd="/usr/sbin/radvd"

. alterator-service-functions
. shell-config
. shell-quote

### daemon

dhcp_daemon_status()
{
local ipv="${1-}"
local IFS=' '

[ "$ipv" = 6 ] || ipv=

service_control "dhcpd$ipv" is-enabled || return 1
service_control "dhcpd$ipv" is-active || return 1
if [ "$ipv" = 6 ]; then
service_control radvd is-enabled || return 1
service_control radvd is-active || return 1
fi

return 0
}

dhcp_daemon_on()
{
local ipv="${1-}"

if [ "$ipv" = 6 ]; then
[ -x "$_radvd" ] || return 1
else
ipv=
fi

dhcp_daemon_status "$ipv" && return 0

service_control "dhcpd$ipv" enable &&
service_control "dhcpd$ipv" start ||:

# Enable radvd too
if [ "$ipv" = 6 ]; then
service_control radvd on &&
service_control radvd start ||:
fi
}

dhcp_daemon_off()
{
local ipv="${1-}"

[ "$ipv" = 6 ] || ipv=

service_control "dhcpd$ipv" condstop ||:
service_control "dhcpd$ipv" disable ||:
# Disable radvd too
if [ "$ipv" = 6 ]; then
service_control radvd condstop ||:
service_control radvd disable ||:
fi
}

dhcp_daemon_condreload()
{
local ipv="${1-}"

[ "$ipv" = 6 ] || ipv=

service_control "dhcpd$ipv" condreload
# Reload radvd too
if [ "$ipv" = 6 ]; then
service_control radvd condreload
fi
}

### config file

dhcp_config_get()
{
local var="$1"; shift
local ipv="${1-}"
local conf_file=

[ "$ipv" = 6 ] || ipv=

eval "conf_file=\$dhcp${ipv}_generalconf_file"
shell_config_get "$conf_file" "$var"
}

dhcp_config_set()
{
local var="$1"; shift
local value="$1"; shift
local ipv="${1-}"
local conf_file=

[ "$ipv" = 6 ] || ipv=

eval "conf_file=\$dhcp${ipv}_generalconf_file"
shell_config_set "$conf_file" "$var" "$value"
}

dhcp_update_config()
{
local ipv="${1-}"
alterator-dhcp-reset "$ipv" && dhcp_daemon_condreload "$ipv" || :
}

#### leases

dhcp_lease_list()
{
local ipv="${1-}"
local lease_file=

[ "$ipv" = 6 ] || ipv=
eval "lease_file=\$dhcp${ipv}_lease_file"

/bin/awk \
'BEGIN { OFS = "_"}

match($0,/^[[:space:]]*lease[[:space:]]+([^[:space:]]+)[[:space:]]+\{[[:space:]]*$/,re) { r["ip"]=re[1]; }
match($0,/^[[:space:]]*binding state[[:space:]]+([^[:space:]]+)[[:space:]]*;[[:space:]]*$/,re) { r["state"] = re[1]; }
match($0,/^[[:space:]]*hardware ethernet[[:space:]]+([^[:space:]]+)[[:space:]]*;[[:space:]]*$/,re) { r["hw"] = re[1]; }
match($0,/^[[:space:]]*ends[[:space:]]+[^[:space:]]+[[:space:]]+([^;]+);[[:space:]]*$/,re) { r["expired"]=re[1]; }
match($0,/^[[:space:]]*client-hostname[[:space:]]+"([^;"]+)"[[:space:]]*;[[:space:]]*$/,re) { r["hostname"]=re[1]; }

/^[[:space:]]*}[[:space:]]*$/ { if (r["state"] == "active") print r["ip"],r["hw"],r["expired"],r["hostname"]; for (i in r) delete r[i]; } ' \
"$lease_file"
}

dhcp_lease_remove()
{
local ip="$1";shift
local ipv="${1-}"
local lease_file=

[ "$ipv" = 6 ] || ipv=
eval "lease_file=\$dhcp${ipv}_lease_file"

dhcp_daemon_status "$ipv"
local running="$?"
service_control "dhcpd$ipv" condstop

sed "/^[[:space:]]*lease[[:space:]]\+$(quote_sed_regexp "$ip")[[:space:]]\+{/,/^[[:space:]]*}[[:space:]]*$/ d" \
-i "$lease_file"

[ "$running" = "0" ] && service_control "dhcpd$ipv" start
}
alterator-dhcp-0.9.3/bin/alterator-dhcp-reset000075500000000000000000000157061212455022700211720ustar00rootroot00000000000000#!/bin/sh -efu

ipv4_general_conf="/etc/alterator/dhcp/general"
ipv4_static_conf="/etc/alterator/dhcp/static"
ipv4_dhcpd_conf="/etc/dhcp/dhcpd.conf"
ipv6_general_conf="/etc/alterator/dhcp6/general"
ipv6_static_conf="/etc/alterator/dhcp6/static"
ipv6_dhcpd_conf="/etc/dhcp/dhcpd6.conf"
radvd_conf="/etc/radvd.conf"
ddns_tool="/usr/sbin/dhcp-print-config"
ddns_key="/var/lib/bind/etc/ddns-key.conf"
kdc_tool="/usr/bin/alterator-kdc-dhcp-host-option"

. shell-config
. alterator-net-functions

tempfile=

if [ "$1" = 6 ]; then
general_conf="$ipv6_general_conf"
static_conf="$ipv6_static_conf"
dhcpd_conf="$ipv6_dhcpd_conf"
generate_func=generate_ipv6
else
general_conf="$ipv4_general_conf"
static_conf="$ipv4_static_conf"
dhcpd_conf="$ipv4_dhcpd_conf"
generate_func=generate_ipv4
fi

exit_handler()
{
local rc="$?"
trap - EXIT
rm -f "$tempfile"
exit "$@"
}

trap exit_handler EXIT HUP PIPE INT QUIT TERM

smart_addr()
{
if [ "$1" = "*" ]; then
echo "${2%%/*}"
else
echo "$1"
fi
}

generate_ipv4()
{
local iface="$(shell_config_get "$general_conf" iface)"
local ip_start="$(shell_config_get "$general_conf" ip_start)"
local ip_end="$(shell_config_get "$general_conf" ip_end)"

[ -n "$iface" -a -n "$ip_start" -a -n "$ip_end" ] || return 1

local ip="$(read_iface_addr "/etc/net/ifaces/$iface" 4)"

[ -n "$ip" ] || return 1

local net="$(netname "$ip"|cut -f1)"
local net_ip="${net%%/*}"
local net_mask="$(maskname "${ip##*/}")"

printf '#auto generated by alterator-dhcp-reset\n\n'

[ -x "$ddns_tool" ] && [ -f "$ddns_key" ] && "$ddns_tool" 4 || printf 'ddns-update-style none;\n'

printf 'authoritative;\n\n'
printf 'option space altlinux;\noption altlinux.keydata code 2 = string;\nvendor-option-space altlinux;\n\n'

local static_map= static_ip=
[ ! -s "$static_conf" ] ||
while IFS=" " read static_mac static_ip static_hname; do
printf 'host %s { hardware ethernet %s; fixed-address %s; ' "$static_ip" "$static_mac" "$static_ip"
[ ! -x "$kdc_tool" ] || $kdc_tool "$static_hname"
echo '}'
done <"$static_conf"

printf '\n'

printf 'subnet %s netmask %s {\n' "$net_ip" "$net_mask"

local client_gw="$(shell_config_get "$general_conf" client_gw)"
local client_dns="$(shell_config_get "$general_conf" client_dns)"
local client_search="$(shell_config_get "$general_conf" client_search)"
local client_time="$(shell_config_get "$general_conf" client_time)"
local client_ntp="$(shell_config_get "$general_conf" client_ntp)"

local client_pxe_root="$(shell_config_get "$general_conf" client_pxe_root)"
local client_pxe_server="$(shell_config_get "$general_conf" client_pxe_server)"
local client_pxe_filename="$(shell_config_get "$general_conf" client_pxe_filename)"

[ -z "$client_pxe_server" ] || printf '\tnext-server %s;\n' "$(smart_addr "$client_pxe_server" "$ip")"
[ -z "$client_pxe_filename" ] || printf '\tfilename "%s";\n' "$(smart_addr "$client_pxe_filename" "$ip")"
[ -z "$client_pxe_root" ] || printf '\toption root-path "%s";\n' "$client_pxe_root"

[ -z "$client_ntp" ] || printf '\toption ntp-servers %s;\n' "$(smart_addr "$client_ntp" "$ip")"
[ -z "$client_gw" ] || printf '\toption routers %s;\n' "$client_gw"
[ -z "$client_dns" ] || printf '\toption domain-name-servers %s;\n' "$(smart_addr "$client_dns" "$ip")"
if [ -n "$client_search" ];then
local client_domain="${client_search%% *}"
printf '\toption domain-name "%s";\n' "$client_domain"
fi
[ -z "$client_time" ] || printf '\tdefault-lease-time %s;\n\tmax-lease-time %s;\n' "$client_time" "$client_time"

printf '\trange %s %s;\n' "$ip_start" "$ip_end"

printf '}\n'
}

generate_ipv6()
{
local iface="$(shell_config_get "$general_conf" iface)"
local ip_start="$(shell_config_get "$general_conf" ip_start)"
local ip_end="$(shell_config_get "$general_conf" ip_end)"

[ -n "$iface" -a -n "$ip_start" -a -n "$ip_end" ] || return 1

local ip="$(read_iface_addr "/etc/net/ifaces/$iface" 6)"

[ -n "$ip" ] || return 1

local net="$(ipv6_network "$ip")"
local net_ip="${net%%/*}"

printf '#auto generated by alterator-dhcp-reset\n\n'

[ -x "$ddns_tool" ] && [ -f "$ddns_key" ] && "$ddns_tool" 6 || printf 'ddns-update-style none;\n'

printf 'authoritative;\n\n'
printf 'option space altlinux;\noption altlinux.keydata code 2 = string;\nvendor-option-space altlinux;\n\n'

local static_map= static_ip=
[ ! -s "$static_conf" ] ||
while IFS=" " read static_mac static_ip static_hname; do
printf 'host %s { hardware ethernet %s; fixed-address6 %s; ' "$static_hname" "$static_mac" "$static_ip"
[ ! -x "$kdc_tool" ] || $kdc_tool "$static_hname"
echo '}'
done <"$static_conf"

printf '\n'

printf 'subnet6 %s {\n' "$net"

local client_dns="$(shell_config_get "$general_conf" client_dns)"
local client_search="$(shell_config_get "$general_conf" client_search)"
local client_time="$(shell_config_get "$general_conf" client_time)"
local client_ntp="$(shell_config_get "$general_conf" client_ntp)"

local client_pxe_root="$(shell_config_get "$general_conf" client_pxe_root)"
local client_pxe_server="$(shell_config_get "$general_conf" client_pxe_server)"
local client_pxe_filename="$(shell_config_get "$general_conf" client_pxe_filename)"

[ -n "$client_pxe_server" -a -n "$client_pxe_filename" -a -n "$client_pxe_root" -a \
"$client_pxe_filename" != '*' ] &&
printf '\toption dhcp6.bootfile-url "tftp://[%s]%s/%s";\n' \
"$(smart_addr "$client_pxe_server" "$ip")" "$client_pxe_root" "$client_pxe_filename"

# Cann't find option like ntp-servers for DHCPv6
# [ -z "$client_ntp" ] || printf '\toption ntp-servers %s;\n' "$(smart_addr "$client_ntp" "$ip")"
[ -z "$client_dns" ] || printf '\toption dhcp6.name-servers %s;\n' "$(smart_addr "$client_dns" "$ip")"
if [ -n "$client_search" ];then
local client_domain="${client_search%% *}"
printf '\toption dhcp6.domain-search "%s";\n' "$client_domain"
fi
[ -z "$client_time" ] || printf '\tdefault-lease-time %s;\n\tmax-lease-time %s;\n' "$client_time" "$client_time"

printf '\trange6 %s %s;\n' "$ip_start" "$ip_end"

printf '}\n'
}

generate_radvd_conf()
{
local iface="$(shell_config_get "$ipv6_general_conf" iface)"
[ -n "$iface" ] || return 1

local ip="$(read_iface_addr "/etc/net/ifaces/$iface" 6)"
local net="$(ipv6_network "$ip")"
[ -n "$net" ] || return 1

printf '#auto generated by alterator-dhcp-reset\n\n'
printf 'interface %s {\n' "$iface"
printf '\tAdvSendAdvert on;\n'
printf '\tAdvManagedFlag on;\n'
printf '\tAdvOtherConfigFlag on;\n'
printf '\tprefix %s {\n' "$net"
printf '\t\tAdvOnLink on;\n'
printf '\t\tAdvAutonomous off;\n'
printf '\t};\n'
printf '};\n'
}

tempfile="$(mktemp -t alterator-dhcp.XXXXXX)"
$generate_func >"$tempfile" && mv "$tempfile" "$dhcpd_conf" || exit 1
if [ "$1" = 6 ]; then
tempfile="$(mktemp -t alterator-dhcp.XXXXXX)"
generate_radvd_conf >"$tempfile" && mv "$tempfile" "$radvd_conf" || exit 1
fi
alterator-dhcp-0.9.3/type/000075500000000000000000000000001212455022700154135ustar00rootroot00000000000000alterator-dhcp-0.9.3/type/dhcp-dns-address.scm000064400000000000000000000003431212455022700212420ustar00rootroot00000000000000(define-module (type dhcp-dns-address)
:use-module ((type ip-address) :renamer (symbol-prefix-proc 'ip-address:))
:export (type))

(define (type v _)
(or (and (string? v) (string=? v "*"))
(ip-address:type v _)))
alterator-dhcp-0.9.3/type/dhcp-mac-address.scm000064400000000000000000000007211212455022700212160ustar00rootroot00000000000000(define-module (type dhcp-mac-address)
:use-module (alterator woo)
:export (type))

(define *hex* "[0-9a-fA-F]{2}")
(define *mac-address-regex-str* (string-append *hex* "(:" *hex* "){5}"))
(define *mac-address-regex* (make-regexp *mac-address-regex-str* regexp/extended))

(define (type v _)
(or (and (string? v) (string-null? v))
(and (string? v) (regexp-exec *mac-address-regex* v))
(type-error (_ "invalid MAC address" "alterator-dhcp"))))
alterator-dhcp-0.9.3/ui/000075500000000000000000000000001212455022700150475ustar00rootroot00000000000000alterator-dhcp-0.9.3/ui/dhcp/000075500000000000000000000000001212455022700157655ustar00rootroot00000000000000alterator-dhcp-0.9.3/ui/dhcp/ajax.scm000064400000000000000000000064011212455022700174150ustar00rootroot00000000000000(define-module (ui dhcp ajax)
:use-module (alterator ajax)
:use-module (alterator woo)
:export (init))

(define *parameters* '("daemon" "iface" "ip_start" "ip_end" "client_time" "client_dns" "client_search" "client_gw"))

(define (ui-general-read)
(catch/message
(lambda()
(let ((data (woo-read-first "/dhcp" 'ipv (form-value "ipv"))))
(form-update-value-list *parameters* data)
(form-update-visibility
'("client_dns" "client_search")
(not (woo-get-option data 'has_ddns)))))))

(define (ui-general-write)
(catch/message
(lambda()
(apply woo-write "/dhcp"
'general #t
'ipv (form-value "ipv")
'language (form-value "language")
(form-value-list *parameters*))
(ui-general-read))))

(define (ui-static-read)
(form-update-value "new_static_ip" "")
(form-update-value "new_static_mac" "")
(form-update-value "new_static_hname" "")
(form-update-enum "static_name" (woo-list "/dhcp/avail_static" 'ipv (form-value "ipv"))))

;; note: iface, ip_start and ip_end are used for config validation
(define (ui-static-del)
(catch/message
(lambda()
(apply woo-write "/dhcp"
'static_del #t
'ipv (form-value "ipv")
'language (form-value "language")
(form-value-list '("static_name"
"iface" "ip_start" "ip_end")))
(ui-static-read))))

;; note: iface, ip_start and ip_end are used for config validation
(define (ui-static-add)
(catch/message
(lambda()
(apply woo-write "/dhcp"
'static_add #t
'ipv (form-value "ipv")
'language (form-value "language")
(form-value-list '("new_static_ip" "new_static_mac" "new_static_hname"
"iface" "ip_start" "ip_end")))
(ui-static-read))))

(define (ui-lease-read)
(form-update-enum "lease_name" (woo-list "/dhcp/avail_lease" 'ipv (form-value "ipv"))))

(define (ui-lease-fix)
(catch/message
(lambda()
(apply woo-write "/dhcp"
'lease_fix #t
'ipv (form-value "ipv")
'language (form-value "language")
(form-value-list '("lease_name"
"iface" "ip_start" "ip_end")))
(ui-lease-read)
(ui-static-read))))

(define (update-ui)
(let* ((ipv (form-value "ipv"))
(iface-list (woo-list "/dhcp/avail_iface" 'ipv ipv 'language (form-value "language"))))
(if (null? iface-list)
(begin
(form-update-visibility "nostatic_page" #t)
(form-update-visibility "static_page" #f))
(begin
(form-update-visibility "client_gw" (string=? ipv "4"))
;; lists
(form-update-enum "iface" iface-list)
;; read
(ui-general-read)
(ui-static-read)
(ui-lease-read)))))

(define (init)
(form-update-enum "ipv" (woo-list "/dhcp/ipv" 'language (form-value "language")))
(form-update-value "ipv" "4")
(form-update-enum "client_time" (woo-list "/dhcp/avail_time" 'language (form-value "language")))
(update-ui)
;; buttons
(form-bind "apply_button" "click" ui-general-write)
(form-bind "reset_button" "click" ui-general-read)
(form-bind "static_del_button" "click" ui-static-del)
(form-bind "static_add_button" "click" ui-static-add)
(form-bind "lease_fix_button" "click" ui-lease-fix)
(form-bind "ipv" "change" update-ui)
)

alterator-dhcp-0.9.3/ui/dhcp/index.html000064400000000000000000000125031212455022700177630ustar00rootroot00000000000000<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<!-- dhcp administration module -->
<html wf="none">
<body>
<form method="POST">
<div name="nostatic_page" class="alterator-attention-message" style="float:none;display:none">
<img src="/design/images/attention.gif"/>
<span translate="_">You must have statically configured ethernet interface to setup dhcp server.</span>
<br/>
<br/>
<a href="/net-eth"><span translate="_">Reconfigure ethernet interfaces...</span></a>
</div>
<div name="static_page">
<table class="form-table-annotated">
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2" style="text-align:left"><strong><span translate="_">General settings</span></strong></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><span translate="_">Select IP version:</span></td>
<td>
<select name="ipv"/>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="checkbox" name="daemon" value="#t"/><span translate="_">Enable DHCP server</span></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><span translate="_">Interface:</span></td>
<td>
<select name="iface"/><br/>
<small><span translate="_">(maximum possible address range)</span></small>
</td>
</tr>
<tr>
<td><span name="ip_start" translate="_">Starting IP address:</span></td>
<td><input class="text" type="text" name="ip_start"/></td>
</tr>
<tr>
<td><span name="ip_end" translate="_">Ending IP address:</span></td>
<td><input class="text" type="text" name="ip_end"/></td>
</tr>
<tr>
<td><span translate="_">Address expiration time:</span></td>
<td><select name="client_time" enumref="/dhcp/avail_time"/></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2" style="text-align:left"><strong><span translate="_">Information provided for clients</span></strong></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><span name="client_dns" translate="_">DNS server:</span></td>
<td><input type="text" class="text" name="client_dns"/></td>
</tr>
<tr>
<td><span name="client_search" translate="_">Search domain:</span></td>
<td><input type="text" class="text" name="client_search"/></td>
</tr>
<tr>
<td><span name="client_gw" translate="_">Default gateway:</span></td>
<td><input type="text" class="text" name="client_gw"/></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="button" class="btn" name="apply_button" value="Apply"/>
&nbsp;
<input type="button" class="btn" name="reset_button" value="Reset"/>
</td>
</tr>
</table>
<hr/>
<strong><span translate="_">Static addresses</span></strong>
<br/><br/>

<div style="width:100%;max-height:300px; overflow: auto;">
<table name="static_name" class="alterator-listbox multi-select" style="width:100%">
<thead>
<tr>
<th><span translate="_">IP address</span></th>
<th><span translate="_">MAC address</span></th>
<th><span translate="_">Computer name</span></th>
</tr>
</thead>
<tbody>
<tr style="display:none">
<td><a class="alterator-href" prefix-href="/dhcp/static?mac=" name="name">
<span class="alterator-label" name="static_ip"/>
</a>
</td>
<td><span class="alterator-label" name="static_mac"/></td>
<td><span class="alterator-label" name="static_hname"/></td>
</tr>
</tbody>
</table>
</div>
<br/>

<input type="button" class="btn" name="static_del_button" value="Remove selected"/><br/>
<br/>
<span translate="_">New static address:</span>
<br/><br/>
<table class="form-table">
<tr>
<td><span name="new_static_ip" translate="_">IP address:</span></td>
<td><input type="text" class="text" name="new_static_ip"/></td>
</tr>
<tr>
<td><span name="new_static_mac" translate="_">MAC address:</span></td>
<td><input type="text" class="text" name="new_static_mac"/></td>
</tr>
<tr>
<td><span name="new_static_hname" translate="_">Computer name:</span></td>
<td><input type="text" class="text" name="new_static_hname"/></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="button" class="btn" name="static_add_button" value="Add"/></td>
</tr>
</table>
<hr/>
<strong><span translate="_">Current dynamically allocated addresses</span></strong>
<br/><br/>

<div style="width:100%;max-height:300px; overflow: auto;">
<table name="lease_name" class="alterator-listbox multi-select" style="width:100%">
<thead>
<tr>
<th><span translate="_">Computer name</span></th>
<th><span translate="_">MAC address</span></th>
<th><span translate="_">IP address</span></th>
<th><span translate="_">Expiration time</span></th>
</tr>
</thead>
<tbody>
<tr style="display:none">
<td><span class="alterator-label" name="lease_hname"/></td>
<td><span class="alterator-label" name="lease_mac"/></td>
<td><span class="alterator-label" name="lease_ip"/></td>
<td><span class="alterator-label" name="lease_expired"/></td>
</tr>
</tbody>
</table>
</div>
<br/>
<input type="button" class="btn" name="lease_fix_button" value="Fix address for selected hosts"/>
</div>
</form>
</body>
</html>
alterator-dhcp-0.9.3/ui/dhcp/static/000075500000000000000000000000001212455022700172545ustar00rootroot00000000000000alterator-dhcp-0.9.3/ui/dhcp/static/ajax.scm000064400000000000000000000015101212455022700207000ustar00rootroot00000000000000(define-module (ui dhcp static ajax)
:use-module (alterator ajax)
:use-module (alterator woo)
:export (init))

(define (ui-read)
(let ((mac (form-value "mac"))
(ipv (form-value "ipv")))
(form-update-value "mac" mac)
(form-update-value-list
'("new_static_ip" "new_static_hname")
(woo-read-first "/dhcp/static" 'mac mac 'ipv ipv))))

(define (ui-write)
(catch/message
(lambda()
(apply woo-write "/dhcp/static"
(form-value-list '("ipv" "language" "mac" "new_static_ip" "new_static_hname")))
(form-replace "/dhcp"))))

(define (init)
(form-update-enum "ipv" (woo-list "/dhcp/ipv" 'language (form-value "language")))
(form-update-value "ipv" "4")
(ui-read)
(form-bind "apply" "click" ui-write)
(form-bind "reset" "click" ui-read)
(form-bind "ipv" "change" ui-read))
alterator-dhcp-0.9.3/ui/dhcp/static/index.html000064400000000000000000000020761212455022700212560ustar00rootroot00000000000000<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html wf="none">
<body>
<form method="POST">
<table class="form-table">
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td><span translate="_">Select IP version:</span></td>
<td>
<select name="ipv"/>
</td>
</tr>
<tr>
<td><span translate="_">MAC address:</span></td>
<td><span class="alterator-label" name="mac"/></td>
</tr>
<tr>
<td><span name="new_static_ip" translate="_">IP address:</span></td>
<td><input type="text" class="text" name="new_static_ip"/></td>
</tr>
<tr>
<td><span name="new_static_hname" translate="_">Computer name:</span></td>
<td><input type="text" class="text" name="new_static_hname"/></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="button" class="btn" name="apply" value="Apply"/>&nbsp;
<input type="button" class="btn" name="reset" value="Reset"/>
</td>
</tr>
</table>
</form>
</body>
</html>
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin