diff options
author | sullrich <sullrich@pfsense.org> | 2009-12-06 19:26:56 -0500 |
---|---|---|
committer | sullrich <sullrich@pfsense.org> | 2009-12-06 19:26:56 -0500 |
commit | 7ea754a830976a57a3eb17bcf464d237dd321617 (patch) | |
tree | 0a39f674662dd17da2c37f48a3564566ef8da1ec | |
parent | 55f681dd599832f29da8e60bd37e1475146eab16 (diff) | |
download | pfsense-7ea754a830976a57a3eb17bcf464d237dd321617.zip pfsense-7ea754a830976a57a3eb17bcf464d237dd321617.tar.gz |
Adding script to parse dhcpd log file and populate /etc/hosts so that we can move to a newer dnsmasq. in addition, the current dnsmasq isc parsing is broken so there is not a choice to move either way. Ticket #79
-rw-r--r-- | etc/inc/services.inc | 5 | ||||
-rwxr-xr-x | etc/rc.bootup | 3 | ||||
-rwxr-xr-x | etc/rc.parse-isc-dhcpd | 66 |
3 files changed, 73 insertions, 1 deletions
diff --git a/etc/inc/services.inc b/etc/inc/services.inc index e47e351..8bb0a14 100644 --- a/etc/inc/services.inc +++ b/etc/inc/services.inc @@ -38,7 +38,10 @@ pfSense_MODULE: utils */ -/* include all configuration functions */ +function services_parse_dhcpd_hostnames() { + exec("kill `ps awux | grep isc | grep parse | awk '{ print $2 }'`"); + mwexec_bg("sh /etc/rc.parse-isc-dhcpd"); +} function services_dhcpd_configure() { global $config, $g; diff --git a/etc/rc.bootup b/etc/rc.bootup index 1936371..5ca8a80 100755 --- a/etc/rc.bootup +++ b/etc/rc.bootup @@ -322,6 +322,9 @@ enable_rrd_graphing(); /* start DHCP service */ services_dhcpd_configure(); +/* start DHCP logging service which populates /etc/hosts */ +services_parse_dhcpd_hostnames(); + /* startup OLSR if needed */ setup_wireless_olsr(); diff --git a/etc/rc.parse-isc-dhcpd b/etc/rc.parse-isc-dhcpd new file mode 100755 index 0000000..468c6cd --- /dev/null +++ b/etc/rc.parse-isc-dhcpd @@ -0,0 +1,66 @@ +#!/bin/sh + +# This script will monitor dhcpd.leases and parse +# out active leases and ensure they are present +# in /etc/hosts + +update_hosts_file() { + # $1 = host + # $2 = ip + cat /etc/hosts | grep -v "$1" > /tmp/hosts.tmp + if [ "$3" != "" ]; then + echo "$2 $1" >> /tmp/hosts.tmp + fi + mv /tmp/hosts.tmp /etc/hosts + killall -HUP dnsmasq +} + +# Parse file on initial run +cat /var/dhcpd/var/db/dhcpd.leases | grep "lease" -A8 | while read LINE +do + HOSTNAMEA=`echo "$LINE" | grep client-hostname | awk '{ print $2 }' | cut -d'"' -f2` + ACTIVEA=`echo "$LINE" | grep active` + IPADDRA=`echo "$LINE" | grep lease | awk '{ print $2 }'` + if [ "$HOSTNAMEA" != "" ]; then + HOSTNAME="$HOSTNAMEA" + fi + if [ "$ACTIVEA" != "" ]; then + ACTIVE="$ACTIVEA" + fi + if [ "$IPADDRA" != "" ]; then + IPADDR="$IPADDRA" + fi + if [ "$HOSTNAME" != "" ]; then + if [ "$IPADDR" != "" ]; then + update_hosts_file "$HOSTNAME" "$IPADDR" "$ACTIVE" + HOSTNAME="" + ACTIVE="" + IPADDR="" + fi + fi +done + +# After processed go ahead and tail file looking for changes. +tail -F /var/dhcpd/var/db/dhcpd.leases | grep "lease" -A8 | while read LINE +do + HOSTNAMEA=`echo "$LINE" | grep client-hostname | awk '{ print $2 }' | cut -d'"' -f2` + ACTIVEA=`echo "$LINE" | grep active` + IPADDRA=`echo "$LINE" | grep lease | awk '{ print $2 }'` + if [ "$HOSTNAMEA" != "" ]; then + HOSTNAME="$HOSTNAMEA" + fi + if [ "$ACTIVEA" != "" ]; then + ACTIVE="$ACTIVEA" + fi + if [ "$IPADDRA" != "" ]; then + IPADDR="$IPADDRA" + fi + if [ "$HOSTNAME" != "" ]; then + if [ "$IPADDR" != "" ]; then + update_hosts_file "$HOSTNAME" "$IPADDR" "$ACTIVE" + HOSTNAME="" + ACTIVE="" + IPADDR="" + fi + fi +done |