[vhffs-dev] [1342] Improved DNS support, subdomains are supported on each record type |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1342
Author: gradator
Date: 2009-02-18 06:40:16 +0100 (Wed, 18 Feb 2009)
Log Message:
-----------
Improved DNS support, subdomains are supported on each record type
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Panel/DNS.pm
trunk/vhffs-api/src/Vhffs/Services/DNS.pm
trunk/vhffs-panel/dns/prefs.pl
trunk/vhffs-panel/templates/dns/list_mx_sub.tmpl
trunk/vhffs-panel/templates/dns/list_ns_sub.tmpl
trunk/vhffs-panel/templates/dns/prefs.tmpl
Modified: trunk/vhffs-api/src/Vhffs/Panel/DNS.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/DNS.pm 2009-02-18 02:34:51 UTC (rev 1341)
+++ trunk/vhffs-api/src/Vhffs/Panel/DNS.pm 2009-02-18 05:40:16 UTC (rev 1342)
@@ -154,6 +154,7 @@
sub delete_record {
my ($dns, $id, $type) = @_;
die() unless(defined $dns && defined $id && defined $type);
+ die(gettext('You cannot delete NS records on origin')."\n") if($type eq 'NS' and defined $dns->{NS}->{$id}->{name} and $dns->{NS}->{$id}->{name} eq '@');
my $rval = $dns->delete_record($id, $type);
return 1 if($rval > 0);
die(gettext('Invalid record')."\n") if($rval == -1);
@@ -269,6 +270,7 @@
sub add_ns {
my ($dns, $name, $host) = @_;
die() unless(defined $dns && defined $name && defined $host);
+ die(gettext('You cannot add NS records on origin')."\n") if($name eq '@');
my $rval = $dns->add_ns($name, $host);
return 1 if($rval > 0);
die(gettext('Invalid hostname')."\n") if($rval == -1);
@@ -338,12 +340,12 @@
sub add_txt {
my ($dns, $name, $txt) = @_;
die() unless(defined $dns && defined $name && defined $txt);
- warn "$name:$txt (2)";
my $rval = $dns->add_txt($name, $txt);
return 1 if($rval > 0);
die(gettext('Invalid prefix')."\n") if($rval == -1);
die(gettext('Text can\'t be empty')."\n") if($rval == -2);
- die(gettext('Database error')."\n") if($rval == -3);
+ die(gettext('A TXT record with the same name already exists for this domain')."\n") if($rval == -3);
+ die(gettext('Database error')."\n") if($rval == -4);
die(gettext('Unknown error')."\n");
}
Modified: trunk/vhffs-api/src/Vhffs/Services/DNS.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/DNS.pm 2009-02-18 02:34:51 UTC (rev 1341)
+++ trunk/vhffs-api/src/Vhffs/Services/DNS.pm 2009-02-18 05:40:16 UTC (rev 1342)
@@ -243,7 +243,7 @@
push @records, $a;
# Fetches NS records
- $sql = 'SELECT id, zone, name, type, data, aux, ttl FROM vhffs_dns_rr WHERE zone = ? AND type = ?';
+ $sql = 'SELECT id, zone, (CASE WHEN name = \'\' THEN \'@\' 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, 'NS');
my $ns = $sth->fetchall_hashref('id');
@@ -257,7 +257,7 @@
push @records, $cname;
# Fetches MX records
- $sql = 'SELECT id, zone, name, type, data, aux, ttl FROM vhffs_dns_rr WHERE zone = ? AND type = ?';
+ $sql = 'SELECT id, zone, (CASE WHEN name = \'\' THEN \'@\' 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, 'MX');
my $mx = $sth->fetchall_hashref('id');
@@ -279,14 +279,14 @@
push @records, $srv;
# Fetches AAAA records
- $sql = 'SELECT id, zone, (CASE WHEN name = \'\' THEN \'@\' ELSE name END) AS name, type, data, aux, ttl FROM vhffs_dns_rr WHERE zone = ? AND type = \'AAAA\'';
+ $sql = 'SELECT id, zone, (CASE WHEN name = \'\' THEN \'@\' 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);
+ $sth->execute($dns_id, 'AAAA');
my $aaaa = $sth->fetchall_hashref('id');
push @records, $aaaa;
# Fetches TXT records
- $sql = 'SELECT id, zone, name, type, data, aux, ttl FROM vhffs_dns_rr WHERE zone = ? AND type = ?';
+ $sql = 'SELECT id, zone, (CASE WHEN name = \'\' THEN \'@\' 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, 'TXT');
my $txt = $sth->fetchall_hashref('id');
@@ -778,10 +778,11 @@
return -1 unless( check_rr_name($name) );
$name = '' if( $name eq '@' );
return -2 if($data =~ /^\s*$/);
+ return -3 if ( $self->name_exists( $name, 'TXT', 'CNAME' ) != 0 );
my $dbh = $self->get_main()->get_db_object();
my $sql = 'INSERT INTO vhffs_dns_rr (zone, name, type, data, aux, ttl) VALUES(?, ?, \'TXT\', ?, 0, ?)';
- $dbh->do($sql, undef, $self->{dns_id}, $name, $data, $ttl) or return -3;
+ $dbh->do($sql, undef, $self->{dns_id}, $name, $data, $ttl) or return -4;
my $id = $dbh->last_insert_id(undef, undef, 'vhffs_dns_rr', undef);
$name = '@' if($name eq '');
Modified: trunk/vhffs-panel/dns/prefs.pl
===================================================================
--- trunk/vhffs-panel/dns/prefs.pl 2009-02-18 02:34:51 UTC (rev 1341)
+++ trunk/vhffs-panel/dns/prefs.pl 2009-02-18 05:40:16 UTC (rev 1342)
@@ -147,7 +147,7 @@
else { $panel->add_info(gettext('MX Record deleted')); }
}
} elsif($action eq 'add_mx') {
- eval { Vhffs::Panel::DNS::add_mx($dns, '@', $data, $aux); };
+ eval { Vhffs::Panel::DNS::add_mx($dns, $name, $data, $aux); };
if($@) { $panel->add_error(sprintf(gettext('Unable to add MX record: %s'), $@)); }
else { $panel->add_info(gettext('MX Record added')); }
} elsif($action eq 'manage_ns') {
@@ -156,7 +156,7 @@
if($@) { $panel->add_error(sprintf(gettext('Unable to delete NS record: %s'), $@)); }
else { $panel->add_info(gettext('NS Record deleted')); }
} elsif($action eq 'add_ns') {
- eval { Vhffs::Panel::DNS::add_ns($dns, '@', $data); };
+ eval { Vhffs::Panel::DNS::add_ns($dns, $name, $data); };
if($@) { $panel->add_error(sprintf(gettext('Unable to add NS record: %s'), $@)); }
else { $panel->add_info(gettext('NS Record added')); }
} elsif($action eq 'manage_cname') {
@@ -193,11 +193,10 @@
my $port = $cgi->param('port');
my $aux = $cgi->param('aux');
my $weight = $cgi->param('weight');
- eval { Vhffs::Panel::DNS::add_srv($dns, '@', $proto, $svc, $host, $port, $aux, $weight); };
+ eval { Vhffs::Panel::DNS::add_srv($dns, $name, $proto, $svc, $host, $port, $aux, $weight); };
if($@) { $panel->add_error(sprintf(gettext('Unable to add SRV record: %s'), $@)); }
else { $panel->add_info(gettext('SRV Record added')); }
} elsif($action eq 'add_txt') {
- warn "$name:$data";
eval { Vhffs::Panel::DNS::add_txt($dns, $name, $data); };
if($@) { $panel->add_error(sprintf(gettext('Unable to add TXT record: %s'), $@)); }
else { $panel->add_info(gettext('TXT Record added')); }
@@ -268,6 +267,7 @@
#All templates for MX reccords
$template->param( TEXT_LIST_MX => gettext("All MX TYPE for your domain name") );
$template->param( TEXT_ADD_MX => gettext("Add a MX field to your domain") );
+ $template->param( MX_DOMAINNAME => gettext("Name of the record") );
$template->param( MX_NAME => gettext("Name of your MX") );
$template->param( MX_PRIORITY => gettext("Priority of your MX") );
$template->param( TEXT_SUBMIT => gettext("Submit") );
@@ -284,12 +284,14 @@
$template->param( TEXT_TYPENS => gettext("NS TYPE") );
$template->param( TEXT_LIST_NS => gettext("All NS TYPE for your domain name") );
$template->param( TEXT_ADD_NS => gettext("Add a NS field to your domain") );
+ $template->param( NS_PREFIX => gettext('Name of the record') );
$template->param( NS_HOSTNAME_TEXT => gettext('Host of your name server') );
#Treat SRV part
$template->param( TEXT_TYPESRV => gettext('SRV TYPE') );
$template->param( TEXT_LIST_SRV => gettext('All SRV records for your domain name') );
$template->param( TEXT_ADD_SRV => gettext('Add a SRV record to your domain') );
+ $template->param( SRV_PREFIX => gettext('Name of the record') );
$template->param( SRV_PROTOCOL_TEXT => gettext('Protocol') );
$template->param( SRV_SERVICE_TEXT => gettext('Service') );
$template->param( SRV_HOSTNAME_TEXT => gettext('Host') );
@@ -334,7 +336,7 @@
if( scalar(keys %{$mx} ) ) {
$thirdtemplate = new HTML::Template( filename => $templatedir.'/panel/dns/list_mx_sub.tmpl', global_vars => 1, die_on_bad_params => 0 );
- my @list_mx = sort {$a->{aux} <=> $b->{aux}} values(%{$mx});
+ my @list_mx = sort {$a->{name} cmp $b->{name}} sort {$a->{aux} <=> $b->{aux}} values(%{$mx});
$thirdtemplate->param( DEL => gettext( 'Delete' ) );
$thirdtemplate->param( DOMAIN => $domain_name );
$thirdtemplate->param( MODIFY => gettext( 'Modify' ) );
@@ -361,7 +363,7 @@
if( scalar(keys %{$ns}) ) {
- my @list_ns = sort {$a->{data} cmp $b->{data}} values(%{$ns});
+ my @list_ns = sort {$a->{name} cmp $b->{name}} sort {$a->{data} cmp $b->{data}} values(%{$ns});
$thirdtemplate = new HTML::Template( filename => $templatedir.'/panel/dns/list_ns_sub.tmpl', global_vars => 1, die_on_bad_params => 0 );
$thirdtemplate->param( DEL => gettext( 'Delete' ) );
$thirdtemplate->param( DOMAIN => $domain_name );
Modified: trunk/vhffs-panel/templates/dns/list_mx_sub.tmpl
===================================================================
--- trunk/vhffs-panel/templates/dns/list_mx_sub.tmpl 2009-02-18 02:34:51 UTC (rev 1341)
+++ trunk/vhffs-panel/templates/dns/list_mx_sub.tmpl 2009-02-18 05:40:16 UTC (rev 1342)
@@ -1,7 +1,7 @@
<TMPL_LOOP NAME="MX_RR">
<form method="post" action="prefs.pl" accept-charset="utf-8">
<p><label for="data_<TMPL_VAR ESCAPE=1 NAME="id">">
- <TMPL_VAR ESCAPE=1 NAME="TEXT_PRIORITY"><TMPL_VAR ESCAPE=1 NAME="aux">
+ <TMPL_VAR ESCAPE=1 NAME="name"> (<TMPL_VAR ESCAPE=1 NAME="TEXT_PRIORITY"><TMPL_VAR ESCAPE=1 NAME="aux">)->
</label>
<input type="text" name="data" id="data_<TMPL_VAR ESCAPE=1 NAME="id">" value="<TMPL_VAR ESCAPE=1 NAME="data">" />
<input type="hidden" name="domain" value="<TMPL_VAR ESCAPE=1 NAME="DOMAIN">" />
Modified: trunk/vhffs-panel/templates/dns/list_ns_sub.tmpl
===================================================================
--- trunk/vhffs-panel/templates/dns/list_ns_sub.tmpl 2009-02-18 02:34:51 UTC (rev 1341)
+++ trunk/vhffs-panel/templates/dns/list_ns_sub.tmpl 2009-02-18 05:40:16 UTC (rev 1342)
@@ -1,7 +1,7 @@
<TMPL_LOOP NAME="NS_RR">
<form method="post" action="prefs.pl" accept-charset="utf-8">
<p>
- <label><TMPL_VAR ESCAPE=1 NAME="data"></label>
+ <label><TMPL_VAR ESCAPE=1 NAME="name">-> <TMPL_VAR ESCAPE=1 NAME="data"></label>
<input type="hidden" name="action" value="manage_ns" />
<input type="hidden" name="rr_id" value="<TMPL_VAR ESCAPE=1 NAME="id">" />
<input type="hidden" name="domain" value="<TMPL_VAR ESCAPE=1 NAME="domain">" />
Modified: trunk/vhffs-panel/templates/dns/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/dns/prefs.tmpl 2009-02-18 02:34:51 UTC (rev 1341)
+++ trunk/vhffs-panel/templates/dns/prefs.tmpl 2009-02-18 05:40:16 UTC (rev 1342)
@@ -74,7 +74,14 @@
<h3><TMPL_VAR ESCAPE=1 NAME="TEXT_ADD_MX"></h3>
<form method="post" action="prefs.pl" accept-charset="utf-8">
+ <p class="help"><TMPL_VAR ESCAPE=1 NAME="TEXT_ORIGIN"></p>
<p>
+ <label for="add_mx_prefix">
+ <TMPL_VAR ESCAPE=1 NAME="MX_DOMAINNAME">
+ </label>
+ <input type="text" name="name" id="add_mx_prefix" /><strong>.<TMPL_VAR ESCAPE=1 NAME="DOMAIN_NAME"></strong>
+ </p>
+ <p>
<label for="add_mx_data">
<TMPL_VAR ESCAPE=1 NAME="MX_NAME">
</label>
@@ -125,8 +132,10 @@
<TMPL_VAR ESCAPE=0 NAME="LIST_NS">
<h3><TMPL_VAR ESCAPE=1 NAME="TEXT_ADD_NS"></h3>
<form method="post" action="prefs.pl" accept-charset="utf-8">
- <label for="add_ns_data"><TMPL_VAR ESCAPE=1 NAME="NS_HOSTNAME_TEXT"></label>
- <input type="text" name="data" id="add_ns_data"/>
+ <p><label for="add_ns_prefix"><TMPL_VAR ESCAPE=1 NAME="NS_PREFIX"></label>
+ <input type="text" name="name" id="add_ns_prefix"/><strong>.<TMPL_VAR ESCAPE=1 NAME="DOMAIN_NAME"></strong></p>
+ <p><label for="add_ns_data"><TMPL_VAR ESCAPE=1 NAME="NS_HOSTNAME_TEXT"></label>
+ <input type="text" name="data" id="add_ns_data"/></p>
<input type="hidden" name="action" value="add_ns"/>
<input type="hidden" name="domain" value="<TMPL_VAR ESCAPE=1 NAME="DOMAIN_NAME">"/>
<input type="submit" value="<TMPL_VAR ESCAPE=1 NAME="TEXT_SUBMIT">" class="autowidth"/>
@@ -137,6 +146,9 @@
<TMPL_VAR ESCAPE=0 NAME="LIST_SRV">
<h3><TMPL_VAR ESCAPE=1 NAME="TEXT_ADD_SRV"></h3>
<form method="post" action="prefs.pl" accept-charset="utf-8">
+ <p class="help"><TMPL_VAR ESCAPE=1 NAME="TEXT_ORIGIN"></p>
+ <p><label for="add_srv_name"><TMPL_VAR ESCAPE=1 NAME="SRV_PREFIX"></label>
+ <input type="text" name="name" id="add_srv_name" /><strong>.<TMPL_VAR ESCAPE=1 NAME="DOMAIN_NAME"></strong></p>
<p><label for="add_srv_protocol"><TMPL_VAR ESCAPE=1 NAME="SRV_PROTOCOL_TEXT"></label>
<input type="text" name="protocol" id="add_srv_protocol"/></p>
<p><label for="add_srv_service"><TMPL_VAR ESCAPE=1 NAME="SRV_SERVICE_TEXT"></label>