imperituroard 0.5.5 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/imperituroard.gemspec +3 -0
- data/lib/.DS_Store +0 -0
- data/lib/imperituroard.rb +97 -71
- data/lib/imperituroard/.DS_Store +0 -0
- data/lib/imperituroard/platforms/cps/cps_multiple_thread_req.rb +0 -0
- data/lib/imperituroard/platforms/staros/get_data_ssh.rb +54 -0
- data/lib/imperituroard/platforms/staros/staros_automation.rb +95 -0
- data/lib/imperituroard/platforms/staros/staros_automation_fun.rb +37 -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 +191 -30
- data/lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb +22 -8
- data/lib/imperituroard/projects/iot/mongoconnector.rb +177 -2
- data/lib/imperituroard/projects/mhub.rb +2 -0
- data/lib/imperituroard/projects/mhub/infobip.rb +1 -1
- data/lib/imperituroard/projects/mhub/sk.rb +171 -157
- data/lib/imperituroard/projects/mhub/subs/dabrab/dabrab_proced.rb +124 -12
- data/lib/imperituroard/projects/ukaz60.rb +140 -0
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/belgim.rb +48 -9
- 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 +43 -4
- data/lib/imperituroard/projects/ukaz60/staros.rb +141 -0
- data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/ukaz60_add_func.rb +159 -4
- data/lib/imperituroard/version.rb +1 -1
- metadata +28 -8
- data/lib/imperituroard/projects/dns/ukaz60.rb +0 -87
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'uri'
|
3
|
+
require "erb"
|
4
|
+
include ERB::Util
|
5
|
+
|
6
|
+
require 'imperituroard/platforms/staros/get_data_ssh'
|
7
|
+
|
8
|
+
|
9
|
+
class Ukaz60Staros_2
|
10
|
+
|
11
|
+
attr_accessor :staros_platform_get,
|
12
|
+
:ukaz60_http_groups,
|
13
|
+
:ukaz60_https_groups,
|
14
|
+
:staros_hosts
|
15
|
+
|
16
|
+
def initialize(star_login, star_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts)
|
17
|
+
@staros_platform_get = StarosGet_2.new(star_login, star_password)
|
18
|
+
@ukaz60_http_groups = ukaz60_http_groups
|
19
|
+
@ukaz60_https_groups = ukaz60_https_groups
|
20
|
+
@staros_hosts = staros_hosts
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
#get data from staros and return urls from staros
|
25
|
+
def get_data_staros(ip_staros)
|
26
|
+
|
27
|
+
input_data = {:ip_staros => ip_staros}
|
28
|
+
output_data = {}
|
29
|
+
ecs_name = ""
|
30
|
+
blocked_urls_http = []
|
31
|
+
blocked_urls_https = []
|
32
|
+
|
33
|
+
begin
|
34
|
+
ecs_config_json = staros_platform_get.get_all_active_charging(ip_staros)
|
35
|
+
|
36
|
+
if ecs_config_json[:code] == 200
|
37
|
+
|
38
|
+
#get ecs name
|
39
|
+
ecs_sss = ecs_config_json[:parsed_data]["config"]["active-charging service"][0]
|
40
|
+
ecs_sss.each do |hhh|
|
41
|
+
ecs_name = hhh[0]
|
42
|
+
end
|
43
|
+
|
44
|
+
regexp_ruldef = /add-ruledef priority \d+ ruledef (.+)/
|
45
|
+
|
46
|
+
#for http urls
|
47
|
+
begin
|
48
|
+
ukaz60_http_groups.each do |rule|
|
49
|
+
group_ruled_ukaz60 = ecs_config_json[:parsed_data]["config"]["active-charging service"][0][ecs_name]["group-of-ruledefs"][rule]
|
50
|
+
|
51
|
+
group_ruled_ukaz60.each do |gr_rul_str|
|
52
|
+
ruledef_name = gr_rul_str.match(regexp_ruldef)[1]
|
53
|
+
rdef_config = ecs_config_json[:parsed_data]["config"]["active-charging service"][0][ecs_name]["ruledef"][ruledef_name]
|
54
|
+
rdef_config.each do |g|
|
55
|
+
if g[0..15] == "www url contains"
|
56
|
+
blocked_urls_http.push({:url => g.gsub("www url contains ", ""), :ruledef => ruledef_name, :gr_of_ruledefs => rule, :gr_rul_str => gr_rul_str})
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
rescue
|
62
|
+
blocked_urls_http.push("failed")
|
63
|
+
end
|
64
|
+
|
65
|
+
for https_rule in ukaz60_https_groups
|
66
|
+
group_rule_https = ecs_config_json[:parsed_data]["config"]["active-charging service"][0][ecs_name]["group-of-ruledefs"][https_rule]
|
67
|
+
end
|
68
|
+
|
69
|
+
output_data = {:code => 200, :result => "Success", :ecs_name => ecs_name, :blocked_urls_http => blocked_urls_http, :http_rules_num => blocked_urls_http.length}
|
70
|
+
|
71
|
+
else
|
72
|
+
output_data = ecs_config_json
|
73
|
+
end
|
74
|
+
rescue
|
75
|
+
output_data = {:code => 507, :result => "get_data_staros: Unknown SDK error"}
|
76
|
+
end
|
77
|
+
output_data
|
78
|
+
# Net::SSH.start("172.24.214.17", "starscript", :password => "$rfv3EDC") do |ssh|
|
79
|
+
# staros_answer = ssh.exec!("show configuration active-charging service all")
|
80
|
+
# p staros_answer
|
81
|
+
#
|
82
|
+
# staros_answer = staros_answer.gsub("\n", "")
|
83
|
+
#
|
84
|
+
# regexp_ukaz60_9 = /group-of-ruledefs Ukaz60-9_HTTP.+HTTP\s+#exit/
|
85
|
+
# regexp_ukaz60_https = /group-of-ruledefs Ukaz60_HTTPS.+HTTPS\s+#exit/
|
86
|
+
# regexp_ukaz60_7 = /group-of-ruledefs Ukaz60-7_HTTP.+HTTP\s+#exit/
|
87
|
+
#
|
88
|
+
#
|
89
|
+
#
|
90
|
+
# group_ruled_ukaz60_9 = staros_answer.match(regexp_ukaz60_9)[0]
|
91
|
+
# group_ruled_ukaz60_https = staros_answer.match(regexp_ukaz60_https)[0]
|
92
|
+
# group_ruled_ukaz60_7 = staros_answer.match(regexp_ukaz60_7)[0]
|
93
|
+
#
|
94
|
+
# p group_ruled_ukaz60_9
|
95
|
+
# p group_ruled_ukaz60_https
|
96
|
+
# p group_ruled_ukaz60_7
|
97
|
+
#
|
98
|
+
# end
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
#procedure for get data from all MPC
|
103
|
+
def get_all_staros_ukaz60
|
104
|
+
|
105
|
+
returned_data = {:mpc_data => [], :add_format => {}}
|
106
|
+
get_all_staros_ukaz60_1 = []
|
107
|
+
|
108
|
+
begin
|
109
|
+
staros_hosts.each do |ggsn|
|
110
|
+
get_all_staros_ukaz60_1 << Thread.new do
|
111
|
+
begin
|
112
|
+
mpc_data = self.get_data_staros(ggsn[1])
|
113
|
+
returned_data[:mpc_data].push({:code => 200, :result => "Success", :hostname => ggsn[0], :host_ip => ggsn[1], :body => mpc_data})
|
114
|
+
returned_data[:add_format][ggsn[0]] = mpc_data
|
115
|
+
rescue
|
116
|
+
returned_data[:mpc_data].push({:code => 507, :result => "Unknown thread error", :hostname => ggsn[0], :host_ip => ggsn[1], :body => {}})
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
get_all_staros_ukaz60_1.each(&:join)
|
121
|
+
returned_data[:code] = 200
|
122
|
+
returned_data[:result] = "get_all_staros_ukaz60: Success"
|
123
|
+
rescue
|
124
|
+
returned_data[:code] = 507
|
125
|
+
returned_data[:result] = "get_all_staros_ukaz60: Unknown SDK error"
|
126
|
+
end
|
127
|
+
returned_data
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
uu ="/fgd?ef"
|
133
|
+
|
134
|
+
#ggg = uu.force_encoding('ASCII-8BIT')
|
135
|
+
#puts CGI.escape ggg
|
136
|
+
p url_encode("foo/bar? baz&")
|
137
|
+
|
138
|
+
p URI.parse("foo/bar? baz&").to_s
|
139
|
+
p URI::encode("foo/bar? baz&")
|
140
|
+
|
141
|
+
p URI.decode("newsx-ru.ru/by/251-potencia-spartagen-by/%3futm%20medium=251&utmcampaign=4&%20utm%20content=57849345&utm%20source=56960717")
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'imperituroard/add_functions/logger/any_functions'
|
2
|
+
require 'uri'
|
2
3
|
|
3
4
|
class AddFuncUkaz60_2
|
4
5
|
|
@@ -116,7 +117,8 @@ class AddFuncUkaz60_2
|
|
116
117
|
|
117
118
|
begin
|
118
119
|
answ_ans_parsed = answer_string.gsub("\n", " ")
|
119
|
-
result_out =
|
120
|
+
result_out = {}
|
121
|
+
#result_out = []
|
120
122
|
num_ok = 0
|
121
123
|
num_failed = 0
|
122
124
|
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 +128,17 @@ class AddFuncUkaz60_2
|
|
126
128
|
for aaa in processed_data
|
127
129
|
begin
|
128
130
|
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
|
131
|
+
result_out[aaa[0]] = "Ok"
|
132
|
+
#result_out.push({aaa[0] => "Ok"})
|
130
133
|
num_ok = num_ok + 1
|
131
134
|
else
|
132
|
-
result_out
|
135
|
+
result_out[aaa[0]] = "Failed"
|
136
|
+
#result_out.push({aaa[0] => "Failed"})
|
133
137
|
num_failed = num_failed + 1
|
134
138
|
end
|
135
139
|
rescue
|
136
|
-
result_out
|
140
|
+
result_out["unknown"] = aaa.to_s
|
141
|
+
#result_out.push({"unknown" => aaa.to_s})
|
137
142
|
num_failed = num_failed + 1
|
138
143
|
end
|
139
144
|
end
|
@@ -148,4 +153,154 @@ class AddFuncUkaz60_2
|
|
148
153
|
output_data
|
149
154
|
end
|
150
155
|
|
156
|
+
|
157
|
+
def https_to_forti_prep(domain)
|
158
|
+
f0 = domain.gsub("#", "")
|
159
|
+
f1 = f0.gsub("https://", "").split("/")
|
160
|
+
f1[0]
|
161
|
+
end
|
162
|
+
|
163
|
+
def http_to_forti_prep(domain)
|
164
|
+
domain.gsub("#", "")
|
165
|
+
end
|
166
|
+
|
167
|
+
#result array2-array1
|
168
|
+
#array2 - all
|
169
|
+
#array1 - blocked
|
170
|
+
def array_hash_compare(array1, array2)
|
171
|
+
diff = []
|
172
|
+
array2.each do |h1|
|
173
|
+
if array1.include?(h1)
|
174
|
+
nil
|
175
|
+
else
|
176
|
+
diff.push(h1)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
diff
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
#procedure for compare http urls from staros and http urls from belgim
|
184
|
+
def staros_compare_http(data_staros, data_belgim)
|
185
|
+
|
186
|
+
notblocked_stat = {}
|
187
|
+
alert_unprotected = {}
|
188
|
+
alert_unprotected_out = {}
|
189
|
+
output_answ = {:body => {:for_block => {}, :for_unblock => {}}}
|
190
|
+
for_unblock_tmp = {}
|
191
|
+
for_unblock = {}
|
192
|
+
for_unblock_stat = {}
|
193
|
+
|
194
|
+
|
195
|
+
begin
|
196
|
+
#only for one ECS instance
|
197
|
+
data_staros[:mpc_data].each do |star_host|
|
198
|
+
alert_unprotected[star_host[:hostname]] = []
|
199
|
+
for_unblock_tmp[star_host[:hostname]] = []
|
200
|
+
|
201
|
+
#check if belgim http url is blocked on STAROS
|
202
|
+
data_belgim[:url_all].each do |belg_url|
|
203
|
+
blocked = 0
|
204
|
+
star_host[:body][:blocked_urls_http].each do |star_dom|
|
205
|
+
star_url_curr = star_dom[:url]
|
206
|
+
star_dom_len = star_url_curr.length
|
207
|
+
star_dom_x = ""
|
208
|
+
if star_url_curr[star_dom_len - 1] == "/"
|
209
|
+
star_dom_x = star_url_curr[0..star_dom_len - 2]
|
210
|
+
else
|
211
|
+
star_dom_x = star_url_curr
|
212
|
+
end
|
213
|
+
if belg_url.include?(star_dom_x) || belg_url.include?(URI.decode(star_dom_x))
|
214
|
+
blocked = 1
|
215
|
+
for_unblock_tmp[star_host[:hostname]].push(star_dom)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
if blocked == 0
|
219
|
+
alert_unprotected[star_host[:hostname]].push(belg_url)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
alert_unprotected.each do |proc_unpro|
|
225
|
+
da123 = proc_unpro[1]
|
226
|
+
alert_unprotected_out[proc_unpro[0]] = da123.uniq
|
227
|
+
notblocked_stat[proc_unpro[0]] = proc_unpro[1].length
|
228
|
+
end
|
229
|
+
|
230
|
+
for_unblock_tmp.each do |tmp_unbl|
|
231
|
+
hostname_st = tmp_unbl[0]
|
232
|
+
host_data_tmp = tmp_unbl[1].uniq
|
233
|
+
staros_all = data_staros[:add_format][hostname_st][:blocked_urls_http].uniq
|
234
|
+
da_annn = self.array_hash_compare(host_data_tmp, staros_all)
|
235
|
+
for_unblock[hostname_st] = da_annn.uniq
|
236
|
+
for_unblock_stat[hostname_st] = da_annn.uniq.length
|
237
|
+
end
|
238
|
+
|
239
|
+
output_answ[:code] = 200
|
240
|
+
output_answ[:result] = "Success"
|
241
|
+
output_answ[:body][:for_block][:notblocked_stat] = notblocked_stat
|
242
|
+
output_answ[:body][:for_block][:not_blocked_belgim] = alert_unprotected_out
|
243
|
+
output_answ[:body][:for_unblock][:for_unblock] = for_unblock
|
244
|
+
output_answ[:body][:for_unblock][:for_unblock_stat] = for_unblock_stat
|
245
|
+
|
246
|
+
rescue
|
247
|
+
output_answ = {:code => 507, :result => "staros_compare_http: Unknown SDK error"}
|
248
|
+
end
|
249
|
+
|
250
|
+
#p JSON.pretty_generate(output_answ)
|
251
|
+
p "staros_compare_http"
|
252
|
+
p output_answ
|
253
|
+
|
254
|
+
p "temp data"
|
255
|
+
for i in output_answ[:body][:for_unblock][:for_unblock]["vit11asr2"]
|
256
|
+
#for i in output_answ[:body][:for_block][:not_blocked_belgim]["vit11asr2"]
|
257
|
+
p i
|
258
|
+
end
|
259
|
+
output_answ
|
260
|
+
end
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
def format_star_processed_answ(data)
|
266
|
+
answ_out = {:body => {:to_message => {:code => 200, :result => "Staros processed", :data => {:block_me => {}, :unblock_me=> {}}}, :config => {}}}
|
267
|
+
compa_n = 0
|
268
|
+
compa_n_data = ""
|
269
|
+
flag = 0
|
270
|
+
notbl_equal = 0
|
271
|
+
data[:body][:for_block][:notblocked_stat].each do |blo_for|
|
272
|
+
if flag == 0
|
273
|
+
compa_n = blo_for[1]
|
274
|
+
compa_n_data = blo_for[0]
|
275
|
+
end
|
276
|
+
if compa_n == blo_for[1]
|
277
|
+
nil
|
278
|
+
else
|
279
|
+
notbl_equal = 1
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
p notbl_equal
|
284
|
+
if notbl_equal == 0
|
285
|
+
block_me = {:for_block_count => data[:body][:for_block][:notblocked_stat][compa_n_data]}
|
286
|
+
unblock_me = {:for_unblock_count => data[:body][:for_unblock][:for_unblock_stat][compa_n_data]}
|
287
|
+
|
288
|
+
if block_me[:for_block_count] != 0 && unblock_me[:for_unblock_count] != 0
|
289
|
+
answ_out[:body][:to_message][:code] = 202
|
290
|
+
answ_out[:body][:to_message][:result] = "Something not actual"
|
291
|
+
else
|
292
|
+
answ_out[:body][:to_message][:code] = 200
|
293
|
+
answ_out[:body][:to_message][:result] = "Staros processed"
|
294
|
+
end
|
295
|
+
|
296
|
+
answ_out[:body][:to_message][:data][:block_me]= block_me
|
297
|
+
answ_out[:body][:to_message][:data][:unblock_me]= unblock_me
|
298
|
+
else
|
299
|
+
answ_out[:body][:to_message][:data][:block_me] = data[:body][:for_block][:notblocked_stat]
|
300
|
+
answ_out[:body][:to_message][:data][:unblock_me] = data[:body][:for_unblock][:for_unblock_stat]
|
301
|
+
end
|
302
|
+
|
303
|
+
answ_out
|
304
|
+
end
|
305
|
+
|
151
306
|
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.
|
4
|
+
version: 1.0.1
|
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-
|
11
|
+
date: 2020-06-07 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.0.7.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.0.7.2
|
167
181
|
description: Gem from imperituroard for different actions
|
168
182
|
email:
|
169
183
|
- imperituro.ard@gmail.com
|
@@ -188,16 +202,15 @@ files:
|
|
188
202
|
- lib/imperituroard.rb
|
189
203
|
- lib/imperituroard/.DS_Store
|
190
204
|
- lib/imperituroard/add_functions/logger/any_functions.rb
|
205
|
+
- lib/imperituroard/platforms/cps/cps_multiple_thread_req.rb
|
191
206
|
- lib/imperituroard/platforms/cps/qps_connector.rb
|
192
207
|
- lib/imperituroard/platforms/cps/request_formatter.rb
|
193
208
|
- lib/imperituroard/platforms/public/telegram.rb
|
209
|
+
- lib/imperituroard/platforms/staros/get_data_ssh.rb
|
210
|
+
- lib/imperituroard/platforms/staros/staros_automation.rb
|
211
|
+
- lib/imperituroard/platforms/staros/staros_automation_fun.rb
|
212
|
+
- lib/imperituroard/platforms/staros/staros_parser.rb
|
194
213
|
- 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
214
|
- lib/imperituroard/projects/iot.rb
|
202
215
|
- lib/imperituroard/projects/iot/add_functions.rb
|
203
216
|
- lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb
|
@@ -208,6 +221,13 @@ files:
|
|
208
221
|
- lib/imperituroard/projects/mhub/sk.rb
|
209
222
|
- lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb
|
210
223
|
- lib/imperituroard/projects/mhub/subs/dabrab/dabrab_proced.rb
|
224
|
+
- lib/imperituroard/projects/ukaz60.rb
|
225
|
+
- lib/imperituroard/projects/ukaz60/belgim.rb
|
226
|
+
- lib/imperituroard/projects/ukaz60/dns.rb
|
227
|
+
- lib/imperituroard/projects/ukaz60/dns_update.rb
|
228
|
+
- lib/imperituroard/projects/ukaz60/fortigate.rb
|
229
|
+
- lib/imperituroard/projects/ukaz60/staros.rb
|
230
|
+
- lib/imperituroard/projects/ukaz60/ukaz60_add_func.rb
|
211
231
|
- lib/imperituroard/projects/vpn/ezuev_fun/functions_ezuev.rb
|
212
232
|
- lib/imperituroard/projects/wttx/phpipamcps.rb
|
213
233
|
- lib/imperituroard/projects/wttx/phpipamdb.rb
|
@@ -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
|