imperituroard 0.5.9 → 1.0.0

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: 281f0e9ae37d21c88b14fc21bbb23b7d80534b6a
4
+ data.tar.gz: 5b98866616ea7d1e15f4cffbafa47cdc09cedfff
5
5
  SHA512:
6
- metadata.gz: '059dd82d5c64924e88897d2685170dc7de79c333c3c1ba367d7f0897604cb554bf145cd3b20fc7fc014bb87c03f0dad42c48ac00fdf874d674535b7236afc45b'
7
- data.tar.gz: 7b9f74f90c3cdf4c3286464622f8e4f4fd0792880039c3c7877a32ec94040ea38c883e65c8e51f1271fa13486f16990eaacd667308418bcae4514db46aa6e523
6
+ metadata.gz: 592995920474f0879d5844f0d1390ba666754e741c13e6268d49ff1ba48d9015991e0b9c851620aefd625c48f9cbf1842a521cf01fddaffa11b837d4fa949661
7
+ data.tar.gz: 3b77fac313a17855d2e03d7d3004aab342c1dba4647d0ac4b2693189a743fd3b324aa604d6594df33b014bb8345a21defaca0ecc2d2e8ce6a5a933c447ec17aa
@@ -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
@@ -211,7 +221,7 @@ class IotFunctions_2
211
221
  # imei
212
222
  # imei_list =[41234,23452345,132412]
213
223
  #++
214
- def device_find_2(login, imei_list)
224
+ def device_find_2(login, imei_list, real_ip, remote_ip)
215
225
  input_json = {:login => login, :imei_list => imei_list}
216
226
  ime_list_approved = []
217
227
  ime_list_notapproved = []
@@ -274,7 +284,7 @@ class IotFunctions_2
274
284
  #massive commands
275
285
  #im_list = [{"imei_old"=>7967843245667, "imei_new"=>7967843245665}]
276
286
  #++
277
- def imei_replace_2(login, im_list)
287
+ def imei_replace_2(login, im_list, real_ip, remote_ip)
278
288
  input_json = {:login => login, :imei_list => im_list}
279
289
  resp_out = {}
280
290
 
@@ -449,7 +459,7 @@ class IotFunctions_2
449
459
  #login="test"
450
460
  #+++
451
461
  #IOT logic added
452
- def device_remove_2(login, imei)
462
+ def device_remove_2(login, imei, real_ip, remote_ip)
453
463
 
454
464
  input_json = {:login => login, :imei_list => imei}
455
465
  resp_out = {}
@@ -533,7 +543,7 @@ class IotFunctions_2
533
543
  #newdevice_list=[{:imei=>7967843245665, :address=>"Golubeva51"}]
534
544
  #+++
535
545
  #iot platform integration completed
536
- def device_add_address_2(login, newdevice_list)
546
+ def device_add_address_2(login, newdevice_list, real_ip, remote_ip)
537
547
  #add_functions_connector.telegram_message(newdevice_list.to_s)
538
548
  p newdevice_list
539
549
  p "gas"
@@ -615,7 +625,7 @@ class IotFunctions_2
615
625
  #msisdn
616
626
  #newdevice_list=[{:imei=>7967843245665, :attributes=>{:address=>"Golubeva51", :profile=>"wqeqcqeqwev", :msisdn=>375298766719, :imsi=>25702858586756875}}]
617
627
  #+
618
- def add_service_2(login, device_list)
628
+ def add_service_2(login, device_list, real_ip, remote_ip)
619
629
  resp_out = {}
620
630
  not_processed = []
621
631
  processed = []
@@ -690,7 +700,7 @@ class IotFunctions_2
690
700
 
691
701
  #7 procedure for subscriber autorization
692
702
  # save data to mongodb
693
- def autorize_subscriber_2(login, password)
703
+ def autorize_subscriber_2(login, password, real_ip, remote_ip)
694
704
  input_json = {:login => login, :password => password}
695
705
  resp_out = {}
696
706
  thr7 = Thread.new do
@@ -722,7 +732,7 @@ class IotFunctions_2
722
732
 
723
733
 
724
734
  #8 get available profiles by login
725
- def get_available_prof_2(login)
735
+ def get_available_prof_2(login, real_ip, remote_ip)
726
736
 
727
737
  input_params = {:login => login}
728
738
  resp_out = {}
@@ -773,7 +783,7 @@ class IotFunctions_2
773
783
  end
774
784
 
775
785
  #9 get available device types by login
776
- def get_available_types_2(login)
786
+ def get_available_types_2(login, real_ip, remote_ip)
777
787
 
778
788
  input_params = {:login => login}
779
789
  resp_out = {}
@@ -830,7 +840,7 @@ class IotFunctions_2
830
840
 
831
841
 
832
842
  #10 get available device types by login and profile. procedure update
833
- def get_available_types2_2(login, profile)
843
+ def get_available_types2_2(login, profile, real_ip, remote_ip)
834
844
 
835
845
  input_params = {:login => login}
836
846
  resp_out = {}
@@ -887,7 +897,7 @@ class IotFunctions_2
887
897
 
888
898
 
889
899
  #11 get info for device type
890
- def get_info_data_type_2(type)
900
+ def get_info_data_type_2(type, real_ip, remote_ip)
891
901
 
892
902
  input_params = {:type => type}
893
903
  output_answ = {}
@@ -917,7 +927,7 @@ class IotFunctions_2
917
927
 
918
928
 
919
929
  #12 get info for profile
920
- def get_info_data_profile_2(profile)
930
+ def get_info_data_profile_2(profile, real_ip, remote_ip)
921
931
 
922
932
  input_params = {:profile => profile}
923
933
  output_answ = {}
@@ -946,6 +956,155 @@ class IotFunctions_2
946
956
  end
947
957
 
948
958
 
959
+ #set_data_replace
960
+ #13
961
+ # {"autorization"=>{"login"=>"test", "token"=>"token"}, "datalist"=>[{"imei"=>"524523654366", "new_profile"=>"3", "new_type"=>"1000001"}, {"imei"=>"53623413423", "new_profile"=>"1", "new_type"=>"1000003"}]}
962
+ # answer = {:code=>200, :result=>"Success", :body=>{:processednum=>1, :failednum=>1, :deviceserr=>[{:failedimei=>524523654366}]}}
963
+ def set_data_replace_2(soapgw_params, real_ip, remote_ip)
964
+ input_params = {:soapgw_params => soapgw_params, :real_ip => real_ip, :remote_ip => remote_ip}
965
+ output_answ = {}
966
+ failes_list = []
967
+ answ_to_soapgw = {}
968
+ not_processed_list = []
969
+ processed_list = []
970
+
971
+ inp_login = soapgw_params["autorization"]["login"]
972
+ inp_dev_list = soapgw_params["datalist"]
973
+
974
+ inp_dev_list.each do |curr_dev|
975
+ begin
976
+ if curr_dev["imei"] != [] && curr_dev["imei"] != nil && curr_dev["imei"] != ""
977
+ list_checked = mongo_client.check_imei_exists([curr_dev["imei"].to_i])
978
+ if list_checked[:code] == 200 && list_checked[:body][:exists] != [] && list_checked[:body][:not_exists] == []
979
+
980
+ #step1 checking permission for writing for imei list
981
+ prof_name1 = mongo_client.get_profile_name_from_imei(curr_dev["imei"].to_i)
982
+ if prof_name1[:code] == 200
983
+ prof_new_id = mongo_client.get_profile_universal(curr_dev["new_profile"])["profile_id"]
984
+
985
+ get_login_info = mongo_client.check_login_prof_perm_id_one(inp_login, prof_name1[:body]["profile_id"])
986
+ if get_login_info[:code] == 200
987
+ get_login_info_new = mongo_client.check_login_prof_perm_id_one(inp_login, prof_new_id)
988
+ if get_login_info_new[:code] == 200
989
+
990
+ cur_comp1 = mongo_client.compare_profiles(prof_name1[:body]["profile_id"], prof_new_id)
991
+ cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["device_type"], curr_dev["new_type"])
992
+
993
+ p cur_comp1
994
+ p cur_comp2
995
+ if cur_comp1[:is_the_same] && cur_comp2[:is_the_same]
996
+ #the same. Nothing to do
997
+ processed_list.append(curr_dev)
998
+ ########
999
+ else
1000
+
1001
+ credentials_old = mongo_client.get_iot_oceanconn_credent_2(prof_name1[:body]["profile"])
1002
+ credentials_new = mongo_client.get_iot_oceanconn_credent_2(prof_new_id)
1003
+ #########
1004
+ if credentials_old[:code] == 200 && credentials_new[:code] == 200
1005
+ imei_data = mongo_client.get_imei_info_from_db([curr_dev["imei"].to_i])
1006
+ if imei_data[:body] != []
1007
+ ans = {}
1008
+ if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
1009
+
1010
+ model_data = mongo_client.get_device_type_info_universal(curr_dev["new_type"])
1011
+
1012
+ #####all checks completed. then process data#####
1013
+ 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"])
1014
+
1015
+ if ans_old[:code].to_i == 200 || ans_old[:code].to_i == 202 || ans_old[:code].to_i == 204
1016
+ begin
1017
+ resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials_new[:body][:app_id],
1018
+ credentials_new[:body][:secret],
1019
+ curr_dev["imei"].to_i,
1020
+ curr_dev["imei"].to_s,
1021
+ prof_name1[:body]["description"],
1022
+ model_data[:body]["device_type"],
1023
+ curr_dev["new_profile"],
1024
+ model_data[:body]["ManufacturerID"],
1025
+ model_data[:body]["ManufacturerNAME"],
1026
+ model_data[:body]["model"]
1027
+ )
1028
+
1029
+ if resss[:code]=="200"
1030
+
1031
+ if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
1032
+ not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1033
+ else
1034
+ new_id_iot = resss[:body]
1035
+ new_profile_id = prof_new_id
1036
+ now_date = DateTime.now
1037
+ #finished success. update database
1038
+ attribute = {profile: new_profile_id, device_type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
1039
+
1040
+ answ_mongo = mongo_client.modify_attr_mongo_universal(curr_dev["imei"].to_i, attribute)
1041
+
1042
+ if answ_mongo[:code] != 200
1043
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Critical error. Mongo not updated", :mongo_err => answ_mongo})
1044
+ else
1045
+ processed_list.append(curr_dev)
1046
+ end
1047
+
1048
+ #added_on_iot_platf.append(s1)
1049
+ end
1050
+
1051
+ else
1052
+ not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1053
+ end
1054
+ rescue
1055
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown error with insertion imei on IOT platform"})
1056
+ end
1057
+ end
1058
+ else
1059
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Not processed by iot platform. deviceId not found in mongoDB"})
1060
+ end
1061
+ else
1062
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get info from database"})
1063
+ end
1064
+ else
1065
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get credentials from database"})
1066
+ end
1067
+ end
1068
+ else
1069
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "New profile modification not permitted"})
1070
+ end
1071
+ else
1072
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Old profile modification not permitted"})
1073
+ end
1074
+ else
1075
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown current profile"})
1076
+ end
1077
+ else
1078
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Device not exists"})
1079
+ end
1080
+ else
1081
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "IMEI can't be nil"})
1082
+ end
1083
+ rescue
1084
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown SDK error"})
1085
+ end
1086
+
1087
+ end
1088
+
1089
+ err_li = []
1090
+ if not_processed_list.length > 0
1091
+ not_processed_list.each do |err_l|
1092
+ err_li.append({:failedimei => err_l[:imei]})
1093
+ end
1094
+ end
1095
+
1096
+ if processed_list.length > 0
1097
+ soap_answ = {:code=>200, :result=>"Success", :body=>{:processednum => processed_list.length, :failednum => not_processed_list.length, :deviceserr => err_li}}
1098
+ else
1099
+ soap_answ = {:code=>202, :result=>"Nothing done", :body=>{:processednum => 0, :failednum => not_processed_list.length, :deviceserr => err_li}}
1100
+ end
1101
+
1102
+ {:code => 200, :result => "Success", :body => {:to_soap_gw => soap_answ}}
1103
+
1104
+ end
1105
+
1106
+
1107
+ #14
949
1108
  #additional procedure for checking status on iot platform
950
1109
  def get_info_by_imeilist_from_iot(login, imei_list)
951
1110
  resp_out={}
@@ -998,10 +1157,10 @@ class IotFunctions_2
998
1157
  p resp_out[:body]
999
1158
  p "resp_out[:body][\"devices\"]"
1000
1159
 
1001
- if resp_out[:body] == nil || resp_out[:body] == {} || resp_out[:body] == {"devices"=>nil}
1160
+ if resp_out[:body] == nil || resp_out[:body] == {} || resp_out[:body] == {"devices" => nil}
1002
1161
  p "step1111"
1003
1162
  p resp_out_1[:body]["devices"]
1004
- resp_out[:body] = { 'devices' => resp_out_1[:body]["devices"]}
1163
+ resp_out[:body] = {'devices' => resp_out_1[:body]["devices"]}
1005
1164
  p "step22222"
1006
1165
  else
1007
1166
  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)
@@ -157,13 +159,18 @@ class HuaIot
157
159
  manufacturerName: manufacturer_name,
158
160
  model: model,
159
161
  isSecurity: "FALSE",
160
- supportedSecurity: "FALSE"}}.to_json
162
+ supportedSecurity: "FALSE"}}
161
163
  internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
162
- request.body = data_out
164
+ request.body = data_out.to_json
163
165
  res = https.request(request)
164
- p res.body.to_s
165
166
  out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
166
- p out_resp
167
+ fff = {:func => "dev_register_passw_code_mode2",
168
+ :iot_fun => "2.2.4",
169
+ :req_header => {:authorization => 'Bearer ' + token,
170
+ :content_type => 'application/json',
171
+ :app_key => app_id
172
+ }}
173
+ client_iot_mongo.audit_iot_logger(fff, url_string, data_out, out_resp)
167
174
  out_resp
168
175
  end
169
176
 
@@ -221,6 +228,14 @@ class HuaIot
221
228
  else
222
229
  out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
223
230
  end
231
+
232
+ fff = {:func => "dev_delete",
233
+ :iot_fun => "2.2.12",
234
+ :req_header => {:authorization => 'Bearer ' + token,
235
+ :content_type => 'application/json',
236
+ :app_key => app_id
237
+ }}
238
+ client_iot_mongo.audit_iot_logger(fff, url_string, "Delete", out_resp)
224
239
  rescue
225
240
  out_resp = {:code => 500, :message => "dev_delete: Unknown IOT error"}
226
241
  end
@@ -364,7 +379,7 @@ class HuaIot
364
379
  begin
365
380
  path = "/iocm/app/dm/v1.4.0/devices/" + dev_id + "?app_Id=" + app_id
366
381
  url_string = "https://" + platformip + ":" + platformport + path
367
- internal_func.printer_texter({:url_string=>url_string, :procedure=>"dev_modify_location_v2"}, "debug")
382
+ internal_func.printer_texter({:url_string => url_string, :procedure => "dev_modify_location_v2"}, "debug")
368
383
  uri = URI.parse url_string
369
384
  https = Net::HTTP.new(uri.host, uri.port)
370
385
  https.use_ssl = true
@@ -392,7 +407,6 @@ class HuaIot
392
407
  end
393
408
 
394
409
 
395
-
396
410
  ##2.10.7 Adding Members to a Device Group
397
411
 
398
412
 
@@ -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)
@@ -364,6 +388,7 @@ class MongoIot
364
388
 
365
389
  def get_profile_name_from_imei(imei)
366
390
  out_resp = {}
391
+ info = {}
367
392
  begin
368
393
  id = ""
369
394
  begin
@@ -387,7 +412,7 @@ class MongoIot
387
412
  end
388
413
  begin
389
414
  if res["profile"]!=nil
390
- out_resp = {:code => 200, :result => "get_profile_name_from_imei: Request completed successfully", :body => res}
415
+ out_resp = {:code => 200, :result => "get_profile_name_from_imei: Request completed successfully", :body => res, :imei_info => info}
391
416
  end
392
417
  rescue
393
418
  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 +548,155 @@ class MongoIot
523
548
  out_resp
524
549
  end
525
550
 
551
+ def get_device_type_info_universal(device_model)
552
+ out_resp = {}
553
+ begin
554
+ as = internal_func.if_digit_or_string(device_model)
555
+
556
+ if as[:body][:string]
557
+ result_ps = []
558
+ collection = client[:device_types]
559
+ collection.find({"model" => device_model}).each {|row|
560
+ result_ps.append(row)
561
+ }
562
+ dattaa = result_ps[0]
563
+ if dattaa!=nil
564
+ out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
565
+ else
566
+ 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"}}
567
+ end
568
+ else
569
+ result_ps2 = []
570
+ collection = client[:device_types]
571
+ collection.find({"type_id" => device_model.to_i}).each {|row|
572
+ result_ps2.append(row)
573
+ }
574
+ dattaa = result_ps2[0]
575
+ if dattaa!=nil
576
+ out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
577
+ else
578
+ 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"}}
579
+ end
580
+ end
581
+
582
+ rescue
583
+ out_resp = {:code => 500, :result => "get_device_type_info_universal: procedure error", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
584
+ end
585
+ internal_func.printer_texter(out_resp, "debug")
586
+ out_resp
587
+ end
588
+
589
+
590
+
591
+ def compare_profiles(profile1, profile2)
592
+ out_answ = {}
593
+ ch1 = internal_func.if_digit_or_string(profile1)
594
+ ch2 = internal_func.if_digit_or_string(profile2)
595
+ if ch1[:body][:string] == ch2[:body][:string] && ch1[:body][:string] == false
596
+ if profile1.to_i == profile2.to_i
597
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are the same", :is_the_same => true, :data_type => "integer"}
598
+ else
599
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are different", :is_the_same => false, :data_type => "integer"}
600
+ end
601
+ elsif ch1[:body][:string] == ch2[:body][:string] && ch1[:body][:string] == true
602
+ if profile1 == profile2
603
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are the same", :is_the_same => true, :data_type => "string"}
604
+ else
605
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are different", :is_the_same => false, :data_type => "string"}
606
+ end
607
+ else
608
+ ch1_data = {}
609
+ ch2_data = {}
610
+ if ch1[:body][:string]
611
+ ch1_data = self.get_profile_id_by_name(profile1)
612
+ else
613
+ ch1_data = self.get_profile_name_by_id(profile1.to_i)
614
+ end
615
+
616
+ if ch2[:body][:string]
617
+ ch2_data = self.get_profile_id_by_name(profile2)
618
+ else
619
+ ch2_data = self.get_profile_name_by_id(profile2.to_i)
620
+ end
621
+
622
+ if ch1_data["profile_id"] == ch2_data["profile_id"]
623
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are the same", :is_the_same => true, :data_type => "different"}
624
+ else
625
+ out_answ = {:code => 200, :result => "compare_profiles: profiles are different", :is_the_same => false, :data_type => "different"}
626
+ end
627
+ end
628
+ out_answ
629
+ end
630
+
631
+ def compare_device_types(type1, type2)
632
+ out_answ = {}
633
+ tp1 = internal_func.if_digit_or_string(type1)
634
+ tp2 = internal_func.if_digit_or_string(type2)
635
+
636
+ if tp1[:body][:string] == tp2[:body][:string] && tp1[:body][:string] == false
637
+ if type1.to_i == type2.to_i
638
+ out_answ = {:code => 200, :result => "compare_device_types: types are the same", :is_the_same => true, :data_type => "integer"}
639
+ else
640
+ out_answ = {:code => 200, :result => "compare_device_types: types are different", :is_the_same => false, :data_type => "integer"}
641
+ end
642
+ elsif tp1[:body][:string] == tp2[:body][:string] && tp1[:body][:string] == true
643
+ if type1 == type2
644
+ out_answ = {:code => 200, :result => "compare_device_types: types are the same", :is_the_same => true, :data_type => "string"}
645
+ else
646
+ out_answ = {:code => 200, :result => "compare_device_types: types are different", :is_the_same => false, :data_type => "string"}
647
+ end
648
+ else
649
+ tp1_data = {}
650
+ tp2_data = {}
651
+ if tp1[:body][:string]
652
+ tp1_data = self.get_type_by_name(type1)
653
+ else
654
+ tp1_data = self.get_type_by_id(type1.to_i)
655
+ end
656
+
657
+ if tp2[:body][:string]
658
+ tp2_data = self.get_type_by_name(type2)
659
+ else
660
+ tp2_data = self.get_type_by_id(type2.to_i)
661
+ end
662
+
663
+ if tp1_data["type_id"] == tp2_data["type_id"]
664
+ out_answ = {:code => 200, :result => "compare_device_types: profiles are the same", :is_the_same => true, :data_type => "different"}
665
+ else
666
+ out_answ = {:code => 200, :result => "compare_device_types: profiles are different", :is_the_same => false, :data_type => "different"}
667
+ end
668
+ end
669
+ out_answ
670
+ end
671
+
672
+
673
+ def get_profile_universal(profile)
674
+ inn = internal_func.if_digit_or_string(profile)
675
+ out = {}
676
+ if inn[:body][:string]
677
+ out = self.get_profile_id_by_name(profile)
678
+ else
679
+ out = self.get_profile_name_by_id(profile.to_i)
680
+ end
681
+ out
682
+ end
683
+
684
+ def modify_attr_mongo_universal(imei, attribute)
685
+ out_resp = {}
686
+ begin
687
+ collection = client[:device_imei]
688
+ doc = {
689
+ "imei" => imei
690
+ }
691
+ sett = {'$set' => attribute}
692
+ result = collection.update_one(doc, sett)
693
+ out_resp = {:code => 200, :result => "modify_attr_mongo_universal: Request completed successfully"}
694
+ rescue
695
+ out_resp = {:code => 507, :result => "modify_attr_mongo_universal: Unknown SDK error"}
696
+ end
697
+ internal_func.printer_texter(out_resp, "debug")
698
+ out_resp
699
+ end
700
+
701
+ end
526
702
 
527
- end
@@ -1,3 +1,3 @@
1
1
  module Imperituroard
2
- VERSION = "0.5.9"
2
+ VERSION = "1.0.0"
3
3
  end
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.0
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-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler