Class: Belgim_2
- Inherits:
-
Object
- Object
- Belgim_2
- Defined in:
- lib/imperituroard/projects/ukaz60/belgim.rb
Instance Attribute Summary collapse
-
#belgim_login ⇒ Object
Returns the value of attribute belgim_login.
-
#belgim_password ⇒ Object
Returns the value of attribute belgim_password.
-
#belgim_url ⇒ Object
Returns the value of attribute belgim_url.
-
#telegram_messanger ⇒ Object
Returns the value of attribute telegram_messanger.
-
#ukaz60_add_func ⇒ Object
Returns the value of attribute ukaz60_add_func.
Instance Method Summary collapse
-
#belgim_ukaz60_get ⇒ Object
get domains from belgim and parse data return all domains urls ips.
-
#initialize(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url) ⇒ Belgim_2
constructor
A new instance of Belgim_2.
Constructor Details
#initialize(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url) ⇒ Belgim_2
Returns a new instance of Belgim_2.
15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 |
Instance Attribute Details
#belgim_login ⇒ Object
Returns the value of attribute belgim_login.
9 10 11 |
# File 'lib/imperituroard/projects/ukaz60/belgim.rb', line 9 def belgim_login @belgim_login end |
#belgim_password ⇒ Object
Returns the value of attribute belgim_password.
9 10 11 |
# File 'lib/imperituroard/projects/ukaz60/belgim.rb', line 9 def belgim_password @belgim_password end |
#belgim_url ⇒ Object
Returns the value of attribute belgim_url.
9 10 11 |
# File 'lib/imperituroard/projects/ukaz60/belgim.rb', line 9 def belgim_url @belgim_url end |
#telegram_messanger ⇒ Object
Returns the value of attribute telegram_messanger.
9 10 11 |
# File 'lib/imperituroard/projects/ukaz60/belgim.rb', line 9 def telegram_messanger @telegram_messanger end |
#ukaz60_add_func ⇒ Object
Returns the value of attribute ukaz60_add_func.
9 10 11 |
# File 'lib/imperituroard/projects/ukaz60/belgim.rb', line 9 def ukaz60_add_func @ukaz60_add_func end |
Instance Method Details
#belgim_ukaz60_get ⇒ Object
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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# 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 |