$LOAD_PATH.unshift File.expand_path("../projects/ukaz60", __dir__) require 'json' require 'imperituroard/projects/ukaz60/belgim' require 'imperituroard/projects/ukaz60/fortigate' require 'imperituroard/projects/ukaz60/staros' class Ukaz60All_2 attr_accessor :telegram_messanger, :belgim_login, :belgim_password, :belgim_url, :ukaz60_add_func, :belgim_connector, :forti_connector, :staros_connector def initialize(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url, ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir, staros_login, staros_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts ) @telegram_messanger = Telegram_2.new(telegram_api_url, telegram_chat_id) @belgim_login = belgim_login @belgim_password = belgim_password @belgim_url = belgim_url @ukaz60_add_func = AddFuncUkaz60_2.new @belgim_connector = Belgim_2.new(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url) @forti_connector = FortiUkaz60_2.new(ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir) @staros_connector = Ukaz60Staros_2.new(staros_login, staros_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts) end def forti_process(get_belgim_data) forti_answer = {} begin format_for_forti = forti_connector.prepare_url_config_fortigate(get_belgim_data) if format_for_forti[:code] == 200 url_uploading = forti_connector.upload_url(format_for_forti[:body][:to_fortigate]) if url_uploading[:code] == 200 #update_fortigate_ansible = forti_connector.update_weburl_fortigate update_fortigate_ansible = forti_connector.update_weburl_fortimanager if update_fortigate_ansible[:code] == 200 forti_answer = {:code => 200, :result => "Fortigate processed", :data => update_fortigate_ansible[:body][:body], :num_uploaded_to_forti => format_for_forti[:body][:num_list]} else forti_answer = {:code => update_fortigate_ansible[:code], :result => update_fortigate_ansible[:result]} end forti_connector.clean_tmp_folders else forti_answer = {:code => 401, :result => "Failed for uploading data to ansible server"} end else forti_answer = {:code => 400, :result => "Error while processing data"} end rescue forti_answer = {:code => 507, :result => "Unknown error with Forti"} end forti_answer end def staros_process(get_belgim_data) output_starprocess = {} begin #get data from staros staros_blocks_current = staros_connector.get_all_staros_ukaz60 if staros_blocks_current[:code] == 200 #compare data with belgim answ = ukaz60_add_func.staros_compare_http(staros_blocks_current, get_belgim_data) p answ if answ[:code] == 200 #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]}} output_starprocess = ukaz60_add_func.format_star_processed_answ(answ)[:body][:to_message] else output_starprocess = answ end else output_starprocess = staros_blocks_current end rescue output_starprocess = {:code => 507, :result => "staros_process: Something wrong"} end output_starprocess end def no_pasaran answer_output = {} forti_answer = {} staros_answer = {} begin get_belgim_data = belgim_connector.belgim_ukaz60_get #p get_belgim_data if get_belgim_data[:code] == 200 thr_forti = Thread.new do forti_answer = self.forti_process(get_belgim_data) end thr_staros = Thread.new do staros_answer = staros_process(get_belgim_data) end thr_staros.join thr_forti.join answer_output = {:code => 200, :result => "No pasaran", :fortigate => forti_answer, :staros => staros_answer, :info_belgim => get_belgim_data[:number]} else answer_output = {:code => 404, :result => "Failed to receive data from Belgim"} end rescue answer_output = {:code => 507, :result => "no_pasaran: Unknown SDK error"} end telegram_messanger.telegram_message(JSON.pretty_generate(answer_output)) answer_output end end