imperituroard 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aed6187f630376b03b976303e1fa4f87800d036e
4
- data.tar.gz: 94fad4b56fd4a5926d3b6433ea7da900cd4d1e20
3
+ metadata.gz: 814b880df6196f3635f3f9b64dd77f6e25766d6f
4
+ data.tar.gz: a4f0e6e3f1b2ee0ce362164ad713178b28096921
5
5
  SHA512:
6
- metadata.gz: e445408da82e71836bb61a94c0ab26cb166e904b48b8aa03f23c0395803cfa3a2ce5026a89364bdfc88b1561c8148815465df8dfcd6313b60fe0e950baf494c8
7
- data.tar.gz: 740a6cbee54ce5949bf0059d3847a86bb66486f43d90b8e766ddf74b362e56f70e44784b71f2bc1643b32e27e11822f33b42c3145493a312948ad61e230c0370
6
+ metadata.gz: f506dbdf7461d0cf4978df6d0185f416f2d5d0f6b6a851d7b847a4780071e73586bcc6204803e52645e4d1fa69acff75a39116f5f84dbb51ebda8dafdb6db8b6
7
+ data.tar.gz: d790d6687195341c546e40072498a32ee06ac7a3028b932f7fedaedc145ac6a2dc8c52998565410c5c0d4157a2702abb39c56f9f31e60f98b5c247657c915ce9
@@ -0,0 +1,22 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'json'
4
+ require 'date'
5
+
6
+
7
+ class LogAddFunctions_2
8
+
9
+
10
+ def datetimenow()
11
+ d_curr = DateTime.now
12
+ time_zone = 'Europe/Minsk'
13
+ DateTime.now.to_s
14
+ end
15
+
16
+ def printer_texter(text, log_level)
17
+ mess = {:datetime => datetimenow, :sdk => "imperituroard", :sdk_version => Imperituroard::VERSION, :message => text}
18
+ p mess
19
+ end
20
+
21
+
22
+ end
@@ -0,0 +1,182 @@
1
+ require 'imperituroard/platforms/public/telegram'
2
+ require 'imperituroard/projects/dns/ukaz60/ukaz60_add_func'
3
+
4
+ require 'simpleidn'
5
+
6
+ class Belgim_2
7
+
8
+
9
+ attr_accessor :telegram_messanger,
10
+ :belgim_login,
11
+ :belgim_password,
12
+ :belgim_url,
13
+ :ukaz60_add_func
14
+
15
+ def initialize(telegram_api_url,
16
+ telegram_chat_id,
17
+ belgim_login,
18
+ belgim_password,
19
+ belgim_url
20
+ )
21
+ @telegram_messanger = Telegram_2.new(telegram_api_url, telegram_chat_id)
22
+ @belgim_login = belgim_login
23
+ @belgim_password = belgim_password
24
+ @belgim_url = belgim_url
25
+ @ukaz60_add_func = AddFuncUkaz60_2.new
26
+ end
27
+
28
+
29
+ #get domains from belgim and parse data
30
+ #return all domains urls ips. Selection specific data for dns or firewall do by additional functions
31
+ #full ready for dns and firewall
32
+ def belgim_ukaz60_get
33
+
34
+ output_data = {}
35
+
36
+ begin
37
+
38
+ #data peremennye
39
+ regexp_redns = /<dns>(.{1,100})dns>/
40
+ regexp_reurl = /<url>(.{1,100})url>/
41
+ regexp_reip = /<ip>(.{1,100})ip>/
42
+
43
+ #processed data in correct format
44
+ domain_parsed = []
45
+ url_parsed = []
46
+ ipv4_parsed = []
47
+ ipv6_parsed = []
48
+
49
+ f2 =[]
50
+ results = {}
51
+
52
+ # Get data from Belgim site by curl
53
+ return_from_belgim = `curl -d "name=#{belgim_login}&pass=#{belgim_password}" -H "Content-Type: application/x-www-form-urlencoded" -X POST #{belgim_url}`
54
+ return_from_belgim = return_from_belgim.gsub!("\n", "")
55
+
56
+ #parse Belgim file by regexpression
57
+ # and split by 3 categories: url, dns, ip
58
+ belgim_domains = return_from_belgim.scan(regexp_redns)
59
+ belgim_urls = return_from_belgim.scan(regexp_reurl)
60
+ belgim_ips = return_from_belgim.scan(regexp_reip)
61
+
62
+ #process only domains.
63
+ for i in belgim_domains
64
+ a1 = i[0]
65
+ elem = a1.gsub("</", "")
66
+
67
+ if elem.include? " "
68
+ elem = elem.gsub(" ", "")
69
+ end
70
+
71
+ if elem.match(/а|б|в|г|д|е|ж|ё|Ё|з|и|й|к|л|м|н|о|п|р|с|т|у|ф|х|ц|ч|ш|щ|ь|ы|ъ|э|ю|я|А|Б|В|Г|Д|Е|Ж|З|И|Й|К|Л|М|Н|О|П|Р|С|Т|У|Ф|Х|Ц|Ч|Ш|Щ|Ь|Ы|Ъ|Э|Ю|Я/)
72
+ elem = SimpleIDN.to_ascii(elem)
73
+ end
74
+
75
+ if elem != "-" && elem != ""
76
+ domain_parsed.push(elem)
77
+ if_www = elem[0]+elem[1]+elem[2]+elem[3]
78
+
79
+ #if not contain www - add domain with www
80
+ if if_www != "www."
81
+ domain_parsed.push("www."+elem)
82
+ end
83
+
84
+ #if contain www - add domain without www
85
+ if if_www == "www."
86
+ gar = elem[4..elem.length]
87
+ domain_parsed.push(gar)
88
+ end
89
+ end
90
+ end
91
+
92
+ #process only urls
93
+ for s in belgim_urls
94
+
95
+ #process every domain. Find if https or http and domain
96
+ func_processed = ukaz60_add_func.delete_dump_symbols_url(s[0])
97
+
98
+ if func_processed[:code] == 200
99
+ processed_url = func_processed[:domain_only]
100
+ processed_domain_in_url = func_processed[:processed_domain_in_url]
101
+
102
+ if func_processed[:type] == "domain" || func_processed[:protocol] == "https"
103
+ domain_parsed.push(processed_url)
104
+ check_if_www = processed_url[0]+processed_url[1]+processed_url[2]+processed_url[3]
105
+
106
+ #if not contains www then add with www too
107
+ if check_if_www != "www."
108
+ domain_parsed.push("www."+processed_url)
109
+ end
110
+
111
+ #if contains www then add without www too
112
+ if check_if_www == "www."
113
+ gar2domain = processed_url[4..processed_url.length]
114
+ domain_parsed.push(gar2domain)
115
+ end
116
+ elsif func_processed[:type] == "url" && func_processed[:protocol] != "https"
117
+ #p "Step4 processed_domain_in_url: #{processed_domain_in_url}"
118
+ #p "Step5 func_processed: #{func_processed.to_s}"
119
+
120
+ url_parsed.push(func_processed[:protocol] + "://" + processed_domain_in_url)
121
+ check_if_www2 = processed_domain_in_url[0]+processed_domain_in_url[1]+processed_domain_in_url[2]+processed_domain_in_url[3]
122
+ if check_if_www2 != "www."
123
+ url_parsed.push(func_processed[:protocol] + "://" + "www."+processed_domain_in_url)
124
+ end
125
+ if check_if_www2 == "www."
126
+ gar1url = processed_domain_in_url[4..processed_domain_in_url.length]
127
+ url_parsed.push(func_processed[:protocol] + "://" + gar1url)
128
+ end
129
+ end
130
+ end
131
+ end
132
+
133
+ #process only IPs
134
+ for f in belgim_ips
135
+
136
+ a2ip = f[0]
137
+
138
+ if a2ip.include? " "
139
+ a2ip = a2ip.gsub(" ", "")
140
+ end
141
+
142
+ elem_ip = a2ip.gsub("</", "")
143
+
144
+ if elem_ip != "-" && elem_ip != ""
145
+ if elem_ip.include?(":")
146
+ ipv6_parsed.push(elem_ip)
147
+ else
148
+ ipv4_parsed.push(elem_ip)
149
+ end
150
+ end
151
+ end
152
+
153
+ domain_parsed = domain_parsed.uniq
154
+ url_parsed = url_parsed.uniq
155
+ ipv6_parsed = ipv6_parsed.uniq
156
+ ipv4_parsed = ipv4_parsed.uniq
157
+
158
+ dns_num = domain_parsed.length
159
+ ipv4_num = ipv4_parsed.length
160
+ ipv6_num = ipv6_parsed.length
161
+ url_num = url_parsed.length
162
+
163
+ output_data = {:code => 200, :result => "Request completed successfully",
164
+ :number =>{:dns_num => dns_num,
165
+ :url_num => url_num,
166
+ :ipv4_num => ipv4_num,
167
+ :ipv6_num => ipv6_num
168
+ },
169
+ :domains_for_block => domain_parsed,
170
+ :url_for_block => url_parsed,
171
+ :ipv6_parsed => ipv6_parsed,
172
+ :ipv4_parsed => ipv4_parsed}
173
+
174
+ rescue
175
+ output_data = {:code => 507, :result => "belgim_ukaz60_get: Unknown error"}
176
+ end
177
+ output_data
178
+
179
+ end
180
+
181
+
182
+ end
@@ -0,0 +1,18 @@
1
+
2
+
3
+ class DnsUkaz60_2
4
+
5
+ attr_accessor :dns_login, :dns_password
6
+
7
+ def initialize(dns_login, dns_password)
8
+ @dns_login = dns_login
9
+ @dns_password = dns_password
10
+ end
11
+
12
+ def get_current_block_dns(dns_ip)
13
+
14
+
15
+
16
+ end
17
+
18
+ end
@@ -142,144 +142,11 @@ class Ukaz60Dns_2
142
142
  end
143
143
 
144
144
 
145
- def dns_processe
146
- a = "cruel world"
147
- f = a.scan(/\w+/)
148
145
 
149
- starttime = DateTime.now
150
-
151
-
152
- comm = `curl -d "name=#{belgim_login}&pass=#{belgim_password}" -H "Content-Type: application/x-www-form-urlencoded" -X POST #{belgim_url}`
153
-
154
- comm = comm.gsub!("\n","")
155
-
156
- #p comm
157
-
158
- #comm = comm.gsub!("\r","")
159
-
160
- #p comm
161
-
162
- redns = /<dns>(.{1,100})dns>/
163
- rednsurl = /<url>(.{1,100})url>/
164
-
165
- m1 = comm.scan(redns)
166
- m2 = []
167
-
168
- f1 = comm.scan(rednsurl)
169
- f2 =[]
170
-
171
- results = {}
172
-
173
- for i in m1
174
- a1 = i[0]
175
- elem = a1.gsub!("</","")
176
-
177
- if elem.include? " "
178
- elem = elem.gsub!(" ", "")
179
- end
180
-
181
-
182
- if elem.match(/а|б|в|г|д|е|ж|ё|Ё|з|и|й|к|л|м|н|о|п|р|с|т|у|ф|х|ц|ч|ш|щ|ь|ы|ъ|э|ю|я|А|Б|В|Г|Д|Е|Ж|З|И|Й|К|Л|М|Н|О|П|Р|С|Т|У|Ф|Х|Ц|Ч|Ш|Щ|Ь|Ы|Ъ|Э|Ю|Я/)
183
- elem = SimpleIDN.to_ascii(elem)
184
- end
185
-
186
- p elem
187
-
188
- if elem != "-"
189
-
190
- m2.push(elem)
191
-
192
- daaa = elem[0]+elem[1]+elem[2]+elem[3]
193
-
194
- if daaa != "www."
195
- m2.push("www."+elem)
196
- end
197
-
198
- if daaa == "www."
199
- gar = elem[4..elem.length]
200
- m2.push(gar)
201
- end
202
-
203
- end
204
-
205
-
206
- end
207
-
208
- p m2
209
-
210
-
211
- for s in f1
212
- a1 = s[0]
213
-
214
-
215
- elem1 = a1.gsub!("</","")
216
- elem2 =""
217
-
218
- if elem1.include? "http://"
219
- elem1.gsub!("http://", "")
220
- end
221
-
222
- if elem1.include? "http:/"
223
- elem1.gsub!("http:/", "")
224
- end
225
-
226
-
227
- if elem1.include? "https://"
228
- elem1.gsub!("https://", "")
229
- if elem1.include?("/")
230
- elem1=elem1.split("/")[0]
231
- end
232
- end
233
-
234
- if elem1.include? " "
235
- elem1 = elem1.gsub!(" ", "")
236
- end
237
-
238
- #p elem1
239
-
240
- if elem1[elem1.size-1]=="/"
241
- sss = elem1.size
242
- elem1 = elem1[0..sss-2]
243
- end
244
-
245
- if !elem1.include? "/"
246
- if elem1.match(/а|б|в|г|д|е|ж|ё|Ё|з|и|й|к|л|м|н|о|п|р|с|т|у|ф|х|ц|ч|ш|щ|ь|ы|ъ|э|ю|я|А|Б|В|Г|Д|Е|Ж|З|И|Й|К|Л|М|Н|О|П|Р|С|Т|У|Ф|Х|Ц|Ч|Ш|Щ|Ь|Ы|Ъ|Э|Ю|Я/)
247
- elem1 = SimpleIDN.to_ascii(elem1)
248
- end
249
-
250
- if elem1 != "-" && elem1 != ""
251
- m2.push(elem1)
252
-
253
- p elem1
254
-
255
-
256
- daaa2 = elem1[0]+elem1[1]+elem1[2]+elem1[3]
257
-
258
- p daaa2
259
-
260
-
261
-
262
-
263
- if daaa2 != "www."
264
- m2.push("www."+elem1)
265
- end
266
-
267
- if daaa2 == "www."
268
- gar1 = elem1[4..elem1.length]
269
- m2.push(gar1)
270
- end
271
-
272
- end
273
- end
274
-
275
- end
276
-
277
- m2 = m2.uniq
278
146
 
279
147
 
280
148
 
281
149
  stringnunblo = File.open('/scripts/ruby/dns/nonblocked.conf', 'r'){ |file| file.read }
282
-
283
150
  noblocked = stringnunblo.split("\n")
284
151
 
285
152
  m2 = m2 - noblocked
@@ -405,7 +272,6 @@ class Ukaz60Dns_2
405
272
  #File.delete("blocked_old.conf") if File.exist?("blocked_old.conf")
406
273
  #File.delete("add_bl_memory.sh") if File.exist?("add_bl_memory.sh")
407
274
 
408
- end
409
275
 
410
276
 
411
277
  end
@@ -0,0 +1,171 @@
1
+ require 'net/scp'
2
+ require 'date'
3
+
4
+ require 'imperituroard/projects/dns/ukaz60/ukaz60_add_func'
5
+
6
+
7
+ class FortiUkaz60_2
8
+
9
+ attr_accessor :ansible_tmp_folder,
10
+ :local_tmp_directory,
11
+ :ansible_ssh_user,
12
+ :ansible_ssh_password,
13
+ :ansible_host,
14
+ :add_func_connector,
15
+ :add_functions_full,
16
+ :url_backup_dir
17
+
18
+
19
+ def initialize(ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir)
20
+ @ansible_tmp_folder = ansible_tmp_folder
21
+ @local_tmp_directory = local_tmp_directory
22
+ @ansible_ssh_user = ansible_ssh_user
23
+ @ansible_ssh_password = ansible_ssh_password
24
+ @ansible_host = ansible_host
25
+ @add_func_connector = AddFuncUkaz60_2.new
26
+ @add_functions_full = LogAddFunctions_2.new
27
+ @url_backup_dir = url_backup_dir
28
+ end
29
+
30
+ #1 Function for upload data to ansible server
31
+ # Full ready
32
+ def upload_url(url_list)
33
+
34
+ input_data = {:url_list => url_list}
35
+ output_data = {}
36
+
37
+ begin
38
+
39
+ write_data = JSON.pretty_generate(url_list)
40
+
41
+ date_time = DateTime.now.to_s
42
+ add_date_name = date_time.gsub("+03:00", "").gsub("-", "_").gsub(":", "_")
43
+
44
+ local_url_file = "#{local_tmp_directory}/urls.json"
45
+ remote_url_file = "#{ansible_tmp_folder}/urls.json"
46
+ backup_url_file = "#{url_backup_dir}/urls_#{add_date_name}.json"
47
+
48
+ #create local file
49
+ gg = File.open(local_url_file, "w:UTF-8") {|f| f.write(write_data)}
50
+
51
+ #create backup
52
+ begin
53
+ gg1 = Net::SCP.upload!(ansible_host, ansible_ssh_user,
54
+ local_url_file, backup_url_file,
55
+ :ssh => {:password => ansible_ssh_password})
56
+ rescue
57
+ nil
58
+ end
59
+
60
+ #upload local file
61
+ gg1 = Net::SCP.upload!(ansible_host, ansible_ssh_user,
62
+ local_url_file, remote_url_file,
63
+ :ssh => {:password => ansible_ssh_password})
64
+
65
+ output_data = {:code => 200, :result => "upload_url: Data uploaded"}
66
+
67
+ rescue
68
+ output_data = {:code => 507, :result => "upload_url: Unknown SDK error"}
69
+ end
70
+ add_functions_full.printer_texter(output_data, "debug")
71
+ output_data
72
+ end
73
+
74
+
75
+ #2 function for process data to fortigate directly by ansible
76
+ # Full ready
77
+ def update_weburl_fortigate
78
+ output_data = {}
79
+ begin
80
+ command = "/bin/bash /scripts/temp_fortigate_url_upload.sh"
81
+ ansible_answer = ""
82
+ Net::SSH.start(ansible_host, ansible_ssh_user, :password => ansible_ssh_password) do |ssh|
83
+ ansible_answer = ssh.exec!(command)
84
+ end
85
+ #hh = "\nPLAY [ha_master] ***************************************************************\n\nTASK [set url table] ***********************************************************\nchanged: [gom32sg1]\nchanged: [bre32sg1]\nchanged: [min32sg1]\nchanged: [vit32sg1]\nchanged: [min32sg3]\nchanged: [gro32sg1]\nchanged: [mog32sg1]\n\nTASK [check current url table] *************************************************\nok: [min32sg1]\nok: [bre32sg1]\nok: [min32sg3]\nok: [vit32sg1]\nok: [gom32sg1]\nok: [gro32sg1]\nok: [mog32sg1]\n\nTASK [debug] *******************************************************************\nok: [min32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [min32sg3] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [bre32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [vit32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [gom32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [gro32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\nok: [mog32sg1] => {\n \"msg\": \"URL loaded/in-file: [1273 / 1273]\"\n}\n\nPLAY RECAP *********************************************************************\nbre32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \ngom32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \ngro32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \nmin32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \nmin32sg3 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \nmog32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \nvit32sg1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 \n\n"
86
+ answ_pr = add_func_connector.ansible_answer_parse(ansible_answer)
87
+ output_data = {:code => 200, :result => "update_weburl_fortigate: Request completed", :body => answ_pr}
88
+ rescue
89
+ output_data = {:code => 507, :result => "update_weburl_fortigate: Unknown SDK error"}
90
+ end
91
+ add_functions_full.printer_texter(output_data, "debug")
92
+ output_data
93
+ end
94
+
95
+ #3 Clean all temp files
96
+ # Full ready
97
+ def clean_tmp_folders
98
+ out_data = {}
99
+ folder = "#{ansible_tmp_folder}/"
100
+ path_to_local_file = "#{local_tmp_directory}/urls.json"
101
+ if folder != "/" && folder != "" && folder != nil && folder != "//" && folder.split("/").length > 2
102
+ begin
103
+ Net::SSH.start(ansible_host, ansible_ssh_user, :password => ansible_ssh_password) do |ssh|
104
+ comm_delete = "rm -rf #{folder}*"
105
+ result = ssh.exec!(comm_delete)
106
+ end
107
+ File.delete(path_to_local_file) if File.exist?(path_to_local_file)
108
+ out_data = {:code => 200, :result => "clean_tmp_folders: Cleared successfully"}
109
+ rescue
110
+ out_data = {:code => 500, :result => "clean_tmp_folders: ssh_failed"}
111
+ end
112
+ else
113
+ out_data = {:code => 404, :result => "clean_tmp_folders: invalid and danger temp path"}
114
+ end
115
+ add_functions_full.printer_texter(out_data, "debug")
116
+ out_data
117
+ end
118
+
119
+ #4 process belgim data parse function
120
+ # and do list for Fortigate upload
121
+ # Full ready
122
+ def prepare_url_config_fortigate(data_belgim)
123
+
124
+ to_fortigate = []
125
+ output_data = {}
126
+
127
+ begin
128
+
129
+ for ipv4 in data_belgim[:ipv4_parsed]
130
+ to_fortigate.push({
131
+ "url" => ipv4,
132
+ "action" => "block"
133
+ })
134
+ end
135
+
136
+ for ipv6 in data_belgim[:ipv6_parsed]
137
+ to_fortigate.push({
138
+ "url" => "[#{ipv6}]",
139
+ "action" => "block"
140
+ })
141
+ end
142
+
143
+ for dns in data_belgim[:domains_for_block]
144
+ to_fortigate.push({
145
+ "url" => dns,
146
+ "action" => "block"
147
+ })
148
+ end
149
+
150
+ for url in data_belgim[:url_for_block]
151
+ format_url = url.gsub("#", "")
152
+ to_fortigate.push({
153
+ "url" => format_url,
154
+ "action" => "block"
155
+ })
156
+ end
157
+
158
+ num_list = to_fortigate.length
159
+
160
+ output_data = {:code => 200, :result => "Request completed", :body => {:num_list => num_list,
161
+ :to_fortigate => to_fortigate}}
162
+ rescue
163
+ output_data = {:code => 507, :result => "Unknown error"}
164
+ p "ERROR !!! prepare_url_config_fortigate"
165
+ end
166
+ output_data
167
+ end
168
+
169
+
170
+ end
171
+
@@ -0,0 +1,151 @@
1
+ require 'imperituroard/add_functions/logger/any_functions'
2
+
3
+ class AddFuncUkaz60_2
4
+
5
+ attr_accessor :add_functions
6
+
7
+ def initialize
8
+ @add_functions = LogAddFunctions_2.new
9
+ end
10
+
11
+ #function for process separate domains
12
+ #for one domain
13
+ def delete_dump_symbols_url(stroka)
14
+ input_params = {:stroka => stroka}
15
+ output_answer = {}
16
+ processed_domain_in_url = ""
17
+ protocol = ""
18
+ type = ""
19
+ domain_only = ""
20
+ begin
21
+
22
+ #p "Step1 stroka: #{stroka}"
23
+
24
+ first_url = stroka.gsub("</", "")
25
+
26
+ if first_url != "-" && first_url != ""
27
+
28
+ #check web protocol (http/https/unknown)
29
+ if stroka.include? "http:"
30
+ protocol = "http"
31
+ elsif stroka.include? "https:"
32
+ protocol = "https"
33
+ else
34
+ protocol = "unknown"
35
+ p "ERROR: delete_dump_symbols_url.unknown protocol"
36
+ end
37
+
38
+ if first_url.include? "http://"
39
+ processed_domain_in_url = first_url.gsub("http://", "")
40
+ else
41
+ processed_domain_in_url = processed_domain_in_url + first_url
42
+ end
43
+
44
+ if processed_domain_in_url.include? "http:///"
45
+ processed_domain_in_url.gsub!("http:///", "")
46
+ end
47
+
48
+ if processed_domain_in_url.include? "http:/"
49
+ processed_domain_in_url.gsub!("http:/", "")
50
+ end
51
+
52
+ if processed_domain_in_url.include? "https://"
53
+ processed_domain_in_url.gsub!("https://", "")
54
+ end
55
+
56
+ if processed_domain_in_url.include? "https:/"
57
+ processed_domain_in_url.gsub!("https:/", "")
58
+ end
59
+
60
+ if processed_domain_in_url.include? " "
61
+ processed_domain_in_url = processed_domain_in_url.gsub!(" ", "")
62
+ end
63
+
64
+ #delete / at the end
65
+ if processed_domain_in_url[processed_domain_in_url.size-1]=="/"
66
+ sss = processed_domain_in_url.size
67
+ processed_domain_in_url = processed_domain_in_url[0..sss-2]
68
+ end
69
+
70
+ #p "Step2 processed_domain_in_url: #{processed_domain_in_url}"
71
+
72
+ if processed_domain_in_url != "-" && processed_domain_in_url != "" && processed_domain_in_url != nil
73
+ #p "Step3 processed_domain_in_url: #{processed_domain_in_url}"
74
+ #if include / then it is url. Else - domain
75
+ if !processed_domain_in_url.include? "/"
76
+ #it is domain. Process domain
77
+ #if it is kirillica then process
78
+ if processed_domain_in_url.match(/а|б|в|г|д|е|ж|ё|Ё|з|и|й|к|л|м|н|о|п|р|с|т|у|ф|х|ц|ч|ш|щ|ь|ы|ъ|э|ю|я|А|Б|В|Г|Д|Е|Ж|З|И|Й|К|Л|М|Н|О|П|Р|С|Т|У|Ф|Х|Ц|Ч|Ш|Щ|Ь|Ы|Ъ|Э|Ю|Я/)
79
+ processed_domain_in_url = SimpleIDN.to_ascii(processed_domain_in_url)
80
+ end
81
+ domain_only = domain_only + processed_domain_in_url
82
+ type = "domain"
83
+ else
84
+ #it is url. process url
85
+ hh = processed_domain_in_url.split("/")
86
+ domain_only = hh[0]
87
+ if domain_only.match(/а|б|в|г|д|е|ж|ё|Ё|з|и|й|к|л|м|н|о|п|р|с|т|у|ф|х|ц|ч|ш|щ|ь|ы|ъ|э|ю|я|А|Б|В|Г|Д|Е|Ж|З|И|Й|К|Л|М|Н|О|П|Р|С|Т|У|Ф|Х|Ц|Ч|Ш|Щ|Ь|Ы|Ъ|Э|Ю|Я/)
88
+ hh[0] = SimpleIDN.to_ascii(domain_only)
89
+ processed_domain_in_url = ""
90
+ for t in hh
91
+ processed_domain_in_url = processed_domain_in_url + t + "/"
92
+ end
93
+ sss1len = processed_domain_in_url.size
94
+ processed_domain_in_url = processed_domain_in_url[0..sss1len-2]
95
+ end
96
+ type = "url"
97
+ end
98
+ else
99
+ type = "empty"
100
+ end
101
+ output_answer = {:code => 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}
102
+
103
+ else
104
+ output_answer = {:code => 202, :result => "Data not found"}
105
+ end
106
+ rescue
107
+ output_answer = {:code => 507, :result => "Something wrong"}
108
+ end
109
+ output_answer
110
+ end
111
+
112
+
113
+ def ansible_answer_parse(answer_string)
114
+ input_data = {:answer_string => answer_string}
115
+ output_data = {}
116
+
117
+ begin
118
+ answ_ans_parsed = answer_string.gsub("\n", " ")
119
+ result_out = []
120
+ num_ok = 0
121
+ num_failed = 0
122
+ 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+/
123
+
124
+ processed_data = answ_ans_parsed.scan(final_checks)
125
+ if processed_data!=[] && processed_data!=""
126
+ for aaa in processed_data
127
+ begin
128
+ 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
129
+ result_out.push({aaa[0] => "Ok"})
130
+ num_ok = num_ok + 1
131
+ else
132
+ result_out.push({aaa[0] => "Failed"})
133
+ num_failed = num_failed + 1
134
+ end
135
+ rescue
136
+ result_out.push({"unknown" => aaa.to_s})
137
+ num_failed = num_failed + 1
138
+ end
139
+ end
140
+ output_data = {:code => 200, :result => "ansible_answer_parse: Request completed successfully", :body => {:list => result_out, :num_ok => num_ok, :num_failed => num_failed}}
141
+ else
142
+ output_data = {:code => 400, :result => "ansible_answer_parse: Ansible returned empty data"}
143
+ end
144
+ rescue
145
+ output_data = {:code => 507, :result => "ansible_answer_parse: Unknown error"}
146
+ end
147
+ add_functions.printer_texter(output_data, "debug")
148
+ output_data
149
+ end
150
+
151
+ end
@@ -0,0 +1,85 @@
1
+ require 'json'
2
+
3
+ require 'imperituroard/projects/dns/ukaz60/belgim'
4
+ require 'imperituroard/projects/dns/ukaz60/fortigate'
5
+
6
+ class Ukaz60All_2
7
+
8
+ attr_accessor :telegram_messanger,
9
+ :belgim_login,
10
+ :belgim_password,
11
+ :belgim_url,
12
+ :ukaz60_add_func,
13
+ :belgim_connector,
14
+ :forti_connector
15
+
16
+ def initialize(telegram_api_url,
17
+ telegram_chat_id,
18
+ belgim_login,
19
+ belgim_password,
20
+ belgim_url,
21
+ ansible_tmp_folder,
22
+ local_tmp_directory,
23
+ ansible_ssh_user,
24
+ ansible_ssh_password,
25
+ ansible_host,
26
+ url_backup_dir)
27
+ @telegram_messanger = Telegram_2.new(telegram_api_url, telegram_chat_id)
28
+ @belgim_login = belgim_login
29
+ @belgim_password = belgim_password
30
+ @belgim_url = belgim_url
31
+ @ukaz60_add_func = AddFuncUkaz60_2.new
32
+ @belgim_connector = Belgim_2.new(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url)
33
+ @forti_connector = FortiUkaz60_2.new(ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir)
34
+
35
+ end
36
+
37
+ def no_pasaran
38
+
39
+ answer_output = {}
40
+ forti_answer = {}
41
+
42
+ begin
43
+ get_belgim_data = belgim_connector.belgim_ukaz60_get
44
+
45
+ if get_belgim_data[:code] == 200
46
+
47
+ thr_forti = Thread.new do
48
+ begin
49
+ format_for_forti = forti_connector.prepare_url_config_fortigate(get_belgim_data)
50
+ if format_for_forti[:code] == 200
51
+ url_uploading = forti_connector.upload_url(format_for_forti[:body][:to_fortigate])
52
+ if url_uploading[:code] == 200
53
+ update_fortigate_ansible = forti_connector.update_weburl_fortigate
54
+ if update_fortigate_ansible[:code] == 200
55
+ forti_answer = {:code => 200, :result => "Fortigate processed", :data => update_fortigate_ansible[:body][:body]}
56
+ else
57
+ forti_answer = {:code => update_fortigate_ansible[:code], :result => update_fortigate_ansible[:result]}
58
+ end
59
+ forti_connector.clean_tmp_folders
60
+ else
61
+ forti_answer = {:code => 401, :result => "Failed for uploading data to ansible server"}
62
+ end
63
+ else
64
+ forti_answer = {:code => 400, :result => "Error while processing data"}
65
+ end
66
+ rescue
67
+ forti_answer = {:code => 507, :result => "Unknown error with Forti"}
68
+ end
69
+ end
70
+
71
+ thr_forti.join
72
+
73
+ answer_output = {:code => 200, :result => "No pasaran", :fortigate => forti_answer}
74
+ else
75
+ answer_output = {:code => 404, :result => "Failed to receive data from Belgim"}
76
+ end
77
+
78
+ rescue
79
+ answer_output = {:code => 507, :result => "no_pasaran: Unknown SDK error"}
80
+ end
81
+ telegram_messanger.telegram_message(answer_output.to_s)
82
+ answer_output
83
+ end
84
+
85
+ end
@@ -96,27 +96,27 @@ class AdditionalFunc
96
96
  end
97
97
 
98
98
  def check_input_1(login, imei_list)
99
- {:code=>200, :result=>"Request completed successfully", :body=>"Data checked"}
99
+ {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
100
100
  end
101
101
 
102
102
  def check_input_2(login, imei_list)
103
- {:code=>200, :result=>"Request completed successfully", :body=>"Data checked"}
103
+ {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
104
104
  end
105
105
 
106
106
  def check_input_3(login, imei_list)
107
- {:code=>200, :result=>"Request completed successfully", :body=>"Data checked"}
107
+ {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
108
108
  end
109
109
 
110
110
  def check_input_4(login, imei_list)
111
- {:code=>200, :result=>"Request completed successfully", :body=>"Data checked"}
111
+ {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
112
112
  end
113
113
 
114
114
  def check_input_5(login, imei_list)
115
- {:code=>200, :result=>"Request completed successfully", :body=>"Data checked"}
115
+ {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
116
116
  end
117
117
 
118
118
  def check_input_6(login, imei_list)
119
- {:code=>200, :result=>"Request completed successfully", :body=>"Data checked"}
119
+ {:code => 200, :result => "Request completed successfully", :body => "Data checked"}
120
120
  end
121
121
 
122
122
  def iot_query_dev_soapgw_answer(input_params, output_answer)
@@ -127,28 +127,28 @@ class AdditionalFunc
127
127
 
128
128
  begin
129
129
 
130
- if output_answer[:code]==200
131
- dataaa = []
132
- dataaa_failed = []
133
-
134
- ddd = answ_dev_query_format_process(output_answer[:data])[:body]
135
- p ddd
136
-
137
- answ = { :code => output_answer[:code],
138
- :result => output_answer[:result],
139
- :data => ddd[:ok],
140
- :error_list => ddd[:failed]
141
- }
142
- else
143
- answ = { :code => output_answer[:code],
144
- :result => output_answer[:result],
145
- :data => [],
146
- :error_list => input_params[:imei]
147
- }
148
- end
130
+ if output_answer[:code]==200
131
+ dataaa = []
132
+ dataaa_failed = []
133
+
134
+ ddd = answ_dev_query_format_process(output_answer[:data])[:body]
135
+ p ddd
136
+
137
+ answ = {:code => output_answer[:code],
138
+ :result => output_answer[:result],
139
+ :data => ddd[:ok],
140
+ :error_list => ddd[:failed]
141
+ }
142
+ else
143
+ answ = {:code => output_answer[:code],
144
+ :result => output_answer[:result],
145
+ :data => [],
146
+ :error_list => input_params[:imei]
147
+ }
148
+ end
149
149
  rescue
150
- answ = { :code => 500,
151
- :result => "Unknown error"
150
+ answ = {:code => 500,
151
+ :result => "Unknown error"
152
152
  }
153
153
  end
154
154
 
@@ -0,0 +1,29 @@
1
+
2
+ require 'net/ssh'
3
+
4
+ class EzuevFun_2
5
+
6
+
7
+ def vpn_create_client
8
+ command = "/usr/bin/python3.6 /projects/vpn_test/methods/create_client.py '{\"unp\": \"\", \"company_name\": \"MinskTrans\", \"full_name\":\"MinskTransTest\", \"info\": \"NewYork\", \"profile\": \"IoT\", \"net_type\": \"static\", \"number_sims\": 1024, \"msisdns\": [37529, 37528]}'"
9
+ Net::SSH.start("172.24.157.24", "soapgw", :password => "3g8Yh2Sl7Vz9Nbd358") do |ssh|
10
+ result = ssh.exec!(command)
11
+ p result
12
+ end
13
+ end
14
+
15
+ def vpn_update_client
16
+ command = "/usr/bin/python3.6 /projects/vpn_test/methods/update_client.py '{\"unp\": \"\", \"old_company_name\": \"MinskTrans\", \"new_company_name\": \"MinskTrans1\", \"new_full_name\": \"MinskTransTest1\", \"new_address\": \"NewYork\", \"new_contact_name\": \"1\", \"new_contact_number\": \"1\"}'"
17
+ Net::SSH.start("172.24.157.24", "soapgw", :password => "3g8Yh2Sl7Vz9Nbd358") do |ssh|
18
+ result = ssh.exec!(command)
19
+ p result
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+
26
+ ff = EzuevFun_2.new
27
+ ff.vpn_update_client
28
+
29
+
@@ -1,3 +1,3 @@
1
1
  module Imperituroard
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
data/lib/imperituroard.rb CHANGED
@@ -194,8 +194,6 @@ class Iot
194
194
  end
195
195
 
196
196
 
197
-
198
-
199
197
  #!5 add address to device
200
198
  #login
201
199
  #imei = newdevice_list
@@ -328,7 +326,8 @@ end
328
326
 
329
327
  class Ukaz60Automation_2
330
328
 
331
- attr_accessor :dns
329
+ attr_accessor :dns,
330
+ :ukaz60_func
332
331
 
333
332
  def initialize(telegram_api_url,
334
333
  telegram_chat_id,
@@ -342,7 +341,13 @@ class Ukaz60Automation_2
342
341
  dns_password,
343
342
  belgim_login,
344
343
  belgim_password,
345
- belgim_url)
344
+ belgim_url,
345
+ ansible_tmp_folder,
346
+ local_tmp_directory,
347
+ ansible_ssh_user,
348
+ ansible_ssh_password,
349
+ ansible_host,
350
+ url_backup_dir)
346
351
  @ukaz69_dns_func = Dns_2.new(telegram_api_url,
347
352
  telegram_chat_id,
348
353
  work_directory,
@@ -356,14 +361,22 @@ class Ukaz60Automation_2
356
361
  belgim_login,
357
362
  belgim_password,
358
363
  belgim_url)
359
- end
360
-
361
-
362
- def test
363
364
 
365
+ @ukaz60_func = Ukaz60All_2(telegram_api_url,
366
+ telegram_chat_id,
367
+ belgim_login,
368
+ belgim_password,
369
+ belgim_url,
370
+ ansible_tmp_folder,
371
+ local_tmp_directory,
372
+ ansible_ssh_user,
373
+ ansible_ssh_password,
374
+ ansible_host,
375
+ url_backup_dir)
364
376
  end
365
377
 
366
-
367
-
378
+ def no_pasaran
379
+ ukaz60_func.no_pasaran
380
+ end
368
381
 
369
382
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imperituroard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dzmitry Buynovskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-19 00:00:00.000000000 Z
11
+ date: 2020-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -187,11 +187,17 @@ files:
187
187
  - lib/.DS_Store
188
188
  - lib/imperituroard.rb
189
189
  - lib/imperituroard/.DS_Store
190
+ - lib/imperituroard/add_functions/logger/any_functions.rb
190
191
  - lib/imperituroard/platforms/cps/qps_connector.rb
191
192
  - lib/imperituroard/platforms/cps/request_formatter.rb
192
193
  - lib/imperituroard/platforms/public/telegram.rb
193
194
  - lib/imperituroard/projects/dns.rb
195
+ - lib/imperituroard/projects/dns/ukaz60.rb
196
+ - lib/imperituroard/projects/dns/ukaz60/belgim.rb
197
+ - lib/imperituroard/projects/dns/ukaz60/dns.rb
194
198
  - lib/imperituroard/projects/dns/ukaz60/dns_update.rb
199
+ - lib/imperituroard/projects/dns/ukaz60/fortigate.rb
200
+ - lib/imperituroard/projects/dns/ukaz60/ukaz60_add_func.rb
195
201
  - lib/imperituroard/projects/iot.rb
196
202
  - lib/imperituroard/projects/iot/add_functions.rb
197
203
  - lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb
@@ -202,6 +208,7 @@ files:
202
208
  - lib/imperituroard/projects/mhub/sk.rb
203
209
  - lib/imperituroard/projects/mhub/subs/dabrab/dabrab_platform.rb
204
210
  - lib/imperituroard/projects/mhub/subs/dabrab/dabrab_proced.rb
211
+ - lib/imperituroard/projects/vpn/ezuev_fun/functions_ezuev.rb
205
212
  - lib/imperituroard/projects/wttx/phpipamcps.rb
206
213
  - lib/imperituroard/projects/wttx/phpipamdb.rb
207
214
  - lib/imperituroard/projects/wttx/updatepostcps.rb