[vhffs-dev] [512] Reworked all SQL code for DNS service. |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 512
Author: beuss
Date: 2007-03-19 17:48:29 +0000 (Mon, 19 Mar 2007)
Log Message:
-----------
Reworked all SQL code for DNS service.
Modified Paths:
--------------
branches/vhffs_4.1/Makefile
branches/vhffs_4.1/vhffs-api/src/Vhffs/Functions.pm
branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/DNS.pm
branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/DNS.pm
branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql
branches/vhffs_4.1/vhffs-irc/modobot.pl
branches/vhffs_4.1/vhffs-panel/admin/moderation.pl
branches/vhffs_4.1/vhffs-panel/cvs/cvs_submit.pl
branches/vhffs_4.1/vhffs-panel/dns/add_a.pl
branches/vhffs_4.1/vhffs-panel/dns/add_cname.pl
branches/vhffs_4.1/vhffs-panel/dns/add_mx.pl
branches/vhffs_4.1/vhffs-panel/dns/add_ns.pl
branches/vhffs_4.1/vhffs-panel/dns/delete.pl
branches/vhffs_4.1/vhffs-panel/dns/delete_a.pl
branches/vhffs_4.1/vhffs-panel/dns/delete_cname.pl
branches/vhffs_4.1/vhffs-panel/dns/delete_mx.pl
branches/vhffs_4.1/vhffs-panel/dns/delete_ns.pl
branches/vhffs_4.1/vhffs-panel/dns/dns_submit.pl
branches/vhffs_4.1/vhffs-panel/dns/dns_type_submit.pl
branches/vhffs_4.1/vhffs-panel/dns/modif_a.pl
branches/vhffs_4.1/vhffs-panel/dns/modif_cname.pl
branches/vhffs_4.1/vhffs-panel/dns/modif_mx.pl
branches/vhffs_4.1/vhffs-panel/dns/prefs.pl
branches/vhffs_4.1/vhffs-panel/templates/dns/prefs.tmpl
branches/vhffs_4.1/vhffs-tests/src/Stats.pl
Added Paths:
-----------
branches/vhffs_4.1/vhffs-tests/src/Services/DNS.pl
Modified: branches/vhffs_4.1/Makefile
===================================================================
--- branches/vhffs_4.1/Makefile 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/Makefile 2007-03-19 17:48:29 UTC (rev 512)
@@ -295,6 +295,8 @@
@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Object.pl");'
test-group:
@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Group.pl");'
+test-dns:
+ @perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Services/DNS.pl");'
test-user:
@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/User.pl");'
test-stats:
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Functions.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Functions.pm 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Functions.pm 2007-03-19 17:48:29 UTC (rev 512)
@@ -441,6 +441,11 @@
return (defined $domain_name && length($domain_name) >= 5 && $domain_name =~ /^(?:[a-z0-9\-]{1,63}[.])+([a-z0-9]{2,10})$/);
}
+sub check_ip($) {
+ my $ip = shift;
+ return (defined $ip && $ip =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/);
+}
+
sub rotate_log
{
use File::Basename;
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/DNS.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/DNS.pm 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/DNS.pm 2007-03-19 17:48:29 UTC (rev 512)
@@ -90,17 +90,13 @@
sub create_dns
{
- my ( $main , $dns_name , $user , $group ) = @_;
+ my ( $main , $dns_name, $description , $user , $group ) = @_;
return undef if( ! defined $user );
- return undef if( $group->fetch < 0 );
+ return undef if( ! defined $group );
- my $dns = new Vhffs::Services::DNS( $main , $dns_name , $user , $group );
+ my $dns = Vhffs::Services::DNS::create( $main , $dns_name, $description, $user , $group );
return undef if( ! defined $dns );
- $dns->set_user( $user );
- $dns->set_group( $group );
- return undef if( $dns->create < 0 );
-
return undef if ( Vhffs::Acl::add_acl( $user , $dns , Vhffs::Constants::ACL_DELETE , $main ) < 0 );
return undef if( Vhffs::Acl::add_acl( $group , $dns , Vhffs::Constants::ACL_VIEW , $main ) < 0 );
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/DNS.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/DNS.pm 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/DNS.pm 2007-03-19 17:48:29 UTC (rev 512)
@@ -80,44 +80,107 @@
# If a state (of Vhffs::Constants) is given more, it returns all DNS objects which have this state
sub getall
{
- my $vhffs = shift;
- my $state = shift;
- my $name = shift;
- my $group = shift;
+ my ($vhffs, $state, $name, $group) = @_;
- my $query;
- my $request;
+ my $domains = [];
+ my @params;
+ my $sql = 'SELECT d.domain FROM vhffs_dns d, vhffs_object o WHERE o.object_id = d.object_id';
+ if(defined $state) {
+ $sql .= ' AND o.state = ?';
+ push @params, $state;
+ }
+ if(defined $name) {
+ $sql .= ' AND d.domain LIKE ?';
+ push @params, '%'.$name.'%';
+ }
+ if(defined $group) {
+ $sql .= ' AND d.owner_gid = ?';
+ push @params, $group->get_gid;
+ }
+ $sql .= ' ORDER BY d.domain';
- my $objs;
- my $result;
- my $tmp;
+ my $dbh = $vhffs->get_db_object();
+ my $sth = $dbh->prepare($sql);
+ $sth->execute(@params);
+ while(my @d = $sth->fetchrow_array) {
+ push @$domains, get_by_domainname($vhffs, $d[0]);
+ }
- $query = "SELECT n.domain, n.object_id FROM vhffs_dns n, vhffs_object o WHERE n.object_id = o.object_id";
- $query.= " AND o.state='".$state."'" if( defined $state );
- $query.= " AND n.domain LIKE '%".$name."%'" if( defined $name );
- $query.= " AND n.owner_gid='".$group->get_gid."'" if( defined $group );
+ return $domains;
+}
- $request = $vhffs->{'db'}->prepare( $query );
- my $rows = $request->execute;
- return undef if( $rows <= 0);
-
- while( $result = $request->fetchrow_hashref() )
- {
- $tmp = new Vhffs::Services::DNS( $vhffs , $result->{'domain'} );
- if( ( defined ( $tmp ) ) && ( $tmp->fetch > 0 ) )
- {
- push @{$objs} , $tmp;
- }
+sub create
+{
+ if($_[0]->isa('Vhffs::Services::DNS')) {
+ my ($package, $file, $line) = caller();
+ warn "Using deprecated form of method Vhffs::DNS::Repository::create from $package ($file:$line)\n";
+ return old_create(@_);
}
- return $objs;
-}
+ my($main, $domain, $description, $user, $group) = @_;
+ my $conf = $main->get_config->get_service("dns");
+ return undef if ( ! defined $conf );
+ return undef unless(defined($user) && defined($group));
+ return undef unless(Vhffs::Functions::check_domain_name($domain));
+
+ my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_DNS);
+
+ return undef unless(defined $parent);
+
+ my $sql = 'INSERT INTO vhffs_dns (domain, owner_uid, owner_gid, object_id, ns, mbox, serial, refresh, retry, expire, minimum, ttl) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
+ my ($day, $month, $year);
+ (undef,undef,undef,$day,$month,$year) = localtime(time);
+ my $serial = sprintf('%.4u%.2u%.2u01',$year+1900,$month+1,$day);
+
+ my $dbh = $main->get_db_object();
+
+ my $sth = $dbh->prepare($sql);
+
+ $sth->execute($domain, $user->get_uid, $group->get_gid, $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}) or return undef;
+
+ my $self = get_by_domainname($main, $domain);
+
+ # Fill in default information defined in configuration.
+ if( defined $conf->{init} ) {
+ my ($ip, $name, $prio);
+ my $init = $conf->{init};
+
+ if( defined $init->{a} ) {
+ foreach( keys %{$init->{a}} ) {
+ $name = $_;
+ $ip = $init->{a}{$_};
+ if( $name eq "default" ) {
+ $self->add_a( "" , $ip );
+ } else {
+ $self->add_a( $name , $ip );
+ }
+ }
+ }
+ if( defined $init->{mx} ) {
+ foreach( keys %{$init->{mx}} ) {
+ $prio = $_;
+ $ip = $init->{mx}{$_};
+ $self->add_mx( $ip , $prio );
+ }
+ }
+ if( defined $init->{ns} ) {
+ foreach( keys %{$init->{ns}} ) {
+ $name = $_;
+ $self->add_ns( $name );
+ }
+ }
+ }
+
+ return $self;
+}
+
#Create the object in VHFFS database
-sub create
+sub old_create
{
my $self = shift;
my $conf = $self->{'main'}->get_config->get_service("dns");
@@ -229,7 +292,72 @@
return 1;
}
+sub get_by_domainname($$)
+{
+ my ($main, $name) = @_;
+
+ my $sql = 'SELECT d.dns_id, d.domain, d.owner_gid, d.ns, d.mbox, d.serial, d.refresh, d.retry, d.expire, d.minimum, d.ttl, o.object_id, o.owner_uid, o.date_creation, o.state, o.description FROM vhffs_dns d INNER JOIN vhffs_object o ON o.object_id = d.object_id WHERE d.domain = ?';
+ my $dbh = $main->get_db_object();
+ my @params = $dbh->selectrow_array($sql, undef, $name);
+ my $dns_id = $params[0];
+
+ # Fetches A records
+ $sql = 'SELECT id, zone, (CASE WHEN name = \'\' THEN \'default\' ELSE name END) AS name, type, data, aux, ttl FROM vhffs_dns_rr WHERE zone = ? AND type = \'A\'';
+ my $sth = $dbh->prepare($sql);
+ $sth->execute($dns_id);
+ my $a = $sth->fetchall_hashref('name');
+ push @params, $a;
+
+ # Fetches NS records
+ $sql = 'SELECT id, zone, name, type, data, aux, ttl FROM vhffs_dns_rr WHERE zone = ? AND type = ?';
+ $sth = $dbh->prepare($sql);
+ $sth->execute($dns_id, 'NS');
+ my $ns = $sth->fetchall_hashref('data');
+ push @params, $ns;
+
+ # Fetches CNAME records
+ $sql = 'SELECT id, zone, (CASE WHEN name = \'\' THEN \'default\' ELSE name END) AS name, type, data, aux, ttl FROM vhffs_dns_rr WHERE zone = ? AND type = ?';
+ $sth = $dbh->prepare($sql);
+ $sth->execute($dns_id, 'CNAME');
+ my $cname = $sth->fetchall_hashref('name');
+ push @params, $cname;
+
+ # Fetches MX records
+ $sql = 'SELECT id, zone, name, type, data, aux, ttl FROM vhffs_dns_rr WHERE zone = ? AND type = ?';
+ $sth = $dbh->prepare($sql);
+ $sth->execute($dns_id, 'MX');
+ my $mx = $sth->fetchall_hashref('aux');
+ push @params, $mx;
+
+ return _new Vhffs::Services::DNS($main, @params);
+}
+
+sub _new
+{
+ my ($class, $main, $dns_id, $domain, $owner_gid, $ns, $mbox, $serial, $refresh, $retry, $expire, $minimum, $ttl, $oid, $owner_uid, $date_creation, $state, $description, $a, $nsr, $cname, $mx) = @_;
+
+ my $self = $class->SUPER::_new($main, $oid, $owner_uid, $date_creation, $description, $state, Vhffs::Constants::TYPE_DNS);
+
+ $self->{dns_id} = $dns_id;
+ $self->{domain} = $domain;
+ $self->{owner_gid} = $owner_gid;
+ $self->{ns} = $ns;
+ $self->{mbox} = $mbox;
+ $self->{serial} = $serial;
+ $self->{refresh} = $refresh;
+ $self->{retry} = $retry;
+ $self->{expire} = $expire;
+ $self->{minimum} = $minimum;
+ $self->{ttl} = $ttl;
+ $self->{A} = $a;
+ $self->{NS} = $nsr;
+ $self->{CNAME} = $cname;
+ $self->{MX} = $mx;
+
+ return $self;
+}
+
#Get all data about this httpd object in the databse
sub fetch
{
@@ -325,115 +453,95 @@
}
}
-
$self->SUPER::fetch;
- $self->SUPER::fetch;
}
-sub get_max_rrid
-{
- my ( $self ) = @_;
-
- my $id = 1;
- my $request = $self->{'db'}->selectall_arrayref("SELECT MAX(id) FROM vhffs_dns_rr");
- $id = $request->[0][0] if ( defined $request->[0][0] );
- $id++;
-
- return $id;
-}
-
-
# This function returns -1 if a name already exists.
# For example, if soda.gunnm.org already exists in the dns_rr table, we return -1. Otherwise, 0.
sub name_exists
{
my ( $self , $name ) = @_;
- my $request = $self->{'db'}->prepare("SELECT * FROM vhffs_dns_rr WHERE name='".$name."' AND zone='".$self->{'dns_id'}."' AND TYPE IN ( 'A' , 'CNAME')");
- my $rows = $request->execute;
- return 1 if ( $rows != 0 );
-
- return 0;
+ my $dbh = $self->get_main->get_db_object();
+ my $sql = 'SELECT id FROM vhffs_dns_rr WHERE name = ? AND zone = ? AND type IN(\'A\', \'CNAME\') LIMIT 1';
+ return ($dbh->do($sql, undef, $name, $self->{dns_id}) != 0);
}
sub delete_cname
{
- my $self = shift;
- my $name = shift;
+ my ($self, $name) = @_;
return -1 if( ! ($name =~ /^[a-z0-9\.\-]*$/ ) );
- $name = "" if( $name eq "default" );
+ $name = '' if( $name eq 'default' );
- my $query = "DELETE FROM vhffs_dns_rr WHERE type='CNAME' AND zone='".$self->{'dns_id'}."' AND name='".$name."'";
- my $request = $self->{'db'}->prepare( $query );
- $request->execute or return -2;
+ my $dbh = $self->get_main()->get_db_object();
+ my $sql = 'DELETE FROM vhffs_dns_rr WHERE type = \'CNAME\' AND zone = ? AND name = ?';
+ $dbh->do($sql, undef, $self->{dns_id}, $name) or return -2;
+ undef $self->{CNAME}->{$name};
+
#Update SOA
- $self->commit;
- $self->add_history("Delete the $name CNAME");
+ $self->update_serial();
+ $self->add_history("Deleted CNAME record $name");
return 1;
}
-
sub delete_ns
{
- my $self = shift;
- my $ip = shift;
+ my ($self, $host) = @_;
- return -1 if( ! ($ip =~ /^[a-z0-9\.\-]+$/ ) );
+ return -1 if( ! ($host =~ /^[a-z0-9\.\-]+$/ ) );
- my $query = "DELETE FROM vhffs_dns_rr WHERE type='NS' AND zone='".$self->{'dns_id'}."' AND data='".$ip."'";
- my $request = $self->{'db'}->prepare( $query );
- $request->execute or return -2;
+ my $dbh = $self->get_main->get_db_object();
+ my $sql = 'DELETE FROM vhffs_dns_rr WHERE type = \'NS\' AND zone = ? AND data = ?';
+ $dbh->do($sql, undef, $self->{dns_id}, $host) or return -2;
- $self->add_history("Delete the ns $ip");
+ undef $self->{NS}->{$host};
+
+ $self->add_history("Deleted NS record $host");
- #Update SOA
- $self->commit;
+ $self->update_serial;
return 1;
}
-
-
-
sub delete_mx
{
- my $self = shift;
- my $aux = shift;
+ my ($self, $aux) = @_;
return -1 if( ! ($aux =~ /^[a-z0-9\.\-]+$/ ) );
- my $query = "DELETE FROM vhffs_dns_rr WHERE type='MX' AND zone='".$self->{'dns_id'}."' AND aux='".$aux."'";
- my $request = $self->{'db'}->prepare( $query );
- $request->execute or return -2;
+ my $dbh = $self->get_main->get_db_object();
+ my $sql = 'DELETE FROM vhffs_dns_rr WHERE type=\'MX\' AND zone= ? AND aux = ?';
+ $dbh->do($sql, undef, $self->{dns_id}, $aux) or return -2;
- $self->add_history("Delete the mx with priority $aux");
+ undef $self->{MX}->{$aux};
+
+ $self->add_history("Deleted the MX record with priority $aux");
- #Update SOA
- $self->commit;
+ $self->update_serial();
return 1;
}
sub delete_a
{
- my $self = shift;
- my $name = shift;
+ my ($self, $name) = @_;
return -1 if( ! ($name =~ /^[a-z0-9\-]*|\*$/ ) );
- $name = "" if( $name eq "default" );
+ $name = '' if( $name eq 'default' );
- my $query = "DELETE FROM vhffs_dns_rr WHERE type='A' AND zone='".$self->{'dns_id'}."' AND name='".$name."'";
- my $request = $self->{'db'}->prepare( $query );
- $request->execute or return -2;
+ my $dbh = $self->get_main->get_db_object();
+ my $sql = 'DELETE FROM vhffs_dns_rr WHERE type = \'A\' AND zone = ? AND name = ?';
+ $dbh->do($sql, undef, $self->{dns_id}, $name) or return -2;
- $self->add_history("Delete $name FROM domain");
+ undef $self->{A}->{$name};
+
+ $self->add_history("Deleted A record $name");
- #Update SOA
- $self->commit;
+ $self->update_serial();
return 1;
}
@@ -442,55 +550,56 @@
{
my ( $self , $name , $ip ) = @_;
- my $id = $self->get_max_rrid();
- return -1 if( ! ($ip =~ /^[a-z0-9\.\-]+$/ ) );
+ return -1 unless( Vhffs::Functions::check_ip($ip) );
return -1 if( ! ($name =~ /^[a-z0-9\-]*|\*$/ ) );
- $name = "" if( $name eq "default" );
+ $name = '' if( $name eq 'default' );
- my $query = "UPDATE vhffs_dns_rr SET data='".$ip."' WHERE name='".$name."' AND zone='".$self->{'dns_id'}."' AND TYPE='A'";
- my $request2 = $self->{'db'}->prepare( $query );
- $request2->execute or return -2;
+ my $dbh = $self->get_main()->get_db_object();
+ my $sql = 'UPDATE vhffs_dns_rr SET data = ? WHERE name = ? AND zone = ? AND type = \'A\'';
+ $dbh->do($sql, undef, $ip, $name, $self->{dns_id}) or return -2;
- #Update SOA
- $self->commit;
- $self->add_history("Update A TYPE $name poiting now on $ip");
+ $self->{A}->{$name}->{data} = $ip;
+
+ $self->add_history("Updated A record $name poiting now on $ip");
+
+ $self->update_serial();
return 1;
}
sub add_ns
{
- my $self = shift;
- my $ip = shift;
- my $ttl = shift;
+ my ($self, $host, $ttl) = @_;
$ttl = 900 if ( ! defined $ttl );
- return -1 if( ! ($ip =~ /^[a-z0-9\-\.]+$/ ) );
+ return -1 if( ! ($host =~ /^[a-z0-9\-\.]+$/ ) );
-# return -1 if ( $self->name_exists( $name ) != 0 );
+ return -1 if( ! defined $host);
+ $host .= "." unless($host =~ /\.$/ );
- return -1 if( ! defined $ip);
- $ip .= "." if(! ($ip =~ /.+\.$/ ) );
+ my $sql = 'SELECT * FROM vhffs_dns_rr WHERE type=\'NS\' AND data=? AND zone=?';
+ my $dbh = $self->get_main->get_db_object();
+ return -1 if($dbh->do($sql, undef, $host, $self->{dns_id}) != 0);
- my $query;
- my $request;
- my $rows;
+ $sql = 'INSERT INTO vhffs_dns_rr(zone, name, type, data, aux, ttl) VALUES(?, \'\', \'NS\', ?, 0, ?)';
+ $dbh->do($sql, undef, $self->{dns_id}, $host, $ttl) or return -2;
- $query = "SELECT * FROM vhffs_dns_rr WHERE type='NS' AND data='".$ip."' AND zone='".$self->{'dns_id'}."'";
- $request = $self->{'db'}->prepare( $query );
- $rows = $request->execute;
+ my $id = $dbh->last_insert_id(undef, undef, 'vhffs_dns_rr', undef);
- return -1 if( $rows != 0 );
- my $id = $self->get_max_rrid();
+ my $ns = {id => $id,
+ zone => $self->{dns_id},
+ name => '',
+ type => 'NS',
+ data => $host,
+ aux => 0,
+ ttl => $ttl
+ };
+ $self->{NS}->{$host} = $ns;
- $query = "INSERT INTO vhffs_dns_rr VALUES( '".$id."' , '".$self->{'dns_id'}."', '' , 'NS' , '".$ip."' , '0' , '$ttl' )";
- $request = $self->{'db'}->prepare( $query );
- $request->execute or return -2;
- #Update SOA
- $self->commit;
+ $self->update_serial;
- $self->add_history("Add a NS TYPE with $ip");
+ $self->add_history("Added a NS record ($host)");
return 1;
}
@@ -502,39 +611,39 @@
my ( $self , $name , $ip , $ttl ) = @_;
$ttl = 900 if ( ! defined $ttl );
- $name = "" if( $name eq "default" );
+ $name = '' if( $name eq 'default' );
return -1 if ( $self->name_exists( $name ) != 0 );
- return -1 if( ! ($name =~ /^[a-z0-9\-]*|\*$/ ) );
+ return -1 if( ! ($name =~ /^[a-z0-9\-]+|\*$/ ) );
- if( ! defined $ip )
- {
- my $config = $self->{'main'}->get_config;
- if( defined $config->get_default_a )
- {
- $ip = $config->get_default_a;
- }
- else
- {
- return -1;
- }
+ if( ! defined $ip ) {
+ my $config = $self->{'main'}->get_config;
+ if( defined $config->get_default_a ) {
+ $ip = $config->get_default_a;
+ } else {
+ return -1;
+ }
}
- return -1 if( ! ($ip =~ /^[a-z0-9\.\-]+$/ ) );
-
- my $id = $self->get_max_rrid();
+ return -1 unless( Vhffs::Functions::check_ip($ip) );
- my $query;
- my $request;
- my $rows;
+ my $dbh = $self->get_main()->get_db_object();
+ my $sql = 'INSERT INTO vhffs_dns_rr (zone, name, type, data, aux, ttl) VALUES(?, ?, \'A\', ?, 0, ?)';
+ $dbh->do($sql, undef, $self->{dns_id}, $name, $ip, $ttl) or return -2;
+ my $id = $dbh->last_insert_id(undef, undef, 'vhffs_dns_rr', undef);
+ my $a = {id => $id,
+ zone => $self->{dns_id},
+ name => $name,
+ type => 'A',
+ data => $ip,
+ aux => 0,
+ ttl => $ttl
+ };
+ $self->{A}->{$name} = $a;
- $query = "INSERT INTO vhffs_dns_rr VALUES( '"."$id"."' , '".$self->{'dns_id'}."', '".$name."' , 'A' , '".$ip."' , '0' , '$ttl' )";
- $request = $self->{'db'}->prepare( $query );
- $request->execute or return -2;
- #Update SOA
- $self->commit;
+ $self->update_serial();
- $self->add_history("Add a A TYPE with name $name poiting on $ip");
+ $self->add_history("Added a A TYPE with name $name pointing on $ip");
return 1;
}
@@ -542,112 +651,112 @@
sub update_mx
{
-# my ( $self , $name , $ip , $aux , $ttl ) = @_;
- my $self = shift;
-# my $name = shift;
- my $data = shift;
- my $aux = shift;
+ my ($self, $data, $aux) = @_;
- my $query = "UPDATE vhffs_dns_rr SET data='".$data."' WHERE zone='".$self->{'dns_id'}."' AND aux='".$aux."' AND type='MX'";
- my $request2 = $self->{'db'}->prepare( $query );
+ my $sql = 'UPDATE vhffs_dns_rr SET data= ? WHERE zone = ? AND aux = ? AND type=\'MX\'';
+ my $dbh = $self->get_main()->get_db_object();
- $self->add_history("Change the MX for priority $aux : $data");
- #Update SOA
- $self->commit;
-
- $request2->execute or return -2;
+ $dbh->do($sql, undef, $data, $self->{dns_id}, $self->{aux}) or return -2;
+
+ $self->{MX}->{$aux}->{data} = $data;
+
+ $self->add_history("Changed the MX for priority $aux : $data");
+
+ $self->update_serial();
}
sub add_mx
{
- my $self = shift;
- my $ip = shift;
- my $aux = shift;
- my $ttl = shift;
+ my ($self, $host, $aux, $ttl) = @_;
$ttl = 900 if ( ! defined $ttl );
$aux = 10 if ( !defined $aux );
- return -1 if( ! ($ip =~ /^[a-z0-9\.\-]+$/ ) );
+ return -1 if( ! ($host =~ /^[a-z0-9\.\-]+$/ ) );
- my $query;
- my $request;
- my $rows;
+ $host .= '.' unless($host =~ /\.$/);
- $ip .= ".";
- $query = "SELECT * FROM vhffs_dns_rr WHERE type='MX' AND data='".$ip."' AND zone='".$self->{'dns_id'}."'";
- $request = $self->{'db'}->prepare( $query );
- $rows = $request->execute;
- return -1 if( $rows != 0 );
+ my $sql = 'SELECT id FROM vhffs_dns_rr WHERE type=\'MX\' AND data=? AND zone=?';
+ my $dbh = $self->get_main()->get_db_object();
+ return -1 if($dbh->do($sql, undef, $host, $self->{dns_id}) != 0);
- my $id = $self->get_max_rrid();
+ $sql = 'INSERT INTO vhffs_dns_rr(zone, name, type, data, aux, ttl) VALUES(?, \'\', \'MX\', ?, ?, ?)';
+ $dbh->do($sql, undef, $self->{dns_id}, $host, $aux, $ttl) or return -2;
+
+ my $id = $dbh->last_insert_id(undef, undef, 'vhffs_dns_rr', undef);
+ my $mx = {id => $id,
+ zone => $self->{dns_id},
+ name => '',
+ type => 'MX',
+ data => $host,
+ aux => $aux,
+ ttl => $ttl
+ };
+ $self->{MX}->{$aux} = $mx;
-
- $query = "INSERT INTO vhffs_dns_rr VALUES( '"."$id"."' , '".$self->{'dns_id'}."', '' , 'MX' , '".$ip."' , '$aux' , '$ttl' )";
- $request = $self->{'db'}->prepare( $query );
-
- $self->add_history("Add an MX in the domain with priority $aux on $ip");
- #Update SOA
- $self->commit;
+ $self->add_history("Added an MX record, host : $host - priority : $aux");
- $request->execute or return -2;
+ $self->update_serial();
}
sub update_cname
{
- my $self = shift;
- my $name = shift;
- my $ip = shift;
+ my ($self, $name, $host) = @_;
return -1 if( ! ($name =~ /^[a-z0-9\.\-]*$/ ) );
- return -1 if( ! ($ip =~ /^[a-z0-9\.\-]+$/ ) );
+ return -1 if( ! ($host =~ /^[a-z0-9\.\-]+$/ ) );
- $ip.=".";
- my $query = "UPDATE vhffs_dns_rr SET data='".$ip."' WHERE TYPE='CNAME' AND zone='".$self->{'dns_id'}."' AND name='".$name."'";
- my $request2 = $self->{'db'}->prepare( $query );
+ $host .='.' unless($host =~ /\.$/);
+ my $dbh = $self->get_main()->get_db_object();
+ my $sql = 'UPDATE vhffs_dns_rr SET data = ? WHERE type = \'CNAME\' AND zone = ? AND name = ?';
+ $dbh->do($sql, undef, $host, $self->{dns_id}, $name)or return -2;
- $self->add_history("Update CNAME $name pointing now on $ip");
- #Update SOA
- $self->commit;
-
- $request2->execute or return -2;
+ $self->{CNAME}->{$name}->{data} = $host;
+
+ $self->add_history("Updated CNAME $name pointing now on $host");
+ $self->update_serial();
}
sub add_cname
{
- my $self = shift;
- my $name = shift;
- my $ip = shift;
- my $ttl = shift;
+ my ($self, $name, $host, $ttl) = @_;
$ttl = 900 if ( ! defined $ttl );
- $name = "" if( $name eq "default" );
- return -1 if( ! ($name =~ /^[a-z0-9\-]*$/ ) );
- return -1 if( ! ($ip =~ /[a-z0-9\.\-]+/ ) );
+ $name = '' if( $name eq 'default' );
+ return -1 if( ! ($name =~ /^[a-z0-9\-]+$/ ) );
+ return -1 if( ! ($host =~ /[a-z0-9\.\-]+/ ) );
return -1 if ( $self->name_exists( $name ) != 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
- $ip.=".";
+ $host .= '.' unless($host =~ /\.$/);
- my $id = $self->get_max_rrid();
+ my $dbh = $self->get_main()->get_db_object();
- my $query = "INSERT INTO vhffs_dns_rr VALUES( '"."$id"."' , '".$self->{'dns_id'}."', '".$name."' , 'CNAME' , '".$ip."' , '0' , '$ttl' )";
- my $request2 = $self->{'db'}->prepare( $query );
+ my $sql = 'INSERT INTO vhffs_dns_rr(zone, name, type, data, aux, ttl) VALUES(?, ?, \'CNAME\', ?, 0, ?)';
+ $dbh->do($sql, undef, $self->{dns_id}, $name, $host, $ttl) or return -2;
+ my $id = $dbh->last_insert_id(undef, undef, 'vhffs_dns_rr', undef);
- $self->add_history("Add a CNAME $name pointing on $ip");
+ my $cname = {id => $id,
+ zone => $self->{dns_id},
+ name => $name,
+ type => 'CNAME',
+ data => $host,
+ aux => 0,
+ ttl => $ttl};
- #Update SOA
- $self->commit;
-
- $request2->execute or return -2;
+ $self->{CNAME}->{$name} = $cname;
+
+ $self->add_history("Added a CNAME record ($name -> $host)");
+
+ $self->update_serial();
}
@@ -666,79 +775,62 @@
return -1 if ( ! defined $self->{'dns_id'} );
#Set some defaults values if not defined
- $self->{SOA}->{'ttl'} = $conf->{default_ttl} if( ! defined $self->{SOA}->{'ttl'} );
- $self->{SOA}->{'ns'} = $conf->{default_ns1} if( ! defined $self->{SOA}->{'ns'} );
- $self->{SOA}->{'mbox'} = $conf->{default_mbox} if( ! defined $self->{SOA}->{'mbox'} );
- $self->{SOA}->{'serial'} = $conf->{default_serial} if( ! defined $self->{SOA}->{'serial'} );
- $self->{SOA}->{'refresh'} = $conf->{default_refresh} if( ! defined $self->{SOA}->{'refresh'} );
- $self->{SOA}->{'retry'} = $conf->{default_retry} if( ! defined $self->{SOA}->{'retry'} );
- $self->{SOA}->{'expire'} = $conf->{default_expire} if( ! defined $self->{SOA}->{'expire'} );
- $self->{SOA}->{'minimum'} = $conf->{default_minimum} if( ! defined $self->{SOA}->{'minimum'} );
+ $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->{SOA}->{'mbox'} =~ s/\@/\./;
+ $self->{'mbox'} =~ s/\@/\./;
#Update the serial to refresh the domain
- my ($second,$minutes,$hours,$day,$month,$year) = localtime(time);
- my $newserial = sprintf('%.4u%.2u%.2u01',$year+1900,$month+1,$day);
-
- if( $self->{SOA}->{serial} =~ /^$year$month$day/ || $self->{SOA}->{serial} > $newserial )
- {
- $self->{SOA}->{serial}++;
- }
- else
- {
- $self->{SOA}->{serial} = $newserial;
- }
+ $self->{serial} = $self->get_next_serial();
#First, commit the SOA
- $query = "UPDATE vhffs_dns SET ns='".$self->{SOA}->{'ns'}."', mbox='".$self->{SOA}->{'mbox'}."', serial='".$self->{SOA}->{'serial'}."', refresh='".$self->{SOA}->{'refresh'}."', retry='".$self->{SOA}->{'retry'}."', expire='".$self->{SOA}->{'expire'}."', minimum='".$self->{SOA}->{'minimum'}."', ttl='".$self->{SOA}->{'ttl'}."' WHERE dns_id=$self->{'dns_id'}";
+ $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;
+ # Commit the object part
+ $self->SUPER::commit;
+}
- if( defined $self->{CNAME} )
- {
- foreach (keys %{$self->{CNAME}} )
- {
- }
- }
+sub get_next_serial
+{
+ my $self = shift;
+ my ($second,$minutes,$hours,$day,$month,$year) = localtime(time);
+ my $newserial = sprintf('%.4u%.2u%.2u01',$year+1900,$month+1,$day);
- if( defined $self->{A} )
- {
- foreach (keys %{$self->{A}} )
- {
- }
+ if( $self->{serial} =~ /^$year$month$day/ || $self->{serial} > $newserial ) {
+ return ($self->{serial} + 1);
+ } else {
+ return ($newserial);
}
+}
-
- if( defined $self->{NS} )
- {
- foreach (keys %{$self->{NS}} )
- {
- }
- }
-
-
- if( defined $self->{MX} )
- {
- foreach (keys %{$self->{MX}} )
- {
- }
- }
-
-
- # Commit the object part
- $self->SUPER::commit;
+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});
}
-
-
########################################
# ACCESSORS
########################################
+sub get_dns_id
+{
+ my $self = shift;
+ return $self->{dns_id};
+}
+
sub get_mx_type
{
my $self = shift;
@@ -766,49 +858,49 @@
sub get_soa_ns
{
my $self = shift;
- return $self->{SOA}->{'ns'};
+ return $self->{'ns'};
}
sub get_soa_mbox
{
my $self = shift;
- return $self->{SOA}->{'mbox'};
+ return $self->{'mbox'};
}
sub get_soa_serial
{
my $self = shift;
- return $self->{SOA}->{'serial'};
+ return $self->{'serial'};
}
sub get_soa_refresh
{
my $self = shift;
- return $self->{SOA}->{'refresh'};
+ return $self->{'refresh'};
}
sub get_soa_retry
{
my $self = shift;
- return $self->{SOA}->{'retry'};
+ return $self->{'retry'};
}
sub get_soa_expire
{
my $self = shift;
- return $self->{SOA}->{'expire'};
+ return $self->{'expire'};
}
sub get_soa_minimum
{
my $self = shift;
- return $self->{SOA}->{'minimum'};
+ return $self->{'minimum'};
}
sub get_soa_ttl
{
my $self = shift;
- return $self->{SOA}->{'ttl'};
+ return $self->{'ttl'};
}
@@ -825,7 +917,7 @@
my $self = shift;
my $value = shift;
- $self->{SOA}->{'ns'} = $value;
+ $self->{'ns'} = $value;
}
sub set_soa_mbox
@@ -833,7 +925,7 @@
my $self = shift;
my $value = shift;
- $self->{SOA}->{'mbox'} = $value;
+ $self->{'mbox'} = $value;
}
sub set_soa_serial
@@ -841,7 +933,7 @@
my $self = shift;
my $value = shift;
- $self->{SOA}->{'serial'} = $value;
+ $self->{'serial'} = $value;
}
sub set_soa_refresh
@@ -849,7 +941,7 @@
my $self = shift;
my $value = shift;
- $self->{SOA}->{'refresh'} = $value;
+ $self->{'refresh'} = $value;
}
sub set_soa_retry
@@ -857,7 +949,7 @@
my $self = shift;
my $value = shift;
- $self->{SOA}->{'retry'} = $value;
+ $self->{'retry'} = $value;
}
@@ -880,7 +972,7 @@
my $self = shift;
my $value = shift;
- $self->{SOA}->{'expire'} = $value;
+ $self->{'expire'} = $value;
}
sub set_soa_minimum
@@ -888,7 +980,7 @@
my $self = shift;
my $value = shift;
- $self->{SOA}->{'minimum'} = $value;
+ $self->{'minimum'} = $value;
}
sub set_soa_ttl
@@ -896,7 +988,7 @@
my $self = shift;
my $value = shift;
- $self->{SOA}->{'ttl'} = $value;
+ $self->{'ttl'} = $value;
}
sub set_user
Modified: branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql
===================================================================
--- branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql 2007-03-19 17:48:29 UTC (rev 512)
@@ -300,13 +300,12 @@
ALTER TABLE vhffs_pgsql ADD CONSTRAINT vhffs_pgsql_unique_dbuser UNIQUE (dbuser);
ALTER TABLE vhffs_repository ADD CONSTRAINT vhffs_repository_unique_name UNIQUE (name);
ALTER TABLE vhffs_svn ADD CONSTRAINT vhffs_svn_unique_reponame UNIQUE (reponame);
+ALTER TABLE vhffs_dns ADD CONSTRAINT vhffs_dns_unique_domain UNIQUE (domain);
-- This index drastically improves performances on get_used_letters
CREATE INDEX idx_vhffs_httpd_servername_firstletter ON vhffs_httpd(substr(servername, 1, 1));
-- state is massively used in WHERE clause, this index improves overall performances
CREATE INDEX idx_vhffs_object_state ON vhffs_object(state);
--- This index drastically improves performances for mydns
-CREATE INDEX idx_vhffs_dns_domain ON vhffs_dns(domain);
/****** Non primary key constraints.
Defining foreign keys here allow to create tables in any order.
Modified: branches/vhffs_4.1/vhffs-irc/modobot.pl
===================================================================
--- branches/vhffs_4.1/vhffs-irc/modobot.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-irc/modobot.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -526,7 +526,7 @@
{
my $groupname = shift;
my $group;
- if ((! defined ($group= new Vhffs::Group( $vhffs , $groupname , '401' ) ) ) || ( $group->fetch < 0 ))
+ if (! defined ($group= Vhffs::Group::get_by_groupname( $vhffs , $groupname , '401' )))
{
irc_msg ("$groupname : No such group");
}
Modified: branches/vhffs_4.1/vhffs-panel/admin/moderation.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/admin/moderation.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/admin/moderation.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -176,7 +176,7 @@
my $nss = Vhffs::Services::DNS::getall( $vhffs , Vhffs::Constants::WAITING_FOR_VALIDATION );
$output = "";
- if( defined $nss )
+ if( @$nss > 0 )
{
foreach $temp ( @{$nss} )
{
Modified: branches/vhffs_4.1/vhffs-panel/cvs/cvs_submit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/cvs/cvs_submit.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/cvs/cvs_submit.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -73,11 +73,11 @@
if( ! ( $repo_name =~ /^[a-z0-9]+$/ ) )
{
- $message = "Your repository name is not correct. It must contains only caracter and numbers";
+ $message = gettext("Your repository name is not correct. It must contains only caracter and numbers");
}
elsif( length( $repo_name ) < 3 )
{
- $message = "Your repository name is not correct. It must contains at least 3 caracters";
+ $message = gettext("Your repository name is not correct. It must contains at least 3 caracters");
}
else
{
Modified: branches/vhffs_4.1/vhffs-panel/dns/add_a.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/add_a.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/add_a.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -49,6 +49,7 @@
use Vhffs::Main;
use Vhffs::Panel::Main;
use Vhffs::Panel::Menu;
+use Vhffs::Services::DNS;
my $panel = new Vhffs::Panel::Main();
if(!$panel) {
@@ -64,7 +65,7 @@
my $ip = $cgi->param("IP");
my $user = $panel->{'user'};
my $question = $cgi->param("QUESTION");
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $session = $panel->{'session'};
my $maintemplate = $panel->{'template'};
my $group = $panel->{'group'};
@@ -78,11 +79,11 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) || ( ! defined $name ) || ( ! defined $ip ))
+if( ( ! defined $domain_name ) || ( ! defined $name ) || ( ! defined $ip ))
{
$message = gettext( "CGI Error!");
}
-elsif( $dns->fetch < 0 )
+elsif( !defined $dns )
{
$message = gettext( "Cannot get informations on this object");
}
Modified: branches/vhffs_4.1/vhffs-panel/dns/add_cname.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/add_cname.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/add_cname.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -58,7 +58,7 @@
my $destination = $cgi->param("DESTINATION");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $session = $panel->{'session'};
@@ -75,11 +75,11 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) || ( ! defined $name ) || ( ! defined $destination ))
+if( ( ! defined $domain_name ) || ( ! defined $name ) || ( ! defined $destination ))
{
$message = gettext( "CGI Error!");
}
-elsif( $dns->fetch < 0 )
+elsif( !defined $dns )
{
$message = gettext( "Cannot get informations on this object");
Modified: branches/vhffs_4.1/vhffs-panel/dns/add_mx.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/add_mx.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/add_mx.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -58,7 +58,7 @@
my $mx = $cgi->param("MXNAME");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $session = $panel->{'session'};
@@ -75,12 +75,10 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) || ( ! defined $mx ) || ( ! defined $priority ))
+if( ( ! defined $domain_name ) || ( ! defined $mx ) || ( ! defined $priority ))
{
$message = gettext( "CGI Error!");
-}
-elsif( $dns->fetch < 0 )
-{
+} elsif( !defined $dns ) {
$message = gettext( "Cannot get informations on this object");
Modified: branches/vhffs_4.1/vhffs-panel/dns/add_ns.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/add_ns.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/add_ns.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -57,7 +57,7 @@
my $destination = $cgi->param("DESTINATION");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $session = $panel->{'session'};
@@ -74,13 +74,10 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) || ( ! defined $destination ))
+if( ( ! defined $domain_name ) || ( ! defined $destination ))
{
$message = gettext( "CGI Error!");
-}
-elsif( $dns->fetch < 0 )
-{
-
+} elsif( !defined $dns ) {
$message = gettext( "Cannot get informations on this object");
}
Modified: branches/vhffs_4.1/vhffs-panel/dns/delete.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/delete.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/delete.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -57,7 +57,7 @@
my $sure = $cgi->param("DELETE");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $templatedir = $vhffs->get_config->get_templatedir;
@@ -74,11 +74,11 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) )
+if( ! defined $domain_name )
{
$message = gettext( "CGI Error!");
}
-elsif( $dns->fetch < 0 )
+elsif( ! defined $dns )
{
$message = gettext( "Cannot get informations on this object");
Modified: branches/vhffs_4.1/vhffs-panel/dns/delete_a.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/delete_a.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/delete_a.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -27,7 +27,7 @@
my $name = $cgi->param("ANAME");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $session = $panel->{'session'};
@@ -45,11 +45,11 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) || ( ! defined $name ) )
+if( ( ! defined $domain_name ) || ( ! defined $name ) )
{
$message = gettext( "CGI Error!");
}
-elsif( $dns->fetch < 0 )
+elsif( !defined $dns )
{
$message = gettext( "Cannot get informations on this object");
Modified: branches/vhffs_4.1/vhffs-panel/dns/delete_cname.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/delete_cname.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/delete_cname.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -45,6 +45,7 @@
use Vhffs::Main;
use Vhffs::Panel::Main;
use Vhffs::Panel::Menu;
+use Vhffs::Services::DNS;
my $panel = new Vhffs::Panel::Main();
if(!$panel) {
@@ -57,7 +58,7 @@
my $name = $cgi->param("NAME");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $session = $panel->{'session'};
@@ -74,12 +75,9 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) || ( ! defined $name ) )
-{
+if( ( ! defined $domain_name ) || ( ! defined $name ) ) {
$message = gettext( "CGI Error!");
-}
-elsif( $dns->fetch < 0 )
-{
+} elsif( !defined $dns ) {
$message = gettext( "Cannot get informations on this object");
Modified: branches/vhffs_4.1/vhffs-panel/dns/delete_mx.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/delete_mx.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/delete_mx.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -57,7 +57,7 @@
my $priority = $cgi->param("PRIORITY");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $session = $panel->{'session'};
@@ -74,11 +74,11 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) || ( ! defined $priority ) )
+if( ( ! defined $domain_name ) || ( ! defined $priority ) )
{
$message = gettext( "CGI Error!");
}
-elsif( $dns->fetch < 0 )
+elsif( !defined $dns )
{
$message = gettext( "Cannot get informations on this object");
Modified: branches/vhffs_4.1/vhffs-panel/dns/delete_ns.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/delete_ns.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/delete_ns.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -56,7 +56,7 @@
my $ip = $cgi->param("IP");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $session = $panel->{'session'};
@@ -73,11 +73,11 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) || ( ! defined $ip ) )
+if( ( ! defined $domain_name ) || ( ! defined $ip ) )
{
$message = gettext( "CGI Error!");
}
-elsif( $dns->fetch < 0 )
+elsif( !defined $dns )
{
$message = gettext( "Cannot get informations on this object");
Modified: branches/vhffs_4.1/vhffs-panel/dns/dns_submit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/dns_submit.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/dns_submit.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -65,23 +65,19 @@
my $templatedir = $vhffs->get_config->get_templatedir;
-my $dns = Vhffs::Panel::DNS::create_dns( $vhffs , "$domain_name" , $user , $group );
if( ! ( $domain_name =~ /^[a-z0-9\.\-]+$/ ) )
{
- $message = gettext("Invalid domain name");
+ $message = gettext('Invalid domain name');
+} else {
+ my $dns = Vhffs::Panel::DNS::create_dns( $vhffs, $domain_name, $description, $user, $group );
+ if( defined $dns ) {
+ $message = gettext('The DNS object was successfully created !');
+ } else {
+ $message = gettext('An error occured while creating the object. The domain is not correct or aleady exists in Vhffs database');
+ }
}
-elsif( defined $dns )
-{
- $dns->set_description( $description );
- $dns->commit;
- $message = gettext("The DNS object was successfully created !");
-}
-else
-{
- $message = gettext( "An error occured while creating the object. The domain is not correct or aleady exists in Vhffs database" );
-}
my $template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
Modified: branches/vhffs_4.1/vhffs-panel/dns/dns_type_submit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/dns_type_submit.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/dns_type_submit.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -45,6 +45,7 @@
use Vhffs::Panel::Main;
use Vhffs::Panel::Menu;
use Vhffs::Panel::Group;
+use Vhffs::Services::DNS;
my $panel = new Vhffs::Panel::Main;
if(!$panel) {
@@ -64,7 +65,7 @@
my $prefix = $cgi->param("PREFIX");
my $ip = $cgi->param("IP");
my $question = $cgi->param("QUESTION");
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $templatedir = $vhffs->get_config->get_templatedir;
@@ -75,32 +76,19 @@
}
else
{
- if( $dns->fetch < 0 )
- {
- $message = "Error while fetching object $domain_name";
- }
- else
- {
-
- if( $dns->add_a( $prefix , $ip ) < 0 )
- {
- $message = "Error while create a type A";
+ if( $dns->add_a( $prefix , $ip ) < 0 ) {
+ $message = "Error while create a type A";
+ } else {
+ if( $dns->commit < 0) {
+ $message = "Error while update object";
+ } else {
+ $message = "Modifications applied to the database";
}
- else
- {
- if( $dns->commit < 0)
- {
- $message = "Error while update object";
- }
- else
- {
- $message = "Modifications applied to the database";
- }
- }
}
}
+
my $template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
$template->param( MESSAGE => $message );
Modified: branches/vhffs_4.1/vhffs-panel/dns/modif_a.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/modif_a.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/modif_a.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -58,7 +58,7 @@
my $ip = $cgi->param("IP");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $templatedir = $vhffs->get_config->get_templatedir;
@@ -75,12 +75,10 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) || ( ! defined $name ) || ( ! defined $ip ))
+if( ( ! defined $domain_name ) || ( ! defined $name ) || ( ! defined $ip ))
{
$message = gettext( "CGI Error!");
-}
-elsif( $dns->fetch < 0 )
-{
+} elsif( !defined $dns ) {
$message = gettext( "Cannot get informations on this object");
Modified: branches/vhffs_4.1/vhffs-panel/dns/modif_cname.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/modif_cname.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/modif_cname.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -45,6 +45,7 @@
use Vhffs::Main;
use Vhffs::Panel::Main;
use Vhffs::Panel::Menu;
+use Vhffs::Services::DNS;
my $panel = new Vhffs::Panel::Main();
if(!$panel) {
@@ -58,7 +59,7 @@
my $destination = $cgi->param("DESTINATION");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $templatedir = $vhffs->get_config->get_templatedir;
@@ -75,11 +76,11 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) || ( ! defined $name ) || ( ! defined $destination ))
+if( ( ! defined $domain_name ) || ( ! defined $name ) || ( ! defined $destination ))
{
$message = gettext( "CGI Error!");
}
-elsif( $dns->fetch < 0 )
+elsif( !defined $dns )
{
$message = gettext( "Cannot get informations on this object");
Modified: branches/vhffs_4.1/vhffs-panel/dns/modif_mx.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/modif_mx.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/modif_mx.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -45,6 +45,7 @@
use Vhffs::Main;
use Vhffs::Panel::Main;
use Vhffs::Panel::Menu;
+use Vhffs::Services::DNS;
my $panel = new Vhffs::Panel::Main();
if(!$panel) {
@@ -58,7 +59,7 @@
my $mx = $cgi->param("IP");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $session = $panel->{'session'};
@@ -75,11 +76,11 @@
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-if( ( ! defined $domain_name ) || ( ! defined $dns ) || ( ! defined $mx ) || ( ! defined $priority ))
+if( ( ! defined $domain_name ) || ( ! defined $mx ) || ( ! defined $priority ))
{
$message = gettext( "CGI Error!");
}
-elsif( $dns->fetch < 0 )
+elsif( !defined $dns )
{
$message = gettext( "Cannot get informations on this object");
Modified: branches/vhffs_4.1/vhffs-panel/dns/prefs.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/dns/prefs.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/dns/prefs.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -56,7 +56,7 @@
my $domain_name = $cgi->param("name");
my $user = $panel->{'user'};
-my $dns = new Vhffs::Services::DNS( $vhffs , $domain_name , $user );
+my $dns = Vhffs::Services::DNS::get_by_domainname( $vhffs , $domain_name );
my $session = $panel->{'session'};
@@ -72,13 +72,13 @@
my $output = "";
my $message;
-if( ( ! defined $domain_name ) || ( ! defined $dns ) )
+if( ! defined $domain_name )
{
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
$message = gettext( "CGI Error!");
$template->param( MESSAGE => $message );
}
-elsif( ( my $retour = $dns->fetch ) < 0 )
+elsif( !defined $dns)
{
$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
Modified: branches/vhffs_4.1/vhffs-panel/templates/dns/prefs.tmpl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/templates/dns/prefs.tmpl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-panel/templates/dns/prefs.tmpl 2007-03-19 17:48:29 UTC (rev 512)
@@ -18,7 +18,7 @@
</label>
<input type="text" name="PREFIX" id="PREFIX" /><strong>.<TMPL_VAR NAME="DOMAIN_NAME"></strong>
</p>
- <p>
+ <p id="ipField" style="display:none">
<label for="IP">
<TMPL_VAR NAME="TEXT_ADDIP">
</label>
@@ -29,13 +29,13 @@
<TMPL_VAR NAME="TEXT_QUESTION_REDIRECTION"> :
</legend>
<p>
- <input type="radio" name="QUESTION" id="QUESTION_YES" value="1" checked="checked" />
+ <input type="radio" name="QUESTION" id="QUESTION_YES" value="1" checked="checked" onclick="document.getElementById('ipField').style.display='none'"/>
<label for="QUESTION_YES">
<TMPL_VAR NAME="TEXT_YES">
</label>
</p>
<p>
- <input type="radio" name="QUESTION" value="0" id="QUESTION_NO" />
+ <input type="radio" name="QUESTION" value="0" id="QUESTION_NO" onclick="document.getElementById('ipField').style.display='block'"/>
<label for="QUESTION_NO">
<TMPL_VAR NAME="TEXT_NO">
</label>
Added: branches/vhffs_4.1/vhffs-tests/src/Services/DNS.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Services/DNS.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-tests/src/Services/DNS.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -0,0 +1,55 @@
+use strict;
+use Vhffs::Tests::Main;
+use Vhffs::Tests::Utils;
+use Vhffs::Constants;
+use Vhffs::User;
+use Vhffs::Services::DNS;
+use Test::More 'no_plan';
+
+my $main = init Vhffs::Tests::Main;
+isa_ok($main, 'Vhffs::Tests::Main', '$main');
+
+Vhffs::Tests::Utils::init_db($main->get_db_object);
+
+my $user1 = Vhffs::User::create($main, 'test1', 'abcdef', 0, 'test1@xxxxxxxx');
+isa_ok($user1, 'Vhffs::User', '$user1');
+
+my $group1 = Vhffs::Group::create($main, 'dnsgroup1', $user1->get_uid, undef, 'Test group for DNS Domain');
+isa_ok($group1, 'Vhffs::Group', '$group1');
+
+my $dns1 = Vhffs::Services::DNS::create($main, 'test.com', 'Test DNS domain 1', $user1, $group1);
+isa_ok($dns1, 'Vhffs::Services::DNS', '$dns1');
+cmp_ok($dns1->get_owneruid, '==', $user1->get_uid, 'uid matches');
+cmp_ok($dns1->get_ownergid, '==', $group1->get_gid, 'gid matches');
+cmp_ok($dns1->get_description, 'eq', 'Test DNS domain 1', 'description matches');
+cmp_ok($dns1->get_domain, 'eq', 'test.com', 'Domainname matches');
+
+$dns1->add_a('sample', '10.10.10.10');
+my $As = $dns1->get_a_type;
+cmp_ok($As->{sample}->{data}, 'eq', '10.10.10.10', 'A record IP matches');
+cmp_ok($As->{sample}->{zone}, '==', $dns1->get_dns_id(), 'A record registered for the right zone');
+cmp_ok($As->{sample}->{type}, 'eq', 'A', 'A Record has the right type');
+
+$dns1->add_ns('ns.test.com');
+my $NSs = $dns1->get_ns_type;
+cmp_ok($NSs->{'ns.test.com.'}->{data}, 'eq', 'ns.test.com.', 'NS record name matches');
+cmp_ok($NSs->{'ns.test.com.'}->{zone}, '==', $dns1->get_dns_id(), 'NS record registered for the right zone');
+cmp_ok($NSs->{'ns.test.com.'}->{type}, 'eq', 'NS', 'NS record has the right type');
+
+$dns1->add_cname('host1', 'host2.test.com');
+my $CNAMEs = $dns1->get_cname_type;
+cmp_ok($CNAMEs->{host1}->{data}, 'eq', 'host2.test.com.', 'Real name matches');
+cmp_ok($CNAMEs->{host1}->{name}, 'eq', 'host1', 'Alias matches');
+cmp_ok($CNAMEs->{host1}->{zone}, '==', $dns1->get_dns_id(), 'CNAME record registered for the right zone');
+cmp_ok($CNAMEs->{host1}->{type}, 'eq', 'CNAME', 'CNAME record has the right type');
+
+
+$dns1->add_mx('mx1.sample.com', 10);
+my $MXs = $dns1->get_mx_type;
+cmp_ok($MXs->{10}->{data}, 'eq', 'mx1.sample.com.', 'Mail server name matches');
+cmp_ok($MXs->{10}->{aux}, '==', 10, 'MX priority matches');
+cmp_ok($MXs->{10}->{zone}, '==', $dns1->get_dns_id(), 'MX record registered for the right zone');
+cmp_ok($MXs->{10}->{type}, 'eq', 'MX', 'MX record has the right type');
+
+my $dns2 = Vhffs::Services::DNS::get_by_domainname($main, 'test.com');
+is_deeply($dns1, $dns2, 'Created DNS matches fetched DNS')
Modified: branches/vhffs_4.1/vhffs-tests/src/Stats.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Stats.pl 2007-03-19 13:09:35 UTC (rev 511)
+++ branches/vhffs_4.1/vhffs-tests/src/Stats.pl 2007-03-19 17:48:29 UTC (rev 512)
@@ -136,15 +136,13 @@
for(my $i = 1 ; $i < 10 ; ++$i) {
$group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
$user = Vhffs::User::get_by_username($main, "testuser0$i");
- $svc = new Vhffs::Services::DNS($main, "dns0$i.test.com", $user, $group);
- $svc->create;
+ $svc = Vhffs::Services::DNS::create($main, "dns0$i.test.com", "Stats domain #$i", $user, $group);
}
$stats = new Vhffs::Stats($main);
is($stats->get_dns_in_moderation, 9, 'All DNS services waiting for moderation');
for(my $i = 1 ; $i < 10 ; ++$i) {
- $svc = new Vhffs::Services::DNS($main, "dns0$i.test.com");
- $svc->fetch;
+ $svc = Vhffs::Services::DNS::get_by_domainname($main, "dns0$i.test.com");
$svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$svc->commit;
$stats = new Vhffs::Stats($main);
@@ -153,8 +151,7 @@
}
for(my $i = 1 ; $i < 10 ; ++$i) {
- $svc = new Vhffs::Services::DNS($main, "dns0$i.test.com");
- $svc->fetch;
+ $svc = Vhffs::Services::DNS::get_by_domainname($main, "dns0$i.test.com");
$svc->set_status(Vhffs::Constants::ACTIVATED);
$svc->commit;
$stats = new Vhffs::Stats($main);
@@ -220,16 +217,14 @@
for(my $i = 1 ; $i < 10 ; ++$i) {
$group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
$user = Vhffs::User::get_by_username($main, "testuser0$i");
- $svc = new Vhffs::Services::Svn($main, "svntest0$i", $user, $group);
- $svc->create;
+ $svc = Vhffs::Services::Svn::create($main, "svntest0$i", "SVN #$i for stats tests", $user, $group);
}
$stats = new Vhffs::Stats($main);
is($stats->get_svn_in_moderation, 9, 'All SVN services waiting for moderation');
for(my $i = 1 ; $i < 10 ; ++$i) {
$group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
- $svc = new Vhffs::Services::Svn($main, "svntest0$i", undef, $group);
- $svc->fetch;
+ $svc = Vhffs::Services::Svn::get_by_reponame($main, "svntest0$i");
$svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$svc->commit;
$stats = new Vhffs::Stats($main);
@@ -239,8 +234,7 @@
for(my $i = 1 ; $i < 10 ; ++$i) {
$group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
- $svc = new Vhffs::Services::Svn($main, "svntest0$i", undef, $group);
- $svc->fetch;
+ $svc = Vhffs::Services::Svn::get_by_reponame($main, "svntest0$i");
$svc->set_status(Vhffs::Constants::ACTIVATED);
$svc->commit;
$stats = new Vhffs::Stats($main);
@@ -252,15 +246,13 @@
for(my $i = 1 ; $i < 10 ; ++$i) {
$group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
$user = Vhffs::User::get_by_username($main, "testuser0$i");
- $svc = new Vhffs::Services::Mail($main, "mail0$i.test.com", $user, $group);
- $svc->create;
+ $svc = Vhffs::Services::Mail::create($main, "mail0$i.test.com", "Mail domain #$i for stats' tests", $user, $group);
}
$stats = new Vhffs::Stats($main);
is($stats->get_mail_in_moderation, 9, 'All Mail services waiting for moderation');
for(my $i = 1 ; $i < 10 ; ++$i) {
- $svc = new Vhffs::Services::Mail($main, "mail0$i.test.com");
- $svc->fetch;
+ $svc = Vhffs::Services::Mail::get_by_mxdomain($main, "mail0$i.test.com");
$svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
$svc->commit;
$stats = new Vhffs::Stats($main);
@@ -269,8 +261,7 @@
}
for(my $i = 1 ; $i < 10 ; ++$i) {
- $svc = new Vhffs::Services::Mail($main, "mail0$i.test.com");
- $svc->fetch;
+ $svc = Vhffs::Services::Mail::get_by_mxdomain($main, "mail0$i.test.com");
$svc->set_status(Vhffs::Constants::ACTIVATED);
$svc->commit;
$stats = new Vhffs::Stats($main);
@@ -280,8 +271,7 @@
# mboxes tests
for(my $i = 1 ; $i < 10 ; ++$i) {
- $svc = new Vhffs::Services::Mail($main, "mail0$i.test.com");
- $svc->fetch;
+ $svc = Vhffs::Services::Mail::get_by_mxdomain($main, "mail0$i.test.com");
for(my $j = 0 ; $j < 10 ; ++$j) {
$svc->addbox("mboxtest0${i}0$j", '123456');
}
@@ -295,8 +285,7 @@
# forward tests
for(my $i = 1 ; $i < 10 ; ++$i) {
- $svc = new Vhffs::Services::Mail($main, "mail0$i.test.com");
- $svc->fetch;
+ $svc = Vhffs::Services::Mail::get_by_mxdomain($main, "mail0$i.test.com");
for(my $j = 0 ; $j < 10 ; ++$j) {
$svc->addforward("fwdtest0${i}0$j", "test0$i\@test.com");
}