Class: IwagRequester

Inherits:
Object
  • Object
show all
Defined in:
lib/imperituroard/platforms/iwag/get_iwag_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(iwag_host, iwag_login, iwag_password) ⇒ IwagRequester

Returns a new instance of IwagRequester.



7
8
9
10
11
# File 'lib/imperituroard/platforms/iwag/get_iwag_data.rb', line 7

def initialize(iwag_host, , iwag_password)
  @iwag_host = iwag_host
  @iwag_login = 
  @iwag_password = iwag_password
end

Instance Attribute Details

#iwag_hostObject

Returns the value of attribute iwag_host.



5
6
7
# File 'lib/imperituroard/platforms/iwag/get_iwag_data.rb', line 5

def iwag_host
  @iwag_host
end

#iwag_loginObject

Returns the value of attribute iwag_login.



5
6
7
# File 'lib/imperituroard/platforms/iwag/get_iwag_data.rb', line 5

def 
  @iwag_login
end

#iwag_passwordObject

Returns the value of attribute iwag_password.



5
6
7
# File 'lib/imperituroard/platforms/iwag/get_iwag_data.rb', line 5

def iwag_password
  @iwag_password
end

Instance Method Details

#iwag_get_dhcp_binding_ssh(bind_ip) ⇒ Object



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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/imperituroard/platforms/iwag/get_iwag_data.rb', line 25

def iwag_get_dhcp_binding_ssh(bind_ip)
  mac = "Unknown"
  accessinterface = "Unknown"
  hostname = "Unknown"
  ssid = "Unknown"
  iwag_thr = Thread.new do
    Net::SSH.start(iwag_host, , :password => iwag_password) do |session|
      answ_bind = session.exec!("show ip dhcp binding #{bind_ip}")
      regexp_main = /\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s{1,20}(\w{2,4}.\w{2,4}.\w{2,4}.\w{2,4})|\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s{1,20}(\w{4}.\w{4}.\w{4})/
      #regexp_main = /\r\n(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\s+(\S{13,18})\s+Sep 18 2020 07:44 PM\s+Automatic\s+Active\s+Tunnel201\r\n/
      ggg7 = answ_bind.match(regexp_main)
      begin
        if ggg7[1] != nil
          mac = mac_parse(ggg7[1])
        else
          mac = mac_parse(ggg7[2])
        end
      rescue
        mac = "Unknown"
      end
      regexp_remote_id = /Remote id :\s(\S{2,100})/
      regexp_tunnel = /Active\s{2,40}(\S{2,40})|Selecting\s{2,40}(\S{2,40})/
      regexp_curcuit_id = /Circuit id :\s(\S{2,100})/
      ggg9 = answ_bind.match(regexp_tunnel)

      begin
        if ggg9[1] != nil
          accessinterface = ggg9[1]
        else
          accessinterface = ggg9[2]
        end
      rescue
        accessinterface = "Unknown"
      end
      ggg8 = answ_bind.match(regexp_remote_id)
      ggg10 = answ_bind.match(regexp_curcuit_id)
      begin
        a1 = ggg8[1].split(":")
        hostname = a1[0]
        ssid = a1[1]
      rescue
        begin
          if ggg8[1] != nil
            if ggg8[1].include?("wireless_public_interface")
              hostname = ggg10[1]
              ssid = "Unknown"
            else
              hostname = ggg8[1]
              ssid = "Unknown"
            end
          else
            ssid = "Unknown"
            hostname = "Unknown"
          end
        rescue
          ssid = "Unknown"
          hostname = "Unknown"
        end
      end
    end
  end
  iwag_thr.join
  {"mac": mac, "iwaginterface": accessinterface, "aphostname": hostname, "SSID": ssid}
end

#mac_parse(mac) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/imperituroard/platforms/iwag/get_iwag_data.rb', line 13

def mac_parse(mac)
  a = mac.upcase
  pos = a[0] + a[1]
  if pos == "01"
    subscribers_mac = a[2] + a[3] + ":" + a[5] + a[6] + ":" + a[7] + a[8] + ":" + a[10] + a[11] + ":" + a[12] + a[13] + ":" + a[15] + a[16]
  else
    subscribers_mac = a[0] + a[1] + ":" + a[2] + a[3] + ":" + a[5] + a[6] + ":" + a[7] + a[8] + ":" + a[10] + a[11] + ":" + a[12] + a[13]
  end
  subscribers_mac
end