[vhffs-dev] [1022] Ending up with the mess of the dns configuration

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


Revision: 1022
Author:   gradator
Date:     2007-10-25 13:43:44 +0000 (Thu, 25 Oct 2007)

Log Message:
-----------
Ending up with the mess of the dns configuration

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Services/DNS.pm
    trunk/vhffs-backend/conf/vhffs.conf.dist.in


Modified: trunk/vhffs-api/src/Vhffs/Services/DNS.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/DNS.pm	2007-10-24 22:16:38 UTC (rev 1021)
+++ trunk/vhffs-api/src/Vhffs/Services/DNS.pm	2007-10-25 13:43:44 UTC (rev 1022)
@@ -127,8 +127,8 @@
 
         my $sth = $dbh->prepare($sql);
 
-        $sth->execute($domain, $parent->get_oid, $conf->{default_ns1}, $conf->{default_mbox}, $serial, 
-            $conf->{default_refresh}, $conf->{default_retry}, $conf->{default_expire}, $conf->{default_minimum}, $conf->{default_minimum});
+        $sth->execute($domain, $parent->get_oid, $conf->{init}->{soa}->{ns}, $conf->{init}->{soa}->{mbox}, $serial, 
+            $conf->{init}->{soa}->{refresh}, $conf->{init}->{soa}->{retry}, $conf->{init}->{soa}->{expire}, $conf->{init}->{soa}->{minimum}, $conf->{init}->{soa}->{ttl} );
 
         $dbh->commit;
         $self = get_by_domainname($main, $domain);
@@ -429,10 +429,8 @@
     
     $ttl = 900 if ( ! defined $ttl );
     
-    return -1 unless(Vhffs::Functions::check_domain_name($host));
+    return -1 unless( Vhffs::Functions::check_domain_name($host) || ( $host =~ /[a-z0-9\-]{1,63}/ ) );
 
-    $host .= '.' unless($host =~ /\.$/ );
-
     my $sql = 'SELECT * FROM vhffs_dns_rr WHERE type=\'NS\' AND data=? AND zone=?';
     my $dbh = $self->get_main->get_db_object();
     return -2 if($dbh->do($sql, undef, $host, $self->{dns_id}) != 0);
@@ -520,13 +518,11 @@
     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));
+    return -3 unless( Vhffs::Functions::check_domain_name($host, 1) || ( $host =~ /[a-z0-9\-]{1,63}/ ) );
 
     my $sql = 'UPDATE vhffs_dns_rr SET data = ? WHERE id = ? AND zone = ? AND type=\'MX\'';
     my $dbh = $self->get_main()->get_db_object();
 
-    $host .= '.' unless($host =~ /\.$/);
-
     $dbh->do($sql, undef, $host, $id, $self->{dns_id}) or return -4;
 
     $rr->{data} = $host;
@@ -544,11 +540,9 @@
     $ttl = 900 if ( ! defined $ttl );
     $aux = 10 if ( !defined $aux );
     
-    return -1 unless( Vhffs::Functions::check_domain_name($host, 1) );
+    return -1 unless( Vhffs::Functions::check_domain_name($host, 1) || ( $host =~ /[a-z0-9\-]{1,63}/ ) );
     return -2 unless( $aux =~ /^\d+$/ );
 
-    $host .= '.' unless($host =~ /\.$/);
-
     my $sql = 'SELECT id FROM vhffs_dns_rr WHERE type=\'MX\' AND data=? AND zone=?';
     my $dbh = $self->get_main()->get_db_object();
     return -3 if($dbh->do($sql, undef, $host, $self->{dns_id}) != 0); 
@@ -589,7 +583,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));
+    return -3 unless( Vhffs::Functions::check_domain_name($host, 1) || ( $host =~ /[a-z0-9\-]{1,63}/ ) );
     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);
@@ -599,7 +593,6 @@
     $svc = "_$svc" unless($svc =~ /^_/);
     $svc = lc($svc);
     my $name = "$svc.$proto";
-    $host .= '.' unless($host =~ /[.]$/);
     my $data = "$weight $port $host";
 
 
@@ -647,13 +640,11 @@
     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));
+    return -3 unless( Vhffs::Functions::check_domain_name($host, 1) || ( $host =~ /[a-z0-9\-]{1,63}/ ) );
     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);
 
-    $host .= '.' unless($host =~ /[.]$/);
-
     my $data = "$weight $port $host";
 
     my $sql = 'UPDATE vhffs_dns_rr SET data = ?, aux = ? WHERE id = ? AND zone = ? AND type = \'SRV\'';
@@ -836,9 +827,8 @@
     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));
+    return -3 unless( Vhffs::Functions::check_domain_name($dest, 1) || ( $dest =~ /[a-z0-9\-]{1,63}/ ) );
     
-    $dest .='.' unless($dest =~ /\.$/);
     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;
@@ -854,15 +844,11 @@
     my ($self, $name, $dest, $ttl) = @_;
 
     $ttl = 900 if ( ! defined $ttl );
-    return -1 unless($name =~ /^[a-z0-9\-]+$/ );
-    return -2 unless(Vhffs::Functions::check_domain_name($dest, 1));
+    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}/ ) );
     $name = '' if( $name eq '@' );
     return -3 if ( $self->name_exists( $name, 'A', 'AAAA', 'CNAME' ) != 0 );
 
-    # Add a '.' the the submitted name. Otherwise, if the user submit tata.toto.com IN CNAME foo.com
-    # MyDNS will understand tata.toto.com IN CNAME foo.com.toto.com
-    $dest .= '.' unless($dest =~ /\.$/);
-
     my $dbh = $self->get_main()->get_db_object();
 
     my $sql = 'INSERT INTO vhffs_dns_rr(zone, name, type, data, aux, ttl) VALUES(?, ?, \'CNAME\', ?, 0, ?)';
@@ -890,62 +876,41 @@
 # Submit changes to the backend
 sub commit
 {
-    my $query;
-    my $self = shift;	
-    
+	my $self = shift;	
+	return -1 unless ( defined $self && defined $self->{'dns_id'} );
+       
+	my $conf = $self->{'main'}->get_config->get_service("dns");
+	return -1 unless defined $conf;
 
-    
-    my $conf = $self->{'main'}->get_config->get_service("dns");
-
-    return -1 if ( ! defined $conf );
-
-    return -1 if ( ! defined $self->{'dns_id'} );
-
-    #Set some defaults values if not defined
-    $self->{'ttl'} = $conf->{default_ttl} if( ! defined $self->{'ttl'} );
-    $self->{'ns'} = $conf->{default_ns1} if( ! defined $self->{'ns'} );
-    $self->{'mbox'} = $conf->{default_mbox} if( ! defined $self->{'mbox'} );
-    $self->{'serial'} = $conf->{default_serial} if( ! defined $self->{'serial'} );
-    $self->{'refresh'} = $conf->{default_refresh} if( ! defined $self->{'refresh'} );
-    $self->{'retry'} = $conf->{default_retry} if( ! defined $self->{'retry'} );
-    $self->{'expire'} = $conf->{default_expire} if( ! defined $self->{'expire'} );
-    $self->{'minimum'} = $conf->{default_minimum} if( ! defined $self->{'minimum'} );
-
-
-    #Convert the mail to the mailbox domain for DNS files
-    $self->{'mbox'} =~ s/\@/\./;
-
 	#Update the serial to refresh the domain
-    $self->{serial} = $self->get_next_serial();
-    
-    #First, commit the SOA
-    $query = "UPDATE vhffs_dns SET ns='".$self->{'ns'}."', mbox='".$self->{'mbox'}."', serial='".$self->{'serial'}."', refresh='".$self->{'refresh'}."', retry='".$self->{'retry'}."', expire='".$self->{'expire'}."', minimum='".$self->{'minimum'}."', ttl='".$self->{'ttl'}."' WHERE dns_id=$self->{'dns_id'}";
-    my $request = $self->{'db'}->prepare( $query );
-    $request->execute or return -2;
+	$self->{serial} = $self->get_next_serial();
 
-    # Commit the object part
-    $self->SUPER::commit;
+	#First, commit the SOA
+	my $request = $self->{'db'}->prepare( 'UPDATE vhffs_dns SET ns=? , mbox=? , serial=? , refresh=? , retry=? , expire=? , minimum=? , ttl=? WHERE dns_id=?' );
+	$request->execute( $self->{'ns'} , $self->{'mbox'} , $self->{'serial'} , $self->{'refresh'} , $self->{'retry'} , $self->{'expire'} , $self->{'minimum'} , $self->{'ttl'} , $self->{'dns_id'} ) or return -2;
+
+	# Commit the object part
+	$self->SUPER::commit;
 }
 
 sub get_next_serial
 {
-    my $self = shift;
+	my $self = shift;
 	my ($second,$minutes,$hours,$day,$month,$year) = localtime(time);
 	my $newserial = sprintf('%.4u%.2u%.2u',$year+1900,$month+1,$day);
 
-    if( $self->{serial} =~ /^$newserial/  ||  $self->{serial} > $newserial.'01' ) {
-        return ($self->{serial} + 1);
-    } else {
-        return $newserial.'01';
-    }
+	if( $self->{serial} =~ /^$newserial/  ||  $self->{serial} > $newserial.'01' ) {
+		return ($self->{serial} + 1);
+	} else {
+		return $newserial.'01';
+	}
 }
 
 sub update_serial {
-    my $self = shift;
-    my $dbh = $self->get_main()->get_db_object();
-    my $sql = 'UPDATE vhffs_dns SET serial = ? WHERE dns_id = ?';
-    $self->{serial} = $self->get_next_serial();
-    $dbh->do($sql, undef, $self->{serial}, $self->{dns_id});
+	my $self = shift;
+	my $dbh = $self->get_main()->get_db_object();
+	$self->{'serial'} = $self->get_next_serial();
+	$dbh->do( 'UPDATE vhffs_dns SET serial=? WHERE dns_id=?' , undef, $self->{'serial'}, $self->{'dns_id'} );
 }
 
 ########################################

Modified: trunk/vhffs-backend/conf/vhffs.conf.dist.in
===================================================================
--- trunk/vhffs-backend/conf/vhffs.conf.dist.in	2007-10-24 22:16:38 UTC (rev 1021)
+++ trunk/vhffs-backend/conf/vhffs.conf.dist.in	2007-10-25 13:43:44 UTC (rev 1022)
@@ -260,35 +260,32 @@
 		# Use this module or not
 		activate	=	no
 
-		# Default configuration for new domains and new entries
-		default_ns1	=	ns1.hoster.org
-		default_ns2	=	ns2.hoster.org
-		default_mx1	=	mx1.hoster.org
-		default_mx2	=	mx2.hoster.org
+		# Default configuration for new records
 		default_a	=	1.2.3.4
 		default_aaaa	=	FEDC::1
-		default_ttl	=	86400
-		default_aux	=	0
-		default_refresh	=	28800
-		default_retry	=	7200
-		default_expire	=	604800
-		default_minimum	=	86400
-		default_serial	=	1
-		default_mbox	=	adm.your.hoster.ext.
 
-		# Initial configuration of new domain name
+		# Initial configuration of new domains names
 		<init>
+			<soa>
+				ns = ns1.hoster.org.
+				mbox = hostmaster.hoster.org.
+				refresh = 28800
+				retry = 7200
+				expire = 604800
+				minimum = 86400
+				ttl = 86400
+			</soa>
 			<a>
 				@	=	10.0.0.1
 				www	=	80.0.0.1
 			</a>
 			<mx>
-				10	=	mx1.hoster.org
-				20	=	mx2.hoster.org
+				10	=	mx1.hoster.org.
+				20	=	mx2.hoster.org.
 			</mx>
 			<ns>
-				ns1.hoster.org
-				ns2.hoster.org
+				ns1.hoster.org.
+				ns2.hoster.org.
 			</ns>
 		</init>
 


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