Class: WLIConfig::Product::WLI_UTX_AG300

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

Overview

Product class for WLI-UTX-AG300

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip_addr, username, password) ⇒ WLI_UTX_AG300

Returns a new instance of WLI_UTX_AG300.



19
20
21
22
# File 'lib/wliconfig.rb', line 19

def initialize(ip_addr, username, password)
  @ip_addr, @username, @password = ip_addr, username, password
  @url = "http://#{ip_addr}/"
end

Instance Attribute Details

#ip_addrObject (readonly)

Returns the value of attribute ip_addr.



17
18
19
# File 'lib/wliconfig.rb', line 17

def ip_addr
  @ip_addr
end

#passwordObject (readonly)

Returns the value of attribute password.



17
18
19
# File 'lib/wliconfig.rb', line 17

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



17
18
19
# File 'lib/wliconfig.rb', line 17

def username
  @username
end

Instance Method Details

#change_config(config) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wliconfig.rb', line 24

def change_config(config)
  # print url
  $wlog.info("Attempt to access to '#{@url}'.")

  agent = create_agent()

  # fetch index page
  $wlog.info("Begin fetch index page.")
  page = agent.get(@url)
  page = fetch_main_iframe(page)
  page = page.links_with(:href => 'index.html?page=wizard_func_wlan_sta_crypto.html')[0].click
  $wlog.info("End fetch index page.")

  # fetch config page and submit config
  $wlog.info("Begin fetch config page and submit config.")
  page = fetch_main_iframe(page)
  form = page.forms[0]
  fill_config_form(form, config)
  page = form.submit
  $wlog.info("End fetch ocnfig page and submit config.")

  # fetch finish page
  $wlog.info("Begin fetch complete page.")
  page = page.forms[0].submit
  $wlog.info("End fetch complete page.")
end

#create_agentObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/wliconfig.rb', line 51

def create_agent()
  agent = Mechanize.new

  # meta refresh enable
  agent.follow_meta_refresh = true

  # basic auth config for url
  agent.add_auth(@url, @username, @password)

  agent
end

#fetch_main_iframe(page) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/wliconfig.rb', line 63

def fetch_main_iframe(page)
  # find lower frame and go
  lower = page.frames_with('lower')[0].click

  # find main iframe and go
  lower.iframes_with('main')[0].click
end

#fill_config_form(form, config) ⇒ Object



71
72
73
74
75
# File 'lib/wliconfig.rb', line 71

def fill_config_form(form, config)
  form.ssid = config.ssid
  form.authmode = config.mode 
  form.auth_pass = config.pass
end