forked from sbominator/sbom-wp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsbominator.php
More file actions
69 lines (54 loc) · 1.84 KB
/
Copy pathsbominator.php
File metadata and controls
69 lines (54 loc) · 1.84 KB
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
<?php
/**
* Plugin Name: Sbominator
* Text Domain: sbominator
* Domain Path: /languages
* Version: 0.1.0
*
* @package Sbominator
*/
// Your code starts here.
include 'vendor/autoload.php';
add_filter('debug_information', 'sbominator_debug_info');
add_action('admin_init', 'sbominator_check_for_download');
use SBOMinator\Scanner\FileScanner;
function sbominator_check_for_download(){
if (isset($_GET['sbom']) && $_GET['sbom'] == 'plugins_themes')
sbominator_get_plugins_themes_scan();
if (isset($_GET['sbom']) && $_GET['sbom'] == 'wordpress')
sbominator_get_wordpress_sbom();
}
function sbomniator_array_to_json_download($data =[], $name = '') {
if (!is_array($data))
return '';
header('Content-Type: application/json');
header('Content-Disposition: attachment; filename=SBOM'.$name.'.json');
header('Pragma: no-cache');
echo json_encode($data);
die();
}
function sbominator_get_wordpress_sbom(){
$scanner = new \Scanninator\Scanninator('https://github.com/WordPress/WordPress');
sbomniator_array_to_json_download($scanner->get_sbom(),'WordPress');
}
function sbominator_get_plugins_themes_scan(){
$scanner = new \SBOMinator\Scanner\FileScanner(10, ['json', 'lock']);
sbomniator_array_to_json_download($scanner->scanForDependencies(WP_CONTENT_DIR),'WordPress Plugins/Themes');
}
function sbominator_debug_info($info) {
$info["sbominator"] = [
"label" => "SBOM",
"description" => "SBOM output for the WordPress installation",
"fields" => [
"WordPress" => [
'label' => 'WordPress',
'value' => '<a href="'.add_query_arg( ['sbom' => 'wordpress']) .'">Download SBOM of WordPress</a>'
],
"Plugin/Themes" => [
'label' => 'Plugin/Themes',
'value' => '<a href="'.add_query_arg( ['sbom' => 'plugins_themes']) .'">Download SBOM of Plugins and Themes</a>'
]
]
];
return $info;
}