Class: Mnemosyne
- Inherits:
-
Object
- Object
- Mnemosyne
- Defined in:
- lib/mnemosyne.rb
Defined Under Namespace
Classes: DomainGenerator, Logger, WebPageSnapshot
Class Method Summary collapse
Class Method Details
.run ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 |
# File 'lib/mnemosyne.rb', line 6 def self.run processed_arguments = {} processed_arguments['arg_random'] = ARGV.include?('-r') processed_arguments['arg_force'] = ARGV.include?('--force') log_levels_arg = ARGV.find { |arg| arg.start_with?('--log-levels=') } processed_arguments['arg_log_levels'] = log_levels_arg ? log_levels_arg.split('=')[1] : ["info", "success", "error", "warn"] count = ARGV.find { |arg| arg.start_with?('--count=') } processed_arguments['arg_count'] = count ? count.split('=')[1].to_i : 1 domain_end = ARGV.find { |arg| arg.start_with?('--end=') } processed_arguments['arg_end'] = domain_end ? domain_end.split('=')[1] : '.net' domain_length = ARGV.find { |arg| arg.start_with?('--length=') } processed_arguments['arg_length'] = domain_length ? domain_length.split('=')[1].to_i : 7 regex_pattern = ARGV.find { |arg| arg.start_with?('--regex=') } processed_arguments['arg_regex'] = regex_pattern ? Regexp.new(regex_pattern.split('=')[1]) : nil processed_arguments['arg_r'] = ARGV.include?('-r') if processed_arguments['arg_r'] generated_count = 0 logger = Logger.new(processed_arguments['arg_log_levels']) web_page_snapshot = WebPageSnapshot.new while generated_count < processed_arguments['arg_count'] if processed_arguments['arg_regex'] domain = DomainGenerator.generate_with_regex(processed_arguments['arg_regex'], processed_arguments['arg_end']) else domain = DomainGenerator.generate(processed_arguments['arg_length'], processed_arguments['arg_end']) end logger.log("Сгенерированный домен: #{domain}") begin filename = web_page_snapshot.take_snapshot(domain) if filename if processed_arguments['arg_force'] generated_count += 1 end logger.log("Успешно: Скриншот #{domain} сохранен как #{filename}", :success) else logger.log("Ошибка: Не удалось загрузить #{domain}", :error) end rescue StandardError => e logger.log("Исключение: #{e.} для #{domain}", :error) end if !processed_arguments['arg_force'] generated_count += 1 end logger.log("Осталось попыток: #{processed_arguments['arg_count'] - generated_count}", :warn) end web_page_snapshot.close logger.log("Завершение работы.", :success) else puts "Использование: mnemosyne -r [--count=N] [--length=L] [--regex=R] [--end=domain_end]" end end |