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