class Moob::SunILom

Public Class Methods

new(hostname, options = {}) click to toggle source
Calls superclass method Moob::BaseLom::new
# File lib/moob/sunilom.rb, line 5
def initialize hostname, options = {}
  super hostname, options
  @username ||= 'root'
  @password ||= 'changeme'
end

Public Instance Methods

authenticate() click to toggle source
# File lib/moob/sunilom.rb, line 11
def authenticate
  auth = @session.post 'iPages/loginProcessor.asp', {
    'username' => @username,
    'password' => @password
  }

  raise ResponseError.new auth unless auth.status == 200

  if auth.body =~ /\/iPages\/i_login.asp\?msg=([^"])+"/
    error = "code #{$1}"
    error_page = @session.get "iPages/i_login.asp?msg=#{$1}"
    if error_page.body =~ /<div class="AlrtErrTxt">(.*?)<\/div>/
      error = "\"#{$1.gsub /<[^>]+>/, ''}\""
    end

    raise "Auth failed (#{error})"
  end

  auth.body =~ /SetWebSessionString\("([^"]+)","([^"]+)"\);/
  raise "Couldn't find session cookie in \"#{auth.body}\"" unless $&

  @cookie = "#{$1}=#{$2}; langsetting=EN"
  return self
end
detect() click to toggle source
# File lib/moob/sunilom.rb, line 44
def detect
  begin
    home = @session.get 'iPages/i_login.asp'
    home.body =~ /Sun\(TM\) Sun Integrated Lights Out Manager/
  rescue
    false
  end
end
jnlp() click to toggle source
# File lib/moob/sunilom.rb, line 37
def jnlp
  viewer = @session.get 'cgi-bin/jnlpgenerator-8', { 'Cookie' => @cookie }
  raise ResponseError.new viewer unless viewer.status == 200

  return viewer.body
end