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