Class: Six::Network::Panel

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/six-updater-web/vendor/plugins/six-network/lib/six/network.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



23
24
25
# File 'lib/six-updater-web/vendor/plugins/six-network/lib/six/network.rb', line 23

def http
  @http
end

Class Method Details

.get(path) ⇒ Object



67
68
69
# File 'lib/six-updater-web/vendor/plugins/six-network/lib/six/network.rb', line 67

def Panel.get(path)
  @http.get(path, @headers)
end

.loggerObject



28
29
30
# File 'lib/six-updater-web/vendor/plugins/six-network/lib/six/network.rb', line 28

def Panel.logger
  @logger
end

.login(webid, password, force = false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/six-updater-web/vendor/plugins/six-network/lib/six/network.rb', line 32

def Panel.(webid, password, force = false)
  unless @headers.nil? || force
    raise ScriptError, "You should already be logged in!"
  end
  url = URI.parse("http://stats.six-updater.net/goldberg/auth/login")
  @http = Net::HTTP.new(url.host, url.port)
  #@http.use_ssl = true

  # GET request -> so the host can set cookies
  resp, data = @http.get2(url.path, {'User-Agent' => USERAGENT})
  cookie = resp.response['set-cookie'].split('; ')[0]
  resp.body[/name="authenticity_token" type="hidden" value="(.*)" \/>/]
  auth = $1

  # POST request -> logging in
  data = "authenticity_token=#{ERB::Util.url_encode(auth)}&login[name]=#{ERB::Util.url_encode(webid)}&login[password]=#{ERB::Util.url_encode(password)}&commit=Login"
  @headers = {
    'Cookie' => cookie,
    'Referer' => url.to_s,
    'Content-Type' => 'application/x-www-form-urlencoded',
    'User-Agent' => USERAGENT
  }

  resp, data = @http.post(url.path, data, @headers)
  # resp, data = Net::HTTP.post_form(URI.parse(url),
  #                           {'login_user'=>'admin', 'login_password'=>'admin', 'authenticity_token' => auth, 'commit'=>'Login'})
  #  {'login[user]'=>'admin', 'login[password]'=>'admin', 'authenticity_token' => auth, 'commit'=>'Login'})

  # Output on the screen -> we should get either a 302 redirect (after a successful login) or an error page
  #logger.debug 'Code = ' + resp.code
  #logger.debug 'Message = ' + resp.message
#  resp.each {|key, val| puts key + ' = ' + val}
  #logger.debug data
end

.setlogger(log) ⇒ Object



24
25
26
# File 'lib/six-updater-web/vendor/plugins/six-network/lib/six/network.rb', line 24

def Panel.setlogger(log)
  @logger = log
end