Clean-up, smarter handling of unreachable URLs
authoroes <oes@users.sourceforge.net>
Sat, 6 Apr 2002 15:19:35 +0000 (15:19 +0000)
committeroes <oes@users.sourceforge.net>
Sat, 6 Apr 2002 15:19:35 +0000 (15:19 +0000)
doc/webserver/actions/index.php
doc/webserver/actions/step2.php
doc/webserver/actions/step3.php

index a949d63..d7dee35 100755 (executable)
  <head>
   <meta http-equiv="Content-Style-Type" content="text/css">
   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-  <style type="text/css">
-   body,td,th { font-family:helvetica,helv,arial,sans-serif; font-size:10px }
-   body { background-color: #ffffff; color: #000000 }
-   h1 { font-size: 140%; marign: 0px; }
-   h2 { font-size: 120%; marign: 0px; }
-   div.title    { background-color:#dddddd; border:solid black 1px; margin:20px; padding:20px; }
-   div.box      { background-color:#eeeeee; border:solid black 1px; margin:20px; padding:20px; }
-   div.infobox  { background-color:#ccccff; border:solid black 1px; margin:20px; padding:20px; width: 60%; }
-   div.errorbox { background-color:#ffdddd; border:solid black 1px; margin:20px; padding:20px; width: 60%; text-align: left; } 
-  </style>
+  <link rel="stylesheet" type="text/css" href="../p_feedback.css">
 
 <?php
 
 /*
- * MUST be updated in sync with actions file:
+ * Config:
  */
 $required_actions_file_version = "1.0";
 $required_privoxy_version = "2.9.13";
 $actions_file_download = "http://www.privoxy.org/actions/testdrive.action";
+$submit_target = "http://www.oesterhelt.org/actions-test/step2.php";
 
 
 /*
- * For testing: 
+ * Debug:
  */
 //phpinfo();
 //error_reporting(E_ALL);
 error_reporting(E_NONE);
 
+/*
+ * Function: error_abort
+ * Purpose:  Return an error page with $title and $message
+ */
+function error_abort($title, $message)
+{
+   if ($title == "invalid") /* shortcut */
+   {
+      $title = "Invalid Feedback Submission";
+   }
+
+   echo ("  <title>Privoxy: $title</title>
+           </head>
+           <body>
+            <div class=\"title\">
+             <h1>
+              <a href=\"http://www.privoxy.org/\">Privoxy</a>: $title
+              </h1>
+             </div>
+            <center>
+             <div class=\"errorbox\">
+              $message
+             </div>
+            </center>
+            <p>Valid <a href=\"http://validator.w3.org/\">HTML 4.01 Transitional</a></p>
+           </body>
+          </html>\n");
+   exit; 
+}
+
 
 /*
  * Bookmarklet that leads here:
@@ -107,22 +129,14 @@ $headers = getallheaders();
 
 if (!isset($headers["X-Actions-File-Version"]) || $headers["X-Actions-File-Version"] < $required_actions_file_version)
 {
-   echo ("<title>Invalid Privoxy Action List Feedback</title></head>
-          <body><div class=\"title\"><h1>Invalid Feedback Submission</h1></div>
-           <center>
-            <div class=\"errorbox\"><p>As much as we welcome your feedback, please note that
-             we can only accept problem reports based on:
-             <ul>
-              <li><a href=\"http://www.privoxy.org/\">Privoxy</a> version $required_privoxy_version or later</li>
-              <li><a href=\"$actions_file_download\">Actionsfile</a> version  version $required_actions_file_version or later</li>
-             </ul>
-             <p>We hope you will understand that we feel unable to maintain concurrent versions of the file.</p>
-            </div>
-           </center>
-           <p>Valid <a href=\"http://validator.w3.org/\">HTML 4.01 Transitional</a></p>
-          </body>
-         </html>");
-   exit;
+
+   error_abort("invalid", "<p>As much as we welcome your feedback, please note that
+               we can only accept problem reports based on:
+               <ul>
+                <li><a href=\"http://www.privoxy.org/\">Privoxy</a> version $required_privoxy_version or later</li>
+                <li><a href=\"$actions_file_download\">Actionsfile</a> version  version $required_actions_file_version or later</li>
+               </ul>
+               <p>We hope you will understand that we feel unable to maintain concurrent versions of the file.</p>");
 }
 
 ?>
@@ -149,14 +163,14 @@ if (!isset($headers["X-Actions-File-Version"]) || $headers["X-Actions-File-Versi
   </div>
 
   <div class="box">
-   <form action="step2.php" method="post">
+   <form action="<?php echo($submit_target); ?>" method="post">
 
     <table border="0" cellpadding="0" cellspacing="4">
 
      <tr>
       <td align="right">URL:</td>
       <td>
-       <input name="referrer_url" value="<?php echo ($url); ?>" type="text" size="45" maxlength="255">
+       <input name="referrer_url" value="<?php echo($url); ?>" type="text" size="45" maxlength="255">
       </td>
      </tr>
 
index 64303d1..539ade1 100644 (file)
   Added Feedback mechanism for actions file
 
 
-  Written by and Copyright (C) 2002 the SourceForge
-  Privoxy team. http://www.privoxy.org/
+  Copyright (C) 2002 the SourceForge Privoxy team.
+  http://www.privoxy.org/
+
+  Written by Andreas Oesterhelt
 
   This program is free software; you can redistribute it
   and/or modify it under the terms of the GNU General
  <head>
   <meta http-equiv="Content-Style-Type" content="text/css">
   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-  <style type="text/css">
-   body,td,th { font-family:helvetica,helv,arial,sans-serif; font-size:10px }
-   body { background-color: #ffffff; color: #000000 }
-   h1 { font-size: 140%; marign: 0px; }
-   h2 { font-size: 120%; marign: 0px; }
-   div.title    { background-color:#dddddd; border:solid black 1px; margin:20px; padding:20px; }
-   div.box      { background-color:#eeeeee; border:solid black 1px; margin:20px; padding:20px; }
-   div.infobox  { background-color:#ccccff; border:solid black 1px; margin:20px; padding:20px; width: 60%; }
-   div.errorbox { background-color:#ffdddd; border:solid black 1px; margin:20px; padding:20px; width: 60%; }
-  </style>
+  <link rel="stylesheet" type="text/css" href="../p_feedback.css">
 
   <script language="javascript" type="text/javascript">
   <!--
  * For testing: 
  */
 //phpinfo();
-//error_reporting(E_ALL);
-error_reporting(E_NONE);
+error_reporting(E_ALL);
+//error_reporting(E_NONE);
 
+/*
+ * Function: link_to_absolute
+ * Purpose:  Make links from $base absolute
+ */
+function link_to_absolute($base, $link)
+{
+   /*
+    * If $link already is absolute, we're done:
+    */
+   if (!strncmp("http://", $link, 7) || !strncmp("https://", $link, 8))
+   {
+      return $link;
+   }
 
-/* 
- * Cannot start with step 2:
+   /*
+    * Cut the base to it's proto://host/ or to its proto://host/dir/,
+    * depending whether $link is host-relative or path-relative.
+    */
+   if ($link{0} == "/")
+   {
+      /*
+       * host-relative:
+       */
+       preg_match('|^(https?://[^/]+)|i', $base, $results);
+       $base = $results[1];
+   }
+   else
+   {
+      /*
+       * path-relative:
+       */
+      if (strpos($base, '/') != strlen($base))
+      {
+         $base = substr($base, 0, -strpos(strrev($base), '/'));
+      }
+   }
+   return $base.$link;
+}
+
+/*
+ * Function: error_abort
+ * Purpose:  Return an error page with $title and $message
  */
-if (!isset($referrer_url))
+function error_abort($title, $message)
 {
-   echo ("  <title>Invalid Feedback Submission</title>
+   if ($title == "invalid") /* shortcut */
+   {
+      $title = "Invalid Feedback Submission";
+   }
+
+   echo ("  <title>Privoxy: $title</title>
            </head>
            <body>
-            <div class=\"title\"><h1>Invalid Feedback Submission</h1></div>
+            <div class=\"title\">
+             <h1>
+              <a href=\"http://www.privoxy.org/\">Privoxy</a>: $title
+              </h1>
+             </div>
             <center>
-             <div class=\"errorbox\">When submitting your feedback please start with
-              <a href=\"index.php\">step 1</a>.
+             <div class=\"errorbox\">
+              $message
              </div>
             </center>
             <p>Valid <a href=\"http://validator.w3.org/\">HTML 4.01 Transitional</a></p>
@@ -135,25 +176,32 @@ if (!isset($referrer_url))
    exit; 
 }
 
+/* 
+ * Cannot start with step 2:
+ */
+if (!isset($referrer_url))
+{
+   error_abort("invalid", "When submitting your feedback please start with
+                <a href=\"index.php\">step 1</a>.");
+}
+
 
 /* 
  * Cannot work on unknown problem:
  */
 if (!isset($problem) || $problem == "INVALID")
 {
-   echo ("  <title>Invalid Feedback Submission</title>
-           </head>
-           <body>
-            <div class=\"title\"><h1>Invalid Feedback Submission</h1></div>
-            <center>
-             <div class=\"errorbox\">You need to select the nature of the problem in
-              <a href=\"javascript:history.back();\">step 1</a>.
-             </div>
-            </center>
-           <p>Valid <a href=\"http://validator.w3.org/\">HTML 4.01 Transitional</a></p>
-           </body>
-          </html>\n");
-   exit; 
+   error_abort("invalid", "You need to select the nature of the problem in
+                <a href=\"javascript:history.back();\">step 1</a>.");
+}
+
+
+/*
+ * If the protocol is missing from $referrer_url, prepend "http://"
+ */
+if (strncmp("http://", $referrer_url, 7))
+{
+   $referrer_url = "http://" . $referrer_url;
 }
 
 
@@ -166,6 +214,11 @@ if (!isset($problem) || $problem == "INVALID")
  *        curls options for Timeouts and HTTP error handling
  *        are not supported by fopen().
  */
+
+
+/*
+ * Slurp the page in:
+ */
 $ch = curl_init ($referrer_url);
 
 curl_setopt ($ch, CURLOPT_HEADER, 0);
@@ -182,25 +235,29 @@ curl_close ($ch);
 
 if (!$success)
 {
-   echo ("  <title>Invalid Feedback Submission</title>
-           </head>
-           <body>
-            <div class=\"title\"><h1>Invalid Feedback Submission</h1></div>
-            <center>
-             <div class=\"errorbox\">
-              <p>The URL that you entered (<a href=\"$referrer_url\">$referrer_url</a>)
-               <br>could not be retrieved.
-              </p>
-              <p>Make sure the URL is correct and publicly accessible.</p>
-              <p><a href=\"javascript:history.back();\">Back to step 1</a></p>
-             </div>
-            </center>
-            <p>Valid <a href=\"http://validator.w3.org/\">HTML 4.01 Transitional</a></p>
-           </body>
-          </html>\n");
-   exit; 
+   $url_confirm = "
+     <dt>
+      <p><b>Confirm the URL:</b></p>
+     </dt>
+     <dd>
+      <p>
+       The URL that you entered could not be retrieved. Please make sure that
+      </p>
+      <p class=\"important\">
+       <a href=\"$referrer_url\">$referrer_url</a>
+      </p>
+      <p>
+       is correct and publicly accssible.
+      </p>
+      <p>
+       <input type=\"checkbox\" name=\"url_confirmed\" value=\"user\"> Yes, I'm sure.
+      </p>
+     </dd>";
+}
+else
+{
+   $url_confirm = "<input type=\"hidden\" name=\"url_confirmed\" value=\"automatic\">";
 }
-
 
 /* 
  * Create description from problem code:
@@ -244,7 +301,13 @@ switch($problem)
 <?php
 
 /*
- * Create / suppress for elements depending on type of
+ * Include the confirmation for an unretrievable URL if
+ * necessary
+ */
+echo ($url_confirm);
+
+/*
+ * Create / suppress form elements depending on type of
  * problem
  */
 if ($problem != "P1")
@@ -258,33 +321,13 @@ else
     * absolute, and present them (scaled to reasonable size)
     * in a table for the user to select
     */
+
    preg_match_all('|<img\s+[^>]*?src=[\'"]?(.*?)[\'" >]|i', $page, $matches);
    $image_urls = array_values(array_unique($matches[1]));
    $count = count($image_urls);
 
    if ($count > 0)
    {
-      /* 
-       * Base URL ends in slash: don't touch.
-       */
-      if (strpos(strrev($referrer_url), '/') == 0)
-      {
-         $referrer_base = $referrer_url;
-      }
-      /* 
-       * Else grab URL up to last slash as base.
-       */
-      else
-      {
-         $referrer_base = substr($referrer_url, 0, -strpos(strrev($referrer_url), '/'));
-      }
-
-      /* 
-       * Get the protocol + host info for relative links
-       * that start with slash. FIXME: Cut trailing slash off!
-       */
-      $referrer_host = "http://".strrev(strrchr(strrev(substr($referrer_url, 7)), "/"));
-
       /*
        * Open section in <dl>; Open table:
        */
@@ -298,22 +341,7 @@ else
        */
       for ($i=0; $i< $count; $i++)
       {
-         $image_url = $image_urls[$i];
-         /*
-          * Make image URLs absolute:
-          */
-         if (strncmp("http://", $image_url, 7))
-         {
-            if ($image_url{0} == "/")
-            {
-               $image_url = $referrer_host.$image_url;
-            }
-            else
-            {
-               $image_url = $referrer_base.$image_url;
-            }
-         }
+         $image_url = link_to_absolute($referrer_url, $image_urls[$i]);
 
          /*
           * Print the row(s):
@@ -397,7 +425,7 @@ else
      </dd>
 
      <dt>
-      <b>Your Name:</b> <i>(optional)</i>
+      <b>Your Name:</b> <i>(optional, public)</i>
      </dt>
      <dd>
       <p>
index 441bb3b..deb79a3 100644 (file)
  -->
 
  <head>
-  <style type="text/css">
-   body, div, p, h1, h2, ul, ol, li, td, th, dl, dt, dd { font-family:helvetica,helv,arial,sans-serif; font-size:10px }
-   body { background-color: #ffffff }
-   div.title    { background-color:#dddddd; border:solid black 1px; margin:20px; min-width: 80%; padding:20px; font-size:15px; font-weight:bold }
-   div.box      { background-color:#eeeeee; border:solid black 1px; margin:20px; min-width: 80%; padding:20px; font-size:10px }
-   div.infobox  { background-color:#ccccff; border:solid black 1px; margin:20px; min-width: 60%; max-width: 60%; padding:20px; font-size:10px; }
-   div.errorbox { background-color:#ffdddd; border:solid black 1px; margin:20px; min-width: 60%; max-width: 60%; padding:20px; font-size:10px; }
-  </style>
+  <meta http-equiv="Content-Style-Type" content="text/css">
+  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+  <link rel="stylesheet" type="text/css" href="../p_feedback.css">
+
 
 <?php
 
 /* 
- * For testing:
+ * Config:
+ */
+$logfile = "results/actions-feedback.txt";
+
+
+/* 
+ * Debug:
  */
 //phpinfo();
 //error_reporting(E_ALL);
 error_reporting(E_NONE);
 
-
-
-/* 
- * Cannot start with step 3:
+/*
+ * Function: error_abort
+ * Purpose:  Return an error page with $title and $message
  */
-if (!isset($referrer_url))
+function error_abort($title, $message)
 {
-   echo ("  <title>Invalid Feedback Submission</title>
+   if ($title == "invalid") /* shortcut */
+   {
+      $title = "Invalid Feedback Submission";
+   }
+
+   echo ("  <title>Privoxy: $title</title>
            </head>
            <body>
-            <div class=\"title\">Invalid Feedback Submission</div>
-            <div align=\"center\">
-             <div class=\"errorbox\" align=\"left\">
-              When submitting your feedback please start with <a href=\"index.php\">step 1</a>.
+            <div class=\"title\">
+             <h1>
+              <a href=\"http://www.privoxy.org/\">Privoxy</a>: $title
+              </h1>
              </div>
-            </div>
+            <center>
+             <div class=\"errorbox\">
+              $message
+             </div>
+            </center>
+            <p>Valid <a href=\"http://validator.w3.org/\">HTML 4.01 Transitional</a></p>
            </body>
-          </html>");
+          </html>\n");
    exit; 
 }
 
 
+/* 
+ * Cannot start with step 3:
+ */
+if (!isset($referrer_url))
+{
+   error_abort("invalid", "When submitting your feedback please start with <a href=\"index.php\">step 1</a>.");
+}
+
+
 /* 
  * Cannot work on unknown problem:
  */
 if (!isset($problem))
 {
-   echo ("  <title>Invalid Feedback Submission</title>
-           </head>
-           <body>
-            <div class=\"title\">Invalid Feedback Submission</div>
-            <div align=\"center\">
-             <div class=\"errorbox\" align=\"left\">
-              You need to select the nature of the problem in <a href=\"index.php\">step 1</a>.
-             </div>
-            </div>
-           </body>
-          </html>");
-   exit; 
+   error_abort("invalid", "You need to select the nature of the problem in <a href=\"index.php\">step 1</a>.");
+}
+
+
+/* 
+ * Don't accept unconfirmed URLs
+ */
+if (!isset($url_confirmed))
+{
+   error_abort("invalid", "When submitting URLs that this script can't retrieve, you need to check \"Yes, I'm sure\"
+                <a href=\"javascript:history.back();\">step 2</a>.");
 }
 
 
@@ -117,7 +136,6 @@ if (!isset($name) || ($name == ""))
 /* 
  * Open the logfile or fail:
  */
-$logfile = "feedback-data.txt";
 $fp = fopen($logfile, "a");
 
 if(!$fp)
@@ -125,9 +143,11 @@ if(!$fp)
    echo ("  <title>Internal Script Error</title>
            </head>
            <body>
-            <div class=\"title\">Internal Script Error</div>
-            <div align=\"center\">
-             <div class=\"errorbox\" align=\"left\">
+            <div class=\"title\">
+              <h1><a href=\"http://www.privoxy.org/\">Privoxy</a>: Internal Script Error</h1>
+            </div>
+            <center>
+             <div class=\"errorbox\">
               <p>
                This script was unable to open its logfile.
               </p>
@@ -135,7 +155,7 @@ if(!$fp)
                Please <a href=\"mailto:info@privoxy.org?SUBJECT=Feedback-Script-Broken\">mail its owner</a>!
               </p>
              </div>
-            </div>
+            </center>
            </body>
           </html>");
    exit; 
@@ -146,7 +166,7 @@ if(!$fp)
  * Write Head (type, severity, user, client-ip)
  * and remarks field:
  */
-fwrite($fp, "\n#FEEDBACK TYPE $problem SEVERITY $severity FROM $name ON $REMOTE_ADDR\n");
+fwrite($fp, "\n#FEEDBACK TYPE $problem SEVERITY $severity FROM $name ON $REMOTE_ADDR VERIFIED $url_verified TIME " . date("r") ."\n");
 if (isset($remarks))
 {
    $lines = explode("\n", $remarks);
@@ -212,7 +232,9 @@ fclose($fp);
 
  <body>
   <div class="title">
-   <a href="http://www.privoxy.org" target="_blank">Privoxy</a> Action List Feedback - Result
+   <h1>
+    <a href="http://www.privoxy.org" target="_blank">Privoxy</a> Action List Feedback - Result
+   </h1>
   </div>
 
   <div class="box">
@@ -230,5 +252,8 @@ fclose($fp);
    </p>
 
   </div>
+
+  <p>Valid <a href="http://validator.w3.org/">HTML 4.01 Transitional</a></p>
+
  </body>
 </html>