Class: Onlylogs::LogsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/onlylogs/logs_controller.rb

Instance Method Summary collapse

Instance Method Details

#downloadObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/onlylogs/logs_controller.rb', line 17

def download
  if params[:log_file_path].blank?
    return render(plain: "Bad Request: missing required parameter 'log_file_path' (encrypted log file path).", status: :bad_request)
  end

  file_path = authorized_log_file_path(params[:log_file_path])
  send_file file_path, filename: ::File.basename(file_path), disposition: :attachment
rescue Onlylogs::SecureFilePath::SecurityError
  render plain: "Bad Request: 'log_file_path' could not be decrypted (tampered or malformed token).", status: :bad_request
rescue Onlylogs::ForbiddenPathError
  render plain: "Forbidden: requested log file path is not in the allowed list.", status: :forbidden
rescue ActionController::MissingFile, Errno::ENOENT
  render plain: "Not Found: log file is currently unreadable (it may have been rotated, moved, or temporarily unavailable).", status: :not_found
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/onlylogs/logs_controller.rb', line 5

def index
  @max_lines = (params[:max_lines] || 100).to_i

  @available_log_files = Onlylogs.available_log_files
  @log_file_path = selected_log_file_path

  @filter = params[:filter]
  @autoscroll = params[:autoscroll] != "false"
  @regexp_mode = params[:regexp_mode] == "true"
  @mode = @filter.blank? ? (params[:mode] || "live") : "search" # "live" or "search"
end