Module: Sockit::Support

Included in:
Sockit
Defined in:
lib/sockit/support.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) connect_via_socks?(host)

Returns:

  • (Boolean)


20
21
22
# File 'lib/sockit/support.rb', line 20

def connect_via_socks?(host)
  (is_configured? && !config.ignore.flatten.include?(host))
end

- (Object) dump(action, data)



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sockit/support.rb', line 39

def dump(action, data)
  return if !config.debug

  bytes = Array.new
  chars = Array.new
  for x in 0..(data.length - 1) do
    bytes << ("%03d" % data[x].ord)
    chars << ("%03s" % (data[x] =~ /^\w+$/ ? data[x].chr : "..."))
  end
  log(:blue, "#{action.to_s.upcase}: #{bytes.join(" ")}#{COLORS[:reset]}")
  log(:blue, "#{action.to_s.upcase}: #{chars.join(" ")}#{COLORS[:reset]}")
end

- (Boolean) is_configured?

Returns:

  • (Boolean)


16
17
18
# File 'lib/sockit/support.rb', line 16

def is_configured?
  (is_host_configured? && is_port_configured? && is_version_configured?)
end

- (Boolean) is_host_configured?

Returns:

  • (Boolean)


4
5
6
# File 'lib/sockit/support.rb', line 4

def is_host_configured?
  (!config.host.nil? && !config.host.empty?)
end

- (Boolean) is_port_configured?

Returns:

  • (Boolean)


8
9
10
# File 'lib/sockit/support.rb', line 8

def is_port_configured?
  (!config.port.nil? && !config.port.empty?)
end

- (Boolean) is_socks_v4?

Returns:

  • (Boolean)


28
29
30
# File 'lib/sockit/support.rb', line 28

def is_socks_v4?
  (is_configured? && config.version.to_i == 4)
end

- (Boolean) is_socks_v5?

Returns:

  • (Boolean)


24
25
26
# File 'lib/sockit/support.rb', line 24

def is_socks_v5?
  (is_configured? && config.version.to_i == 5)
end

- (Boolean) is_version_configured?

Returns:

  • (Boolean)


12
13
14
# File 'lib/sockit/support.rb', line 12

def is_version_configured?
  ((config.version == 4) || (config.version == 5))
end

- (Object) log(color, message)



32
33
34
35
36
37
# File 'lib/sockit/support.rb', line 32

def log(color, message)
  return if !config.debug

  timestamp = Time.now.utc
  puts("%s%s.%06d %s%s" % [COLORS[color], timestamp.strftime("%Y-%m-%d|%H:%M:%S"), timestamp.usec, message, COLORS[:reset]])
end