freewifi 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,142 @@
1
+ require 'net-telnet'
2
+
3
+ class HuaWifi_1
4
+
5
+ attr_accessor :hua_wlc_1_ip, :hua_wlc_2_ip, :hua_wlc_login, :hua_wlc_password
6
+
7
+ def initialize(hua_wlc_1_ip, hua_wlc_2_ip, hua_wlc_login, hua_wlc_password)
8
+ @hua_wlc_1_ip = hua_wlc_1_ip
9
+ @hua_wlc_2_ip = hua_wlc_2_ip
10
+ @hua_wlc_login = hua_wlc_login
11
+ @hua_wlc_password = hua_wlc_password
12
+ end
13
+
14
+
15
+ def get_sub_info_1(mac)
16
+
17
+ subscribers_mac =mac
18
+ access_point = "unknown"
19
+ ssid_ap = "unknown"
20
+ tx_rate_set = "unknown"
21
+ tx_rate = "unknown"
22
+ rx_rate = "unknown"
23
+ rx_signal = "unknown"
24
+ uptime = "unknown"
25
+ packets = "unknown"
26
+ bytes = "unknown"
27
+
28
+
29
+ begin
30
+ p macaddr1 = mac.downcase
31
+ p macaddr2 = macaddr1[0]+macaddr1[1]+macaddr1[3]+macaddr1[4]+"-"+macaddr1[6]+macaddr1[7]+macaddr1[9]+macaddr1[10]+"-"+macaddr1[12]+macaddr1[13]+macaddr1[15]+macaddr1[16]
32
+
33
+ dump = ""
34
+ connection = Net::Telnet.new( "Host" => hua_wlc_1_ip, "Timeout" => 10, "Prompt" => /.*>/ ) { |str| print str }
35
+ connection.login({ "Name" => hua_wlc_login, "Password" => hua_wlc_password, "LoginPrompt" => /Username:/ }) { |str| }
36
+ connection.cmd("system-view\n display station sta-mac #{macaddr2}\n quit \n") {
37
+ |c|
38
+ dump << c
39
+ }
40
+ connection.close
41
+
42
+
43
+ iter1 = dump.split("\n")
44
+ ssid_ap = iter1[7].split(" ")[3]
45
+ temmmm=""
46
+ temmmm1="1"
47
+ i=0
48
+ while i < iter1.length
49
+ if iter1[i].include? "AP Name"
50
+ temmmm = iter1[i]
51
+ elsif iter1[i].include? "Station's Channel Band-width" && "20MHz"
52
+ temmmm1="0"
53
+ end
54
+ i+=1
55
+ end
56
+
57
+ if temmmm1=="0"
58
+ access_point = temmmm.gsub!("Station's AP Name","").gsub!(" ","").gsub(":","")+"-1"
59
+ else
60
+ access_point = temmmm.gsub!("Station's AP Name","").gsub!(" ","").gsub(":","")+"-2"
61
+ end
62
+ tx_rate_set = iter1[11].split(" ")[4]
63
+ rx_signal = iter1[10].split(" ")[6]
64
+ uptime = iter1[8].split(" ")[4]
65
+ # p iter1 = dump.split("----------------------------------------------------------------------------------------------------")
66
+ # p iter2 = iter1[2]
67
+ # p iter3 = iter2.split("\n")
68
+ # i = 1
69
+ # while i<iter3.length
70
+ # p iter4 = iter3[i].split(" ")
71
+ # i+=1
72
+ # end
73
+
74
+ rescue
75
+
76
+ p "failed to get info from huawei controller1"
77
+ end
78
+
79
+ return subscribers_mac+ ",,," + access_point + ",,," + ssid_ap + ",,," + tx_rate_set + ",,,"+ tx_rate + ",,,"+ rx_rate + ",,,"+ rx_signal + ",,,"+ uptime + ",,,"+ packets + ",,,"+ bytes
80
+
81
+ end
82
+
83
+
84
+
85
+ def get_sub_info2_1(mac)
86
+
87
+ subscribers_mac =mac
88
+ access_point = "unknown"
89
+ ssid_ap = "unknown"
90
+ tx_rate_set = "unknown"
91
+ tx_rate = "unknown"
92
+ rx_rate = "unknown"
93
+ rx_signal = "unknown"
94
+ uptime = "unknown"
95
+ packets = "unknown"
96
+ bytes = "unknown"
97
+
98
+
99
+ begin
100
+ macaddr1 = mac.downcase
101
+ macaddr2 = macaddr1[0]+macaddr1[1]+macaddr1[3]+macaddr1[4]+"-"+macaddr1[6]+macaddr1[7]+macaddr1[9]+macaddr1[10]+"-"+macaddr1[12]+macaddr1[13]+macaddr1[15]+macaddr1[16]
102
+
103
+ dump = ""
104
+ connection = Net::Telnet.new( "Host" => hua_wlc_2_ip, "Timeout" => 10, "Prompt" => /.*>/ ) { |str| print str }
105
+ connection.login({ "Name" => hua_wlc_login, "Password" => hua_wlc_password, "LoginPrompt" => /Username:/ }) { |str| }
106
+ connection.cmd("system-view\n display station sta-mac #{macaddr2}\n quit \n") {
107
+ |c|
108
+ dump << c
109
+ }
110
+ connection.close
111
+
112
+
113
+ iter1 = dump.split("\n")
114
+ ssid_ap = iter1[7].split(" ")[3]
115
+ if iter1[41].gsub!(" ","").split(":")[1]=="20MHz"
116
+ access_point = iter1[35].gsub!("Station's AP Name","").gsub!(" ","").gsub(":","")+"-1"
117
+ else
118
+ access_point = iter1[35].gsub!("Station's AP Name","").gsub!(" ","").gsub(":","")+"-2"
119
+ end
120
+ tx_rate_set = iter1[11].split(" ")[4]
121
+ rx_signal = iter1[10].split(" ")[6]
122
+ uptime = iter1[8].split(" ")[4]
123
+ # p iter1 = dump.split("----------------------------------------------------------------------------------------------------")
124
+ # p iter2 = iter1[2]
125
+ # p iter3 = iter2.split("\n")
126
+ # i = 1
127
+ # while i<iter3.length
128
+ # p iter4 = iter3[i].split(" ")
129
+ # i+=1
130
+ # end
131
+
132
+ rescue
133
+
134
+ p "failed to get info from huawei controller1"
135
+ end
136
+
137
+ return subscribers_mac+ ",,," + access_point + ",,," + ssid_ap + ",,," + tx_rate_set + ",,,"+ tx_rate + ",,,"+ rx_rate + ",,,"+ rx_signal + ",,,"+ uptime + ",,,"+ packets + ",,,"+ bytes
138
+
139
+ end
140
+
141
+
142
+ end
@@ -0,0 +1,97 @@
1
+ require 'mtik'
2
+
3
+ class NEWhubWifiApi_1
4
+
5
+ attr_accessor :mtik_control_ips_get, :mtik_user, :mtik_password
6
+
7
+ def initialize(mtik_control_ips_get, mtik_user, mtik_password)
8
+ @mtik_control_ips_get = mtik_control_ips_get
9
+ @mtik_user = mtik_user
10
+ @mtik_password = mtik_password
11
+ end
12
+
13
+
14
+ def get_info_subs_from_mik_1(subs_mac, controllers_ip)
15
+ #region get additional information
16
+
17
+ subscribers_mac = subs_mac
18
+ access_point =""
19
+ ssid_ap =""
20
+ tx_rate_set = ""
21
+ tx_rate = ""
22
+ rx_rate = ""
23
+ rx_signal = ""
24
+ uptime = ""
25
+ packets = ""
26
+ bytes = ""
27
+
28
+ MTik::verbose = false
29
+ mikrot_connection1 = MTik::Connection.new :host => controllers_ip, :user => mtik_user, :pass => mtik_password, :conn_timeout => 7, :cmd_timeout => 7
30
+ mikrot_connection1.get_reply('/caps-man/registration-table/getall') do |req, sentence|
31
+
32
+ req.reply.each do |reply|
33
+ if reply.key?('!re')
34
+ if reply['mac-address'] == subscribers_mac
35
+
36
+ access_point = reply['interface']
37
+ ssid_ap = reply['ssid']
38
+ tx_rate = reply['tx-rate']
39
+ rx_rate = reply['rx-rate']
40
+ rx_signal = reply['rx-signal']
41
+ uptime = reply['uptime']
42
+ packets = reply['packets']
43
+ bytes = reply['bytes']
44
+ tx_rate_set = reply['tx-rate-set']
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ if access_point=="" || ssid_ap=="" || packets==""
51
+ access_point = "not on mikrotik controller"
52
+ ssid_ap = "unknown"
53
+ tx_rate_set = "unknown"
54
+ tx_rate = "0"
55
+ rx_rate = "0"
56
+ rx_signal = "0"
57
+ uptime = "0"
58
+ packets = "0"
59
+ bytes = "0"
60
+ end
61
+
62
+ if access_point==nil
63
+ access_point= "unknown"
64
+ end
65
+ if ssid_ap==nil
66
+ ssid_ap= "unknown"
67
+ end
68
+ if tx_rate_set==nil
69
+ tx_rate_set= "unknown"
70
+ end
71
+ if tx_rate==nil
72
+ tx_rate= "unknown"
73
+ end
74
+ if rx_rate==nil
75
+ rx_rate= "unknown"
76
+ end
77
+ if rx_signal==nil
78
+ rx_signal= "unknown"
79
+ end
80
+ if uptime==nil
81
+ uptime= "unknown"
82
+ end
83
+ if packets==nil
84
+ packets= "unknown"
85
+ end
86
+ if bytes==nil
87
+ bytes= "unknown"
88
+ end
89
+
90
+ #endregion
91
+ answ = subscribers_mac+ "---" + access_point + "---" + ssid_ap + "---" + tx_rate_set + "---"+ tx_rate + "---"+ rx_rate + "---"+ rx_signal + "---"+ uptime + "---"+ packets + "---"+ bytes
92
+
93
+ return answ
94
+
95
+ end
96
+
97
+ end
@@ -1,3 +1,3 @@
1
1
  module Freewifi_1
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/lib/freewifi.rb CHANGED
@@ -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,75 @@ class Fwifi_1
232
266
  end
233
267
 
234
268
 
269
+ class PortalFwifi_1
270
+
271
+ attr_accessor :apigw_wsdl,
272
+ :apigw_endpoint,
273
+ :apigw_namespace,
274
+ :apigw_wsse_aut_log,
275
+ :apigw_wsse_aut_pass,
276
+ :general_procedures,
277
+ :mtik_control_ips_get,
278
+ :mtik_user,
279
+ :mtik_password,
280
+ :mongo_connector_wifi_1,
281
+ :remote_ip,
282
+ :real_ip
283
+
284
+
285
+ def initialize(apigw_wsdl,
286
+ apigw_endpoint,
287
+ apigw_namespace,
288
+ apigw_wsse_aut_log,
289
+ apigw_wsse_aut_pass,
290
+ iwag1_host,
291
+ iwag_username,
292
+ iwag_password,
293
+ mtik_control_ips_get,
294
+ mtik_user,
295
+ mtik_password,
296
+ mongo_ip,
297
+ mongo_port,
298
+ mongo_database,
299
+ remote_ip,
300
+ real_ip,
301
+ hua_wlc_1_ip,
302
+ hua_wlc_2_ip,
303
+ hua_wlc_login,
304
+ hua_wlc_password
305
+ )
306
+
307
+ @apigw_wsdl = apigw_wsdl
308
+ @apigw_endpoint = apigw_endpoint
309
+ @apigw_namespace = apigw_namespace
310
+ @apigw_wsse_aut_log = apigw_wsse_aut_log
311
+ @apigw_wsse_aut_pass = apigw_wsse_aut_pass
312
+ @general_procedures = WiFiPortal_1.new(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)
313
+ @mtik_control_ips_get = mtik_control_ips_get
314
+ @mtik_user = mtik_user
315
+ @mtik_password = mtik_password
316
+ @mongo_connector_wifi_1 = MongoWifiCl_1.new(mongo_ip, mongo_port, mongo_database)
317
+ @remote_ip = remote_ip
318
+ @real_ip = real_ip
319
+ end
320
+
321
+
322
+ def wifi_get_subs_info_return_1(ipaddress)
323
+ input_params = {:ipaddress => ipaddress}
324
+ output_params = {}
325
+
326
+ begin
327
+ resp_procedure = general_procedures.get_subs_info_return_1(ipaddress)
328
+ output_params = resp_procedure
329
+ rescue
330
+ output_params = {:code => 507, :result => "Unknown SDK error"}
331
+ end
332
+
333
+ mongo_connector_wifi_1.audit_logger_wifi_portal_1("wifi_get_subs_info_return_1", remote_ip, input_params, output_params, real_ip)
334
+
335
+ end
336
+
337
+ end
338
+
235
339
  #tested on 6.46.2 router os
236
340
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freewifi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Buynovskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-27 00:00:00.000000000 Z
11
+ date: 2020-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,6 +150,48 @@ dependencies:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
152
  version: 0.1.5
153
+ - !ruby/object:Gem::Dependency
154
+ name: savon
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 2.12.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 2.12.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: net-telnet
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '='
172
+ - !ruby/object:Gem::Version
173
+ version: 0.2.0
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '='
179
+ - !ruby/object:Gem::Version
180
+ version: 0.2.0
181
+ - !ruby/object:Gem::Dependency
182
+ name: mtik
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '='
186
+ - !ruby/object:Gem::Version
187
+ version: 4.0.3
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - '='
193
+ - !ruby/object:Gem::Version
194
+ version: 4.0.3
153
195
  description: description for my gem
154
196
  email:
155
197
  - imperituro.ard@gmail.com
@@ -175,11 +217,15 @@ files:
175
217
  - freewifi.gemspec
176
218
  - lib/freewifi.rb
177
219
  - lib/freewifi/additional/additional_functions.rb
178
- - lib/freewifi/cisco/cisco_schemes_conf_gen.rb
220
+ - lib/freewifi/cisco/any/cisco_schemes_conf_gen.rb
221
+ - lib/freewifi/cisco/iwag/iwag_telnet_connector.rb
179
222
  - lib/freewifi/config.rb
180
223
  - lib/freewifi/database/mongo/mongoconnector.rb
181
224
  - lib/freewifi/database/mysql/database_methods_wifi.rb
225
+ - lib/freewifi/general/wifi_portal_procedures.rb
226
+ - lib/freewifi/huawei/hua_controller_class.rb
182
227
  - lib/freewifi/mikrotik/getsubscribermikrotik.rb
228
+ - lib/freewifi/mikrotik/newhub_mtik_api.rb
183
229
  - lib/freewifi/mikrotik/newhub_mtik_ssh.rb
184
230
  - lib/freewifi/mikrotik/schemes_conf_gen.rb
185
231
  - lib/freewifi/params.rb