From 0d3b49ccd42e49548aed77abf524306e1bfe4770 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Fri, 8 Dec 2006 19:38:02 +0000 Subject: * Split tinydns data row code out to its own function * Add load balancing support --- packages/tinydns/tinydns.inc | 61 +++++++++++++++++++++++------------- packages/tinydns/tinydns_domains.xml | 6 ++++ 2 files changed, 45 insertions(+), 22 deletions(-) (limited to 'packages/tinydns') diff --git a/packages/tinydns/tinydns.inc b/packages/tinydns/tinydns.inc index 67e49abb..48e12216 100644 --- a/packages/tinydns/tinydns.inc +++ b/packages/tinydns/tinydns.inc @@ -190,36 +190,27 @@ function tinydns_create_zone_file() { $record_data = ""; $hostname = $domain['hostname']; $ipaddress = $domain['ipaddress']; - $ttl = $domain['ttl']; - if($ttl) - $ttl_string = "::{$ttl}"; - else - $ttl_string = ""; /* check record status, if it is down request * backup server if defined. */ $status = tinydns_get_record_status($ipaddress); if(!$status) $ipaddress = tinydns_get_backup_record($ipaddress); - switch ($domain['recordtype']) { - case "SOA": - $record_data = ".{$hostname}::{$ipaddress}"; - break; - case "MX": - $record_data = "@{$hostname}:{$ipaddress}{$ttl_string}"; - break; - case "A": - $record_data = "+{$hostname}:{$ipaddress}{$ttl_string}"; - break; - case "PTR": - $record_data = "={$hostname}:{$ipaddress}{$ttl_string}"; - break; - case "CNAME": - $record_data = "C{$hostname}:{$ipaddress}{$ttl_string}"; - break; - } + $record_data = tinydns_get_rowline_data($ipaddress, $domain['recordtype'], $ttl); if($record_data) fwrite($fd, $record_data . "\n"); + /* process load balanced items */ + if($domain['row']) { + foreach($domain['row'] as $row) { + if($row['loadbalance']) { + $status = tinydns_get_record_status($row['failoverip']); + if(!$status) { + $record_data = tinydns_get_rowline_data($row['failoverip'], $domain['recordtype'], $ttl); + fwrite($fd, $record_data . "\n"); + } + } + } + } } } fclose($fd); @@ -228,4 +219,30 @@ function tinydns_create_zone_file() { conf_mount_ro(); } +/* formats data as a tinydns data row item */ +function tinydns_get_rowline_data($recordip, $recordtype, $ttl) { + if($ttl) + $ttl_string = "::{$ttl}"; + else + $ttl_string = ""; + switch ($recordtype) { + case "SOA": + $record_data = ".{$hostname}::{$ipaddress}"; + break; + case "MX": + $record_data = "@{$hostname}:{$ipaddress}{$ttl_string}"; + break; + case "A": + $record_data = "+{$hostname}:{$ipaddress}{$ttl_string}"; + break; + case "PTR": + $record_data = "={$hostname}:{$ipaddress}{$ttl_string}"; + break; + case "CNAME": + $record_data = "C{$hostname}:{$ipaddress}{$ttl_string}"; + break; + } + return $record_data; +} + ?> \ No newline at end of file diff --git a/packages/tinydns/tinydns_domains.xml b/packages/tinydns/tinydns_domains.xml index 94a124c5..5814834e 100644 --- a/packages/tinydns/tinydns_domains.xml +++ b/packages/tinydns/tinydns_domains.xml @@ -79,6 +79,12 @@ input 45 + + Load balance + loadbalance + Adds this member to active group when host is alive. + checkbox + -- cgit v1.2.3