Class: CspReport::CspReportsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CspReport::CspReportsController
- Defined in:
- app/controllers/csp_report/csp_reports_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #destroy_all ⇒ Object
- #index ⇒ Object
- #report_by_ip ⇒ Object
- #report_by_rule ⇒ Object
- #report_by_source ⇒ Object
Instance Method Details
#create ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/csp_report/csp_reports_controller.rb', line 11 def create param = request.request_parameters()['csp-report'] report = CspReport::CspReport.new do |r| r.document_uri = param['document-uri'] r.referrer = param['referrer'] r.violated_directive = param['violated-directive'] r.original_policy = param['original-policy'] r.blocked_uri = param['blocked-uri'] r.incoming_ip = request.remote_ip end report.save! render status: 200, nothing: true end |
#destroy ⇒ Object
25 26 27 28 |
# File 'app/controllers/csp_report/csp_reports_controller.rb', line 25 def destroy CspReport::CspReport.destroy(params[:id]) redirect_to csp_reports_path end |
#destroy_all ⇒ Object
30 31 32 33 |
# File 'app/controllers/csp_report/csp_reports_controller.rb', line 30 def destroy_all CspReport::CspReport.delete_all redirect_to csp_reports_path end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/csp_report/csp_reports_controller.rb', line 7 def index @reports = CspReport::CspReport.all end |
#report_by_ip ⇒ Object
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 |
# File 'app/controllers/csp_report/csp_reports_controller.rb', line 35 def report_by_ip @report_by_ip = CspReport::CspReport.select( "incoming_ip, count(*) as count").group("incoming_ip") data = [] for report in @report_by_ip data.push [report.incoming_ip, report.count] end @chart = { chart: { :defaultSeriesType=>"pie" , :margin=> [50, 200, 60, 170] }, series: [{ :type=> 'pie', :name=> 'Violations by client IP', :data=> data }], title: {text: "By IP"}, legend: { :layout=> 'vertical', :style=> { :left=> 'auto', :bottom=> 'auto', :right=> '50px', :top=> '100px' } }, plotOptions: { :pie=>{ :allowPointSelect=>true, :cursor=>"pointer" , :dataLabels=>{ :enabled=>true, :color=>"black", :style=>{ :font=>"13px Trebuchet MS, Verdana, sans-serif" } } } } } end |
#report_by_rule ⇒ Object
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 120 121 122 123 |
# File 'app/controllers/csp_report/csp_reports_controller.rb', line 80 def report_by_rule @report_by_rule = CspReport::CspReport.select( "violated_directive, count(*) as count").group("violated_directive") data = [] for report in @report_by_rule data.push [report.violated_directive, report.count] end @chart = { chart: { :defaultSeriesType=>"pie" , :margin=> [50, 200, 60, 170] }, series: [{ :type=> 'pie', :name=> 'Violations by violated policy', :data=> data }], title: {text: "By rule"}, legend: { :layout=> 'vertical', :style=> { :left=> 'auto', :bottom=> 'auto', :right=> '50px', :top=> '100px' } }, plotOptions: { :pie=>{ :allowPointSelect=>true, :cursor=>"pointer" , :dataLabels=>{ :enabled=>true, :color=>"black", :style=>{ :font=>"13px Trebuchet MS, Verdana, sans-serif" } } } } } end |
#report_by_source ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/controllers/csp_report/csp_reports_controller.rb', line 125 def report_by_source @report_by_source = CspReport::CspReport.select( "document_uri, count(*) as count").group("document_uri") data = [] for report in @report_by_source data.push [report.document_uri, report.count] end @chart = { chart: { :defaultSeriesType=>"pie" , :margin=> [50, 200, 60, 170] }, series: [{ :type=> 'pie', :name=> 'Violations by source document URI', :data=> data }], title: {text: "By source"}, legend: { :layout=> 'vertical', :style=> { :left=> 'auto', :bottom=> 'auto', :right=> '50px', :top=> '100px' } }, plotOptions: { :pie=>{ :allowPointSelect=>true, :cursor=>"pointer" , :dataLabels=>{ :enabled=>true, :color=>"black", :style=>{ :font=>"13px Trebuchet MS, Verdana, sans-serif" } } } } } end |