imperituroard 0.5.5 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/imperituroard.gemspec +4 -1
- data/lib/imperituroard.rb +34 -16
- data/lib/imperituroard/platforms/staros/get_data_ssh.rb +54 -0
- data/lib/imperituroard/platforms/staros/staros_parser.rb +141 -0
- data/lib/imperituroard/projects/dns.rb +1 -1
- data/lib/imperituroard/projects/iot.rb +1 -1
- data/lib/imperituroard/projects/mhub/infobip.rb +1 -1
- data/lib/imperituroard/projects/ukaz60.rb +138 -0
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/belgim.rb +43 -8
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/dns.rb +0 -0
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/dns_update.rb +0 -0
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/fortigate.rb +20 -4
- data/lib/imperituroard/projects/ukaz60/staros.rb +126 -0
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/ukaz60_add_func.rb +150 -4
- data/lib/imperituroard/version.rb +1 -1
- metadata +26 -9
- data/lib/imperituroard/projects/dns/ukaz60.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96222a0e0f14b7abc4ff4d1434d6c55115f07623
|
4
|
+
data.tar.gz: 8d1d4264fa33fec3d27cfb5c7c900c1f293a1112
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c8887a0051b6fb3e7d57d3092ae7ac343f677e32d2e24a2ebaaaf8e54acd15662ad41185d4e2c588a2987001c2c7a5a8fcdc24eb7c65bad6633bdf316f7634b
|
7
|
+
data.tar.gz: 98c743b8d56c5a6b637edeb8f11445664ab30af49625eae7d6d1e76f9fa04cebb9dffb07b30fa16a230b08034a86314c8eac6f93e9981476266c296f73113368
|
data/imperituroard.gemspec
CHANGED
@@ -10,7 +10,8 @@ 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.5.0")
|
14
15
|
|
15
16
|
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
16
17
|
|
@@ -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.2.4.2"
|
56
|
+
|
54
57
|
end
|
data/lib/imperituroard.rb
CHANGED
@@ -24,7 +24,7 @@ require 'imperituroard/projects/iot'
|
|
24
24
|
require 'imperituroard/projects/dns'
|
25
25
|
require 'imperituroard/platforms/cps/qps_connector'
|
26
26
|
require 'imperituroard/platforms/public/telegram'
|
27
|
-
require 'imperituroard/projects/
|
27
|
+
require 'imperituroard/projects/ukaz60'
|
28
28
|
|
29
29
|
require 'json'
|
30
30
|
require 'ipaddr'
|
@@ -255,7 +255,7 @@ class Iot
|
|
255
255
|
end
|
256
256
|
|
257
257
|
def test111
|
258
|
-
iot_connector.
|
258
|
+
iot_connector.test1278493
|
259
259
|
end
|
260
260
|
|
261
261
|
|
@@ -345,12 +345,24 @@ class Ukaz60Automation_2
|
|
345
345
|
belgim_login,
|
346
346
|
belgim_password,
|
347
347
|
belgim_url,
|
348
|
-
|
349
|
-
|
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
|
350
352
|
ansible_ssh_user,
|
351
353
|
ansible_ssh_password,
|
352
|
-
ansible_host,
|
353
|
-
url_backup_dir
|
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
|
+
)
|
354
366
|
=begin
|
355
367
|
@ukaz69_dns_func = Dns_2.new(telegram_api_url,
|
356
368
|
telegram_chat_id,
|
@@ -368,18 +380,24 @@ class Ukaz60Automation_2
|
|
368
380
|
=end
|
369
381
|
|
370
382
|
@ukaz60_func = Ukaz60All_2.new(telegram_api_url,
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
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)
|
381
398
|
end
|
382
399
|
|
400
|
+
#1 block all devices by belgim list
|
383
401
|
def no_pasaran
|
384
402
|
ukaz60_func.no_pasaran
|
385
403
|
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,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
|
+
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
|
7
7
|
|
8
|
-
class
|
8
|
+
class Infobip_2
|
9
9
|
|
10
10
|
def test
|
11
11
|
gg = "{\"destinations\"=>[{\"to\"=>{\"phoneNumber\"=>\"375297116638\", \"emailAddress\"=>nil}}], \"scenarioKey\"=>\"1\", \"viber\"=>nil, \"sms\"=>{\"text\"=>\"карточка готова\"}, \"sendAt\"=>\"2019-08-15T08:40:00.000\", \"notifyUrl\"=>\"https://bpmonline.bankdabrabyt.by:444/0/ServiceModel/ScGetReports.svc/GetReports\", \"notifyContentType\"=>\"application/json\", \"controller\"=>\"bank\", \"action\"=>\"api\", \"bank\"=>{\"destinations\"=>[{\"to\"=>{\"phoneNumber\"=>\"375297116638\", \"emailAddress\"=>nil}}], \"scenarioKey\"=>\"1\", \"viber\"=>nil, \"sms\"=>{\"text\"=>\"карточка готова\"}, \"sendAt\"=>\"2019-08-15T08:40:00.000\", \"notifyUrl\"=>\"https://bpmonline.bankdabrabyt.by:444/0/ServiceModel/ScGetReports.svc/GetReports\", \"notifyContentType\"=>\"application/json\"}}"
|
@@ -0,0 +1,138 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../projects/ukaz60", __dir__)
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require 'imperituroard/projects/ukaz60/belgim'
|
6
|
+
require 'imperituroard/projects/ukaz60/fortigate'
|
7
|
+
require 'imperituroard/projects/ukaz60/staros'
|
8
|
+
|
9
|
+
class Ukaz60All_2
|
10
|
+
|
11
|
+
attr_accessor :telegram_messanger,
|
12
|
+
:belgim_login,
|
13
|
+
:belgim_password,
|
14
|
+
:belgim_url,
|
15
|
+
:ukaz60_add_func,
|
16
|
+
:belgim_connector,
|
17
|
+
:forti_connector,
|
18
|
+
:staros_connector
|
19
|
+
|
20
|
+
def initialize(telegram_api_url,
|
21
|
+
telegram_chat_id,
|
22
|
+
belgim_login,
|
23
|
+
belgim_password,
|
24
|
+
belgim_url,
|
25
|
+
ansible_tmp_folder,
|
26
|
+
local_tmp_directory,
|
27
|
+
ansible_ssh_user,
|
28
|
+
ansible_ssh_password,
|
29
|
+
ansible_host,
|
30
|
+
url_backup_dir,
|
31
|
+
staros_login,
|
32
|
+
staros_password,
|
33
|
+
ukaz60_http_groups,
|
34
|
+
ukaz60_https_groups,
|
35
|
+
staros_hosts
|
36
|
+
|
37
|
+
)
|
38
|
+
@telegram_messanger = Telegram_2.new(telegram_api_url, telegram_chat_id)
|
39
|
+
@belgim_login = belgim_login
|
40
|
+
@belgim_password = belgim_password
|
41
|
+
@belgim_url = belgim_url
|
42
|
+
@ukaz60_add_func = AddFuncUkaz60_2.new
|
43
|
+
@belgim_connector = Belgim_2.new(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url)
|
44
|
+
@forti_connector = FortiUkaz60_2.new(ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir)
|
45
|
+
@staros_connector = Ukaz60Staros_2.new(staros_login, staros_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def forti_process(get_belgim_data)
|
50
|
+
forti_answer = {}
|
51
|
+
begin
|
52
|
+
format_for_forti = forti_connector.prepare_url_config_fortigate(get_belgim_data)
|
53
|
+
if format_for_forti[:code] == 200
|
54
|
+
url_uploading = forti_connector.upload_url(format_for_forti[:body][:to_fortigate])
|
55
|
+
if url_uploading[:code] == 200
|
56
|
+
update_fortigate_ansible = forti_connector.update_weburl_fortigate
|
57
|
+
if update_fortigate_ansible[:code] == 200
|
58
|
+
forti_answer = {:code => 200, :result => "Fortigate processed", :data => update_fortigate_ansible[:body][:body], :num_uploaded_to_forti => format_for_forti[:body][:num_list]}
|
59
|
+
else
|
60
|
+
forti_answer = {:code => update_fortigate_ansible[:code], :result => update_fortigate_ansible[:result]}
|
61
|
+
end
|
62
|
+
forti_connector.clean_tmp_folders
|
63
|
+
else
|
64
|
+
forti_answer = {:code => 401, :result => "Failed for uploading data to ansible server"}
|
65
|
+
end
|
66
|
+
else
|
67
|
+
forti_answer = {:code => 400, :result => "Error while processing data"}
|
68
|
+
end
|
69
|
+
rescue
|
70
|
+
forti_answer = {:code => 507, :result => "Unknown error with Forti"}
|
71
|
+
end
|
72
|
+
forti_answer
|
73
|
+
end
|
74
|
+
|
75
|
+
def staros_process(get_belgim_data)
|
76
|
+
|
77
|
+
output_starprocess = {}
|
78
|
+
|
79
|
+
begin
|
80
|
+
#get data from staros
|
81
|
+
staros_blocks_current = staros_connector.get_all_staros_ukaz60
|
82
|
+
|
83
|
+
if staros_blocks_current[:code] == 200
|
84
|
+
#compare data with belgim
|
85
|
+
answ = ukaz60_add_func.staros_compare_http(staros_blocks_current, get_belgim_data)
|
86
|
+
|
87
|
+
if answ[:code] == 200
|
88
|
+
#output_starprocess = {:code => 200, :result => "Staros processed", :data => {:block_me => answ[:body][:for_block][:notblocked_stat], :unblock_me =>answ[:body][:for_unblock][:for_unblock_stat]}}
|
89
|
+
output_starprocess = ukaz60_add_func.format_star_processed_answ(answ)[:body][:to_message]
|
90
|
+
else
|
91
|
+
output_starprocess = answ
|
92
|
+
end
|
93
|
+
|
94
|
+
else
|
95
|
+
output_starprocess = staros_blocks_current
|
96
|
+
end
|
97
|
+
rescue
|
98
|
+
output_starprocess = {:code => 507, :result => "staros_process: Something wrong"}
|
99
|
+
end
|
100
|
+
|
101
|
+
output_starprocess
|
102
|
+
end
|
103
|
+
|
104
|
+
def no_pasaran
|
105
|
+
|
106
|
+
answer_output = {}
|
107
|
+
forti_answer = {}
|
108
|
+
staros_answer = {}
|
109
|
+
|
110
|
+
begin
|
111
|
+
get_belgim_data = belgim_connector.belgim_ukaz60_get
|
112
|
+
|
113
|
+
if get_belgim_data[:code] == 200
|
114
|
+
|
115
|
+
thr_forti = Thread.new do
|
116
|
+
forti_answer = self.forti_process(get_belgim_data)
|
117
|
+
end
|
118
|
+
|
119
|
+
thr_staros = Thread.new do
|
120
|
+
staros_answer = staros_process(get_belgim_data)
|
121
|
+
end
|
122
|
+
|
123
|
+
thr_staros.join
|
124
|
+
thr_forti.join
|
125
|
+
|
126
|
+
answer_output = {:code => 200, :result => "No pasaran", :fortigate => forti_answer, :staros => staros_answer, :info_belgim => get_belgim_data[:number]}
|
127
|
+
else
|
128
|
+
answer_output = {:code => 404, :result => "Failed to receive data from Belgim"}
|
129
|
+
end
|
130
|
+
|
131
|
+
rescue
|
132
|
+
answer_output = {:code => 507, :result => "no_pasaran: Unknown SDK error"}
|
133
|
+
end
|
134
|
+
telegram_messanger.telegram_message(JSON.pretty_generate(answer_output))
|
135
|
+
answer_output
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'imperituroard/platforms/public/telegram'
|
2
|
-
require 'imperituroard/projects/
|
2
|
+
require 'imperituroard/projects/ukaz60/ukaz60_add_func'
|
3
3
|
|
4
4
|
require 'simpleidn'
|
5
5
|
|
@@ -45,6 +45,8 @@ class Belgim_2
|
|
45
45
|
url_parsed = []
|
46
46
|
ipv4_parsed = []
|
47
47
|
ipv6_parsed = []
|
48
|
+
https_parsed = []
|
49
|
+
url_all = []
|
48
50
|
|
49
51
|
f2 =[]
|
50
52
|
results = {}
|
@@ -99,7 +101,7 @@ class Belgim_2
|
|
99
101
|
processed_url = func_processed[:domain_only]
|
100
102
|
processed_domain_in_url = func_processed[:processed_domain_in_url]
|
101
103
|
|
102
|
-
if func_processed[:type] == "domain"
|
104
|
+
if func_processed[:type] == "domain"
|
103
105
|
domain_parsed.push(processed_url)
|
104
106
|
check_if_www = processed_url[0]+processed_url[1]+processed_url[2]+processed_url[3]
|
105
107
|
|
@@ -126,6 +128,17 @@ class Belgim_2
|
|
126
128
|
gar1url = processed_domain_in_url[4..processed_domain_in_url.length]
|
127
129
|
url_parsed.push(func_processed[:protocol] + "://" + gar1url)
|
128
130
|
end
|
131
|
+
elsif func_processed[:protocol] == "https"
|
132
|
+
#additional section for https urls
|
133
|
+
https_parsed.push(func_processed[:protocol] + "://" + processed_domain_in_url)
|
134
|
+
check_if_www2https = processed_domain_in_url[0]+processed_domain_in_url[1]+processed_domain_in_url[2]+processed_domain_in_url[3]
|
135
|
+
if check_if_www2https != "www."
|
136
|
+
https_parsed.push(func_processed[:protocol] + "://" + "www."+processed_domain_in_url)
|
137
|
+
end
|
138
|
+
if check_if_www2https == "www."
|
139
|
+
gar1url_https = processed_domain_in_url[4..processed_domain_in_url.length]
|
140
|
+
https_parsed.push(func_processed[:protocol] + "://" + gar1url_https)
|
141
|
+
end
|
129
142
|
end
|
130
143
|
end
|
131
144
|
end
|
@@ -154,22 +167,44 @@ class Belgim_2
|
|
154
167
|
url_parsed = url_parsed.uniq
|
155
168
|
ipv6_parsed = ipv6_parsed.uniq
|
156
169
|
ipv4_parsed = ipv4_parsed.uniq
|
170
|
+
https_parsed = https_parsed.uniq
|
171
|
+
|
172
|
+
https_parsed_tmmp = []
|
173
|
+
https_parsed.each do |tmp_tmp|
|
174
|
+
https_parsed_tmmp.push(tmp_tmp.gsub("https://", "http://"))
|
175
|
+
end
|
176
|
+
url_all = https_parsed_tmmp + url_parsed
|
177
|
+
url_all = url_all.uniq
|
178
|
+
url_all_num = url_all.length
|
179
|
+
|
157
180
|
|
158
181
|
dns_num = domain_parsed.length
|
159
182
|
ipv4_num = ipv4_parsed.length
|
160
183
|
ipv6_num = ipv6_parsed.length
|
161
184
|
url_num = url_parsed.length
|
185
|
+
https_num = https_parsed.length
|
186
|
+
|
187
|
+
all_num = dns_num + ipv4_num + ipv6_num + url_num + https_num
|
188
|
+
|
189
|
+
|
162
190
|
|
163
|
-
output_data = {:code => 200,
|
164
|
-
:
|
165
|
-
|
166
|
-
|
167
|
-
|
191
|
+
output_data = {:code => 200,
|
192
|
+
:result => "Request completed successfully",
|
193
|
+
:number => {:domain_num => dns_num,
|
194
|
+
:url_http_num => url_num,
|
195
|
+
:ipv4_num => ipv4_num,
|
196
|
+
:ipv6_num => ipv6_num,
|
197
|
+
:url_https_num => https_num,
|
198
|
+
:url_all_num => url_all_num,
|
199
|
+
:all_num => all_num
|
168
200
|
},
|
169
201
|
:domains_for_block => domain_parsed,
|
170
202
|
:url_for_block => url_parsed,
|
171
203
|
:ipv6_parsed => ipv6_parsed,
|
172
|
-
:ipv4_parsed => ipv4_parsed
|
204
|
+
:ipv4_parsed => ipv4_parsed,
|
205
|
+
:https_parsed => https_parsed,
|
206
|
+
:url_all => url_all
|
207
|
+
}
|
173
208
|
|
174
209
|
rescue
|
175
210
|
output_data = {:code => 507, :result => "belgim_ukaz60_get: Unknown error"}
|
File without changes
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'net/scp'
|
2
2
|
require 'date'
|
3
3
|
|
4
|
-
require 'imperituroard/projects/
|
4
|
+
require 'imperituroard/projects/ukaz60/ukaz60_add_func'
|
5
5
|
|
6
6
|
|
7
7
|
class FortiUkaz60_2
|
@@ -16,7 +16,12 @@ class FortiUkaz60_2
|
|
16
16
|
:url_backup_dir
|
17
17
|
|
18
18
|
|
19
|
-
def initialize(ansible_tmp_folder,
|
19
|
+
def initialize(ansible_tmp_folder,
|
20
|
+
local_tmp_directory,
|
21
|
+
ansible_ssh_user,
|
22
|
+
ansible_ssh_password,
|
23
|
+
ansible_host,
|
24
|
+
url_backup_dir)
|
20
25
|
@ansible_tmp_folder = ansible_tmp_folder
|
21
26
|
@local_tmp_directory = local_tmp_directory
|
22
27
|
@ansible_ssh_user = ansible_ssh_user
|
@@ -82,6 +87,8 @@ class FortiUkaz60_2
|
|
82
87
|
Net::SSH.start(ansible_host, ansible_ssh_user, :password => ansible_ssh_password) do |ssh|
|
83
88
|
ansible_answer = ssh.exec!(command)
|
84
89
|
end
|
90
|
+
p "ansible_answer: #{ansible_answer}"
|
91
|
+
|
85
92
|
#hh = "\nPLAY [ha_master] ***************************************************************\n\nTASK [set url table] ***********************************************************\nchanged: [gom32sg1]\nchanged: [bre32sg1]\nchanged: [min32sg1]\nchanged: [vit32sg1]\nchanged: [min32sg3]\nchanged: [gro32sg1]\nchanged: [mog32sg1]\n\nTASK [check current url table] *************************************************\nok: [min32sg1]\nok: [bre32sg1]\nok: [min32sg3]\nok: [vit32sg1]\nok: [gom32sg1]\nok: [gro32sg1]\nok: [mog32sg1]\n\nTASK [debug] *******************************************************************\nok: [min32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [min32sg3] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [bre32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [vit32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [gom32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [gro32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [mog32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\n\nPLAY RECAP *********************************************************************\nbre32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \ngom32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \ngro32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \nmin32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \nmin32sg3 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \nmog32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \nvit32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \n\n"
|
86
93
|
answ_pr = add_func_connector.ansible_answer_parse(ansible_answer)
|
87
94
|
output_data = {:code => 200, :result => "update_weburl_fortigate: Request completed", :body => answ_pr}
|
@@ -147,10 +154,19 @@ class FortiUkaz60_2
|
|
147
154
|
})
|
148
155
|
end
|
149
156
|
|
157
|
+
#for url in data_belgim[:url_for_block]
|
150
158
|
for url in data_belgim[:url_for_block]
|
151
|
-
|
159
|
+
format_url1 = add_func_connector.http_to_forti_prep(url)
|
160
|
+
to_fortigate.push({
|
161
|
+
"url" => format_url1,
|
162
|
+
"action" => "block"
|
163
|
+
})
|
164
|
+
end
|
165
|
+
|
166
|
+
for https in data_belgim[:https_parsed]
|
167
|
+
format_url2 = add_func_connector.https_to_forti_prep(https)
|
152
168
|
to_fortigate.push({
|
153
|
-
"url" =>
|
169
|
+
"url" => format_url2,
|
154
170
|
"action" => "block"
|
155
171
|
})
|
156
172
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
|
3
|
+
require 'imperituroard/platforms/staros/get_data_ssh'
|
4
|
+
|
5
|
+
|
6
|
+
class Ukaz60Staros_2
|
7
|
+
|
8
|
+
attr_accessor :staros_platform_get,
|
9
|
+
:ukaz60_http_groups,
|
10
|
+
:ukaz60_https_groups,
|
11
|
+
:staros_hosts
|
12
|
+
|
13
|
+
def initialize(star_login, star_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts)
|
14
|
+
@staros_platform_get = StarosGet_2.new(star_login, star_password)
|
15
|
+
@ukaz60_http_groups = ukaz60_http_groups
|
16
|
+
@ukaz60_https_groups = ukaz60_https_groups
|
17
|
+
@staros_hosts = staros_hosts
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
#get data from staros and return urls from staros
|
22
|
+
def get_data_staros(ip_staros)
|
23
|
+
|
24
|
+
input_data = {:ip_staros => ip_staros}
|
25
|
+
output_data = {}
|
26
|
+
ecs_name = ""
|
27
|
+
blocked_urls_http = []
|
28
|
+
blocked_urls_https = []
|
29
|
+
|
30
|
+
begin
|
31
|
+
ecs_config_json = staros_platform_get.get_all_active_charging(ip_staros)
|
32
|
+
|
33
|
+
if ecs_config_json[:code] == 200
|
34
|
+
|
35
|
+
#get ecs name
|
36
|
+
ecs_sss = ecs_config_json[:parsed_data]["config"]["active-charging service"][0]
|
37
|
+
ecs_sss.each do |hhh|
|
38
|
+
ecs_name = hhh[0]
|
39
|
+
end
|
40
|
+
|
41
|
+
regexp_ruldef = /add-ruledef priority \d+ ruledef (.+)/
|
42
|
+
|
43
|
+
#for http urls
|
44
|
+
begin
|
45
|
+
ukaz60_http_groups.each do |rule|
|
46
|
+
group_ruled_ukaz60 = ecs_config_json[:parsed_data]["config"]["active-charging service"][0][ecs_name]["group-of-ruledefs"][rule]
|
47
|
+
|
48
|
+
group_ruled_ukaz60.each do |gr_rul_str|
|
49
|
+
ruledef_name = gr_rul_str.match(regexp_ruldef)[1]
|
50
|
+
rdef_config = ecs_config_json[:parsed_data]["config"]["active-charging service"][0][ecs_name]["ruledef"][ruledef_name]
|
51
|
+
rdef_config.each do |g|
|
52
|
+
if g[0..15] == "www url contains"
|
53
|
+
blocked_urls_http.push({:url => g.gsub("www url contains ", ""), :ruledef => ruledef_name, :gr_of_ruledefs => rule, :gr_rul_str => gr_rul_str})
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
rescue
|
59
|
+
blocked_urls_http.push("failed")
|
60
|
+
end
|
61
|
+
|
62
|
+
for https_rule in ukaz60_https_groups
|
63
|
+
group_rule_https = ecs_config_json[:parsed_data]["config"]["active-charging service"][0][ecs_name]["group-of-ruledefs"][https_rule]
|
64
|
+
end
|
65
|
+
|
66
|
+
output_data = {:code => 200, :result => "Success", :ecs_name => ecs_name, :blocked_urls_http => blocked_urls_http, :http_rules_num => blocked_urls_http.length}
|
67
|
+
|
68
|
+
else
|
69
|
+
output_data = ecs_config_json
|
70
|
+
end
|
71
|
+
rescue
|
72
|
+
output_data = {:code => 507, :result => "get_data_staros: Unknown SDK error"}
|
73
|
+
end
|
74
|
+
output_data
|
75
|
+
# Net::SSH.start("172.24.214.17", "starscript", :password => "$rfv3EDC") do |ssh|
|
76
|
+
# staros_answer = ssh.exec!("show configuration active-charging service all")
|
77
|
+
# p staros_answer
|
78
|
+
#
|
79
|
+
# staros_answer = staros_answer.gsub("\n", "")
|
80
|
+
#
|
81
|
+
# regexp_ukaz60_9 = /group-of-ruledefs Ukaz60-9_HTTP.+HTTP\s+#exit/
|
82
|
+
# regexp_ukaz60_https = /group-of-ruledefs Ukaz60_HTTPS.+HTTPS\s+#exit/
|
83
|
+
# regexp_ukaz60_7 = /group-of-ruledefs Ukaz60-7_HTTP.+HTTP\s+#exit/
|
84
|
+
#
|
85
|
+
#
|
86
|
+
#
|
87
|
+
# group_ruled_ukaz60_9 = staros_answer.match(regexp_ukaz60_9)[0]
|
88
|
+
# group_ruled_ukaz60_https = staros_answer.match(regexp_ukaz60_https)[0]
|
89
|
+
# group_ruled_ukaz60_7 = staros_answer.match(regexp_ukaz60_7)[0]
|
90
|
+
#
|
91
|
+
# p group_ruled_ukaz60_9
|
92
|
+
# p group_ruled_ukaz60_https
|
93
|
+
# p group_ruled_ukaz60_7
|
94
|
+
#
|
95
|
+
# end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
#procedure for get data from all MPC
|
100
|
+
def get_all_staros_ukaz60
|
101
|
+
|
102
|
+
returned_data = {:mpc_data => [], :add_format => {}}
|
103
|
+
get_all_staros_ukaz60_1 = []
|
104
|
+
|
105
|
+
begin
|
106
|
+
staros_hosts.each do |ggsn|
|
107
|
+
get_all_staros_ukaz60_1 << Thread.new do
|
108
|
+
begin
|
109
|
+
mpc_data = self.get_data_staros(ggsn[1])
|
110
|
+
returned_data[:mpc_data].push({:code => 200, :result => "Success", :hostname => ggsn[0], :host_ip => ggsn[1], :body => mpc_data})
|
111
|
+
returned_data[:add_format][ggsn[0]] = mpc_data
|
112
|
+
rescue
|
113
|
+
returned_data[:mpc_data].push({:code => 507, :result => "Unknown thread error", :hostname => ggsn[0], :host_ip => ggsn[1], :body => {}})
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
get_all_staros_ukaz60_1.each(&:join)
|
118
|
+
returned_data[:code] = 200
|
119
|
+
returned_data[:result] = "get_all_staros_ukaz60: Success"
|
120
|
+
rescue
|
121
|
+
returned_data[:code] = 507
|
122
|
+
returned_data[:result] = "get_all_staros_ukaz60: Unknown SDK error"
|
123
|
+
end
|
124
|
+
returned_data
|
125
|
+
end
|
126
|
+
end
|
@@ -116,7 +116,8 @@ class AddFuncUkaz60_2
|
|
116
116
|
|
117
117
|
begin
|
118
118
|
answ_ans_parsed = answer_string.gsub("\n", " ")
|
119
|
-
result_out =
|
119
|
+
result_out = {}
|
120
|
+
#result_out = []
|
120
121
|
num_ok = 0
|
121
122
|
num_failed = 0
|
122
123
|
final_checks = /(\S+)\s+:\s+ok=(\d)\s+changed=(\d)\s+unreachable=(\d)\s+failed=(\d)\s+skipped=(\d)\s+rescued=(\d)\s+ignored=(\d)\s+/
|
@@ -126,14 +127,17 @@ class AddFuncUkaz60_2
|
|
126
127
|
for aaa in processed_data
|
127
128
|
begin
|
128
129
|
if aaa[1].to_i>0 && aaa[3].to_i==0 && aaa[4].to_i==0 && aaa[5].to_i==0 && aaa[6].to_i==0 && aaa[7].to_i==0
|
129
|
-
result_out
|
130
|
+
result_out[aaa[0]] = "Ok"
|
131
|
+
#result_out.push({aaa[0] => "Ok"})
|
130
132
|
num_ok = num_ok + 1
|
131
133
|
else
|
132
|
-
result_out
|
134
|
+
result_out[aaa[0]] = "Failed"
|
135
|
+
#result_out.push({aaa[0] => "Failed"})
|
133
136
|
num_failed = num_failed + 1
|
134
137
|
end
|
135
138
|
rescue
|
136
|
-
result_out
|
139
|
+
result_out["unknown"] = aaa.to_s
|
140
|
+
#result_out.push({"unknown" => aaa.to_s})
|
137
141
|
num_failed = num_failed + 1
|
138
142
|
end
|
139
143
|
end
|
@@ -148,4 +152,146 @@ class AddFuncUkaz60_2
|
|
148
152
|
output_data
|
149
153
|
end
|
150
154
|
|
155
|
+
|
156
|
+
def https_to_forti_prep(domain)
|
157
|
+
f0 = domain.gsub("#", "")
|
158
|
+
f1 = f0.gsub("https://", "").split("/")
|
159
|
+
f1[0]
|
160
|
+
end
|
161
|
+
|
162
|
+
def http_to_forti_prep(domain)
|
163
|
+
domain.gsub("#", "")
|
164
|
+
end
|
165
|
+
|
166
|
+
#result array2-array1
|
167
|
+
#array2 - all
|
168
|
+
#array1 - blocked
|
169
|
+
def array_hash_compare(array1, array2)
|
170
|
+
diff = []
|
171
|
+
array2.each do |h1|
|
172
|
+
if array1.include?(h1)
|
173
|
+
nil
|
174
|
+
else
|
175
|
+
diff.push(h1)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
diff
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
#procedure for compare http urls from staros and http urls from belgim
|
183
|
+
def staros_compare_http(data_staros, data_belgim)
|
184
|
+
|
185
|
+
notblocked_stat = {}
|
186
|
+
alert_unprotected = {}
|
187
|
+
alert_unprotected_out = {}
|
188
|
+
output_answ = {:body => {:for_block => {}, :for_unblock => {}}}
|
189
|
+
for_unblock_tmp = {}
|
190
|
+
for_unblock = {}
|
191
|
+
for_unblock_stat = {}
|
192
|
+
|
193
|
+
|
194
|
+
begin
|
195
|
+
#only for one ECS instance
|
196
|
+
data_staros[:mpc_data].each do |star_host|
|
197
|
+
alert_unprotected[star_host[:hostname]] = []
|
198
|
+
for_unblock_tmp[star_host[:hostname]] = []
|
199
|
+
|
200
|
+
#check if belgim http url is blocked on STAROS
|
201
|
+
data_belgim[:url_all].each do |belg_url|
|
202
|
+
blocked = 0
|
203
|
+
star_host[:body][:blocked_urls_http].each do |star_dom|
|
204
|
+
star_url_curr = star_dom[:url]
|
205
|
+
star_dom_len = star_url_curr.length
|
206
|
+
star_dom_x = ""
|
207
|
+
if star_url_curr[star_dom_len - 1] == "/"
|
208
|
+
star_dom_x = star_url_curr[0..star_dom_len - 2]
|
209
|
+
else
|
210
|
+
star_dom_x = star_url_curr
|
211
|
+
end
|
212
|
+
if belg_url.include?(star_dom_x)
|
213
|
+
blocked = 1
|
214
|
+
for_unblock_tmp[star_host[:hostname]].push(star_dom)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
if blocked == 0
|
218
|
+
alert_unprotected[star_host[:hostname]].push(belg_url)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
alert_unprotected.each do |proc_unpro|
|
224
|
+
da123 = proc_unpro[1]
|
225
|
+
alert_unprotected_out[proc_unpro[0]] = da123.uniq
|
226
|
+
notblocked_stat[proc_unpro[0]] = proc_unpro[1].length
|
227
|
+
end
|
228
|
+
|
229
|
+
for_unblock_tmp.each do |tmp_unbl|
|
230
|
+
hostname_st = tmp_unbl[0]
|
231
|
+
host_data_tmp = tmp_unbl[1].uniq
|
232
|
+
staros_all = data_staros[:add_format][hostname_st][:blocked_urls_http].uniq
|
233
|
+
da_annn = self.array_hash_compare(host_data_tmp, staros_all)
|
234
|
+
for_unblock[hostname_st] = da_annn.uniq
|
235
|
+
for_unblock_stat[hostname_st] = da_annn.uniq.length
|
236
|
+
end
|
237
|
+
|
238
|
+
output_answ[:code] = 200
|
239
|
+
output_answ[:result] = "Success"
|
240
|
+
output_answ[:body][:for_block][:notblocked_stat] = notblocked_stat
|
241
|
+
output_answ[:body][:for_block][:not_blocked_belgim] = alert_unprotected_out
|
242
|
+
output_answ[:body][:for_unblock][:for_unblock] = for_unblock
|
243
|
+
output_answ[:body][:for_unblock][:for_unblock_stat] = for_unblock_stat
|
244
|
+
|
245
|
+
rescue
|
246
|
+
output_answ = {:code => 507, :result => "staros_compare_http: Unknown SDK error"}
|
247
|
+
end
|
248
|
+
output_answ
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
def format_star_processed_answ(data)
|
255
|
+
answ_out = {:body => {:to_message => {:code => 200, :result => "Staros processed", :data => {:block_me => {}, :unblock_me=> {}}}, :config => {}}}
|
256
|
+
compa_n = 0
|
257
|
+
compa_n_data = ""
|
258
|
+
flag = 0
|
259
|
+
notbl_equal = 0
|
260
|
+
data[:body][:for_block][:notblocked_stat].each do |blo_for|
|
261
|
+
if flag == 0
|
262
|
+
compa_n = blo_for[1]
|
263
|
+
compa_n_data = blo_for[0]
|
264
|
+
end
|
265
|
+
if compa_n == blo_for[1]
|
266
|
+
nil
|
267
|
+
else
|
268
|
+
notbl_equal = 1
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
p notbl_equal
|
273
|
+
if notbl_equal == 0
|
274
|
+
block_me = {:for_block_count => data[:body][:for_block][:notblocked_stat][compa_n_data]}
|
275
|
+
unblock_me = {:for_unblock_count => data[:body][:for_unblock][:for_unblock_stat][compa_n_data]}
|
276
|
+
|
277
|
+
if block_me[:for_block_count] != 0 && unblock_me[:for_unblock_count] != 0
|
278
|
+
answ_out[:body][:to_message][:code] = 202
|
279
|
+
answ_out[:body][:to_message][:result] = "Something not actual"
|
280
|
+
else
|
281
|
+
answ_out[:body][:to_message][:code] = 200
|
282
|
+
answ_out[:body][:to_message][:result] = "Staros processed"
|
283
|
+
end
|
284
|
+
|
285
|
+
answ_out[:body][:to_message][:data][:block_me]= block_me
|
286
|
+
answ_out[:body][:to_message][:data][:unblock_me]= unblock_me
|
287
|
+
else
|
288
|
+
answ_out[:body][:to_message][:data][:block_me] = data[:body][:for_block][:notblocked_stat]
|
289
|
+
answ_out[:body][:to_message][:data][:unblock_me] = data[:body][:for_unblock][:for_unblock_stat]
|
290
|
+
end
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
answ_out
|
295
|
+
end
|
296
|
+
|
151
297
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imperituroard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
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-05-
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - '='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: 3.0.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rails
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 5.2.4.2
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 5.2.4.2
|
167
181
|
description: Gem from imperituroard for different actions
|
168
182
|
email:
|
169
183
|
- imperituro.ard@gmail.com
|
@@ -191,13 +205,9 @@ files:
|
|
191
205
|
- lib/imperituroard/platforms/cps/qps_connector.rb
|
192
206
|
- lib/imperituroard/platforms/cps/request_formatter.rb
|
193
207
|
- lib/imperituroard/platforms/public/telegram.rb
|
208
|
+
- lib/imperituroard/platforms/staros/get_data_ssh.rb
|
209
|
+
- lib/imperituroard/platforms/staros/staros_parser.rb
|
194
210
|
- lib/imperituroard/projects/dns.rb
|
195
|
-
- lib/imperituroard/projects/dns/ukaz60.rb
|
196
|
-
- lib/imperituroard/projects/dns/ukaz60/belgim.rb
|
197
|
-
- lib/imperituroard/projects/dns/ukaz60/dns.rb
|
198
|
-
- lib/imperituroard/projects/dns/ukaz60/dns_update.rb
|
199
|
-
- lib/imperituroard/projects/dns/ukaz60/fortigate.rb
|
200
|
-
- lib/imperituroard/projects/dns/ukaz60/ukaz60_add_func.rb
|
201
211
|
- lib/imperituroard/projects/iot.rb
|
202
212
|
- lib/imperituroard/projects/iot/add_functions.rb
|
203
213
|
- lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb
|
@@ -208,6 +218,13 @@ files:
|
|
208
218
|
- lib/imperituroard/projects/mhub/sk.rb
|
209
219
|
- lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb
|
210
220
|
- lib/imperituroard/projects/mhub/subs/dabrab/dabrab_proced.rb
|
221
|
+
- lib/imperituroard/projects/ukaz60.rb
|
222
|
+
- lib/imperituroard/projects/ukaz60/belgim.rb
|
223
|
+
- lib/imperituroard/projects/ukaz60/dns.rb
|
224
|
+
- lib/imperituroard/projects/ukaz60/dns_update.rb
|
225
|
+
- lib/imperituroard/projects/ukaz60/fortigate.rb
|
226
|
+
- lib/imperituroard/projects/ukaz60/staros.rb
|
227
|
+
- lib/imperituroard/projects/ukaz60/ukaz60_add_func.rb
|
211
228
|
- lib/imperituroard/projects/vpn/ezuev_fun/functions_ezuev.rb
|
212
229
|
- lib/imperituroard/projects/wttx/phpipamcps.rb
|
213
230
|
- lib/imperituroard/projects/wttx/phpipamdb.rb
|
@@ -229,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
229
246
|
requirements:
|
230
247
|
- - ">="
|
231
248
|
- !ruby/object:Gem::Version
|
232
|
-
version: 2.
|
249
|
+
version: 2.5.0
|
233
250
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
234
251
|
requirements:
|
235
252
|
- - ">="
|
@@ -1,87 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path("../projects/dns/ukaz60", __dir__)
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
require 'imperituroard/projects/dns/ukaz60/belgim'
|
6
|
-
require 'imperituroard/projects/dns/ukaz60/fortigate'
|
7
|
-
|
8
|
-
class Ukaz60All_2
|
9
|
-
|
10
|
-
attr_accessor :telegram_messanger,
|
11
|
-
:belgim_login,
|
12
|
-
:belgim_password,
|
13
|
-
:belgim_url,
|
14
|
-
:ukaz60_add_func,
|
15
|
-
:belgim_connector,
|
16
|
-
:forti_connector
|
17
|
-
|
18
|
-
def initialize(telegram_api_url,
|
19
|
-
telegram_chat_id,
|
20
|
-
belgim_login,
|
21
|
-
belgim_password,
|
22
|
-
belgim_url,
|
23
|
-
ansible_tmp_folder,
|
24
|
-
local_tmp_directory,
|
25
|
-
ansible_ssh_user,
|
26
|
-
ansible_ssh_password,
|
27
|
-
ansible_host,
|
28
|
-
url_backup_dir)
|
29
|
-
@telegram_messanger = Telegram_2.new(telegram_api_url, telegram_chat_id)
|
30
|
-
@belgim_login = belgim_login
|
31
|
-
@belgim_password = belgim_password
|
32
|
-
@belgim_url = belgim_url
|
33
|
-
@ukaz60_add_func = AddFuncUkaz60_2.new
|
34
|
-
@belgim_connector = Belgim_2.new(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url)
|
35
|
-
@forti_connector = FortiUkaz60_2.new(ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir)
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def no_pasaran
|
40
|
-
|
41
|
-
answer_output = {}
|
42
|
-
forti_answer = {}
|
43
|
-
|
44
|
-
begin
|
45
|
-
get_belgim_data = belgim_connector.belgim_ukaz60_get
|
46
|
-
|
47
|
-
if get_belgim_data[:code] == 200
|
48
|
-
|
49
|
-
thr_forti = Thread.new do
|
50
|
-
begin
|
51
|
-
format_for_forti = forti_connector.prepare_url_config_fortigate(get_belgim_data)
|
52
|
-
if format_for_forti[:code] == 200
|
53
|
-
url_uploading = forti_connector.upload_url(format_for_forti[:body][:to_fortigate])
|
54
|
-
if url_uploading[:code] == 200
|
55
|
-
update_fortigate_ansible = forti_connector.update_weburl_fortigate
|
56
|
-
if update_fortigate_ansible[:code] == 200
|
57
|
-
forti_answer = {:code => 200, :result => "Fortigate processed", :data => update_fortigate_ansible[:body][:body]}
|
58
|
-
else
|
59
|
-
forti_answer = {:code => update_fortigate_ansible[:code], :result => update_fortigate_ansible[:result]}
|
60
|
-
end
|
61
|
-
forti_connector.clean_tmp_folders
|
62
|
-
else
|
63
|
-
forti_answer = {:code => 401, :result => "Failed for uploading data to ansible server"}
|
64
|
-
end
|
65
|
-
else
|
66
|
-
forti_answer = {:code => 400, :result => "Error while processing data"}
|
67
|
-
end
|
68
|
-
rescue
|
69
|
-
forti_answer = {:code => 507, :result => "Unknown error with Forti"}
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
thr_forti.join
|
74
|
-
|
75
|
-
answer_output = {:code => 200, :result => "No pasaran", :fortigate => forti_answer}
|
76
|
-
else
|
77
|
-
answer_output = {:code => 404, :result => "Failed to receive data from Belgim"}
|
78
|
-
end
|
79
|
-
|
80
|
-
rescue
|
81
|
-
answer_output = {:code => 507, :result => "no_pasaran: Unknown SDK error"}
|
82
|
-
end
|
83
|
-
telegram_messanger.telegram_message(answer_output.to_s)
|
84
|
-
answer_output
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|