--- websec	2005-01-02 02:52:36.000000000 +0100
+++ /home/dstadler/websec-snapshot-2003.06.28/websec	2005-01-02 15:46:18.000000000 +0100
@@ -64,7 +64,14 @@
     if ( -e $urllist ) {
         $base = ".";
     } else {
-        $base = $ENV{HOME} . "/.websec";
+    if ( ($^O eq "Windows_NT") or ($^O eq "MSWin32"))
+    {
+            $base = $ENV{HOME} . "\\.websec";
+        }
+        else
+    {
+            $base = $ENV{HOME} . "/.websec";
+        }
     }
 }
 
@@ -87,12 +94,25 @@
 
 # Location of webdiff, if it's in the same directory as websec, use it,
 # this enables simply opening the archive and using the program inplace.
+$webdiffbin = ".\\webdiff";
+if ( -e $webdiffbin ) {
+    $webdiffbin = "perl .\\webdiff";
+}
+else
+{
 use FindBin;
 $webdiffbin = "$FindBin::Bin/webdiff";
 if ( !-e $webdiffbin ) {
     $webdiffbin = "webdiff";
 }
+}
 
+$htmldiffbin = ".\\htmldiff";
+if ( -e $htmldiffbin ) {
+    $htmldiffbin = "perl .\\htmldiff";
+}
+else
+{
 $htmldiffbin = "$FindBin::Bin/htmldiff";
 if ( !-e $htmldiffbin ) {
   $htmldiffbin = "./htmldiff";
@@ -100,10 +120,12 @@
       $htmldiffbin = "htmldiff";
   }
 }
+}
 
 # prepare digest
 @digest = ();
 @htmldigest = ();
+@htmldigest2 = ();
 
 # Set default values
 local %defaults = (
@@ -181,13 +203,32 @@
 }
 
 if (@htmldigest) {
-    ($OUTPAGE, $pagename) = tempfile(DIR=>"$base", UNLINK=>1, SUFFIX=>".html");
-    print OUTPAGE "<HTML><BODY>The contents of the following URLs has changed:<P><P>";
-    foreach (@htmldigest) { print OUTPAGE "$_<P>\n"; }
-    print OUTPAGE "<P></BODY></HTML>";
+    open( OUTPAGE, "> $base/index.html" ) or die "Cannot open $base/index.html: $!\n";
+    print OUTPAGE "<HTML><BODY>The contents of the following URLs has changed:<P>";
+    print OUTPAGE "The small version of this document is available <A HREF=\"index2.html\">here</A>";
+    print OUTPAGE "<TABLE CELLSPACING=\"2\" CELLPADDING=\"2\" WIDTH=\"100%\" BORDER=\"1\">";
+    print OUTPAGE "<TBODY>";
+    foreach (@htmldigest) { print OUTPAGE "$_\n"; }
+    print OUTPAGE "</TBODY>";
+    print OUTPAGE "</TABLE>";
+    print OUTPAGE "</BODY></HTML>";
     close(OUTPAGE);
 
-    &ShowDocument( $program, $pagename);
+    #&ShowDocument( $program, $base."/index.html");
+}
+if (@htmldigest2) {
+    open( OUTPAGE, "> $base/index2.html" ) or die "Cannot open $base/index2.html: $!\n";
+    print OUTPAGE "<HTML><BODY>The contents of the following URLs has changed:<P>";
+    print OUTPAGE "The normal version of this document is available <A HREF=\"index.html\">here</A>";
+    print OUTPAGE "<TABLE CELLSPACING=\"2\" CELLPADDING=\"2\" WIDTH=\"100%\" BORDER=\"1\">";
+    print OUTPAGE "<TBODY>";
+    foreach (@htmldigest2) { print OUTPAGE "$_\n"; }
+    print OUTPAGE "</TBODY>";
+    print OUTPAGE "</TABLE>";
+    print OUTPAGE "</BODY></HTML>";
+    close(OUTPAGE);
+
+    &ShowDocument( $program, $base."/index2.html");
 }
 
 
@@ -262,10 +303,19 @@
         return 0;
     }
 
+    # use name or prefix if one of them is missing
+    if ( $name eq "" && $prefix ne "")
+    {
+        $name = $prefix;
+    }
+    elsif ( $prefix eq "" && $name ne "")
+    {
+        $prefix = $name;
+    }
     # If essential parameters are not present, abort with error
-    if ( $name eq ""
+    elsif ( $name eq ""
         || $prefix eq ""
-        || ( $email eq "" && $emailLink eq "" && $program eq "" ) )
+        || ( $email eq "" && $emaillink eq "" && $program eq "" ) )
     {
         print "Name, prefix, program or email info missing from URL: $url.\n";
         return -1;
@@ -385,10 +435,15 @@
                             ShowDocument( $program, $outgoing );
                         }
                         else {
-                            push @htmldigest, "<A HREF=\"".$outgoing."\">Changes for ".$name."</A>".
-                                    "&nbsp;<A HREF=\"".$page_archive."\">previous page</A>".
-                                    "&nbsp;<A HREF=\"".$page_previous."\">current page</A>".
-                                    "&nbsp;<A HREF=\"".$url."\">current page on the net</A><P><P>";
+                            push @htmldigest,
+                                      "<TR><TD><A HREF=\"file://".$outgoing."\">Changes for ".$name."</A></TD>".
+                                    "&nbsp;<TD><A HREF=\"file://".$page_archive."\">previous page</A></TD>".
+                                    "&nbsp;<TD><A HREF=\"file://".$page_previous."\">current page</A></TD>".
+                                    "&nbsp;<TD><A HREF=\"".$url."\">current page on the net</A></TD>".
+                                    "</TR>";
+                            push @htmldigest2,
+                                      "<TR><TD><A HREF=\"file://".$outgoing."\">Changes for ".$name."</A></TD>".
+                                    "</TR>";
                         }
                     }
                 }
@@ -433,10 +488,70 @@
                             ShowDocument( $program, $outgoing );
                         }
                         else {
-                            push @htmldigest, "<A HREF=\"".$outgoing."\">Changes for ".$name."</A>".
-                                    "&nbsp;<A HREF=\"".$page_archive."\">previous page</A>".
-                                    "&nbsp;<A HREF=\"".$page_previous."\">current page</A>".
-                                    "&nbsp;<A HREF=\"".$url."\">current page on the net</A><P><P>";
+                            push @htmldigest,
+                                      "<TR><TD><A HREF=\"file://".$outgoing."\">Changes for ".$name."</A></TD>".
+                                    "&nbsp;<TD><A HREF=\"file://".$page_archive."\">previous page</A></TD>".
+                                    "&nbsp;<TD><A HREF=\"file://".$page_previous."\">current page</A></TD>".
+                                    "&nbsp;<TD><A HREF=\"".$url."\">current page on the net</A></TD>".
+                                    "</TR>";
+                            push @htmldigest2,
+                                      "<TR><TD><A HREF=\"file://".$outgoing."\">Changes for ".$name."</A></TD>".
+                                    "</TR>";
+                        }
+                    }
+                }
+                else {
+                    print "No changes were detected.\n";
+                }
+                rename $page_previous, $page_archive;
+                rename $page_current,  $page_previous;
+            }
+            else {
+                print
+                  "No previous version for this page. Storing in archive ...\n";
+                rename $page_current, $page_previous;
+            }
+        }
+        elsif ( $diff eq "webdiff_htmldiff" )
+        {
+            if ( $page_previousExists == 1 ) {
+                print "First testing differences from previous version of webpage with webdiff...\n";
+                $rc = system($webdiff);
+                if ( $rc != 0 ) {
+                    print "webdiff found differences, now Highlighting differences from previous version of webpage using htmldiff...\n";
+                    $rc = system($htmldiff);
+                }
+                if ( $rc != 0 ) {
+                    if ( $email ne "" ) {
+                        print "Sending highlighted page to $email ...\n";
+                        MailDocument( $outgoing, $subj, $email );
+                    }
+                    if ( $emaillink ne "" ) {
+                        print "Sending link to $emaillink ...\n";
+                        if ( ( $digest ne "no" ) && ( $digest ne "false" ) ) {
+                            push @digest, $url;
+                            ($digestEmail) or ( $digestEmail = $emaillink );
+                        }
+                        else {
+                            my $filepath = File::Spec->rel2abs($page_previous);
+                            $linkmsg = "The contents of the following URL has changed:\n$url\n\nIt can also be found at:\nfile://$filepath\n";
+                            MailMessage( $linkmsg, $subj, $emaillink );
+                        }
+                    }
+                    if ( $program ne "" ) {
+                        if ( $programdigest ne "true" ) {
+                            ShowDocument( $program, $outgoing );
+                        }
+                        else {
+                            push @htmldigest,
+                                      "<TR><TD><A HREF=\"file://".$outgoing."\">Changes for ".$name."</A></TD>".
+                                    "&nbsp;<TD><A HREF=\"file://".$page_archive."\">previous page</A></TD>".
+                                    "&nbsp;<TD><A HREF=\"file://".$page_previous."\">current page</A></TD>".
+                                    "&nbsp;<TD><A HREF=\"".$url."\">current page on the net</A></TD>".
+                                    "</TR>";
+                            push @htmldigest2,
+                                      "<TR><TD><A HREF=\"file://".$outgoing."\">Changes for ".$name."</A></TD>".
+                                    "</TR>";
                         }
                     }
                 }
@@ -573,24 +688,35 @@
     my $status;
 
     # special handling for mozilla, try to use remoting...
-    if ( $program eq "mozilla" ) {
-        $status = system("mozilla -remote \"ping()\"");
-
-        # print "Status after ping: ".$status."\n";
-
-# if ping() returns ne 0, mozilla is not running, we cannot use openurl()
-        if ( $status ne 0 ) {
-            $status = system( "mozilla", $outgoing );
+    if ( $program eq "mozilla" or $program eq "firefox" ) {
+        # on Windows, remoting is not available
+        if ( ($^O eq "Windows_NT") or ($^O eq "MSWin32"))
+        {
+            $status = system( $program, "file://".$outgoing );
             if ( $status ne 0 ) {
-                print "Running mozilla returned status: " . $status . "\n";
+                print "Running $program returned status: " . $status . "\n";
             }
         }
-        else {
-            $status =
-              system(
-                "mozilla -remote \"openurl(file:" . $outgoing . ",new-tab)\"" );
+        else
+        {
+            $status = system($program." -remote \"ping()\"");
+
+            # print "Status after ping: ".$status."\n";
+
+    # if ping() returns ne 0, mozilla is not running, we cannot use openurl()
             if ( $status ne 0 ) {
-                print "Running mozilla returned status: " . $status . "\n";
+                $status = system( $program, $outgoing );
+                if ( $status ne 0 ) {
+                    print "Running $program returned status: " . $status . "\n";
+                }
+            }
+            else {
+                $status =
+                  system(
+                    $program." -remote \"openurl(file:" . $outgoing . ",new-tab)\"" );
+                if ( $status ne 0 ) {
+                    print "Running $program returned status: " . $status . "\n";
+                }
             }
         }
     }
