On 12/19/2011 05:12 PM, Petr Vobornik wrote:
On 12/19/2011 04:44 PM, Petr Vobornik wrote:
[Web UI]
Added support of parsing and validation of IPv4 and IPv6 addresses.
Class IP.address can also create reverse address from any valid IPv4 or
IPv6 address.
This functionality is prerequisite for tickets:
https://fedorahosted.org/freeipa/ticket/1466
https://fedorahosted.org/freeipa/ticket/1975
Ticket: https://fedorahosted.org/freeipa/ticket/1466
Self NACK
Getting reverse addresses is not functional for integer IPv4 input.
Updated patch will follow tomorrow.
Fixed.
Attached new patch.
--
Petr Vobornik
From 5c64802a363f1361d5d6a23446238e9c1eacbbdf Mon Sep 17 00:00:00 2001
From: Petr Vobornik pvobo...@redhat.com
Date: Mon, 19 Dec 2011 16:14:04 +0100
Subject: [PATCH] Parsing of IPv4 and IPv6 addresses
Added support of parsing and validation of IPv4 and IPv6 addresses.
Class IP.address can also create reverse address from any valid IPv4 or IPv6 address.
This functionality is needed for tickets:
https://fedorahosted.org/freeipa/ticket/1466
https://fedorahosted.org/freeipa/ticket/1975
---
install/ui/Makefile.am |1 +
install/ui/ip.js | 366 ++
install/ui/jsl.conf |1 +
install/ui/test/all_tests.html |4 +-
install/ui/test/details_tests.js |1 -
install/ui/test/ip_tests.html| 18 ++
install/ui/test/ip_tests.js | 217 ++
install/ui/test/jsl.conf |4 +-
8 files changed, 609 insertions(+), 3 deletions(-)
create mode 100644 install/ui/ip.js
create mode 100644 install/ui/test/ip_tests.html
create mode 100644 install/ui/test/ip_tests.js
diff --git a/install/ui/Makefile.am b/install/ui/Makefile.am
index 835888d94e65704ae12d4098ead210bfb195ce85..b316c391c184874c6dd6cb6d855c2769de2b259d 100644
--- a/install/ui/Makefile.am
+++ b/install/ui/Makefile.am
@@ -30,6 +30,7 @@ app_DATA =\
hostgroup.js \
index.html \
ipa.css\
+ ip.js\
ipa.js\
jquery-ui.css \
jquery-ui.js \
diff --git a/install/ui/ip.js b/install/ui/ip.js
new file mode 100644
index ..9ba39416aba660024071e3eb604470ddcfd845d8
--- /dev/null
+++ b/install/ui/ip.js
@@ -0,0 +1,366 @@
+/* Authors:
+ *Petr Vobornik pvobo...@redhat.com
+ *
+ * Copyright (C) 2010 Red Hat
+ * see file 'COPYING' for use and warranty information
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/.
+ */
+
+var IP = {};
+
+IP.address = function(spec) {
+
+spec = spec || {};
+
+var that = {};
+
+that.input = spec.address || '';
+
+that.type;
+that.parts = [];
+that.reverse_address = '';
+that.only_decimal = spec.only_decimal !== undefined? spec.only_decimal :
+false ; //for parsing IPv4 address
+
+that.parse = function() {
+
+that.get_type();
+
+if (that.type === 'v4-quads') {
+return that.parse_v4_quads();
+} else if (that.type === 'v4-int') {
+return that.parse_v4_int();
+} else if (that.type === 'v6') {
+return that.parse_v6();
+}
+
+that.set_error('not an ip address');
+return false;
+};
+
+that.get_type = function() {
+
+if (that.input.indexOf(':') -1) that.type = 'v6';
+else if (that.input.indexOf('.') -1) that.type = 'v4-quads';
+else that.type = 'v4-int';
+
+return that.type;
+};
+
+that.parse_v4_int = function() {
+
+var part = { value: that.input };
+if(!that.is_part_valid_v4(part, 32, that.only_decimal)) return false;
+
+that.parts = [];
+that.make_quads(part.decimal_value, that.parts);
+
+that.valid = true;
+return true;
+};
+
+that.parse_v4_quads = function() {
+
+that.parts = that.input.split('.');
+
+if (that.parts.length !== 4) {
+return that.set_error('invalid number of parts');
+}
+
+for (var i=0; i4; i++) {
+
+var part = { value: that.parts[i] };
+
+if (!that.is_part_valid_v4(part, 8, that.only_decimal)) {
+return false;
+}
+that.parts[i] = part.decimal_value;
+}
+
+that.valid = true;
+return true;
+};
+
+that.parse_v6 = function() {
+
+that.parts =