Class: NatasLevelBase
- Inherits:
-
Object
- Object
- NatasLevelBase
- Defined in:
- lib/natas.rb
Overview
Base class of level
Direct Known Subclasses
NatasLevel0, NatasLevel1, NatasLevel10, NatasLevel11, NatasLevel12, NatasLevel13, NatasLevel14, NatasLevel15, NatasLevel16, NatasLevel17, NatasLevel18, NatasLevel19, NatasLevel2, NatasLevel20, NatasLevel21, NatasLevel22, NatasLevel23, NatasLevel24, NatasLevel25, NatasLevel26, NatasLevel27, NatasLevel28, NatasLevel29, NatasLevel3, NatasLevel30, NatasLevel31, NatasLevel32, NatasLevel33, NatasLevel34, NatasLevel4, NatasLevel5, NatasLevel6, NatasLevel7, NatasLevel8, NatasLevel9
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
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#password ⇒ Object
Returns the value of attribute password.
Instance Method Summary collapse
- #exec ⇒ Object
- #get(query, headers = {}) ⇒ Object
-
#initialize(shell) ⇒ NatasLevelBase
constructor
A new instance of NatasLevelBase.
- #level ⇒ Object
- #post(query, headers = {}, data = nil, multipart: false) ⇒ Object
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
#login ⇒ Object (readonly)
Returns the value of attribute login.
56 57 58 |
# File 'lib/natas.rb', line 56 def login @login end |
#password ⇒ Object
Returns the value of attribute password.
57 58 59 |
# File 'lib/natas.rb', line 57 def password @password end |
Instance Method Details
#exec ⇒ Object
66 |
# File 'lib/natas.rb', line 66 def exec; end |
#get(query, headers = {}) ⇒ Object
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 |
#level ⇒ Object
68 69 70 |
# File 'lib/natas.rb', line 68 def level self.class::LEVEL end |
#post(query, headers = {}, data = nil, multipart: false) ⇒ Object
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 |