Class: Detector::Addons::SMTP

Inherits:
Base
  • Object
show all
Defined in:
lib/detector/addons/smtp.rb

Instance Attribute Summary

Attributes inherited from Base

#keys, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#asn, #close, #connection?, #connection_count, #connection_info, #connection_limit, #connection_usage_percentage, #database_count, #databases, #databases?, detect, #estimated_row_count, #geo, #geography, #host, #infrastructure, #initialize, #ip, #kind, #ping, #port, #region, register_addon, #replication_available?, #sql?, #summary, #table_count, #tables, #tables?, #tcp_test, #transport?, #udp_test, #usage, #valid?, #with_connection

Constructor Details

This class inherits a constructor from Detector::Base

Class Method Details

.capabilities_for(url) ⇒ Object



10
11
12
# File 'lib/detector/addons/smtp.rb', line 10

def self.capabilities_for(url)
  { kv: true, sql: false, url: url, kind: :smtp, databases: false, tables: false }
end

.handles_uri?(uri) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/detector/addons/smtp.rb', line 6

def self.handles_uri?(uri)
  uri.scheme.downcase == 'smtp' || uri.scheme.downcase == 'smtps'
end

Instance Method Details

#cli_nameObject



31
32
33
# File 'lib/detector/addons/smtp.rb', line 31

def cli_name
  "telnet"
end

#connectionObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/detector/addons/smtp.rb', line 14

def connection
  # Create a new connection each time without caching
  begin
    conn = Net::SMTP.new(host, port)
    conn.open_timeout = 5
    conn.start('detector.local', uri.user, uri.password, :login)
    conn
  rescue => e
    nil
  end
end

#protocol_typeObject



35
36
37
# File 'lib/detector/addons/smtp.rb', line 35

def protocol_type
  :tcp
end

#user_access_levelObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/detector/addons/smtp.rb', line 39

def user_access_level
  return nil unless connection
  
  # For SMTP, limited testing is possible
  # We know we have authenticated access already if connection exists
  
  # Try to validate recipient (admin-level feature)
  admin_level = false
  begin
    connection.vrfy("postmaster")
    admin_level = true
  rescue => e
    admin_level = false
  end
  
  if admin_level
    "Administrator (VRFY command allowed)"
  else
    "Authenticated user (send mail)"
  end
end

#versionObject



26
27
28
29
# File 'lib/detector/addons/smtp.rb', line 26

def version
  return nil unless connection
  "SMTP server at #{host}:#{port}"
end