From eee0826628756ea524472c902a4fe35c39d5bd26 Mon Sep 17 00:00:00 2001 From: root21 Date: Wed, 2 Nov 2022 14:40:22 -0600 Subject: [PATCH 1/3] Added method to send link via SMS on large file sizes and unsupported MIME types. --- sgx-bwmsgsv2.rb | 72 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index cb2e2ae4850c153c26a961d63868cc5008515bd8..d2fdf8e0dccdcb890cec4dbbf0c79b4cc9d90dc9 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -40,6 +40,54 @@ require_relative 'lib/registration_repo' Sentry.init +MMS_MIME_TYPES = [ + "application/json", + "application/ogg", + "application/pdf", + "application/rtf", + "application/zip", + "application/x-tar", + "application/xml", + "application/gzip", + "application/x-bzip2", + "application/x-gzip", + "application/smil", + "application/javascript", + "audio/mp4", + "audio/mpeg", + "audio/ogg", + "audio/flac", + "audio/webm", + "audio/wav", + "audio/amr", + "audio/3gpp", + "image/bmp", + "image/gif", + "image/jpeg", + "image/pjpeg", + "image/png", + "image/svg+xml", + "image/tiff", + "image/webp", + "image/x-icon", + "text/css", + "text/csv", + "text/calendar", + "text/plain", + "text/javascript", + "text/vcard", + "text/vnd.wap.wml", + "text/xml", + "video/avi", + "video/mp4", + "video/mpeg", + "video/ogg", + "video/quicktime", + "video/webm", + "video/x-ms-wmv", + "video/x-flv" +] + def panic(e) Sentry.capture_exception(e) puts "Shutting down gateway due to exception: #{e.message}" @@ -252,17 +300,25 @@ module SGXbwmsgsv2 end puts "MMSOOB: found a url node - checking if to make MMS..." - # TODO: check size of file at un.text and shrink if need - body = s.respond_to?(:body) ? s.body : '' - # some clients send URI in both body & so delete - s.body = body.sub(/\s*#{Regexp.escape(un.text)}\s*$/, '') + EM::HttpRequest.new(un.text, tls: { verify_peer: true }).head.then { |http| + if http.response_header["CONTENT_LENGTH"].to_i > 3500000 || + !MMS_MIME_TYPES.include?(http.response_header["CONTENT_TYPE"]) + unless body.include?(un.text) + s.body = body.empty? ? un.text : "#{body}\n#{un.text}" + end + to_catapult(s, nil, num_dest, user_id, token, secret, usern) + else + # some clients send URI in both body & so delete + s.body = body.sub(/\s*#{Regexp.escape(un.text)}\s*$/, '') - puts "MMSOOB: url text is '#{un.text}'" - puts "MMSOOB: the body is '#{body.to_s.strip}'" + puts "MMSOOB: url text is '#{un.text}'" + puts "MMSOOB: the body is '#{body.to_s.strip}'" - puts "MMSOOB: sending MMS since found OOB & user asked" - to_catapult(s, un.text, num_dest, user_id, token, secret, usern) + puts "MMSOOB: sending MMS since found OOB & user asked" + to_catapult(s, un.text, num_dest, user_id, token, secret, usern) + end + } end def self.to_catapult(s, murl, num_dest, user_id, token, secret, usern) From d5f7384ca3c6010ea89637da3aa35d3b62761732 Mon Sep 17 00:00:00 2001 From: root root Date: Tue, 15 Nov 2022 00:27:41 +0000 Subject: [PATCH 2/3] Added commented link for MIME type support --- sgx-bwmsgsv2.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index d2fdf8e0dccdcb890cec4dbbf0c79b4cc9d90dc9..b5705ee3eb37ee12df28016d4b77ebd1efda63e7 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -40,6 +40,7 @@ require_relative 'lib/registration_repo' Sentry.init +# List of supported MIME types from Bandwidth - https://support.bandwidth.com/hc/en-us/articles/360014128994-What-MMS-file-types-are-supported- MMS_MIME_TYPES = [ "application/json", "application/ogg", From 9595adebc2d316ade764e11fff2d9b3f86063a1e Mon Sep 17 00:00:00 2001 From: root root Date: Tue, 15 Nov 2022 00:34:39 +0000 Subject: [PATCH 3/3] Added comments to new code blocks. --- sgx-bwmsgsv2.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index b5705ee3eb37ee12df28016d4b77ebd1efda63e7..325f2259b67f64869e318107d2bac1c7dbf59c3c 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -303,13 +303,14 @@ module SGXbwmsgsv2 body = s.respond_to?(:body) ? s.body : '' EM::HttpRequest.new(un.text, tls: { verify_peer: true }).head.then { |http| + # If content is too large, or MIME type is not supported, place the link inside the body and do not send MMS. if http.response_header["CONTENT_LENGTH"].to_i > 3500000 || !MMS_MIME_TYPES.include?(http.response_header["CONTENT_TYPE"]) unless body.include?(un.text) s.body = body.empty? ? un.text : "#{body}\n#{un.text}" end to_catapult(s, nil, num_dest, user_id, token, secret, usern) - else + else # If size is less than ~3.5MB, strip the link from the body and attach media in the body. # some clients send URI in both body & so delete s.body = body.sub(/\s*#{Regexp.escape(un.text)}\s*$/, '')