#!/bin/bash

exit_status=0

. exec/system/config/allg.sh
. exec/system/shell/allg/file.sh

find_script domain/dns read.sh

echo > /tmp/dhcpfix.$$
echo > /tmp/dhcpfix6.$$
get_data "$getfixaddress" | \
  while read line; 
  do
    get_dnsaddress "$line"
    if [ "$macaddr" != "" ]; then
      if [ "$record" = "A" ]; then
      cat >> /tmp/dhcpfix.$$ << EOF
    host $name {
                option host-name "$name";
                ddns-hostname "$name";
                hardware ethernet $macaddr;
                fixed-address $address;
    } 
EOF
      fi
      if [ "$record" = "AAAA" ]; then
      cat >> /tmp/dhcpfix6.$$ << EOF
    host $name {
                option host-name "$name";
                ddns-hostname "$name";
                host-identifier option dhcp6.client-id $macaddr;
                fixed-address6 $address;
    } 
EOF
      fi
    fi
      
  done
  
mv /tmp/dhcpfix.$$ /etc/dhcp/fix.conf
mv /tmp/dhcpfix6.$$ /etc/dhcp/fix6.conf

if [ ! "$dhcpstart" = "" ] && [ ! "$dhcpend" = "" ]; then
  systemctl restart isc-dhcp-server
fi
   
