imperituroard 0.5.9 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd14223003e59a7d5e907811784e45156363c086
4
- data.tar.gz: 53254977a65f45d29edfc93d527b71307b97bcd6
3
+ metadata.gz: 64ac99c5a41209df78fa5f319ec47a51cb28b05b
4
+ data.tar.gz: 004ea48aa310c5d3159ffa8f93b6451f6105fe0a
5
5
  SHA512:
6
- metadata.gz: '059dd82d5c64924e88897d2685170dc7de79c333c3c1ba367d7f0897604cb554bf145cd3b20fc7fc014bb87c03f0dad42c48ac00fdf874d674535b7236afc45b'
7
- data.tar.gz: 7b9f74f90c3cdf4c3286464622f8e4f4fd0792880039c3c7877a32ec94040ea38c883e65c8e51f1271fa13486f16990eaacd667308418bcae4514db46aa6e523
6
+ metadata.gz: 97de046b4032c0751a046c4e1f57cbaffafd63936e53bfa08bcca6dc7216b6a5f73dcf1a68715c9a0a21b4f4ff5e1c116b3fabe0f450a264962543e68b6055b3
7
+ data.tar.gz: 62ad29d69a43d0b0574c5249ac6777bc153a10472b9cce01298a80e27c8c956b6776aa86eef9d558d87acd1d260d5f7ca66428fa12ac8cfead71aab7fb0a7383
@@ -107,42 +107,47 @@ class Pipam
107
107
  end
108
108
 
109
109
  class Iot
110
- attr_accessor :mongoip,
111
- :mongoport,
112
- :iotip,
113
- :mongo_database,
114
- :iotplatform_ip,
115
- :iotplatform_port,
116
- :cert_path,
117
- :key_path,
110
+ attr_accessor :param_all,
118
111
  :mongo_client,
119
112
  :add_functions_connector,
120
- :real_ip, #real ip address of procedure caller
121
- :remote_ip, #ip address of balancer
113
+ #:real_ip, #real ip address of procedure caller
114
+ #:remote_ip, #ip address of balancer
122
115
  :hua_aceanconnect_connector,
123
116
  :internal_func,
124
117
  :iot_connector
125
118
 
126
- def initialize(mongoip, mongoport, iotip, mongo_database,
127
- iotplatform_ip, iotplatform_port, cert_path, key_path, telegram_api_url, telegram_chat_id, real_ip, remote_ip)
128
- @mongoip = mongoip
129
- @mongoport = mongoport
130
- @iotip = iotip
131
- @mongo_database = mongo_database
132
- @iotplatform_ip = iotplatform_ip
133
- @iotplatform_port = iotplatform_port
134
- @cert_path = cert_path
135
- @key_path = key_path
136
- @mongo_client = MongoIot.new(mongoip, mongoport, mongo_database)
119
+ def initialize(mongoip,
120
+ mongoport,
121
+ iotip,
122
+ mongo_database,
123
+ iotplatform_ip,
124
+ iotplatform_port,
125
+ cert_path,
126
+ key_path,
127
+ telegram_api_url,
128
+ telegram_chat_id
129
+ #real_ip,
130
+ #remote_ip
131
+ )
132
+ @param_all = {:mongoip => mongoip,
133
+ :mongoport => mongoport,
134
+ :iotip => iotip,
135
+ :mongo_database => mongo_database,
136
+ :iotplatform_ip => iotplatform_ip,
137
+ :cert_path => cert_path,
138
+ :key_path => key_path
139
+ }
140
+ @mongo_client = MongoIot.new(param_all[:mongoip], param_all[:mongoport], param_all[:mongo_database])
137
141
  @add_functions_connector = AdditionalFunc.new(telegram_api_url, telegram_chat_id)
138
- @real_ip = real_ip
139
- @remote_ip = remote_ip
140
- @hua_aceanconnect_connector = HuaIot.new(iotplatform_ip, iotplatform_port, cert_path, key_path)
142
+ #@real_ip = real_ip
143
+ #@remote_ip = remote_ip
144
+ @hua_aceanconnect_connector = HuaIot.new(iotplatform_ip, iotplatform_port, cert_path, key_path, param_all[:mongoip], param_all[:mongoport], param_all[:mongo_database])
141
145
  @internal_func = InternalFunc.new
142
- @iot_connector = IotFunctions_2.new(mongoip, mongoport, iotip, mongo_database,
143
- iotplatform_ip, iotplatform_port, cert_path, key_path, telegram_api_url, telegram_chat_id, real_ip, remote_ip)
146
+ @iot_connector = IotFunctions_2.new(param_all[:mongoip], param_all[:mongoport], iotip, param_all[:mongo_database],
147
+ iotplatform_ip, iotplatform_port, cert_path, key_path, telegram_api_url, telegram_chat_id)
144
148
  end
145
149
 
150
+
146
151
  #error list
147
152
 
148
153
  #:code => 507, :result => "Unknown SDK error"
@@ -157,8 +162,8 @@ class Iot
157
162
  #massive commands
158
163
  #+++
159
164
  #iot logic added
160
- def add_device_to_profile(login, imei_list)
161
- iot_connector.add_device_to_prof_2(login, imei_list)
165
+ def add_device_to_profile(login, imei_list, real_ip, remote_ip)
166
+ iot_connector.add_device_to_prof_2(login, imei_list, real_ip, remote_ip)
162
167
  end
163
168
 
164
169
 
@@ -169,8 +174,8 @@ class Iot
169
174
  # imei
170
175
  # imei_list =[41234,23452345,132412]
171
176
  #++
172
- def device_find(login, imei_list)
173
- iot_connector.device_find_2(login, imei_list)
177
+ def device_find(login, imei_list, real_ip, remote_ip)
178
+ iot_connector.device_find_2(login, imei_list, real_ip, remote_ip)
174
179
  end
175
180
 
176
181
  #!3 device modify, change imei
@@ -180,8 +185,8 @@ class Iot
180
185
  #massive commands
181
186
  #im_list = [{"imei_old"=>7967843245667, "imei_new"=>7967843245665}]
182
187
  #++
183
- def imei_replace(login, im_list)
184
- iot_connector.imei_replace_2(login, im_list)
188
+ def imei_replace(login, im_list, real_ip, remote_ip)
189
+ iot_connector.imei_replace_2(login, im_list, real_ip, remote_ip)
185
190
  end
186
191
 
187
192
  #!!4 remove device
@@ -192,8 +197,8 @@ class Iot
192
197
  #login="test"
193
198
  #+++
194
199
  #IOT logic added
195
- def device_remove(login, imei)
196
- iot_connector.device_remove_2(login, imei)
200
+ def device_remove(login, imei, real_ip, remote_ip)
201
+ iot_connector.device_remove_2(login, imei, real_ip, remote_ip)
197
202
  end
198
203
 
199
204
 
@@ -204,8 +209,8 @@ class Iot
204
209
  #newdevice_list=[{:imei=>7967843245665, :address=>"Golubeva51"}]
205
210
  #+++
206
211
  #iot platform integration completed
207
- def device_add_address(login, newdevice_list)
208
- iot_connector.device_add_address_2(login, newdevice_list)
212
+ def device_add_address(login, newdevice_list, real_ip, remote_ip)
213
+ iot_connector.device_add_address_2(login, newdevice_list, real_ip, remote_ip)
209
214
  end
210
215
 
211
216
  #6 add service by SPA
@@ -215,38 +220,42 @@ class Iot
215
220
  #msisdn
216
221
  #newdevice_list=[{:imei=>7967843245665, :attributes=>{:address=>"Golubeva51", :profile=>"wqeqcqeqwev", :msisdn=>375298766719, :imsi=>25702858586756875}}]
217
222
  #+
218
- def add_service(login, device_list)
219
- iot_connector.add_service_2(login, device_list)
223
+ def add_service(login, device_list, real_ip, remote_ip)
224
+ iot_connector.add_service_2(login, device_list, real_ip, remote_ip)
220
225
  end
221
226
 
222
-
223
227
  #7 procedure for subscriber autorization
224
- def autorize_subscriber(login, password)
225
- iot_connector.autorize_subscriber_2(login, password)
228
+ def autorize_subscriber(login, password, real_ip, remote_ip)
229
+ iot_connector.autorize_subscriber_2(login, password, real_ip, remote_ip)
226
230
  end
227
231
 
228
-
229
232
  #8 get available profiles for login
230
- def get_available_profiles(login)
231
- iot_connector.get_available_prof_2(login)
233
+ def get_available_profiles(login, real_ip, remote_ip)
234
+ iot_connector.get_available_prof_2(login, real_ip, remote_ip)
232
235
  end
233
236
 
234
-
235
237
  #9 get available types for login
236
- def get_available_types(login)
237
- iot_connector.get_available_types_2(login)
238
+ def get_available_types(login, real_ip, remote_ip)
239
+ iot_connector.get_available_types_2(login, real_ip, remote_ip)
238
240
  end
239
241
 
240
-
241
242
  #10 get info for device type
242
- def get_info_data_type(type)
243
- iot_connector.get_info_data_type_2(type)
243
+ def get_info_data_type(type, real_ip, remote_ip)
244
+ iot_connector.get_info_data_type_2(type, real_ip, remote_ip)
244
245
  end
245
246
 
246
-
247
247
  #11 get info for profile
248
- def get_info_data_profile(profile)
249
- iot_connector.get_info_data_profile_2(profile)
248
+ def get_info_data_profile(profile, real_ip, remote_ip)
249
+ iot_connector.get_info_data_profile_2(profile, real_ip, remote_ip)
250
+ end
251
+
252
+ #13 replace data for imei. Replace Type and Profile
253
+ #new procedure 2020-06-06
254
+ #params =
255
+ # {"autorization"=>{"login"=>"test", "token"=>"token"}, "datalist"=>[{"imei"=>"524523654366", "new_profile"=>"3", "new_type"=>"1000001"}, {"imei"=>"53623413423", "new_profile"=>"1", "new_type"=>"1000003"}]}
256
+ # answer = {:code=>200, :result=>"Success", :body=>{:processednum=>1, :failednum=>1, :deviceserr=>[{:failedimei=>524523654366}]}}
257
+ def set_data_replace(soapgw_params, real_ip, remote_ip)
258
+ iot_connector.set_data_replace_2(soapgw_params, real_ip, remote_ip)
250
259
  end
251
260
 
252
261
 
@@ -258,7 +267,6 @@ class Iot
258
267
  iot_connector.test1278493
259
268
  end
260
269
 
261
-
262
270
  end
263
271
 
264
272
 
@@ -402,4 +410,4 @@ class Ukaz60Automation_2
402
410
  ukaz60_func.no_pasaran
403
411
  end
404
412
 
405
- end
413
+ end
@@ -17,34 +17,44 @@ class IotFunctions_2
17
17
 
18
18
  attr_accessor :mongoip,
19
19
  :mongoport,
20
- :iotip,
21
- :mongo_database,
22
- :iotplatform_ip,
23
- :iotplatform_port,
20
+ #:iotip,
21
+ #:mongo_database,
22
+ #:iotplatform_ip,
23
+ #:iotplatform_port,
24
24
  :cert_path,
25
25
  :key_path,
26
26
  :mongo_client,
27
27
  :add_functions_connector,
28
- :real_ip, #real ip address of procedure caller
29
- :remote_ip, #ip address of balancer
28
+ #:real_ip, #real ip address of procedure caller
29
+ #:remote_ip, #ip address of balancer
30
30
  :hua_aceanconnect_connector,
31
31
  :internal_func
32
32
 
33
- def initialize(mongoip, mongoport, iotip, mongo_database,
34
- iotplatform_ip, iotplatform_port, cert_path, key_path, telegram_api_url, telegram_chat_id, real_ip, remote_ip)
33
+ def initialize(mongoip,
34
+ mongoport,
35
+ iotip,
36
+ mongo_database,
37
+ iotplatform_ip,
38
+ iotplatform_port,
39
+ cert_path,
40
+ key_path,
41
+ telegram_api_url,
42
+ telegram_chat_id
43
+ #real_ip, remote_ip
44
+ )
35
45
  @mongoip = mongoip
36
46
  @mongoport = mongoport
37
- @iotip = iotip
38
- @mongo_database = mongo_database
39
- @iotplatform_ip = iotplatform_ip
40
- @iotplatform_port = iotplatform_port
47
+ #@iotip = iotip
48
+ #@mongo_database = mongo_database
49
+ #@iotplatform_ip = iotplatform_ip
50
+ #@iotplatform_port = iotplatform_port
41
51
  @cert_path = cert_path
42
52
  @key_path = key_path
43
53
  @mongo_client = MongoIot.new(mongoip, mongoport, mongo_database)
44
54
  @add_functions_connector = AdditionalFunc.new(telegram_api_url, telegram_chat_id)
45
- @real_ip = real_ip
46
- @remote_ip = remote_ip
47
- @hua_aceanconnect_connector = HuaIot.new(iotplatform_ip, iotplatform_port, cert_path, key_path)
55
+ #@real_ip = real_ip
56
+ #@remote_ip = remote_ip
57
+ @hua_aceanconnect_connector = HuaIot.new(iotplatform_ip, iotplatform_port, cert_path, key_path, mongoip, mongoport, mongo_database)
48
58
  @internal_func = InternalFunc.new
49
59
  end
50
60
 
@@ -57,7 +67,7 @@ class IotFunctions_2
57
67
  #massive commands
58
68
  #+++
59
69
  #iot logic added
60
- def add_device_to_prof_2(login, imei_list)
70
+ def add_device_to_prof_2(login, imei_list, real_ip, remote_ip)
61
71
  input_json = {:login => login, :imei_list => imei_list}
62
72
  resp_out = {}
63
73
  begin
@@ -144,24 +154,21 @@ class IotFunctions_2
144
154
  model_data[:body]["model"]
145
155
  )
146
156
  if resss[:code]=="200"
147
-
148
157
  if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
149
158
  not_processed_list.append({:imei => aaa["imei"], :error => resss})
150
159
  else
151
160
  s1 = aaa
152
161
  s1[:huadata] = resss
153
162
  s1[:created] = DateTime.now
163
+ s1[:type] = s1["device_type"]
154
164
  added_on_iot_platf.append(s1)
155
165
  end
156
-
157
166
  else
158
167
  not_processed_list.append({:imei => aaa["imei"], :error => resss})
159
168
  end
160
169
  rescue
161
170
  not_processed_list.append({:imei => aaa["imei"], :error => "Unknown error with insertion imei on IOT platform"})
162
171
  end
163
-
164
-
165
172
  #########end iot platform logic#######
166
173
 
167
174
  else
@@ -177,16 +184,12 @@ class IotFunctions_2
177
184
  else
178
185
  resp_out = {:code => 202, :result => "Empty list. Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
179
186
  end
180
-
181
-
182
187
  else
183
188
  resp_out = {:code => 202, :result => "Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
184
-
185
189
  end
186
190
  rescue
187
191
  resp_out = {:code => 505, :result => "Error with database communication"}
188
192
  end
189
-
190
193
  else
191
194
  resp_out = {:code => 509, :result => "Input data invalid"}
192
195
  end
@@ -211,7 +214,7 @@ class IotFunctions_2
211
214
  # imei
212
215
  # imei_list =[41234,23452345,132412]
213
216
  #++
214
- def device_find_2(login, imei_list)
217
+ def device_find_2(login, imei_list, real_ip, remote_ip)
215
218
  input_json = {:login => login, :imei_list => imei_list}
216
219
  ime_list_approved = []
217
220
  ime_list_notapproved = []
@@ -274,7 +277,7 @@ class IotFunctions_2
274
277
  #massive commands
275
278
  #im_list = [{"imei_old"=>7967843245667, "imei_new"=>7967843245665}]
276
279
  #++
277
- def imei_replace_2(login, im_list)
280
+ def imei_replace_2(login, im_list, real_ip, remote_ip)
278
281
  input_json = {:login => login, :imei_list => im_list}
279
282
  resp_out = {}
280
283
 
@@ -449,7 +452,7 @@ class IotFunctions_2
449
452
  #login="test"
450
453
  #+++
451
454
  #IOT logic added
452
- def device_remove_2(login, imei)
455
+ def device_remove_2(login, imei, real_ip, remote_ip)
453
456
 
454
457
  input_json = {:login => login, :imei_list => imei}
455
458
  resp_out = {}
@@ -533,7 +536,7 @@ class IotFunctions_2
533
536
  #newdevice_list=[{:imei=>7967843245665, :address=>"Golubeva51"}]
534
537
  #+++
535
538
  #iot platform integration completed
536
- def device_add_address_2(login, newdevice_list)
539
+ def device_add_address_2(login, newdevice_list, real_ip, remote_ip)
537
540
  #add_functions_connector.telegram_message(newdevice_list.to_s)
538
541
  p newdevice_list
539
542
  p "gas"
@@ -615,7 +618,7 @@ class IotFunctions_2
615
618
  #msisdn
616
619
  #newdevice_list=[{:imei=>7967843245665, :attributes=>{:address=>"Golubeva51", :profile=>"wqeqcqeqwev", :msisdn=>375298766719, :imsi=>25702858586756875}}]
617
620
  #+
618
- def add_service_2(login, device_list)
621
+ def add_service_2(login, device_list, real_ip, remote_ip)
619
622
  resp_out = {}
620
623
  not_processed = []
621
624
  processed = []
@@ -676,9 +679,7 @@ class IotFunctions_2
676
679
  else
677
680
  resp_out = {:code => 509, :result => "Input data invalid"}
678
681
  end
679
-
680
682
  end
681
-
682
683
  rescue
683
684
  resp_out = {:code => 507, :result => "Unknown SDK error"}
684
685
  end
@@ -690,7 +691,7 @@ class IotFunctions_2
690
691
 
691
692
  #7 procedure for subscriber autorization
692
693
  # save data to mongodb
693
- def autorize_subscriber_2(login, password)
694
+ def autorize_subscriber_2(login, password, real_ip, remote_ip)
694
695
  input_json = {:login => login, :password => password}
695
696
  resp_out = {}
696
697
  thr7 = Thread.new do
@@ -722,7 +723,7 @@ class IotFunctions_2
722
723
 
723
724
 
724
725
  #8 get available profiles by login
725
- def get_available_prof_2(login)
726
+ def get_available_prof_2(login, real_ip, remote_ip)
726
727
 
727
728
  input_params = {:login => login}
728
729
  resp_out = {}
@@ -773,7 +774,7 @@ class IotFunctions_2
773
774
  end
774
775
 
775
776
  #9 get available device types by login
776
- def get_available_types_2(login)
777
+ def get_available_types_2(login, real_ip, remote_ip)
777
778
 
778
779
  input_params = {:login => login}
779
780
  resp_out = {}
@@ -830,7 +831,7 @@ class IotFunctions_2
830
831
 
831
832
 
832
833
  #10 get available device types by login and profile. procedure update
833
- def get_available_types2_2(login, profile)
834
+ def get_available_types2_2(login, profile, real_ip, remote_ip)
834
835
 
835
836
  input_params = {:login => login}
836
837
  resp_out = {}
@@ -887,7 +888,7 @@ class IotFunctions_2
887
888
 
888
889
 
889
890
  #11 get info for device type
890
- def get_info_data_type_2(type)
891
+ def get_info_data_type_2(type, real_ip, remote_ip)
891
892
 
892
893
  input_params = {:type => type}
893
894
  output_answ = {}
@@ -917,7 +918,7 @@ class IotFunctions_2
917
918
 
918
919
 
919
920
  #12 get info for profile
920
- def get_info_data_profile_2(profile)
921
+ def get_info_data_profile_2(profile, real_ip, remote_ip)
921
922
 
922
923
  input_params = {:profile => profile}
923
924
  output_answ = {}
@@ -946,6 +947,180 @@ class IotFunctions_2
946
947
  end
947
948
 
948
949
 
950
+ #set_data_replace
951
+ #13
952
+ # {"autorization"=>{"login"=>"test", "token"=>"token"}, "datalist"=>[{"imei"=>"524523654366", "new_profile"=>"3", "new_type"=>"1000001"}, {"imei"=>"53623413423", "new_profile"=>"1", "new_type"=>"1000003"}]}
953
+ # answer = {:code=>200, :result=>"Success", :body=>{:processednum=>1, :failednum=>1, :deviceserr=>[{:failedimei=>524523654366}]}}
954
+ def set_data_replace_2(soapgw_params, real_ip, remote_ip)
955
+ input_params = {:soapgw_params => soapgw_params, :real_ip => real_ip, :remote_ip => remote_ip}
956
+ output_answ = {}
957
+ failes_list = []
958
+ answ_to_soapgw = {}
959
+ not_processed_list = []
960
+ processed_list = []
961
+
962
+ inp_login = soapgw_params["autorization"]["login"]
963
+ inp_dev_list = soapgw_params["datalist"]
964
+
965
+ thr13set = Thread.new do
966
+ inp_dev_list.each do |curr_dev|
967
+ begin
968
+ if curr_dev["imei"] != [] && curr_dev["imei"] != nil && curr_dev["imei"] != ""
969
+ list_checked = mongo_client.check_imei_exists([curr_dev["imei"].to_i])
970
+ if list_checked[:code] == 200 && list_checked[:body][:exists] != [] && list_checked[:body][:not_exists] == []
971
+
972
+ #step1 checking permission for writing for imei list
973
+ prof_name1 = mongo_client.get_profile_name_from_imei(curr_dev["imei"].to_i)
974
+ p prof_name1
975
+ p "prof_name1"
976
+ if prof_name1[:code] == 200
977
+
978
+ if curr_dev["new_profile"] != "nil" && curr_dev["new_profile"] != "null" && curr_dev["new_profile"] != "empty" && curr_dev["new_profile"] != "nill"
979
+ prof_new_id = mongo_client.get_profile_universal(curr_dev["new_profile"])["profile_id"]
980
+ else
981
+ prof_new_id = prof_name1[:body]["profile_id"]
982
+ end
983
+
984
+ if curr_dev["new_type"] != "nil" && curr_dev["new_type"] != "null" && curr_dev["new_type"] != "empty" && curr_dev["new_type"] != "nill"
985
+ type_new_pr = curr_dev["new_type"]
986
+ else
987
+ type_new_pr = prof_name1[:imei_info][:body][0]["device_type"]
988
+ end
989
+
990
+ p type_new_pr
991
+ p prof_new_id
992
+ p "st111111"
993
+
994
+ get_login_info = mongo_client.check_login_prof_perm_id_one(inp_login, prof_name1[:body]["profile_id"])
995
+ p get_login_info
996
+ p "get_login_info"
997
+ if get_login_info[:code] == 200
998
+ get_login_info_new = mongo_client.check_login_prof_perm_id_one(inp_login, prof_new_id)
999
+ p get_login_info_new
1000
+ p "get_login_info_new"
1001
+ if get_login_info_new[:code] == 200
1002
+ cur_comp1 = mongo_client.compare_profiles(prof_name1[:body]["profile_id"], prof_new_id)
1003
+ p cur_comp1
1004
+ p "cur_comp1"
1005
+ cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["type"], type_new_pr)
1006
+
1007
+
1008
+ p cur_comp2
1009
+ p "cur_comp2"
1010
+
1011
+ if cur_comp1[:is_the_same] && cur_comp2[:is_the_same]
1012
+ #the same. Nothing to do
1013
+ processed_list.append(curr_dev)
1014
+ ########
1015
+ else
1016
+ credentials_old = mongo_client.get_iot_oceanconn_credent_2(prof_name1[:body]["profile"])
1017
+ credentials_new = mongo_client.get_iot_oceanconn_credent_2(prof_new_id)
1018
+ p credentials_new
1019
+ p "credentials_new"
1020
+ #########
1021
+ if credentials_old[:code] == 200 && credentials_new[:code] == 200
1022
+ imei_data = mongo_client.get_imei_info_from_db([curr_dev["imei"].to_i])
1023
+ p imei_data
1024
+ p "imei_data"
1025
+ if imei_data[:body] != []
1026
+ ans = {}
1027
+ if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
1028
+ model_data = mongo_client.get_device_type_info_universal(type_new_pr)
1029
+ p model_data
1030
+ p "model_data"
1031
+ #####all checks completed. then process data#####
1032
+ ans_old = hua_aceanconnect_connector.remove_one_device_from_iot(credentials_old[:body][:app_id], credentials_old[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"])
1033
+
1034
+
1035
+ if ans_old[:code].to_i == 200 || ans_old[:code].to_i == 202 || ans_old[:code].to_i == 204
1036
+ begin
1037
+ resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials_new[:body][:app_id],
1038
+ credentials_new[:body][:secret],
1039
+ curr_dev["imei"].to_i,
1040
+ curr_dev["imei"].to_s,
1041
+ prof_name1[:body]["description"],
1042
+ model_data[:body]["device_type"],
1043
+ curr_dev["new_profile"],
1044
+ model_data[:body]["ManufacturerID"],
1045
+ model_data[:body]["ManufacturerNAME"],
1046
+ model_data[:body]["model"]
1047
+ )
1048
+ if resss[:code] == "200"
1049
+ if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
1050
+ not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1051
+ else
1052
+ new_id_iot = resss[:body]
1053
+ new_profile_id = prof_new_id
1054
+ now_date = DateTime.now
1055
+ #finished success. update database
1056
+ attribute = {profile: new_profile_id, type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
1057
+ answ_mongo = mongo_client.modify_attr_mongo_universal(curr_dev["imei"].to_i, attribute)
1058
+ if answ_mongo[:code] != 200
1059
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Critical error. Mongo not updated", :mongo_err => answ_mongo})
1060
+ else
1061
+ processed_list.append(curr_dev)
1062
+ end
1063
+ end
1064
+ else
1065
+ not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1066
+ end
1067
+ rescue
1068
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown error with insertion imei on IOT platform"})
1069
+ end
1070
+ end
1071
+ else
1072
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Not processed by iot platform. deviceId not found in mongoDB"})
1073
+ end
1074
+ else
1075
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get info from database"})
1076
+ end
1077
+ else
1078
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get credentials from database"})
1079
+ end
1080
+ end
1081
+ else
1082
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "New profile modification not permitted"})
1083
+ end
1084
+ else
1085
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Old profile modification not permitted"})
1086
+ end
1087
+ else
1088
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown current profile"})
1089
+ end
1090
+ else
1091
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Device not exists"})
1092
+ end
1093
+ else
1094
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "IMEI can't be nil"})
1095
+ end
1096
+ rescue
1097
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown SDK error"})
1098
+ end
1099
+
1100
+ end
1101
+
1102
+ err_li = []
1103
+ if not_processed_list.length > 0
1104
+ not_processed_list.each do |err_l|
1105
+ err_li.append({:failedimei => err_l[:imei]})
1106
+ end
1107
+ end
1108
+
1109
+ if processed_list.length > 0
1110
+ answ_to_soapgw = {:code => 200, :result => "Success", :body => {:processednum => processed_list.length, :failednum => not_processed_list.length, :deviceserr => err_li}}
1111
+ else
1112
+ answ_to_soapgw = {:code => 202, :result => "Nothing done", :body => {:processednum => 0, :failednum => not_processed_list.length, :deviceserr => err_li}}
1113
+ end
1114
+ end
1115
+ thr13set.join
1116
+
1117
+ output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => answ_to_soapgw, :not_processed_list => not_processed_list, :processed_list => processed_list}}
1118
+ mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip)
1119
+ output_answ
1120
+ end
1121
+
1122
+
1123
+ #14
949
1124
  #additional procedure for checking status on iot platform
950
1125
  def get_info_by_imeilist_from_iot(login, imei_list)
951
1126
  resp_out={}
@@ -998,10 +1173,10 @@ class IotFunctions_2
998
1173
  p resp_out[:body]
999
1174
  p "resp_out[:body][\"devices\"]"
1000
1175
 
1001
- if resp_out[:body] == nil || resp_out[:body] == {} || resp_out[:body] == {"devices"=>nil}
1176
+ if resp_out[:body] == nil || resp_out[:body] == {} || resp_out[:body] == {"devices" => nil}
1002
1177
  p "step1111"
1003
1178
  p resp_out_1[:body]["devices"]
1004
- resp_out[:body] = { 'devices' => resp_out_1[:body]["devices"]}
1179
+ resp_out[:body] = {'devices' => resp_out_1[:body]["devices"]}
1005
1180
  p "step22222"
1006
1181
  else
1007
1182
  if resp_out_1[:body]["devices"] != nil
@@ -6,13 +6,14 @@ require 'rubygems'
6
6
  require 'nokogiri'
7
7
  require 'rails'
8
8
  require "imperituroard/projects/iot/internal_functions"
9
+ require 'imperituroard/projects/iot/mongoconnector'
9
10
 
10
11
 
11
12
  class HuaIot
12
13
 
13
- attr_accessor :platformip, :platformport, :client, :database, :cert_file, :key_file, :internal_func
14
+ attr_accessor :platformip, :platformport, :client, :database, :cert_file, :key_file, :internal_func, :client_iot_mongo
14
15
 
15
- def initialize(platformip, platformport, cert_file, key_file)
16
+ def initialize(platformip, platformport, cert_file, key_file, mongo_ip, mongo_port, mongo_database)
16
17
  @database = database
17
18
  @platformip = platformip
18
19
  @platformport = platformport
@@ -21,6 +22,7 @@ class HuaIot
21
22
  #client_host = [mongoip + ":" + mongoport]
22
23
  #@client = Mongo::Client.new(client_host, :database => database)
23
24
  @internal_func = InternalFunc.new
25
+ @client_iot_mongo = MongoIot.new(mongo_ip, mongo_port, mongo_database)
24
26
  end
25
27
 
26
28
  def parse_token(str)
@@ -72,6 +74,11 @@ class HuaIot
72
74
  request.body = URI.encode_www_form(data)
73
75
  res = https.request(request)
74
76
  out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
77
+ fff = {:func => "get_token",
78
+ :iot_fun => "",
79
+ :req_header => {:content_type => 'application/x-www-form-urlencoded'
80
+ }}
81
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
75
82
  rescue
76
83
  out_resp = {:code => 500, :message => "failed get token"}
77
84
  end
@@ -104,6 +111,10 @@ class HuaIot
104
111
  request.body = URI.encode_www_form(data)
105
112
  res = https.request(request)
106
113
  out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
114
+ fff = {:func => "token_logout",
115
+ :iot_fun => "logout"
116
+ }
117
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
107
118
  rescue
108
119
  out_resp = {:code => 500, :message => "failed logout token"}
109
120
  end
@@ -129,7 +140,6 @@ class HuaIot
129
140
  request['app_key'] = app_id
130
141
  request.body = {nodeId: node_id}.to_json
131
142
  res = https.request(request)
132
- p res.body.to_s
133
143
  {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
134
144
  end
135
145
 
@@ -157,13 +167,18 @@ class HuaIot
157
167
  manufacturerName: manufacturer_name,
158
168
  model: model,
159
169
  isSecurity: "FALSE",
160
- supportedSecurity: "FALSE"}}.to_json
170
+ supportedSecurity: "FALSE"}}
161
171
  internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
162
- request.body = data_out
172
+ request.body = data_out.to_json
163
173
  res = https.request(request)
164
- p res.body.to_s
165
174
  out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
166
- p out_resp
175
+ fff = {:func => "dev_register_passw_code_mode2",
176
+ :iot_fun => "2.2.4",
177
+ :req_header => {:authorization => 'Bearer ' + token,
178
+ :content_type => 'application/json',
179
+ :app_key => app_id
180
+ }}
181
+ client_iot_mongo.audit_iot_logger(fff, url_string, data_out, out_resp)
167
182
  out_resp
168
183
  end
169
184
 
@@ -213,18 +228,21 @@ class HuaIot
213
228
  request['Authorization'] = 'Bearer ' + token
214
229
  request['app_key'] = app_id
215
230
  res = https.request(request)
216
- p "res.code"
217
- p res.code
218
- p res.body
219
231
  if res.body != nil
220
232
  out_resp = {:code => res.code, :message => res.message, :body => {:answ => JSON.parse(res.body.to_s)}}
221
233
  else
222
234
  out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
223
235
  end
236
+ fff = {:func => "dev_delete",
237
+ :iot_fun => "2.2.12",
238
+ :req_header => {:authorization => 'Bearer ' + token,
239
+ :content_type => 'application/json',
240
+ :app_key => app_id
241
+ }}
242
+ client_iot_mongo.audit_iot_logger(fff, url_string, "Delete", out_resp)
224
243
  rescue
225
244
  out_resp = {:code => 500, :message => "dev_delete: Unknown IOT error"}
226
245
  end
227
- p out_resp
228
246
  out_resp
229
247
  end
230
248
 
@@ -295,6 +313,7 @@ class HuaIot
295
313
 
296
314
  #2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
297
315
  def querying_device_direct_conn(app_id, secret, dev_list)
316
+ output_str = {}
298
317
  token = get_token(app_id, secret)[:body]["accessToken"]
299
318
  path = "/iocm/app/dm/v1.1.0/queryDevicesByIds"
300
319
  url_string = "https://" + platformip + ":" + platformport + path
@@ -308,9 +327,18 @@ class HuaIot
308
327
  request.content_type = 'application/json'
309
328
  request['Authorization'] = 'Bearer ' + token
310
329
  request['app_key'] = app_id
311
- request.body = {deviceIds: dev_list}.to_json
330
+ req_body = {deviceIds: dev_list}
331
+ request.body = req_body.to_json
312
332
  res = https.request(request)
313
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
333
+ output_str = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
334
+ fff = {:func => "querying_device_direct_conn",
335
+ :iot_fun => "2.9.6",
336
+ :req_header => {:authorization => 'Bearer ' + token,
337
+ :content_type => 'application/json',
338
+ :app_key => app_id
339
+ }}
340
+ client_iot_mongo.audit_iot_logger(fff, url_string, req_body, output_str)
341
+ output_str
314
342
  end
315
343
 
316
344
 
@@ -364,7 +392,7 @@ class HuaIot
364
392
  begin
365
393
  path = "/iocm/app/dm/v1.4.0/devices/" + dev_id + "?app_Id=" + app_id
366
394
  url_string = "https://" + platformip + ":" + platformport + path
367
- internal_func.printer_texter({:url_string=>url_string, :procedure=>"dev_modify_location_v2"}, "debug")
395
+ internal_func.printer_texter({:url_string => url_string, :procedure => "dev_modify_location_v2"}, "debug")
368
396
  uri = URI.parse url_string
369
397
  https = Net::HTTP.new(uri.host, uri.port)
370
398
  https.use_ssl = true
@@ -375,7 +403,8 @@ class HuaIot
375
403
  request.content_type = 'application/json'
376
404
  request['Authorization'] = 'Bearer ' + token
377
405
  request['app_key'] = app_id
378
- request.body = {location: address}.to_json
406
+ req_b = {location: address}
407
+ request.body = req_b.to_json
379
408
  res = https.request(request)
380
409
  p res.code
381
410
  p res.body
@@ -384,6 +413,13 @@ class HuaIot
384
413
  else
385
414
  out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
386
415
  end
416
+ fff = {:func => "dev_modify_location_v2",
417
+ :iot_fun => "2.2.11",
418
+ :req_header => {:authorization => 'Bearer ' + token,
419
+ :content_type => 'application/json',
420
+ :app_key => app_id
421
+ }}
422
+ client_iot_mongo.audit_iot_logger(fff, url_string, req_b, out_resp)
387
423
  rescue
388
424
  out_resp = {:code => 500, :message => "dev_modify_location_v2: Unknown IOT error"}
389
425
  end
@@ -392,7 +428,6 @@ class HuaIot
392
428
  end
393
429
 
394
430
 
395
-
396
431
  ##2.10.7 Adding Members to a Device Group
397
432
 
398
433
 
@@ -41,6 +41,30 @@ class MongoIot
41
41
  out_resp
42
42
  end
43
43
 
44
+ def audit_iot_logger(proc_name, url_str, input_json, output_json)
45
+ out_resp = {}
46
+ p "iiiiiiiot"
47
+ p input_json
48
+ begin
49
+ current = internal_func.datetimenow
50
+ collection = client[:audit_iot_platform]
51
+ doc = {
52
+ :proc_name => proc_name,
53
+ :date => current,
54
+ :url => url_str,
55
+ :iot_platform_request => input_json,
56
+ :iot_platform_responce => output_json
57
+ }
58
+ p doc
59
+ result = collection.insert_one(doc)
60
+ out_resp = {:code => 200, :result => "audit_logger: Request completed successfully", :body => result}
61
+ rescue
62
+ out_resp = {:code => 507, :result => "audit_logger: Unknown SDK error"}
63
+ end
64
+ internal_func.printer_texter(out_resp, "debug")
65
+ out_resp
66
+ end
67
+
44
68
  #:code => 507, :result => "Unknown SDK error"
45
69
  #{:code => 200, :result => "Request completed successfully", :body => result_ps}
46
70
  def get_profiles_by_login(login)
@@ -317,6 +341,7 @@ class MongoIot
317
341
  note: "second description",
318
342
  profile: 0,
319
343
  type: 0,
344
+ device_type: 0,
320
345
  address: "unknown"
321
346
  }
322
347
  result = collection.insert_one(l)
@@ -340,6 +365,7 @@ class MongoIot
340
365
  note: "second description",
341
366
  profile: 0,
342
367
  type: 0,
368
+ device_type: 0,
343
369
  address: "unknown"
344
370
  }
345
371
  result = collection.insert_one(l)
@@ -364,6 +390,7 @@ class MongoIot
364
390
 
365
391
  def get_profile_name_from_imei(imei)
366
392
  out_resp = {}
393
+ info = {}
367
394
  begin
368
395
  id = ""
369
396
  begin
@@ -387,7 +414,7 @@ class MongoIot
387
414
  end
388
415
  begin
389
416
  if res["profile"]!=nil
390
- out_resp = {:code => 200, :result => "get_profile_name_from_imei: Request completed successfully", :body => res}
417
+ out_resp = {:code => 200, :result => "get_profile_name_from_imei: Request completed successfully", :body => res, :imei_info => info}
391
418
  end
392
419
  rescue
393
420
  out_resp = {:code => 506, :result => "get_profile_name_from_imei: Function get_profile_name_by_id not processed correctly and returned: #{res.to_s}"}
@@ -523,5 +550,164 @@ class MongoIot
523
550
  out_resp
524
551
  end
525
552
 
553
+ def get_device_type_info_universal(device_model)
554
+ out_resp = {}
555
+ begin
556
+ as = internal_func.if_digit_or_string(device_model)
557
+
558
+ if as[:body][:string]
559
+ result_ps = []
560
+ collection = client[:device_types]
561
+ collection.find({"model" => device_model}).each {|row|
562
+ result_ps.append(row)
563
+ }
564
+ dattaa = result_ps[0]
565
+ if dattaa!=nil
566
+ out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
567
+ else
568
+ out_resp = {:code => 404, :result => "get_device_type_info_by_model: Device info not found", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
569
+ end
570
+ else
571
+ result_ps2 = []
572
+ collection = client[:device_types]
573
+ collection.find({"type_id" => device_model.to_i}).each {|row|
574
+ result_ps2.append(row)
575
+ }
576
+ dattaa = result_ps2[0]
577
+ if dattaa!=nil
578
+ out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
579
+ else
580
+ out_resp = {:code => 404, :result => "get_device_type_info_by_model: Device info not found", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
581
+ end
582
+ end
583
+
584
+ rescue
585
+ out_resp = {:code => 500, :result => "get_device_type_info_universal: procedure error", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
586
+ end
587
+ internal_func.printer_texter(out_resp, "debug")
588
+ out_resp
589
+ end
590
+
591
+
592
+
593
+ def compare_profiles(profile1, profile2)
594
+ out_answ = {}
595
+ ch1 = internal_func.if_digit_or_string(profile1)
596
+ ch2 = internal_func.if_digit_or_string(profile2)
597
+ if ch1[:body][:string] == ch2[:body][:string] && ch1[:body][:string] == false
598
+ if profile1.to_i == profile2.to_i
599
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are the same", :is_the_same => true, :data_type => "integer"}
600
+ else
601
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are different", :is_the_same => false, :data_type => "integer"}
602
+ end
603
+ elsif ch1[:body][:string] == ch2[:body][:string] && ch1[:body][:string] == true
604
+ if profile1 == profile2
605
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are the same", :is_the_same => true, :data_type => "string"}
606
+ else
607
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are different", :is_the_same => false, :data_type => "string"}
608
+ end
609
+ else
610
+ ch1_data = {}
611
+ ch2_data = {}
612
+ if ch1[:body][:string]
613
+ ch1_data = self.get_profile_id_by_name(profile1)
614
+ else
615
+ ch1_data = self.get_profile_name_by_id(profile1.to_i)
616
+ end
617
+
618
+ if ch2[:body][:string]
619
+ ch2_data = self.get_profile_id_by_name(profile2)
620
+ else
621
+ ch2_data = self.get_profile_name_by_id(profile2.to_i)
622
+ end
623
+
624
+ if ch1_data["profile_id"] == ch2_data["profile_id"]
625
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are the same", :is_the_same => true, :data_type => "different"}
626
+ else
627
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are different", :is_the_same => false, :data_type => "different"}
628
+ end
629
+ end
630
+ out_answ
631
+ end
632
+
633
+ def compare_device_types(type1, type2)
634
+ out_answ = {}
635
+ tp1 = internal_func.if_digit_or_string(type1)
636
+ tp2 = internal_func.if_digit_or_string(type2)
637
+ p tp1
638
+ p tp2
639
+ p "tp"
640
+
641
+ if tp1[:body][:string] == tp2[:body][:string] && tp1[:body][:string] == false
642
+ if type1.to_i == type2.to_i
643
+ out_answ = {:code => 200, :result => "compare_device_types: types are the same", :is_the_same => true, :data_type => "integer"}
644
+ else
645
+ out_answ = {:code => 200, :result => "compare_device_types: types are different", :is_the_same => false, :data_type => "integer"}
646
+ end
647
+ elsif tp1[:body][:string] == tp2[:body][:string] && tp1[:body][:string] == true
648
+ if type1 == type2
649
+ out_answ = {:code => 200, :result => "compare_device_types: types are the same", :is_the_same => true, :data_type => "string"}
650
+ else
651
+ out_answ = {:code => 200, :result => "compare_device_types: types are different", :is_the_same => false, :data_type => "string"}
652
+ end
653
+ else
654
+ tp1_data = {}
655
+ tp2_data = {}
656
+ p "gggggggg"
657
+ if tp1[:body][:string]
658
+ tp1_data = self.get_type_by_name(type1)
659
+ else
660
+ tp1_data = self.get_type_by_id(type1.to_i)
661
+ end
662
+
663
+ if tp2[:body][:string]
664
+ tp2_data = self.get_type_by_name(type2)
665
+ else
666
+ tp2_data = self.get_type_by_id(type2.to_i)
667
+ end
668
+
669
+ p tp1_data
670
+ p tp2_data
671
+ p type1
672
+ p type2
673
+
674
+ if tp1_data["type_id"] == tp2_data["type_id"]
675
+ out_answ = {:code => 200, :result => "compare_device_types: profiles are the same", :is_the_same => true, :data_type => "different"}
676
+ else
677
+ out_answ = {:code => 200, :result => "compare_device_types: profiles are different", :is_the_same => false, :data_type => "different"}
678
+ end
679
+ end
680
+ out_answ
681
+ end
682
+
683
+
684
+ def get_profile_universal(profile)
685
+ inn = internal_func.if_digit_or_string(profile)
686
+ out = {}
687
+ if inn[:body][:string]
688
+ out = self.get_profile_id_by_name(profile)
689
+ else
690
+ out = self.get_profile_name_by_id(profile.to_i)
691
+ end
692
+ out
693
+ end
694
+
695
+ def modify_attr_mongo_universal(imei, attribute)
696
+ out_resp = {}
697
+ begin
698
+ collection = client[:device_imei]
699
+ doc = {
700
+ "imei" => imei
701
+ }
702
+ sett = {'$set' => attribute}
703
+ result = collection.update_one(doc, sett)
704
+ out_resp = {:code => 200, :result => "modify_attr_mongo_universal: Request completed successfully"}
705
+ rescue
706
+ out_resp = {:code => 507, :result => "modify_attr_mongo_universal: Unknown SDK error"}
707
+ end
708
+ internal_func.printer_texter(out_resp, "debug")
709
+ out_resp
710
+ end
711
+
712
+ end
526
713
 
527
- end
@@ -1,3 +1,4 @@
1
1
  module Imperituroard
2
- VERSION = "0.5.9"
2
+ VERSION = "1.0.4"
3
3
  end
4
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imperituroard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 1.0.4
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-06-03 00:00:00.000000000 Z
11
+ date: 2020-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler