summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Voborník <pvoborni@redhat.com>2012-02-09 11:10:27 +0100
committerPetr Voborník <pvoborni@redhat.com>2012-02-15 09:25:47 +0100
commit578669daa42b1b34d5e76462aa42dea89d1a2f32 (patch)
treebb8690972440620d22e938e550042797accae1c8
parent05973d2e61ab21b2ba4bb8afebd7a0a4a111eab7 (diff)
downloadfreeipa-578669daa42b1b34d5e76462aa42dea89d1a2f32.tar.gz
freeipa-578669daa42b1b34d5e76462aa42dea89d1a2f32.tar.xz
freeipa-578669daa42b1b34d5e76462aa42dea89d1a2f32.zip
Redirection to PTR records from A,AAAA records
Address column in A, AAAA DNS records was exented of redirection capabilities. Redirection dialog is shown after a click on a value. Dialog does following steps: 1) fetch all dns zones 2) find most accurate reverse zone for IP address 2 -fail) show error message, stop 3) checks if target record exists in the zone 3 -fail) show 'dns record create link', stop 4) redirects Click on 'dns record create link': 1) creates record 1 -fail) show error, stop 2) redirects https://fedorahosted.org/freeipa/ticket/1975
-rw-r--r--install/ui/dns.js235
-rw-r--r--install/ui/test/data/ipa_init.json11
-rw-r--r--ipalib/plugins/internal.py11
3 files changed, 255 insertions, 2 deletions
diff --git a/install/ui/dns.js b/install/ui/dns.js
index edd9274c6..5c6fc6c03 100644
--- a/install/ui/dns.js
+++ b/install/ui/dns.js
@@ -582,7 +582,12 @@ IPA.dns.get_record_metadata = function() {
validators: [IPA.ip_v4_address_validator()]
}
],
- columns: ['a_part_ip_address']
+ columns: [
+ {
+ factory: IPA.dns.ptr_redirection_column,
+ name: 'a_part_ip_address'
+ }
+ ]
},
{
name: 'aaaarecord',
@@ -592,7 +597,12 @@ IPA.dns.get_record_metadata = function() {
validators: [IPA.ip_v6_address_validator()]
}
],
- columns: ['aaaa_part_ip_address']
+ columns: [
+ {
+ factory: IPA.dns.ptr_redirection_column,
+ name: 'aaaa_part_ip_address'
+ }
+ ]
},
{
name: 'a6record',
@@ -1833,6 +1843,227 @@ IPA.dns.record_modify_column = function(spec) {
return that;
};
+IPA.dns.ptr_redirection_column = function(spec) {
+
+ spec = spec || {};
+
+ var that = IPA.column(spec);
+
+ that.link = true;
+
+ that.link_handler = function(value) {
+
+ var address = NET.ip_address(value);
+
+ var dialog = IPA.dns.ptr_redirection_dialog({
+ address: address
+ });
+ dialog.open();
+
+ return false;
+ };
+
+ return that;
+};
+
+IPA.dns.ptr_redirection_dialog = function(spec) {
+
+ spec = spec || {};
+
+ spec.title = IPA.messages.objects.dnsrecord.ptr_redir_title;
+
+ var that = IPA.dialog(spec);
+
+ that.address = spec.address;
+
+ that.create = function() {
+
+ that.status_div = $('<div />', {
+ 'class': 'redirection-status'
+ }).appendTo(that.container);
+ };
+
+ that.create_buttons = function() {
+
+ that.create_button({
+ name: 'close',
+ label: IPA.messages.buttons.close,
+ click: function() {
+ that.close();
+ }
+ });
+ };
+
+ that.create_add_record_button = function() {
+
+ $('<a />', {
+ text: IPA.messages.objects.dnsrecord.ptr_redir_create,
+ href: '#create_record',
+ click: function() {
+ that.create_record();
+ return false;
+ }
+ }).appendTo(that.container);
+ };
+
+ that.append_status = function(message) {
+
+ $('<div />', {
+ text: message
+ }).appendTo(that.status_div);
+ };
+
+ that.open = function() {
+
+ that.dialog_open();
+ that.start_redirect();
+ };
+
+ //step 0 - preparation
+ that.start_redirect = function() {
+
+ if (!that.address.valid) {
+ that.append_status(IPA.messages.objects.dnsrecord.ptr_redir_address_err);
+ } else {
+ that.reverse_address = that.address.get_reverse().toLowerCase()+'.';
+
+ var record = IPA.nav.get_state('dnsrecord-pkey');
+ var zone = IPA.nav.get_state('dnszone-pkey');
+
+ if (record && zone && record !== '' && zone !== '') {
+ that.dns_record = {
+ name: record,
+ zone: zone
+ };
+ }
+
+ that.get_zones();
+ }
+ };
+
+ //1st step: get all zones
+ that.get_zones = function() {
+
+ that.append_status(IPA.messages.objects.dnsrecord.ptr_redir_zones);
+
+ var command = IPA.command({
+ entity: 'dnszone',
+ method: 'find',
+ options: {
+ pkey_only: true
+ },
+ on_success: that.find_zone,
+ on_error: function() {
+ that.append_status(IPA.messages.objects.dnsrecord.ptr_redir_zones_err);
+ }
+ });
+
+ command.execute();
+ };
+
+ //2nd step: find target zone
+ that.find_zone = function(data) {
+ var zones = data.result.result;
+ var target_zone = null;
+
+ for (var i=0; i<zones.length; i++) {
+
+ var zone_name = zones[i].idnsname[0];
+ if (that.reverse_address.indexOf(zone_name) > -1) {
+ var msg = IPA.messages.objects.dnsrecord.ptr_redir_zone;
+ msg = msg.replace('${zone}', zone_name);
+ that.append_status(msg);
+
+ if (!target_zone ||
+ (target_zone && zone_name.length > target_zone.length)) {
+
+ target_zone = zone_name;
+ }
+
+ break;
+ }
+ }
+
+ if (target_zone) {
+ that.zone = target_zone;
+ that.check_record();
+ } else {
+ that.append_status(IPA.messages.objects.dnsrecord.ptr_redir_zone_err);
+ }
+ };
+
+ //3rd step: check record existance
+ that.check_record = function(zone) {
+
+ that.append_status(IPA.messages.objects.dnsrecord.ptr_redir_record);
+
+ var i1 = that.reverse_address.indexOf(that.zone);
+ var record_name = that.reverse_address.substring(0,i1 - 1);
+ that.record_keys = [that.zone, record_name];
+
+ var command = IPA.command({
+ entity: 'dnsrecord',
+ method: 'show',
+ args: that.record_keys,
+ on_success: function() {
+ that.redirect();
+ },
+ on_error: function() {
+ that.append_status(IPA.messages.objects.dnsrecord.ptr_redir_record_err);
+ if (that.dns_record) {
+ that.create_add_record_button();
+ }
+ },
+ retry: false
+ });
+
+ command.execute();
+ };
+
+ //4th-a step: actual redirect
+ that.redirect = function() {
+
+ var entity = IPA.get_entity('dnsrecord');
+
+ IPA.nav.show_entity_page(
+ entity,
+ 'default',
+ that.record_keys);
+
+ that.close();
+ };
+
+ //4th-b optional step: create PTR record
+ that.create_record = function() {
+
+ that.append_status(IPA.messages.objects.dnsrecord.ptr_redir_creating);
+
+ var ptr = that.dns_record.name +'.' + that.dns_record.zone;
+
+ var command = IPA.command({
+ entity: 'dnsrecord',
+ method: 'add',
+ args: that.record_keys,
+ options: {
+ ptrrecord: [ptr]
+ },
+ on_success: function() {
+ that.redirect();
+ },
+ on_error: function() {
+ that.append_status(IPA.messages.objects.dnsrecord.ptr_redir_creating_err);
+ }
+ });
+
+ command.execute();
+ };
+
+
+ that.create_buttons();
+
+ return that;
+};
+
IPA.ip_address_validator = function(spec) {
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index b755c4628..740307f7a 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -186,6 +186,17 @@
"data": "Data",
"deleted_no_data": "DNS record was deleted because it contained no data.",
"other": "Other Record Types",
+ "ptr_redir_address_err": "Address not valid, can't redirect",
+ "ptr_redir_create": "Create dns record",
+ "ptr_redir_creating": "Creating record.",
+ "ptr_redir_creating_err": "Record creation failed.",
+ "ptr_redir_record": "Checking if record exists.",
+ "ptr_redir_record_err": "Record not found.",
+ "ptr_redir_title": "Redirection to PTR record",
+ "ptr_redir_zone": "Zone found: ${zone}",
+ "ptr_redir_zone_err": "Target reverse zone not found.",
+ "ptr_redir_zones": "Fetching DNS zones.",
+ "ptr_redir_zones_err": "An error occurd while fetching dns zones.",
"redirection_dnszone": "You will be redirected to DNS Zone.",
"standard": "Standard Record Types",
"title": "Records for DNS Zone",
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index 7557ff99c..8623e61a8 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -323,6 +323,17 @@ class i18n_messages(Command):
"data": _("Data"),
"deleted_no_data": _("DNS record was deleted because it contained no data."),
"other": _("Other Record Types"),
+ "ptr_redir_address_err": _("Address not valid, can't redirect"),
+ "ptr_redir_create": _("Create dns record"),
+ "ptr_redir_creating": _("Creating record."),
+ "ptr_redir_creating_err": _("Record creation failed."),
+ "ptr_redir_record": _("Checking if record exists."),
+ "ptr_redir_record_err": _("Record not found."),
+ "ptr_redir_title": _("Redirection to PTR record"),
+ "ptr_redir_zone": _("Zone found: ${zone}"),
+ "ptr_redir_zone_err": _("Target reverse zone not found."),
+ "ptr_redir_zones": _("Fetching DNS zones."),
+ "ptr_redir_zones_err": _("An error occurd while fetching dns zones."),
"redirection_dnszone": _("You will be redirected to DNS Zone."),
"standard": _("Standard Record Types"),
"title": _("Records for DNS Zone"),