Class: NatasLevelBase

Inherits:
Object
  • Object
show all
Defined in:
lib/natas.rb

Overview

Base class of level

Constant Summary collapse

HOST =
'natas.labs.overthewire.org'
PORT =
80
LOGIN =
'natas'
WEBPASS =
'/etc/natas_webpass'
LEVEL =
nil
PASSWORD_LENGTH =
32

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell) ⇒ NatasLevelBase

Returns a new instance of NatasLevelBase.



59
60
61
62
63
64
# File 'lib/natas.rb', line 59

def initialize(shell)
  @shell = shell
  @login = LOGIN + self.class::LEVEL.to_s
  @password = nil
  @client = Net::HTTP.new("#{@login}.#{HOST}", PORT)
end

Instance Attribute Details

#loginObject (readonly)

Returns the value of attribute login.



56
57
58
# File 'lib/natas.rb', line 56

def 
  @login
end

#passwordObject

Returns the value of attribute password.



57
58
59
# File 'lib/natas.rb', line 57

def password
  @password
end

Instance Method Details

#execObject



66
# File 'lib/natas.rb', line 66

def exec; end

#get(query, headers = {}) ⇒ Object

Raises:

  • (StandardError)


72
73
74
75
76
77
78
79
80
81
# File 'lib/natas.rb', line 72

def get(query, headers = {})
  request = Net::HTTP::Get.new(query, headers)
  request.basic_auth(@login, @password)

  response = @client.request(request)

  raise StandardError, 'Unauthorized' if response.instance_of?(Net::HTTPUnauthorized)

  response
end

#levelObject



68
69
70
# File 'lib/natas.rb', line 68

def level
  self.class::LEVEL
end

#post(query, headers = {}, data = nil, multipart: false) ⇒ Object

Raises:

  • (StandardError)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/natas.rb', line 83

def post(query, headers = {}, data = nil, multipart: false)
  request = Net::HTTP::Post.new(query, headers)
  request.basic_auth(@login, @password)
  unless data.nil?
    request.set_form(
      data,
      multipart ? 'multipart/form-data' : 'application/x-www-form-urlencoded'
    )
  end

  response = @client.request(request)

  raise StandardError, 'Unauthorized' if response.instance_of?(Net::HTTPUnauthorized)

  response
end