require 'imperituroard/platforms/public/telegram' require 'imperituroard/projects/ukaz60/ukaz60_add_func' require 'simpleidn' class Belgim_2 attr_accessor :telegram_messanger, :belgim_login, :belgim_password, :belgim_url, :ukaz60_add_func def initialize(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url ) @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 end #get domains from belgim and parse data #return all domains urls ips. Selection specific data for dns or firewall do by additional functions #full ready for dns and firewall def belgim_ukaz60_get output_data = {} begin #data peremennye regexp_redns = /(.{1,100})dns>/ regexp_reurl = /(.{1,100})url>/ regexp_reip = /(.{1,100})ip>/ #processed data in correct format domain_parsed = [] url_parsed = [] ipv4_parsed = [] ipv6_parsed = [] https_parsed = [] url_all = [] f2 =[] results = {} # Get data from Belgim site by curl return_from_belgim = `curl -d "name=#{belgim_login}&pass=#{belgim_password}" -H "Content-Type: application/x-www-form-urlencoded" -X POST #{belgim_url}` return_from_belgim = return_from_belgim.gsub!("\n", "") #parse Belgim file by regexpression # and split by 3 categories: url, dns, ip belgim_domains = return_from_belgim.scan(regexp_redns) belgim_urls = return_from_belgim.scan(regexp_reurl) belgim_ips = return_from_belgim.scan(regexp_reip) #process only domains. for i in belgim_domains a1 = i[0] elem = a1.gsub(" 200, :result => "Request completed successfully", :number => {:domain_num => dns_num, :url_http_num => url_num, :ipv4_num => ipv4_num, :ipv6_num => ipv6_num, :url_https_num => https_num, :url_all_num => url_all_num, :all_num => all_num }, :domains_for_block => domain_parsed, :url_for_block => url_parsed, :ipv6_parsed => ipv6_parsed, :ipv4_parsed => ipv4_parsed, :https_parsed => https_parsed, :url_all => url_all } rescue output_data = {:code => 507, :result => "belgim_ukaz60_get: Unknown error"} end output_data end end