summaryrefslogtreecommitdiff
path: root/app/controllers/trigger_controller.rb
diff options
context:
space:
mode:
authorspag <spag@golwen.net>2013-01-24 16:38:42 +0100
committerspag <spag@golwen.net>2013-01-24 16:38:42 +0100
commitfed98f1002ab5c874f55e7a3730f9b5ca2555ec3 (patch)
treea46f1868e76697d8f5705ee3f987f13a92c7ae20 /app/controllers/trigger_controller.rb
parent108bab40025a41a03f42bdb6db12ca843a329d4a (diff)
fax and voicemail notification
Diffstat (limited to 'app/controllers/trigger_controller.rb')
-rw-r--r--app/controllers/trigger_controller.rb123
1 files changed, 119 insertions, 4 deletions
diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb
index e9821f6..c49e0b9 100644
--- a/app/controllers/trigger_controller.rb
+++ b/app/controllers/trigger_controller.rb
@@ -1,11 +1,126 @@
class TriggerController < ApplicationController
+ TIFF_FUFFIX = ".tiff"
+ PDF_SUFFIX = ".pdf"
+ TMP_DIR = "/tmp/"
+
def voicemail
- # Something is triggered when ever a local script fetches this action.
- #
+ if !params[:sip_account_id].blank?
+ sip_account = SipAccount.where(:id => params[:sip_account_id].to_i).first
+ if sip_account
+ sip_account.voicemail_messages.where(:notification => nil).each do |message|
+ message.notification = false
+ message.save
+ if !File.exists?( message.file_path )
+ next
+ end
+
+ user = sip_account.sip_accountable
+ if user.class != User
+ next
+ end
+
+ if user.email.blank?
+ next
+ end
+
+ voicemail_settings = sip_account.voicemail_setting
+ if !voicemail_settings
+ voicemail_settings = VoicemailSetting.new(:notify => user.send_voicemail_as_email_attachment, :attachment => user.send_voicemail_as_email_attachment, :mark_read => user.send_voicemail_as_email_attachment)
+ end
+
+ message.notification = voicemail_settings.notify
+ if voicemail_settings.notify
+ if Notifications.new_voicemail(message, voicemail_settings.attachment).deliver
+ if voicemail_settings.purge
+ message.delete
+ next
+ end
+ message.save
+ if voicemail_settings.mark_read
+ message.mark_read
+ end
+ end
+ else
+ message.save
+ end
+ end
+
+ render(
+ :status => 200,
+ :layout => false,
+ :content_type => 'text/plain',
+ :text => "<!-- OK -->",
+ )
+ else
+ render(
+ :status => 404,
+ :layout => false,
+ :content_type => 'text/plain',
+ :text => "<!-- Account not found -->",
+ )
+ end
+ end
end
def fax
- # Something is triggered when ever a local script fetches this action.
- #
+ if !params[:fax_account_id].blank?
+ fax_account = FaxAccount.where(:id => params[:fax_account_id].to_i).first
+ if fax_account
+ fax_account.fax_documents.where(:state => 'received').each do |fax_document|
+
+ tiff_file = File.basename(fax_document.tiff.to_s)
+
+ if !File.exists?( "#{TMP_DIR}#{tiff_file}" )
+ fax_document.state = 'unsuccessful'
+ fax_document.save
+ next
+ end
+
+ paper_size = "letter"
+ pdf_file = "#{TMP_DIR}#{File.basename(tiff_file, TIFF_FUFFIX)}#{PDF_SUFFIX}"
+
+ system "tiff2pdf \\
+ -o \"#{pdf_file}\" \\
+ -p #{paper_size} \\
+ -a \"#{fax_document.remote_station_id}\" \\
+ -c \"AMOOMA Gemeinschaft version #{GsParameter.get('GEMEINSCHAFT_VERSION')}\" \\
+ -t \"#{fax_document.remote_station_id}\" \"#{TMP_DIR}#{tiff_file}\""
+
+ if !File.exists?( pdf_file )
+ fax_document.state = 'unsuccessful'
+ fax_document.save
+ next
+ end
+
+ fax_document.document = File.open(pdf_file)
+ fax_document.state = 'successful'
+
+ if fax_document.save
+ Notifications.new_fax(fax_document).deliver
+ File.delete("#{TMP_DIR}#{tiff_file}");
+ File.delete(pdf_file);
+ fax_document.tiff = nil
+ fax_document.save
+ else
+ fax_document.state = 'unsuccessful'
+ fax_document.save
+ end
+ end
+
+ render(
+ :status => 200,
+ :layout => false,
+ :content_type => 'text/plain',
+ :text => "<!-- OK -->",
+ )
+ else
+ render(
+ :status => 404,
+ :layout => false,
+ :content_type => 'text/plain',
+ :text => "<!-- Account not found -->",
+ )
+ end
+ end
end
end