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
|
|
|
|
2011-10-04 20:14:36 +02:00
|
|
|
skip_before_filter :login_required, :only => [:cloudmailin, :search_plugin, :google_gadget]
|
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
|
|
|
|
2007-10-14 05:33:00 +00:00
|
|
|
def get_quicksilver_applescript
|
2012-07-12 13:14:21 +02:00
|
|
|
get_applescript('quicksilver_applescript')
|
2007-10-14 05:33:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_applescript1
|
2012-07-12 13:14:21 +02:00
|
|
|
get_applescript('applescript1')
|
2007-10-14 05:33:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_applescript2
|
2012-07-12 13:14:21 +02:00
|
|
|
get_applescript('applescript2')
|
2007-10-14 05:33:00 +00:00
|
|
|
end
|
2008-12-10 21:30:43 +01:00
|
|
|
|
|
|
|
def search_plugin
|
2012-06-29 16:48:30 +02:00
|
|
|
@icon_data = [File.open(File.join(Rails.root, 'app', 'assets', 'images', 'done.png')).read].
|
2011-10-04 20:14:36 +02:00
|
|
|
pack('m').gsub(/\n/, '')
|
2008-12-10 21:30:43 +01:00
|
|
|
end
|
|
|
|
|
2009-08-04 09:54:45 +02:00
|
|
|
def google_gadget
|
|
|
|
render :layout => false, :content_type => Mime::XML
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2011-10-04 20:14:36 +02:00
|
|
|
def cloudmailin
|
2013-05-05 20:32:32 +02:00
|
|
|
if !verify_cloudmailin_signature
|
2011-10-06 16:41:46 +02:00
|
|
|
render :text => "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])
|
2012-07-12 13:14:21 +02:00
|
|
|
render :text => 'success', :status => 200
|
2011-10-04 20:14:36 +02:00
|
|
|
else
|
2012-07-12 13:14:21 +02:00
|
|
|
render :text => "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)
|
|
|
|
MessageGateway::receive(Mail.new(message))
|
|
|
|
end
|
|
|
|
|
|
|
|
def verify_cloudmailin_signature
|
|
|
|
provided = request.request_parameters.delete(:signature)
|
2014-09-08 00:29:22 -04: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|
|
|
|
|
if value.kind_of?(Hash)
|
|
|
|
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
|
|
|
|
|
2012-07-12 13:14:21 +02:00
|
|
|
def get_applescript(partial_name)
|
|
|
|
context = current_user.contexts.find params[:context_id]
|
|
|
|
render :partial => partial_name, :locals => { :context => context }
|
|
|
|
end
|
2014-08-14 21:05:05 -05:00
|
|
|
|
2007-10-14 05:33:00 +00:00
|
|
|
end
|