Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/mms/client.rb
Views: 11704
# -*- coding: binary -*-12module Rex3module Proto4module Mms5class Client67# @!attribute carrier8# @return [Symbol] The service provider for the phone numbers.9attr_accessor :carrier1011# @!attribute smtp_server12# @return [Rex::Proto::Mms::Model::Smtp] The Smtp object with the Smtp settings.13attr_accessor :smtp_server141516# Initializes the Client object.17#18# @param [Hash] opts19# @option opts [Symbol] Service provider name (see Rex::Proto::Mms::Model::GATEWAYS)20# @option opts [Rex::Proto::mms::Model::Smtp] SMTP object21#22# @return [Rex::Proto::Mms::Client]23def initialize(opts={})24self.carrier = opts[:carrier]25self.smtp_server = opts[:smtp_server]2627validate_carrier!28end293031# Sends a media text to multiple recipients.32#33# @param phone_numbers [<String>Array] An array of phone numbers.34# @param subject [String] MMS subject35# @param message [String] The message to send.36# @param attachment_path [String] (Optional) The attachment to include37# @param ctype [String] (Optional) The content type to use for the attachment38#39# @return [void]40def send_mms_to_phones(phone_numbers, subject, message, attachment_path=nil, ctype=nil)41carrier = Rex::Proto::Mms::Model::GATEWAYS[self.carrier]42recipients = phone_numbers.collect { |p| "#{p}@#{carrier}" }43address = self.smtp_server.address44port = self.smtp_server.port45username = self.smtp_server.username46password = self.smtp_server.password47helo_domain = self.smtp_server.helo_domain48login_type = self.smtp_server.login_type49from = self.smtp_server.from5051smtp = Net::SMTP.new(address, port)5253begin54smtp.enable_starttls_auto55smtp.start(helo_domain, username, password, login_type) do56recipients.each do |r|57mms_message = Rex::Proto::Mms::Model::Message.new(58message: message,59content_type: ctype,60attachment_path: attachment_path,61from: from,62to: r,63subject: subject64)65smtp.send_message(mms_message.to_s, from, r)66end67end68rescue Net::SMTPAuthenticationError => e69raise Rex::Proto::Mms::Exception, e.message70ensure71smtp.finish if smtp && smtp.started?72end73end747576# Validates the carrier parameter.77#78# @raise [Rex::Proto::Mms::Exception] If an invalid service provider is used.79def validate_carrier!80unless Rex::Proto::Mms::Model::GATEWAYS.include?(self.carrier)81raise Rex::Proto::Mms::Exception, 'Invalid carrier.'82end83end8485end86end87end88end899091