libexec=/usr/share/ebox

firewall_script=$libexec/dhcp-firewall.pl

ebox_bound() {
	$libexec/dhcp-address.pl $interface $new_ip_address $new_subnet_mask
	$libexec/dhcp-nameservers.pl $interface $new_domain_name_servers
	$libexec/dhcp-gateway.pl $new_routers

	if ( [ -x $firewall_script ] ); then
	    $firewall_script
	fi;
}

ebox_renew() {
	change="no"
	if [ "z$new_ip_address" != "z$old_ip_address" ] ; then
		change="yes"
	fi
	if [ "z$new_subnet_mask" != "z$old_subnet_mask" ] ; then
		change="yes"
	fi
	if [ "$change" == "yes" ] ; then
		$libexec/dhcp-address.pl $interface $new_ip_address \
					$new_subnet_mask
	fi
	if [ "z$new_domain_name_servers" != "z$old_domain_name_servers" ] ; then
		change="yes"
		$libexec/dhcp-nameservers.pl $interface $new_domain_name_servers
	fi
	if [ "z$new_routers" != "z$old_routers" ] ; then
		$libexec/dhcp-gateway.pl $new_routers
	fi
	if [ "$change" == "yes" ] ; then

	if ( [ -x $firewall_script ] ); then
		$firewall_script
	    fi;
	fi
}

ebox_expire() {
	$libexec/dhcp-clear.pl $interface
	if [ "z" != "z$old_routers" ] ; then
		$libexec/dhcp-clear-gateway.pl
	fi

	if ( [ -x $firewall_script ] ); then
		$firewall_script $interface
	fi;
	
}

case $reason in
	BOUND)
		ebox_bound
		;;
	REBOOT|RENEW|REBIND|TIMEOUT)
		ebox_renew
		;;
	EXPIRE|FAIL|RELEASE)
		ebox_expire
		;;
	*)
		;;
esac
