[vhffs-dev] [1269] Added support for TTL update

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1269
Author:   beuss
Date:     2008-10-08 16:17:16 +0200 (Wed, 08 Oct 2008)

Log Message:
-----------
Added support for TTL update

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Services/DNS.pm


Modified: trunk/vhffs-api/src/Vhffs/Services/DNS.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/DNS.pm	2008-10-07 21:41:49 UTC (rev 1268)
+++ trunk/vhffs-api/src/Vhffs/Services/DNS.pm	2008-10-08 14:17:16 UTC (rev 1269)
@@ -403,20 +403,21 @@
 
 sub update_a
 {
-    my ( $self , $id, $ip ) = @_;
+    my ( $self , $id, $ip, $ttl ) = @_;
     
     return -1 unless($id =~ /^\d+$/ );
     my $rr = $self->{A}{$id};
     return -2 unless(defined $rr);
     return -3 unless( Vhffs::Functions::check_ip($ip) );
+    $ttl = $rr->{ttl} unless(defined $ttl and $ttl =~ /^\d+$/);
 
     my $dbh = $self->get_main()->get_db_object();
-    my $sql = 'UPDATE vhffs_dns_rr SET data = ? WHERE id = ? AND zone = ? AND type = \'A\'';
-    $dbh->do($sql, undef, $ip, $id, $self->{dns_id}) or return -4;
+    my $sql = 'UPDATE vhffs_dns_rr SET data = ?, ttl = ? WHERE id = ? AND zone = ? AND type = \'A\'';
+    $dbh->do($sql, undef, $ip, $ttl, $id, $self->{dns_id}) or return -4;
 
     $rr->{data} = $ip;
 
-    $self->add_history('Updated A record '.$rr->{name}." pointing now on $ip");
+    $self->add_history('Updated A record '.$rr->{name}." pointing now on $ip (TTL $ttl)");
     
     $self->update_serial();
     return 1;
@@ -508,7 +509,7 @@
 
 =head2 update_mx
 
-    $dns->update_mx($rr_id, $host);
+    $dns->update_mx($rr_id, $host[, $priority, $ttl]);
 
 Replace address for MX record C<$rr_id>.
 
@@ -516,17 +517,19 @@
 
 sub update_mx
 {
-    my ($self, $id, $host) = @_;
+    my ($self, $id, $host, $priority, $ttl) = @_;
     
     return -1 unless($id =~ /^\d+$/);
     my $rr = $self->{MX}{$id};
+    $priority = $rr->{aux} unless(defined $priority and $priority =~ /^\d+$/);
+    $ttl = $rr->{ttl} unless(defined $ttl and $ttl =~ /^\d+$/);
     return -2 unless(defined $rr);
     return -3 unless( Vhffs::Functions::check_domain_name($host, 1) || check_rr_name($host) );
 
-    my $sql = 'UPDATE vhffs_dns_rr SET data = ? WHERE id = ? AND zone = ? AND type=\'MX\'';
+    my $sql = 'UPDATE vhffs_dns_rr SET data = ?, aux = ?, ttl = ? WHERE id = ? AND zone = ? AND type=\'MX\'';
     my $dbh = $self->get_main()->get_db_object();
 
-    $dbh->do($sql, undef, $host, $id, $self->{dns_id}) or return -4;
+    $dbh->do($sql, undef, $host, $priority, $ttl, $id, $self->{dns_id}) or return -4;
 
     $rr->{data} = $host;
 
@@ -730,16 +733,17 @@
 
 sub update_aaaa
 {
-    my ( $self , $id, $ip ) = @_;
+    my ( $self , $id, $ip, $ttl ) = @_;
     
     return -1 unless($id =~ /^\d+$/ );
     my $rr = $self->{AAAA}{$id};
     return -2 unless(defined $rr);
     return -3 unless( Vhffs::Functions::check_ipv6($ip) );
+    $ttl = $rr->{ttl} unless(defined $ttl);
 
     my $dbh = $self->get_main()->get_db_object();
-    my $sql = 'UPDATE vhffs_dns_rr SET data = ? WHERE id = ? AND zone = ? AND type = \'AAAA\'';
-    $dbh->do($sql, undef, $ip, $id, $self->{dns_id}) or return -4;
+    my $sql = 'UPDATE vhffs_dns_rr SET data = ?, ttl = ? WHERE id = ? AND zone = ? AND type = \'AAAA\'';
+    $dbh->do($sql, undef, $ip, $ttl, $id, $self->{dns_id}) or return -4;
 
     $rr->{data} = $ip;
 
@@ -804,17 +808,18 @@
     
 sub update_txt
 {
-    my ($self, $id, $data) = @_;
+    my ($self, $id, $data, $ttl) = @_;
     
     return -1 unless($id =~ /^\d+$/);
     my $rr = $self->{TXT}{$id};
     return -2 unless(defined $rr);
     return -3 if($data =~ /^\s*$/);
+    $ttl = $rr->{ttl} unless(defined $ttl and $ttl =~ /^\d+$/);
 
-    my $sql = 'UPDATE vhffs_dns_rr SET data = ? WHERE id = ? AND zone = ? AND type=\'TXT\'';
+    my $sql = 'UPDATE vhffs_dns_rr SET data = ?, ttl = ? WHERE id = ? AND zone = ? AND type=\'TXT\'';
     my $dbh = $self->get_main()->get_db_object();
 
-    $dbh->do($sql, undef, $data, $id, $self->{dns_id}) or return -4;
+    $dbh->do($sql, undef, $data, $ttl, $id, $self->{dns_id}) or return -4;
 
     $rr->{data} = $data;
 
@@ -825,16 +830,17 @@
 
 sub update_cname
 {
-    my ($self, $id, $dest) = @_;
+    my ($self, $id, $dest, $ttl) = @_;
     
     return -1 unless($id =~ /^\d+$/ );
     my $rr = $self->{CNAME}{$id};
     return -2 unless(defined $rr);
     return -3 unless( Vhffs::Functions::check_domain_name($dest, 1) || check_rr_name($dest) );
+    $ttl = $rr->{ttl} unless(defined $ttl and $ttl =~ /^\d+$/);
     
     my $dbh = $self->get_main()->get_db_object();
-    my $sql = 'UPDATE vhffs_dns_rr SET data = ? WHERE id = ? AND type = \'CNAME\' AND zone = ?';
-    $dbh->do($sql, undef, $dest, $id, $self->{dns_id})or return -4;
+    my $sql = 'UPDATE vhffs_dns_rr SET data = ?, ttl = ? WHERE id = ? AND type = \'CNAME\' AND zone = ?';
+    $dbh->do($sql, undef, $dest, $ttl, $id, $self->{dns_id})or return -4;
 
     $rr->{data} = $dest;
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/