#!/usr/local/bin/perl
# Works with Perl4 and Perl5
#
# unpgphtml -- a perl script to unmake PGP signed web-pages
#
# by SANFACE Software <sanface@sanface.com> 19 June 2002
#
# Requires PGP or GPG
# GPG support added by John Arundel <john@splange.freeserve.co.uk>
#
# Copy, use, and redistribute freely, but don't take my name off it and
# clearly mark an altered version.  Fixes and enhancements cheerfully 
# accepted.
#
# This is version 4.1.
#
# use strict;
use Getopt::Long;
use File::DosGlob 'glob';

my $help="";
my $verbose="";
my $gpg=0;
do GetOptions("help"    => \$help,
              "gpg"	=> \$gpg,
              "verbose" => \$verbose) || printusage() ;
$help and printusage();

my $out = "unpgphtml-out$$";
my $x="";
my @files;
if (@ARGV)
   {
   if ($^O =~ /^MSWin32$/i && !$recursive) {
     foreach $i (@ARGV) {
       if($i=~/\*|\?/) {push @files,glob($i)}
       else {push @files,$i}
       }
     }
   else {@files = @ARGV}
   foreach $x (@files)
      {
      if ($x=~/\.htm$/i || $x=~/\.html$/i)
         {
         $verbose and print "Processing file: $x\n\n";
         if($gpg) {
 	     system("gpg -o ${out} ${x}");
 	 } else {
 	     system("pgp < ${x} > ${out}");
 	 }
         open(TEMP, "$out")
             || die("unpgphtml: couldn't open tempfile $out \n");
         open(HTML, ">$x")
             || die("unpgphtml: couldn't open $x\n");
         while (<TEMP>)
            {
            s/ -->\n//;
            s/<KBD>----BEGIN PGP SIGNED WEB-PAGE----<\/KBD>\n//;
            s/<KBD>.*<pre>/<\/body>\n<\/html>/;
            print HTML $_;
            }

         close(TEMP);
         }
      else {print "Warning: the extension of the file isn't one of these .htm .HTM .html .HTML\n";}
      unlink($out);
      }
   }
else {printusage();}

sub printusage {
    print <<USAGEDESC;

usage:
        unpgphtml [-options ...] files

where options include:
    -help                        print out this message
    -gpg                         use GPG instead of PGP
    -verbose                     verbose

files:
    with files you can use metacharacters and relative and absolute path name
    
If you want to know more about this tool, you might want
to read the docs. They came together with unpgphtml!

Home: http://www.sanface.com/pgphtml.html

USAGEDESC
    exit(1);
}
