diff options
author | Seth Mos <seth.mos@xs4all.nl> | 2009-01-13 17:22:05 +0000 |
---|---|---|
committer | Seth Mos <seth.mos@xs4all.nl> | 2009-01-13 17:22:05 +0000 |
commit | 7723c7e032ef7e284f0048e50f593b9f902e663d (patch) | |
tree | aad7586caa09a5dd55b0249c654d943b24c69d33 /etc | |
parent | c60cae980297426b0dfee28954efff7876ab10ca (diff) | |
download | pfsense-7723c7e032ef7e284f0048e50f593b9f902e663d.zip pfsense-7723c7e032ef7e284f0048e50f593b9f902e663d.tar.gz |
Add a function that compares current DNS to the dnscache file.
If they are not identical it will return the old Ip addresses which can
be used for removal of old items before adding new ones.
This is used by the rc.newipsecdns script when the remote ipsec gateway
hostname has changed IP and we need to remove the old SPD entries
Diffstat (limited to 'etc')
-rw-r--r-- | etc/inc/pfsense-utils.inc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index b45c954..6a006e0 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -3441,4 +3441,49 @@ function read_body($ch, $string) { return $length; } +/* Compare the current hostname DNS to the DNS cache we made + * if it has changed we return the old records + * if no change we return true */ +function compare_hostname_to_dnscache($hostname) { + if(!is_dir("/var/db/dnscache")) { + mkdir("/var/db/dnscache"); + } + $hostname = trim($hostname); + if(is_readable("/var/db/dnscache/{$hostname}")) { + $oldcontents = file_get_contents("/var/db/dnscache/{$hostname}"); + } else { + $oldcontents = ""; + } + if((is_fqdn($hostname)) && (!is_ipaddr($hostname))) { + $domrecords = array(); + $domips = array(); + exec("host -t A $hostname", $domrecords, $rethost); + if($rethost == 0) { + foreach($domrecords as $domr) { + $doml = explode(" ", $domr); + $domip = $doml[3]; + /* fill array with domain ip addresses */ + if(is_ipaddr($domip)) { + $domips[] = $domip; + } + } + } + sort($domips); + $contents = ""; + if(! empty($domips)) { + foreach($domips as $ip) { + $contents .= "$ip\n"; + } + } + } + + if(trim($oldcontents) != trim($contents)) { + log_error("DNSCACHE: Found old IP {$oldcontents} and new IP {$contents}"); + return ($oldcontents); + } else { + return false; + } +} + + ?> |