imperituroard 0.5.8 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dec8fb3791d83727a6bfd54fc71889481af42b42
4
- data.tar.gz: 583739817cad732740861c08845910e849770b55
3
+ metadata.gz: 5264f8d3d00a73980d4de22a91b93c49ccd65904
4
+ data.tar.gz: a165a821f4ea118ca20916f6ca512aa4d1f4b173
5
5
  SHA512:
6
- metadata.gz: 27b131265896d1793261ea994a011e436171f6d5e74bc0c11a4d2e7039545a715ca693be6faab217e321d52e41ae92a6488fb00027c9c2a3beab8fc24b4f198b
7
- data.tar.gz: c5d72b86f1168829d5287c14120f70705a1bfb317ee896071d84b161a0a6b2ec3495a3e3c525a2e1aa2aa0a7d530c78f76c8d790dfe0a290a9c56401a7d9f71e
6
+ metadata.gz: e8d44ca288a3ebadc98ebd0ad7844e781c1ca3085c4df144113f9cd61a349915f71565daeeaa460437d4b6da545a40f7577c488bc7f4f6ca09230dafacc535b1
7
+ data.tar.gz: 1161e315402988d67d08cb63d0c7660412a24d2826172e5d23c38f81d1fa876c84cfef2f56b83754a7f8ff3cbc1d45e2cdd1415b6cc96abb8c8a9a8a5c15739f
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.homepage = "https://rubygems.org/"
12
12
  spec.license = "MIT"
13
13
 
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
15
 
16
16
  spec.metadata["allowed_push_host"] = "https://rubygems.org/"
17
17
 
@@ -52,6 +52,6 @@ Gem::Specification.new do |spec|
52
52
  spec.add_dependency "simpleidn", "0.1.1"
53
53
  spec.add_dependency "net-scp", "3.0.0"
54
54
 
55
- spec.add_dependency "rails", "5.2.4.2"
55
+ spec.add_dependency "rails", "5.0.7.2"
56
56
 
57
57
  end
@@ -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,157 @@ 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
+
984
+ if curr_dev["new_profile"] != "nil" && curr_dev["new_profile"] != "null" && curr_dev["new_profile"] != "empty"
985
+ prof_new_id = mongo_client.get_profile_universal(curr_dev["new_profile"])["profile_id"]
986
+ else
987
+ prof_new_id = prof_name1[:body]["profile_id"]
988
+ end
989
+
990
+
991
+ if curr_dev["new_type"] != "nil" && curr_dev["new_type"] != "null" && curr_dev["new_type"] != "empty"
992
+ type_new_pr = curr_dev["new_type"]
993
+ else
994
+ type_new_pr = prof_name1[:imei_info][:body][0]["device_type"]
995
+ end
996
+
997
+
998
+ get_login_info = mongo_client.check_login_prof_perm_id_one(inp_login, prof_name1[:body]["profile_id"])
999
+ if get_login_info[:code] == 200
1000
+ get_login_info_new = mongo_client.check_login_prof_perm_id_one(inp_login, prof_new_id)
1001
+ if get_login_info_new[:code] == 200
1002
+ cur_comp1 = mongo_client.compare_profiles(prof_name1[:body]["profile_id"], prof_new_id)
1003
+ cur_comp2 = mongo_client.compare_device_types(prof_name1[:imei_info][:body][0]["device_type"], type_new_pr)
1004
+
1005
+ if cur_comp1[:is_the_same] && cur_comp2[:is_the_same]
1006
+ #the same. Nothing to do
1007
+ processed_list.append(curr_dev)
1008
+ ########
1009
+ else
1010
+ credentials_old = mongo_client.get_iot_oceanconn_credent_2(prof_name1[:body]["profile"])
1011
+ credentials_new = mongo_client.get_iot_oceanconn_credent_2(prof_new_id)
1012
+ #########
1013
+ if credentials_old[:code] == 200 && credentials_new[:code] == 200
1014
+ imei_data = mongo_client.get_imei_info_from_db([curr_dev["imei"].to_i])
1015
+ if imei_data[:body] != []
1016
+ ans = {}
1017
+ if imei_data[:body][0]["huadata"]["body"]["deviceId"] != nil
1018
+ model_data = mongo_client.get_device_type_info_universal(type_new_pr)
1019
+ #####all checks completed. then process data#####
1020
+ 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"])
1021
+
1022
+ if ans_old[:code].to_i == 200 || ans_old[:code].to_i == 202 || ans_old[:code].to_i == 204
1023
+ begin
1024
+ resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials_new[:body][:app_id],
1025
+ credentials_new[:body][:secret],
1026
+ curr_dev["imei"].to_i,
1027
+ curr_dev["imei"].to_s,
1028
+ prof_name1[:body]["description"],
1029
+ model_data[:body]["device_type"],
1030
+ curr_dev["new_profile"],
1031
+ model_data[:body]["ManufacturerID"],
1032
+ model_data[:body]["ManufacturerNAME"],
1033
+ model_data[:body]["model"]
1034
+ )
1035
+ if resss[:code]=="200"
1036
+ if resss[:body].key?("error_code") && resss[:body]["error_code"] != 200
1037
+ not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1038
+ else
1039
+ new_id_iot = resss[:body]
1040
+ new_profile_id = prof_new_id
1041
+ now_date = DateTime.now
1042
+ #finished success. update database
1043
+ attribute = {profile: new_profile_id, device_type: model_data[:body]["model"], huadata: {body: new_id_iot}, updated: now_date}
1044
+ answ_mongo = mongo_client.modify_attr_mongo_universal(curr_dev["imei"].to_i, attribute)
1045
+ if answ_mongo[:code] != 200
1046
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Critical error. Mongo not updated", :mongo_err => answ_mongo})
1047
+ else
1048
+ processed_list.append(curr_dev)
1049
+ end
1050
+ #added_on_iot_platf.append(s1)
1051
+ end
1052
+ else
1053
+ not_processed_list.append({:imei => curr_dev["imei"], :error => resss})
1054
+ end
1055
+ rescue
1056
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown error with insertion imei on IOT platform"})
1057
+ end
1058
+ end
1059
+ else
1060
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Not processed by iot platform. deviceId not found in mongoDB"})
1061
+ end
1062
+ else
1063
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get info from database"})
1064
+ end
1065
+ else
1066
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Failed to get credentials from database"})
1067
+ end
1068
+ end
1069
+ else
1070
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "New profile modification not permitted"})
1071
+ end
1072
+ else
1073
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Old profile modification not permitted"})
1074
+ end
1075
+ else
1076
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown current profile"})
1077
+ end
1078
+ else
1079
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Device not exists"})
1080
+ end
1081
+ else
1082
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "IMEI can't be nil"})
1083
+ end
1084
+ rescue
1085
+ not_processed_list.append({:imei => curr_dev["imei"], :error => "Unknown SDK error"})
1086
+ end
1087
+
1088
+ end
1089
+
1090
+ err_li = []
1091
+ if not_processed_list.length > 0
1092
+ not_processed_list.each do |err_l|
1093
+ err_li.append({:failedimei => err_l[:imei]})
1094
+ end
1095
+ end
1096
+
1097
+ if processed_list.length > 0
1098
+ soap_answ = {:code=>200, :result=>"Success", :body=>{:processednum => processed_list.length, :failednum => not_processed_list.length, :deviceserr => err_li}}
1099
+ else
1100
+ soap_answ = {:code=>202, :result=>"Nothing done", :body=>{:processednum => 0, :failednum => not_processed_list.length, :deviceserr => err_li}}
1101
+ end
1102
+
1103
+ output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => soap_answ, :not_processed_list => not_processed_list, :processed_list => processed_list}}
1104
+ mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip)
1105
+ output_answ
1106
+ end
1107
+
1108
+
1109
+ #14
949
1110
  #additional procedure for checking status on iot platform
950
1111
  def get_info_by_imeilist_from_iot(login, imei_list)
951
1112
  resp_out={}
@@ -998,10 +1159,10 @@ class IotFunctions_2
998
1159
  p resp_out[:body]
999
1160
  p "resp_out[:body][\"devices\"]"
1000
1161
 
1001
- if resp_out[:body] == nil || resp_out[:body] == {} || resp_out[:body] == {"devices"=>nil}
1162
+ if resp_out[:body] == nil || resp_out[:body] == {} || resp_out[:body] == {"devices" => nil}
1002
1163
  p "step1111"
1003
1164
  p resp_out_1[:body]["devices"]
1004
- resp_out[:body] = { 'devices' => resp_out_1[:body]["devices"]}
1165
+ resp_out[:body] = {'devices' => resp_out_1[:body]["devices"]}
1005
1166
  p "step22222"
1006
1167
  else
1007
1168
  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)
@@ -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,4 @@
1
1
  module Imperituroard
2
- VERSION = "0.5.8"
2
+ VERSION = "1.0.3"
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.8
4
+ version: 1.0.3
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
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 5.2.4.2
173
+ version: 5.0.7.2
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 5.2.4.2
180
+ version: 5.0.7.2
181
181
  description: Gem from imperituroard for different actions
182
182
  email:
183
183
  - imperituro.ard@gmail.com
@@ -249,7 +249,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
249
249
  requirements:
250
250
  - - ">="
251
251
  - !ruby/object:Gem::Version
252
- version: 2.5.0
252
+ version: 2.3.0
253
253
  required_rubygems_version: !ruby/object:Gem::Requirement
254
254
  requirements:
255
255
  - - ">="