freewifi 0.1.6 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,4 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency "mysql2", "0.5.3"
41
41
  spec.add_development_dependency "mongo", "2.11.4"
42
42
  spec.add_development_dependency "translit", "0.1.5"
43
+ spec.add_development_dependency "savon", "2.12.0"
44
+ spec.add_development_dependency "net-telnet", "0.2.0"
45
+ spec.add_development_dependency "mtik", "4.0.3"
43
46
  end
@@ -3,6 +3,8 @@ $LOAD_PATH.unshift File.expand_path("../mikrotik", __dir__)
3
3
  $LOAD_PATH.unshift File.expand_path("../database/mysql", __dir__)
4
4
  $LOAD_PATH.unshift File.expand_path("../database/mongo", __dir__)
5
5
  $LOAD_PATH.unshift File.expand_path("../additional", __dir__)
6
+ $LOAD_PATH.unshift File.expand_path("../general", __dir__)
7
+ $LOAD_PATH.unshift File.expand_path("../huawei", __dir__)
6
8
 
7
9
  require "freewifi/version"
8
10
  require "freewifi/params"
@@ -11,6 +13,7 @@ require 'freewifi/mikrotik/newhub_mtik_ssh'
11
13
  require 'freewifi/mikrotik/schemes_conf_gen'
12
14
  require 'freewifi/database/mysql/database_methods_wifi'
13
15
  require 'freewifi/database/mongo/mongoconnector'
16
+ require 'freewifi/general/wifi_portal_procedures'
14
17
  require 'date'
15
18
  require 'json'
16
19
 
@@ -36,10 +39,36 @@ module Freewifi_1
36
39
  :mtik_config_gen_1,
37
40
  :hub_vip,
38
41
  :ap_admin_password,
39
- :capsman_ip_wifi
42
+ :capsman_ip_wifi,
43
+ :apigw_wsdl,
44
+ :apigw_endpoint,
45
+ :apigw_namespace,
46
+ :apigw_wsse_aut_log,
47
+ :apigw_wsse_aut_pass,
48
+ :general_procedures
49
+
50
+
51
+ def initialize(hub1ip,
52
+ hub2ip,
53
+ username_hub,
54
+ password_hub,
55
+ database_username,
56
+ database_password,
57
+ database_host,
58
+ mongo_ip,
59
+ mongo_port,
60
+ mongo_database,
61
+ remote_ip,
62
+ real_ip,
63
+ subscriber_ip,
64
+ capsman_ip_man,
65
+ capsman_user,
66
+ capsman_password,
67
+ hub_vip,
68
+ ap_admin_password,
69
+ capsman_ip_wifi
70
+ )
40
71
 
41
-
42
- def initialize(hub1ip, hub2ip, username_hub, password_hub, database_username, database_password, database_host, mongo_ip, mongo_port, mongo_database, remote_ip, real_ip, subscriber_ip, capsman_ip_man, capsman_user, capsman_password, hub_vip, ap_admin_password, capsman_ip_wifi)
43
72
  @mtik_hub1_ip = hub1ip
44
73
  @mtik_hub2_ip = hub2ip
45
74
  @user_hub = username_hub
@@ -58,9 +87,12 @@ module Freewifi_1
58
87
  @hub_vip = hub_vip
59
88
  @ap_admin_password = ap_admin_password
60
89
  @capsman_ip_wifi = capsman_ip_wifi
90
+
91
+
61
92
  end
62
93
 
63
94
 
95
+ #1 procedure for creation mikrotik AP
64
96
  def add_mikrotik_ap_mobile_1(sim_ipaddress, sim_msisdn, bridge_name_hub, company_name, subscribers_address, subscribers_region, subscribers_contacts, wifi_ssid, portalstyle, ap_serial_number, ap_model, description, note)
65
97
 
66
98
  input_params = {:sim_ipaddress => sim_ipaddress,
@@ -126,7 +158,7 @@ module Freewifi_1
126
158
  wifi_ssid_processed = additional_func_wifi_1.prep_ssid_for_config_1(wifi_ssid)
127
159
  company_name_processed = additional_func_wifi_1.prep_comp_name_for_config_1(company_name)
128
160
 
129
- input_intern_data = {:wifi_ssid_processed =>wifi_ssid_processed, :company_name_processed =>company_name_processed, :capsman => capsman}
161
+ input_intern_data = {:wifi_ssid_processed => wifi_ssid_processed, :company_name_processed => company_name_processed, :capsman => capsman}
130
162
 
131
163
  mongo_connector_wifi_1.audit_logger_wifi_1("add_mikrotik_ap_mobile_1", remote_ip, input_intern_data, nil, real_ip, subscriber_ip)
132
164
 
@@ -134,7 +166,7 @@ module Freewifi_1
134
166
  end
135
167
  end
136
168
  threads_1.each(&:join)
137
-
169
+
138
170
  output_params = {:code => 200, :result => "Request completed successfully", :body => {:tunnel_id => tunnel_addition[:body][:eoip_tunnel_id], :tunnel_name => tunnel_addition[:body][:eoip_tunnel_name]}}
139
171
  else
140
172
  output_params = {:code => 400, :result => "Something wrong with insertion to mongo"}
@@ -154,6 +186,8 @@ module Freewifi_1
154
186
  end
155
187
 
156
188
 
189
+ #2 procedure for generation configuration for mikrotik AP
190
+ #scheme 1 MikroTik throw mobile network
157
191
  def mtik_sch1_config_gen_1(sim_ipaddress, sim_msisdn, bridge_name_hub, company_name, subscribers_address, subscribers_region, subscribers_contacts, wifi_ssid, portalstyle, ap_serial_number, ap_model, description, note)
158
192
  input_params = {:sim_ipaddress => sim_ipaddress,
159
193
  :sim_msisdn => sim_msisdn,
@@ -232,5 +266,101 @@ class Fwifi_1
232
266
  end
233
267
 
234
268
 
269
+ class PortalFwifi_1
270
+
271
+ attr_accessor :general_procedures,
272
+ :mtik_control_ips_get,
273
+ :mtik_user,
274
+ :mtik_password,
275
+ :mongo_connector_wifi_1,
276
+ :telegram_api_url,
277
+ :telegram_chat_id,
278
+ :mongo_ip,
279
+ :mongo_port,
280
+ :mongo_database,
281
+ :additional_func_wifi_1
282
+
283
+
284
+ def initialize(apigw_wsdl,
285
+ apigw_endpoint,
286
+ apigw_namespace,
287
+ apigw_wsse_aut_log,
288
+ apigw_wsse_aut_pass,
289
+ iwag1_host,
290
+ iwag_username,
291
+ iwag_password,
292
+ mtik_control_ips_get,
293
+ mtik_user,
294
+ mtik_password,
295
+ mongo_ip,
296
+ mongo_port,
297
+ mongo_database,
298
+ hua_wlc_1_ip,
299
+ hua_wlc_2_ip,
300
+ hua_wlc_login,
301
+ hua_wlc_password,
302
+ telegram_api_url,
303
+ telegram_chat_id
304
+ )
305
+
306
+ @general_procedures = WiFiPortal_1.new(apigw_wsdl,
307
+ apigw_endpoint,
308
+ apigw_namespace,
309
+ apigw_wsse_aut_log,
310
+ apigw_wsse_aut_pass,
311
+ iwag1_host,
312
+ iwag_username,
313
+ iwag_password,
314
+ mtik_control_ips_get,
315
+ mtik_user,
316
+ mtik_password,
317
+ hua_wlc_1_ip,
318
+ hua_wlc_2_ip,
319
+ hua_wlc_login,
320
+ hua_wlc_password
321
+ )
322
+ @mtik_control_ips_get = mtik_control_ips_get
323
+ @mtik_user = mtik_user
324
+ @mtik_password = mtik_password
325
+ @additional_func_wifi_1 = InternalFunc_1.new
326
+ @telegram_api_url = telegram_api_url
327
+ @telegram_chat_id = telegram_chat_id
328
+ @mongo_ip = mongo_ip
329
+ @mongo_port = mongo_port
330
+ @mongo_database = mongo_database
331
+ end
332
+
333
+
334
+ def wifi_get_subs_info_return_1(ipaddress, remote_ip, real_ip)
335
+ input_params = {:ipaddress => ipaddress}
336
+ output_params = {}
337
+
338
+ subs_info_ret_1_thr1 = Thread.new do
339
+ begin
340
+ resp_procedure = general_procedures.get_subs_info_return_1(ipaddress)
341
+ output_params = resp_procedure
342
+ rescue
343
+ output_params = {:code => 507, :result => "Unknown SDK error"}
344
+ end
345
+ end
346
+ subs_info_ret_1_thr1.join
347
+
348
+ subs_info_ret_1_thr2 = Thread.new do
349
+ begin
350
+ p "mongo"
351
+ #mongo_connector_wifi_1 = MongoWifiCl_1.new(mongo_ip, mongo_port, mongo_database)
352
+ #mongo_connector_wifi_1.audit_logger_wifi_portal_1("wifi_get_subs_info_return_1", remote_ip, input_params, output_params, real_ip)
353
+ rescue
354
+ additional_func_wifi_1.printer_texter_wifi_1({:input_params => input_params, :output_params => {:result => "mongo failed"}, :procedure => "wifi_get_subs_info_return_1", :file => "freewifi.rb"}, "debug")
355
+ additional_func_wifi_1.telegram_message_1("{:function => \"wifi_get_subs_info_return_1\", :result => \"failed communicate with mongo database\", :sdk => \"freewifi\"}", telegram_api_url, telegram_chat_id)
356
+ end
357
+ end
358
+ subs_info_ret_1_thr2.join
359
+
360
+ output_params
361
+ end
362
+
363
+ end
364
+
235
365
  #tested on 6.46.2 router os
236
366
 
@@ -12,6 +12,25 @@ class InternalFunc_1
12
12
  d_curr.to_s
13
13
  end
14
14
 
15
+ def telegram_message_1(message, telegram_api_url, telegram_chat_id)
16
+ begin
17
+ uri = URI.parse(telegram_api_url)
18
+ https_connector = Net::HTTP.new(uri.host, uri.port)
19
+ https_connector.use_ssl = true
20
+ data = {chat_id: telegram_chat_id, text: message}
21
+ request_mess = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' => 'application/json'})
22
+ request_mess.body = data.to_json
23
+ response_mess = https_connector.request(request_mess)
24
+ body = response_mess.body
25
+ return {:code => 200,
26
+ :result => "Request completed successfully",
27
+ :body => {:telegram_resp => JSON.parse(body.to_s),
28
+ :description => "Telegram message to telegram_chat_id: #{telegram_chat_id.to_s}"}}
29
+ rescue
30
+ return {:code => 507, :result => "Unknown SDK error"}
31
+ end
32
+ end
33
+
15
34
  def printer_texter_wifi_1(text, log_level)
16
35
  begin
17
36
  if log_level == "debug" && Freewifi_1::LOGLEVEL_1 == "debug"
@@ -9,4 +9,5 @@ class CiscoSchemesGen_1
9
9
 
10
10
  end
11
11
 
12
- end
12
+ end
13
+
@@ -0,0 +1,112 @@
1
+ require 'net-telnet'
2
+ require 'net/ssh'
3
+ require 'date'
4
+
5
+ class CSRtelnet_1
6
+
7
+ attr_accessor :iwag1_host, :iwag_username, :iwag_password
8
+
9
+ def initialize(iwag1_host, iwag_username, iwag_password)
10
+ @iwag1_host = iwag1_host
11
+ @iwag_username = iwag_username
12
+ @iwag_password = iwag_password
13
+ end
14
+
15
+ def get_subs_mac2_1(ipaddress)
16
+
17
+ subscribers_mac = ""
18
+
19
+ #begin
20
+
21
+ dump =""
22
+ connection = Net::Telnet.new( "Host" => iwag1_host, "Timeout" => false, "Prompt" => /.*\#/ ) { |str| }
23
+ connection.login({ "Name" => iwag_username, "Password" => iwag_password, "LoginPrompt" => /Username:/ }) { |str| }
24
+ connection.cmd("show ip dhcp binding #{ipaddress}") {
25
+ |c|
26
+ p c
27
+ dump << c
28
+ }
29
+ connection.close
30
+ as = dump.split("\n")
31
+ p as
32
+ reer = as[4].split(" ")
33
+
34
+ ma = reer[1].to_s.upcase
35
+ pos = ma[0]+ma[1]
36
+ if pos=="01"
37
+ subscribers_mac = ma[2]+ma[3]+":"+ma[5]+ma[6]+":"+ma[7]+ma[8]+":"+ma[10]+ma[11]+":"+ma[12]+ma[13]+":"+ma[15]+ma[16]
38
+ else
39
+ subscribers_mac = ma[0]+ma[1]+":"+ma[2]+ma[3]+":"+ma[5]+ma[6]+":"+ma[7]+ma[8]+":"+ma[10]+ma[11]+":"+ma[12]+ma[13]
40
+ end
41
+
42
+
43
+ #rescue
44
+ # subscribers_mac = "unknown"
45
+ #end
46
+
47
+ return subscribers_mac
48
+
49
+ end
50
+
51
+
52
+ #test function. Not used
53
+ def get_iwag_info_ssh_1(ipaddress)
54
+ p DateTime.now
55
+ Net::SSH.start(iwag1_host, iwag_username, :password => iwag_password) do |ssh|
56
+ result = ssh.exec!("show ip dhcp binding #{ipaddress}\n")
57
+ p result
58
+ end
59
+ p DateTime.now
60
+ end
61
+
62
+
63
+
64
+ def return_iwag_access_interface_1(ipaddress)
65
+ host_iwag = iwag1_host
66
+ username_iwag = iwag_username
67
+ password_iwag = iwag_password
68
+ answer =""
69
+
70
+ dump =""
71
+ begin
72
+ connection = Net::Telnet.new("Host" => host_iwag, "Timeout" => false, "Prompt" => /.*\#/) {|str| print str}
73
+ connection.login({"Name" => username_iwag, "Password" => password_iwag, "LoginPrompt" => /Username:/}) {|str| print str}
74
+ connection.cmd("show ip dhcp binding #{ipaddress}") {
75
+ |c|
76
+ dump << c
77
+ }
78
+ connection.close
79
+ as = dump.split("\n")
80
+
81
+ if as[4] != nil && as[3] != ""
82
+ access_interface = as[4].gsub!(" ", "").split(" ").last
83
+ return access_interface
84
+ else
85
+ answer ="false"
86
+ return answer
87
+ end
88
+ rescue
89
+ begin
90
+ connection = Net::Telnet.new("Host" => host_iwag, "Timeout" => false, "Prompt" => /.*\#/) {|str| print str}
91
+ connection.login({"Name" => username_iwag, "Password" => password_iwag, "LoginPrompt" => /Username:/}) {|str| print str}
92
+ connection.cmd("show ip dhcp binding #{ipaddress}") {
93
+ |c|
94
+ dump << c
95
+ }
96
+ connection.close
97
+ as = dump.split("\n")
98
+ if as[4] != nil && as[3] != ""
99
+ access_interface = as[4].gsub!(" ", "").split(" ").last
100
+ return access_interface
101
+ else
102
+ answer ="false"
103
+ return answer
104
+ end
105
+ rescue
106
+ return "unknown"
107
+ end
108
+ end
109
+ end
110
+
111
+
112
+ end
@@ -1,4 +1,5 @@
1
1
  module Freewifi_1
2
2
  LOGLEVEL_1 = "debug"
3
+
3
4
  end
4
5
 
@@ -14,7 +14,7 @@ class MongoWifiCl_1
14
14
  @mongo_ip = mongo_ip
15
15
  @mongo_port = mongo_port
16
16
  client_host = [mongo_ip + ":" + mongo_port]
17
- @client = Mongo::Client.new(client_host, :database => mongo_database)
17
+ @client = Mongo::Client.new(client_host, :database => mongo_database, :connect_timeout => 2)
18
18
 
19
19
  @additional_func_1 = InternalFunc_1.new
20
20
  end
@@ -41,6 +41,28 @@ class MongoWifiCl_1
41
41
  out_resp
42
42
  end
43
43
 
44
+ def audit_logger_wifi_portal_1(proc_name, src_ip, input_json, output_json, real_ip)
45
+ out_resp = {}
46
+ begin
47
+ current = additional_func_1.datetimenow_1
48
+ collection = client[:audit_portal]
49
+ doc = {
50
+ :proc_name => proc_name,
51
+ :date => current,
52
+ :sender => {:src_ip => src_ip, :real_ip => real_ip},
53
+ :input_params => input_json,
54
+ :output_params => output_json,
55
+ :sdk_version => Freewifi_1::VERSION
56
+ }
57
+ result = collection.insert_one(doc)
58
+ out_resp = {:code => 200, :result => "audit_logger_wifi_1: Request completed successfully", :body => result, :sdk => "freewifi"}
59
+ rescue
60
+ out_resp = {:code => 507, :result => "audit_logger_wifi_1: Unknown SDK error", :sdk => "freewifi"}
61
+ end
62
+ additional_func_1.printer_texter_wifi_1(out_resp, "debug")
63
+ out_resp
64
+ end
65
+
44
66
 
45
67
  def data_ap_auto_created_insert_1(data)
46
68
  input_params = {:data => data}
@@ -97,4 +119,6 @@ class MongoWifiCl_1
97
119
  out_resp
98
120
  end
99
121
 
122
+
123
+
100
124
  end
@@ -0,0 +1,630 @@
1
+ $LOAD_PATH.unshift File.expand_path("../cisco/iwag", __dir__)
2
+ $LOAD_PATH.unshift File.expand_path("../mikrotik", __dir__)
3
+ $LOAD_PATH.unshift File.expand_path("../huawei", __dir__)
4
+
5
+ require 'freewifi/cisco/iwag/iwag_telnet_connector'
6
+ require 'freewifi/mikrotik/newhub_mtik_api'
7
+ require 'freewifi/huawei/hua_controller_class'
8
+ require 'rubygems'
9
+ require 'savon'
10
+
11
+ class WiFiPortal_1
12
+ attr_accessor :iwag_telnet_connector,
13
+ :ard_api_gw_connector_wifi,
14
+ :iwag1_host,
15
+ :iwag_username,
16
+ :iwag_password,
17
+ :mtik_control_ips_get,
18
+ :mtik_user,
19
+ :mtik_password,
20
+ :mtik_api_connector,
21
+ :hua_controller_connector
22
+
23
+ def initialize(apigw_wsdl, apigw_endpoint, apigw_namespace, apigw_wsse_aut_log, apigw_wsse_aut_pass, iwag1_host, iwag_username, iwag_password, mtik_control_ips_get, mtik_user, mtik_password, hua_wlc_1_ip, hua_wlc_2_ip, hua_wlc_login, hua_wlc_password)
24
+ @iwag_telnet_connector = CSRtelnet_1.new(iwag1_host, iwag_username, iwag_password)
25
+ @ard_api_gw_connector_wifi = Savon.client do
26
+ #ssl_verify_mode :none
27
+ wsdl apigw_wsdl
28
+ endpoint apigw_endpoint
29
+ namespace apigw_namespace
30
+ wsse_auth(apigw_wsse_aut_log, apigw_wsse_aut_pass, :digest)
31
+ encoding 'UTF-8'
32
+ headers = {"Accept-Encoding" => "gzip, deflate", "Connection" => "Keep-Alive"}
33
+ end
34
+
35
+ @iwag1_host = iwag1_host
36
+ @iwag_username = iwag_username
37
+ @iwag_password = iwag_password
38
+
39
+ @mtik_api_connector = NEWhubWifiApi_1.new(mtik_control_ips_get, mtik_user, mtik_password)
40
+
41
+ @hua_controller_connector = HuaWifi_1.new(hua_wlc_1_ip, hua_wlc_2_ip, hua_wlc_login, hua_wlc_password)
42
+
43
+ end
44
+
45
+
46
+ def python_mac_iwag1_1(ipaddress)
47
+ begin
48
+ response = ard_api_gw_connector_wifi.call(:mts_python_mac_iwag1) do
49
+ message({:ipaddress => ipaddress})
50
+ end
51
+ answer = response.to_hash
52
+ return answer[:mts_python_mac_iwag1_response][:data].gsub("\n", "")
53
+ rescue
54
+ return "Unknown Unknown Unknown Unknown"
55
+ end
56
+ end
57
+
58
+ def python_mac_iwag2_1(ipaddress)
59
+ begin
60
+ response = ard_api_gw_connector_wifi.call(:mts_python_mac_iwag2) do
61
+ message({:ipaddress => ipaddress})
62
+ end
63
+ answer = response.to_hash
64
+ return answer[:mts_python_mac_iwag2_response][:data].gsub("\n", "")
65
+ rescue
66
+ return "Unknown Unknown Unknown Unknown"
67
+ end
68
+ end
69
+
70
+ def get_subs_add_info3_1(ipaddress, access_interface)
71
+
72
+
73
+ answer = ""
74
+
75
+ #region get additional information
76
+ if access_interface != "false"
77
+
78
+ subscribers_mac = ""
79
+
80
+ begin
81
+
82
+ dump =""
83
+ connection = Net::Telnet.new("Host" => "172.24.247.183", "Timeout" => false, "Prompt" => /.*\#/) {|str|}
84
+ connection.login({"Name" => iwag_username, "Password" => iwag_password, "LoginPrompt" => /Username:/}) {|str|}
85
+ connection.cmd("show ip dhcp binding #{ipaddress}") {
86
+ |c|
87
+ dump << c
88
+ }
89
+ connection.close
90
+ as = dump.split("\n")
91
+ reer = as[4].split(" ")
92
+
93
+ ma = reer[1].to_s.upcase
94
+ pos = ma[0]+ma[1]
95
+ if pos=="01"
96
+ subscribers_mac = ma[2]+ma[3]+":"+ma[5]+ma[6]+":"+ma[7]+ma[8]+":"+ma[10]+ma[11]+":"+ma[12]+ma[13]+":"+ma[15]+ma[16]
97
+ else
98
+ subscribers_mac = ma[0]+ma[1]+":"+ma[2]+ma[3]+":"+ma[5]+ma[6]+":"+ma[7]+ma[8]+":"+ma[10]+ma[11]+":"+ma[12]+ma[13]
99
+ end
100
+
101
+ rescue
102
+ subscribers_mac = "unknown"
103
+ end
104
+
105
+
106
+ begin
107
+ thr0 = Thread.new do
108
+ begin
109
+ p mikr_info5 = mtik_api_connector.get_info_subs_from_mik_1(subscribers_mac, "172.24.247.15")
110
+ splitting5 = mikr_info5.split("---")
111
+ if splitting5[1] != "not on mikrotik controller" && splitting5[1]!="unknown" && splitting5[1]!=nil
112
+ answer = mikr_info5
113
+ end
114
+ rescue
115
+ p "thr1 wrong"
116
+ end
117
+ end
118
+ rescue
119
+ p "thread 0 failed"
120
+ end
121
+
122
+
123
+ begin
124
+ thr1 = Thread.new do
125
+ begin
126
+ p mikr_info7 = mtik_api_connector.get_info_subs_from_mik_1(subscribers_mac, "172.24.214.155")
127
+ splitting7 = mikr_info7.split("---")
128
+ if splitting7[1] != "not on mikrotik controller" && splitting7[1]!="unknown" && splitting7[1]!=nil
129
+ answer = mikr_info7
130
+ end
131
+ rescue
132
+ p "thr1 wrong"
133
+ end
134
+ end
135
+ rescue
136
+ p "thread 1 failed"
137
+ end
138
+
139
+
140
+ begin
141
+ thr2 = Thread.new do
142
+ begin
143
+ p mikr_info9 = mtik_api_connector.get_info_subs_from_mik_1(subscribers_mac, "172.24.214.140")
144
+ splitting9 = mikr_info9.split("---")
145
+ if splitting9[1] != "not on mikrotik controller" && splitting9[1]!="unknown" && splitting9[1]!=nil
146
+ answer = mikr_info9
147
+ end
148
+ rescue
149
+ p "thr2 wrong"
150
+ end
151
+ end
152
+ rescue
153
+ p "thread 2 failed"
154
+ end
155
+
156
+
157
+ begin
158
+ thr3 = Thread.new do
159
+ begin
160
+ p mikr_info9 = mtik_api_connector.get_info_subs_from_mik_1(subscribers_mac, "172.24.214.105")
161
+ splitting9 = mikr_info9.split("---")
162
+ if splitting9[1] != "not on mikrotik controller" && splitting9[1]!="unknown" && splitting9[1]!=nil
163
+ answer = mikr_info9
164
+ end
165
+ rescue
166
+ p "thr3 wrong"
167
+ end
168
+ end
169
+ rescue
170
+ p "thread 3 failed"
171
+ end
172
+
173
+ begin
174
+ thr4 = Thread.new do
175
+ begin
176
+ p mikr_info9 = mtik_api_connector.get_info_subs_from_mik_1(subscribers_mac, "172.24.223.105")
177
+ splitting9 = mikr_info9.split("---")
178
+ if splitting9[1] != "not on mikrotik controller" && splitting9[1]!="unknown" && splitting9[1]!=nil
179
+ answer = mikr_info9
180
+ end
181
+ rescue
182
+ p "thr4 wrong"
183
+ end
184
+ end
185
+ rescue
186
+ p "thread 4 failed"
187
+ end
188
+
189
+
190
+ thr0.join
191
+ thr1.join
192
+ thr2.join
193
+ thr3.join
194
+ thr4.join
195
+
196
+ if answer==""
197
+ answer = subscribers_mac + "---" + "not on mikrotik controller" + "---" + "unknown" + "---" + "unknown" + "---"+ "unknown" + "---"+ "unknown" + "---"+ "unknown" + "---"+ "unknown" + "---"+ "unknown" + "---"+ "unknown"
198
+ end
199
+
200
+ end
201
+
202
+
203
+ return answer
204
+
205
+ end
206
+
207
+
208
+ def get_subs_add_info4new_1(access_interface, subscribers_mac)
209
+
210
+ capsman_list = [
211
+ "172.24.247.15",
212
+ "172.24.214.155",
213
+ "172.24.214.140",
214
+ "172.24.214.105",
215
+ "172.24.223.105"
216
+ ]
217
+
218
+ answer = ""
219
+
220
+ #region get additional information
221
+ if access_interface != "false"
222
+
223
+ p subscribers_mac
224
+
225
+ threads_mikro_wlc = []
226
+ capsman_list.each do |capsman|
227
+ threads_mikro_wlc << Thread.new do
228
+ begin
229
+ p mikr_info5 = mtik_api_connector.get_info_subs_from_mik_1(subscribers_mac, capsman)
230
+ splitting5 = mikr_info5.split("---")
231
+ if splitting5[1] != "not on mikrotik controller" && splitting5[1]!="unknown" && splitting5[1]!=nil
232
+ answer = mikr_info5
233
+ p answer
234
+ end
235
+ rescue
236
+ p "thr0 wrong"
237
+ end
238
+ end
239
+ end
240
+ threads_mikro_wlc.each(&:join)
241
+
242
+ if answer==""
243
+ answer = subscribers_mac + "---" + "not on mikrotik controller" + "---" + "unknown" + "---" + "unknown" + "---"+ "unknown" + "---"+ "unknown" + "---"+ "unknown" + "---"+ "unknown" + "---"+ "unknown" + "---"+ "unknown"
244
+ end
245
+ end
246
+ answer
247
+ end
248
+
249
+ def proc_100_71_0_0(ip_address)
250
+ begin
251
+ p access_int = iwag_telnet_connector.return_iwag_access_interface_1(ip_address)
252
+
253
+ ip_a = ip_address
254
+
255
+ access_poi = "unknown"
256
+ ssid_a = "unknown"
257
+ tx_rate_se = "unknown"
258
+ tx_rat = "unknown"
259
+ rx_rat = "unknown"
260
+ rx_signa = "unknown"
261
+ uptim = "unknown"
262
+ packet = "unknown"
263
+ byt = "unknown"
264
+
265
+ if access_int == "Tunnel5"
266
+ mikr_info2 = self.get_subs_add_info3_1(ip_address, access_int)
267
+ splitting2 = mikr_info2.split("---")
268
+ subs_mac = splitting2[0]
269
+ access_poi = "belrw_3_Cisco_ap1-1"
270
+ ssid_a = "BelRW_WiFi"
271
+ tx_rate_se = "unknown"
272
+ tx_rat = "unknown"
273
+ rx_rat = "unknown"
274
+ rx_signa = "unknown"
275
+ uptim = "unknown"
276
+ packet = "unknown"
277
+ byt = "unknown"
278
+ elsif access_int == "GigabitEthernet2.4008"
279
+ mikr_info3 = self.get_subs_add_info3_1(ip_address, access_int)
280
+ splitting3 = mikr_info3.split("---")
281
+ subs_mac = splitting3[0]
282
+ access_poi = "belrw_4_HP_ap1-1"
283
+ ssid_a = "BelRW_WiFi"
284
+ tx_rate_se = "unknown"
285
+ tx_rat = "unknown"
286
+ rx_rat = "unknown"
287
+ rx_signa = "unknown"
288
+ uptim = "unknown"
289
+ packet = "unknown"
290
+ byt = "unknown"
291
+ elsif access_int == "Tunnel9"
292
+ subs_mac = iwag_telnet_connector.get_subs_mac2_1(ip_address)
293
+ p resp1 = hua_controller_connector.get_sub_info_1(subs_mac)
294
+ p resp=resp1.split(",,,")
295
+
296
+ p access_poi = resp[1]
297
+ p ssid_a = resp[2]
298
+ p tx_rate_se = resp[3]
299
+ p tx_rat = resp[4]
300
+ p rx_rat = resp[5]
301
+ p rx_signa = resp[6]
302
+ p uptim = resp[7]
303
+ p packet = resp[8]
304
+ p byt = resp[9]
305
+ elsif access_int == "Tunnel16"
306
+ subs_mac = iwag_telnet_connector.get_subs_mac2_1(ip_address)
307
+ p resp1 = hua_controller_connector.get_sub_info2_1(subs_mac)
308
+ p resp=resp1.split(",,,")
309
+
310
+ p access_poi = resp[1]
311
+ p ssid_a = resp[2]
312
+ p tx_rate_se = resp[3]
313
+ p tx_rat = resp[4]
314
+ p rx_rat = resp[5]
315
+ p rx_signa = resp[6]
316
+ p uptim = resp[7]
317
+ p packet = resp[8]
318
+ p byt = resp[9]
319
+ else
320
+ p "before get info"
321
+ p mikr_info5 = self.get_subs_add_info3_1(ip_address, access_int)
322
+ p "after get info"
323
+ splitting5 = mikr_info5.split("---")
324
+ p subs_mac = splitting5[0]
325
+
326
+ p access_poi = splitting5[1]
327
+ p ssid_a = splitting5[2]
328
+ p tx_rate_se = splitting5[3]
329
+ p tx_rat = splitting5[4]
330
+ p rx_rat = splitting5[5]
331
+ p rx_signa = splitting5[6]
332
+ p uptim = splitting5[7]
333
+ p packet = splitting5[8]
334
+ p byt = splitting5[9]
335
+
336
+
337
+ if access_poi==nil || access_poi=="" || access_poi=="unknown"
338
+ access_poi = "not on mikrotik controller"
339
+ end
340
+
341
+ if ssid_a==nil || ssid_a=="" || ssid_a=="unknown"
342
+ ssid_a = "unknown"
343
+ tx_rate_se = "unknown"
344
+ tx_rat = "unknown"
345
+ rx_rat = "unknown"
346
+ rx_signa = "unknown"
347
+ uptim = "unknown"
348
+ packet = "unknown"
349
+ byt = "unknown"
350
+ end
351
+
352
+ end
353
+
354
+ if subs_mac=="unknown"
355
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
356
+ end
357
+
358
+ if subs_mac==""
359
+ subs_mac="unknown"
360
+ end
361
+
362
+
363
+ mess = {:iwag_access_interface => access_int,
364
+ :subscribers_mac => subs_mac,
365
+ :access_point => access_poi,
366
+ :ssid_ap => ssid_a,
367
+ :apid => "unknown",
368
+ :statistics =>
369
+ {:tx_rate_set => tx_rate_se,
370
+ :tx_rate => tx_rat,
371
+ :rx_rate => rx_rat,
372
+ :rx_signal => rx_signa,
373
+ :uptime => uptim,
374
+ :packets => packet,
375
+ :bytes => byt}
376
+ }
377
+ # logger.info "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}, ipaddressinputparameter: #{ip_address} recieved from mts_wifi_get_subs_info_return procedure of wifi_portal_controller such information as: #{mess.to_xml}"
378
+ output_params = {:code => 200, :result => "Request completed", :body => {:message => mess}}
379
+ rescue
380
+
381
+ puts 'SOAP mts_wifi_get_subs_info_return errorMethod'
382
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
383
+ end
384
+ output_params
385
+ end
386
+
387
+ def proc_100_75_0_0(ip_address)
388
+
389
+ begin
390
+ result_iwag = self.python_mac_iwag2_1(ip_address)
391
+ if result_iwag.split(" ")[0]!="Unknown"
392
+ ppp = result_iwag.split(" ")
393
+
394
+ subs_mac = ppp[0]
395
+ access_int = ppp[1]
396
+ access_poi = ppp[2]
397
+ ssid_a = ppp[3]
398
+
399
+ tx_rate_se = "unknown"
400
+ tx_rat = "unknown"
401
+ rx_rat = "unknown"
402
+ rx_signa = "unknown"
403
+ uptim = "unknown"
404
+ packet = "unknown"
405
+ byt = "unknown"
406
+
407
+ if access_int=='GigabitEthernet4.3002'
408
+ access_poi = "belrw_4_HP_ap1-1"
409
+ ssid_a = "BelRW_WiFi"
410
+ elsif access_int=='GigabitEthernet4.3005'
411
+ access_poi = "belbiz-AP1-1"
412
+ ssid_a = "IMAGURU_GUEST"
413
+ end
414
+
415
+ if access_poi == "Unknown" && ssid_a == "Unknown" && subs_mac != "Unknown"
416
+ frommikrotik = self.get_subs_add_info4new_1(access_int, subs_mac)
417
+ splitting5 = frommikrotik.split("---")
418
+ p access_poi = splitting5[1]
419
+ p ssid_a = splitting5[2]
420
+ p tx_rate_se = splitting5[3]
421
+ p tx_rat = splitting5[4]
422
+ p rx_rat = splitting5[5]
423
+ p rx_signa = splitting5[6]
424
+ p uptim = splitting5[7]
425
+ p packet = splitting5[8]
426
+ p byt = splitting5[9]
427
+ end
428
+
429
+ if subs_mac=="unknown"
430
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
431
+ end
432
+
433
+ if subs_mac==""
434
+ subs_mac="unknown"
435
+ end
436
+
437
+
438
+ mess = {:iwag_access_interface => access_int,
439
+ :subscribers_mac => subs_mac,
440
+ :access_point => access_poi,
441
+ :ssid_ap => ssid_a,
442
+ :apid => "unknown",
443
+ :statistics =>
444
+ {:tx_rate_set => tx_rate_se,
445
+ :tx_rate => tx_rat,
446
+ :rx_rate => rx_rat,
447
+ :rx_signal => rx_signa,
448
+ :uptime => uptim,
449
+ :packets => packet,
450
+ :bytes => byt}
451
+ }
452
+ # logger.info "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}, ipaddressinputparameter: #{ip_address} recieved from mts_wifi_get_subs_info_return procedure of wifi_portal_controller such information as: #{mess.to_xml}"
453
+ output_params = {:code => 200, :result => "Request completed", :body => {:message => mess}}
454
+ p output_params
455
+
456
+ else
457
+
458
+ mess = {:iwag_access_interface => "unknown",
459
+ :subscribers_mac => "unknown",
460
+ :access_point => "unknown",
461
+ :ssid_ap => "unknown",
462
+ :apid => "unknown",
463
+ :statistics =>
464
+ {:tx_rate_set => "unknown",
465
+ :tx_rate => "unknown",
466
+ :rx_rate => "unknown",
467
+ :rx_signal => "unknown",
468
+ :uptime => "unknown",
469
+ :packets => "unknown",
470
+ :bytes => "unknown"}
471
+ }
472
+ # logger.info "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}, ipaddressinputparameter: #{params[:ipaddress]} recieved from mts_wifi_get_subs_info_return procedure of wifi_portal_controller such information as: #{mess.to_xml}"
473
+ output_params = {:code => 202, :result => "Request completed", :body => {:message => mess}}
474
+ p output_params
475
+
476
+ end
477
+ rescue
478
+ puts 'SOAP mts_wifi_get_subs_info_return errorMethod'
479
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
480
+ end
481
+
482
+ output_params
483
+
484
+ ####
485
+ end
486
+
487
+
488
+ def proc_100_70_0_0(ip_address)
489
+ p "min11iwag1"
490
+
491
+ begin
492
+ result_iwag = self.python_mac_iwag1_1(ip_address)
493
+ p result_iwag
494
+ if result_iwag.split(" ")[0]!="Unknown"
495
+ ppp = result_iwag.split(" ")
496
+
497
+ subs_mac = ppp[0]
498
+ access_int = ppp[1]
499
+ access_poi = ppp[2]
500
+ ssid_a = ppp[3]
501
+
502
+
503
+ if access_int=='GigabitEthernet4.3002'
504
+ access_poi = "belrw_4_HP_ap1-1"
505
+ ssid_a = "BelRW_WiFi"
506
+ elsif access_int=='GigabitEthernet4.3005'
507
+ access_poi = "belbiz-AP1-1"
508
+ ssid_a = "IMAGURU_GUEST"
509
+ end
510
+
511
+ if access_poi == "Unknown" && ssid_a == "Unknown" && subs_mac != "Unknown"
512
+ frommikrotik = self.get_subs_add_info4new_1(access_int, subs_mac)
513
+ splitting5 = frommikrotik.split("---")
514
+ p access_poi = splitting5[1]
515
+ p ssid_a = splitting5[2]
516
+ p tx_rate_se = splitting5[3]
517
+ p tx_rat = splitting5[4]
518
+ p rx_rat = splitting5[5]
519
+ p rx_signa = splitting5[6]
520
+ p uptim = splitting5[7]
521
+ p packet = splitting5[8]
522
+ p byt = splitting5[9]
523
+ end
524
+
525
+ tx_rate_se = "unknown"
526
+ tx_rat = "unknown"
527
+ rx_rat = "unknown"
528
+ rx_signa = "unknown"
529
+ uptim = "unknown"
530
+ packet = "unknown"
531
+ byt = "unknown"
532
+
533
+ if subs_mac=="unknown"
534
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
535
+ end
536
+
537
+ if subs_mac==""
538
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
539
+ end
540
+
541
+ mess = {:iwag_access_interface => access_int,
542
+ :subscribers_mac => subs_mac,
543
+ :access_point => access_poi,
544
+ :ssid_ap => ssid_a,
545
+ :apid => "unknown",
546
+ :statistics =>
547
+ {:tx_rate_set => tx_rate_se,
548
+ :tx_rate => tx_rat,
549
+ :rx_rate => rx_rat,
550
+ :rx_signal => rx_signa,
551
+ :uptime => uptim,
552
+ :packets => packet,
553
+ :bytes => byt}
554
+ }
555
+ # logger.info "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}, ipaddressinputparameter: #{ip_address} recieved from mts_wifi_get_subs_info_return procedure of wifi_portal_controller such information as: #{mess.to_xml}"
556
+ output_params = {:code => 200, :result => "Request completed", :body => {:message => mess}}
557
+ p output_params
558
+
559
+ else
560
+
561
+ mess = {:iwag_access_interface => "unknown",
562
+ :subscribers_mac => "unknown",
563
+ :access_point => "unknown",
564
+ :ssid_ap => "unknown",
565
+ :apid => "unknown",
566
+ :statistics =>
567
+ {:tx_rate_set => "unknown",
568
+ :tx_rate => "unknown",
569
+ :rx_rate => "unknown",
570
+ :rx_signal => "unknown",
571
+ :uptime => "unknown",
572
+ :packets => "unknown",
573
+ :bytes => "unknown"}
574
+ }
575
+
576
+ # logger.info "HAproxy #{request.remote_ip}, request device real ip: #{request.headers['X-Client']}, ipaddressinputparameter: #{ip_address} recieved from mts_wifi_get_subs_info_return procedure of wifi_portal_controller such information as: #{mess.to_xml}"
577
+
578
+ output_params = {:code => 405, :result => "ERROR. MAC address not found on IWAG."}
579
+
580
+ #render :soap => mess
581
+
582
+ end
583
+ rescue
584
+ puts 'SOAP mts_wifi_get_subs_info_return errorMethod'
585
+ output_params = {:code => 505, :result => "ERROR. Something wrong."}
586
+ end
587
+
588
+ output_params
589
+
590
+ ####
591
+
592
+ end
593
+
594
+
595
+ def get_subs_info_return_1(ip_address)
596
+
597
+ input_params = {:ip_address => ip_address}
598
+ output_params = {}
599
+
600
+ begin
601
+ ipaddr_transformed = IPAddr.new ip_address
602
+ ipaddr_network = ipaddr_transformed.mask(17).to_s
603
+
604
+ if ipaddr_network == "100.71.0.0" #iwag old
605
+
606
+ output_params = self.proc_100_71_0_0(ip_address)
607
+
608
+ elsif ipaddr_network == "100.75.0.0" #min11iwag2
609
+
610
+ output_params = self.proc_100_75_0_0(ip_address)
611
+
612
+ elsif ipaddr_network == "100.70.0.0" #min11iwag1
613
+
614
+ output_params = self.proc_100_70_0_0(ip_address)
615
+
616
+ else
617
+ output_params = {:code => 404, :result => "ERROR. Unknown IP Pool."}
618
+ end
619
+
620
+ rescue
621
+ output_params = {:code => 500, :result => "ERROR. Something wrong.", :body => "SOAP mts_wifi_get_subs_info_return errorMethod unknown error"}
622
+ end
623
+
624
+ output_params
625
+
626
+ end
627
+
628
+
629
+ end
630
+