real-world-onion-sites/walk.pl

157 lines
3.5 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");
}
@optional = qw(
comment
proof
status
check-date
check-status
check-date-1
check-status-1
check-date-2
check-status-2
check-date-3
check-status-3
check-date-4
check-status-4
);
foreach $x (@optional) {
2018-07-09 18:50:40 -04:00
$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";
2018-07-10 03:46:55 -04:00
$last_check = &first('directory/.check-date');
2018-07-10 03:46:55 -04:00
print <<"EOF";
# Index
This index is sorted alphabetically; the main text is sorted by size of each category.
Connectivity was last checked at: **$last_check**
EOF
print "\n";
2018-07-09 17:38:14 -04:00
foreach $catname (sort keys %tree) {
my $catprint = &canon($catname);
print "* [$catprint](#$catname)\n"
}
2018-07-09 17:30:55 -04:00
print "\n";
foreach $catname (sort { (scalar keys %{$tree{$a}}) <=> (scalar keys %{$tree{$b}}) } keys %tree) {
2018-07-09 17:17:45 -04:00
print "----\n\n";
my $catprint = &canon($catname);
print "# $catprint\n\n";
$catcontents = $tree{$catname};
foreach $catsortkey (sort { lc($a) cmp lc($b) } keys %{$catcontents}) {
2018-07-09 18:50:40 -04:00
my $onion = $catcontents->{$catsortkey};
my @foo = keys(%{$onion});
2018-07-09 20:29:22 -04:00
2018-07-09 18:50:40 -04:00
print "## $onion->{title}\n\n";
2018-07-09 20:29:22 -04:00
2018-07-09 18:50:40 -04:00
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 20:29:22 -04:00
foreach $suffix ('', '-1') {
$cd = "check-date$suffix";
$cs = "check-status$suffix";
if ($onion->{$cd}) {
print " * ";
print "@{$onion->{$cd}}";
if ($onion->{$cs}) {
print " ";
print "@{$onion->{$cs}}";
}
2018-07-09 20:29:22 -04:00
print "\n";
2018-07-09 18:50:40 -04:00
}
}
2018-07-09 20:29:22 -04:00
2018-07-09 18:50:40 -04:00
foreach my $line (@{$onion->{proof}}) {
2018-07-09 19:03:04 -04:00
print " * $line";
2018-07-13 00:25:08 -04:00
print " :no_entry_sign: Not HTTPS" if ($line =~ m!http://!);
2018-07-09 19:03:04 -04:00
print "\n";
2018-07-09 17:17:45 -04:00
}
2018-07-09 20:29:22 -04:00
2018-07-09 17:17:45 -04:00
print "\n";
}
print "\n";
}
2018-07-09 17:30:55 -04:00
print "----\n\n";