imperituroard 0.5.3 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/imperituroard.gemspec +3 -0
  3. data/lib/.DS_Store +0 -0
  4. data/lib/imperituroard.rb +47 -11
  5. data/lib/imperituroard/.DS_Store +0 -0
  6. data/lib/imperituroard/add_functions/logger/any_functions.rb +22 -0
  7. data/lib/imperituroard/platforms/cps/cps_multiple_thread_req.rb +0 -0
  8. data/lib/imperituroard/platforms/staros/get_data_ssh.rb +54 -0
  9. data/lib/imperituroard/platforms/staros/staros_automation.rb +95 -0
  10. data/lib/imperituroard/platforms/staros/staros_automation_fun.rb +37 -0
  11. data/lib/imperituroard/platforms/staros/staros_parser.rb +141 -0
  12. data/lib/imperituroard/projects/dns.rb +1 -1
  13. data/lib/imperituroard/projects/iot.rb +1 -1
  14. data/lib/imperituroard/projects/iot/add_functions.rb +27 -27
  15. data/lib/imperituroard/projects/mhub.rb +2 -0
  16. data/lib/imperituroard/projects/mhub/infobip.rb +1 -1
  17. data/lib/imperituroard/projects/mhub/sk.rb +171 -157
  18. data/lib/imperituroard/projects/mhub/subs/dabrab/dabrab_proced.rb +124 -12
  19. data/lib/imperituroard/projects/ukaz60.rb +140 -0
  20. data/lib/imperituroard/projects/ukaz60/belgim.rb +221 -0
  21. data/lib/imperituroard/projects/ukaz60/dns.rb +18 -0
  22. data/lib/imperituroard/projects/{dns/ukaz60 → ukaz60}/dns_update.rb +2 -134
  23. data/lib/imperituroard/projects/ukaz60/fortigate.rb +210 -0
  24. data/lib/imperituroard/projects/ukaz60/staros.rb +141 -0
  25. data/lib/imperituroard/projects/ukaz60/ukaz60_add_func.rb +306 -0
  26. data/lib/imperituroard/projects/vpn/ezuev_fun/functions_ezuev.rb +29 -0
  27. data/lib/imperituroard/version.rb +1 -1
  28. metadata +30 -3
@@ -1,5 +1,117 @@
1
1
  class Dabrab
2
2
 
3
+ def dabrabyt_text_field_parse(stri)
4
+ button_url = ""
5
+ image = ""
6
+ button_text = ""
7
+ text = stri
8
+
9
+ #############
10
+ #0 - Text only
11
+ #1 - Text + Button
12
+ #2 - Text + Image + Button
13
+ #3 - image only
14
+ #############
15
+ scheme = 0
16
+ scheme_dic = {0 => "Text only", 1 => "Text+Button", 2 => "Text+Image+Button", 3 => "Image only"}
17
+ #############
18
+
19
+ output_answer = {}
20
+ sk_format = {}
21
+
22
+ begin
23
+
24
+ regexp_image1 = /(image:(\S+)[\s\n]?)/
25
+ button_url1 = /(button_url:(\S+)[\s\n]?)/
26
+ button_text1 = /(button_text:["']([^"]+)["'][\s\n])/
27
+
28
+ button_url_dat = stri.scan(button_url1)
29
+ button_text_dat = stri.scan(button_text1)
30
+ image_dat = stri.scan(regexp_image1)
31
+
32
+
33
+ p button_url_dat
34
+ p button_text_dat
35
+ p image_dat
36
+
37
+ begin
38
+ if button_url_dat != [] && button_url_dat != nil && button_url_dat != ""
39
+ button_url = button_url_dat[0][1]
40
+ text = text.gsub(button_url_dat[0][0], "")
41
+ end
42
+ rescue
43
+ nil
44
+ end
45
+
46
+ begin
47
+ if button_text_dat != [] && button_text_dat != nil && button_text_dat != ""
48
+ button_text = button_text_dat[0][1]
49
+ text = text.gsub(button_text_dat[0][0], "")
50
+ end
51
+ rescue
52
+ nil
53
+ end
54
+
55
+ begin
56
+ if image_dat != [] && image_dat != nil && image_dat != ""
57
+ image = image_dat[0][1]
58
+ text = text.gsub(image_dat[0][0], "")
59
+ end
60
+ rescue
61
+ nil
62
+ end
63
+ text = text.gsub(/\s+$/, '').gsub(/\n$/, '')
64
+
65
+
66
+ if button_url != "" && button_text != "" && image != "" #111
67
+ scheme = 2
68
+ elsif button_url != "" && button_text != "" && image == "" #110
69
+ scheme = 1
70
+ elsif button_url == "" && button_text == "" && image != "" #001
71
+ if text == ""
72
+ scheme = 3
73
+ else
74
+ scheme = 2
75
+ button_url = image
76
+ button_text = "Открыть"
77
+ end
78
+ elsif button_url != "" && button_text == "" && image != "" #101
79
+ scheme = 2
80
+ button_text = "Открыть"
81
+ elsif button_url == "" && button_text != "" && image != "" #011
82
+ scheme = 2
83
+ button_url = image
84
+ elsif button_url == "" && button_text != "" && image == "" #010
85
+ scheme = 0
86
+ elsif button_url != "" && button_text == "" && image == "" #100
87
+ button_text = "Открыть"
88
+ scheme = 1
89
+ else
90
+ scheme = 0
91
+ end
92
+
93
+ if scheme==0
94
+ sk_format = {"text": text, "ttl": 60}
95
+ elsif scheme==1
96
+ sk_format = {"text": text, "ttl": 60, "caption": button_text, "action": button_url}
97
+ elsif scheme==2
98
+ sk_format = {"text": text, "ttl": 60, "caption": button_text, "action": button_url, "img": image}
99
+ elsif scheme==3
100
+ sk_format = {"img": image, "ttl": 60}
101
+ else
102
+ nil
103
+ end
104
+
105
+ p sk_format
106
+
107
+ output_answer ={:code => 200, :result => "Success", :body => {:to_sk_format => sk_format, :button_url => button_url, :image => image, :button_text => button_text, :text => text, :scheme => scheme, :scheme_dic => scheme_dic[scheme]}}
108
+ rescue
109
+ output_answer ={:code => 507, :result => "dabrabyt_text_field_parse: Unknown error"}
110
+ end
111
+ output_answer
112
+ end
113
+
114
+
3
115
  def num_formatter(infobip_msisdn, extra_id)
4
116
  #[{"to"=>{"phoneNumber"=>"375297116638", "emailAddress"=>nil}}]
5
117
  # [{"phone_number": 375298766719}, {"phone_number": 375295730878}]
@@ -50,20 +162,20 @@ class Dabrab
50
162
  status1 = {}
51
163
  if a["processed"] == true && a["accepted"] == true
52
164
  status1 = {"to": {"phoneNumber": a["phone_number"]},
53
- "status": {"groupId": 1,
54
- "groupName": "PENDING",
55
- "id": 26,
56
- "name": "MESSAGE_ACCEPTED",
57
- "description": "Message sent to next instance"},
58
- "messageId": a["message_id"]}
165
+ "status": {"groupId": 1,
166
+ "groupName": "PENDING",
167
+ "id": 26,
168
+ "name": "MESSAGE_ACCEPTED",
169
+ "description": "Message sent to next instance"},
170
+ "messageId": a["message_id"]}
59
171
  else
60
172
  status1 = {"to": {"phoneNumber": a["phone_number"]},
61
- "status": {"groupId": 5,
62
- "groupName": "REJECTED",
63
- "id": 21,
64
- "name": "REJECTED_SYSTEM_ERROR",
65
- "description": "Unknown error"},
66
- "messageId": a["message_id"]}
173
+ "status": {"groupId": 5,
174
+ "groupName": "REJECTED",
175
+ "id": 21,
176
+ "name": "REJECTED_SYSTEM_ERROR",
177
+ "description": "Unknown error"},
178
+ "messageId": a["message_id"]}
67
179
  end
68
180
 
69
181
  messages_sect.append(status1)
@@ -0,0 +1,140 @@
1
+ $LOAD_PATH.unshift File.expand_path("../projects/ukaz60", __dir__)
2
+
3
+ require 'json'
4
+
5
+ require 'imperituroard/projects/ukaz60/belgim'
6
+ require 'imperituroard/projects/ukaz60/fortigate'
7
+ require 'imperituroard/projects/ukaz60/staros'
8
+
9
+ class Ukaz60All_2
10
+
11
+ attr_accessor :telegram_messanger,
12
+ :belgim_login,
13
+ :belgim_password,
14
+ :belgim_url,
15
+ :ukaz60_add_func,
16
+ :belgim_connector,
17
+ :forti_connector,
18
+ :staros_connector
19
+
20
+ def initialize(telegram_api_url,
21
+ telegram_chat_id,
22
+ belgim_login,
23
+ belgim_password,
24
+ belgim_url,
25
+ ansible_tmp_folder,
26
+ local_tmp_directory,
27
+ ansible_ssh_user,
28
+ ansible_ssh_password,
29
+ ansible_host,
30
+ url_backup_dir,
31
+ staros_login,
32
+ staros_password,
33
+ ukaz60_http_groups,
34
+ ukaz60_https_groups,
35
+ staros_hosts
36
+
37
+ )
38
+ @telegram_messanger = Telegram_2.new(telegram_api_url, telegram_chat_id)
39
+ @belgim_login = belgim_login
40
+ @belgim_password = belgim_password
41
+ @belgim_url = belgim_url
42
+ @ukaz60_add_func = AddFuncUkaz60_2.new
43
+ @belgim_connector = Belgim_2.new(telegram_api_url, telegram_chat_id, belgim_login, belgim_password, belgim_url)
44
+ @forti_connector = FortiUkaz60_2.new(ansible_tmp_folder, local_tmp_directory, ansible_ssh_user, ansible_ssh_password, ansible_host, url_backup_dir)
45
+ @staros_connector = Ukaz60Staros_2.new(staros_login, staros_password, ukaz60_http_groups, ukaz60_https_groups, staros_hosts)
46
+
47
+ end
48
+
49
+ def forti_process(get_belgim_data)
50
+ forti_answer = {}
51
+ begin
52
+ format_for_forti = forti_connector.prepare_url_config_fortigate(get_belgim_data)
53
+ if format_for_forti[:code] == 200
54
+ url_uploading = forti_connector.upload_url(format_for_forti[:body][:to_fortigate])
55
+ if url_uploading[:code] == 200
56
+ #update_fortigate_ansible = forti_connector.update_weburl_fortigate
57
+ update_fortigate_ansible = forti_connector.update_weburl_fortimanager
58
+ if update_fortigate_ansible[:code] == 200
59
+ forti_answer = {:code => 200, :result => "Fortigate processed", :data => update_fortigate_ansible[:body][:body], :num_uploaded_to_forti => format_for_forti[:body][:num_list]}
60
+ else
61
+ forti_answer = {:code => update_fortigate_ansible[:code], :result => update_fortigate_ansible[:result]}
62
+ end
63
+ #forti_connector.clean_tmp_folders
64
+ else
65
+ forti_answer = {:code => 401, :result => "Failed for uploading data to ansible server"}
66
+ end
67
+ else
68
+ forti_answer = {:code => 400, :result => "Error while processing data"}
69
+ end
70
+ rescue
71
+ forti_answer = {:code => 507, :result => "Unknown error with Forti"}
72
+ end
73
+ forti_answer
74
+ end
75
+
76
+ def staros_process(get_belgim_data)
77
+
78
+ output_starprocess = {}
79
+
80
+ begin
81
+ #get data from staros
82
+ staros_blocks_current = staros_connector.get_all_staros_ukaz60
83
+
84
+ if staros_blocks_current[:code] == 200
85
+ #compare data with belgim
86
+ answ = ukaz60_add_func.staros_compare_http(staros_blocks_current, get_belgim_data)
87
+
88
+ if answ[:code] == 200
89
+ #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]}}
90
+ output_starprocess = ukaz60_add_func.format_star_processed_answ(answ)[:body][:to_message]
91
+ else
92
+ output_starprocess = answ
93
+ end
94
+
95
+ else
96
+ output_starprocess = staros_blocks_current
97
+ end
98
+ rescue
99
+ output_starprocess = {:code => 507, :result => "staros_process: Something wrong"}
100
+ end
101
+
102
+ output_starprocess
103
+ end
104
+
105
+ def no_pasaran
106
+
107
+ answer_output = {}
108
+ forti_answer = {}
109
+ staros_answer = {}
110
+
111
+ begin
112
+ get_belgim_data = belgim_connector.belgim_ukaz60_get
113
+ p get_belgim_data
114
+
115
+ if get_belgim_data[:code] == 200
116
+
117
+ thr_forti = Thread.new do
118
+ forti_answer = self.forti_process(get_belgim_data)
119
+ end
120
+
121
+ thr_staros = Thread.new do
122
+ staros_answer = staros_process(get_belgim_data)
123
+ end
124
+
125
+ thr_staros.join
126
+ thr_forti.join
127
+
128
+ answer_output = {:code => 200, :result => "No pasaran", :fortigate => forti_answer, :staros => staros_answer, :info_belgim => get_belgim_data[:number]}
129
+ else
130
+ answer_output = {:code => 404, :result => "Failed to receive data from Belgim"}
131
+ end
132
+
133
+ rescue
134
+ answer_output = {:code => 507, :result => "no_pasaran: Unknown SDK error"}
135
+ end
136
+ telegram_messanger.telegram_message(JSON.pretty_generate(answer_output))
137
+ answer_output
138
+ end
139
+
140
+ end
@@ -0,0 +1,221 @@
1
+ require 'imperituroard/platforms/public/telegram'
2
+ require 'imperituroard/projects/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
+ https_parsed = []
49
+ url_all = []
50
+
51
+ f2 =[]
52
+ results = {}
53
+
54
+ # Get data from Belgim site by curl
55
+ curl_belgie_command = "curl -d \"name=#{belgim_login}&pass=#{belgim_password}\" -H \"Content-Type: application/x-www-form-urlencoded\" -X POST #{belgim_url} --insecure"
56
+ #return_from_belgim = `curl -d "name=#{belgim_login}&pass=#{belgim_password}" -H "Content-Type: application/x-www-form-urlencoded" -X POST #{belgim_url} --insecure`
57
+ return_from_belgim = `#{curl_belgie_command}`
58
+ p curl_belgie_command
59
+
60
+ return_from_belgim = return_from_belgim.gsub!("\n", "")
61
+
62
+ #parse Belgim file by regexpression
63
+ # and split by 3 categories: url, dns, ip
64
+ belgim_domains = return_from_belgim.scan(regexp_redns)
65
+ belgim_urls = return_from_belgim.scan(regexp_reurl)
66
+ belgim_ips = return_from_belgim.scan(regexp_reip)
67
+
68
+ #process only domains.
69
+ for i in belgim_domains
70
+ a1 = i[0]
71
+ elem = a1.gsub("</", "")
72
+
73
+ if elem.include? " "
74
+ elem = elem.gsub(" ", "")
75
+ end
76
+
77
+ if elem.match(/а|б|в|г|д|е|ж|ё|Ё|з|и|й|к|л|м|н|о|п|р|с|т|у|ф|х|ц|ч|ш|щ|ь|ы|ъ|э|ю|я|А|Б|В|Г|Д|Е|Ж|З|И|Й|К|Л|М|Н|О|П|Р|С|Т|У|Ф|Х|Ц|Ч|Ш|Щ|Ь|Ы|Ъ|Э|Ю|Я/)
78
+ elem = SimpleIDN.to_ascii(elem)
79
+ end
80
+
81
+ if elem != "-" && elem != ""
82
+ domain_parsed.push(elem)
83
+ if_www = elem[0]+elem[1]+elem[2]+elem[3]
84
+
85
+ #if not contain www - add domain with www
86
+ if if_www != "www."
87
+ domain_parsed.push("www."+elem)
88
+ end
89
+
90
+ #if contain www - add domain without www
91
+ if if_www == "www."
92
+ gar = elem[4..elem.length]
93
+ domain_parsed.push(gar)
94
+ end
95
+ end
96
+ end
97
+
98
+ #process only urls
99
+ for s in belgim_urls
100
+
101
+ #process every domain. Find if https or http and domain
102
+ func_processed = ukaz60_add_func.delete_dump_symbols_url(s[0])
103
+
104
+ if func_processed[:code] == 200
105
+ processed_url = func_processed[:domain_only]
106
+ processed_domain_in_url = func_processed[:processed_domain_in_url]
107
+
108
+ if func_processed[:type] == "domain"
109
+ domain_parsed.push(processed_url)
110
+ check_if_www = processed_url[0]+processed_url[1]+processed_url[2]+processed_url[3]
111
+
112
+ #if not contains www then add with www too
113
+ if check_if_www != "www."
114
+ domain_parsed.push("www."+processed_url)
115
+ end
116
+
117
+ #if contains www then add without www too
118
+ if check_if_www == "www."
119
+ gar2domain = processed_url[4..processed_url.length]
120
+ domain_parsed.push(gar2domain)
121
+ end
122
+ elsif func_processed[:type] == "url" && func_processed[:protocol] != "https"
123
+ #p "Step4 processed_domain_in_url: #{processed_domain_in_url}"
124
+ #p "Step5 func_processed: #{func_processed.to_s}"
125
+
126
+ url_parsed.push(func_processed[:protocol] + "://" + processed_domain_in_url)
127
+ check_if_www2 = processed_domain_in_url[0]+processed_domain_in_url[1]+processed_domain_in_url[2]+processed_domain_in_url[3]
128
+ if check_if_www2 != "www."
129
+ url_parsed.push(func_processed[:protocol] + "://" + "www."+processed_domain_in_url)
130
+ end
131
+ if check_if_www2 == "www."
132
+ gar1url = processed_domain_in_url[4..processed_domain_in_url.length]
133
+ url_parsed.push(func_processed[:protocol] + "://" + gar1url)
134
+ end
135
+ elsif func_processed[:protocol] == "https"
136
+ #additional section for https urls
137
+ https_parsed.push(func_processed[:protocol] + "://" + processed_domain_in_url)
138
+ check_if_www2https = processed_domain_in_url[0]+processed_domain_in_url[1]+processed_domain_in_url[2]+processed_domain_in_url[3]
139
+ if check_if_www2https != "www."
140
+ https_parsed.push(func_processed[:protocol] + "://" + "www."+processed_domain_in_url)
141
+ end
142
+ if check_if_www2https == "www."
143
+ gar1url_https = processed_domain_in_url[4..processed_domain_in_url.length]
144
+ https_parsed.push(func_processed[:protocol] + "://" + gar1url_https)
145
+ end
146
+ end
147
+ end
148
+ end
149
+
150
+ #process only IPs
151
+ for f in belgim_ips
152
+
153
+ a2ip = f[0]
154
+
155
+ if a2ip.include? " "
156
+ a2ip = a2ip.gsub(" ", "")
157
+ end
158
+
159
+ elem_ip = a2ip.gsub("</", "")
160
+
161
+ if elem_ip != "-" && elem_ip != ""
162
+ if elem_ip.include?(":")
163
+ ipv6_parsed.push(elem_ip)
164
+ else
165
+ ipv4_parsed.push(elem_ip)
166
+ end
167
+ end
168
+ end
169
+
170
+ domain_parsed = domain_parsed.uniq
171
+ url_parsed = url_parsed.uniq
172
+ ipv6_parsed = ipv6_parsed.uniq
173
+ ipv4_parsed = ipv4_parsed.uniq
174
+ https_parsed = https_parsed.uniq
175
+
176
+ https_parsed_tmmp = []
177
+ https_parsed.each do |tmp_tmp|
178
+ https_parsed_tmmp.push(tmp_tmp.gsub("https://", "http://"))
179
+ end
180
+ url_all = https_parsed_tmmp + url_parsed
181
+ url_all = url_all.uniq
182
+ url_all_num = url_all.length
183
+
184
+
185
+ dns_num = domain_parsed.length
186
+ ipv4_num = ipv4_parsed.length
187
+ ipv6_num = ipv6_parsed.length
188
+ url_num = url_parsed.length
189
+ https_num = https_parsed.length
190
+
191
+ all_num = dns_num + ipv4_num + ipv6_num + url_num + https_num
192
+
193
+
194
+
195
+ output_data = {:code => 200,
196
+ :result => "Request completed successfully",
197
+ :number => {:domain_num => dns_num,
198
+ :url_http_num => url_num,
199
+ :ipv4_num => ipv4_num,
200
+ :ipv6_num => ipv6_num,
201
+ :url_https_num => https_num,
202
+ :url_all_num => url_all_num,
203
+ :all_num => all_num
204
+ },
205
+ :domains_for_block => domain_parsed,
206
+ :url_for_block => url_parsed,
207
+ :ipv6_parsed => ipv6_parsed,
208
+ :ipv4_parsed => ipv4_parsed,
209
+ :https_parsed => https_parsed,
210
+ :url_all => url_all
211
+ }
212
+
213
+ rescue
214
+ output_data = {:code => 507, :result => "belgim_ukaz60_get: Unknown error"}
215
+ end
216
+ output_data
217
+
218
+ end
219
+
220
+
221
+ end