onlylogs 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4856715cec18b6f3e8bca4cd01d3d3de18c4a6286eea249239d4a61423db5107
4
- data.tar.gz: c73534414629768100cf3be121e9a06c8a0cc6841bce942dc02ed31655581432
3
+ metadata.gz: 8f62d620f18a738931a2e17cdad1e30b4027210ffc69fc56d5eb281ea4569885
4
+ data.tar.gz: 3c6cb173191da7ed4a323d398961b7bbb26805e0a543e07de379c4d739eb3f88
5
5
  SHA512:
6
- metadata.gz: d25035152f19a9711cfd0ce93a238162067d1a7a070971b06eebe023569645536a63358c89d0475fd0d4201f1327aac6fc1d9a44168166278dd886564e2a788b
7
- data.tar.gz: 165b9455a35fc3f4e882995ca9201340e65c13ea6074214015b529b04c5add2a828d71e29a479ad127eef1f625f2619932aaf688aba803e57338b68fb3543532
6
+ metadata.gz: 0226e7b4af50b81e0d25d31c01ce3a7f5a66ad809875ba7a0e95fba772934ab2f9991a632091c3960ecfbcdd4bf35067ed197f55c8087dd2da45630e18f68531
7
+ data.tar.gz: 8d13b4f0f9f1b54c0cb9ce72640da13be0b365e951f5aac8b4126dc143b6785f27902c00492a6bc3b4c4357cb0f4ccd19442fdb2e906fe01c13c51fc6bc7c3d1
@@ -2,8 +2,10 @@
2
2
 
3
3
  module Onlylogs
4
4
  class LogsController < ApplicationController
5
+ rescue_from(Onlylogs::ForbiddenPathError) { render plain: "Forbidden: you cannot open this log file.", status: :forbidden }
6
+
5
7
  def index
6
- @available_log_files = Onlylogs.available_log_files
8
+ @available_log_files = Onlylogs.available_log_files.select { |file| authorized?(file.to_s) }
7
9
  @log_file_path = selected_log_file_path
8
10
  end
9
11
 
@@ -31,19 +33,21 @@ module Onlylogs
31
33
 
32
34
  def authorized_log_file_path(encrypted_path)
33
35
  decrypted_path = Onlylogs::SecureFilePath.decrypt(encrypted_path)
34
- if Onlylogs.file_path_permitted?(decrypted_path)
35
- decrypted_path
36
- else
37
- raise Onlylogs::ForbiddenPathError, "File path not allowed"
38
- end
36
+ raise Onlylogs::ForbiddenPathError, "File path not allowed" unless authorized?(decrypted_path)
37
+
38
+ decrypted_path
39
+ end
40
+
41
+ # The same check the queries endpoints and the viewer use: the allow-list, then the host's hook.
42
+ def authorized?(path)
43
+ Onlylogs.file_path_permitted?(path) && Onlylogs.log_file_authorized?(self, path)
39
44
  end
40
45
 
41
46
  def default_log_file_path
42
- # "/Users/alessandrorodi/RenuoWorkspace/onlylogs/test/fixtures/files/very_big.log"
43
47
  configured_default = Onlylogs.default_log_file_path
44
- return configured_default if Onlylogs.file_path_permitted?(configured_default) && ::File.exist?(configured_default)
48
+ return configured_default if authorized?(configured_default) && ::File.exist?(configured_default)
45
49
 
46
- @available_log_files.first&.to_s || configured_default
50
+ @available_log_files.first&.to_s
47
51
  end
48
52
  end
49
53
  end
@@ -53,13 +53,13 @@ module Onlylogs
53
53
  query: pattern, regexp: regexp_mode, case_sensitive: case_sensitive, start_position: start_position,
54
54
  end_position: end_position, max_matches: max_matches) do |payload|
55
55
  each_output_line(command_args, timeout: timeout) do |line|
56
- line = line.chomp
56
+ line = line.scrub.chomp
57
57
  next if context.positive? && line == GROUP_SEPARATOR
58
58
 
59
59
  byte_offset, content, context_line = parse_line.call(line)
60
60
 
61
61
  # Use String.new to create a copy and prevent memory retention from IO buffers
62
- content = String.new(content, encoding: Encoding::UTF_8).scrub
62
+ content = String.new(content, encoding: Encoding::UTF_8)
63
63
 
64
64
  result = {byte_offset: byte_offset, content: content}
65
65
  result[:context] = true if context_line
@@ -38,6 +38,11 @@
38
38
  .download-link:hover {
39
39
  background-color: #d7e5fd;
40
40
  }
41
+
42
+ .no-log-files {
43
+ padding: 0.65rem;
44
+ color: #58626f;
45
+ }
41
46
  </style>
42
47
  <div class="grid">
43
48
  <div class="grid-header">
@@ -56,5 +61,9 @@
56
61
  <% end %>
57
62
  <% end %>
58
63
  </div>
59
- <%= render partial: "onlylogs/shared/log_container", locals: { log_file_path: @log_file_path } %>
64
+ <% if @log_file_path %>
65
+ <%= render partial: "onlylogs/shared/log_container", locals: { log_file_path: @log_file_path } %>
66
+ <% else %>
67
+ <p class="no-log-files">No log files you can open.</p>
68
+ <% end %>
60
69
  </div>
data/bin/onlylogs_sidecar CHANGED
@@ -70,7 +70,6 @@ def send_batch(uri, lines)
70
70
  http.use_ssl = (uri.scheme == "https")
71
71
  request = Net::HTTP::Post.new(uri.path)
72
72
  request.body = lines.join("\n")
73
- puts "[OnlylogsSidecar] Sending #{request.body}"
74
73
  request.content_type = "text/plain"
75
74
  http.read_timeout = 5
76
75
  http.open_timeout = 2
data/bin/super_grep CHANGED
@@ -60,7 +60,8 @@ query_regex="${query_regex//$placeholder/$actual_color_regex}"
60
60
 
61
61
 
62
62
  # Build grep command
63
- grep_cmd=(grep -E -h) # -h = no filename (portable)
63
+ # -a: a NUL byte makes grep take the file for binary and print "Binary file matches" instead of the lines
64
+ grep_cmd=(grep -E -h -a) # -h = no filename (portable)
64
65
  if [ -n "$max_matches" ]; then
65
66
  grep_cmd+=(-m "$max_matches") # -m = max count (portable)
66
67
  fi
@@ -86,8 +87,8 @@ if [ -n "$start_position" ] || [ -n "$end_position" ]; then
86
87
  [ $range_end -gt $file_size ] && range_end=$file_size && range_size=$((range_end - range_start))
87
88
 
88
89
  tail -c +$((range_start + 1)) "$file" | head -c $range_size | \
89
- "${grep_cmd[@]}" "$query_regex"
90
+ "${grep_cmd[@]}" -e "$query_regex"
90
91
  else
91
- # Search entire file
92
- "${grep_cmd[@]}" "$query_regex" "$file"
92
+ # Search entire file. -e and -- keep a query or file that starts with "-" from being read as options.
93
+ "${grep_cmd[@]}" -e "$query_regex" -- "$file"
93
94
  fi
data/bin/super_ripgrep CHANGED
@@ -68,7 +68,8 @@ query_regex="${query_regex//$placeholder/$actual_color_regex}"
68
68
  # charges those pages to the cgroup as active memory, which can trigger an OOM
69
69
  # kill. Plain read() pages are ordinary, readily-reclaimable page cache.
70
70
  # --byte-offset: include byte offset in output for the logs-around-line feature
71
- rg_cmd="rg --color=never --no-filename --byte-offset --no-mmap"
71
+ # --text: a NUL byte makes ripgrep take the file for binary and stop printing matches from there on
72
+ rg_cmd="rg --color=never --no-filename --byte-offset --no-mmap --text"
72
73
  [ -n "$max_matches" ] && rg_cmd="$rg_cmd --max-count=$max_matches"
73
74
  [ "$case_insensitive" = true ] && rg_cmd="$rg_cmd --ignore-case"
74
75
  # Context lines come out as "offset-line" instead of "offset:line", with "--" between groups
@@ -1,3 +1,3 @@
1
1
  module Onlylogs
2
- VERSION = "0.14.0"
2
+ VERSION = "0.15.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onlylogs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi