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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d269dedfbb6ec6eae3a77491cc5ec7ca6241f388f2658964541cdd3983b8298
4
- data.tar.gz: 6f24d23c8d06430b3605aad90522e08818cd18fd6c71c5fe90823cdc9483c81e
3
+ metadata.gz: 0a915af429fe2492f17bc767c86767e38d37a674af6206fb3b2c0a76e4cad620
4
+ data.tar.gz: bf4cc3a1e438b752c9c99fee5f91c85abd38de95dac947c2382e2f9825b51467
5
5
  SHA512:
6
- metadata.gz: a63f715b281101a6f61029da3e2bcf5db4d47a537af562507b0184d6c6755eed436afed729c31cc95255bf064cbe9f487917c96d78199bbee25e6d4189469951
7
- data.tar.gz: 77c62a24c3c81067dd0288ad606b732e0f112d0d1710b326be9e894aa72a93db4cb0a188c93b54ada728c2eeb0cf7378fb7033e13982c9a0932414c8455d2703
6
+ metadata.gz: 5612ef5474aa397132527588d289d9d1eba4f8954b92553e32fd5b856f2bd5441ba09d89d1bf12a0f220c602dcd2e73de2d6e360b6177b162d57adc2726442c9
7
+ data.tar.gz: c3b546cc177a3364b1b513f4274c1521aa1669bb17b142eb453ba73251f1e3458e7b9d1703b692ef275a474821ce7375e387155f63e3e7d5d7c9c42e1c50a150
data/CHANGELOG.org CHANGED
@@ -2,6 +2,10 @@
2
2
  #+AUTHOR: Adolfo Villafiorita
3
3
  #+STARTUP: showall
4
4
 
5
+ * 1.6.1
6
+
7
+ - Country DB now stores country name.
8
+
5
9
  * 1.6.0
6
10
 
7
11
  - [User] New output format =ufw= generates directives to blacklist IPs
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
- filename = args[:filename]
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 "Error. Could not find: #{filename}"
17
- puts
18
- puts 'I see the following files:'
19
- puts Dir.glob("ip_locations/dbip-country-lite*").map { |x| "- #{x}\n" }
20
- puts
21
- puts "1. Download (if necessary) a more recent version from: https://db-ip.com/db/download/ip-to-country-lite"
22
- puts "2. Save downloaded file to ip_locations/"
23
- puts "3. Relaunch with YYYY-MM"
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
@@ -16,18 +16,26 @@ module LogSense
16
16
  from_ip_n INTEGER,
17
17
  from_ip TEXT,
18
18
  to_ip TEXT,
19
- country_code TEXT
19
+ country TEXT
20
20
  )"
21
21
 
22
22
  ins = db.prepare "INSERT INTO ip_location(
23
- from_ip_n, from_ip, to_ip, country_code)
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
- ins.execute(ip.to_i, row[0], row[1], row[2])
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
- country_code = result_set.map { |x| x[3] }[0]
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
 
@@ -1,3 +1,3 @@
1
1
  module LogSense
2
- VERSION = "1.6.0"
2
+ VERSION = "1.6.1"
3
3
  end
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.0
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: 2022-12-18 00:00:00.000000000 Z
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.3.7
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.