You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.8 KiB
88 lines
2.8 KiB
class ReportsController < ApplicationController
|
|
attr_reader :report
|
|
def initialize
|
|
@search_term=""
|
|
end
|
|
|
|
def search
|
|
from = params[:mail_from]
|
|
to = params[:rcpt_to]
|
|
if !params[:date_to].nil?
|
|
date_to = Time.parse(params[:date_to]).to_i.to_s if !params[:date_to].empty?
|
|
to_next_day = (Time.parse(params[:date_to]).to_i + 86400).to_s if !params[:date_to].empty?
|
|
end
|
|
if !params[:date_to].nil?
|
|
date_from = Time.parse(params[:date_from]).to_i.to_s if !params[:date_from].empty?
|
|
from_next_day = (Time.parse(params[:date_from]).to_i + 86400).to_s if !params[:date_from].empty?
|
|
end
|
|
status = params[:status]
|
|
from ||= ''
|
|
to ||= ''
|
|
|
|
if !from.empty?
|
|
@search_term << 'messages.mail_from="'+from+'"'
|
|
end
|
|
|
|
if !to.empty?
|
|
if !@search_term.empty?
|
|
@search_term << " AND "
|
|
end
|
|
@search_term << 'messages.rcpt_to="'+to+'"'
|
|
puts "search term is #{@search_term}"
|
|
end
|
|
|
|
if !date_to.nil?
|
|
if !@search_term.empty?
|
|
@search_term << " AND "
|
|
end
|
|
if params[:date_from].nil? or params[:date_from].empty?
|
|
@search_term << 'messages.timestamp>'+date_to+" AND messages.timestamp<"+ to_next_day
|
|
else
|
|
@search_term << 'messages.timestamp<='+date_to
|
|
end
|
|
end
|
|
|
|
if !date_from.nil?
|
|
if !@search_term.empty?
|
|
@search_term << " AND "
|
|
end
|
|
if params[:date_to].nil? or params[:date_to].empty?
|
|
@search_term << 'messages.timestamp>'+date_from+" AND messages.timestamp<"+ from_next_day
|
|
else
|
|
@search_term << 'messages.timestamp>='+date_from
|
|
end
|
|
end
|
|
|
|
if status != "All" and @search_term.empty?
|
|
@search_term << 'messages.status="'+status+'"'
|
|
elsif status != "All" and !@search_term.empty?
|
|
@search_term << ' AND messages.status="'+status+'"'
|
|
end
|
|
puts "search term is #{@search_term}"
|
|
|
|
@@report_search = Report.find(@search_term)
|
|
p @query_report
|
|
@query_report = Report.find(@search_term)
|
|
end
|
|
|
|
def export
|
|
if File.file?("#{Rails.root}/mail_delivery_report.csv")
|
|
File.delete("#{Rails.root}/mail_delivery_report.csv")
|
|
end
|
|
|
|
file = File.open("mail_delivery_report.csv", "a")
|
|
file.write("ID|SENDER|RECIPIENT|SUBJECT|DATE|TIME|SIZE|STATUS|DELIVERY DETAILS\n")
|
|
@@report_search.each(:as => :hash) do |mail|
|
|
file.write("#{mail['message_id']}|#{mail['mail_from']}|#{mail['rcpt_to']}|#{mail['subject']}|#{Time.at(mail['timestamp']).strftime('%d-%m-%Y')}|#{Time.at(mail['timestamp']).strftime('%H:%M:%S')}|#{ mail['size'].to_f >= 1048576 ? "#{(mail['size'].to_d/1048576).round(2)} MB" : "#{(mail['size'].to_d/1024).round(2)} KB" }|#{mail['status']}|#{mail['details']}\n")
|
|
end
|
|
file.close
|
|
send_file("#{Rails.root}/mail_delivery_report.csv")
|
|
end
|
|
|
|
|
|
def index
|
|
@mails = Report.all
|
|
# @pagy, @record = pagy(Report.all)
|
|
end
|
|
|
|
end
|
|
|