imperituroard 0.5.3 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/imperituroard.gemspec +3 -0
  3. data/lib/.DS_Store +0 -0
  4. data/lib/imperituroard.rb +47 -11
  5. data/lib/imperituroard/.DS_Store +0 -0
  6. data/lib/imperituroard/add_functions/logger/any_functions.rb +22 -0
  7. data/lib/imperituroard/platforms/cps/cps_multiple_thread_req.rb +0 -0
  8. data/lib/imperituroard/platforms/staros/get_data_ssh.rb +54 -0
  9. data/lib/imperituroard/platforms/staros/staros_automation.rb +95 -0
  10. data/lib/imperituroard/platforms/staros/staros_automation_fun.rb +37 -0
  11. data/lib/imperituroard/platforms/staros/staros_parser.rb +141 -0
  12. data/lib/imperituroard/projects/dns.rb +1 -1
  13. data/lib/imperituroard/projects/iot.rb +1 -1
  14. data/lib/imperituroard/projects/iot/add_functions.rb +27 -27
  15. data/lib/imperituroard/projects/mhub.rb +2 -0
  16. data/lib/imperituroard/projects/mhub/infobip.rb +1 -1
  17. data/lib/imperituroard/projects/mhub/sk.rb +171 -157
  18. data/lib/imperituroard/projects/mhub/subs/dabrab/dabrab_proced.rb +124 -12
  19. data/lib/imperituroard/projects/ukaz60.rb +140 -0
  20. data/lib/imperituroard/projects/ukaz60/belgim.rb +221 -0
  21. data/lib/imperituroard/projects/ukaz60/dns.rb +18 -0
  22. data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/dns_update.rb +2 -134
  23. data/lib/imperituroard/projects/ukaz60/fortigate.rb +210 -0
  24. data/lib/imperituroard/projects/ukaz60/staros.rb +141 -0
  25. data/lib/imperituroard/projects/ukaz60/ukaz60_add_func.rb +306 -0
  26. data/lib/imperituroard/projects/vpn/ezuev_fun/functions_ezuev.rb +29 -0
  27. data/lib/imperituroard/version.rb +1 -1
  28. metadata +30 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aed6187f630376b03b976303e1fa4f87800d036e
4
- data.tar.gz: 94fad4b56fd4a5926d3b6433ea7da900cd4d1e20
3
+ metadata.gz: dd14223003e59a7d5e907811784e45156363c086
4
+ data.tar.gz: 53254977a65f45d29edfc93d527b71307b97bcd6
5
5
  SHA512:
6
- metadata.gz: e445408da82e71836bb61a94c0ab26cb166e904b48b8aa03f23c0395803cfa3a2ce5026a89364bdfc88b1561c8148815465df8dfcd6313b60fe0e950baf494c8
7
- data.tar.gz: 740a6cbee54ce5949bf0059d3847a86bb66486f43d90b8e766ddf74b362e56f70e44784b71f2bc1643b32e27e11822f33b42c3145493a312948ad61e230c0370
6
+ metadata.gz: '059dd82d5c64924e88897d2685170dc7de79c333c3c1ba367d7f0897604cb554bf145cd3b20fc7fc014bb87c03f0dad42c48ac00fdf874d674535b7236afc45b'
7
+ data.tar.gz: 7b9f74f90c3cdf4c3286464622f8e4f4fd0792880039c3c7877a32ec94040ea38c883e65c8e51f1271fa13486f16990eaacd667308418bcae4514db46aa6e523
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = %q{Gem from imperituroard for different actions}
11
11
  spec.homepage = "https://rubygems.org/"
12
12
  spec.license = "MIT"
13
+
13
14
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
15
 
15
16
  spec.metadata["allowed_push_host"] = "https://rubygems.org/"
@@ -51,4 +52,6 @@ Gem::Specification.new do |spec|
51
52
  spec.add_dependency "simpleidn", "0.1.1"
52
53
  spec.add_dependency "net-scp", "3.0.0"
53
54
 
55
+ spec.add_dependency "rails", "5.0.7.2"
56
+
54
57
  end
Binary file
@@ -5,6 +5,7 @@ $LOAD_PATH.unshift File.expand_path("../projects/mhub/subs/dabrab", __dir__)
5
5
  $LOAD_PATH.unshift File.expand_path("../platforms/cps", __dir__)
6
6
  $LOAD_PATH.unshift File.expand_path("../platforms/public", __dir__)
7
7
  $LOAD_PATH.unshift File.expand_path("../projects", __dir__)
8
+ $LOAD_PATH.unshift File.expand_path("../projects/dns", __dir__)
8
9
 
9
10
 
10
11
  require "imperituroard/version"
@@ -23,6 +24,8 @@ require 'imperituroard/projects/iot'
23
24
  require 'imperituroard/projects/dns'
24
25
  require 'imperituroard/platforms/cps/qps_connector'
25
26
  require 'imperituroard/platforms/public/telegram'
27
+ require 'imperituroard/projects/ukaz60'
28
+
26
29
  require 'json'
27
30
  require 'ipaddr'
28
31
  require 'date'
@@ -194,8 +197,6 @@ class Iot
194
197
  end
195
198
 
196
199
 
197
-
198
-
199
200
  #!5 add address to device
200
201
  #login
201
202
  #imei = newdevice_list
@@ -254,7 +255,7 @@ class Iot
254
255
  end
255
256
 
256
257
  def test111
257
- iot_connector.test
258
+ iot_connector.test1278493
258
259
  end
259
260
 
260
261
 
@@ -328,7 +329,8 @@ end
328
329
 
329
330
  class Ukaz60Automation_2
330
331
 
331
- attr_accessor :dns
332
+ attr_accessor :dns,
333
+ :ukaz60_func
332
334
 
333
335
  def initialize(telegram_api_url,
334
336
  telegram_chat_id,
@@ -342,7 +344,26 @@ class Ukaz60Automation_2
342
344
  dns_password,
343
345
  belgim_login,
344
346
  belgim_password,
345
- belgim_url)
347
+ belgim_url,
348
+
349
+ ###########for fortigate############
350
+ ansible_tmp_folder, #folder on fortigate ansible server where url list uploaded
351
+ local_tmp_directory, #folder on local mashin where script work
352
+ ansible_ssh_user,
353
+ ansible_ssh_password,
354
+ ansible_host, #fortigate ansible server
355
+ url_backup_dir,
356
+ ####################################
357
+
358
+ #########for STAROS#############
359
+ staros_login,
360
+ staros_password,
361
+ ukaz60_http_groups,
362
+ ukaz60_https_groups,
363
+ staros_hosts
364
+
365
+ )
366
+ =begin
346
367
  @ukaz69_dns_func = Dns_2.new(telegram_api_url,
347
368
  telegram_chat_id,
348
369
  work_directory,
@@ -356,14 +377,29 @@ class Ukaz60Automation_2
356
377
  belgim_login,
357
378
  belgim_password,
358
379
  belgim_url)
380
+ =end
381
+
382
+ @ukaz60_func = Ukaz60All_2.new(telegram_api_url,
383
+ telegram_chat_id,
384
+ belgim_login,
385
+ belgim_password,
386
+ belgim_url,
387
+ ansible_tmp_folder,
388
+ local_tmp_directory,
389
+ ansible_ssh_user,
390
+ ansible_ssh_password,
391
+ ansible_host,
392
+ url_backup_dir,
393
+ staros_login,
394
+ staros_password,
395
+ ukaz60_http_groups,
396
+ ukaz60_https_groups,
397
+ staros_hosts)
359
398
  end
360
399
 
361
-
362
- def test
363
-
400
+ #1 block all devices by belgim list
401
+ def no_pasaran
402
+ ukaz60_func.no_pasaran
364
403
  end
365
404
 
366
-
367
-
368
-
369
405
  end
Binary file
@@ -0,0 +1,22 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'json'
4
+ require 'date'
5
+
6
+
7
+ class LogAddFunctions_2
8
+
9
+
10
+ def datetimenow()
11
+ d_curr = DateTime.now
12
+ time_zone = 'Europe/Minsk'
13
+ DateTime.now.to_s
14
+ end
15
+
16
+ def printer_texter(text, log_level)
17
+ mess = {:datetime => datetimenow, :sdk => "imperituroard", :sdk_version => Imperituroard::VERSION, :message => text}
18
+ p mess
19
+ end
20
+
21
+
22
+ end
@@ -0,0 +1,54 @@
1
+ require 'net/ssh'
2
+
3
+ require 'imperituroard/platforms/staros/staros_parser'
4
+
5
+ class StarosGet_2
6
+
7
+ attr_accessor :staros_parser, :staros_login, :staros_password
8
+
9
+ def initialize(staros_login, staros_password)
10
+ @staros_parser = StarosParser_2.new
11
+ @staros_login = staros_login
12
+ @staros_password = staros_password
13
+ end
14
+
15
+
16
+ #get all active-charging data
17
+ #host - staros device IP address
18
+ #return parsed ECS configuration in JSON
19
+ def get_all_active_charging(host_ip)
20
+
21
+ input_data = {:host_ip => host_ip}
22
+ out_data = {}
23
+ config_all = []
24
+
25
+ begin
26
+
27
+ Net::SSH.start(host_ip, staros_login, :password => staros_password) do |ssh|
28
+ staros_answer = ssh.exec!("show configuration active-charging service all")
29
+ staros_answer = staros_answer.gsub("#exit", "exit")
30
+ #staros_answer = staros_answer.gsub("\n", " ")
31
+ #p staros_answer
32
+ #host_pool_regexp = /(host-pool.+\s+exit)/
33
+ #fff = staros_answer.scan(host_pool_regexp)
34
+ #p fff
35
+
36
+ staros_answer = staros_answer.split("\n")
37
+ for ttt in staros_answer
38
+ regexp_full_command = /\s+(.+)/
39
+ group_ruled_ukaz60_9 = ttt.match(regexp_full_command)
40
+ if group_ruled_ukaz60_9 != nil
41
+ config_all.push(group_ruled_ukaz60_9[1])
42
+ else
43
+ config_all.push(ttt)
44
+ end
45
+ end
46
+ end
47
+ staros_json = staros_parser.ecs_config_parser(config_all)
48
+ out_data = {:code => 200, :result => "Successfully completed", :parsed_data => staros_json}
49
+ rescue
50
+ out_data = {:code => 507, :result => "get_all_active_charging: Unknown SDK error"}
51
+ end
52
+ out_data
53
+ end
54
+ end
@@ -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
@@ -0,0 +1,141 @@
1
+ class StarosParser_2
2
+
3
+
4
+ #parser for staros ECS configuration
5
+ def ecs_config_parser(config_string_array)
6
+
7
+ out_ans = {}
8
+ parsed_config = {"config" => {"active-charging service" => []}}
9
+ config_string_array.shift
10
+
11
+ # {"config" => {"active-charging service" => [{"ECS-SVC" => {"root" => [], "host-pool"=>{"1b1.nekurims.top"=>["ip 185.59.101.182/32"]}, "ruledef"=>{"VKONTAKTE_CDN_b"=>[]}}}}]}
12
+
13
+ flag_inter_ecs_name = 0
14
+ current_ecs_name = ""
15
+ current_section = "root"
16
+ current_section_name = ""
17
+ section_flag = 0
18
+ section_deep = 0
19
+ ecs_number = 0
20
+ for aaa in config_string_array
21
+ if section_deep == 0 && aaa[0..22] == "active-charging service" #&& flag_inter_ecs_name == 0
22
+ ecs_name_regexp = /active-charging service (\S+)/
23
+ current_ecs_name = aaa.match(ecs_name_regexp)[1]
24
+ #p current_ecs_name
25
+ parsed_config["config"]["active-charging service"].push({current_ecs_name => {"root" => [],
26
+ "host-pool" => {},
27
+ "port-map" => {},
28
+ "ruledef" => {},
29
+ "access-ruledef" => {},
30
+ "group-of-ruledefs" => {},
31
+ "packet-filter" => {},
32
+ "edr-format" => {},
33
+ "xheader-format" => {},
34
+ "charging-action" => {},
35
+ "rulebase" => {},
36
+ "fw-and-nat policy" => {}
37
+ }})
38
+ flag_inter_ecs_name = 1
39
+ section_deep = 1
40
+ current_section = "root"
41
+ else
42
+ if aaa == "exit" && section_deep == 2
43
+ section_flag = 0
44
+ section_deep = section_deep - 1
45
+ current_section = "root"
46
+ elsif aaa[0..9] == "host-pool " && section_flag == 0 && section_deep == 1
47
+ current_section = "host-pool"
48
+ ecs_hostpool_regexp = /host-pool\s+(.+)/
49
+ current_section_name = aaa.match(ecs_hostpool_regexp)[1]
50
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
51
+ section_flag = 1
52
+ section_deep = section_deep + 1
53
+ elsif aaa[0..8] == "port-map " && section_flag == 0 && section_deep == 1
54
+ current_section = "port-map"
55
+ ecs_portmap_regexp = /port-map\s+(.+)/
56
+ current_section_name = aaa.match(ecs_portmap_regexp)[1]
57
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
58
+ section_flag = 1
59
+ section_deep = section_deep + 1
60
+ elsif aaa[0..7] == "ruledef " && section_flag == 0 && section_deep == 1
61
+ current_section = "ruledef"
62
+ ecs_ruldef_regexp = /ruledef\s+(.+)/
63
+ current_section_name = aaa.match(ecs_ruldef_regexp)[1]
64
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
65
+ section_flag = 1
66
+ section_deep = section_deep + 1
67
+ elsif aaa[0..14] == "access-ruledef " && section_flag == 0 && section_deep == 1
68
+ current_section = "access-ruledef"
69
+ ecs_accruldef_regexp = /access-ruledef\s+(.+)/
70
+ current_section_name = aaa.match(ecs_accruldef_regexp)[1]
71
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
72
+ section_flag = 1
73
+ section_deep = section_deep + 1
74
+ elsif aaa[0..17] == "group-of-ruledefs " && section_flag == 0 && section_deep == 1
75
+ current_section = "group-of-ruledefs"
76
+ ecs_grruldef_regexp = /group-of-ruledefs\s+(.+)/
77
+ current_section_name = aaa.match(ecs_grruldef_regexp)[1]
78
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
79
+ section_flag = 1
80
+ section_deep = section_deep + 1
81
+ elsif aaa[0..13] == "packet-filter " && section_flag == 0 && section_deep == 1
82
+ current_section = "packet-filter"
83
+ ecs_packfil_regexp = /packet-filter\s+(.+)/
84
+ current_section_name = aaa.match(ecs_packfil_regexp)[1]
85
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
86
+ section_flag = 1
87
+ section_deep = section_deep + 1
88
+ elsif aaa[0..10] == "edr-format " && section_flag == 0 && section_deep == 1
89
+ current_section = "edr-format"
90
+ ecs_edrformat_regexp = /edr-format\s+(.+)/
91
+ current_section_name = aaa.match(ecs_edrformat_regexp)[1]
92
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
93
+ section_flag = 1
94
+ section_deep = section_deep + 1
95
+ elsif aaa[0..14] == "xheader-format " && section_flag == 0 && section_deep == 1
96
+ current_section = "xheader-format"
97
+ ecs_xheader_regexp = /xheader-format\s+(.+)/
98
+ current_section_name = aaa.match(ecs_xheader_regexp)[1]
99
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
100
+ section_flag = 1
101
+ section_deep = section_deep + 1
102
+ elsif aaa[0..15] == "charging-action " && section_flag == 0 && section_deep == 1
103
+ current_section = "charging-action"
104
+ ecs_xheader_regexp = /charging-action\s+(.+)/
105
+ current_section_name = aaa.match(ecs_xheader_regexp)[1]
106
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
107
+ section_flag = 1
108
+ section_deep = section_deep + 1
109
+ elsif aaa[0..8] == "rulebase " && section_flag == 0 && section_deep == 1
110
+ current_section = "rulebase"
111
+ ecs_xheader_regexp = /rulebase\s+(.+)/
112
+ current_section_name = aaa.match(ecs_xheader_regexp)[1]
113
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
114
+ section_flag = 1
115
+ section_deep = section_deep + 1
116
+ elsif aaa[0..17] == "fw-and-nat policy " && section_flag == 0 && section_deep == 1
117
+ current_section = "fw-and-nat policy"
118
+ ecs_xheader_regexp = /fw-and-nat policy\s+(.+)/
119
+ current_section_name = aaa.match(ecs_xheader_regexp)[1]
120
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name] = []
121
+ section_flag = 1
122
+ section_deep = section_deep + 1
123
+ elsif section_flag == 1 && current_section != "root" && current_section != "end" && section_deep == 2
124
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name][current_section][current_section_name].push(aaa)
125
+ elsif current_section == "root" && section_deep == 1 && aaa != "end"
126
+ parsed_config["config"]["active-charging service"][ecs_number][current_ecs_name]["root"].push(aaa)
127
+ elsif aaa == "end"
128
+ section_flag = 0
129
+ section_deep = 0
130
+ current_section = "end"
131
+ p "end"
132
+ else
133
+ p aaa
134
+ end
135
+ end
136
+ end
137
+ parsed_config
138
+ end
139
+ end
140
+
141
+