remove cacert/ prefix
[cacert.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
21 loadem("account");
22
23 if(array_key_exists('date',$_POST) && $_POST['date'] != "")
24 $_SESSION['_config']['date'] = $_POST['date'];
25
26 if(array_key_exists('location',$_POST) && $_POST['location'] != "")
27 $_SESSION['_config']['location'] = $_POST['location'];
28
29 $oldid=array_key_exists('oldid',$_REQUEST)?intval($_REQUEST['oldid']):0;
30
31 if($oldid == 12)
32 {
33 $id = $oldid;
34 }
35
36 if(($id == 5 || $oldid == 5 || $id == 6 || $oldid == 6))
37 {
38 if (!is_assurer($_SESSION['profile']['id'])) {
39 showheader(_("My CAcert.org Account!"));
40 echo "<p>".get_assurer_reason($_SESSION['profile']['id'])."</p>";
41 showfooter();
42 exit;
43 }
44 }
45
46 if($oldid == 6 && intval($_SESSION['_config']['notarise']['id']) <= 0)
47 {
48 $oldid=0;
49 $id = 5;
50 }
51
52 if($oldid == 5 && array_key_exists('reminder',$_POST) && $_POST['reminder'] != "")
53 {
54 $body = "";
55 if($_POST['reminder-lang'] != "" && $_POST['reminder-lang'] != "en_AU")
56 {
57 $userlang = $_POST['reminder-lang'];
58 $_SESSION['_config']['reminder-lang'] = $_POST['reminder-lang'];
59 putenv("LANG=".$userlang);
60 setlocale(LC_ALL, $userlang);
61
62 $body .= $_SESSION['_config']['translations'][$userlang].":\n\n";
63 $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";
64 $body .= _("Best regards")."\n";
65 $body .= _("CAcert Support Team");
66
67 $body .= "\n\nEnglish:\n\n";
68 }
69
70 $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";
71 $body .= "Best regards"."\n";
72 $body .= "CAcert Support Team";
73
74 sendmail($_POST['email'], "[CAcert.org] "._("Reminder Notice"), $body, $_SESSION['profile']['email'], "", "", $_SESSION['profile']['fname']);
75
76 if($_POST['reminder-lang'] != "" && $_POST['reminder-lang'] != "en_AU")
77 {
78 $userlang = $_SESSION['profile']['language'];
79 putenv("LANG=".$userlang);
80 setlocale(LC_ALL, $userlang);
81 }
82
83 $_SESSION['_config']['remindersent'] = 1;
84 $_SESSION['_config']['error'] = _("A reminder notice has been sent.");
85
86 $id = $oldid;
87 $oldid=0;
88 }
89
90 if($oldid == 5)
91 {
92 $_SESSION['_config']['noemailfound'] = 0;
93 $query = "select * from `users` where `email`='".mysql_escape_string(stripslashes($_POST['email']))."' and `deleted`=0";
94 $res = mysql_query($query);
95 if(mysql_num_rows($res) != 1)
96 {
97 $id = $oldid;
98 $oldid=0;
99 $_SESSION['_config']['error'] = _("I'm sorry, there was no email matching what you entered in the system. Please double check your information.");
100 $_SESSION['_config']['noemailfound'] = 1;
101 } else {
102 $_SESSION['_config']['notarise'] = mysql_fetch_assoc($res);
103 }
104 }
105
106 if($oldid == 5 || $oldid == 6)
107 {
108 if(array_key_exists('cancel',$_REQUEST) && $_REQUEST['cancel'] != "")
109 {
110 header("location: wot.php");
111 exit;
112 }
113
114 if($_SESSION['_config']['notarise']['id'] == $_SESSION['profile']['id'])
115 {
116 $id = 5;
117 $oldid=0;
118 $_SESSION['_config']['error'] = _("You are never allowed to Assure yourself!");
119 }
120 }
121
122 if($oldid == 5 || $oldid == 6)
123 {
124 $query = "select * from `notary` where `from`='".$_SESSION['profile']['id']."' and
125 `to`='".$_SESSION['_config']['notarise']['id']."'";
126 $_SESSION['_config']['alreadydone'] = 0;
127 $res = mysql_query($query);
128 if(mysql_num_rows($res) > 0 && $_SESSION['profile']['points'] < 200)
129 {
130 $id = 5;
131 $oldid=0;
132 $_SESSION['_config']['error'] = _("You are only allowed to Assure someone once!");
133 } elseif($oldid == 5) {
134 $id = 6;
135 }
136 if($id == 6 && mysql_num_rows($res) > 0)
137 {
138 $_SESSION['_config']['alreadydone'] = 1;
139 }
140 unset($_SESSION['_config']['pointsalready']);
141 if($id == 6 && $_SESSION['profile']['points'] >= 100)
142 {
143 $query = "select sum(`points`) as `total` from `notary` where `to`='".$_SESSION['_config']['notarise']['id']."' group by `to`";
144 $res = mysql_query($query);
145 $drow = mysql_fetch_assoc($res);
146 $_SESSION['_config']['pointsalready'] = $drow['total'];
147 }
148 unset($_SESSION['_config']['verified']);
149 if($id == 6 && $_SESSION['profile']['points'] >= 100)
150 {
151 $query = "select `verified` from `users` where `id`='".$_SESSION['_config']['notarise']['id']."'";
152 $res = mysql_query($query);
153 $drow = mysql_fetch_assoc($res);
154 $_SESSION['_config']['verified'] = $drow['verified'];
155 }
156 }
157
158 if($oldid == 6)
159 {
160 if(!array_key_exists('assertion',$_POST) || $_POST['assertion'] != 1 || !array_key_exists('rules',$_POST) || $_POST['rules'] != 1)
161 {
162 $id = $oldid;
163 $oldid=6;
164 $_SESSION['_config']['error'] = _("You failed to check all boxes to validate your adherence to the rules and policies of CAcert");
165 }
166
167 if((!array_key_exists('certify',$_POST) || $_POST['certify'] != 1 ) && $_SESSION['profile']['ttpadmin'] != 1)
168 {
169 $id = $oldid;
170 $oldid=6;
171 $_SESSION['_config']['error'] = _("You failed to check all boxes to validate your adherence to the rules and policies of CAcert");
172 }
173 }
174
175 if($oldid == 6 && $_SESSION['profile']['ttpadmin'] != 1)
176 {
177 if($_POST['location'] == "")
178 {
179 $id = $oldid;
180 $oldid=0;
181 $_SESSION['_config']['error'] = _("You failed to enter a location of your meeting.");
182 }
183 }
184
185 if($oldid == 6)
186 {
187 $query = "select * from `users` where `id`='".$_SESSION['_config']['notarise']['id']."'";
188 $res = mysql_query($query);
189 $row = mysql_fetch_assoc($res);
190 $name = $row['fname']." ".$row['mname']." ".$row['lname']." ".$row['suffix'];
191 if($_SESSION['_config']['wothash'] != md5($name."-".$row['dob']) || $_SESSION['_config']['wothash'] != $_REQUEST['pagehash'])
192 {
193 $id = $oldid;
194 $oldid=0;
195 $_SESSION['_config']['error'] = _("Race condition discovered, user altered details during assurance procedure. PLEASE MAKE SURE THE NEW DETAILS BELOW MATCH THE ID DOCUMENTS.");
196 }
197 }
198
199 if($oldid == 6 && $_REQUEST['points'] == "")
200 {
201 $id = $oldid;
202 $oldid=0;
203 $_SESSION['_config']['error'] = _("You must enter the number of points you wish to allocate to this person.");
204 }
205
206 if($oldid == 6)
207 {
208 $max = maxpoints();
209 $awarded = $newpoints = intval($_POST['points']);
210 if($newpoints > $max)
211 $newpoints = $max;
212 $query = "select sum(`points`) as `total` from `notary` where `to`='".$_SESSION['_config']['notarise']['id']."' group by `to`";
213 $res = mysql_query($query);
214 $drow = mysql_fetch_assoc($res);
215
216 if($_SESSION['profile']['board'] == 1 && intval($_POST['expire']) > 0 && $drow['total'] > 150)
217 {
218 showheader(_("My CAcert.org Account!"));
219 echo "<p>"._("You tried to give a temporary points increase to someone that already has more then 150 points. Can't continue.")."</p>";
220 showfooter();
221 exit;
222 }
223
224 if($_SESSION['profile']['board'] == 1 && intval($_POST['expire']) > 0 && intval($_POST['sponsor']) <= 0)
225 {
226 showheader(_("My CAcert.org Account!"));
227 echo "<p>"._("You didn't list a valid sponsor for this action.")."</p>";
228 showfooter();
229 exit;
230 }
231
232 if($_SESSION['profile']['board'] == 1 && intval($_POST['expire']) > 0 && intval($_POST['sponsor']) > 0)
233 {
234 $resc = mysql_query("select * from `users` where `id`='".intval($_POST['sponsor'])."' and `board`='1'");
235 $rc = mysql_num_rows($resc);
236 $sponsor = mysql_fetch_assoc($resc);
237 if($rc <= 0)
238 {
239 showheader(_("My CAcert.org Account!"));
240 echo "<p>"._("You listed an invalid sponsor for this action.")."</p>";
241 showfooter();
242 exit;
243 }
244 }
245
246 if($_SESSION['profile']['board'] == 1 && intval($_POST['expire']) > 0)
247 {
248 $_POST['method'] == "Administrative Increase";
249 $newpoints = 200 - $drow['total'];
250 if(intval($_POST['expire']) > 45)
251 $_POST['expire'] = 45;
252 if(intval($_POST['expire']) <= 7)
253 $_POST['expire'] = 7;
254 } else {
255 $_POST['expire'] = 0;
256 if(($drow['total'] + $newpoints) > 100 && $max < 100)
257 $newpoints = 100 - $drow['total'];
258 if(($drow['total'] + $newpoints) > $max && $max >= 100)
259 $newpoints = $max - $drow['total'];
260 if($newpoints < 0)
261 $newpoints = 0;
262 }
263
264 if(mysql_escape_string(stripslashes($_POST['date'])) == "")
265 $_POST['date'] = date("Y-m-d H:i:s");
266
267 $query = "select * from `notary` where `from`='".$_SESSION['profile']['id']."' AND
268 `to`='".$_SESSION['_config']['notarise']['id']."' AND
269 `awarded`='$awarded' AND
270 `location`='".mysql_escape_string(stripslashes($_POST['location']))."' AND
271 `date`='".mysql_escape_string(stripslashes($_POST['date']))."'";
272 $res = mysql_query($query);
273 if(mysql_num_rows($res) > 0)
274 {
275 $id = $oldid;
276 $oldid=0;
277 $_SESSION['_config']['error'] = _("Identical Assurance attempted, will not continue.");
278 }
279 }
280
281 if($oldid == 6)
282 {
283 $query = "insert into `notary` set `from`='".$_SESSION['profile']['id']."',
284 `to`='".$_SESSION['_config']['notarise']['id']."',
285 `points`='$newpoints', `awarded`='$awarded',
286 `location`='".mysql_escape_string(stripslashes($_POST['location']))."',
287 `date`='".mysql_escape_string(stripslashes($_POST['date']))."',
288 `when`=NOW()";
289 if($_SESSION['profile']['board'] == 1 && intval($_POST['expire']) > 0)
290 {
291 $query .= ",\n`method`='Temporary Increase'";
292 $query .= ",\n`expire`=DATE_ADD(NOW(), INTERVAL '".intval($_POST['expire'])."' DAY)";
293 $query .= ",\n`sponsor`='".intval($_POST['sponsor'])."'";
294 } else if($_SESSION['profile']['board'] == 1) {
295 $query .= ",\n`method`='".mysql_escape_string(stripslashes($_POST['method']))."'";
296 } else if($_SESSION['profile']['ttpadmin'] == 1 && ($_POST['method'] == 'Trusted 3rd Parties' || $_POST['method'] == 'Trusted third Parties')) {
297 $query .= ",\n`method`='Trusted Third Parties'";
298 }
299 mysql_query($query);
300 fix_assurer_flag($_SESSION['_config']['notarise']['id']);
301
302 if($_SESSION['profile']['points'] < 150)
303 {
304 $addpoints = 0;
305 if($_SESSION['profile']['points'] < 149 && $_SESSION['profile']['points'] >= 100)
306 $addpoints = 2;
307 else if($_SESSION['profile']['points'] == 149 && $_SESSION['profile']['points'] >= 100)
308 $addpoints = 1;
309 $query = "insert into `notary` set `from`='".$_SESSION['profile']['id']."',
310 `to`='".$_SESSION['profile']['id']."',
311 `points`='$addpoints', `awarded`='$addpoints',
312 `location`='".mysql_escape_string(stripslashes($_POST['location']))."',
313 `date`='".mysql_escape_string(stripslashes($_POST['date']))."',
314 `method`='Administrative Increase',
315 `when`=NOW()";
316 mysql_query($query);
317 // No need to fix_assurer_flag here, this should only happen for assurers...
318 $_SESSION['profile']['points'] += $addpoints;
319 }
320
321 if($_SESSION['_config']['notarise']['language'] != "")
322 {
323 $userlang = $_SESSION['_config']['notarise']['language'];
324 putenv("LANG=".$userlang);
325 setlocale(LC_ALL, $userlang);
326 }
327
328 $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";
329 if($_POST['points'] != $newpoints)
330 $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";
331 else
332 $body .= sprintf(_("You were issued %s points and you now have %s points in total."), $newpoints, ($newpoints + $drow['total']))."\n\n";
333
334 if(($drow['total'] + $newpoints) < 100 && ($drow['total'] + $newpoints) >= 50)
335 {
336 $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";
337 }
338
339 if(($drow['total'] + $newpoints) >= 100 && $newpoints > 0)
340 {
341 // $body .= _("You now have over 100 points and can start assuring others.")."\n\n";
342 $body .= _("You have at least 100 Assurance Points, if you want to become an assurer try the")." ";
343 $body .= _("Assurer Challenge")." ( https://cats.cacert.org )\n\n";
344 $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\n";
345 $body .= "https://www.cacert.org/wot.php?id=8\n\n";
346 $body .= _("You can list your location by going to:")."\n\n";
347 $body .= "https://www.cacert.org/wot.php?id=13\n\n";
348 }
349
350 if($_SESSION['profile']['board'] == 1 && intval($_POST['expire']) > 0)
351 $body .= sprintf(_("Please Note: this is a temporary increase for %s days only. After that time your points will be reduced to 150 points."), intval($_POST['expire']))."\n\n";
352
353 $body .= _("Best regards")."\n";
354 $body .= _("CAcert Support Team");
355
356 sendmail($_SESSION['_config']['notarise']['email'], "[CAcert.org] "._("You've been Assured."), $body, "support@cacert.org", "", "", "CAcert Website");
357
358 putenv("LANG=".$_SESSION['profile']['language']);
359 setlocale(LC_ALL, $_SESSION['profile']['language']);
360
361 $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";
362 if($_POST['points'] != $newpoints)
363 $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";
364 else
365 $body .= sprintf(_("You issued %s points and they now have %s points in total."), $newpoints, ($newpoints + $drow['total']))."\n\n";
366
367 if($_SESSION['profile']['board'] == 1 && intval($_POST['expire']) > 0)
368 $body .= sprintf(_("Please Note: this is a temporary increase for %s days only. After that time their points will be reduced to 150 points."), intval($_POST['expire']))."\n\n";
369 $body .= _("Best regards")."\n";
370 $body .= _("CAcert Support Team");
371
372 sendmail($_SESSION['profile']['email'], "[CAcert.org] "._("You've Assured Another Member."), $body, "support@cacert.org", "", "", "CAcert Support");
373
374 if($_SESSION['profile']['board'] == 1 && intval($_POST['expire']) > 0)
375 {
376 $body = sprintf("%s %s (%s) has issued a temporary increase to 200 points for %s %s (%s) for %s days. This action was sponsored by %s %s (%s).", $_SESSION['profile']['fname'], $_SESSION['profile']['lname'], $_SESSION['profile']['email'], $_SESSION['_config']['notarise']['fname'], $_SESSION['_config']['notarise']['lname'], $_SESSION['_config']['notarise']['email'], intval($_POST['expire']), $sponsor['fname'], $sponsor['lname'], $sponsor['email'])."\n\n";
377
378 sendmail("cacert-board@lists.cacert.org", "[CAcert.org] Temporary Increase Issued.", $body, "website@cacert.org", "", "", "CAcert Website");
379 }
380
381 showheader(_("My CAcert.org Account!"));
382 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>";
383 ?><form method="post" action="wot.php">
384 <table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper">
385 <tr>
386 <td colspan="2" class="title"><?=_("Assure Someone")?></td>
387 </tr>
388 <tr>
389 <td class="DataTD"><?=_("Email")?>:</td>
390 <td class="DataTD"><input type="text" name="email" id="email" value=""></td>
391 </tr>
392 <tr>
393 <td class="DataTD" colspan="2"><input type="submit" name="process" value="<?=_("Next")?>"></td>
394 </tr>
395 </table>
396 <input type="hidden" name="oldid" value="5">
397 </form>
398 <SCRIPT LANGUAGE="JavaScript">
399 //<![CDATA[
400 function my_init()
401 {
402 document.getElementById("email").focus();
403 }
404
405 window.onload = my_init();
406 //]]>
407 </script>
408 <?
409 showfooter();
410 exit;
411 }
412
413 if($oldid == 8)
414 {
415 csrf_check("chgcontact");
416
417 $info = mysql_escape_string(strip_tags(stripslashes($_POST['contactinfo'])));
418 $listme = intval($_POST['listme']);
419 if($listme < 0 || $listme > 1)
420 $listme = 0;
421
422 $_SESSION['profile']['listme'] = $listme;
423 $_SESSION['profile']['contactinfo'] = $info;
424
425 $query = "update `users` set `listme`='$listme',`contactinfo`='$info' where `id`='".$_SESSION['profile']['id']."'";
426 mysql_query($query);
427
428 showheader(_("My CAcert.org Account!"));
429 echo "<p>"._("Your account information has been updated.")."</p>";
430 showfooter();
431 exit;
432 }
433
434 if($oldid == 9 && $_REQUEST['userid'] > 0 && $_SESSION['profile']['id'] > 0)
435 {
436 if($_SESSION['_config']['pagehash'] != $_REQUEST['pageid'])
437 {
438 $oldid=0;
439 $id = 9;
440 $error = _("It looks like you were trying to contact multiple people, this isn't allowed due to data security reasons.");
441 } else {
442 $body = $_REQUEST['message'];
443 $subject = $_REQUEST['subject'];
444 $userid = intval($_REQUEST['userid']);
445 $user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='$userid' and `listme`=1"));
446 $points = mysql_num_rows(mysql_query("select sum(`points`) as `total` from `notary`
447 where `to`='".$user['id']."' group by `to` HAVING SUM(`points`) > 0"));
448 if($points > 0)
449 {
450 sendmail($user['email'], "[CAcert.org] ".$_REQUEST['subject'], $_REQUEST['message'],
451 $_SESSION['profile']['email'], "", "", $_SESSION['profile']['fname']." ".$_SESSION['profile']['lname']);
452 showheader(_("My CAcert.org Account!"));
453 echo "<p>"._("Your email has been sent to")." ".$user['fname'].".</p>";
454 echo "<p>[ <a href='javascript:history.go(-2)'>Go Back</a> ]</p>\n";
455 showfooter();
456 exit;
457 } else {
458 showheader(_("My CAcert.org Account!"));
459 echo _("Sorry, I was unable to locate that user.");
460 showfooter();
461 exit;
462 }
463 }
464 } elseif($oldid == 9) {
465 $oldid=0;
466 $error = _("There was an error and I couldn't proceed");
467 $id = 9;
468 }
469
470 showheader(_("My CAcert.org Account!"));
471 includeit($id, "wot");
472 showfooter();
473 ?>