require 'imperituroard/add_functions/logger/any_functions' class AddFuncUkaz60_2 attr_accessor :add_functions def initialize @add_functions = LogAddFunctions_2.new end #function for process separate domains #for one domain def delete_dump_symbols_url(stroka) input_params = {:stroka => stroka} output_answer = {} processed_domain_in_url = "" protocol = "" type = "" domain_only = "" begin #p "Step1 stroka: #{stroka}" first_url = stroka.gsub(" 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} else output_answer = {:code => 202, :result => "Data not found"} end rescue output_answer = {:code => 507, :result => "Something wrong"} end output_answer end def ansible_answer_parse(answer_string) input_data = {:answer_string => answer_string} output_data = {} begin answ_ans_parsed = answer_string.gsub("\n", " ") result_out = {} #result_out = [] num_ok = 0 num_failed = 0 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+/ processed_data = answ_ans_parsed.scan(final_checks) if processed_data!=[] && processed_data!="" for aaa in processed_data begin 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 result_out[aaa[0]] = "Ok" #result_out.push({aaa[0] => "Ok"}) num_ok = num_ok + 1 else result_out[aaa[0]] = "Failed" #result_out.push({aaa[0] => "Failed"}) num_failed = num_failed + 1 end rescue result_out["unknown"] = aaa.to_s #result_out.push({"unknown" => aaa.to_s}) num_failed = num_failed + 1 end end output_data = {:code => 200, :result => "ansible_answer_parse: Request completed successfully", :body => {:list => result_out, :num_ok => num_ok, :num_failed => num_failed}} else output_data = {:code => 400, :result => "ansible_answer_parse: Ansible returned empty data"} end rescue output_data = {:code => 507, :result => "ansible_answer_parse: Unknown error"} end add_functions.printer_texter(output_data, "debug") output_data end def https_to_forti_prep(domain) f0 = domain.gsub("#", "") f1 = f0.gsub("https://", "").split("/") f1[0] end def http_to_forti_prep(domain) domain.gsub("#", "") end #result array2-array1 #array2 - all #array1 - blocked def array_hash_compare(array1, array2) diff = [] array2.each do |h1| if array1.include?(h1) nil else diff.push(h1) end end diff end #procedure for compare http urls from staros and http urls from belgim def staros_compare_http(data_staros, data_belgim) notblocked_stat = {} alert_unprotected = {} alert_unprotected_out = {} output_answ = {:body => {:for_block => {}, :for_unblock => {}}} for_unblock_tmp = {} for_unblock = {} for_unblock_stat = {} begin #only for one ECS instance data_staros[:mpc_data].each do |star_host| alert_unprotected[star_host[:hostname]] = [] for_unblock_tmp[star_host[:hostname]] = [] #check if belgim http url is blocked on STAROS data_belgim[:url_all].each do |belg_url| blocked = 0 star_host[:body][:blocked_urls_http].each do |star_dom| star_url_curr = star_dom[:url] star_dom_len = star_url_curr.length star_dom_x = "" if star_url_curr[star_dom_len - 1] == "/" star_dom_x = star_url_curr[0..star_dom_len - 2] else star_dom_x = star_url_curr end if belg_url.include?(star_dom_x) blocked = 1 for_unblock_tmp[star_host[:hostname]].push(star_dom) end end if blocked == 0 alert_unprotected[star_host[:hostname]].push(belg_url) end end end alert_unprotected.each do |proc_unpro| da123 = proc_unpro[1] alert_unprotected_out[proc_unpro[0]] = da123.uniq notblocked_stat[proc_unpro[0]] = proc_unpro[1].length end for_unblock_tmp.each do |tmp_unbl| hostname_st = tmp_unbl[0] host_data_tmp = tmp_unbl[1].uniq staros_all = data_staros[:add_format][hostname_st][:blocked_urls_http].uniq da_annn = self.array_hash_compare(host_data_tmp, staros_all) for_unblock[hostname_st] = da_annn.uniq for_unblock_stat[hostname_st] = da_annn.uniq.length end output_answ[:code] = 200 output_answ[:result] = "Success" output_answ[:body][:for_block][:notblocked_stat] = notblocked_stat output_answ[:body][:for_block][:not_blocked_belgim] = alert_unprotected_out output_answ[:body][:for_unblock][:for_unblock] = for_unblock output_answ[:body][:for_unblock][:for_unblock_stat] = for_unblock_stat rescue output_answ = {:code => 507, :result => "staros_compare_http: Unknown SDK error"} end output_answ end def format_star_processed_answ(data) answ_out = {:body => {:to_message => {:code => 200, :result => "Staros processed", :data => {:block_me => {}, :unblock_me=> {}}}, :config => {}}} compa_n = 0 compa_n_data = "" flag = 0 notbl_equal = 0 data[:body][:for_block][:notblocked_stat].each do |blo_for| if flag == 0 compa_n = blo_for[1] compa_n_data = blo_for[0] end if compa_n == blo_for[1] nil else notbl_equal = 1 end end p notbl_equal if notbl_equal == 0 block_me = {:for_block_count => data[:body][:for_block][:notblocked_stat][compa_n_data]} unblock_me = {:for_unblock_count => data[:body][:for_unblock][:for_unblock_stat][compa_n_data]} if block_me[:for_block_count] != 0 && unblock_me[:for_unblock_count] != 0 answ_out[:body][:to_message][:code] = 202 answ_out[:body][:to_message][:result] = "Something not actual" else answ_out[:body][:to_message][:code] = 200 answ_out[:body][:to_message][:result] = "Staros processed" end answ_out[:body][:to_message][:data][:block_me]= block_me answ_out[:body][:to_message][:data][:unblock_me]= unblock_me else answ_out[:body][:to_message][:data][:block_me] = data[:body][:for_block][:notblocked_stat] answ_out[:body][:to_message][:data][:unblock_me] = data[:body][:for_unblock][:for_unblock_stat] end answ_out end end