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
@@ -0,0 +1,306 @@
1
+ require 'imperituroard/add_functions/logger/any_functions'
2
+ require 'uri'
3
+
4
+ class AddFuncUkaz60_2
5
+
6
+ attr_accessor :add_functions
7
+
8
+ def initialize
9
+ @add_functions = LogAddFunctions_2.new
10
+ end
11
+
12
+ #function for process separate domains
13
+ #for one domain
14
+ def delete_dump_symbols_url(stroka)
15
+ input_params = {:stroka => stroka}
16
+ output_answer = {}
17
+ processed_domain_in_url = ""
18
+ protocol = ""
19
+ type = ""
20
+ domain_only = ""
21
+ begin
22
+
23
+ #p "Step1 stroka: #{stroka}"
24
+
25
+ first_url = stroka.gsub("</", "")
26
+
27
+ if first_url != "-" && first_url != ""
28
+
29
+ #check web protocol (http/https/unknown)
30
+ if stroka.include? "http:"
31
+ protocol = "http"
32
+ elsif stroka.include? "https:"
33
+ protocol = "https"
34
+ else
35
+ protocol = "unknown"
36
+ p "ERROR: delete_dump_symbols_url.unknown protocol"
37
+ end
38
+
39
+ if first_url.include? "http://"
40
+ processed_domain_in_url = first_url.gsub("http://", "")
41
+ else
42
+ processed_domain_in_url = processed_domain_in_url + first_url
43
+ end
44
+
45
+ if processed_domain_in_url.include? "http:///"
46
+ processed_domain_in_url.gsub!("http:///", "")
47
+ end
48
+
49
+ if processed_domain_in_url.include? "http:/"
50
+ processed_domain_in_url.gsub!("http:/", "")
51
+ end
52
+
53
+ if processed_domain_in_url.include? "https://"
54
+ processed_domain_in_url.gsub!("https://", "")
55
+ end
56
+
57
+ if processed_domain_in_url.include? "https:/"
58
+ processed_domain_in_url.gsub!("https:/", "")
59
+ end
60
+
61
+ if processed_domain_in_url.include? " "
62
+ processed_domain_in_url = processed_domain_in_url.gsub!(" ", "")
63
+ end
64
+
65
+ #delete / at the end
66
+ if processed_domain_in_url[processed_domain_in_url.size-1]=="/"
67
+ sss = processed_domain_in_url.size
68
+ processed_domain_in_url = processed_domain_in_url[0..sss-2]
69
+ end
70
+
71
+ #p "Step2 processed_domain_in_url: #{processed_domain_in_url}"
72
+
73
+ if processed_domain_in_url != "-" && processed_domain_in_url != "" && processed_domain_in_url != nil
74
+ #p "Step3 processed_domain_in_url: #{processed_domain_in_url}"
75
+ #if include / then it is url. Else - domain
76
+ if !processed_domain_in_url.include? "/"
77
+ #it is domain. Process domain
78
+ #if it is kirillica then process
79
+ if processed_domain_in_url.match(/а|б|в|г|д|е|ж|ё|Ё|з|и|й|к|л|м|н|о|п|р|с|т|у|ф|х|ц|ч|ш|щ|ь|ы|ъ|э|ю|я|А|Б|В|Г|Д|Е|Ж|З|И|Й|К|Л|М|Н|О|П|Р|С|Т|У|Ф|Х|Ц|Ч|Ш|Щ|Ь|Ы|Ъ|Э|Ю|Я/)
80
+ processed_domain_in_url = SimpleIDN.to_ascii(processed_domain_in_url)
81
+ end
82
+ domain_only = domain_only + processed_domain_in_url
83
+ type = "domain"
84
+ else
85
+ #it is url. process url
86
+ hh = processed_domain_in_url.split("/")
87
+ domain_only = hh[0]
88
+ if domain_only.match(/а|б|в|г|д|е|ж|ё|Ё|з|и|й|к|л|м|н|о|п|р|с|т|у|ф|х|ц|ч|ш|щ|ь|ы|ъ|э|ю|я|А|Б|В|Г|Д|Е|Ж|З|И|Й|К|Л|М|Н|О|П|Р|С|Т|У|Ф|Х|Ц|Ч|Ш|Щ|Ь|Ы|Ъ|Э|Ю|Я/)
89
+ hh[0] = SimpleIDN.to_ascii(domain_only)
90
+ processed_domain_in_url = ""
91
+ for t in hh
92
+ processed_domain_in_url = processed_domain_in_url + t + "/"
93
+ end
94
+ sss1len = processed_domain_in_url.size
95
+ processed_domain_in_url = processed_domain_in_url[0..sss1len-2]
96
+ end
97
+ type = "url"
98
+ end
99
+ else
100
+ type = "empty"
101
+ end
102
+ output_answer = {:code => 200, :result => "Request processed", :ishodnye_dannye => stroka, :first_url => first_url, :processed_domain_in_url => processed_domain_in_url, :domain_only => domain_only, :protocol => protocol, :type => type}
103
+
104
+ else
105
+ output_answer = {:code => 202, :result => "Data not found"}
106
+ end
107
+ rescue
108
+ output_answer = {:code => 507, :result => "Something wrong"}
109
+ end
110
+ output_answer
111
+ end
112
+
113
+
114
+ def ansible_answer_parse(answer_string)
115
+ input_data = {:answer_string => answer_string}
116
+ output_data = {}
117
+
118
+ begin
119
+ answ_ans_parsed = answer_string.gsub("\n", " ")
120
+ result_out = {}
121
+ #result_out = []
122
+ num_ok = 0
123
+ num_failed = 0
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+/
125
+
126
+ processed_data = answ_ans_parsed.scan(final_checks)
127
+ if processed_data!=[] && processed_data!=""
128
+ for aaa in processed_data
129
+ begin
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
131
+ result_out[aaa[0]] = "Ok"
132
+ #result_out.push({aaa[0] => "Ok"})
133
+ num_ok = num_ok + 1
134
+ else
135
+ result_out[aaa[0]] = "Failed"
136
+ #result_out.push({aaa[0] => "Failed"})
137
+ num_failed = num_failed + 1
138
+ end
139
+ rescue
140
+ result_out["unknown"] = aaa.to_s
141
+ #result_out.push({"unknown" => aaa.to_s})
142
+ num_failed = num_failed + 1
143
+ end
144
+ end
145
+ output_data = {:code => 200, :result => "ansible_answer_parse: Request completed successfully", :body => {:list => result_out, :num_ok => num_ok, :num_failed => num_failed}}
146
+ else
147
+ output_data = {:code => 400, :result => "ansible_answer_parse: Ansible returned empty data"}
148
+ end
149
+ rescue
150
+ output_data = {:code => 507, :result => "ansible_answer_parse: Unknown error"}
151
+ end
152
+ add_functions.printer_texter(output_data, "debug")
153
+ output_data
154
+ end
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
+
306
+ end
@@ -0,0 +1,29 @@
1
+
2
+ require 'net/ssh'
3
+
4
+ class EzuevFun_2
5
+
6
+
7
+ def vpn_create_client
8
+ command = "/usr/bin/python3.6 /projects/vpn_test/methods/create_client.py '{\"unp\": \"\", \"company_name\": \"MinskTrans\", \"full_name\":\"MinskTransTest\", \"info\": \"NewYork\", \"profile\": \"IoT\", \"net_type\": \"static\", \"number_sims\": 1024, \"msisdns\": [37529, 37528]}'"
9
+ Net::SSH.start("172.24.157.24", "soapgw", :password => "3g8Yh2Sl7Vz9Nbd358") do |ssh|
10
+ result = ssh.exec!(command)
11
+ p result
12
+ end
13
+ end
14
+
15
+ def vpn_update_client
16
+ command = "/usr/bin/python3.6 /projects/vpn_test/methods/update_client.py '{\"unp\": \"\", \"old_company_name\": \"MinskTrans\", \"new_company_name\": \"MinskTrans1\", \"new_full_name\": \"MinskTransTest1\", \"new_address\": \"NewYork\", \"new_contact_name\": \"1\", \"new_contact_number\": \"1\"}'"
17
+ Net::SSH.start("172.24.157.24", "soapgw", :password => "3g8Yh2Sl7Vz9Nbd358") do |ssh|
18
+ result = ssh.exec!(command)
19
+ p result
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+
26
+ ff = EzuevFun_2.new
27
+ ff.vpn_update_client
28
+
29
+
@@ -1,3 +1,3 @@
1
1
  module Imperituroard
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.9"
3
3
  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.3
4
+ version: 0.5.9
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-19 00:00:00.000000000 Z
11
+ date: 2020-06-03 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
@@ -187,11 +201,16 @@ files:
187
201
  - lib/.DS_Store
188
202
  - lib/imperituroard.rb
189
203
  - lib/imperituroard/.DS_Store
204
+ - lib/imperituroard/add_functions/logger/any_functions.rb
205
+ - lib/imperituroard/platforms/cps/cps_multiple_thread_req.rb
190
206
  - lib/imperituroard/platforms/cps/qps_connector.rb
191
207
  - lib/imperituroard/platforms/cps/request_formatter.rb
192
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
193
213
  - lib/imperituroard/projects/dns.rb
194
- - lib/imperituroard/projects/dns/ukaz60/dns_update.rb
195
214
  - lib/imperituroard/projects/iot.rb
196
215
  - lib/imperituroard/projects/iot/add_functions.rb
197
216
  - lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb
@@ -202,6 +221,14 @@ files:
202
221
  - lib/imperituroard/projects/mhub/sk.rb
203
222
  - lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb
204
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
231
+ - lib/imperituroard/projects/vpn/ezuev_fun/functions_ezuev.rb
205
232
  - lib/imperituroard/projects/wttx/phpipamcps.rb
206
233
  - lib/imperituroard/projects/wttx/phpipamdb.rb
207
234
  - lib/imperituroard/projects/wttx/updatepostcps.rb