foreman_openscap 0.8.3 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/compliance/arf_reports_controller.rb +15 -6
- data/app/controllers/api/v2/compliance/policies_controller.rb +4 -2
- data/app/controllers/api/v2/compliance/scap_contents_controller.rb +3 -2
- data/app/controllers/api/v2/compliance/tailoring_files_controller.rb +3 -2
- data/app/controllers/arf_reports_controller.rb +4 -4
- data/app/controllers/policies_controller.rb +6 -5
- data/app/controllers/scap_contents_controller.rb +3 -3
- data/app/helpers/arf_report_dashboard_helper.rb +1 -1
- data/app/helpers/arf_reports_helper.rb +8 -8
- data/app/helpers/compliance_dashboard_helper.rb +0 -2
- data/app/helpers/compliance_hosts_helper.rb +7 -8
- data/app/helpers/policies_helper.rb +18 -18
- data/app/helpers/policy_dashboard_helper.rb +3 -3
- data/app/lib/proxy_api/available_proxy.rb +2 -2
- data/app/lib/proxy_api/openscap.rb +1 -1
- data/app/mailers/foreman_openscap/policy_mailer.rb +0 -2
- data/app/models/concerns/foreman_openscap/compliance_status_scoped_search.rb +7 -7
- data/app/models/concerns/foreman_openscap/data_stream_content.rb +1 -1
- data/app/models/concerns/foreman_openscap/host_extensions.rb +16 -6
- data/app/models/concerns/foreman_openscap/openscap_proxy_extensions.rb +1 -1
- data/app/models/foreman_openscap/arf_report.rb +5 -5
- data/app/models/foreman_openscap/policy.rb +6 -6
- data/app/models/foreman_openscap/scap_content.rb +2 -2
- data/app/models/foreman_openscap/tailoring_file.rb +1 -1
- data/app/services/foreman_openscap/arf_report_status_calculator.rb +0 -1
- data/app/services/foreman_openscap/host_report_dashboard/data.rb +2 -3
- data/app/services/foreman_openscap/openscap_proxy_version_check.rb +0 -1
- data/app/services/foreman_openscap/policy_dashboard/data.rb +7 -6
- data/app/services/foreman_openscap/report_dashboard/data.rb +1 -0
- data/app/views/api/v2/compliance/common/_loc.json.rabl +1 -1
- data/app/views/api/v2/compliance/common/_org.json.rabl +1 -1
- data/app/views/api/v2/compliance/policies/base.json.rabl +1 -1
- data/app/views/arf_reports/_list.html.erb +1 -1
- data/app/views/arf_reports/delete_multiple.html.erb +1 -1
- data/app/views/arf_reports/welcome.html.erb +12 -0
- data/app/views/compliance_hosts/show.html.erb +3 -1
- data/app/views/policy_dashboard/_policy_reports.html.erb +1 -1
- data/app/views/scap_contents/_list.html.erb +1 -1
- data/app/views/smart_proxies/_openscap_spool.html.erb +1 -1
- data/app/views/tailoring_files/_list.html.erb +1 -1
- data/config/routes.rb +9 -11
- data/db/migrate/20141015115511_add_arf_report_unique_constraint.rb +1 -1
- data/db/migrate/20141113221054_create_scaptimony_scap_content_profiles.rb +2 -3
- data/db/migrate/20141206211151_create_scaptimony_assets_policies.rb +1 -1
- data/db/migrate/20150115155947_add_scaptimony_scap_content_digest.rb +1 -1
- data/db/migrate/20150821100137_migrate_from_scaptimony.rb +1 -1
- data/db/migrate/20150929152345_move_arf_reports_to_reports_table.rb +0 -1
- data/db/migrate/20161223153249_add_permissions_to_arf_report.rb +2 -2
- data/db/migrate/20171016125613_add_content_title_unique_constraint.foreman_openscap.rb +6 -0
- data/lib/foreman_openscap/bulk_upload.rb +1 -1
- data/lib/foreman_openscap/engine.rb +54 -56
- data/lib/foreman_openscap/version.rb +1 -1
- data/lib/tasks/foreman_openscap_tasks.rake +11 -2
- data/locale/de/foreman_openscap.po +52 -13
- data/locale/en_GB/foreman_openscap.po +52 -13
- data/locale/es/foreman_openscap.po +52 -13
- data/locale/foreman_openscap.pot +140 -90
- data/locale/fr/foreman_openscap.po +52 -13
- data/locale/gl/foreman_openscap.po +52 -13
- data/locale/it/foreman_openscap.po +52 -13
- data/locale/ja/foreman_openscap.po +52 -13
- data/locale/ko/foreman_openscap.po +52 -13
- data/locale/pt_BR/foreman_openscap.po +52 -13
- data/locale/ru/foreman_openscap.po +52 -13
- data/locale/sv_SE/foreman_openscap.po +52 -13
- data/locale/zh_CN/foreman_openscap.po +52 -13
- data/locale/zh_TW/foreman_openscap.po +52 -13
- data/test/factories/arf_report_factory.rb +1 -1
- data/test/factories/asset_factory.rb +2 -2
- data/test/factories/compliance_host_factory.rb +2 -2
- data/test/factories/compliance_log_factory.rb +1 -1
- data/test/factories/policy_arf_report_factory.rb +1 -1
- data/test/factories/policy_factory.rb +3 -3
- data/test/factories/scap_content_related.rb +2 -2
- data/test/functional/api/v2/compliance/arf_reports_controller_test.rb +28 -9
- data/test/functional/api/v2/compliance/policies_controller_test.rb +16 -16
- data/test/functional/api/v2/compliance/scap_contents_controller_test.rb +8 -9
- data/test/functional/api/v2/compliance/tailoring_files_controller_test.rb +10 -11
- data/test/functional/arf_reports_controller_test.rb +4 -4
- data/test/functional/openscap_proxies_controller_test.rb +5 -3
- data/test/functional/tailoring_files_controller_test.rb +1 -1
- data/test/test_plugin_helper.rb +7 -7
- data/test/unit/arf_report_status_calculator_test.rb +0 -1
- data/test/unit/arf_report_test.rb +50 -50
- data/test/unit/compliance_status_test.rb +13 -13
- data/test/unit/concerns/host_extensions_test.rb +38 -22
- data/test/unit/concerns/openscap_proxy_extenstions_test.rb +5 -6
- data/test/unit/message_cleaner_test.rb +7 -7
- data/test/unit/openscap_host_test.rb +13 -13
- data/test/unit/policy_mailer_test.rb +12 -12
- data/test/unit/policy_test.rb +30 -30
- data/test/unit/scap_content_test.rb +4 -4
- data/test/unit/services/report_dashboard/data_test.rb +6 -6
- data/test/unit/services/tailoring_files_proxy_check_test.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3c549bddac8d76de26371740d282a226a08300f5
|
|
4
|
+
data.tar.gz: efb9f59e37b0b2bb7351f2ccd62e3dc3dab41aea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 07c6aa94f281c2a5617e92667fcb4dd85f4b2fce25ca8bd1fe7a1ed87facb618b75f019a8e9f82d2b8be61010ddf08ad69b4230d019ff90407bc745522e81f50
|
|
7
|
+
data.tar.gz: 4ff5e641877263dcd2792106893610c7183bb6d15d2b65772600722790475cd4b4d1b1480c5ba741f889310c329605eb8032ebc1e1136fb107a88419b0c3d9e2
|
|
@@ -3,7 +3,6 @@ require 'foreman_openscap/helper'
|
|
|
3
3
|
module Api
|
|
4
4
|
module V2
|
|
5
5
|
module Compliance
|
|
6
|
-
|
|
7
6
|
class ArfReportsController < V2::BaseController
|
|
8
7
|
include Api::Version2
|
|
9
8
|
include Foreman::Controller::SmartProxyAuth
|
|
@@ -19,7 +18,7 @@ module Api
|
|
|
19
18
|
end
|
|
20
19
|
|
|
21
20
|
def get_resource(message = 'no resource loaded')
|
|
22
|
-
instance_variable_get
|
|
21
|
+
instance_variable_get(:"@arf_report") || raise(message)
|
|
23
22
|
end
|
|
24
23
|
|
|
25
24
|
api :GET, '/compliance/arf_reports', N_('List ARF reports')
|
|
@@ -49,9 +48,13 @@ module Api
|
|
|
49
48
|
|
|
50
49
|
def create
|
|
51
50
|
asset = ForemanOpenscap::Helper::get_asset(params[:cname], params[:policy_id])
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
if asset.host.openscap_proxy
|
|
52
|
+
arf_report = ForemanOpenscap::ArfReport.create_arf(asset, params)
|
|
53
|
+
asset.host.refresh_statuses([HostStatus.find_status_by_humanized_name("compliance")])
|
|
54
|
+
render :json => { :result => :OK, :id => arf_report.id.to_s }
|
|
55
|
+
else
|
|
56
|
+
no_proxy_for_host asset
|
|
57
|
+
end
|
|
55
58
|
end
|
|
56
59
|
|
|
57
60
|
api :GET, "/compliance/arf_reports/:id/download/", N_("Download bzipped ARF report")
|
|
@@ -77,7 +80,7 @@ module Api
|
|
|
77
80
|
private
|
|
78
81
|
|
|
79
82
|
def find_resource
|
|
80
|
-
not_found
|
|
83
|
+
not_found && return if params[:id].blank?
|
|
81
84
|
instance_variable_set("@arf_report", resource_scope.find(params[:id]))
|
|
82
85
|
end
|
|
83
86
|
|
|
@@ -85,6 +88,12 @@ module Api
|
|
|
85
88
|
render_error 'standard_error', :status => :internal_error, :locals => { :exception => error }
|
|
86
89
|
end
|
|
87
90
|
|
|
91
|
+
def no_proxy_for_host(asset)
|
|
92
|
+
msg = _('Failed to upload Arf Report, no OpenSCAP proxy set for host %s') % asset.host.name
|
|
93
|
+
logger.error msg
|
|
94
|
+
render :json => { :result => msg }, :status => :unprocessable_entity
|
|
95
|
+
end
|
|
96
|
+
|
|
88
97
|
def action_permission
|
|
89
98
|
case params[:action]
|
|
90
99
|
when 'download', 'download_html'
|
|
@@ -15,7 +15,7 @@ module Api::V2
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def get_resource(message = 'no resource loaded')
|
|
18
|
-
instance_variable_get
|
|
18
|
+
instance_variable_get(:"@policy") || raise(message)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def policy_url(policy = nil)
|
|
@@ -46,6 +46,7 @@ module Api::V2
|
|
|
46
46
|
param :day_of_month, Integer, :desc => N_('Policy schedule day of month (only if period == "monthly")')
|
|
47
47
|
param :cron_line, String, :desc => N_('Policy schedule cron line (only if period == "custom")')
|
|
48
48
|
param :hostgroup_ids, Array, :desc => N_('Apply policy to host groups')
|
|
49
|
+
param :host_ids, Array, :desc => N_('Apply policy to hosts')
|
|
49
50
|
param :tailoring_file_id, Integer, :desc => N_('Tailoring file ID')
|
|
50
51
|
param :tailoring_file_profile_id, Integer, :desc => N_('Tailoring file profile ID')
|
|
51
52
|
param_group :taxonomies, ::Api::V2::BaseController
|
|
@@ -100,8 +101,9 @@ module Api::V2
|
|
|
100
101
|
end
|
|
101
102
|
|
|
102
103
|
private
|
|
104
|
+
|
|
103
105
|
def find_resource
|
|
104
|
-
not_found
|
|
106
|
+
not_found && return if params[:id].blank?
|
|
105
107
|
instance_variable_set("@policy", resource_scope.find(params[:id]))
|
|
106
108
|
end
|
|
107
109
|
|
|
@@ -9,7 +9,7 @@ module Api::V2
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def get_resource(message = 'no resource loaded')
|
|
12
|
-
instance_variable_get
|
|
12
|
+
instance_variable_get(:"@scap_content") || raise(message)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
api :GET, '/compliance/scap_contents', N_('List SCAP contents')
|
|
@@ -66,8 +66,9 @@ module Api::V2
|
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
private
|
|
69
|
+
|
|
69
70
|
def find_resource
|
|
70
|
-
not_found
|
|
71
|
+
not_found && return if params[:id].blank?
|
|
71
72
|
instance_variable_set("@scap_content", resource_scope.find(params[:id]))
|
|
72
73
|
end
|
|
73
74
|
|
|
@@ -10,7 +10,7 @@ module Api::V2
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def get_resource(message = 'no resource loaded')
|
|
13
|
-
instance_variable_get
|
|
13
|
+
instance_variable_get(:"@tailoring_file") || raise(message)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
api :GET, '/compliance/tailoring_files', N_('List Tailoring files')
|
|
@@ -67,8 +67,9 @@ module Api::V2
|
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
private
|
|
70
|
+
|
|
70
71
|
def find_resource
|
|
71
|
-
not_found
|
|
72
|
+
not_found && return if params[:id].blank?
|
|
72
73
|
instance_variable_set("@tailoring_file", resource_scope.find(params[:id]))
|
|
73
74
|
end
|
|
74
75
|
|
|
@@ -54,7 +54,7 @@ class ArfReportsController < ApplicationController
|
|
|
54
54
|
if @arf_report.destroy
|
|
55
55
|
process_success(:success_msg => _("Successfully deleted ARF report."), :success_redirect => arf_reports_path)
|
|
56
56
|
else
|
|
57
|
-
process_error(:error_msg => _("Failed to delete ARF Report for host %{host_name} reported at %{reported_at}") % {:host_name => @arf_report.host.name, :reported_at => @arf_report.reported_at})
|
|
57
|
+
process_error(:error_msg => _("Failed to delete ARF Report for host %{host_name} reported at %{reported_at}") % { :host_name => @arf_report.host.name, :reported_at => @arf_report.reported_at })
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
|
|
@@ -83,18 +83,18 @@ class ArfReportsController < ApplicationController
|
|
|
83
83
|
@arf_reports = ::ForemanOpenscap::ArfReport.where(:id => params[:arf_report_ids])
|
|
84
84
|
if @arf_reports.empty?
|
|
85
85
|
error _('No compliance reports were found.')
|
|
86
|
-
redirect_to(arf_reports_path)
|
|
86
|
+
redirect_to(arf_reports_path) && (return false)
|
|
87
87
|
end
|
|
88
88
|
else
|
|
89
89
|
error _('No compliance reports selected')
|
|
90
|
-
redirect_to(arf_reports_path)
|
|
90
|
+
redirect_to(arf_reports_path) && (return false)
|
|
91
91
|
end
|
|
92
92
|
return @arf_reports
|
|
93
93
|
rescue => e
|
|
94
94
|
error _("Something went wrong while selecting compliance reports - %s") % e
|
|
95
95
|
logger.debug e.message
|
|
96
96
|
logger.debug e.backtrace.join("\n")
|
|
97
|
-
redirect_to
|
|
97
|
+
redirect_to(arf_reports_path) && (return false)
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
def action_permission
|
|
@@ -35,7 +35,7 @@ class PoliciesController < ApplicationController
|
|
|
35
35
|
if @policy.wizard_completed? && @policy.save
|
|
36
36
|
process_success :success_redirect => policies_path
|
|
37
37
|
elsif @policy.valid?
|
|
38
|
-
render
|
|
38
|
+
render('new') && return
|
|
39
39
|
else
|
|
40
40
|
@policy.rewind_step
|
|
41
41
|
process_error :object => @policy
|
|
@@ -64,7 +64,7 @@ class PoliciesController < ApplicationController
|
|
|
64
64
|
def scap_content_selected
|
|
65
65
|
if params[:scap_content_id] && (@scap_content = ::ForemanOpenscap::ScapContent.find(params[:scap_content_id]))
|
|
66
66
|
@policy ||= ::ForemanOpenscap::Policy.new
|
|
67
|
-
render :partial => 'scap_content_results', :locals => {:policy => @policy}
|
|
67
|
+
render :partial => 'scap_content_results', :locals => { :policy => @policy }
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
@@ -104,6 +104,7 @@ class PoliciesController < ApplicationController
|
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
private
|
|
107
|
+
|
|
107
108
|
def find_by_id
|
|
108
109
|
@policy = resource_base.find(params[:id])
|
|
109
110
|
end
|
|
@@ -118,18 +119,18 @@ class PoliciesController < ApplicationController
|
|
|
118
119
|
@hosts = Host.where("id IN (?)", params[:host_ids])
|
|
119
120
|
if @hosts.empty?
|
|
120
121
|
error _('No hosts were found.')
|
|
121
|
-
redirect_to(hosts_path)
|
|
122
|
+
redirect_to(hosts_path) && (return false)
|
|
122
123
|
end
|
|
123
124
|
else
|
|
124
125
|
error _('No hosts selected')
|
|
125
|
-
redirect_to(hosts_path)
|
|
126
|
+
redirect_to(hosts_path) && (return false)
|
|
126
127
|
end
|
|
127
128
|
return @hosts
|
|
128
129
|
rescue => e
|
|
129
130
|
error _("Something went wrong while selecting hosts - %s") % e
|
|
130
131
|
logger.debug e.message
|
|
131
132
|
logger.debug e.backtrace.join("\n")
|
|
132
|
-
redirect_to
|
|
133
|
+
redirect_to(hosts_path) && (return false)
|
|
133
134
|
end
|
|
134
135
|
|
|
135
136
|
def action_permission
|
|
@@ -15,8 +15,8 @@ class ScapContentsController < ApplicationController
|
|
|
15
15
|
|
|
16
16
|
def show
|
|
17
17
|
send_data @scap_content.scap_file,
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
:type => 'application/xml',
|
|
19
|
+
:filename => @scap_content.original_filename
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def new
|
|
@@ -49,6 +49,7 @@ class ScapContentsController < ApplicationController
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
private
|
|
52
|
+
|
|
52
53
|
def find_by_id
|
|
53
54
|
@scap_content = resource_base.find(params[:id])
|
|
54
55
|
end
|
|
@@ -58,5 +59,4 @@ class ScapContentsController < ApplicationController
|
|
|
58
59
|
params[:scap_content][:original_filename] = scap_raw_file.original_filename
|
|
59
60
|
params[:scap_content][:scap_file] = scap_raw_file.tempfile.read if scap_raw_file.tempfile.respond_to?(:read)
|
|
60
61
|
end
|
|
61
|
-
|
|
62
62
|
end
|
|
@@ -10,7 +10,7 @@ module ArfReportDashboardHelper
|
|
|
10
10
|
[[:failed, _('Failed')],
|
|
11
11
|
[:passed, _('Passed')],
|
|
12
12
|
[:othered, _('Othered')],].each do |i|
|
|
13
|
-
data << {:label => i[1], :data => report[i[0]], :color => COLORS[i[0]]}
|
|
13
|
+
data << { :label => i[1], :data => report[i[0]], :color => COLORS[i[0]] }
|
|
14
14
|
end
|
|
15
15
|
flot_pie_chart 'overview', _('Compliance reports breakdown'), data, options
|
|
16
16
|
end
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
module ArfReportsHelper
|
|
2
2
|
def report_arf_column(event, style = "")
|
|
3
3
|
style = "label-default" if event == 0
|
|
4
|
-
content_tag(:span, event, :class=>'label ' + style)
|
|
4
|
+
content_tag(:span, event, :class => 'label ' + style)
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def show_logs
|
|
8
8
|
return if @arf_report.logs.empty?
|
|
9
9
|
form_tag arf_report_path(@arf_report), :id => 'level_filter', :method => :get, :class => "form form-horizontal" do
|
|
10
10
|
content_tag(:span, _("Show log messages:") + ' ') +
|
|
11
|
-
select(nil, 'level', [[_('All messages'), 'info'],[_('Failed and Othered'), 'warning'],[_('Failed only'), 'error']],
|
|
12
|
-
{}, {:class=>"col-md-1 form-control", :onchange =>"filter_by_level(this);"})
|
|
11
|
+
select(nil, 'level', [[_('All messages'), 'info'], [_('Failed and Othered'), 'warning'], [_('Failed only'), 'error']],
|
|
12
|
+
{}, { :class => "col-md-1 form-control", :onchange => "filter_by_level(this);" })
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
@@ -46,11 +46,11 @@ module ArfReportsHelper
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def multiple_actions_arf_report_select
|
|
49
|
-
select_action_button(_("Select Action"), {:id => 'submit_multiple'},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
select_action_button(_("Select Action"), { :id => 'submit_multiple' },
|
|
50
|
+
multiple_actions_arf_report.map do |action|
|
|
51
|
+
link_to_function(action[0], "buildArfModal(this, '#{action[1]}')",
|
|
52
|
+
:'data-dialog-title' => _("%s - The following compliance reports are about to be changed") % action[0])
|
|
53
|
+
end.flatten)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def openscap_proxy_link(arf_report)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
module ComplianceDashboardHelper
|
|
2
|
-
|
|
3
2
|
def latest_compliance_headers
|
|
4
3
|
string = "<th class='col-md-7'>#{_("Host")}</th>"
|
|
5
4
|
string += "<th class='col-md-3'>#{_("Policy")}</th>"
|
|
@@ -12,5 +11,4 @@ module ComplianceDashboardHelper
|
|
|
12
11
|
|
|
13
12
|
string.html_safe
|
|
14
13
|
end
|
|
15
|
-
|
|
16
14
|
end
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
module ComplianceHostsHelper
|
|
2
|
-
|
|
3
2
|
def host_policy_breakdown_chart(report, options = {})
|
|
4
3
|
data = []
|
|
5
4
|
[[:passed, _('Passed')],
|
|
6
5
|
[:failed, _('Failed')],
|
|
7
6
|
[:othered, _('Other')],].each do |i|
|
|
8
|
-
data << {:label => i[1], :data => report[i[0]], :color => ArfReportDashboardHelper::COLORS[i[0]]}
|
|
7
|
+
data << { :label => i[1], :data => report[i[0]], :color => ArfReportDashboardHelper::COLORS[i[0]] }
|
|
9
8
|
end
|
|
10
9
|
flot_pie_chart 'overview', _('Compliance reports breakdown'), data, options
|
|
11
10
|
end
|
|
@@ -15,12 +14,12 @@ module ComplianceHostsHelper
|
|
|
15
14
|
failed = []
|
|
16
15
|
othered = []
|
|
17
16
|
@host.arf_reports.of_policy(policy_id).each do |report|
|
|
18
|
-
passed << [report.created_at.to_i*1000, report.passed]
|
|
19
|
-
failed << [report.created_at.to_i*1000, report.failed]
|
|
20
|
-
othered << [report.created_at.to_i*1000, report.othered]
|
|
17
|
+
passed << [report.created_at.to_i * 1000, report.passed]
|
|
18
|
+
failed << [report.created_at.to_i * 1000, report.failed]
|
|
19
|
+
othered << [report.created_at.to_i * 1000, report.othered]
|
|
21
20
|
end
|
|
22
|
-
[{:label => _("Passed"), :data => passed, :color => ArfReportDashboardHelper::COLORS[:passed]},
|
|
23
|
-
{:label => _("Failed"), :data => failed, :color => ArfReportDashboardHelper::COLORS[:failed]},
|
|
24
|
-
{:label => _("Othered"), :data => othered, :color => ArfReportDashboardHelper::COLORS[:othered]}]
|
|
21
|
+
[{ :label => _("Passed"), :data => passed, :color => ArfReportDashboardHelper::COLORS[:passed] },
|
|
22
|
+
{ :label => _("Failed"), :data => failed, :color => ArfReportDashboardHelper::COLORS[:failed] },
|
|
23
|
+
{ :label => _("Othered"), :data => othered, :color => ArfReportDashboardHelper::COLORS[:othered] }]
|
|
25
24
|
end
|
|
26
25
|
end
|
|
@@ -17,32 +17,32 @@ module PoliciesHelper
|
|
|
17
17
|
scap_contents = ::ForemanOpenscap::ScapContent.authorized(:view_scap_contents).all
|
|
18
18
|
if scap_contents.length > 1
|
|
19
19
|
select_f form, :scap_content_id, scap_contents, :id, :title,
|
|
20
|
-
{:include_blank => _("Choose existing SCAP Content")},
|
|
21
|
-
{:label => _("SCAP Content"),
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
{ :include_blank => _("Choose existing SCAP Content") },
|
|
21
|
+
{ :label => _("SCAP Content"),
|
|
22
|
+
:onchange => 'scap_content_selected(this);',
|
|
23
|
+
:'data-url' => method_path('scap_content_selected') }
|
|
24
24
|
else
|
|
25
25
|
select_f form, :scap_content_id, scap_contents, :id, :title,
|
|
26
|
-
{:label => _("SCAP Content"),
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
{ :label => _("SCAP Content"),
|
|
27
|
+
:onchange => 'scap_content_selected(this);',
|
|
28
|
+
:'data-url' => method_path('scap_content_selected') }
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def scap_content_profile_selector(form)
|
|
33
33
|
if profiles_selection.length == 1
|
|
34
34
|
select_f form, :scap_content_profile_id, profiles_selection, :id, :title,
|
|
35
|
-
{:selected => @policy.scap_content_profile_id },
|
|
36
|
-
{:label => _("XCCDF Profile"),
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
{ :selected => @policy.scap_content_profile_id },
|
|
36
|
+
{ :label => _("XCCDF Profile"),
|
|
37
|
+
:disabled => profiles_selection.empty? ? true : false,
|
|
38
|
+
:help_inline => :indicator }
|
|
39
39
|
else
|
|
40
40
|
select_f form, :scap_content_profile_id, profiles_selection, :id, :title,
|
|
41
|
-
{:selected => @policy.scap_content_profile_id,
|
|
42
|
-
|
|
43
|
-
{:label => _("XCCDF Profile"),
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
{ :selected => @policy.scap_content_profile_id,
|
|
42
|
+
:include_blank => _("Default XCCDF profile") },
|
|
43
|
+
{ :label => _("XCCDF Profile"),
|
|
44
|
+
:disabled => profiles_selection.empty? ? true : false,
|
|
45
|
+
:help_inline => :indicator }
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -66,12 +66,12 @@ module PoliciesHelper
|
|
|
66
66
|
end
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
def submit_or_cancel_policy(form, overwrite = nil, args = {
|
|
69
|
+
def submit_or_cancel_policy(form, overwrite = nil, args = {})
|
|
70
70
|
args[:cancel_path] ||= send("#{controller_name}_path")
|
|
71
71
|
content_tag(:div, :class => "clearfix") do
|
|
72
72
|
content_tag(:div, :class => "form-actions") do
|
|
73
73
|
text = overwrite ? overwrite : _("Submit")
|
|
74
|
-
options = {:class => "btn btn-primary"}
|
|
74
|
+
options = { :class => "btn btn-primary" }
|
|
75
75
|
options[:'data-id'] = form_to_submit_id(form) unless options.key?(:'data-id')
|
|
76
76
|
previous = form.object.first_step? ? ' ' : previous_link(form)
|
|
77
77
|
cancel_and_submit = content_tag(:div, :class => "pull-right") do
|
|
@@ -12,16 +12,16 @@ module PolicyDashboardHelper
|
|
|
12
12
|
[:incompliant_hosts, _('Incompliant hosts')],
|
|
13
13
|
[:inconclusive_hosts, _('Inconclusive')],
|
|
14
14
|
[:report_missing, _('Not audited')],].each do |i|
|
|
15
|
-
data << {:label => i[1], :data => report[i[0]], :color => COLORS[i[0]]}
|
|
15
|
+
data << { :label => i[1], :data => report[i[0]], :color => COLORS[i[0]] }
|
|
16
16
|
end
|
|
17
17
|
flot_pie_chart 'overview', _('Compliance Status'), data, options
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def status_link(name, label, path)
|
|
21
21
|
content_tag :li do
|
|
22
|
-
content_tag(:i, raw(' '), :class=>'label', :style => 'background-color:' + COLORS[label]) +
|
|
22
|
+
content_tag(:i, raw(' '), :class => 'label', :style => 'background-color:' + COLORS[label]) +
|
|
23
23
|
raw(' ') +
|
|
24
|
-
link_to(name, path, :class=>'dashboard-links') +
|
|
24
|
+
link_to(name, path, :class => 'dashboard-links') +
|
|
25
25
|
content_tag(:h4, @report[label])
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
module ::ProxyAPI
|
|
2
2
|
class AvailableProxy
|
|
3
|
-
|
|
4
3
|
HTTP_ERRORS = [
|
|
5
4
|
EOFError,
|
|
6
5
|
Errno::ECONNRESET,
|
|
@@ -8,7 +7,8 @@ module ::ProxyAPI
|
|
|
8
7
|
Net::HTTPBadResponse,
|
|
9
8
|
Net::HTTPHeaderSyntaxError,
|
|
10
9
|
Net::ProtocolError,
|
|
11
|
-
Timeout::Error
|
|
10
|
+
Timeout::Error,
|
|
11
|
+
ProxyAPI::ProxyException
|
|
12
12
|
].freeze
|
|
13
13
|
|
|
14
14
|
def initialize(args)
|
|
@@ -21,7 +21,7 @@ module ::ProxyAPI
|
|
|
21
21
|
raise ::ProxyAPI::ProxyException.new(url, e, N_("Request timed out. Please try increasing Settings -> proxy_request_timeout"))
|
|
22
22
|
rescue RestClient::ResourceNotFound => e
|
|
23
23
|
raise ::ProxyAPI::ProxyException.new(url, e,
|
|
24
|
-
|
|
24
|
+
N_("Could not validate %s. Please make sure you have appropriate proxy version to use this functionality") % scap_file.class)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def policy_html_guide(scap_file, policy)
|
|
@@ -14,7 +14,7 @@ module ForemanOpenscap
|
|
|
14
14
|
{ :conditions => ArfReport.arel_table[:id].in(
|
|
15
15
|
PolicyArfReport.select(PolicyArfReport.arel_table[:arf_report_id])
|
|
16
16
|
.of_policy(Policy.find_by(name: cond).id).ast
|
|
17
|
-
).to_sql}
|
|
17
|
+
).to_sql }
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def search_by_comply_with(_key, _operator, policy_name)
|
|
@@ -34,7 +34,7 @@ module ForemanOpenscap
|
|
|
34
34
|
{ :conditions => ArfReport.arel_table[:id].in(
|
|
35
35
|
ArfReport.select(ArfReport.arel_table[:id])
|
|
36
36
|
.latest_of_policy(Policy.find_by(name: cond)).instance_eval(&selection).ast
|
|
37
|
-
).to_sql}
|
|
37
|
+
).to_sql }
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def search_by_last_for(key, operator, by)
|
|
@@ -68,19 +68,19 @@ module ForemanOpenscap
|
|
|
68
68
|
|
|
69
69
|
included do
|
|
70
70
|
scoped_search :relation => :policy, :on => :name, :complete_value => true, :rename => :compliance_policy,
|
|
71
|
-
|
|
71
|
+
:only_explicit => true, :ext_method => :search_by_policy_name
|
|
72
72
|
|
|
73
73
|
scoped_search :on => :id, :rename => :last_for, :complete_value => { :host => 0, :policy => 1 },
|
|
74
|
-
|
|
74
|
+
:only_explicit => true, :ext_method => :search_by_last_for
|
|
75
75
|
|
|
76
76
|
scoped_search :relation => :policy, :on => :name, :complete_value => true, :rename => :comply_with,
|
|
77
|
-
|
|
77
|
+
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_comply_with
|
|
78
78
|
|
|
79
79
|
scoped_search :relation => :policy, :on => :name, :complete_value => true, :rename => :not_comply_with,
|
|
80
|
-
|
|
80
|
+
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_not_comply_with
|
|
81
81
|
|
|
82
82
|
scoped_search :relation => :policy, :on => :name, :complete_value => true, :rename => :inconclusive_with,
|
|
83
|
-
|
|
83
|
+
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_inconclusive_with
|
|
84
84
|
|
|
85
85
|
compliance_status_scoped_search 'passed', :on => :status, :rename => :compliance_passed
|
|
86
86
|
compliance_status_scoped_search 'failed', :on => :status, :rename => :compliance_failed
|
|
@@ -10,7 +10,7 @@ module ForemanOpenscap
|
|
|
10
10
|
|
|
11
11
|
validates_with ForemanOpenscap::DataStreamValidator
|
|
12
12
|
|
|
13
|
-
after_save :create_profiles
|
|
13
|
+
after_save :create_profiles, :if => lambda { |ds_content| ds_content.scap_file_changed? }
|
|
14
14
|
|
|
15
15
|
before_validation :redigest, :if => lambda { |ds_content| ds_content.persisted? && ds_content.scap_file_changed? }
|
|
16
16
|
before_destroy ActiveRecord::Base::EnsureNotUsedBy.new(:policies)
|
|
@@ -13,13 +13,16 @@ module ForemanOpenscap
|
|
|
13
13
|
scoped_search :relation => :policies, :on => :name, :complete_value => true, :rename => :compliance_policy,
|
|
14
14
|
:only_explicit => true, :operators => ['= '], :ext_method => :search_by_policy_name
|
|
15
15
|
|
|
16
|
+
scoped_search :relation => :policies, :on => :id, :complete_value => false, :rename => :compliance_policy_id,
|
|
17
|
+
:only_explicit => true, :operators => ['= ', '!= '], :ext_method => :search_by_policy_id
|
|
18
|
+
|
|
16
19
|
scoped_search :relation => :policies, :on => :name, :complete_value => true, :rename => :compliance_report_missing_for,
|
|
17
20
|
:only_explicit => true, :operators => ['= ', '!= '], :ext_method => :search_by_missing_arf
|
|
18
21
|
|
|
19
22
|
scoped_search :relation => :compliance_status_object, :on => :status, :rename => :compliance_status,
|
|
20
|
-
:complete_value => {:compliant => ::ForemanOpenscap::ComplianceStatus::COMPLIANT,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
:complete_value => { :compliant => ::ForemanOpenscap::ComplianceStatus::COMPLIANT,
|
|
24
|
+
:incompliant => ::ForemanOpenscap::ComplianceStatus::INCOMPLIANT,
|
|
25
|
+
:inconclusive => ::ForemanOpenscap::ComplianceStatus::INCONCLUSIVE }
|
|
23
26
|
after_update :puppetrun!, :if => ->(host) { Setting[:puppetrun] && host.changed.include?('openscap_proxy_id') }
|
|
24
27
|
|
|
25
28
|
scope :comply_with, lambda { |policy|
|
|
@@ -110,15 +113,22 @@ module ForemanOpenscap
|
|
|
110
113
|
{ :conditions => Host::Managed.arel_table[:id].in(Host::Managed.select(Host::Managed.arel_table[:id]).joins(:policies).where(cond).pluck(:id)).to_sql + host_group_cond }
|
|
111
114
|
end
|
|
112
115
|
|
|
116
|
+
def search_by_policy_id(key, operator, policy_id)
|
|
117
|
+
cond = sanitize_sql_for_conditions(["foreman_openscap_policies.id #{operator} ?", value_to_sql(operator, policy_id)])
|
|
118
|
+
search_assigned_all cond, []
|
|
119
|
+
end
|
|
120
|
+
|
|
113
121
|
def search_by_missing_arf(key, operator, policy_name)
|
|
114
122
|
cond = sanitize_sql_for_conditions(["foreman_openscap_policies.name #{operator} ?", value_to_sql(operator, policy_name)])
|
|
115
123
|
|
|
116
124
|
host_ids_from_arf_of_policy = ForemanOpenscap::ArfReport.joins(:policy).where(cond).pluck(:host_id).uniq
|
|
117
125
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
hg_result = policy_assigned_using_hostgroup_host_ids cond, host_ids_from_arf_of_policy
|
|
126
|
+
search_assigned_all cond, host_ids_from_arf_of_policy
|
|
127
|
+
end
|
|
121
128
|
|
|
129
|
+
def search_assigned_all(condition, not_in_host_ids)
|
|
130
|
+
direct_result = policy_assigned_directly_host_ids condition, not_in_host_ids
|
|
131
|
+
hg_result = policy_assigned_using_hostgroup_host_ids condition, not_in_host_ids
|
|
122
132
|
result = (direct_result + hg_result).uniq
|
|
123
133
|
{ :conditions => "hosts.id IN (#{result.empty? ? 'NULL' : result.join(',')})" }
|
|
124
134
|
end
|
|
@@ -5,7 +5,7 @@ module ForemanOpenscap
|
|
|
5
5
|
def openscap_proxy_api
|
|
6
6
|
return @openscap_api if @openscap_api
|
|
7
7
|
proxy_url = openscap_proxy.url if openscap_proxy
|
|
8
|
-
raise ::Foreman::Exception.new(N_("No OpenSCAP proxy found for %{class} with %{id}"), { :class => self.class, :id => id }) unless proxy_url
|
|
8
|
+
raise ::Foreman::Exception.new(N_("No OpenSCAP proxy found for %{class} with id %{id}"), { :class => self.class, :id => id }) unless proxy_url
|
|
9
9
|
@openscap_api = ::ProxyAPI::Openscap.new(:url => proxy_url)
|
|
10
10
|
end
|
|
11
11
|
end
|
|
@@ -10,15 +10,16 @@ module ForemanOpenscap
|
|
|
10
10
|
BIT_NUM = 10
|
|
11
11
|
MAX = (1 << BIT_NUM) - 1
|
|
12
12
|
|
|
13
|
-
scoped_search :on => :status, :offset => 0, :word_size => 4*BIT_NUM, :complete_value => {:true => true, :false => false}, :rename => :eventful
|
|
13
|
+
scoped_search :on => :status, :offset => 0, :word_size => 4 * BIT_NUM, :complete_value => { :true => true, :false => false }, :rename => :eventful
|
|
14
14
|
|
|
15
15
|
has_one :policy_arf_report
|
|
16
16
|
has_one :policy, :through => :policy_arf_report, :dependent => :destroy
|
|
17
17
|
has_one :asset, :through => :host, :class_name => 'ForemanOpenscap::Asset', :as => :assetable
|
|
18
|
-
after_save :assign_locations_organizations
|
|
19
18
|
has_one :log, :foreign_key => :report_id
|
|
20
19
|
belongs_to :openscap_proxy, :class_name => "SmartProxy"
|
|
21
20
|
|
|
21
|
+
after_save :assign_locations_organizations
|
|
22
|
+
before_destroy :destroy_from_proxy
|
|
22
23
|
|
|
23
24
|
delegate :asset=, :to => :host
|
|
24
25
|
|
|
@@ -139,7 +140,7 @@ module ForemanOpenscap
|
|
|
139
140
|
end
|
|
140
141
|
msg.save!
|
|
141
142
|
end
|
|
142
|
-
#TODO: log level
|
|
143
|
+
# TODO: log level
|
|
143
144
|
Log.create!(:source_id => src.id,
|
|
144
145
|
:message_id => msg.id,
|
|
145
146
|
:level => :info,
|
|
@@ -187,7 +188,7 @@ module ForemanOpenscap
|
|
|
187
188
|
policy.id == other.policy.id
|
|
188
189
|
end
|
|
189
190
|
|
|
190
|
-
def
|
|
191
|
+
def destroy_from_proxy
|
|
191
192
|
if host
|
|
192
193
|
begin
|
|
193
194
|
openscap_proxy_api.destroy_report(self, ForemanOpenscap::Helper::find_name_or_uuid_by_host(host))
|
|
@@ -198,7 +199,6 @@ module ForemanOpenscap
|
|
|
198
199
|
else
|
|
199
200
|
logger.error "Failed to delete report with id #{id} from proxy, no host associated with report"
|
|
200
201
|
end
|
|
201
|
-
super
|
|
202
202
|
end
|
|
203
203
|
|
|
204
204
|
def self.newline_to_space(string)
|