Class: NEWhubWifi_1

Inherits:
Object
  • Object
show all
Defined in:
lib/freewifi/mikrotik/newhub_mtik_ssh.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNEWhubWifi_1

Returns a new instance of NEWhubWifi_1.



13
14
15
16
17
18
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 13

def initialize
  @t_id_min = 10001
  @t_id_max = 65535

  @additional_func_wifi_1 = InternalFunc_1.new
end

Instance Attribute Details

#additional_func_wifi_1Object

Returns the value of attribute additional_func_wifi_1.



11
12
13
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 11

def additional_func_wifi_1
  @additional_func_wifi_1
end

#t_id_maxObject

Returns the value of attribute t_id_max.



11
12
13
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 11

def t_id_max
  @t_id_max
end

#t_id_minObject

Returns the value of attribute t_id_min.



11
12
13
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 11

def t_id_min
  @t_id_min
end

Instance Method Details

#add_eoip_for_mikr_wifi_1(bridge_name, ap_ip_address, company_name, hub1, hub2, user_hub, password_hub) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 149

def add_eoip_for_mikr_wifi_1(bridge_name, ap_ip_address, company_name, hub1, hub2, user_hub, password_hub)

  input_params = {:bridge_name => bridge_name,
                  :ap_ip_address => ap_ip_address,
                  :company_name => company_name,
                  :hub1 => hub1,
                  :hub2 => hub2,
                  :user_hub => user_hub,
                  :password_hub => password_hub
  }
  output_params = {}
  hub1_processed = ""
  hub2_processed = ""

  get_tun_id_answ = get_tun_id2_1(1, hub_get_all_eoip_tunnels_1(hub1, user_hub, password_hub)[:body][:busy_tunnel_ids])
  eoip_tunnel_name = additional_func_wifi_1.hub_tunnelname_generator_1(get_tun_id_answ[:body][:selected_tun_ids][0], company_name)

  if get_tun_id_answ[:code] == 200

    begin
      Net::SSH.start(hub1, user_hub, :password => password_hub) do |ssh|
        result = ssh.exec!("/interface eoip add remote-address=#{ap_ip_address} tunnel-id=#{get_tun_id_answ[:body][:selected_tun_ids][0]} name=#{eoip_tunnel_name}")
        result2 = ssh.exec!("/interface bridge port add bridge=#{bridge_name} interface=#{eoip_tunnel_name} unknown-multicast-flood=no unknown-unicast-flood=no")
      end
      hub1_processed = "Success"
    rescue
      hub1_processed = "Failed"
    end
    #Net::SSH.stop

    begin
      Net::SSH.start(hub2, user_hub, :password => password_hub) do |ssh|
        result = ssh.exec!("/interface eoip add remote-address=#{ap_ip_address} tunnel-id=#{get_tun_id_answ[:body][:selected_tun_ids][0]} name=#{eoip_tunnel_name}")
        result2 = ssh.exec!("/interface bridge port add bridge=#{bridge_name} interface=#{eoip_tunnel_name} unknown-multicast-flood=no unknown-unicast-flood=no")
      end
      #Net::SSH.stop
      hub2_processed = "Success"
    rescue
      hub2_processed = "Failed"
    end
    output_params = {:code => 200, :result => "add_eoip_for_mikr_wifi_1: Request completed", :body => {:eoip_tunnel_id => get_tun_id_answ[:body][:selected_tun_ids][0], :eoip_tunnel_name => eoip_tunnel_name, :hub1_processed => hub1_processed, :hub2_processed => hub2_processed}}
  else
    output_params = {:code => 500, :result => "add_eoip_for_mikr_wifi_1: Something Wrong with empty eoip tun id", :sdk => "freewifi"}
  end
  additional_func_wifi_1.printer_texter_wifi_1({:input_params => input_params, :output_params => output_params, :procedure => "add_eoip_for_mikr_wifi_1", :sdk => "freewifi"}, "debug")
  output_params
end

#ap_get_info(ap_ip_address, ap_login, ap_password) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 62

def ap_get_info(ap_ip_address, , ap_password)
  res = ""
  Net::SSH.start(ap_ip_address, , :password => ap_password) do |ssh|
    result = ssh.exec!("system identity print")
    dff = result.to_s
    res = dff.gsub!("name: ", "").gsub!("\r\n\r\n", "").gsub!(" ", "")
  end
  res
end

#ap_tun_rewrite(ap_ip_address, tun_id, ap_login, ap_password) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 72

def ap_tun_rewrite(ap_ip_address, tun_id, , ap_password)
  res = ""
  Net::SSH.start(ap_ip_address, , :password => ap_password) do |ssh|
    result = ssh.exec!("/interface eoip set tunnel_to_hab1 tunnel-id=#{tun_id} remote-address=172.24.202.145")
  end
  res
end

#capsman_add_ip_to_existed_1(ap_name_list, capsman1, capsman_user1, capsman_pass1, ap_ip) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 259

def capsman_add_ip_to_existed_1(ap_name_list, capsman1, capsman_user1, capsman_pass1, ap_ip)
  command = "/caps-man provisioning print where "

  for h in ap_name_list
    command = command + " or master-configuration=" + h
  end
  command = command.gsub("where  or", "where")

  final_provision_old = []

  Net::SSH.start(capsman1, capsman_user1, :password => capsman_pass1) do |ssh|
    result = ssh.exec!(command)
    s1 = result.split("\r\n\r\n")
    for a in s1
      a1 = a.gsub("\r\n", '')
      a2 = a1.gsub(',     ', ',')
      reg_addr_range = / (\d) .+ ip-address-ranges=(\d{1,3}.+\.\d{1,3}|\d{1,3}.+\.\d{1,3}\/\d{1,2})\s+/
      m1 = a2.scan(reg_addr_range)
      num = m1[0][0]
      ip_ran = m1[0][1].gsub(" ", "")
      triplet = [num, ip_ran]
      final_provision_old << triplet
      exists_check = self.check_pool_range_includes_1(triplet[1], ap_ip)

      if exists_check[:body][:result] != 'exists'
        #self.capsman_set_ip_range_1(capsman1, capsman_user1, capsman_pass1, ap_ip)
        #set data to capsman
        rewrite_ip_command = "/caps-man provisioning set numbers=#{triplet[0]} ip-address-ranges=#{triplet[1]},#{ap_ip}"
        p rewrite_ip_command

        ssh.exec!(rewrite_ip_command)

      end
    end
  end


end

#capsman_new_configuration_1(wifissid, capsman1, capsman_user1, capsman_pass1, ap_ip, companyname) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 238

def capsman_new_configuration_1(wifissid, capsman1, capsman_user1, capsman_pass1, ap_ip, companyname)

  conf_24ghz_name = "auto_cfg_24ghz_#{companyname}_#{wifissid}"
  command_conf_24ghz = "/caps-man configuration add name=#{conf_24ghz_name} ssid=#{wifissid} country=belarus mode=ap hw-retries=15 channel=24_channel_24GHz_dynamic_power22 datapath=1_datapath_MTS_Local-forwarding security=security_without_passphrase_default_FREE-WiFi"

  conf_5ghz_name = "auto_cfg_5ghz_#{companyname}_#{wifissid}"
  command_conf_5ghz = "/caps-man configuration add name=#{conf_5ghz_name} ssid=#{wifissid} country=belarus mode=ap hw-retries=15 channel=5_channel_5GHz_number1_power23 datapath=1_datapath_MTS_Local-forwarding security=security_without_passphrase_default_FREE-WiFi"

  command_provisioning_24ghz = "/caps-man provisioning add hw-supported-modes=b,g,gn ip-address-ranges=#{ap_ip} action=create-dynamic-enabled place-before=30 master-configuration=#{conf_24ghz_name} name-format=identity"

  command_provisioning_5ghz = "/caps-man provisioning add hw-supported-modes=a,ac,an ip-address-ranges=#{ap_ip} action=create-dynamic-enabled place-before=30 master-configuration=#{conf_5ghz_name} name-format=identity"

  Net::SSH.start(capsman1, capsman_user1, :password => capsman_pass1) do |ssh|
    result = ssh.exec!(command_conf_24ghz)
    result1 = ssh.exec!(command_conf_5ghz)
    result2 = ssh.exec!(command_provisioning_24ghz)
    result3 = ssh.exec!(command_provisioning_5ghz)
  end

end

#capsman_set_ip_range_1(capsman1, capsman_user1, capsman_pass1, ap_ip) ⇒ Object



234
235
236
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 234

def capsman_set_ip_range_1(capsman1, capsman_user1, capsman_pass1, ap_ip)

end

#check_pool_range_includes_1(range, ip_addr_new) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 203

def check_pool_range_includes_1(range, ip_addr_new)
  input_params ={:range => range, :ip_addr_new => ip_addr_new}
  output_params = {}

  begin
    res = "nothing"
    gs = range.split(",")
    for j in gs
      if j.include?("/")
        ipaddr1 = IPAddr.new ip_addr_new
        x1 = j.split("/")
        ipaddr2 = ipaddr1.mask(x1[1].to_i).to_s
        ipaddr3 = ipaddr2.to_s
        if ipaddr3 == x1[0]
          res = "exists"
        end
      else
        if j == ip_addr_new
          res = "exists"
        end
      end
    end
    output_params = {:code => 200, :result => 'check_pool_range_includes_1: Request processed', :body => {:result => res}}
  rescue
    output_params = {:code => 507, :result => 'check_pool_range_includes_1: Unknown SDK error'}
  end

  additional_func_wifi_1.printer_texter_wifi_1({:input_params => input_params, :output_params => output_params, :procedure => 'check_pool_range_includes_1', :file => 'freewifi/mikrotik/newhub_mtik_ssh.rb', :sdk => 'freewifi'}, 'debug')
  output_params
end

#del_eoip_for_mikr_1(tunnel_id, hub1, hub2, user_hub, password_hub) ⇒ Object



21
22
23
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
50
51
52
53
54
55
56
57
58
59
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 21

def del_eoip_for_mikr_1(tunnel_id, hub1, hub2, user_hub, password_hub)

  begin
    Net::SSH.start(hub1, user_hub, :password => password_hub) do |ssh|
      #result = ssh.exec!("/interface eoip print where tunnel-id=#{tunnel_id}")
      #p result
      result = ssh.exec!("/interface eoip print where tunnel-id=#{tunnel_id}")
      regimsi = /\s+name="(.+)"\s+/
      m1 = regimsi.match(result)[1]
      sleep 0.2
      result2 = ssh.exec!("/interface bridge port remove [/interface bridge port find interface=#{m1}]")
      sleep 0.2
      result3 = ssh.exec!("/interface eoip remove [/interface eoip find where tunnel-id=#{tunnel_id}]")

      #result2 = ssh.exec!("interface bridge port add bridge=#{bridge_name} interface=#{tunnel_name}")
    end
      #Net::SSH.stop
  rescue
    nil
  end

  begin
    Net::SSH.start(hub2, user_hub, :password => password_hub) do |ssh|
      result = ssh.exec!("/interface eoip print where tunnel-id=#{tunnel_id}")
      regimsi = /\s+name="(.+)"\s+/
      m1 = regimsi.match(result)[1]
      sleep 0.2
      result2 = ssh.exec!("/interface bridge port remove [/interface bridge port find interface=#{m1}]")
      sleep 0.2
      result3 = ssh.exec!("/interface eoip remove [/interface eoip find where tunnel-id=#{tunnel_id}]")

      #result = ssh.exec!("interface eoip add remote-address=#{ap_ip_address} tunnel-id=#{tunnel_id} name=#{tunnel_name}")
      #result2 = ssh.exec!("interface bridge port add bridge=#{bridge_name} interface=#{tunnel_name}")
    end
      #Net::SSH.stop
  rescue
    nil
  end
end

#get_tun_id(req_num_of_tunid, busy_tun_id) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 80

def get_tun_id(req_num_of_tunid, busy_tun_id)
  all_ids=[]
  i = t_id_min
  while i < t_id_max
    all_ids << i
    i=i+1
  end
  p all_ids
end

#get_tun_id2_1(req_num_of_tunid, busy_tun_id) ⇒ Object

procedure for tunnel id-s selection based on all_tunids array



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 91

def get_tun_id2_1(req_num_of_tunid, busy_tun_id)
  #req_num_of_tunid - integer number of necessary tun ids
  #busy_tun_id - [] dictionary of currently used tun ids with integer elements
  input_params = {:req_num_of_tunid => req_num_of_tunid, :busy_tun_id => busy_tun_id}
  output_params = {}
  all_ids = []
  req_tun_ids = []
  begin
    available_tun_id = Freewifi_1::ALL_TUNIDS - busy_tun_id
    i = 0
    while i < req_num_of_tunid
      req_tun_ids << available_tun_id[i]
      i=i+1
    end
    output_params = {:code => 200, :result => "get_tun_id2_1: Request completed", :body => {:selected_tun_ids => req_tun_ids}, :sdk => "freewifi"}
  rescue
    output_params = {:code => 500, :result => "get_tun_id2_1: Something Wrong", :sdk => "freewifi"}
  end
  additional_func_wifi_1.printer_texter_wifi_1({:input_params => input_params, :output_params => output_params, :procedure => "get_tun_id2_1"}, "debug")
  output_params
end

#hub_get_all_eoip_tunnels_1(hub_ip_address, hub_login, hub_password) ⇒ Object

universal procedure for get currently configured eoip tunnels



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 114

def hub_get_all_eoip_tunnels_1(hub_ip_address, , hub_password)
  input_params = {:hub_ip_address => hub_ip_address, :hub_login => , :hub_password => hub_password}
  output_params = {}
  result = ""
  busy_tunnel_ids = []
  begin
    ssh_connection = Net::SSH.start(hub_ip_address, , :password => hub_password) do |ssh|
      result = ssh.exec!("/interface eoip print where tunnel-id>=#{t_id_min.to_s} tunnel-id<=#{t_id_max.to_s}")
    end
    #p ssh_connection.
    reg_tunnelid = /tunnel-id=(\d+)/
    m1 = result.scan(reg_tunnelid)
    for a1 in m1
      if a1[0] != []
        s1 = a1[0].to_i
        busy_tunnel_ids << s1
      end
    end
    output_params = {:code => 200, :result => "hub_get_all_eoip_tunnels_1: Request completed", :body => {:busy_tunnel_ids => busy_tunnel_ids}, :sdk => "freewifi"}

  rescue
    output_params = {:code => 500, :result => "hub_get_all_eoip_tunnels_1: Something Wrong", :sdk => "freewifi"}
  end

  additional_func_wifi_1.printer_texter_wifi_1({:input_params => input_params, :output_params => output_params, :procedure => "hub_get_all_eoip_tunnels_1"}, "debug")
  output_params

  #m1 = reg_tunnelid.scan(result)
  #p busy_tunnel_ids
  #g = result.split("\r\n\r\n")
  #p g
  #result
end

#mikr_tunnelid_genObject



198
199
200
201
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 198

def mikr_tunnelid_gen()
  t_id_min = 10001
  t_id_max = 65535
end

#set_capsman_config_1(wifissid, capsman1, capsman_user1, capsman_pass1, ap_ip, companyname) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/freewifi/mikrotik/newhub_mtik_ssh.rb', line 299

def set_capsman_config_1(wifissid, capsman1, capsman_user1, capsman_pass1, ap_ip, companyname)
  input_params ={:wifissid => wifissid,
                 :capsman1 => capsman1,
                 :capsman_user1 => capsman_user1,
                 :capsman_pass1 => capsman_pass1,
                 :ap_ip => ap_ip,
                 :companyname => companyname
  }
  output_params = {}

  begin
  Net::SSH.start(capsman1, capsman_user1, :password => capsman_pass1) do |ssh|
    result = ssh.exec!("/caps-man configuration print where ssid=#{wifissid}")
    if result == "\r\n" || result == "" || result == nil
      self.capsman_new_configuration_1(wifissid, capsman1, capsman_user1, capsman_pass1, ap_ip, companyname)
    else
      p result
      conf_names = []
      reg_config_name = /name="(\S+)"/
      m1 = result.scan(reg_config_name)
      for a1 in m1
        if a1[0] != []
          s1 = a1[0]
          conf_names << s1
        end
      end
      self.capsman_add_ip_to_existed_1(conf_names, capsman1, capsman_user1, capsman_pass1, ap_ip)
    end
  end
  rescue
    output_params = {:code => 507, :result => 'set_capsman_config_1: Unknown SDK error'}
  end

  additional_func_wifi_1.printer_texter_wifi_1({:input_params => input_params, :output_params => output_params, :procedure => "set_capsman_config_1", :file => "freewifi/mikrotik/newhub_mtik_ssh.rb", :sdk => "freewifi"}, "debug")
  output_params

end