#!perl


$tutorials = "html/tutorials/vulnerability";
$cves      = "html/cve/cve_sara.db";

opendir(DIR, "$tutorials/base") || die "cannot opendir $tutorials/base\n"; ;
(@base_dir)  = readdir(DIR);
close(DIR);
for (@base_dir) {
  $file = $_;
  $name = $file;
  $name =~ s/\.html//g;
  $name =~ s/\_/ /g;
  $valid =  `grep -c "$file" $cves`;
  $valid =~ s/\n/ /;
  $used  =  `grep  "$name" bin/* | grep -v 'CA\-'`;
  $used  =  "YES-0" if $used;
  $used  =  `grep "$name" rules/sid.def | grep -v 'CA\-'` if ($used ne 'YES-0');
  $used  =  "YES-1" if ($used && $used ne 'YES-0');
  $used  =  `grep "$name" rules/facts | grep -v 'CA\-'` if ($used !~ /YES/);
  $used  =  "YES-2" if ($used && $used !~ /YES/);

  print "$file $valid $used\n";
}

opendir(DIR, "$tutorials/cert") || die "cannot opendir $tutorials/cert\n"; ;
(@cert_dir)  = readdir(DIR);
close(DIR);
for (@cert_dir) {
  $file = $_;
  $name = $file;
  $name =~ s/\.html//g;
  $name =~ s/\_/ /g;
  $valid =  `grep -c "$file" $cves`;
  $valid =~ s/\n//;
  $used  =  `grep  "$name" bin/*`;
  $used  =  "YES-0" if $used;
  $used  =  `grep "$name" rules/sid.def` if ($used ne 'YES-0');
  $used  =  "YES-1" if ($used && $used ne 'YES-0');
  $used  =  `grep "$name" rules/facts` if ($used !~ /YES/);
  $used  =  "YES-2" if ($used && $used !~ /YES/);

print "$file $valid $used\n";
}
