Class: Dmarcurator::Cli::App

Inherits:
Object
  • Object
show all
Defined in:
lib/dmarcurator/cli/app.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_path:, reports_path: nil) ⇒ App

Returns a new instance of App.



53
54
55
56
# File 'lib/dmarcurator/cli/app.rb', line 53

def initialize(db_path:, reports_path: nil)
  @db_uri = "sqlite://#{File.expand_path(db_path)}"
  @reports_path = reports_path
end

Instance Attribute Details

#db_uriObject (readonly)

Returns the value of attribute db_uri.



7
8
9
# File 'lib/dmarcurator/cli/app.rb', line 7

def db_uri
  @db_uri
end

#reports_pathObject (readonly)

Returns the value of attribute reports_path.



7
8
9
# File 'lib/dmarcurator/cli/app.rb', line 7

def reports_path
  @reports_path
end

Class Method Details

.mainObject



9
10
11
12
# File 'lib/dmarcurator/cli/app.rb', line 9

def self.main
  params = parse_options(ARGV)
  new(params).run
end

.parse_options(options) ⇒ Object



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
# File 'lib/dmarcurator/cli/app.rb', line 14

def self.parse_options(options)
  params = {}

  opt_parser = OptionParser.new do |parser|
    parser.banner = "dmarcurator parses DMARC reports and stores them into an SQLite3 DB.\nIt can also serve a basic web UI for viewing reports (-ui=true).\nUsage: dmarcurator [options]"

    parser.on("-db", "--db-sqlite=SQLITE_DB", "[Required] Path to sqlite3 DB. (e.g. ./tmp/reports.sqlite)") do |value|
      params[:db_path] = value
    end

    parser.on("-rp", "--reports-path=REPORTS_PATH", "Path to directory containing DMARC reports. (e.g. ./tmp/reports/)") do |value|
      params[:reports_path] = value
    end

    parser.on("-h", "--help", "Halp pls") do
      puts parser
      exit 0
    end

    parser.on("-v", "--version", "Print version") do
      puts ::Dmarcurator::VERSION
      exit 0
    end

    if options.empty?
      puts parser
      exit 1
    end
  end

  opt_parser.parse!(options)
  if !params[:reports_path]
    puts "Dmarcurator can import DMARC reports into an sqlite3 database -> Set --db and --reports-path)"
    exit 0
  end

  params
end

Instance Method Details

#runObject



58
59
60
61
62
# File 'lib/dmarcurator/cli/app.rb', line 58

def run
  if reports_path
    ::Dmarcurator::ImportReports.new(db_uri: db_uri, reports_path: reports_path).run
  end
end