Class: Rex::Proto::Sms::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/sms/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Rex::Proto::Sms::Client

Initializes the Client object.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):



24
25
26
27
28
29
# File 'lib/rex/proto/sms/client.rb', line 24

def initialize(opts={})
  self.carrier       = opts[:carrier]
  self.smtp_server   = opts[:smtp_server]

  validate_carrier!
end

Instance Attribute Details

#carrierSymbol

Returns The service provider for the phone numbers.

Returns:

  • (Symbol)

    The service provider for the phone numbers.



10
11
12
# File 'lib/rex/proto/sms/client.rb', line 10

def carrier
  @carrier
end

#smtp_serverRex::Proto::Sms::Model::Smtp

Returns The Smtp object with the Smtp settings.

Returns:



14
15
16
# File 'lib/rex/proto/sms/client.rb', line 14

def smtp_server
  @smtp_server
end

Instance Method Details

#send_text_to_phones(phone_numbers, subject, message) ⇒ void

This method returns an undefined value.

Sends a text to multiple recipients.

Parameters:

  • phone_numbers (<String>Array)

    An array of phone numbers.

  • subject (String)

    Subject of the message

  • message (String)

    The text message to send.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rex/proto/sms/client.rb', line 39

def send_text_to_phones(phone_numbers, subject, message)
  carrier     = Rex::Proto::Sms::Model::GATEWAYS[self.carrier]
  recipients  = phone_numbers.collect { |p| "#{p}@#{carrier}" }
  address     = self.smtp_server.address
  port        = self.smtp_server.port
  username    = self.smtp_server.username
  password    = self.smtp_server.password
  helo_domain = self.smtp_server.helo_domain
    = self.smtp_server.
  from        = self.smtp_server.from

  smtp = Net::SMTP.new(address, port)

  begin
    smtp.enable_starttls_auto
    smtp.start(helo_domain, username, password, ) do
      recipients.each do |r|
        sms_message = Rex::Proto::Sms::Model::Message.new(
          from: from,
          to: r,
          subject: subject,
          message: message
        )
        smtp.send_message(sms_message.to_s, from, r)
      end
    end
  rescue Net::SMTPAuthenticationError => e
    raise Rex::Proto::Sms::Exception, e.message
  ensure
    smtp.finish if smtp && smtp.started?
  end
end