smart_proxy_openscap 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +41 -0
- data/.rubocop_todo.yml +111 -0
- data/.travis.yml +14 -0
- data/COPYING +674 -0
- data/Gemfile +14 -0
- data/README.md +107 -0
- data/Rakefile +16 -0
- data/bin/smart-proxy-arf-html +7 -0
- data/bin/smart-proxy-arf-json +7 -0
- data/bin/smart-proxy-openscap-send +61 -0
- data/bin/smart-proxy-policy-guide +7 -0
- data/bin/smart-proxy-scap-profiles +7 -0
- data/bin/smart-proxy-scap-validation +7 -0
- data/bundler.d/openscap.rb +6 -0
- data/extra/rubygem-smart_proxy_openscap.spec +101 -0
- data/extra/smart-proxy-openscap-send.cron +2 -0
- data/lib/smart_proxy_openscap.rb +14 -0
- data/lib/smart_proxy_openscap/arf_html.rb +22 -0
- data/lib/smart_proxy_openscap/arf_json.rb +114 -0
- data/lib/smart_proxy_openscap/arf_parser.rb +39 -0
- data/lib/smart_proxy_openscap/content_parser.rb +30 -0
- data/lib/smart_proxy_openscap/fetch_file.rb +60 -0
- data/lib/smart_proxy_openscap/fetch_scap_content.rb +17 -0
- data/lib/smart_proxy_openscap/fetch_tailoring_file.rb +17 -0
- data/lib/smart_proxy_openscap/foreman_forwarder.rb +40 -0
- data/lib/smart_proxy_openscap/http_config.ru +20 -0
- data/lib/smart_proxy_openscap/openscap_api.rb +187 -0
- data/lib/smart_proxy_openscap/openscap_exception.rb +9 -0
- data/lib/smart_proxy_openscap/openscap_html_generator.rb +38 -0
- data/lib/smart_proxy_openscap/openscap_import_api.rb +32 -0
- data/lib/smart_proxy_openscap/openscap_lib.rb +67 -0
- data/lib/smart_proxy_openscap/openscap_plugin.rb +27 -0
- data/lib/smart_proxy_openscap/policy_guide.rb +23 -0
- data/lib/smart_proxy_openscap/policy_parser.rb +33 -0
- data/lib/smart_proxy_openscap/profiles_parser.rb +32 -0
- data/lib/smart_proxy_openscap/scap_profiles.rb +52 -0
- data/lib/smart_proxy_openscap/scap_validation.rb +35 -0
- data/lib/smart_proxy_openscap/shell_wrapper.rb +77 -0
- data/lib/smart_proxy_openscap/spool_forwarder.rb +79 -0
- data/lib/smart_proxy_openscap/storage.rb +47 -0
- data/lib/smart_proxy_openscap/storage_fs.rb +102 -0
- data/lib/smart_proxy_openscap/version.rb +15 -0
- data/settings.d/openscap.yml.example +33 -0
- data/smart_proxy_openscap.gemspec +23 -0
- data/test/data/arf_report +0 -0
- data/test/data/corrupted_arf_report +0 -0
- data/test/data/spool/cleanup_spool/arf/2c101b95-033f-4b15-b490-f50bf9090dae/1/1484313035/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1 +0 -0
- data/test/data/spool/cleanup_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484309984/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1 +0 -0
- data/test/data/spool/corrupted_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484309984/a4dfba5db27b21795e6fa401b8dce7a70faeb25b7963891f07f6f4baaf052afb +0 -0
- data/test/data/spool/corrupted_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484313035/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1 +0 -0
- data/test/data/spool/valid_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484309984/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1 +0 -0
- data/test/data/spool/valid_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484313035/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1 +0 -0
- data/test/data/ssg-rhel7-ds.xml +20271 -0
- data/test/data/tailoring.xml +31 -0
- data/test/fetch_scap_api_test.rb +73 -0
- data/test/fetch_tailoring_api_test.rb +37 -0
- data/test/get_report_xml_html_test.rb +58 -0
- data/test/post_report_api_test.rb +86 -0
- data/test/scap_content_parser_api_test.rb +69 -0
- data/test/script_class_test.rb +96 -0
- data/test/spool_forwarder_test.rb +84 -0
- data/test/test_helper.rb +13 -0
- metadata +180 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'smart_proxy_openscap/shell_wrapper'
|
2
|
+
|
3
|
+
module Proxy
|
4
|
+
module OpenSCAP
|
5
|
+
class ArfParser < ShellWrapper
|
6
|
+
|
7
|
+
def initialize(cname, policy_id, date)
|
8
|
+
@cname = cname
|
9
|
+
@policy_id = policy_id
|
10
|
+
@date = date
|
11
|
+
@script_name = 'smart-proxy-arf-json'
|
12
|
+
end
|
13
|
+
|
14
|
+
def as_json(arf_data)
|
15
|
+
execute_shell_command arf_data
|
16
|
+
end
|
17
|
+
|
18
|
+
def in_filename
|
19
|
+
"#{super}-#{@cname}-#{@policy_id}-#{@date}-"
|
20
|
+
end
|
21
|
+
|
22
|
+
def out_filename
|
23
|
+
"#{in_filename}json-"
|
24
|
+
end
|
25
|
+
|
26
|
+
def failure_message
|
27
|
+
"Failure when running script which parses reports"
|
28
|
+
end
|
29
|
+
|
30
|
+
def command(in_file, out_file)
|
31
|
+
"#{script_location} " <<
|
32
|
+
"#{in_file.path} " <<
|
33
|
+
"#{out_file.path} " <<
|
34
|
+
"#{Proxy::OpenSCAP::Plugin.settings.registered_proxy_name} " <<
|
35
|
+
"#{Proxy::OpenSCAP::Plugin.settings.registered_proxy_url}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'smart_proxy_openscap/shell_wrapper'
|
2
|
+
|
3
|
+
module Proxy::OpenSCAP
|
4
|
+
class ContentParser < ShellWrapper
|
5
|
+
def initialize(type)
|
6
|
+
@type = type
|
7
|
+
@script_name = 'smart-proxy-scap-validation'
|
8
|
+
end
|
9
|
+
|
10
|
+
def validate(scap_file)
|
11
|
+
execute_shell_command scap_file
|
12
|
+
end
|
13
|
+
|
14
|
+
def out_filename
|
15
|
+
"#{in_filename}json-"
|
16
|
+
end
|
17
|
+
|
18
|
+
def in_filename
|
19
|
+
"#{super}-#{@type}-validate-"
|
20
|
+
end
|
21
|
+
|
22
|
+
def failure_message
|
23
|
+
"Failure when running script which validates scap files"
|
24
|
+
end
|
25
|
+
|
26
|
+
def command(in_file, out_file)
|
27
|
+
"#{script_location} #{in_file.path} #{out_file.path} #{@type}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Proxy::OpenSCAP
|
2
|
+
class FetchFile
|
3
|
+
include ::Proxy::Log
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def create_store_dir(store_dir)
|
8
|
+
logger.info "Creating directory to store SCAP file: #{store_dir}"
|
9
|
+
FileUtils.mkdir_p(store_dir) # will fail silently if exists
|
10
|
+
rescue Errno::EACCES => e
|
11
|
+
logger.error "No permission to create directory #{store_dir}"
|
12
|
+
raise e
|
13
|
+
rescue StandardError => e
|
14
|
+
logger.error "Could not create '#{store_dir}' directory: #{e.message}"
|
15
|
+
raise e
|
16
|
+
end
|
17
|
+
|
18
|
+
def policy_content_file(policy_scap_file)
|
19
|
+
return nil if !File.file?(policy_scap_file) || File.zero?(policy_scap_file)
|
20
|
+
File.open(policy_scap_file, 'rb').read
|
21
|
+
end
|
22
|
+
|
23
|
+
def clean_store_folder(policy_store_dir)
|
24
|
+
FileUtils.rm_f Dir["#{policy_store_dir}/*.xml"]
|
25
|
+
end
|
26
|
+
|
27
|
+
def save_or_serve_scap_file(policy_scap_file, file_download_path)
|
28
|
+
lock = Proxy::FileLock::try_locking(policy_scap_file)
|
29
|
+
response = fetch_scap_content_xml(file_download_path)
|
30
|
+
if lock.nil?
|
31
|
+
return response
|
32
|
+
else
|
33
|
+
begin
|
34
|
+
File.open(policy_scap_file, 'wb') do |file|
|
35
|
+
file << response
|
36
|
+
end
|
37
|
+
ensure
|
38
|
+
Proxy::FileLock::unlock(lock)
|
39
|
+
end
|
40
|
+
scap_file = policy_content_file(policy_scap_file)
|
41
|
+
raise FileNotFound if scap_file.nil?
|
42
|
+
return scap_file
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def fetch_scap_content_xml(file_download_path)
|
47
|
+
foreman_request = Proxy::HttpRequest::ForemanRequest.new
|
48
|
+
req = foreman_request.request_factory.create_get(file_download_path)
|
49
|
+
timeout = Proxy::OpenSCAP::Plugin.settings.timeout
|
50
|
+
foreman_request.http.read_timeout = timeout if timeout
|
51
|
+
response = foreman_request.send_request(req)
|
52
|
+
response.value
|
53
|
+
response.body
|
54
|
+
end
|
55
|
+
|
56
|
+
def clean_store_folder(policy_store_dir)
|
57
|
+
FileUtils.rm_f Dir["#{policy_store_dir}/*.xml"]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'smart_proxy_openscap/fetch_file'
|
2
|
+
|
3
|
+
module Proxy::OpenSCAP
|
4
|
+
class FetchScapContent < FetchFile
|
5
|
+
def get_policy_content(policy_id, digest)
|
6
|
+
policy_store_dir = File.join(Proxy::OpenSCAP.fullpath(Proxy::OpenSCAP::Plugin.settings.contentdir), policy_id.to_s)
|
7
|
+
policy_scap_file = File.join(policy_store_dir, "#{policy_id}_#{digest}.xml")
|
8
|
+
file_download_path = "api/v2/compliance/policies/#{policy_id}/content"
|
9
|
+
|
10
|
+
create_store_dir policy_store_dir
|
11
|
+
|
12
|
+
scap_file = policy_content_file(policy_scap_file)
|
13
|
+
clean_store_folder(policy_store_dir) unless scap_file
|
14
|
+
scap_file ||= save_or_serve_scap_file(policy_scap_file, file_download_path)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'smart_proxy_openscap/fetch_file'
|
2
|
+
|
3
|
+
module Proxy::OpenSCAP
|
4
|
+
class FetchTailoringFile < FetchFile
|
5
|
+
def get_tailoring_file(policy_id, digest)
|
6
|
+
store_dir = File.join(Proxy::OpenSCAP.fullpath(Proxy::OpenSCAP::Plugin.settings.tailoring_dir), policy_id.to_s)
|
7
|
+
policy_tailoring_file = File.join(store_dir, "#{policy_id}_#{digest}.xml")
|
8
|
+
file_download_path = "api/v2/compliance/policies/#{policy_id}/tailoring"
|
9
|
+
|
10
|
+
create_store_dir store_dir
|
11
|
+
|
12
|
+
scap_file = policy_content_file(policy_tailoring_file)
|
13
|
+
clean_store_folder(store_dir) unless scap_file
|
14
|
+
scap_file ||= save_or_serve_scap_file(policy_tailoring_file, file_download_path)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'smart_proxy_openscap/openscap_exception'
|
2
|
+
|
3
|
+
module Proxy::OpenSCAP
|
4
|
+
class ForemanForwarder < Proxy::HttpRequest::ForemanRequest
|
5
|
+
include ::Proxy::Log
|
6
|
+
|
7
|
+
def post_arf_report(cname, policy_id, date, data, timeout)
|
8
|
+
begin
|
9
|
+
foreman_api_path = upload_path(cname, policy_id, date)
|
10
|
+
json = Proxy::OpenSCAP::ArfParser.new(cname, policy_id, date).as_json(data)
|
11
|
+
response = send_request(foreman_api_path, json, timeout)
|
12
|
+
# Raise an HTTP error if the response is not 2xx (success).
|
13
|
+
response.value
|
14
|
+
JSON.parse(response.body)
|
15
|
+
rescue Net::HTTPServerException => e
|
16
|
+
logger.debug "Received response: #{response.code} #{response.msg}"
|
17
|
+
logger.debug response.body
|
18
|
+
raise ReportUploadError, e.message if response.code.to_i == 422
|
19
|
+
raise e
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def upload_path(cname, policy_id, date)
|
26
|
+
"/api/v2/compliance/arf_reports/#{cname}/#{policy_id}/#{date}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def send_request(path, body, timeout)
|
30
|
+
# Override the parent method to set the right headers
|
31
|
+
path = [uri.path, path].join('/') unless uri.path.empty?
|
32
|
+
req = Net::HTTP::Post.new(URI.join(uri.to_s, path).path)
|
33
|
+
req.add_field('Accept', 'application/json,version=2')
|
34
|
+
req.content_type = 'application/json'
|
35
|
+
req.body = body
|
36
|
+
http.read_timeout = timeout if timeout
|
37
|
+
http.request(req)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014--2015 Red Hat Inc.
|
3
|
+
#
|
4
|
+
# This software is licensed to you under the GNU General Public License,
|
5
|
+
# version 3 (GPLv3). There is NO WARRANTY for this software, express or
|
6
|
+
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
+
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv3
|
8
|
+
# along with this software; if not, see http://www.gnu.org/licenses/gpl.txt
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'smart_proxy_openscap/openscap_api'
|
12
|
+
require 'smart_proxy_openscap/openscap_import_api'
|
13
|
+
|
14
|
+
map '/compliance' do
|
15
|
+
run Proxy::OpenSCAP::Api
|
16
|
+
end
|
17
|
+
|
18
|
+
map '/compliance-importer' do
|
19
|
+
run Proxy::OpenSCAP::ImportApi
|
20
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2014--2015 Red Hat Inc.
|
3
|
+
#
|
4
|
+
# This software is licensed to you under the GNU General Public License,
|
5
|
+
# version 3 (GPLv3). There is NO WARRANTY for this software, express or
|
6
|
+
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
7
|
+
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv3
|
8
|
+
# along with this software; if not, see http://www.gnu.org/licenses/gpl.txt
|
9
|
+
#
|
10
|
+
require 'smart_proxy_openscap/openscap_lib'
|
11
|
+
|
12
|
+
module Proxy::OpenSCAP
|
13
|
+
HTTP_ERRORS = [
|
14
|
+
EOFError,
|
15
|
+
Errno::ECONNRESET,
|
16
|
+
Errno::EINVAL,
|
17
|
+
Errno::ECONNREFUSED,
|
18
|
+
Net::HTTPBadResponse,
|
19
|
+
Net::HTTPHeaderSyntaxError,
|
20
|
+
Net::ProtocolError,
|
21
|
+
Timeout::Error
|
22
|
+
]
|
23
|
+
|
24
|
+
class Api < ::Sinatra::Base
|
25
|
+
include ::Proxy::Log
|
26
|
+
helpers ::Proxy::Helpers
|
27
|
+
authorize_with_ssl_client
|
28
|
+
|
29
|
+
post "/arf/:policy" do
|
30
|
+
# first let's verify client's certificate
|
31
|
+
begin
|
32
|
+
cn = Proxy::OpenSCAP::common_name request
|
33
|
+
rescue Proxy::Error::Unauthorized => e
|
34
|
+
log_halt 403, "Client authentication failed: #{e.message}"
|
35
|
+
end
|
36
|
+
date = Time.now.to_i
|
37
|
+
policy = params[:policy]
|
38
|
+
|
39
|
+
begin
|
40
|
+
post_to_foreman = ForemanForwarder.new.post_arf_report(cn, policy, date, request.body.string, Proxy::OpenSCAP::Plugin.settings.timeout)
|
41
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, cn, post_to_foreman['id'], date).store_archive(request.body.string)
|
42
|
+
post_to_foreman.to_json
|
43
|
+
rescue Proxy::OpenSCAP::StoreReportError => e
|
44
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.failed_dir, cn, post_to_foreman['id'], date).store_failed(request.body.string)
|
45
|
+
logger.error "Failed to save Report in reports directory (#{Proxy::OpenSCAP::Plugin.settings.reportsdir}). Failed with: #{e.message}.
|
46
|
+
Saving file in #{Proxy::OpenSCAP::Plugin.settings.failed_dir}. Please copy manually to #{Proxy::OpenSCAP::Plugin.settings.reportsdir}"
|
47
|
+
{ :result => 'Storage failure on proxy, see proxy logs for details' }.to_json
|
48
|
+
rescue Proxy::OpenSCAP::OpenSCAPException => e
|
49
|
+
error = "Failed to parse Arf Report, moving to #{Proxy::OpenSCAP::Plugin.settings.corrupted_dir}"
|
50
|
+
logger.error error
|
51
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.corrupted_dir, cn, policy, date).store_corrupted(request.body.string)
|
52
|
+
{ :result => (error << ' on proxy') }.to_json
|
53
|
+
rescue *HTTP_ERRORS => e
|
54
|
+
### If the upload to foreman fails then store it in the spooldir
|
55
|
+
msg = "Failed to upload to Foreman, saving in spool. Failed with: #{e.message}"
|
56
|
+
logger.error msg
|
57
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.spooldir, cn, policy, date).store_spool(request.body.string)
|
58
|
+
{ :result => msg }.to_json
|
59
|
+
rescue Proxy::OpenSCAP::StoreSpoolError => e
|
60
|
+
log_halt 500, e.message
|
61
|
+
rescue Proxy::OpenSCAP::ReportUploadError => e
|
62
|
+
{ :result => e.message }.to_json
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
get "/arf/:id/:cname/:date/:digest/xml" do
|
67
|
+
content_type 'application/x-bzip2'
|
68
|
+
begin
|
69
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date]).get_arf_xml(params[:digest])
|
70
|
+
rescue FileNotFound => e
|
71
|
+
log_halt 500, "Could not find requested file, #{e.message}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
delete "/arf/:id/:cname/:date/:digest" do
|
76
|
+
begin
|
77
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date]).delete_arf_file
|
78
|
+
rescue FileNotFound => e
|
79
|
+
logger.debug "Could not find requested file, #{e.message} - Assuming deleted"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
get "/arf/:id/:cname/:date/:digest/html" do
|
84
|
+
begin
|
85
|
+
Proxy::OpenSCAP::OpenscapHtmlGenerator.new(params[:cname], params[:id], params[:date], params[:digest]).get_html
|
86
|
+
rescue FileNotFound => e
|
87
|
+
log_halt 500, "Could not find requested file, #{e.message}"
|
88
|
+
rescue OpenSCAPException => e
|
89
|
+
log_halt 500, "Could not generate report in HTML"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
get "/policies/:policy_id/content/:digest" do
|
94
|
+
content_type 'application/xml'
|
95
|
+
begin
|
96
|
+
Proxy::OpenSCAP::FetchScapContent.new.get_policy_content(params[:policy_id], params[:digest])
|
97
|
+
rescue *HTTP_ERRORS => e
|
98
|
+
log_halt e.response.code.to_i, "File not found on Foreman. Wrong policy id?"
|
99
|
+
rescue StandardError => e
|
100
|
+
log_halt 500, "Error occurred: #{e.message}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
get "/policies/:policy_id/content" do
|
105
|
+
content_type 'application/xml'
|
106
|
+
logger.warn 'DEPRECATION WARNING: /policies/:policy_id/content/:digest should be used, please update foreman_openscap'
|
107
|
+
begin
|
108
|
+
Proxy::OpenSCAP::FetchScapContent.new.get_policy_content(params[:policy_id], 'scap_content')
|
109
|
+
rescue *HTTP_ERRORS => e
|
110
|
+
log_halt e.response.code.to_i, "File not found on Foreman. Wrong policy id?"
|
111
|
+
rescue StandardError => e
|
112
|
+
log_halt 500, "Error occurred: #{e.message}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
get "/policies/:policy_id/tailoring/:digest" do
|
117
|
+
content_type 'application/xml'
|
118
|
+
begin
|
119
|
+
Proxy::OpenSCAP::FetchTailoringFile.new.get_tailoring_file(params[:policy_id], params[:digest])
|
120
|
+
rescue *HTTP_ERRORS => e
|
121
|
+
log_halt e.response.code.to_i, "File not found on Foreman. Wrong policy id?"
|
122
|
+
rescue StandardError => e
|
123
|
+
log_halt 500, "Error occurred: #{e.message}"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
post "/scap_content/policies" do
|
128
|
+
begin
|
129
|
+
Proxy::OpenSCAP::ProfilesParser.new('scap_content').profiles(request.body.string)
|
130
|
+
rescue *HTTP_ERRORS => e
|
131
|
+
log_halt 500, e.message
|
132
|
+
rescue StandardError => e
|
133
|
+
log_halt 500, "Error occurred: #{e.message}"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
post "/tailoring_file/profiles" do
|
138
|
+
begin
|
139
|
+
Proxy::OpenSCAP::ProfilesParser.new('tailoring_file').profiles(request.body.string)
|
140
|
+
rescue *HTTP_ERRORS => e
|
141
|
+
log_halt 500, e.message
|
142
|
+
rescue StandardError => e
|
143
|
+
log_halt 500, "Error occurred: #{e.message}"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
post "/scap_file/validator/:type" do
|
148
|
+
validate_scap_file params
|
149
|
+
end
|
150
|
+
|
151
|
+
post "/scap_content/validator" do
|
152
|
+
logger.warn "DEPRECATION WARNING: '/scap_content/validator' will be removed in the future. Use '/scap_file/validator/scap_content' instead"
|
153
|
+
params[:type] = 'scap_content'
|
154
|
+
validate_scap_file params
|
155
|
+
end
|
156
|
+
|
157
|
+
post "/scap_content/guide/?:policy?" do
|
158
|
+
begin
|
159
|
+
Proxy::OpenSCAP::PolicyParser.new(params[:policy]).guide(request.body.string)
|
160
|
+
rescue *HTTP_ERRORS => e
|
161
|
+
log_halt 500, e.message
|
162
|
+
rescue StandardError => e
|
163
|
+
log_halt 500, "Error occurred: #{e.message}"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
get "/spool_errors" do
|
168
|
+
begin
|
169
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.corrupted_dir, nil, nil, nil).spool_errors.to_json
|
170
|
+
rescue StandardError => e
|
171
|
+
log_halt 500, "Error occurred: #{e.message}"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
private
|
176
|
+
|
177
|
+
def validate_scap_file(params)
|
178
|
+
begin
|
179
|
+
Proxy::OpenSCAP::ContentParser.new(params[:type]).validate(request.body.string)
|
180
|
+
rescue *HTTP_ERRORS => e
|
181
|
+
log_halt 500, e.message
|
182
|
+
rescue StandardError => e
|
183
|
+
log_halt 500, "Error occurred: #{e.message}"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Proxy::OpenSCAP
|
2
|
+
class OpenSCAPException < StandardError; end
|
3
|
+
class StoreReportError < StandardError; end
|
4
|
+
class StoreSpoolError < StandardError; end
|
5
|
+
class StoreFailedError < StandardError; end
|
6
|
+
class FileNotFound < StandardError; end
|
7
|
+
class StoreCorruptedError < StandardError; end
|
8
|
+
class ReportUploadError < StandardError; end
|
9
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'smart_proxy_openscap/storage_fs'
|
2
|
+
require 'smart_proxy_openscap/shell_wrapper'
|
3
|
+
|
4
|
+
module Proxy
|
5
|
+
module OpenSCAP
|
6
|
+
class OpenscapHtmlGenerator < ShellWrapper
|
7
|
+
def initialize(cname, id, date, digest)
|
8
|
+
@cname = cname
|
9
|
+
@id = id
|
10
|
+
@date = date
|
11
|
+
@digest = digest
|
12
|
+
@script_name = 'smart-proxy-arf-html'
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_html
|
16
|
+
execute_shell_command
|
17
|
+
end
|
18
|
+
|
19
|
+
def out_filename
|
20
|
+
"#{super}-#{@cname}-#{@id}-#{@date}-#{@digest}-"
|
21
|
+
end
|
22
|
+
|
23
|
+
def command(in_file, out_file)
|
24
|
+
"#{script_location} #{file_path_in_storage} #{out_file.path}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def failure_message
|
28
|
+
"Failure when running script which generates html reports"
|
29
|
+
end
|
30
|
+
|
31
|
+
def file_path_in_storage
|
32
|
+
path_to_dir = Proxy::OpenSCAP::Plugin.settings.reportsdir
|
33
|
+
storage = Proxy::OpenSCAP::StorageFS.new(path_to_dir, @cname, @id, @date)
|
34
|
+
storage.get_path(@digest)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|