imperituroard 0.2.2 → 0.2.3

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: 6c27b1af6fc8da6333b67a5c283bb1ae02a7a475
4
- data.tar.gz: 1191a3d14976315a5d03b4c4efd10208a36e65f9
3
+ metadata.gz: 46aa713f31f0c1e5b2d3f03b38f982e3e8c81f49
4
+ data.tar.gz: b467695375d37a96b7b83d367ecae06f1cee0f9a
5
5
  SHA512:
6
- metadata.gz: fe7261a30e0f300ad63eda191ffe88ec4fae8fac984fa5dc460df5db13da1f096df2b1b378220dee2ec9d4abd9541fb22edeec1f0731953540e863fbb7c99955
7
- data.tar.gz: 4abebbab6074f3dd1ae35d5bb66cab71eb424950d3aafb640669200f4ff976cdf1f84231c3c77ff96c4c4262b0b037e907232c838cb2c2eb68842d7462801616
6
+ metadata.gz: a3fbecc2ba5f4c8d2ff27596a3722ff478a2353802c7528a782fb9ba4f517b7adb1594026be032afb3e1a18706b381c9806dfc936c4e1fd7b934675433c3b62e
7
+ data.tar.gz: 36a662f1bb948831b07e42d061364909bf14ada71f7eabd2ea49c7e9adda2efd55de9dae9f29906fe691b08f2f7c4a12e5e1782f303686cd5e45800b047bb041
@@ -6,6 +6,7 @@ require 'savon'
6
6
 
7
7
  class Pcps
8
8
  attr_accessor :wsdl, :endpoint, :namespace, :clientcps
9
+
9
10
  def initialize(wsdl, endpoint, namespace)
10
11
  @wsdl = wsdl
11
12
  @endpoint = endpoint
@@ -22,7 +23,7 @@ class Pcps
22
23
 
23
24
  def avp_attr_list(username)
24
25
 
25
- message2 = { :networkId => username }
26
+ message2 = {:networkId => username}
26
27
  response = clientcps.call(:get_subscriber) do
27
28
  message(message2)
28
29
  end
@@ -96,7 +97,7 @@ class Pcps
96
97
 
97
98
 
98
99
  def get_current_attributes(msisdn)
99
- message2 = { :networkId => msisdn }
100
+ message2 = {:networkId => msisdn}
100
101
  response = clientcps.call(:get_subscriber) do
101
102
  message(message2)
102
103
  end
@@ -131,10 +132,10 @@ class Pcps
131
132
  end
132
133
  end
133
134
 
134
- added_res = add_attribute(res_list, new_msisdn)
135
+ added_res = add_attribute(res_list, new_msisdn)
135
136
 
136
137
  if added_res == "0"
137
- ans = del_attribute(old_msisdn)
138
+ ans = del_attribute(old_msisdn)
138
139
  p ans
139
140
  end
140
141
 
@@ -146,5 +147,4 @@ class Pcps
146
147
  end
147
148
 
148
149
 
149
-
150
150
  end
@@ -62,6 +62,8 @@ class MongoIot
62
62
  end
63
63
 
64
64
  def get_imei_info_from_db(imeilist)
65
+ p imeilist
66
+ p "imeilist"
65
67
  begin
66
68
  req2 = []
67
69
  result_ps = []
@@ -119,7 +121,7 @@ class MongoIot
119
121
  p "sgsgsd"
120
122
  for j in get_login_info[:body]
121
123
  p j
122
- if j["profile_id"]==dst_profile["profile_id"]
124
+ if j["profile_id"].to_i==dst_profile["profile_id"].to_i
123
125
  access=0
124
126
  end
125
127
  if access==0
@@ -145,18 +147,18 @@ class MongoIot
145
147
  p get_login_info
146
148
  access=1
147
149
  if get_login_info[:body]!=[]
148
- p "sgsgsd"
149
- for j in get_login_info[:body]
150
- p j
151
- if j["profile_id"]==profile_id
152
- access=0
153
- end
154
- if access==0
155
- return {:code => 200, :result => "Permission granted"}
156
- else
157
- return {:code => 400, :result => "Access denied. This incident will be reported."}
158
- end
150
+ p "sgsgsd"
151
+ for j in get_login_info[:body]
152
+ p j
153
+ if j["profile_id"].to_i==profile_id.to_i
154
+ access=0
155
+ end
156
+ if access==0
157
+ return {:code => 200, :result => "Permission granted"}
158
+ else
159
+ return {:code => 400, :result => "Access denied. This incident will be reported."}
159
160
  end
161
+ end
160
162
  else
161
163
  {:code => 500, :result => "Login not found"}
162
164
  end
@@ -179,7 +181,7 @@ class MongoIot
179
181
  p not_ex
180
182
  p res_exists
181
183
  {:code => 200, :result => "check_imei_exists: Request completed successfully",
182
- :body => {:exists => res_exists, :not_exists => not_ex}}
184
+ :body => {:exists => res_exists, :not_exists => not_ex}}
183
185
  end
184
186
 
185
187
 
@@ -248,12 +250,18 @@ class MongoIot
248
250
 
249
251
  def device_remove_single_mongo(imei)
250
252
 
251
- collection = client[:device_imei]
252
- doc = {
253
- "imei" => imei
254
- }
255
- result = collection.delete_many(doc)
256
- p result
253
+ begin
254
+ collection = client[:device_imei]
255
+ doc = {
256
+ "imei" => imei
257
+ }
258
+ result = collection.delete_many(doc)
259
+ p result
260
+ return {:code => 200, :result => "device_remove_single_mongo: Request completed successfully"}
261
+ rescue
262
+ return {:code => 507, :result => "device_remove_single_mongo: Unknown SDK error"}
263
+ end
264
+
257
265
  end
258
266
 
259
267
  def device_modify_attr_mongo(imei, address)
@@ -264,9 +272,9 @@ class MongoIot
264
272
  }
265
273
  sett = {'$set' => {address: address}}
266
274
  result = collection.update_one(doc, sett)
267
- p result
275
+ return {:code => 200, :result => "device_modify_attr_mongo: Request completed successfully"}
268
276
  rescue
269
- continue
277
+ return {:code => 507, :result => "device_remove_single_mongo: Unknown SDK error"}
270
278
  end
271
279
  end
272
280
 
@@ -1,3 +1,3 @@
1
1
  module Imperituroard
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/imperituroard.rb CHANGED
@@ -23,7 +23,7 @@ module Imperituroard
23
23
  # Your code goes here...
24
24
  end
25
25
 
26
- module Phpipam
26
+ module PhpipamModule
27
27
  def test(ggg)
28
28
  p ggg
29
29
  end
@@ -81,7 +81,7 @@ class Pipam
81
81
  end
82
82
  end
83
83
 
84
- include Phpipam
84
+ include PhpipamModule
85
85
  end
86
86
 
87
87
  class Iot
@@ -131,44 +131,50 @@ class Iot
131
131
  begin
132
132
  thr1 = Thread.new do
133
133
 
134
- imei = []
135
- list1 = {}
136
- for_insert = []
137
- not_processed_list = []
138
- processed_list = []
134
+ imei = []
135
+ list1 = {}
136
+ for_insert = []
137
+ not_processed_list = []
138
+ processed_list = []
139
139
 
140
- for ii in imei_list
141
- list1[ii["imei"]] = ii
142
- imei.append(ii["imei"])
143
- end
144
- list_checked = mongo_client.check_imei_exists(imei)
145
- for ss in list_checked[:body][:exists]
146
- not_processed_list.append({:imei=>ss, :error => "Device exists in database"})
147
- end
148
-
149
- for jj in list_checked[:body][:not_exists]
150
- begin
151
- get_login_info = mongo_client.check_login_prof_perm_id_one(login, list1[jj]["profile"])[:code]
152
- if get_login_info==200
153
- for_insert.append(list1[jj])
154
- else
155
- not_processed_list.append({:imei=>list1[jj], :error => "Permission denied for this profile"})
140
+ for ii in imei_list
141
+ list1[ii["imei"]] = ii
142
+ imei.append(ii["imei"])
143
+ end
144
+ list_checked = mongo_client.check_imei_exists(imei)
145
+ for ss in list_checked[:body][:exists]
146
+ not_processed_list.append({:imei => ss, :error => "Device exists in database"})
156
147
  end
157
- rescue
158
- not_processed_list.append({:imei=>list1[jj], :error => "Unknown error"})
159
- end
160
- end
161
148
 
162
- begin
163
- if for_insert!=[]
164
- mongo_client.imei_insert_list(for_insert)
165
- resp_out = {:code => 200, :result => "Data processed", :body => {:imei_processed => for_insert, :error_list => not_processed_list}}
166
- else
167
- resp_out = {:code => 202, :result => "Nothing for insertion", :body => {:imei_processed => for_insert, :error_list => not_processed_list}}
149
+ for jj in list_checked[:body][:not_exists]
150
+ begin
151
+ get_login_info = mongo_client.check_login_prof_perm_id_one(login, list1[jj]["profile"])[:code]
152
+ if get_login_info==200
168
153
 
154
+
155
+ for_insert.append(list1[jj])
156
+ else
157
+ not_processed_list.append({:imei => list1[jj], :error => "Permission denied for this profile"})
158
+ end
159
+ rescue
160
+ not_processed_list.append({:imei => list1[jj], :error => "Unknown error"})
161
+ end
169
162
  end
170
- rescue
171
- resp_out = {:code => 505, :result => "Error with database communication"}
163
+
164
+ begin
165
+ if for_insert!=[]
166
+ ##Logic for IOT Platform connection###
167
+
168
+ #########end iot platform logic#######
169
+
170
+ mongo_client.imei_insert_list(for_insert)
171
+ resp_out = {:code => 200, :result => "Data processed", :body => {:imei_processed => for_insert, :error_list => not_processed_list}}
172
+ else
173
+ resp_out = {:code => 202, :result => "Nothing for insertion", :body => {:imei_processed => for_insert, :error_list => not_processed_list}}
174
+
175
+ end
176
+ rescue
177
+ resp_out = {:code => 505, :result => "Error with database communication"}
172
178
  end
173
179
  end
174
180
  rescue
@@ -232,93 +238,207 @@ class Iot
232
238
  resp
233
239
  end
234
240
 
235
- #3 device modify, change imei
241
+ #!3 device modify, change imei
236
242
  #login
237
243
  #imei_old
238
244
  #imei_new
239
245
  #massive commands
240
- #im_list = [{:imei_old=>7967843245667, :imei_new=>7967843245665}]
241
- #+
242
- def imei_replace(login, im_list)
246
+ #im_list = [{"imei_old"=>7967843245667, "imei_new"=>7967843245665}]
247
+ #++
248
+ def imei_replace(login, im_list, remote_ip)
243
249
  input_json = {:login => login, :imei_list => im_list}
250
+
251
+ li_new_imei = []
252
+ list1 = {}
253
+ not_processed_list = []
254
+ approved_list = []
255
+ resp_out = {}
256
+
257
+ for pr1 in im_list
258
+ p "pr1"
259
+ p pr1
260
+ li_new_imei.append(pr1["imei_new"])
261
+ list1[pr1["imei_new"]]=pr1["imei_old"]
262
+ end
263
+
264
+ p list1
265
+
244
266
  begin
245
- for a in im_list
246
- p a
247
- prof_name1 = mongo_client.get_profile_name_from_imei(a[:imei_old])
248
- p prof_name1
249
- permiss1 = mongo_client.check_login_profile_permiss(login, prof_name1["profile"])[:code]
250
- if permiss1==200
251
- mongo_client.device_modify_any_attr_mongo(a[:imei_old], {:imei => a[:imei_new]})
267
+
268
+ thr3 = Thread.new do
269
+
270
+ list_checked = mongo_client.check_imei_exists(li_new_imei)
271
+ for ss in list_checked[:body][:exists]
272
+ not_processed_list.append({:record => {:imei_old => list1[ss], :imei_new => ss}, :error => "New IMEI exists in database"})
252
273
  end
274
+
275
+ step2_list = list_checked[:body][:not_exists]
276
+
277
+ for a in step2_list
278
+ begin
279
+ p "list1[a]"
280
+ p list1
281
+ p a
282
+ p list1[a]
283
+ prof_name1 = mongo_client.get_profile_name_from_imei(list1[a])
284
+
285
+ p prof_name1
286
+ if prof_name1[:code]==200
287
+
288
+ p "if prof_name1[:code]==200"
289
+
290
+ permiss1 = mongo_client.check_login_profile_permiss(login, prof_name1[:body]["profile"])[:code]
291
+ p "permiss1"
292
+ p permiss1
293
+ if permiss1==200
294
+
295
+ ##Logic for IOT Platform connection###
296
+
297
+ #########end iot platform logic#######
298
+
299
+ mongo_client.device_modify_any_attr_mongo(list1[a], {:imei => a})
300
+
301
+ approved_list.append({:imei_old => list1[a], :imei_new => a})
302
+
303
+
304
+ else
305
+ not_processed_list.append({:record => {:imei_old => list1[a], :imei_new => a}, :error => "Old IMEI modification denied"})
306
+ end
307
+ else
308
+ not_processed_list.append({:record => {:imei_old => list1[a], :imei_new => a}, :error => "Old IMEI not exists in database"})
309
+ end
310
+ rescue
311
+ not_processed_list.append({:record => {:imei_old => list1[a], :imei_new => a}, :error => "Unknown error"})
312
+ end
313
+ end
314
+
315
+ if approved_list!=[]
316
+ resp_out = {:code => 200, :result => "Request completed successfully", :data => {:approved_list => approved_list, :unapproved_list => not_processed_list}}
317
+ else
318
+ resp_out = {:code => 202, :result => "Nothing to do", :data => {:approved_list => approved_list, :unapproved_list => not_processed_list}}
319
+ end
320
+
253
321
  end
322
+
323
+
254
324
  rescue
255
- {:code => 507, :result => "Unknown SDK error"}
325
+ resp_out = {:code => 507, :result => "Unknown SDK error"}
256
326
  end
257
327
 
258
- mongo_client.audit_logger("add_device_to_profile", "127.0.0.1", input_json, "resp")
328
+ thr3.join
329
+ mongo_client.audit_logger("imei_replace", remote_ip, input_json, resp_out)
330
+
331
+ resp_out
259
332
 
260
333
  end
261
334
 
262
335
 
263
- #4 remove device
336
+ #!4 remove device
264
337
  #login
265
338
  #imei
266
339
  # not massive commands
267
340
  #imei=11341341234
268
341
  #login="test"
269
- #+
270
- def device_remove(login, imei)
342
+ #++
343
+ def device_remove(login, imei, remote_ip)
271
344
 
272
345
  input_json = {:login => login, :imei_list => imei}
273
- resp = {}
346
+ resp_out = {}
274
347
 
275
348
  begin
276
-
349
+ thr4 = Thread.new do
277
350
  prof_name = mongo_client.get_profile_name_from_imei(imei)
278
- permiss = mongo_client.check_login_profile_permiss(login, prof_name["profile"])[:code]
279
- if permiss==200
280
- resp = mongo_client.device_remove_single_mongo(imei)
351
+ if prof_name[:code]==200
352
+ permiss = mongo_client.check_login_profile_permiss(login, prof_name[:body]["profile"])
353
+ if permiss[:code]==200
354
+
355
+ ##Logic for IOT Platform connection###
356
+
357
+ #########end iot platform logic#######
358
+
359
+ resp = mongo_client.device_remove_single_mongo(imei)
360
+
361
+ if resp[:code]==200
362
+ resp_out = {:code => 200, :result => "Request completed successfully"}
363
+ else
364
+ resp_out=resp
365
+ end
366
+ else
367
+ resp_out=permiss
368
+ end
369
+ else
370
+ resp_out=prof_name
371
+ end
281
372
  end
373
+
282
374
  rescue
283
- {:code => 507, :result => "Unknown SDK error"}
375
+ resp_out = {:code => 507, :result => "Unknown SDK error"}
284
376
  end
285
- mongo_client.audit_logger("device_remove", "127.0.0.1", input_json, "resp")
286
- resp
377
+ thr4.join
378
+ mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out)
379
+ resp_out
287
380
  end
288
381
 
289
382
 
290
- #5 add address to device
383
+ #!5 add address to device
291
384
  #login
292
385
  #imei = newdevice_list
293
386
  #address = newdevice_list
294
387
  #newdevice_list=[{:imei=>7967843245665, :address=>"Golubeva51"}]
295
- #+
296
- def device_add_address(login, newdevice_list)
297
- add_functions_connector.telegram_message(newdevice_list.to_s)
388
+ #++
389
+ def device_add_address(login, newdevice_list, remote_ip)
390
+ #add_functions_connector.telegram_message(newdevice_list.to_s)
298
391
  p newdevice_list
299
392
  p "gas"
300
393
  p MyJSON.valid?(newdevice_list[0].to_s)
301
394
  p "sdfsdfgs"
302
395
  input_json = {:login => login, :devices => newdevice_list}
396
+ resp_out = {}
397
+ not_processed = []
398
+ processed = []
303
399
  begin
304
- resp = {}
400
+ thr5 = Thread.new do
305
401
  for p in newdevice_list
306
402
  prof_name = mongo_client.get_profile_name_from_imei(p[:imei])
307
403
 
308
- p "prof_name"
309
- p prof_name
310
- permiss = mongo_client.check_login_profile_permiss(login, prof_name["profile"])[:code]
311
- if permiss==200
312
- resp = mongo_client.device_modify_attr_mongo(p[:imei], p[:address])
404
+ if prof_name[:code]==200
405
+ p "prof_name"
406
+ p prof_name
407
+ permiss = mongo_client.check_login_profile_permiss(login, prof_name[:body]["profile"])
408
+ if permiss[:code]==200
409
+
410
+ ##Logic for IOT Platform connection###
411
+
412
+ #########end iot platform logic#######
413
+
414
+
415
+ resp = mongo_client.device_modify_attr_mongo(p[:imei], p[:address])
416
+ if resp[:code]==200
417
+ processed.append({:imei=>p[:imei]})
418
+ end
419
+ else
420
+ not_processed.append({:imei=>p[:imei], :address=>p[:address], :error=>permiss})
421
+ end
422
+ else
423
+ not_processed.append({:imei=>p[:imei], :address=>p[:address], :error=>prof_name})
313
424
  end
314
425
  end
315
- return resp
426
+
427
+ if processed!=[]
428
+ resp_out = {:code => 200, :result => "Request completed successfully", :body => {:imei_processed => processed, :error_list => not_processed}}
429
+ else
430
+ resp_out = {:code => 202, :result => "Nothing processed", :body => {:imei_processed => processed, :error_list => not_processed}}
431
+ end
432
+ end
316
433
  rescue
317
- {:code => 507, :result => "Unknown SDK error"}
434
+ resp_out = {:code => 507, :result => "Unknown SDK error"}
318
435
  end
319
- mongo_client.audit_logger("device_remove", "127.0.0.1", input_json, "resp")
436
+ thr5.join
437
+ mongo_client.audit_logger("device_add_address", remote_ip, input_json, resp_out)
438
+ resp_out
320
439
  end
321
440
 
441
+
322
442
  #6 add service by SPA
323
443
  #imei
324
444
  #profile
@@ -326,7 +446,12 @@ class Iot
326
446
  #msisdn
327
447
  #newdevice_list=[{:imei=>7967843245665, :attributes=>{:address=>"Golubeva51", :profile=>"wqeqcqeqwev", :msisdn=>375298766719, :imsi=>25702858586756875}}]
328
448
  #+
329
- def add_service(login, device_list)
449
+ def add_service(login, device_list, remote_ip)
450
+
451
+ resp_out = {}
452
+
453
+ not_processed = []
454
+ processed = []
330
455
 
331
456
 
332
457
  input_json = {:login => login, :devices => device_list}
@@ -334,35 +459,69 @@ class Iot
334
459
  begin
335
460
 
336
461
  for g in device_list
462
+ p g
463
+
337
464
  prof_name1 = mongo_client.get_profile_name_from_imei(g[:imei])
338
465
  p prof_name1
339
- permiss1 = mongo_client.check_login_profile_permiss(login, prof_name1["profile"])[:code]
340
- p permiss1
341
- permiss2 = mongo_client.check_login_profile_permiss(login, g[:attributes][:profile])[:code]
342
- if permiss1==200 && permiss2==200
343
466
 
344
- attr = g[:attributes]
345
- #mod_attr = {}
467
+ if prof_name1[:code]==200
468
+ p prof_name1
469
+ permiss1 = mongo_client.check_login_profile_permiss(login, prof_name1[:body]["profile"])
470
+ p "permiss1"
471
+ p permiss1
472
+ if permiss1[:code]==200
473
+
474
+ if g[:attributes].key?(:profile)
475
+ permiss2 = mongo_client.check_login_profile_permiss(login, g[:attributes][:profile])[:code]
476
+
477
+ if permiss2==200
478
+
479
+ attr = g[:attributes]
480
+ #mod_attr = {}
481
+
482
+ if attr.key?(:profile)
483
+ if attr[:profile].is_a? Integer
484
+ p "Ok"
485
+ else
486
+ p new = mongo_client.get_profile_id_by_name(attr[:profile])
487
+ attr[:profile] = new["profile_id"]
488
+ end
489
+ end
490
+ p attr
491
+
492
+ mongo_client.device_modify_any_attr_mongo(g[:imei], attr)
493
+
494
+ processed.append(g[:imei])
495
+
496
+ else
497
+ not_processed.append({:imei=>g[:imei], :description=> "New profile permission error", :error=>permiss2 })
498
+ end
346
499
 
347
- if attr.key?(:profile)
348
- if attr[:profile].is_a? Integer
349
- p "Ok"
350
500
  else
351
- p new = mongo_client.get_profile_id_by_name(attr[:profile])
352
- attr[:profile] = new["profile_id"]
501
+ attr = g[:attributes]
502
+ mongo_client.device_modify_any_attr_mongo(g[:imei], attr)
503
+
504
+ processed.append(g[:imei])
505
+
353
506
  end
507
+
508
+
509
+ else
510
+ not_processed.append({:imei=>g[:imei], :description=> "Old profile permission error", :error=>permiss1 })
354
511
  end
355
- p attr
356
512
 
357
- mongo_client.device_modify_any_attr_mongo(g[:imei], attr)
513
+ else
514
+ not_processed.append({:imei=>g[:imei],:error=>prof_name1})
358
515
  end
516
+
359
517
  end
518
+ resp_out = {:code => 200, :result => "Request completed successfully", :body => {:imei_processed => processed, :error_list => not_processed}}
519
+
360
520
  rescue
361
- {:code => 507, :result => "Unknown SDK error"}
521
+ resp_out = {:code => 507, :result => "Unknown SDK error"}
362
522
  end
363
-
364
- mongo_client.audit_logger("device_remove", "127.0.0.1", input_json, "resp")
365
-
523
+ mongo_client.audit_logger("device_remove", remote_ip, input_json, resp_out)
524
+ resp_out
366
525
  end
367
526
 
368
527
 
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.2.2
4
+ version: 0.2.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-04-08 00:00:00.000000000 Z
11
+ date: 2020-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler