2007-10-14 05:33:00 +00:00
|
|
|
class IntegrationsController < ApplicationController
|
2011-10-04 20:14:36 +02:00
|
|
|
require 'mail'
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2018-09-22 12:55:27 -05:00
|
|
|
skip_before_action :login_required, :only => [:cloudmailin, :search_plugin]
|
|
|
|
skip_before_action :verify_authenticity_token, only: [:cloudmailin]
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2007-10-14 05:33:00 +00:00
|
|
|
def index
|
|
|
|
@page_title = 'TRACKS::Integrations'
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2007-12-05 06:48:24 +00:00
|
|
|
def rest_api
|
|
|
|
@page_title = 'TRACKS::REST API Documentation'
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2020-07-23 22:20:28 +03:00
|
|
|
def help
|
|
|
|
@page_title = 'TRACKS::Help'
|
|
|
|
end
|
|
|
|
|
2008-12-10 21:30:43 +01:00
|
|
|
def search_plugin
|
2020-10-27 21:39:19 +02:00
|
|
|
@icon_data = [File.open(File.join(Rails.root, 'app', 'assets', 'images', 'done.png')).read]
|
|
|
|
.pack('m').gsub(/\n/, '')
|
2008-12-10 21:30:43 +01:00
|
|
|
end
|
|
|
|
|
2011-10-04 20:14:36 +02:00
|
|
|
def cloudmailin
|
2013-05-05 20:32:32 +02:00
|
|
|
if !verify_cloudmailin_signature
|
2018-09-22 13:03:35 -05:00
|
|
|
render :body => "Message signature verification failed.", :status => 403
|
2011-10-05 23:53:49 +02:00
|
|
|
return false
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2013-05-05 20:32:32 +02:00
|
|
|
if process_message(params[:message])
|
2018-09-22 13:03:35 -05:00
|
|
|
render :body => 'success', :status => 200
|
2011-10-04 20:14:36 +02:00
|
|
|
else
|
2018-09-22 13:03:35 -05:00
|
|
|
render :body => "No user found or other error", :status => 404
|
2011-10-04 20:14:36 +02:00
|
|
|
end
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2012-07-12 13:14:21 +02:00
|
|
|
private
|
2013-05-05 20:32:32 +02:00
|
|
|
|
|
|
|
def process_message(message)
|
2020-10-27 21:39:19 +02:00
|
|
|
MessageGateway.receive(Mail.new(message))
|
2013-05-05 20:32:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def verify_cloudmailin_signature
|
|
|
|
provided = request.request_parameters.delete(:signature)
|
2020-10-27 21:39:19 +02:00
|
|
|
signature = Digest::MD5.hexdigest(flatten_params(request.request_parameters).sort.map { |k, v| v }.join + SITE_CONFIG['cloudmailin'])
|
2013-05-05 20:32:32 +02:00
|
|
|
return provided == signature
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2014-09-08 00:29:22 -04:00
|
|
|
def flatten_params(params, title = nil, result = {})
|
|
|
|
params.each do |key, value|
|
2020-10-27 21:39:19 +02:00
|
|
|
if value.is_a? Hash
|
2014-09-08 00:29:22 -04:00
|
|
|
key_name = title ? "#{title}[#{key}]" : key
|
|
|
|
flatten_params(value, key_name, result)
|
|
|
|
else
|
|
|
|
key_name = title ? "#{title}[#{key}]" : key
|
|
|
|
result[key_name] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return result
|
|
|
|
end
|
2007-10-14 05:33:00 +00:00
|
|
|
end
|