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