Module: PWN::Reports::HTMLFooter

Defined in:
lib/pwn/reports/html_footer.rb

Overview

This plugin generates the HTML header and includes external JS/CSS libraries for PWN reports.

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

0day Inc. <[email protected]>



141
142
143
144
145
# File 'lib/pwn/reports/html_footer.rb', line 141

public_class_method def self.authors
  "AUTHOR(S):
    0day Inc. <[email protected]>
  "
end

.generateObject

Supported Method Parameters

PWN::Reports::HTMLFooter.generate(

column_names: 'required - array of column names to use in the report table',
driver_src_uri: 'required - pwn driver source code uri',

)



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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/pwn/reports/html_footer.rb', line 13

public_class_method def self.generate
  %(
          // Select All and Deselect All
          function select_deselect_all() {
            var visible_multi_line_trs = $('#pwn_results tbody tr:visible .multi_line_select tr');
            var highlighted_in_visible = visible_multi_line_trs.filter('.highlighted');
            if (highlighted_in_visible.length === visible_multi_line_trs.length) {
              highlighted_in_visible.removeClass('highlighted');
            } else {
              visible_multi_line_trs.filter(':not(.highlighted)').addClass('highlighted');
            }
          }

          function getExportData(table) {
            return new Promise((resolve) => {
              $.getJSON(table.ajax.url(), function(original_json) {
                let new_data;
                if ($('.multi_line_select tr.highlighted').length === 0) {
                  new_data = original_json.data;
                } else {
                  var selected_results = {};

                  $('.multi_line_select tr.highlighted').each(function() {
                    var inner_tr = $(this);
                    var main_tr = inner_tr.closest('td').parent();
                    var row = table.row(main_tr);
                    var row_index = row.index();
                    var line_index = inner_tr.index();

                    if (selected_results[row_index] === undefined) {
                      selected_results[row_index] = {
                        row: row,
                        lines: []
                      };
                    }

                    selected_results[row_index].lines.push(line_index);
                  });

                  new_data = [];

                  Object.keys(selected_results).forEach(function(ri) {
                    var sel = selected_results[ri];
                    var orig_row_data = sel.row.data();
                    var new_row_data = JSON.parse(JSON.stringify(orig_row_data));

                    sel.lines.sort((a, b) => a - b);
                    new_row_data.line_no_and_contents = sel.lines.map(function(li) {
                      return orig_row_data.line_no_and_contents[li];
                    });

                    new_row_data.raw_content = new_row_data.line_no_and_contents.map(l => l.contents).join('\\n');

                    new_data.push(new_row_data);
                  });
                }
                resolve({data: new_data, report_name: original_json.report_name});
              });
            });
          }

          function export_json(table) {
            if ($('.multi_line_select tr.highlighted').length === 0 && !confirm('No lines selected. Export all records?')) {
              return;
            }

            getExportData(table).then(({data, report_name}) => {
              var original_json = {report_name: report_name, data: data};

              var json_str = JSON.stringify(original_json, null, 2);
              var blob = new Blob([json_str], { type: 'application/json' });
              var url = URL.createObjectURL(blob);
              var a = document.createElement('a');
              a.href = url;
              a.download = report_name + '.json';
              document.body.appendChild(a);
              a.click();
              document.body.removeChild(a);
              URL.revokeObjectURL(url);
            });
          }

          // Custom advanced search handling
          $('#dt-search-0').unbind();
          $('#dt-search-0').on('input', function() {
            var table = $('#pwn_results').DataTable();
            var searchTerm = this.value;
            var isRegex = false;
            var isSmart = true;
            table.search(searchTerm, isRegex, isSmart).draw();
          });

          // Toggle Columns
          $('a.toggle-vis').on('click', function (e) {
            var table = $('#pwn_results').DataTable();
            e.preventDefault();

            // Get the column API object
            var column = table.column( $(this).attr('data-column') );

            // Toggle the visibility
            column.visible( ! column.visible() );
          });

          // Row highlighting for multi-line selection
          $('#pwn_results').on('click', '.multi_line_select tr', function () {
            $(this).toggleClass('highlighted');
          });

          // Detect window size changes and recalculate/update scrollY
          $(window).resize(function() {
            var table = $('#pwn_results').DataTable();
            var newWindowHeight = $(window).height();
            var newScrollYHeight = Math.max(min_scroll_height, newWindowHeight - offset);  // Your offset
            $('.dt-scroll-body').css('max-height', newScrollYHeight + 'px')
            table.columns.adjust().draw(false);  // Adjust columns first, then redraw without data reload
          });

      </script>
    </body>
  </html>
  )
rescue StandardError => e
  raise e
end

.helpObject

Display Usage for this Module



149
150
151
152
153
154
155
156
157
# File 'lib/pwn/reports/html_footer.rb', line 149

public_class_method def self.help
  puts "USAGE:
    #{self}.generate(
      column_names: 'Array of Column Names to use in the report table',
      driver_src_uri: 're

    #{self}.authors
  "
end