class Belgim_2
Attributes
belgim_login[RW]
belgim_password[RW]
belgim_url[RW]
telegram_messanger[RW]
ukaz60_add_func[RW]
Public Class Methods
new(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url )
click to toggle source
# File lib/imperituroard/projects/ukaz60/belgim.rb, line 15 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
Public Instance Methods
belgim_ukaz60_get()
click to toggle source
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
# File lib/imperituroard/projects/ukaz60/belgim.rb, line 32 def belgim_ukaz60_get output_data = {} begin #data peremennye regexp_redns = /<dns>(.{1,100})dns>/ regexp_reurl = /<url>(.{1,100})url>/ regexp_reip = /<ip>(.{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 curl_belgie_command = "curl -d \"name=#{belgim_login}&pass=#{belgim_password}\" -H \"Content-Type: application/x-www-form-urlencoded\" -X POST #{belgim_url} --insecure" #return_from_belgim = `curl -d "name=#{belgim_login}&pass=#{belgim_password}" -H "Content-Type: application/x-www-form-urlencoded" -X POST #{belgim_url} --insecure` return_from_belgim = `#{curl_belgie_command}` #p curl_belgie_command 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("</", "") if elem.include? " " elem = elem.gsub(" ", "") end #if elem.match(/а|б|в|г|д|е|ж|ё|Ё|з|и|й|к|л|м|н|о|п|р|с|т|у|ф|х|ц|ч|ш|щ|ь|ы|ъ|э|ю|я|А|Б|В|Г|Д|Е|Ж|З|И|Й|К|Л|М|Н|О|П|Р|С|Т|У|Ф|Х|Ц|Ч|Ш|Щ|Ь|Ы|Ъ|Э|Ю|Я/) if elem.match(/[а-яА-ЯЁё]/) elem = SimpleIDN.to_ascii(elem) end if elem != "-" && elem != "" domain_parsed.push(elem) if_www = elem[0] + elem[1] + elem[2] + elem[3] #if not contain www - add domain with www if if_www != "www." domain_parsed.push("www."+elem) end #if contain www - add domain without www if if_www == "www." gar = elem[4..elem.length] domain_parsed.push(gar) end end end #process only urls for s in belgim_urls #process every domain. Find if https or http and domain func_processed = ukaz60_add_func.delete_dump_symbols_url(s[0]) if func_processed[:code] == 200 processed_url = func_processed[:domain_only] processed_domain_in_url = func_processed[:processed_domain_in_url] if func_processed[:type] == "domain" domain_parsed.push(processed_url) check_if_www = processed_url[0]+processed_url[1]+processed_url[2]+processed_url[3] #if not contains www then add with www too if check_if_www != "www." domain_parsed.push("www."+processed_url) end #if contains www then add without www too if check_if_www == "www." gar2domain = processed_url[4..processed_url.length] domain_parsed.push(gar2domain) end elsif func_processed[:type] == "url" && func_processed[:protocol] != "https" #p "Step4 processed_domain_in_url: #{processed_domain_in_url}" #p "Step5 func_processed: #{func_processed.to_s}" url_parsed.push(func_processed[:protocol] + "://" + processed_domain_in_url) check_if_www2 = processed_domain_in_url[0]+processed_domain_in_url[1]+processed_domain_in_url[2]+processed_domain_in_url[3] if check_if_www2 != "www." url_parsed.push(func_processed[:protocol] + "://" + "www."+processed_domain_in_url) end if check_if_www2 == "www." gar1url = processed_domain_in_url[4..processed_domain_in_url.length] url_parsed.push(func_processed[:protocol] + "://" + gar1url) end elsif func_processed[:protocol] == "https" #additional section for https urls https_parsed.push(func_processed[:protocol] + "://" + processed_domain_in_url) check_if_www2https = processed_domain_in_url[0]+processed_domain_in_url[1]+processed_domain_in_url[2]+processed_domain_in_url[3] if check_if_www2https != "www." https_parsed.push(func_processed[:protocol] + "://" + "www."+processed_domain_in_url) end if check_if_www2https == "www." gar1url_https = processed_domain_in_url[4..processed_domain_in_url.length] https_parsed.push(func_processed[:protocol] + "://" + gar1url_https) end end end end #process only IPs for f in belgim_ips a2ip = f[0] if a2ip.include? " " a2ip = a2ip.gsub(" ", "") end elem_ip = a2ip.gsub("</", "") if elem_ip != "-" && elem_ip != "" if elem_ip.include?(":") ipv6_parsed.push(elem_ip) else ipv4_parsed.push(elem_ip) end end end domain_parsed = domain_parsed.uniq url_parsed = url_parsed.uniq ipv6_parsed = ipv6_parsed.uniq ipv4_parsed = ipv4_parsed.uniq https_parsed = https_parsed.uniq https_parsed_tmmp = [] https_parsed.each do |tmp_tmp| https_parsed_tmmp.push(tmp_tmp.gsub("https://", "http://")) end url_all = https_parsed_tmmp + url_parsed url_all = url_all.uniq url_all_num = url_all.length dns_num = domain_parsed.length ipv4_num = ipv4_parsed.length ipv6_num = ipv6_parsed.length url_num = url_parsed.length https_num = https_parsed.length all_num = dns_num + ipv4_num + ipv6_num + url_num + https_num output_data = {:code => 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