Clean-up, smarter handling of unreachable URLs
[privoxy.git] / doc / webserver / actions / step2.php
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3  <!--
4
5   File :  $Source: /cvsroot/ijbswa/current/doc/webserver/actions/step2.php,v $
6
7   Purpose  :  Submit form for actions file feedback (step 2)
8               This file belongs in
9               ijbswa.sourceforge.net:/home/groups/i/ij/ijbswa/htdocs/
10
11   $Id: step2.php,v 1.6 2002/04/02 07:22:19 oes Exp $
12
13   $Log: step2.php,v $
14   Revision 1.6  2002/04/02 07:22:19  oes
15   Elimnating duplicate images; using relative link for step3
16
17   Revision 1.4  2002/04/01 19:13:47  oes
18   Extended, fixed bugs, beefed up design, made IE-safe
19
20   Revision 1.1  2002/03/30 03:20:30  oes
21   Added Feedback mechanism for actions file
22
23
24   Copyright (C) 2002 the SourceForge Privoxy team.
25   http://www.privoxy.org/
26
27   Written by Andreas Oesterhelt
28
29   This program is free software; you can redistribute it
30   and/or modify it under the terms of the GNU General
31   Public License as published by the Free Software
32   Foundation; either version 2 of the License, or (at
33   your option) any later version.
34
35   This program is distributed in the hope that it will
36   be useful, but WITHOUT ANY WARRANTY; without even the
37   implied warranty of MERCHANTABILITY or FITNESS FOR A
38   PARTICULAR PURPOSE.  See the GNU General Public
39   License for more details.
40
41   The GNU General Public License should be included with
42   this file.  If not, you can view it at
43   http://www.gnu.org/copyleft/gpl.html
44   or write to the Free Software Foundation, Inc., 59
45   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
46
47  -->
48
49  <head>
50   <meta http-equiv="Content-Style-Type" content="text/css">
51   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
52   <link rel="stylesheet" type="text/css" href="../p_feedback.css">
53
54   <script language="javascript" type="text/javascript">
55   <!--
56    //
57    // Could be as easy as style="max-wdith: 300px; max-height..." inside the
58    // <img> tag, but IE doesn't do that. Setting the values directly also
59    // screws IE for some weird reason. All praise MS.
60    //
61
62    function prettyscale(image)
63    {
64       newwidth = 0
65       newheight = 0
66
67       if (image.width > 300)
68       {
69          newwidth = 300
70       }
71
72       if (image.height > 50)
73       {
74          newheight = 50
75       }
76
77       if (image.width < 20)
78       {
79          newwidth = 20
80       }
81
82       if (image.height < 20)
83       {
84          newheight = 20
85       }
86
87       if (newwidth != 0)
88       {
89          image.width = newwidth
90       }
91
92       if (newheight != 0)
93       {
94          image.height = newheight
95       }
96    }
97   //-->
98   </script>
99
100
101 <?php
102
103 /*
104  * For testing: 
105  */
106 //phpinfo();
107 error_reporting(E_ALL);
108 //error_reporting(E_NONE);
109
110 /*
111  * Function: link_to_absolute
112  * Purpose:  Make links from $base absolute
113  */
114 function link_to_absolute($base, $link)
115 {
116    /*
117     * If $link already is absolute, we're done:
118     */
119    if (!strncmp("http://", $link, 7) || !strncmp("https://", $link, 8))
120    {
121       return $link;
122    }
123
124    /*
125     * Cut the base to it's proto://host/ or to its proto://host/dir/,
126     * depending whether $link is host-relative or path-relative.
127     */
128    if ($link{0} == "/")
129    {
130       /*
131        * host-relative:
132        */
133        preg_match('|^(https?://[^/]+)|i', $base, $results);
134        $base = $results[1];
135    }
136    else
137    {
138       /*
139        * path-relative:
140        */
141       if (strpos($base, '/') != strlen($base))
142       {
143          $base = substr($base, 0, -strpos(strrev($base), '/'));
144       }
145    }
146    return $base.$link;
147 }
148
149 /*
150  * Function: error_abort
151  * Purpose:  Return an error page with $title and $message
152  */
153 function error_abort($title, $message)
154 {
155    if ($title == "invalid") /* shortcut */
156    {
157       $title = "Invalid Feedback Submission";
158    }
159
160    echo ("  <title>Privoxy: $title</title>
161            </head>
162            <body>
163             <div class=\"title\">
164              <h1>
165               <a href=\"http://www.privoxy.org/\">Privoxy</a>: $title
166               </h1>
167              </div>
168             <center>
169              <div class=\"errorbox\">
170               $message
171              </div>
172             </center>
173             <p>Valid <a href=\"http://validator.w3.org/\">HTML 4.01 Transitional</a></p>
174            </body>
175           </html>\n");
176    exit; 
177 }
178
179 /* 
180  * Cannot start with step 2:
181  */
182 if (!isset($referrer_url))
183 {
184    error_abort("invalid", "When submitting your feedback please start with
185                 <a href=\"index.php\">step 1</a>.");
186 }
187
188
189 /* 
190  * Cannot work on unknown problem:
191  */
192 if (!isset($problem) || $problem == "INVALID")
193 {
194    error_abort("invalid", "You need to select the nature of the problem in
195                 <a href=\"javascript:history.back();\">step 1</a>.");
196 }
197
198
199 /*
200  * If the protocol is missing from $referrer_url, prepend "http://"
201  */
202 if (strncmp("http://", $referrer_url, 7))
203 {
204    $referrer_url = "http://" . $referrer_url;
205 }
206
207
208 /*
209  * Check if URL really exists and buffer its contents:
210  *
211  * FIXME: Curl is not installed on SF; Filed as Alexandria
212  *        Feature Request #537014. 
213  *        PHP's fopen() supports URLs, but it seems that
214  *        curls options for Timeouts and HTTP error handling
215  *        are not supported by fopen().
216  */
217
218
219 /*
220  * Slurp the page in:
221  */
222 $ch = curl_init ($referrer_url);
223
224 curl_setopt ($ch, CURLOPT_HEADER, 0);
225 curl_setopt ($ch, CURLOPT_FAILONERROR, 1);
226 curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
227 curl_setopt ($ch, CURLOPT_TIMEOUT, 20);            
228
229 ob_start();
230 $success = curl_exec ($ch);
231 $page = ob_get_contents();
232 ob_end_clean();
233
234 curl_close ($ch);
235
236 if (!$success)
237 {
238    $url_confirm = "
239      <dt>
240       <p><b>Confirm the URL:</b></p>
241      </dt>
242      <dd>
243       <p>
244        The URL that you entered could not be retrieved. Please make sure that
245       </p>
246       <p class=\"important\">
247        <a href=\"$referrer_url\">$referrer_url</a>
248       </p>
249       <p>
250        is correct and publicly accssible.
251       </p>
252       <p>
253        <input type=\"checkbox\" name=\"url_confirmed\" value=\"user\"> Yes, I'm sure.
254       </p>
255      </dd>";
256 }
257 else
258 {
259    $url_confirm = "<input type=\"hidden\" name=\"url_confirmed\" value=\"automatic\">";
260 }
261
262 /* 
263  * Create description from problem code:
264  */
265 switch($problem)
266 {
267    case "P1": $problem_description="an advertisment was not blocked"; break;
268    case "P2": $problem_description="an innocent image was blocked"; break;
269    case "P3": $problem_description="the whole page was erraneously blocked"; break;
270    case "P4": $problem_description="the page needs popups but they don't work"; break;
271    case "P5": $problem_description="a problem occured"; break;
272    default: $problem_description="AN UNPROCESSABLE PROBLEM OCCURED";
273 }
274
275 ?>
276
277   <title>Privoxy Action List Feedback - Step 2 of 2</title>
278  </head>
279  <body>
280
281   <div class="title">
282    <h1>
283      <a href="http://www.privoxy.org" target="_blank">Privoxy</a> Action List Feedback - Step 2 of 2
284    </h1>
285   </div>
286
287   <div class="box">
288    <b>You are about to report that <?php echo ($problem_description) ?> on
289    <a href="<?php echo ($referrer_url) ?>"><?php echo ($referrer_url) ?></a>.</b>
290   </div>
291
292   <div class="box">
293    <form action="step3.php" method="post">
294     <p>
295      <input type="hidden" name="problem" value="<?php echo ($problem) ?>">
296      <input type="hidden" name="referrer_url" value="<?php echo ($referrer_url) ?>">
297     </p>
298
299     <dl>
300
301 <?php
302
303 /*
304  * Include the confirmation for an unretrievable URL if
305  * necessary
306  */
307 echo ($url_confirm);
308
309 /*
310  * Create / suppress form elements depending on type of
311  * problem
312  */
313 if ($problem != "P1")
314 {
315    echo ("<!--");
316 }
317 else
318 {
319    /*
320     * Extract all image links from page, make them
321     * absolute, and present them (scaled to reasonable size)
322     * in a table for the user to select
323     */
324
325    preg_match_all('|<img\s+[^>]*?src=[\'"]?(.*?)[\'" >]|i', $page, $matches);
326    $image_urls = array_values(array_unique($matches[1]));
327    $count = count($image_urls);
328
329    if ($count > 0)
330    {
331       /*
332        * Open section in <dl>; Open table:
333        */
334       echo ("     <dt><b>Choose the images you want blocked from the following list:</b></dt>
335                   <dd>
336                    <p>
337                     <input type=\"hidden\" name=\"num_images\" value=\"$count\">
338                     <table border=\"0\" cellpadding=\"0\" cellspacing=\"4\">\n");
339       /*
340        * Print one table row for each image found:
341        */
342       for ($i=0; $i< $count; $i++)
343       {
344          $image_url = link_to_absolute($referrer_url, $image_urls[$i]);
345
346          /*
347           * Print the row(s):
348           */
349          echo ("       <tr>
350                         <td rowspan=\"2\">
351                          <input type=\"checkbox\" name=\"block_image[$i]\" value=\"off\">
352                         </td>
353                         <td>
354                          <a href=\"$image_url\">$image_url</a>:
355                         </td>
356                         <td>
357                          <input type=\"hidden\" name=\"image_url[$i]\" value=\"$image_url\">
358                         </td>
359                        </tr>
360                        <tr>
361                         <td>
362                          <img onload=\"prettyscale(this);\" src=\"$image_url\" alt=\"banner or not?\">
363                         </td>
364                        </tr>\n");
365       }
366       echo ("      </table>
367                   </dd>
368
369                   <dt>
370                    <b>If the banner that you saw is not listed above, enter the URL here</b>\n");
371    }
372    else
373    {
374       echo ("     <dt>
375                    <b>URL of the advertisment image:</b>\n");
376    }
377 }
378
379 ?>
380
381       <br><i>Hint: right-click the image, select "Copy image location" and paste the URL here.</i>
382      </dt>
383      <dd>
384       <p>
385        <input name="manual_image_url" type="text" size="45" maxlength="255">
386       </p>
387      </dd>
388
389 <?php if($problem != "P1") echo ("-->") ?>
390
391 <?php if($problem != "P2") echo ("<!--") ?>
392
393      <dt>
394       <p><b>URL of the innocent image:</b>
395        <br><i>Hint: right-click the image, select "Copy image location" and paste the URL here.
396        <br>This may not work if the image was blocked by size or if +image-blocker is set to redirect.</i>
397       </p>
398      </dt>
399      <dd>
400       <p>
401        <input name="image_url" value="unknown" type="text" size="45" maxlength="255">
402       </p>
403      </dd>
404
405 <?php if($problem != "P2") echo ("-->") ?>
406
407      <dt><b>Severity:</b></dt>
408      <dd>
409       <p>
410        <select name="severity">
411         <option value="3">drives me crazy</option>
412         <option selected value="2">normal</option>
413         <option value="1">cosmetic</option>
414        </select>
415       </p>
416      </dd>
417
418      <dt>
419       <b>Remarks:</b> <i>(optional)</i>
420      </dt>
421      <dd>
422       <p>
423        <textarea wrap="hard" style="font-size: 10px" name="remarks" cols="35" rows="3">None.</textarea>
424       </p>
425      </dd>
426
427      <dt>
428       <b>Your Name:</b> <i>(optional, public)</i>
429      </dt>
430      <dd>
431       <p>
432        <input name="name" size="45">
433       </p>
434      </dd>
435
436      <dt>&nbsp;</dt>
437      <dd>
438       <input type="submit" value="Submit">
439      </dd>
440
441     </dl>
442    </form>
443   </div>
444
445   <p>Valid <a href="http://validator.w3.org/">HTML 4.01 Transitional</a></p>
446
447  </body>
448 </html>