-
Notifications
You must be signed in to change notification settings - Fork 3
/
import.pl
executable file
·132 lines (100 loc) · 3.29 KB
/
import.pl
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
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
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
use File::Copy;
my $product = shift @ARGV;
# Elements to add to the frontmatter, per product
# For reference: https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs#markdown-front-matter
my %image = (
threatstryker => "/img/social/threatstryker.jpg",
secretscanner => "/img/social/secretscanner.jpg",
packetstreamer => "/img/social/packetstreamer.jpg",
flowmeter => "/img/social/flowmeter.jpg",
yarahunter => "/img/social/yarahunter.jpg"
# TODO(tjonak): ebpfguard image
);
my %keywords = (
threatstryker => "[vulnerability, threat, appsecurity, CVE, MITRE, TTP, supply chain, graph, attack path, eBPF, attack signal, indicator of compromise]",
secretscanner => "[secret, secret scanning, token, key, password, container, image]",
packetstreamer => "[tcpdump, distributed, remote, pcap, packet]",
flowmeter => "[pcap, packet, ML, machine learning]",
yarahunter => "[yara, scan, container, image, filesystem, malware]",
ebpfguard => "[eBPF,LSM,rust]"
);
my $fromdir = undef;
my $todir = undef;
my $verbose = undef;
GetOptions ("from=s" => \$fromdir,
"to=s" => \$todir,
"verbose" => \$verbose);
do {
print "Copying $product docs from $fromdir to $todir\n";
print "\n"
} if $verbose;
sub processDir( $$ );
sub processMarkdown( $$ );
processDir( "$fromdir/$product", "$todir/$product" );
print "Done\n" if $verbose;
exit 0;
# --------------------------------
sub processDir( $$ ) {
my( $from, $to ) = @_;
print "Processing $from to $to\n" if $verbose;
if( ! -d $to ) {
mkdir $to or die "Cannot mkdir $to: $!";
print " mkdir $to\n" if $verbose;
};
opendir( my $dh, $from ) or die "Can't open $from: $!";
while (readdir $dh) {
next if $_ =~ /^\./; # skip .files
print " Considering $_\n" if $verbose;
if( -d "$from/$_" ) {
print " recursing into $from/$_\n" if $verbose;
processDir( "$from/$_", "$to/$_" );
next;
};
if( -f "$from/$_" && $_ =~ /\.md$/ ) {
print " process markdown $from/$_ to $to/$_\n" if $verbose;
processMarkdown( "$from/$_", "$to/$_" );
next;
}
if( -f "$from/$_" ) {
print " copy $from/$_ to $to/$_\n" if $verbose;
copy( "$from/$_","$to/$_") or die "Copy $from/$_ to $to/$_ failed: $!";
next;
}
print " I don't know what to do with $_, sorry!\n";
}
closedir $dh;
}
sub processMarkdown( $$ ) {
my( $from, $to ) = @_;
my @frontmatter;
my $markdown;
open IN, "<$from" or die "Cannot open $from: $!";
my $line = <IN>;
if( $line =~ /^---\s+$/ ) {
# There is some frontmatter content, terminated with '---'
$line = <IN>;
while( $line !~ /^---\s+$/ ) {
push @frontmatter, $line;
$line = <IN>;
}
$line = <IN>;
}
# $line is now the first line of markdown content
local $/;
$markdown = $line.<IN>;
close IN;
# customise the front-matter
#
push @frontmatter, "image: $image{$product}\n" if defined $image{$product};
push @frontmatter, "keywords: $keywords{$product}\n" if defined $keywords{$product};
#push @frontmatter, "hide_table_of_contents: true\n";
open OUT, ">$to" or die "Cannot open $to: $!";
if( @frontmatter ) {
print OUT "---\n", @frontmatter, "---\n";
}
print OUT $markdown;
close OUT;
}