-
Notifications
You must be signed in to change notification settings - Fork 18
/
prometheus.rb
executable file
·119 lines (96 loc) · 2.57 KB
/
prometheus.rb
1
2
3
4
5
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
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
#!/usr/bin/env ruby
# Copyright 2012 Stephen Haywood aka AverageSecurityGuy
# All rights reserved see LICENSE file.
# Tell Ruby to look in the lib folder for include files
base = __FILE__
while File.symlink?(base)
base = File.expand_path(File.readlink(base), File.dirname(base))
end
$:.unshift(File.join(File.dirname(base), 'lib'))
$base_dir = File.dirname(base)
# Set the version number
version = '2.0.4'
# Setup optparse to handle command line arguments.
require 'optparse'
options = {}
optparse = OptionParser.new do |opts|
# Usage banner
opts.banner = "Usage: ./prometheus.rb -c config_file [options]"
# Firewall configuration file
options[:config] = ""
opts.on( '-c', '--config_file FILE', "Firewall configuration to parse." ) do|c|
options[:config] = c
end
# Report output file
options[:report] = nil
opts.on( '-r', '--report_file FILE', "Report file to write." ) do |r|
options[:report] = r
end
# Report format
options[:format] = "html"
opts.on( '-f', '--format FORMAT', "Report format to use." ) do |f|
options[:format] = f
end
# Report template
options[:template] = nil
opts.on( '-t', '--template FILE', "File to use as template." ) do |t|
options[:template] = t
end
# Verbose output
options[:verbose] = false
opts.on( '-v', '--verbose', "Print verbose output.") do |v|
options[:verbose] = true
end
# Debug output
options[:debug] = false
opts.on( '-d', '--debug', "Print debug output (very verbose).") do |d|
options[:debug] = true
end
# Display Version
options[:version] = false
opts.on( '-V', '--version', "Print version number.") do |ver|
options[:version] = true
end
# This displays the help screen.
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
optparse.parse!
# Begin main program
require 'common'
require 'parse'
require 'analyze'
require 'report'
include PrometheusErrors
include PrometheusUI
$verbose = options[:verbose]
$debug = options[:debug]
if options[:version]
print_line("Prometheus version #{version}")
exit(1)
end
print_status("Launching Prometheus version #{version}.")
config = open_config_file(options[:config])
# Parse the firewall config
begin
firewall = parse_firewall(config)
rescue ParseError => e
print_error(e.message)
exit(1)
end
# Analyze the firewall config
begin
analysis = analyze_firewall(firewall, config)
rescue AnalysisError => e
print_error(e.message)
exit(1)
end
#Create report for firewall config and analysis
begin
report_firewall(firewall, analysis, options[:report], options[:format], options[:template] )
rescue ReportError => e
print_error(e.message)
exit(1)
end