log_sense 1.6.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.org +4 -0
- data/Rakefile +29 -9
- data/ip_locations/dbip-country-lite.sqlite3 +0 -0
- data/lib/log_sense/ip_locator.rb +12 -7
- data/lib/log_sense/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a915af429fe2492f17bc767c86767e38d37a674af6206fb3b2c0a76e4cad620
|
4
|
+
data.tar.gz: bf4cc3a1e438b752c9c99fee5f91c85abd38de95dac947c2382e2f9825b51467
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5612ef5474aa397132527588d289d9d1eba4f8954b92553e32fd5b856f2bd5441ba09d89d1bf12a0f220c602dcd2e73de2d6e360b6177b162d57adc2726442c9
|
7
|
+
data.tar.gz: c3b546cc177a3364b1b513f4274c1521aa1669bb17b142eb453ba73251f1e3458e7b9d1703b692ef275a474821ce7375e387155f63e3e7d5d7c9c42e1c50a150
|
data/CHANGELOG.org
CHANGED
data/Rakefile
CHANGED
@@ -10,17 +10,37 @@ require_relative './lib/log_sense/ip_locator.rb'
|
|
10
10
|
|
11
11
|
desc "Convert Geolocation DB to sqlite"
|
12
12
|
task :dbip, [:filename] do |tasks, args|
|
13
|
-
|
13
|
+
filename_or_yyyy_mm = args[:filename]
|
14
|
+
|
15
|
+
filename = if /\d{4}-\d{2}/.match(filename_or_yyyy_mm)
|
16
|
+
"ip_locations/dbip-country-lite-#{filename_or_yyyy_mm}.csv"
|
17
|
+
else
|
18
|
+
filename_or_yyyy_mm
|
19
|
+
end
|
20
|
+
|
21
|
+
# if the filename has a .gz extension or a gzipped version of the file
|
22
|
+
# exists, gunzip it
|
23
|
+
if File.extname(filename) == ".gz" || File.exist?("#{filename}.gz")
|
24
|
+
system "gunzip #{filename}.gz"
|
25
|
+
end
|
14
26
|
|
15
27
|
if !File.exist? filename
|
16
|
-
puts
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
puts <<-EOS
|
29
|
+
Error. Could not find: #{filename}
|
30
|
+
|
31
|
+
I see the following files:
|
32
|
+
|
33
|
+
#{Dir.glob("ip_locations/dbip-country-lite*").map { |x| "- #{x}" }.join("\n")}
|
34
|
+
|
35
|
+
1. Download (if necessary) a more recent version from: https://db-ip.com/db/download/ip-to-country-lite
|
36
|
+
2. Save downloaded file to ip_locations/
|
37
|
+
3. Relaunch with YYYY-MM (will build: dbip-country-lite-YYYY-MM.csv)
|
38
|
+
or with filename.
|
39
|
+
|
40
|
+
Remark. If the filename has the extension .gz or if the
|
41
|
+
filename does not exist, but a file with the same name and .gz extension
|
42
|
+
exists, it is gunzipped first
|
43
|
+
EOS
|
24
44
|
|
25
45
|
exit
|
26
46
|
else
|
Binary file
|
data/lib/log_sense/ip_locator.rb
CHANGED
@@ -16,18 +16,26 @@ module LogSense
|
|
16
16
|
from_ip_n INTEGER,
|
17
17
|
from_ip TEXT,
|
18
18
|
to_ip TEXT,
|
19
|
-
|
19
|
+
country TEXT
|
20
20
|
)"
|
21
21
|
|
22
22
|
ins = db.prepare "INSERT INTO ip_location(
|
23
|
-
from_ip_n, from_ip, to_ip,
|
23
|
+
from_ip_n, from_ip, to_ip, country)
|
24
24
|
values (?, ?, ?, ?)"
|
25
25
|
CSV.foreach(db_location) do |row|
|
26
26
|
# skip ip v6 addresses
|
27
27
|
next if row[0].include?(":")
|
28
28
|
|
29
29
|
ip = IPAddr.new row[0]
|
30
|
-
|
30
|
+
country_code = row[2]
|
31
|
+
|
32
|
+
begin
|
33
|
+
country = IsoCountryCodes.find(country_code).name
|
34
|
+
rescue IsoCountryCodes::UnknownCodeError
|
35
|
+
country = country_code
|
36
|
+
end
|
37
|
+
|
38
|
+
ins.execute(ip.to_i, row[0], row[1], country)
|
31
39
|
end
|
32
40
|
|
33
41
|
# persist to file
|
@@ -55,12 +63,9 @@ module LogSense
|
|
55
63
|
begin
|
56
64
|
ip_n = IPAddr.new(ip).to_i
|
57
65
|
result_set = query.execute ip_n
|
58
|
-
|
59
|
-
IsoCountryCodes.find(country_code).name
|
66
|
+
result_set.map { |x| x[3] }[0]
|
60
67
|
rescue IPAddr::InvalidAddressError
|
61
68
|
"INVALID IP"
|
62
|
-
rescue IsoCountryCodes::UnknownCodeError
|
63
|
-
country_code
|
64
69
|
end
|
65
70
|
end
|
66
71
|
|
data/lib/log_sense/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log_sense
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adolfo Villafiorita
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: browser
|
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
188
|
- !ruby/object:Gem::Version
|
189
189
|
version: '0'
|
190
190
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
191
|
+
rubygems_version: 3.4.21
|
192
192
|
signing_key:
|
193
193
|
specification_version: 4
|
194
194
|
summary: Generate analytics for Apache and Rails log file.
|