real-world-onion-sites/walk.pl

119 lines
2.7 KiB
Perl
Raw Normal View History

2018-07-09 17:17:45 -04:00
#!/usr/bin/perl -w
use Data::Dumper;
sub canon {
my $foo = shift;
$foo =~ s/-/ /go;
return join '', map { ucfirst lc } split /(\s+)/, $foo;
}
sub listdir {
my $d = shift;
opendir(D, $d) || die "opendir: $d: $!\n";
my @foo = sort(grep(!/^\./o, readdir(D)));
closedir(D);
return @foo;
}
sub first {
my $f = shift;
my $line;
open(F, $f) || die "open: $f: $!\n";
chomp($line = <F>);
close(F);
return $line;
}
sub lines {
my $f = shift;
my @results;
open(F, $f) || die "open: $f: $!\n";
chomp(@results = <F>);
close(F);
return \@results; # REF!
}
sub doonion {
my ($path, $onion) = @_;
my $odir = "$path/$onion";
my %result = ();
2018-07-09 18:50:40 -04:00
foreach $x (qw(title)) {
$result{$x} = &first("$odir/$x");
}
foreach $x (qw(urls)) {
$result{$x} = &lines("$odir/$x");
}
foreach $x (qw(comment proof status check-date check-status)) {
$result{$x} = &lines("$odir/$x") if (-f "$odir/$x"); # OPTIONAL
}
2018-07-09 17:17:45 -04:00
$result{'sortkey'} = "$result{title}::$onion";
return \%result;
}
sub docat {
my ($path, $category) = @_;
my $catdir = "$path/$category";
my @onions = &listdir($catdir);
my %result = ();
foreach $onion (@onions) {
my $foo = &doonion($catdir, $onion);
my $key = $$foo{'sortkey'};
$result{$key} = $foo;
}
return \%result;
}
# load
@categories = &listdir('directory');
foreach $catname (@categories) {
$tree{$catname} = &docat('directory', $catname);
}
2018-07-09 17:38:14 -04:00
print "\n";
print "----\n\n";
print "# Index\n\n";
foreach $catname (sort keys %tree) {
my $catprint = &canon($catname);
print "* [$catprint](#$catname)\n"
}
2018-07-09 17:30:55 -04:00
print "\n";
2018-07-09 17:17:45 -04:00
foreach $catname (sort keys %tree) {
print "----\n\n";
my $catprint = &canon($catname);
print "# $catprint\n\n";
$catcontents = $tree{$catname};
foreach $catsortkey (sort keys %{$catcontents}) {
2018-07-09 18:50:40 -04:00
my $onion = $catcontents->{$catsortkey};
my @foo = keys(%{$onion});
print "## $onion->{title}\n\n";
foreach my $line (@{$onion->{urls}}) {
2018-07-09 17:17:45 -04:00
print "* $line";
print " :lock:" if ($line =~ m!https://!);
print "\n";
}
2018-07-09 18:50:40 -04:00
if ($onion->{'check-status'}) {
print " * ";
print "@{$onion->{'check-status'}}";
if ($onion->{'check-date'}) {
print " ";
print "@{$onion->{'check-date'}}";
}
print "\n";
}
foreach my $line (@{$onion->{proof}}) {
2018-07-09 19:03:04 -04:00
print " * $line";
2018-07-09 19:04:52 -04:00
print " :poop::poop::poop: (not HTTPS)" if ($line !~ m!https://!);
2018-07-09 19:03:04 -04:00
print "\n";
2018-07-09 17:17:45 -04:00
}
print "\n";
}
print "\n";
}
2018-07-09 17:30:55 -04:00
print "----\n\n";