Tracker submit via curl (no need for user to see), fixing problems, removing monster...
[privoxy.git] / doc / webserver / actions / step3.php
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3  <!--
4
5   File :  $Source: /cvsroot/ijbswa/current/doc/webserver/actions/step3.php,v $
6
7   Purpose  :  Submit form for actions file feedback (step 1)
8               This file belongs in
9               ijbswa.sourceforge.net:/home/groups/i/ij/ijbswa/htdocs/
10
11   $Id: step3.php,v 1.12 2002/04/06 18:57:38 swa Exp $
12
13   $Log: step3.php,v $
14   Revision 1.12  2002/04/06 18:57:38  swa
15   first version of the script that writes the
16   logfile with all submissions and additionally
17   submits the entries to our tracker.
18
19   Revision 1.11  2002/04/06 15:54:08  swa
20   prework: list of what needs to
21   be submitted to the tracker.
22
23   Revision 1.10  2002/04/06 15:19:35  oes
24   Clean-up, smarter handling of unreachable URLs
25
26   Revision 1.9  2002/04/06 11:34:44  oes
27   Cosmetics
28
29   Revision 1.8  2002/04/04 19:48:11  oes
30   Reactivating the scripts ,-)
31
32   Revision 1.7  2002/04/04 10:29:58  oes
33   Keeping feedback confidential
34
35   Revision 1.6  2002/04/03 19:36:04  swa
36   consistent look
37
38   Revision 1.5  2002/04/02 07:22:43  oes
39   Cosmetics
40
41   Revision 1.4  2002/04/01 19:13:47  oes
42   Extended, fixed bugs, beefed up design, made IE-safe
43
44   Revision 1.3  2002/03/30 20:44:46  swa
45   have consistent look and feel. part 2.
46   use correct urls.
47
48   Revision 1.2  2002/03/30 19:49:34  swa
49   have consistent look and feel
50
51   Revision 1.1  2002/03/30 03:20:30  oes
52   Added Feedback mechanism for actions file
53
54
55   Copyright (C) 2002 the SourceForge Privoxy team.
56   http://www.privoxy.org/
57
58   Written by Andreas Oesterhelt
59
60   This program is free software; you can redistribute it
61   and/or modify it under the terms of the GNU General
62   Public License as published by the Free Software
63   Foundation; either version 2 of the License, or (at
64   your option) any later version.
65
66   This program is distributed in the hope that it will
67   be useful, but WITHOUT ANY WARRANTY; without even the
68   implied warranty of MERCHANTABILITY or FITNESS FOR A
69   PARTICULAR PURPOSE.  See the GNU General Public
70   License for more details.
71
72   The GNU General Public License should be included with
73   this file.  If not, you can view it at
74   http://www.gnu.org/copyleft/gpl.html
75   or write to the Free Software Foundation, Inc., 59
76   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
77
78  -->
79
80  <head>
81   <meta http-equiv="Content-Style-Type" content="text/css">
82   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
83   <link rel="stylesheet" type="text/css" href="../p_feedback.css">
84
85
86 <?php
87
88 /* 
89  * Config:
90  */
91 $logfile = "results/actions-feedback.txt";
92
93
94 /* 
95  * Debug:
96  */
97 //phpinfo();
98 //error_reporting(E_ALL);
99 error_reporting(E_NONE);
100
101 /*
102  * Function: error_abort
103  * Purpose:  Return an error page with $title and $message
104  */
105 function error_abort($title, $message)
106 {
107    if ($title == "invalid") /* shortcut */
108    {
109       $title = "Invalid Feedback Submission";
110    }
111
112    echo ("  <title>Privoxy: $title</title>
113            </head>
114            <body>
115             <div class=\"title\">
116              <h1>
117               <a href=\"http://www.privoxy.org/\">Privoxy</a>: $title
118               </h1>
119              </div>
120             <center>
121              <div class=\"errorbox\">
122               $message
123              </div>
124             </center>
125             <p>Valid <a href=\"http://validator.w3.org/\">HTML 4.01 Transitional</a></p>
126            </body>
127           </html>\n");
128    exit; 
129 }
130
131
132 /* 
133  * Cannot start with step 3:
134  */
135 if (!isset($referrer_url))
136 {
137    error_abort("invalid", "When submitting your feedback please start with <a href=\"index.php\">step 1</a>.");
138 }
139
140
141 /* 
142  * Cannot work on unknown problem:
143  */
144 if (!isset($problem))
145 {
146    error_abort("invalid", "You need to select the nature of the problem in <a href=\"index.php\">step 1</a>.");
147 }
148
149
150 /* 
151  * Don't accept unconfirmed URLs
152  */
153 if (!isset($url_confirmed))
154 {
155    error_abort("invalid", "When submitting URLs that this script can't retrieve, you need to check \"Yes, I'm sure\"
156                 <a href=\"javascript:history.back();\">step 2</a>.");
157 }
158
159
160 /*
161  * Handle optional text fields:
162  */
163 if (!isset($name) || ($name == ""))
164 {
165    $name = "anonymous";
166 }
167
168
169 /* 
170  * Open the logfile or fail:
171  */
172 $fp = fopen($logfile, "a");
173
174 if(!$fp)
175 {
176    echo ("  <title>Internal Script Error</title>
177            </head>
178            <body>
179             <div class=\"title\">
180               <h1><a href=\"http://www.privoxy.org/\">Privoxy</a>: Internal Script Error</h1>
181             </div>
182             <center>
183              <div class=\"errorbox\">
184               <p>
185                This script was unable to open its logfile.
186               </p>
187               <p>
188                Please <a href=\"mailto:info@privoxy.org?SUBJECT=Feedback-Script-Broken\">mail its owner</a>!
189               </p>
190              </div>
191             </center>
192            </body>
193           </html>");
194    exit; 
195 }
196
197
198 /*
199  * Write Head (type, severity, user, client-ip)
200  * and remarks field:
201  */
202 fwrite($fp, "\n#FEEDBACK TYPE $problem SEVERITY $severity FROM $name ON $REMOTE_ADDR VERIFIED $url_confirmed TIME " . date("r") ."\n");
203 if (isset($remarks))
204 {
205    $lines = explode("\n", $remarks);
206    foreach ($lines as $line)
207    {
208       fwrite($fp, "#REMARKS: $line\n");
209    }
210 }
211
212
213 /*
214  * Depending on the type of problem reported,
215  * we need to write additional data:
216  */
217 switch ($problem)
218 {
219    /*
220     * Banner not blocked:
221     */
222    case "P1":
223       fwrite($fp, "#BLOCK-REFERRER: $referrer_url\n");
224       if (isset($num_images))
225       {
226          for($i=0; $i < $num_images; $i++)
227          {
228              if (isset($block_image[$i]))
229              {
230                 fwrite($fp, "#BLOCK-URL: $image_url[$i]\n");
231                 $trackertext .= "Block image: $image_url[$i]\n";
232              }
233          }
234       }
235       if (isset($manual_image_url) && ($manual_image_url != ""))
236       {
237          fwrite($fp, "#BLOCK-URL: $manual_image_url\n");
238          $trackertext .= "Block image: $manual_image_url\n";
239       }
240       break;
241
242    /*
243     * Innocent image blocked:
244     */
245    case "P2":
246       fwrite($fp, "#UNBLOCK-REFERRER: $referrer_url\n");
247       if (isset($image_url) && ($image_url != ""))
248       {
249          fwrite($fp, "#UNBLOCK-URL: $image_url\n");
250          $trackertext .= "Unblock image: $image_url\n";
251       }
252       break;
253
254    /*
255     * All other problems:
256     */
257    default:
258       fwrite($fp, "#PROBLEM-URL: $referrer_url\n");
259       break;
260 }        
261             
262 fclose($fp);
263
264 /*
265  * Notify our SF tracker that new data is waiting to be
266  * processed
267  */
268 switch($problem)
269 {
270    case "P1": $category_id="412811"; $summary = "Ad not blocked "; break;
271    case "P2": $category_id="412810"; $summary = "Image blocked ";break;
272    case "P3": $category_id="412812"; $summary = "Page plocked ";break;
273    case "P4": $category_id="412813"; $summary = "Popups blocked ";break;
274    case "P5": $category_id="412814"; $summary = "Other problem ";break;
275    default:   $category_id="412814"; $summary = "IMPOSSIBLE ";break;
276 }
277
278 $summary .= date("U"); /* Must be unique */
279 $priority = 3 * $severity;
280
281 $details = urlencode("On " . date("r") . " new data was received from $name:\n"
282                     ."URL: $referrer_url\n$trackertext\nRemarks:\n\n$remarks");
283
284 $postfields = ( "group_id=11118&atid=460288&func=postadd&category_id=$category_id&artifact_group_id=195890" .
285                 "&priority=$priority&summary=$summary&details=$details" );
286
287 $ch = curl_init ("http://sourceforge.net/tracker/index.php");
288 curl_setopt($ch, CURLOPT_HEADER, 0);
289 curl_setopt($ch, CURLOPT_FAILONERROR, 1);
290 curl_setopt($ch, CURLOPT_TIMEOUT, 20);            
291 curl_setopt($ch, CURLOPT_POST, 1);
292 curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
293
294 ob_start();
295 curl_exec($ch);
296 ob_end_clean();
297
298 curl_close ($ch);
299
300 ?>
301
302   <title>Privoxy Action List Feedback - Result</title>
303  </head>
304
305  <body>
306   <div class="title">
307    <h1>
308     <a href="http://www.privoxy.org" target="_blank">Privoxy</a> Action List Feedback - Result
309    </h1>
310   </div>
311
312   <div class="box">
313    <p>
314     <b>Thank you very much for taking the time to submit your feedback!</b>
315    </p>
316
317    <p>
318     It will be reviewed by the developers and used to improve the
319     distribution actions file.
320    </p>
321    
322    <p align=center>
323     <input type="submit" value="Close this window" onclick="window.close();">
324    </p>
325
326   </div>
327
328   <p>Valid <a href="http://validator.w3.org/">HTML 4.01 Transitional</a></p>
329
330  </body>
331 </html>