bug 1200: Use a freshly created temporary directory as gpg homedir
[cacert-devel.git] / www / wot.php
1 <? /*
2 LibreSSL - CAcert web application
3 Copyright (C) 2004-2008 CAcert Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */ ?>
18 <?
19 require_once("../includes/loggedin.php");
20 require_once("../includes/lib/l10n.php");
21
22
23 function show_page($target,$message,$error)
24 {
25 showheader(_("My CAcert.org Account!"));
26 if ($error != "")
27 $message=_("ERROR").": ".$error;
28 if ($message != "")
29 echo "<p><font color='orange' size='+1'>".$message."</font></p>";
30
31 switch ($target)
32 {
33 case '0':
34 case 'InfoPage': includeit(0, "wot");
35 break;
36 case '1':
37 case 'ListByCity': includeit(1, "wot");
38 break;
39 case '2':
40 case 'BecomeAssurer': includeit(2, "wot");
41 break;
42 case '3':
43 case 'TrustRules': includeit(3, "wot");
44 break;
45 case '4':
46 case 'ShowTTPInfo': includeit(4, "wot");
47 break;
48 case '5';
49 case 'EnterEmail': includeit(5, "wot");
50 break;
51 case '6':
52 case 'VerifyData': includeit(6, "wot");
53 break;
54 // case '7':
55 // case '???': includeit(7, "wot");
56 // break;
57 case '8':
58 case 'EnterMyInfo': includeit(8, "wot");
59 break;
60 case '9':
61 case 'ContactAssurer': includeit(9, "wot");
62 break;
63 case '10':
64 case 'MyPointsOld': includeit(10, "wot");
65 break;
66 // case '11':
67 // case 'OAInfo': includeit(11, "wot");
68 // break;
69 case '12':
70 case 'SearchAssurer': includeit(12, "wot");
71 break;
72 case '13':
73 case 'EnterMyCity': includeit(13, "wot");
74 break;
75 // case '14':
76 // case 'EnterEmail': includeit(14, "wot");
77 // break;
78 case '15':
79 case 'MyPointsNew': includeit(15, "wot");
80 break;
81 }
82
83 showfooter();
84 }
85
86 function send_reminder()
87 {
88 $body = "";
89 $my_translation = L10n::get_translation();
90
91 $_SESSION['_config']['reminder-lang'] = $_POST['reminder-lang'];
92
93 $reminder_translations[] = $_POST['reminder-lang'];
94 if ( !in_array("en", $reminder_translations, $strict=true) ) {
95 $reminder_translations[] = "en";
96 }
97
98 foreach ($reminder_translations as $translation) {
99 L10n::set_translation($translation);
100
101 $body .= L10n::$translations[$translation].":\n\n";
102 $body .= sprintf(_("This is a short reminder that you filled out forms to become trusted with CAcert.org, and %s has attempted to issue you points. Please create your account at %s as soon as possible and then notify %s so that the points can be issued."), $_SESSION['profile']['fname']." (".$_SESSION['profile']['email'].")", "http://www.cacert.org", $_SESSION['profile']['fname'])."\n\n";
103 $body .= _("Best regards")."\n";
104 $body .= _("CAcert Support Team")."\n\n";
105 }
106
107 L10n::set_translation($reminder_translations[0]); // for the subject
108 sendmail($_POST['email'], "[CAcert.org] "._("Reminder Notice"), $body, $_SESSION['profile']['email'], "", "", $_SESSION['profile']['fname']);
109
110 L10n::set_translation($my_translation);
111
112 $_SESSION['_config']['remindersent'] = 1;
113 $_SESSION['_config']['error'] = _("A reminder notice has been sent.");
114 }
115
116
117
118
119 loadem("account");
120 if(array_key_exists('date',$_POST) && $_POST['date'] != "")
121 $_SESSION['_config']['date'] = $_POST['date'];
122
123 if(array_key_exists('location',$_POST) && $_POST['location'] != "")
124 $_SESSION['_config']['location'] = $_POST['location'];
125
126 $oldid=array_key_exists('oldid',$_REQUEST)?intval($_REQUEST['oldid']):0;
127
128 if($oldid == 12)
129 $id = $oldid;
130
131 if($oldid == 4)
132 {
133 if ($_POST['ttp']!='') {
134 //This mail does not need to be translated
135 $body = "Hi TTP adminstrators,\n\n";
136 $body .= "User ".$_SESSION['profile']['fname']." ".
137 $_SESSION['profile']['lname']." with email address '".
138 $_SESSION['profile']['email']."' is requesting a TTP assurances for ".
139 mysql_escape_string(stripslashes($_POST['country'])).".\n\n";
140 if ($_POST['ttptopup']=='1') {
141 $body .= "The user is also requesting TTP TOPUP.\n\n";
142 }else{
143 $body .= "The user is NOT requesting TTP TOPUP.\n\n";
144 }
145 $body .= "The user received ".intval($_SESSION['profile']['points'])." assurance points up to today.\n\n";
146 $body .= "Please start the TTP assurance process.";
147 sendmail("support@cacert.org", "[CAcert.org] TTP request.", $body, "support@cacert.org", "", "", "CAcert Website");
148
149 //This mail needs to be translated
150 $body =_("You are receiving this email because you asked for TTP assurance.")."\n\n";
151 if ($_POST['ttptopup']=='1') {
152 $body .=_("You are requesting TTP TOPUP.")."\n\n";
153 }else{
154 $body .=_("You are NOT requesting TTP TOPUP.")."\n\n";
155 }
156 $body .= _("Best regards")."\n";
157 $body .= _("CAcert Support Team");
158
159 sendmail($_SESSION['profile']['email'], "[CAcert.org] "._("You requested TTP assurances"), $body, "support@cacert.org", "", "", "CAcert Support");
160
161 }
162
163 }
164
165 if(($id == 5 || $oldid == 5 || $id == 6 || $oldid == 6))
166 if (!is_assurer($_SESSION['profile']['id']))
167 {
168 show_page ("Exit","",get_assurer_reason($_SESSION['profile']['id']));
169 exit;
170 }
171
172 if($oldid == 6 && intval($_SESSION['_config']['notarise']['id']) <= 0)
173 {
174 show_page ("EnterEmail","",_("Something went wrong. Please enter the email address again"));
175 exit;
176 }
177 if($oldid == 5 && array_key_exists('reminder',$_POST) && $_POST['reminder'] != "")
178 {
179 send_reminder();
180 show_page ("EnterEmail",_("A reminder notice has been sent."),"");
181 exit;
182 }
183
184 if($oldid == 5)
185 {
186 $query = "select * from `users` where `email`='".mysql_escape_string(stripslashes($_POST['email']))."' and `deleted`=0";
187 $res = mysql_query($query);
188 if(mysql_num_rows($res) != 1)
189 {
190 $_SESSION['_config']['noemailfound'] = 1;
191 show_page("EnterEmail","",_("I'm sorry, there was no email matching what you entered in the system. Please double check your information."));
192 exit;
193 } else
194 {
195 $_SESSION['_config']['noemailfound'] = 0;
196 $_SESSION['_config']['notarise'] = mysql_fetch_assoc($res);
197 if ($_SESSION['_config']['notarise']['verified'] == 0)
198 {
199 show_page("EnterEmail","",_("User is not yet verified. Please try again in 24 hours!"));
200 exit;
201 }
202 }
203 $query = "select * from `users` where `email`='".mysql_escape_string(stripslashes($_POST['email']))."' and `locked`=1";
204 $res = mysql_query($query);
205 if(mysql_num_rows($res) >= 1)
206 {
207 $_SESSION['_config']['noemailfound'] = 0;
208 show_page("EnterEmail","",_("This account is locked and can not be assured. For more information ask support@cacert.org."));
209 exit;
210 }
211 }
212
213 if($oldid == 5 || $oldid == 6)
214 {
215 $id=6;
216 // $oldid=0;
217 if(array_key_exists('cancel',$_REQUEST) && $_REQUEST['cancel'] != "")
218 {
219 show_page("EnterEmail","","");
220 exit;
221 }
222 if($_SESSION['_config']['notarise']['id'] == $_SESSION['profile']['id'])
223 {
224 show_page("EnterEmail","",_("You are never allowed to Assure yourself!"));
225 exit;
226 }
227
228 $query = "select * from `notary` where `from`='".$_SESSION['profile']['id']."' and
229 `to`='".$_SESSION['_config']['notarise']['id']."'";
230 $res = mysql_query($query);
231 if(mysql_num_rows($res) > 0)
232 {
233 show_page("EnterEmail","",_("You are only allowed to Assure someone once!"));
234 exit;
235 }
236 }
237
238 if($oldid == 6)
239 {
240 $iecho= "c";
241 if(!array_key_exists('assertion',$_POST) || $_POST['assertion'] != 1)
242 {
243 show_page("VerifyData","",_("You failed to check all boxes to validate your adherence to the rules and policies of CAcert"));
244 exit;
245 }
246
247 /* if(!array_key_exists('rules',$_POST) || $_POST['rules'] != 1)
248 {
249 show_page("VerifyData","",_("You failed to check all boxes to validate your adherence to the rules and policies of CAcert"));
250 exit;
251 }
252 */
253
254 if((!array_key_exists('certify',$_POST) || $_POST['certify'] != 1 ) && $_SESSION['profile']['ttpadmin'] != 1)
255 {
256 show_page("VerifyData","",_("You failed to check all boxes to validate your adherence to the rules and policies of CAcert"));
257 exit;
258 }
259
260 if($_SESSION['profile']['ttpadmin'] != 1 && $_POST['location'] == "")
261 {
262 show_page("VerifyData","",_("You failed to enter a location of your meeting."));
263 exit;
264 }
265
266 if($_REQUEST['points'] == "" || !is_numeric($_REQUEST['points']))
267 {
268 show_page("VerifyData","",_("You must enter the number of points you wish to allocate to this person."));
269 exit;
270 }
271
272 $query = "select * from `users` where `id`='".$_SESSION['_config']['notarise']['id']."'";
273 $res = mysql_query($query);
274 $row = mysql_fetch_assoc($res);
275 $name = $row['fname']." ".$row['mname']." ".$row['lname']." ".$row['suffix'];
276 if($_SESSION['_config']['wothash'] != md5($name."-".$row['dob']) || $_SESSION['_config']['wothash'] != $_REQUEST['pagehash'])
277 {
278 show_page("VerifyData","",_("Race condition discovered, user altered details during assurance procedure. PLEASE MAKE SURE THE NEW DETAILS BELOW MATCH THE ID DOCUMENTS."));
279 exit;
280 }
281 }
282
283
284 if($oldid == 6)
285 {
286 $max = maxpoints();
287
288 $awarded = $newpoints = intval($_POST['points']);
289 if($newpoints > $max)
290 $newpoints = $awarded = $max;
291 if($newpoints < 0)
292 $newpoints = $awarded = 0;
293
294 $query = "select sum(`points`) as `total` from `notary` where `to`='".$_SESSION['_config']['notarise']['id']."' group by `to`";
295 $res = mysql_query($query);
296 $drow = mysql_fetch_assoc($res);
297
298 $_POST['expire'] = 0;
299
300 if(($drow['total'] + $newpoints) > 100 && $max < 100)
301 $newpoints = 100 - $drow['total'];
302 if(($drow['total'] + $newpoints) > $max && $max >= 100)
303 $newpoints = $max - $drow['total'];
304 if($newpoints < 0)
305 $newpoints = 0;
306
307 if(mysql_escape_string(stripslashes($_POST['date'])) == "")
308 $_POST['date'] = date("Y-m-d H:i:s");
309
310 $query = "select * from `notary` where `from`='".$_SESSION['profile']['id']."' AND
311 `to`='".$_SESSION['_config']['notarise']['id']."' AND
312 `awarded`='$awarded' AND
313 `location`='".mysql_escape_string(stripslashes($_POST['location']))."' AND
314 `date`='".mysql_escape_string(stripslashes($_POST['date']))."'";
315 $res = mysql_query($query);
316 if(mysql_num_rows($res) > 0)
317 {
318 show_page("VerifyEmail","",_("Identical Assurance attempted, will not continue."));
319 exit;
320 }
321 }
322
323 if($oldid == 6)
324 {
325 $query = "insert into `notary` set `from`='".$_SESSION['profile']['id']."',
326 `to`='".$_SESSION['_config']['notarise']['id']."',
327 `points`='$newpoints', `awarded`='$awarded',
328 `location`='".mysql_escape_string(stripslashes($_POST['location']))."',
329 `date`='".mysql_escape_string(stripslashes($_POST['date']))."',
330 `when`=NOW()";
331 if($_SESSION['profile']['ttpadmin'] == 1 && ($_POST['method'] == 'Trusted 3rd Parties' || $_POST['method'] == 'Trusted Third Parties')) {
332 $query .= ",\n`method`='TTP-Assisted'";
333 }
334 mysql_query($query);
335 fix_assurer_flag($_SESSION['_config']['notarise']['id']);
336 include_once("../includes/notary.inc.php");
337 /*to be activated after CCA accept option is implemented in form
338 write_user_agreement($_SESSION['profile']['id'], "CCA", "assurance", "Assuring", 1, $_SESSION['_config']['notarise']['id']);}*/
339 /* to be activated after the CCA recording is announced
340 write_user_agreement($_SESSION['_config']['notarise']['id'], "CCA", "assurance", "Being assured", 0, $_SESSION['profile']['id']); */
341
342 if($_SESSION['profile']['points'] < 150)
343 {
344 $addpoints = 0;
345 if($_SESSION['profile']['points'] < 149 && $_SESSION['profile']['points'] >= 100)
346 $addpoints = 2;
347 else if($_SESSION['profile']['points'] == 149 && $_SESSION['profile']['points'] >= 100)
348 $addpoints = 1;
349 $query = "insert into `notary` set `from`='".$_SESSION['profile']['id']."',
350 `to`='".$_SESSION['profile']['id']."',
351 `points`='$addpoints', `awarded`='$addpoints',
352 `location`='".mysql_escape_string(stripslashes($_POST['location']))."',
353 `date`='".mysql_escape_string(stripslashes($_POST['date']))."',
354 `method`='Administrative Increase',
355 `when`=NOW()";
356 mysql_query($query);
357
358 // No need to fix_assurer_flag here, this should only happen for assurers...
359 $_SESSION['profile']['points'] += $addpoints;
360 }
361
362 $my_translation = L10n::get_translation();
363 L10n::set_translation($_SESSION['_config']['notarise']['language']);
364
365 $body = sprintf(_("You are receiving this email because you have been assured by %s %s (%s)."), $_SESSION['profile']['fname'], $_SESSION['profile']['lname'], $_SESSION['profile']['email'])."\n\n";
366 if($_POST['points'] != $newpoints)
367 $body .= sprintf(_("You were issued %s points however the system has rounded this down to %s and you now have %s points in total."), $_POST['points'], $newpoints, ($newpoints + $drow['total']))."\n\n";
368 else
369 $body .= sprintf(_("You were issued %s points and you now have %s points in total."), $newpoints, ($newpoints + $drow['total']))."\n\n";
370
371 if(($drow['total'] + $newpoints) < 100 && ($drow['total'] + $newpoints) >= 50)
372 {
373 $body .= _("You now have over 50 points, and can now have your name added to client certificates, and issue server certificates for up to 2 years.")."\n\n";
374 }
375
376 if(($drow['total'] + $newpoints) >= 100 && $newpoints > 0)
377 {
378 $body .= _("You have at least 100 Assurance Points, if you want to become an assurer try the Assurer Challenge")." ( https://cats.cacert.org )\n\n";
379 $body .= _("To make it easier for others in your area to find you, it's helpful to list yourself as an assurer (this is voluntary), as well as a physical location where you live or work the most. You can flag your account to be listed, and add a comment to the display by going to:")."\n";
380 $body .= "https://www.cacert.org/wot.php?id=8\n\n";
381 $body .= _("You can list your location by going to:")."\n";
382 $body .= "https://www.cacert.org/wot.php?id=13\n\n";
383 }
384
385 $body .= _("Best regards")."\n";
386 $body .= _("CAcert Support Team");
387
388 sendmail($_SESSION['_config']['notarise']['email'], "[CAcert.org] "._("You've been Assured."), $body, "support@cacert.org", "", "", "CAcert Website");
389
390 L10n::set_translation($my_translation);
391
392 $body = sprintf(_("You are receiving this email because you have assured %s %s (%s)."), $_SESSION['_config']['notarise']['fname'], $_SESSION['_config']['notarise']['lname'], $_SESSION['_config']['notarise']['email'])."\n\n";
393 if($_POST['points'] != $newpoints)
394 $body .= sprintf(_("You issued %s points however the system has rounded this down to %s and they now have %s points in total."), $_POST['points'], $newpoints, ($newpoints + $drow['total']))."\n\n";
395 else
396 $body .= sprintf(_("You issued %s points and they now have %s points in total."), $newpoints, ($newpoints + $drow['total']))."\n\n";
397
398 $body .= _("Best regards")."\n";
399 $body .= _("CAcert Support Team");
400
401 sendmail($_SESSION['profile']['email'], "[CAcert.org] "._("You've Assured Another Member."), $body, "support@cacert.org", "", "", "CAcert Support");
402
403 showheader(_("My CAcert.org Account!"));
404 echo "<p>"._("Shortly you and the person you were assuring will receive an email confirmation. There is no action on your behalf required to complete this.")."</p>";
405 ?><form method="post" action="wot.php">
406 <table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper">
407 <tr>
408 <td colspan="2" class="title"><?=_("Assure Someone")?></td>
409 </tr>
410 <tr>
411 <td class="DataTD"><?=_("Email")?>:</td>
412 <td class="DataTD"><input type="text" name="email" id="email" value=""></td>
413 </tr>
414 <tr>
415 <td class="DataTD" colspan="2"><input type="submit" name="process" value="<?=_("Next")?>"></td>
416 </tr>
417 </table>
418 <input type="hidden" name="oldid" value="5">
419 </form>
420 <SCRIPT LANGUAGE="JavaScript">
421 //<![CDATA[
422 function my_init()
423 {
424 document.getElementById("email").focus();
425 }
426
427 window.onload = my_init();
428 //]]>
429 </script>
430 <?
431 showfooter();
432 exit;
433 }
434
435 if($oldid == 8)
436 {
437 csrf_check("chgcontact");
438
439 $info = mysql_escape_string(strip_tags(stripslashes($_POST['contactinfo'])));
440 $listme = intval($_POST['listme']);
441 if($listme < 0 || $listme > 1)
442 $listme = 0;
443
444 $_SESSION['profile']['listme'] = $listme;
445 $_SESSION['profile']['contactinfo'] = $info;
446
447 $query = "update `users` set `listme`='$listme',`contactinfo`='$info' where `id`='".$_SESSION['profile']['id']."'";
448 mysql_query($query);
449
450 showheader(_("My CAcert.org Account!"));
451 echo "<p>"._("Your account information has been updated.")."</p>";
452 showfooter();
453 exit;
454 }
455
456 if($oldid == 9 && $_REQUEST['userid'] > 0 && $_SESSION['profile']['id'] > 0)
457 {
458 if($_SESSION['_config']['pagehash'] != $_REQUEST['pageid'])
459 {
460 $oldid=0;
461 $id = 9;
462 show_page("ContactAssurer","",_("It looks like you were trying to contact multiple people, this isn't allowed due to data security reasons."));
463 exit;
464 } else {
465 $body = $_REQUEST['message'];
466 $subject = $_REQUEST['subject'];
467 $userid = intval($_REQUEST['userid']);
468 $user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='$userid' and `listme`=1"));
469 $points = mysql_num_rows(mysql_query("select sum(`points`) as `total` from `notary`
470 where `to`='".$user['id']."' group by `to` HAVING SUM(`points`) > 0"));
471 if($points > 0)
472 {
473 $my_translation = L10n::get_translation();
474 L10n::set_translation($user['language']);
475
476 $subject = "[CAcert.org] ".sprintf(_("Message from %s"),
477 $_SESSION['profile']['fname']);
478
479 $body = sprintf(_("Hi %s,"), $user['fname'])."\n\n";
480 $body .= sprintf(_("%s %s has sent you a message via the ".
481 "contact an Assurer form on CAcert.org."),
482 $_SESSION['profile']['fname'],
483 $_SESSION['profile']['lname'])."\n\n";
484 $body .= sprintf(_("Subject: %s"), $_REQUEST['subject'])."\n";
485 $body .= _("Message:")."\n";
486 $body .= $_REQUEST['message']."\n\n";
487 $body .= "------------------------------------------------\n\n";
488 $body .= _("Please note, that this is NOT a message on behalf ".
489 "of CAcert but another CAcert community member. If ".
490 "you suspect that the contact form might have been ".
491 "abused, please write to support@cacert.org")."\n\n";
492 $body .= _("Best regards")."\n";
493 $body .= _("Your CAcert Community");
494
495 sendmail($user['email'], $subject, $body,
496 $_SESSION['profile']['email'], //from
497 "", //replyto
498 "", //toname
499 $_SESSION['profile']['fname']." ".
500 $_SESSION['profile']['lname']); //fromname
501
502 L10n::set_translation($my_translation);
503
504 showheader(_("My CAcert.org Account!"));?>
505 <p>
506 <? printf(_("Your email has been sent to %s."), $user['fname']); ?>
507 </p>
508 <p>[ <a href='javascript:history.go(-2)'><?= _("Go Back") ?></a> ]</p>
509 <?
510 showfooter();
511 exit;
512 } else {
513 show_page(0,"",_("Sorry, I was unable to locate that user."));
514 exit;
515 }
516
517 }
518 }
519 if($oldid == 9)
520 {
521 $oldid=0;
522 $id = 9;
523 show_page("ContactAssurer","",_("There was an error and I couldn't proceed"));
524 exit;
525 }
526
527 // showheader(_("My CAcert.org Account!"));
528 // echo "ID now = ".$id."/".$oldid.">>".$iecho;
529 // includeit($id, "wot");
530 // showfooter();
531 show_page ($id,"","");
532 ?>