imperituroard 0.5.7 → 1.0.2

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: 96222a0e0f14b7abc4ff4d1434d6c55115f07623
4
- data.tar.gz: 8d1d4264fa33fec3d27cfb5c7c900c1f293a1112
3
+ metadata.gz: e940fef724694620f92446e776b76f186aefb9f2
4
+ data.tar.gz: 7684c9da421ec5e068e1992aa69d9908d8617398
5
5
  SHA512:
6
- metadata.gz: 3c8887a0051b6fb3e7d57d3092ae7ac343f677e32d2e24a2ebaaaf8e54acd15662ad41185d4e2c588a2987001c2c7a5a8fcdc24eb7c65bad6633bdf316f7634b
7
- data.tar.gz: 98c743b8d56c5a6b637edeb8f11445664ab30af49625eae7d6d1e76f9fa04cebb9dffb07b30fa16a230b08034a86314c8eac6f93e9981476266c296f73113368
6
+ metadata.gz: 192b9dc5e4d12006aa68c10cd50455edffb5c6d0ed0452022437653c7780c506e40a99bf2a084c1ce264fd4f5214e8511e37f4e8c32e505a8b54638be9422bab
7
+ data.tar.gz: 65d41e4c02a8f54585dd6652e9637e60b0b60204788d7e0bcfd50ed7632ee3c9959dc7f50a26745189a11cf8104f1859843d67cedb0ed47602df6463a3d8b559
@@ -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
Binary file
@@ -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
Binary file
@@ -0,0 +1,95 @@
1
+ require 'net/ssh'
2
+
3
+ staros_thr_1233 = []
4
+ conf = {}
5
+
6
+ staros_hosts = {
7
+ #5700
8
+ }
9
+
10
+ def printer (config)
11
+ for gggg1 in config
12
+
13
+ p ""
14
+ p ""
15
+ p "##{gggg1[0]}"
16
+ for jjj in gggg1[1]
17
+ p jjj
18
+ end
19
+ end
20
+ end
21
+
22
+ staros_hosts.each do |ggsn|
23
+ staros_thr_1233 << Thread.new do
24
+
25
+ p ggsn
26
+
27
+ begin
28
+
29
+ conf[ggsn[0]] = []
30
+
31
+ Net::SSH.start(ggsn[1], "ывапывап", :password => "пыапыва") do |ssh|
32
+ staros_answer = ssh.exec!("show configuration context Ga | grep edr")
33
+
34
+ regexp = /file name (\S+) rotation volume (\d+) rotation time \d+ storage-limit \d+ headers edr-format-name compression gzip file-sequence-number rulebase-seq-num/
35
+
36
+ ggg = staros_answer.match(regexp)
37
+ conf[ggsn[0]].push("configure")
38
+ conf[ggsn[0]].push("context Ga")
39
+ conf[ggsn[0]].push("edr-module active-charging-service charging")
40
+ conf[ggsn[0]].push("file name #{ggg[1]} rotation volume 40000000 rotation time 600 storage-limit 536870912 headers edr-format-name compression gzip file-sequence-number rulebase-seq-num")
41
+ conf[ggsn[0]].push("end")
42
+
43
+ #config
44
+ # staros_answer1 = ssh.exec!("configure")
45
+ # p staros_answer1
46
+ # staros_answer2 = ssh.exec!("context Ga")
47
+ # p staros_answer2
48
+ # staros_answer3 = ssh.exec!("edr-module active-charging-service charging")
49
+ # p staros_answer3
50
+ # staros_answer4 = ssh.exec!("file name #{ggg[1]} rotation volume 40000000 rotation time 600 storage-limit 536870912 headers edr-format-name compression gzip file-sequence-number rulebase-seq-num")
51
+ # p staros_answer4
52
+ # staros_answer5 = ssh.exec!("end")
53
+ # p staros_answer5
54
+
55
+ #check
56
+ staros_answer7 = ssh.exec!("show configuration | grep hostname")
57
+ reggg = /system hostname (\S+)/
58
+ hostname_this = staros_answer7.match(reggg)[1]
59
+
60
+ staros_answer8 = ssh.exec!("show configuration context Ga | grep edr")
61
+ regexp2 = /file name (\S+) rotation volume (\d+) rotation time \d+ storage-limit \d+ headers edr-format-name compression gzip file-sequence-number rulebase-seq-num/
62
+
63
+ ggg2 = staros_answer8.match(regexp2)
64
+
65
+ a1 = ggg2[1].gsub("edr-", "")
66
+ #p a1
67
+ #p hostname_this
68
+ #p ggg2
69
+
70
+ if a1 != hostname_this
71
+ p "incorrect: #{hostname_this}"
72
+ end
73
+
74
+
75
+ if ggg2[2] == "40000000"
76
+ else
77
+ p "incorrect value: #{hostname_this}"
78
+ end
79
+
80
+ end
81
+
82
+ rescue
83
+
84
+ p "#{ggsn[0]} ERROR"
85
+
86
+ end
87
+
88
+ end
89
+ end
90
+ staros_thr_1233.each(&:join)
91
+
92
+ #p conf
93
+
94
+
95
+ #printer(conf)
@@ -0,0 +1,37 @@
1
+ require 'net/ssh'
2
+
3
+ class StarosAutomationFun
4
+
5
+ attr_accessor :ignore_y
6
+
7
+ def initialize
8
+ @ignore_y = 1 #1-yes, 0-no
9
+ end
10
+
11
+ def staros_massive_command(staros_hosts, staros_login, staros_password, command_array)
12
+
13
+
14
+ staros_thr_pool_222 = []
15
+
16
+ staros_hosts.each do |ggsn|
17
+ staros_thr_pool_222 << Thread.new do
18
+
19
+ Net::SSH.start(ggsn[1], staros_login, :password => staros_password) do |session|
20
+
21
+ gg = session.exec!("context AAA")
22
+ p gg
23
+ gg1 = session.exec!("show subscribers summary")
24
+ p gg1
25
+
26
+
27
+
28
+ end
29
+
30
+
31
+
32
+ end
33
+ end
34
+ staros_thr_pool_222.each(&:join)
35
+
36
+ end
37
+ 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
+ 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
+ output_answ = {:code => 200, :result => "Success", :body => {:to_soap_gw => soap_answ, :not_processed_list => not_processed_list, :processed_list => processed_list}}
1103
+ mongo_client.audit_logger("set_data_replace_2", remote_ip, input_params, output_answ, real_ip)
1104
+ output_answ
1105
+
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