ipaddrjs-rails 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/ipaddrjs-rails.gemspec +24 -0
- data/lib/ipaddrjs/rails.rb +7 -0
- data/lib/ipaddrjs/rails/engine.rb +6 -0
- data/lib/ipaddrjs/rails/version.rb +5 -0
- data/vendor/assets/javascripts/ipaddr.js +526 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 78b0857007f0f39ee23bc6bd2dd7012ec859a88b
|
4
|
+
data.tar.gz: 9d7c2eaae6467542272d368764eb76e9d3ec2514
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1873c8153cd7eb167ad71ea18562edd86e095fedbd10d301415110da584455ed9e87c366fda3af58c8b60f95e176c7d08db5b6ec8bdb30adc4eec681a4718b6a
|
7
|
+
data.tar.gz: ad7b29c7384695d376ff404311ab0b18a75f1951d5d3c62db3079804b1e5e0e30a98eefe5d62f11dfd7742ab9f6e4e7954efb85ceabe066a8849e2987f00fe7b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2011 Peter Zotov <whitequark@whitequark.org>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Ipaddrjs::Rails
|
2
|
+
|
3
|
+
https://github.com/whitequark/ipaddr.js packaged as a rails gem asset.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ipaddrjs-rails'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ipaddrjs-rails
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The ipaddr javascript files will be added to the asset pipeline and available for you to use. If they're not already in `app/assets/javascripts/application.js` by default, add these lines:
|
24
|
+
|
25
|
+
```js
|
26
|
+
//= require ipaddr
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/timogoebel/ipaddrjs-rails.
|
32
|
+
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ipaddrjs/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ipaddrjs-rails"
|
8
|
+
spec.version = Ipaddrjs::Rails::VERSION
|
9
|
+
spec.authors = ["Peter Zotov"]
|
10
|
+
spec.email = ["whitequark@whitequark.org"]
|
11
|
+
|
12
|
+
spec.summary = %q{A library for manipulating IPv4 and IPv6 addresses in JavaScript. For Rails.}
|
13
|
+
spec.description = %q{A library for manipulating IPv4 and IPv6 addresses in JavaScript. For Rails.}
|
14
|
+
spec.homepage = "https://github.com/timogoebel/ipaddrjs-rails"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
@@ -0,0 +1,526 @@
|
|
1
|
+
(function() {
|
2
|
+
var expandIPv6, ipaddr, ipv4Part, ipv4Regexes, ipv6Part, ipv6Regexes, matchCIDR, root;
|
3
|
+
|
4
|
+
ipaddr = {};
|
5
|
+
|
6
|
+
root = this;
|
7
|
+
|
8
|
+
if ((typeof module !== "undefined" && module !== null) && module.exports) {
|
9
|
+
module.exports = ipaddr;
|
10
|
+
} else {
|
11
|
+
root['ipaddr'] = ipaddr;
|
12
|
+
}
|
13
|
+
|
14
|
+
matchCIDR = function(first, second, partSize, cidrBits) {
|
15
|
+
var part, shift;
|
16
|
+
if (first.length !== second.length) {
|
17
|
+
throw new Error("ipaddr: cannot match CIDR for objects with different lengths");
|
18
|
+
}
|
19
|
+
part = 0;
|
20
|
+
while (cidrBits > 0) {
|
21
|
+
shift = partSize - cidrBits;
|
22
|
+
if (shift < 0) {
|
23
|
+
shift = 0;
|
24
|
+
}
|
25
|
+
if (first[part] >> shift !== second[part] >> shift) {
|
26
|
+
return false;
|
27
|
+
}
|
28
|
+
cidrBits -= partSize;
|
29
|
+
part += 1;
|
30
|
+
}
|
31
|
+
return true;
|
32
|
+
};
|
33
|
+
|
34
|
+
ipaddr.subnetMatch = function(address, rangeList, defaultName) {
|
35
|
+
var rangeName, rangeSubnets, subnet, _i, _len;
|
36
|
+
if (defaultName == null) {
|
37
|
+
defaultName = 'unicast';
|
38
|
+
}
|
39
|
+
for (rangeName in rangeList) {
|
40
|
+
rangeSubnets = rangeList[rangeName];
|
41
|
+
if (rangeSubnets[0] && !(rangeSubnets[0] instanceof Array)) {
|
42
|
+
rangeSubnets = [rangeSubnets];
|
43
|
+
}
|
44
|
+
for (_i = 0, _len = rangeSubnets.length; _i < _len; _i++) {
|
45
|
+
subnet = rangeSubnets[_i];
|
46
|
+
if (address.match.apply(address, subnet)) {
|
47
|
+
return rangeName;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
return defaultName;
|
52
|
+
};
|
53
|
+
|
54
|
+
ipaddr.IPv4 = (function() {
|
55
|
+
function IPv4(octets) {
|
56
|
+
var octet, _i, _len;
|
57
|
+
if (octets.length !== 4) {
|
58
|
+
throw new Error("ipaddr: ipv4 octet count should be 4");
|
59
|
+
}
|
60
|
+
for (_i = 0, _len = octets.length; _i < _len; _i++) {
|
61
|
+
octet = octets[_i];
|
62
|
+
if (!((0 <= octet && octet <= 255))) {
|
63
|
+
throw new Error("ipaddr: ipv4 octet should fit in 8 bits");
|
64
|
+
}
|
65
|
+
}
|
66
|
+
this.octets = octets;
|
67
|
+
}
|
68
|
+
|
69
|
+
IPv4.prototype.kind = function() {
|
70
|
+
return 'ipv4';
|
71
|
+
};
|
72
|
+
|
73
|
+
IPv4.prototype.toString = function() {
|
74
|
+
return this.octets.join(".");
|
75
|
+
};
|
76
|
+
|
77
|
+
IPv4.prototype.toByteArray = function() {
|
78
|
+
return this.octets.slice(0);
|
79
|
+
};
|
80
|
+
|
81
|
+
IPv4.prototype.match = function(other, cidrRange) {
|
82
|
+
var _ref;
|
83
|
+
if (cidrRange === void 0) {
|
84
|
+
_ref = other, other = _ref[0], cidrRange = _ref[1];
|
85
|
+
}
|
86
|
+
if (other.kind() !== 'ipv4') {
|
87
|
+
throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");
|
88
|
+
}
|
89
|
+
return matchCIDR(this.octets, other.octets, 8, cidrRange);
|
90
|
+
};
|
91
|
+
|
92
|
+
IPv4.prototype.SpecialRanges = {
|
93
|
+
unspecified: [[new IPv4([0, 0, 0, 0]), 8]],
|
94
|
+
broadcast: [[new IPv4([255, 255, 255, 255]), 32]],
|
95
|
+
multicast: [[new IPv4([224, 0, 0, 0]), 4]],
|
96
|
+
linkLocal: [[new IPv4([169, 254, 0, 0]), 16]],
|
97
|
+
loopback: [[new IPv4([127, 0, 0, 0]), 8]],
|
98
|
+
"private": [[new IPv4([10, 0, 0, 0]), 8], [new IPv4([172, 16, 0, 0]), 12], [new IPv4([192, 168, 0, 0]), 16]],
|
99
|
+
reserved: [[new IPv4([192, 0, 0, 0]), 24], [new IPv4([192, 0, 2, 0]), 24], [new IPv4([192, 88, 99, 0]), 24], [new IPv4([198, 51, 100, 0]), 24], [new IPv4([203, 0, 113, 0]), 24], [new IPv4([240, 0, 0, 0]), 4]]
|
100
|
+
};
|
101
|
+
|
102
|
+
IPv4.prototype.range = function() {
|
103
|
+
return ipaddr.subnetMatch(this, this.SpecialRanges);
|
104
|
+
};
|
105
|
+
|
106
|
+
IPv4.prototype.toIPv4MappedAddress = function() {
|
107
|
+
return ipaddr.IPv6.parse("::ffff:" + (this.toString()));
|
108
|
+
};
|
109
|
+
|
110
|
+
IPv4.prototype.prefixLengthFromSubnetMask = function() {
|
111
|
+
var cidr, i, octet, stop, zeros, zerotable, _i;
|
112
|
+
zerotable = {
|
113
|
+
0: 8,
|
114
|
+
128: 7,
|
115
|
+
192: 6,
|
116
|
+
224: 5,
|
117
|
+
240: 4,
|
118
|
+
248: 3,
|
119
|
+
252: 2,
|
120
|
+
254: 1,
|
121
|
+
255: 0
|
122
|
+
};
|
123
|
+
cidr = 0;
|
124
|
+
stop = false;
|
125
|
+
for (i = _i = 3; _i >= 0; i = _i += -1) {
|
126
|
+
octet = this.octets[i];
|
127
|
+
if (octet in zerotable) {
|
128
|
+
zeros = zerotable[octet];
|
129
|
+
if (stop && zeros !== 0) {
|
130
|
+
return null;
|
131
|
+
}
|
132
|
+
if (zeros !== 8) {
|
133
|
+
stop = true;
|
134
|
+
}
|
135
|
+
cidr += zeros;
|
136
|
+
} else {
|
137
|
+
return null;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
return 32 - cidr;
|
141
|
+
};
|
142
|
+
|
143
|
+
return IPv4;
|
144
|
+
|
145
|
+
})();
|
146
|
+
|
147
|
+
ipv4Part = "(0?\\d+|0x[a-f0-9]+)";
|
148
|
+
|
149
|
+
ipv4Regexes = {
|
150
|
+
fourOctet: new RegExp("^" + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "$", 'i'),
|
151
|
+
longValue: new RegExp("^" + ipv4Part + "$", 'i')
|
152
|
+
};
|
153
|
+
|
154
|
+
ipaddr.IPv4.parser = function(string) {
|
155
|
+
var match, parseIntAuto, part, shift, value;
|
156
|
+
parseIntAuto = function(string) {
|
157
|
+
if (string[0] === "0" && string[1] !== "x") {
|
158
|
+
return parseInt(string, 8);
|
159
|
+
} else {
|
160
|
+
return parseInt(string);
|
161
|
+
}
|
162
|
+
};
|
163
|
+
if (match = string.match(ipv4Regexes.fourOctet)) {
|
164
|
+
return (function() {
|
165
|
+
var _i, _len, _ref, _results;
|
166
|
+
_ref = match.slice(1, 6);
|
167
|
+
_results = [];
|
168
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
169
|
+
part = _ref[_i];
|
170
|
+
_results.push(parseIntAuto(part));
|
171
|
+
}
|
172
|
+
return _results;
|
173
|
+
})();
|
174
|
+
} else if (match = string.match(ipv4Regexes.longValue)) {
|
175
|
+
value = parseIntAuto(match[1]);
|
176
|
+
if (value > 0xffffffff || value < 0) {
|
177
|
+
throw new Error("ipaddr: address outside defined range");
|
178
|
+
}
|
179
|
+
return ((function() {
|
180
|
+
var _i, _results;
|
181
|
+
_results = [];
|
182
|
+
for (shift = _i = 0; _i <= 24; shift = _i += 8) {
|
183
|
+
_results.push((value >> shift) & 0xff);
|
184
|
+
}
|
185
|
+
return _results;
|
186
|
+
})()).reverse();
|
187
|
+
} else {
|
188
|
+
return null;
|
189
|
+
}
|
190
|
+
};
|
191
|
+
|
192
|
+
ipaddr.IPv6 = (function() {
|
193
|
+
function IPv6(parts) {
|
194
|
+
var i, part, _i, _j, _len, _ref;
|
195
|
+
if (parts.length === 16) {
|
196
|
+
this.parts = [];
|
197
|
+
for (i = _i = 0; _i <= 14; i = _i += 2) {
|
198
|
+
this.parts.push((parts[i] << 8) | parts[i + 1]);
|
199
|
+
}
|
200
|
+
} else if (parts.length === 8) {
|
201
|
+
this.parts = parts;
|
202
|
+
} else {
|
203
|
+
throw new Error("ipaddr: ipv6 part count should be 8 or 16");
|
204
|
+
}
|
205
|
+
_ref = this.parts;
|
206
|
+
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
|
207
|
+
part = _ref[_j];
|
208
|
+
if (!((0 <= part && part <= 0xffff))) {
|
209
|
+
throw new Error("ipaddr: ipv6 part should fit in 16 bits");
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
IPv6.prototype.kind = function() {
|
215
|
+
return 'ipv6';
|
216
|
+
};
|
217
|
+
|
218
|
+
IPv6.prototype.toString = function() {
|
219
|
+
var compactStringParts, part, pushPart, state, stringParts, _i, _len;
|
220
|
+
stringParts = (function() {
|
221
|
+
var _i, _len, _ref, _results;
|
222
|
+
_ref = this.parts;
|
223
|
+
_results = [];
|
224
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
225
|
+
part = _ref[_i];
|
226
|
+
_results.push(part.toString(16));
|
227
|
+
}
|
228
|
+
return _results;
|
229
|
+
}).call(this);
|
230
|
+
compactStringParts = [];
|
231
|
+
pushPart = function(part) {
|
232
|
+
return compactStringParts.push(part);
|
233
|
+
};
|
234
|
+
state = 0;
|
235
|
+
for (_i = 0, _len = stringParts.length; _i < _len; _i++) {
|
236
|
+
part = stringParts[_i];
|
237
|
+
switch (state) {
|
238
|
+
case 0:
|
239
|
+
if (part === '0') {
|
240
|
+
pushPart('');
|
241
|
+
} else {
|
242
|
+
pushPart(part);
|
243
|
+
}
|
244
|
+
state = 1;
|
245
|
+
break;
|
246
|
+
case 1:
|
247
|
+
if (part === '0') {
|
248
|
+
state = 2;
|
249
|
+
} else {
|
250
|
+
pushPart(part);
|
251
|
+
}
|
252
|
+
break;
|
253
|
+
case 2:
|
254
|
+
if (part !== '0') {
|
255
|
+
pushPart('');
|
256
|
+
pushPart(part);
|
257
|
+
state = 3;
|
258
|
+
}
|
259
|
+
break;
|
260
|
+
case 3:
|
261
|
+
pushPart(part);
|
262
|
+
}
|
263
|
+
}
|
264
|
+
if (state === 2) {
|
265
|
+
pushPart('');
|
266
|
+
pushPart('');
|
267
|
+
}
|
268
|
+
return compactStringParts.join(":");
|
269
|
+
};
|
270
|
+
|
271
|
+
IPv6.prototype.toByteArray = function() {
|
272
|
+
var bytes, part, _i, _len, _ref;
|
273
|
+
bytes = [];
|
274
|
+
_ref = this.parts;
|
275
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
276
|
+
part = _ref[_i];
|
277
|
+
bytes.push(part >> 8);
|
278
|
+
bytes.push(part & 0xff);
|
279
|
+
}
|
280
|
+
return bytes;
|
281
|
+
};
|
282
|
+
|
283
|
+
IPv6.prototype.toNormalizedString = function() {
|
284
|
+
var part;
|
285
|
+
return ((function() {
|
286
|
+
var _i, _len, _ref, _results;
|
287
|
+
_ref = this.parts;
|
288
|
+
_results = [];
|
289
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
290
|
+
part = _ref[_i];
|
291
|
+
_results.push(part.toString(16));
|
292
|
+
}
|
293
|
+
return _results;
|
294
|
+
}).call(this)).join(":");
|
295
|
+
};
|
296
|
+
|
297
|
+
IPv6.prototype.match = function(other, cidrRange) {
|
298
|
+
var _ref;
|
299
|
+
if (cidrRange === void 0) {
|
300
|
+
_ref = other, other = _ref[0], cidrRange = _ref[1];
|
301
|
+
}
|
302
|
+
if (other.kind() !== 'ipv6') {
|
303
|
+
throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");
|
304
|
+
}
|
305
|
+
return matchCIDR(this.parts, other.parts, 16, cidrRange);
|
306
|
+
};
|
307
|
+
|
308
|
+
IPv6.prototype.SpecialRanges = {
|
309
|
+
unspecified: [new IPv6([0, 0, 0, 0, 0, 0, 0, 0]), 128],
|
310
|
+
linkLocal: [new IPv6([0xfe80, 0, 0, 0, 0, 0, 0, 0]), 10],
|
311
|
+
multicast: [new IPv6([0xff00, 0, 0, 0, 0, 0, 0, 0]), 8],
|
312
|
+
loopback: [new IPv6([0, 0, 0, 0, 0, 0, 0, 1]), 128],
|
313
|
+
uniqueLocal: [new IPv6([0xfc00, 0, 0, 0, 0, 0, 0, 0]), 7],
|
314
|
+
ipv4Mapped: [new IPv6([0, 0, 0, 0, 0, 0xffff, 0, 0]), 96],
|
315
|
+
rfc6145: [new IPv6([0, 0, 0, 0, 0xffff, 0, 0, 0]), 96],
|
316
|
+
rfc6052: [new IPv6([0x64, 0xff9b, 0, 0, 0, 0, 0, 0]), 96],
|
317
|
+
'6to4': [new IPv6([0x2002, 0, 0, 0, 0, 0, 0, 0]), 16],
|
318
|
+
teredo: [new IPv6([0x2001, 0, 0, 0, 0, 0, 0, 0]), 32],
|
319
|
+
reserved: [[new IPv6([0x2001, 0xdb8, 0, 0, 0, 0, 0, 0]), 32]]
|
320
|
+
};
|
321
|
+
|
322
|
+
IPv6.prototype.range = function() {
|
323
|
+
return ipaddr.subnetMatch(this, this.SpecialRanges);
|
324
|
+
};
|
325
|
+
|
326
|
+
IPv6.prototype.isIPv4MappedAddress = function() {
|
327
|
+
return this.range() === 'ipv4Mapped';
|
328
|
+
};
|
329
|
+
|
330
|
+
IPv6.prototype.toIPv4Address = function() {
|
331
|
+
var high, low, _ref;
|
332
|
+
if (!this.isIPv4MappedAddress()) {
|
333
|
+
throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");
|
334
|
+
}
|
335
|
+
_ref = this.parts.slice(-2), high = _ref[0], low = _ref[1];
|
336
|
+
return new ipaddr.IPv4([high >> 8, high & 0xff, low >> 8, low & 0xff]);
|
337
|
+
};
|
338
|
+
|
339
|
+
return IPv6;
|
340
|
+
|
341
|
+
})();
|
342
|
+
|
343
|
+
ipv6Part = "(?:[0-9a-f]+::?)+";
|
344
|
+
|
345
|
+
ipv6Regexes = {
|
346
|
+
"native": new RegExp("^(::)?(" + ipv6Part + ")?([0-9a-f]+)?(::)?$", 'i'),
|
347
|
+
transitional: new RegExp(("^((?:" + ipv6Part + ")|(?:::)(?:" + ipv6Part + ")?)") + ("" + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "$"), 'i')
|
348
|
+
};
|
349
|
+
|
350
|
+
expandIPv6 = function(string, parts) {
|
351
|
+
var colonCount, lastColon, part, replacement, replacementCount;
|
352
|
+
if (string.indexOf('::') !== string.lastIndexOf('::')) {
|
353
|
+
return null;
|
354
|
+
}
|
355
|
+
colonCount = 0;
|
356
|
+
lastColon = -1;
|
357
|
+
while ((lastColon = string.indexOf(':', lastColon + 1)) >= 0) {
|
358
|
+
colonCount++;
|
359
|
+
}
|
360
|
+
if (string.substr(0, 2) === '::') {
|
361
|
+
colonCount--;
|
362
|
+
}
|
363
|
+
if (string.substr(-2, 2) === '::') {
|
364
|
+
colonCount--;
|
365
|
+
}
|
366
|
+
if (colonCount > parts) {
|
367
|
+
return null;
|
368
|
+
}
|
369
|
+
replacementCount = parts - colonCount;
|
370
|
+
replacement = ':';
|
371
|
+
while (replacementCount--) {
|
372
|
+
replacement += '0:';
|
373
|
+
}
|
374
|
+
string = string.replace('::', replacement);
|
375
|
+
if (string[0] === ':') {
|
376
|
+
string = string.slice(1);
|
377
|
+
}
|
378
|
+
if (string[string.length - 1] === ':') {
|
379
|
+
string = string.slice(0, -1);
|
380
|
+
}
|
381
|
+
return (function() {
|
382
|
+
var _i, _len, _ref, _results;
|
383
|
+
_ref = string.split(":");
|
384
|
+
_results = [];
|
385
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
386
|
+
part = _ref[_i];
|
387
|
+
_results.push(parseInt(part, 16));
|
388
|
+
}
|
389
|
+
return _results;
|
390
|
+
})();
|
391
|
+
};
|
392
|
+
|
393
|
+
ipaddr.IPv6.parser = function(string) {
|
394
|
+
var match, octet, octets, parts, _i, _len;
|
395
|
+
if (string.match(ipv6Regexes['native'])) {
|
396
|
+
return expandIPv6(string, 8);
|
397
|
+
} else if (match = string.match(ipv6Regexes['transitional'])) {
|
398
|
+
parts = expandIPv6(match[1].slice(0, -1), 6);
|
399
|
+
if (parts) {
|
400
|
+
octets = [parseInt(match[2]), parseInt(match[3]), parseInt(match[4]), parseInt(match[5])];
|
401
|
+
for (_i = 0, _len = octets.length; _i < _len; _i++) {
|
402
|
+
octet = octets[_i];
|
403
|
+
if (!((0 <= octet && octet <= 255))) {
|
404
|
+
return null;
|
405
|
+
}
|
406
|
+
}
|
407
|
+
parts.push(octets[0] << 8 | octets[1]);
|
408
|
+
parts.push(octets[2] << 8 | octets[3]);
|
409
|
+
return parts;
|
410
|
+
}
|
411
|
+
}
|
412
|
+
return null;
|
413
|
+
};
|
414
|
+
|
415
|
+
ipaddr.IPv4.isIPv4 = ipaddr.IPv6.isIPv6 = function(string) {
|
416
|
+
return this.parser(string) !== null;
|
417
|
+
};
|
418
|
+
|
419
|
+
ipaddr.IPv4.isValid = function(string) {
|
420
|
+
var e;
|
421
|
+
try {
|
422
|
+
new this(this.parser(string));
|
423
|
+
return true;
|
424
|
+
} catch (_error) {
|
425
|
+
e = _error;
|
426
|
+
return false;
|
427
|
+
}
|
428
|
+
};
|
429
|
+
|
430
|
+
ipaddr.IPv6.isValid = function(string) {
|
431
|
+
var e;
|
432
|
+
if (typeof string === "string" && string.indexOf(":") === -1) {
|
433
|
+
return false;
|
434
|
+
}
|
435
|
+
try {
|
436
|
+
new this(this.parser(string));
|
437
|
+
return true;
|
438
|
+
} catch (_error) {
|
439
|
+
e = _error;
|
440
|
+
return false;
|
441
|
+
}
|
442
|
+
};
|
443
|
+
|
444
|
+
ipaddr.IPv4.parse = ipaddr.IPv6.parse = function(string) {
|
445
|
+
var parts;
|
446
|
+
parts = this.parser(string);
|
447
|
+
if (parts === null) {
|
448
|
+
throw new Error("ipaddr: string is not formatted like ip address");
|
449
|
+
}
|
450
|
+
return new this(parts);
|
451
|
+
};
|
452
|
+
|
453
|
+
ipaddr.IPv4.parseCIDR = function(string) {
|
454
|
+
var maskLength, match;
|
455
|
+
if (match = string.match(/^(.+)\/(\d+)$/)) {
|
456
|
+
maskLength = parseInt(match[2]);
|
457
|
+
if (maskLength >= 0 && maskLength <= 32) {
|
458
|
+
return [this.parse(match[1]), maskLength];
|
459
|
+
}
|
460
|
+
}
|
461
|
+
throw new Error("ipaddr: string is not formatted like an IPv4 CIDR range");
|
462
|
+
};
|
463
|
+
|
464
|
+
ipaddr.IPv6.parseCIDR = function(string) {
|
465
|
+
var maskLength, match;
|
466
|
+
if (match = string.match(/^(.+)\/(\d+)$/)) {
|
467
|
+
maskLength = parseInt(match[2]);
|
468
|
+
if (maskLength >= 0 && maskLength <= 128) {
|
469
|
+
return [this.parse(match[1]), maskLength];
|
470
|
+
}
|
471
|
+
}
|
472
|
+
throw new Error("ipaddr: string is not formatted like an IPv6 CIDR range");
|
473
|
+
};
|
474
|
+
|
475
|
+
ipaddr.isValid = function(string) {
|
476
|
+
return ipaddr.IPv6.isValid(string) || ipaddr.IPv4.isValid(string);
|
477
|
+
};
|
478
|
+
|
479
|
+
ipaddr.parse = function(string) {
|
480
|
+
if (ipaddr.IPv6.isValid(string)) {
|
481
|
+
return ipaddr.IPv6.parse(string);
|
482
|
+
} else if (ipaddr.IPv4.isValid(string)) {
|
483
|
+
return ipaddr.IPv4.parse(string);
|
484
|
+
} else {
|
485
|
+
throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format");
|
486
|
+
}
|
487
|
+
};
|
488
|
+
|
489
|
+
ipaddr.parseCIDR = function(string) {
|
490
|
+
var e;
|
491
|
+
try {
|
492
|
+
return ipaddr.IPv6.parseCIDR(string);
|
493
|
+
} catch (_error) {
|
494
|
+
e = _error;
|
495
|
+
try {
|
496
|
+
return ipaddr.IPv4.parseCIDR(string);
|
497
|
+
} catch (_error) {
|
498
|
+
e = _error;
|
499
|
+
throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format");
|
500
|
+
}
|
501
|
+
}
|
502
|
+
};
|
503
|
+
|
504
|
+
ipaddr.fromByteArray = function(bytes) {
|
505
|
+
var length;
|
506
|
+
length = bytes.length;
|
507
|
+
if (length === 4) {
|
508
|
+
return new ipaddr.IPv4(bytes);
|
509
|
+
} else if (length === 16) {
|
510
|
+
return new ipaddr.IPv6(bytes);
|
511
|
+
} else {
|
512
|
+
throw new Error("ipaddr: the binary input is neither an IPv6 nor IPv4 address");
|
513
|
+
}
|
514
|
+
};
|
515
|
+
|
516
|
+
ipaddr.process = function(string) {
|
517
|
+
var addr;
|
518
|
+
addr = this.parse(string);
|
519
|
+
if (addr.kind() === 'ipv6' && addr.isIPv4MappedAddress()) {
|
520
|
+
return addr.toIPv4Address();
|
521
|
+
} else {
|
522
|
+
return addr;
|
523
|
+
}
|
524
|
+
};
|
525
|
+
|
526
|
+
}).call(this);
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ipaddrjs-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Zotov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: A library for manipulating IPv4 and IPv6 addresses in JavaScript. For
|
42
|
+
Rails.
|
43
|
+
email:
|
44
|
+
- whitequark@whitequark.org
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- ipaddrjs-rails.gemspec
|
55
|
+
- lib/ipaddrjs/rails.rb
|
56
|
+
- lib/ipaddrjs/rails/engine.rb
|
57
|
+
- lib/ipaddrjs/rails/version.rb
|
58
|
+
- vendor/assets/javascripts/ipaddr.js
|
59
|
+
homepage: https://github.com/timogoebel/ipaddrjs-rails
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.5
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: A library for manipulating IPv4 and IPv6 addresses in JavaScript. For Rails.
|
83
|
+
test_files: []
|
84
|
+
has_rdoc:
|