summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--install/ui/dns.js60
-rw-r--r--install/ui/index.html1
-rw-r--r--install/ui/test/data/ipa_init.json3
-rw-r--r--ipalib/plugins/internal.py3
4 files changed, 64 insertions, 3 deletions
diff --git a/install/ui/dns.js b/install/ui/dns.js
index 4853a9445..f4f93389b 100644
--- a/install/ui/dns.js
+++ b/install/ui/dns.js
@@ -1,5 +1,6 @@
/*jsl:import ipa.js */
/*jsl:import search.js */
+/*jsl:import net.js */
/* Authors:
* Adam Young <ayoung@redhat.com>
@@ -21,7 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/* REQUIRES: ipa.js, details.js, search.js, add.js, facet.js, entity.js, widget.js */
+/* REQUIRES: ipa.js, details.js, search.js, add.js, facet.js, entity.js,
+ * net.js, widget.js */
IPA.dns = {};
@@ -526,13 +528,15 @@ IPA.dns.record_entity = function(spec) {
type: 'multivalued',
name: 'arecord',
metadata: { primary_key: false },
- label: 'A'
+ label: 'A',
+ validators: [ IPA.ip_v4_address_validator() ]
},
{
type: 'multivalued',
name: 'aaaarecord',
metadata: { primary_key: false },
- label: 'AAAA'
+ label: 'AAAA',
+ validators: [ IPA.ip_v6_address_validator() ]
},
{
type: 'multivalued',
@@ -824,5 +828,55 @@ IPA.dnsrecord_get_delete_values = function() {
return value_array;
};
+IPA.ip_address_validator = function(spec) {
+
+ var that = IPA.validator(spec);
+
+ that.address_type = spec.address_type;
+ that.message = spec.message || IPA.messages.widget.validation.ip_address;
+
+ that.validate = function(value) {
+
+ var address = NET.ip_address(value);
+
+ if (!address.valid || !that.is_type_match(address.type)) {
+ return {
+ valid: false,
+ message: that.message
+ };
+ }
+
+ return { valid: true };
+ };
+
+ that.is_type_match = function(net_type) {
+
+ return (!that.address_type ||
+
+ (that.address_type === 'IPv4' &&
+ (net_type === 'v4-quads' || net_type === 'v4-int')) ||
+
+ (that.address_type === 'IPv6' && net_type === 'v6'));
+ };
+
+ return that;
+};
+
+IPA.ip_v4_address_validator = function(spec) {
+
+ spec = spec || {};
+ spec.address_type = 'IPv4';
+ spec.message = IPA.messages.widget.validation.ip_v4_address;
+ return IPA.ip_address_validator(spec);
+};
+
+IPA.ip_v6_address_validator = function(spec) {
+
+ spec = spec || {};
+ spec.address_type = 'IPv6';
+ spec.message = IPA.messages.widget.validation.ip_v6_address;
+ return IPA.ip_address_validator(spec);
+};
+
IPA.register('dnszone', IPA.dns.zone_entity);
IPA.register('dnsrecord', IPA.dns.record_entity);
diff --git a/install/ui/index.html b/install/ui/index.html
index 5c0ebdbb9..6239debab 100644
--- a/install/ui/index.html
+++ b/install/ui/index.html
@@ -10,6 +10,7 @@
<script type="text/javascript" src="jquery.ba-bbq.js"></script>
<script type="text/javascript" src="jquery.ordered-map.js"></script>
<script type="text/javascript" src="browser.js"></script>
+ <script type="text/javascript" src="net.js"></script>
<script type="text/javascript" src="ipa.js"></script>
<script type="text/javascript" src="widget.js"></script>
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index a5ef756eb..77af2f8f2 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -376,6 +376,9 @@
"validation": {
"error": "Text does not match field pattern",
"integer": "Must be an integer",
+ "ip_address": "Not a valid IP address",
+ "ip_v4_address": "Not a valid IPv4 address",
+ "ip_v6_address": "Not a valid IPv6 address",
"max_value": "Maximum value is ${value}",
"min_value": "Minimum value is ${value}",
"required": "Required field"
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index e4308140b..3eed9ec56 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -515,6 +515,9 @@ class i18n_messages(Command):
"validation": {
"error": _("Text does not match field pattern"),
"integer": _("Must be an integer"),
+ "ip_address": _('Not a valid IP address'),
+ "ip_v4_address": _('Not a valid IPv4 address'),
+ "ip_v6_address": _('Not a valid IPv6 address'),
"max_value": _("Maximum value is ${value}"),
"min_value": _("Minimum value is ${value}"),
"required": _("Required field"),