idrac 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e41b7b9b93deb9e404e63931d7923fcbbbe93ab9fa800f75ae67f7c0e584fe3
4
- data.tar.gz: d082799ca43c5d5f84b781e8b1ac2f89600f9c781b8cc3977645e0052d2e609d
3
+ metadata.gz: ea684775e5a6c176d4089ce5a88a0907170896a3818d715479ca53a58ee95d05
4
+ data.tar.gz: dbe078ef0f036c27ecefbaeb454f63357561ecb0a9c9ee0f618f870b4e12b812
5
5
  SHA512:
6
- metadata.gz: 9a4d52657ed48583f0721dd84b3ef30e08184b613368b511dbabf61242811ef86cf3e3d37e3caf6e49db0ee63a963eac8f6ce692e566223851b9806f469817e8
7
- data.tar.gz: 8bea1a7c91c8404b6292688410b9c01e0d894295b4ae44318d452498e01dff5f168b76605a3b40eb2c535b41b3a1e9d5f13c2b8af26bbfbfc61f4f1a31f0818a
6
+ metadata.gz: cfd4619dc968e53dd5ca1f773881c7c422b3b281ef423c6f626cae934ecce20368e2a4bccf9598a84a07e300c7540bf2c3bd0236f5ad2b3cb7c163f3f05a4357
7
+ data.tar.gz: b6ee7e98a9ff60ba6886e01f8aac2d8c0da2c792e26bdab28409e532577660bbd8727e3c307af8351efb3b19cb2defcc91d37235c6c8a43e712b355d53bb2a43
data/idrac.gemspec CHANGED
@@ -32,7 +32,14 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ["lib"]
33
33
 
34
34
  # Uncomment to register a new dependency of your gem
35
- # spec.add_dependency "example-gem", "~> 1.0"
35
+ spec.add_dependency "httparty"
36
+ spec.add_dependency "nokogiri"
37
+
38
+ # Add dev dependencies:
39
+ spec.add_development_dependency "bundler"
40
+ spec.add_development_dependency "rake"
41
+ spec.add_development_dependency "rspec"
42
+ spec.add_development_dependency "debug"
36
43
 
37
44
  # For more information and examples about making a new gem, check out our
38
45
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -0,0 +1,48 @@
1
+ module Idrac
2
+ class Client
3
+ def initialize(url:)
4
+ @url = url
5
+ @cookies = nil
6
+ end
7
+
8
+ def login(user: 'root', password: 'calvin')
9
+ login_response = HTTParty.post(
10
+ "#{@url}/data/login",
11
+ body: { user: user, password: password },
12
+ headers: {
13
+ "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
14
+ "Accept-Encoding" => "deflate, gzip"
15
+ },
16
+ verify: false
17
+ )
18
+ @cookies = login_response.headers['set-cookie']
19
+ xml_doc = Nokogiri::XML(login_response.body)
20
+
21
+ # Extract the forwardUrl from the XML
22
+ error_message = xml_doc.at_xpath('//errorMsg')&.text
23
+ # Error Message: The maximum number of user sessions has been reached!
24
+ if error_message && !error_message.empty?
25
+ raise "Error Message: #{error_message}"
26
+ end
27
+ forward_url = xml_doc.xpath('//forwardUrl').text
28
+ end
29
+
30
+ def logout
31
+ path = "data/logout"
32
+ res = get(path: path)
33
+ raise "Invalid login." unless res.code.between?(200, 299)
34
+ end
35
+
36
+ def get(path:, headers: {})
37
+ response = HTTParty.get(
38
+ "#{@url}/#{path}",
39
+ headers: {
40
+ "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
41
+ "Accept-Encoding" => "deflate, gzip",
42
+ "Cookie" => @cookies
43
+ }.merge(headers),
44
+ verify: false
45
+ )
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,24 @@
1
+ module Idrac
2
+ # Reverse engineered the screenshot functionality in iDRAC 2.X
3
+ # Emulates the manual screenshot functionality in the web UI.
4
+ class Client
5
+ def screenshot
6
+ forward_url = login
7
+ # Extract the key-value pairs from the forward URL
8
+ # index?ST1=ABC,ST2=DEF
9
+ tokens = forward_url.split("?").last.split(",").inject({}) { |acc,kv| k,v = kv.split("="); acc[k]=v; acc }
10
+ timestamp_ms = (Time.now.to_f * 1000).to_i
11
+ path = "data?get=consolepreview[manual%20#{timestamp_ms}]"
12
+ res = get(path: path, headers: tokens)
13
+ raise "Invalid login." unless res.code.between?(200, 299)
14
+ sleep 2
15
+ path = "capconsole/scapture0.png?#{timestamp_ms}"
16
+ res = get(path: path, headers: tokens)
17
+ raise "Invalid login." unless res.code.between?(200, 299)
18
+ filename = "#{timestamp_ms}.png"
19
+ File.write(filename, res.body)
20
+ logout
21
+ filename
22
+ end
23
+ end
24
+ end
data/lib/idrac/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Idrac
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/idrac.rb CHANGED
@@ -1,8 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'httparty'
4
+ require 'nokogiri'
5
+ # If dev, required debug
6
+ require 'debug' if ENV['RUBY_ENV'] == 'development'
7
+
3
8
  require_relative "idrac/version"
9
+ require_relative "idrac/client"
10
+ require_relative "idrac/screenshot"
4
11
 
5
12
  module Idrac
6
13
  class Error < StandardError; end
7
14
  # Your code goes here...
15
+ def self.new(url:)
16
+ Client.new(url:)
17
+ end
8
18
  end
metadata CHANGED
@@ -1,15 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idrac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Siegel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-07 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: debug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
13
97
  description: A Ruby client for the Dell iDRAC API
14
98
  email:
15
99
  - "<248302+usiegj00@users.noreply.github.com>"
@@ -22,6 +106,8 @@ files:
22
106
  - Rakefile
23
107
  - idrac.gemspec
24
108
  - lib/idrac.rb
109
+ - lib/idrac/client.rb
110
+ - lib/idrac/screenshot.rb
25
111
  - lib/idrac/version.rb
26
112
  - sig/idrac.rbs
27
113
  homepage: http://github.com