diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:05:14 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:05:14 +0100 |
commit | eaad37485fe59d0306c37cc038dda6d210052910 (patch) | |
tree | 072c4b0e33d442528555b82c415f5e7a1712b2b0 /script/fax_new | |
parent | 3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff) | |
parent | b80bd744ad873f6fc43018bc4bfb90677de167bd (diff) |
Merge branch 'develop'
Diffstat (limited to 'script/fax_new')
-rwxr-xr-x | script/fax_new | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/script/fax_new b/script/fax_new new file mode 100755 index 0000000..8015da8 --- /dev/null +++ b/script/fax_new @@ -0,0 +1,111 @@ +#! /usr/bin/env ruby + +begin + +if !ARGV[0] or ARGV[0] == '' or !ARGV[10] or ARGV[10] == '' + $stderr.puts "usage: fax_new <fax_account_id> \ +<result_code> \ +<document_total_pages> \ +<document_transferred_pages> \ +<ecm_requested> \ +<ecm_used> \ +<image_resolution> \ +<remote_station_id> \ +<transfer_rate> \ +<transmission_time> \ +<document> \ +<caller_id_number> \ +<caller_id_name>" + exit 1 +end + +fax_arguments = { + :fax_account_id => ARGV[0], + :result_code => ARGV[1], + :document_total_pages => ARGV[2], + :document_transferred_pages => ARGV[3], + :ecm_requested => ARGV[4], + :ecm_used => ARGV[5], + :image_resolution => ARGV[6], + :remote_station_id => ARGV[7], + :transfer_rate => ARGV[8], + :transmission_time => ARGV[9], + :document => ARGV[10], + :caller_id_number => ARGV[11], + :caller_id_name => ARGV[12], +} + +APP_PATH = File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/boot', __FILE__) +require APP_PATH + +begin + Rails.application.require_environment! +rescue ActiveRecord::AdapterNotSpecified => e + error "No such Rails environment: \"#{Rails.env}\"." + exit 1 +end + +TIFF_FUFFIX = ".tiff" +PDF_SUFFIX = ".pdf" + +tiff_file = fax_arguments[:document] + +if !tiff_file or !File.exists?( tiff_file ) + $stderr.puts "File \"#{tiff_file}\" does not exist" + exit 1 +end + +paper_size = "letter" +pdf_file = "#{File.dirname(tiff_file)}/#{File.basename(tiff_file, TIFF_FUFFIX)}#{PDF_SUFFIX}" + +system "tiff2pdf \\ + -o \"#{pdf_file}\" \\ + -p #{paper_size} \\ + -a \"#{fax_arguments[:remote_station_id]}\" \\ + -c \"AMOOMA Gemeinschaft version #{GEMEINSCHAFT_VERSION}\" \\ + -t \"#{fax_arguments[:remote_station_id]}\" \"#{tiff_file}\"" + +if !File.exists?( pdf_file ) + $stderr.puts "File \"#{pdf_file}\" does not exist" + exit 1 +end + +fax_account = FaxAccount.find(fax_arguments[:fax_account_id]) +if !fax_account + $stderr.puts "Fax account \"#{fax_arguments[:fax_account_id]}\" does not exist" + exit 1 +end + +fax_arguments[:document] = nil +fax_arguments[:success] = true +fax_arguments[:inbound] = true +fax_arguments[:sent_at] = Time.now +fax_arguments[:local_station_id] = fax_account.station_id +fax_arguments[:retry_counter] = 0 +fax_arguments[:fax_resolution_id] = FaxResolution.first.id +fax_arguments[:image_size] = File.size(tiff_file) +fax_arguments[:ecm_used] = fax_arguments[:ecm_used] == "on" ? true : false +fax_document = fax_account.fax_documents.build(fax_arguments) +fax_document.document = File.open(pdf_file) + +if ! fax_document.save + $stderr.puts "Error(s) creating fax document:" + $stderr.puts fax_document.errors.inspect + exit 1 +end + +fax_document.mark_as_inbound! + +Notifications.new_fax(fax_document).deliver + +exit 0 + +rescue SignalException => e + $stderr.print "#{e.class.to_s}" + $stderr.print " (Signal #{e.signo.to_s})" if e.respond_to?(:signo) && e.signo + $stderr.puts "" + exit 130 +end + +exit 0 |