[vhffs-dev] [1255] Allows entries a. b in DNS module without requiring a new zone creation |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1255
Author: beuss
Date: 2008-09-22 09:44:03 +0200 (Mon, 22 Sep 2008)
Log Message:
-----------
Allows entries a.b in DNS module without requiring a new zone creation
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-09-20 23:32:21 UTC (rev 1254)
+++ trunk/vhffs-api/src/Vhffs/Services/DNS.pm 2008-09-22 07:44:03 UTC (rev 1255)
@@ -456,15 +456,18 @@
return $id;
}
+sub check_rr_name {
+ my $name = shift;
+ return ($name =~ /^(?:(?:[a-z0-9\-]{1,63}(?:\.[a-z0-9\-]{1,63})*)|@)$/ );
+}
-
sub add_a
{
my ( $self , $name , $ip , $ttl ) = @_;
$ttl = 900 if ( ! defined $ttl );
- return -1 if( ! ($name =~ /^(?:[a-z0-9\-]+|@)$/ ) );
+ return -1 if( ! check_rr_name($name) );
$name = '' if( $name eq '@' );
return -2 if ( $self->name_exists( $name, 'A', 'CNAME' ) != 0 );
@@ -518,7 +521,7 @@
return -1 unless($id =~ /^\d+$/);
my $rr = $self->{MX}{$id};
return -2 unless(defined $rr);
- return -3 unless( Vhffs::Functions::check_domain_name($host, 1) || ( $host =~ /[a-z0-9\-]{1,63}/ ) );
+ 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 $dbh = $self->get_main()->get_db_object();
@@ -540,7 +543,7 @@
$ttl = 900 if ( ! defined $ttl );
$aux = 10 if ( !defined $aux );
- return -1 unless( Vhffs::Functions::check_domain_name($host, 1) || ( $host =~ /[a-z0-9\-]{1,63}/ ) );
+ return -1 unless( Vhffs::Functions::check_domain_name($host, 1) || check_rr_name($host) );
return -2 unless( $aux =~ /^\d+$/ );
my $sql = 'SELECT id FROM vhffs_dns_rr WHERE type=\'MX\' AND data=? AND zone=?';
@@ -583,7 +586,7 @@
my ($self, $proto, $svc, $host, $port, $priority, $weight) = @_;
return -1 unless($proto =~ /^(?:_\w+)|(?:[^_]\w*)$/);
return -2 unless($svc =~ /^(?:_\w+)|(?:[^_]\w*)$/);
- return -3 unless( Vhffs::Functions::check_domain_name($host, 1) || ( $host =~ /[a-z0-9\-]{1,63}/ ) );
+ return -3 unless( Vhffs::Functions::check_domain_name($host, 1) || ( check_rr_name($host) ) );
return -4 unless($port =~ /^\d+$/ && $port <= 65535 && $port > 0);
return -5 unless($priority =~ /^\d+$/ && $priority <= 65535 && $priority >= 0);
return -6 unless($weight =~ /^\d+$/ && $weight <= 65535 && $weight >= 0);
@@ -640,7 +643,7 @@
return -1 unless($id =~ /^\d+$/);
my $rr = $self->{SRV}{$id};
return -2 unless(defined $rr);
- return -3 unless( Vhffs::Functions::check_domain_name($host, 1) || ( $host =~ /[a-z0-9\-]{1,63}/ ) );
+ return -3 unless( Vhffs::Functions::check_domain_name($host, 1) || check_rr_name($host) );
return -4 unless($port =~ /^\d+$/ && $port <= 65535 && $port > 0);
return -5 unless($priority =~ /^\d+$/ && $priority <= 65535 && $priority >= 0);
return -6 unless($weight =~ /^\d+$/ && $weight <= 65535 && $weight >= 0);
@@ -678,7 +681,7 @@
my ( $self , $name , $ip , $ttl ) = @_;
$ttl = 900 if ( ! defined $ttl );
- return -1 if( ! ($name =~ /^(?:[a-z0-9\-]+|\@)$/ ) );
+ return -1 if( ! check_rr_name($name) );
$name = '' if( $name eq '@' );
return -2 if ( $self->name_exists( $name, 'CNAME', 'AAAA' ) != 0 );
@@ -761,7 +764,7 @@
my ($self, $name, $data, $ttl) = @_;
$ttl = 900 if ( ! defined $ttl );
- return -1 unless($name =~ /^(?:[a-z0-9\-]+|\@)$/ );
+ return -1 unless( check_rr_name($name) );
$name = '' if( $name eq '@' );
return -2 if($data =~ /^\s*$/);
@@ -827,7 +830,7 @@
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) || ( $dest =~ /[a-z0-9\-]{1,63}/ ) );
+ return -3 unless( Vhffs::Functions::check_domain_name($dest, 1) || check_rr_name($dest) );
my $dbh = $self->get_main()->get_db_object();
my $sql = 'UPDATE vhffs_dns_rr SET data = ? WHERE id = ? AND type = \'CNAME\' AND zone = ?';
@@ -844,8 +847,8 @@
my ($self, $name, $dest, $ttl) = @_;
$ttl = 900 if ( ! defined $ttl );
- return -1 unless( $name =~ /^[a-z0-9\-]{1,63}$/ );
- return -2 unless( Vhffs::Functions::check_domain_name($dest, 1) || ( $dest =~ /[a-z0-9\-]{1,63}/ ) );
+ return -1 unless( check_rr_name($name) );
+ return -2 unless( Vhffs::Functions::check_domain_name($dest, 1) || check_rr_name( $dest ) );
$name = '' if( $name eq '@' );
return -3 if ( $self->name_exists( $name, 'A', 'AAAA', 'CNAME' ) != 0 );