0cbaea0d1bc88c1ef3b0e771de47124c1214f748
[cacert-devel.git] / includes / account.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 require_once("../includes/loggedin.php");
19 require_once("../includes/lib/l10n.php");
20 require_once("../includes/lib/check_weak_key.php");
21 require_once("../includes/notary.inc.php");
22
23 loadem("account");
24
25 /**
26 * Build a subject string as needed by the signer
27 *
28 * @param array(string) $domains
29 * First domain is used as CN and repeated in subjectAltName. Duplicates
30 * should already been removed
31 *
32 * @param bool $include_xmpp_addr
33 * [default: true] Whether to include the XmppAddr in the subjectAltName.
34 * This is needed if the Jabber server is jabber.example.com but a Jabber ID
35 * on that server would be alice@example.com
36 *
37 * @return string
38 */
39 function buildSubject(array $domains, $include_xmpp_addr = true) {
40 $subject = "/CN=${domains[0]}";
41
42 foreach ($domains as $domain) {
43 $subject .= "/subjectAltName=DNS:$domain";
44
45 if ($include_xmpp_addr) {
46 $subject .= "/subjectAltName=otherName:1.3.6.1.5.5.7.8.5;UTF8:$domain";
47 }
48 }
49
50 return $subject;
51 }
52
53 /**
54 * Builds the subject string from the session variables
55 * $_SESSION['_config']['rows'] and $_SESSION['_config']['altrows']
56 *
57 * @return string
58 */
59 function buildSubjectFromSession() {
60 $domains = array();
61
62 if (is_array($_SESSION['_config']['rows'])) {
63 $domains = array_merge($domains, $_SESSION['_config']['rows']);
64 }
65
66 if (is_array($_SESSION['_config']['altrows']))
67 foreach ($_SESSION['_config']['altrows'] as $row) {
68 if (substr($row, 0, 4) === "DNS:") {
69 $domains[] = substr($row, 4);
70 }
71 }
72
73 return buildSubject(array_unique($domains));
74 }
75
76 $id = array_key_exists("id",$_REQUEST) ? intval($_REQUEST['id']) : 0;
77 $oldid = array_key_exists("oldid",$_REQUEST) ? intval($_REQUEST['oldid']) : 0;
78 $process = array_key_exists("process",$_REQUEST) ? $_REQUEST['process'] : "";
79 // $showdetalis refers to Secret Question and Answers from account/13.php
80 $showdetails = array_key_exists("showdetails",$_REQUEST) ? intval($_REQUEST['showdetails']) : 0;
81
82 $cert = array_key_exists('cert',$_REQUEST) ? intval($_REQUEST['cert']) : 0;
83 $orgid = array_key_exists('orgid',$_REQUEST) ? intval($_REQUEST['orgid']) : 0;
84 $memid = array_key_exists('memid',$_REQUEST) ? intval($_REQUEST['memid']) : 0;
85 $domid = array_key_exists('domid',$_REQUEST) ? intval($_REQUEST['domid']) : 0;
86 $ticketno = array_key_exists('ticketno',$_REQUEST) ? $_REQUEST['ticketno'] : "";
87 $ticketvalidation = FALSE;
88 $actionrequest = array_key_exists('action',$_REQUEST) ? $_REQUEST['action'] : "";
89
90
91 if(!$_SESSION['mconn'])
92 {
93 echo _("Several CAcert Services are currently unavailable. Please try again later.");
94 exit;
95 }
96
97 if ($process == _("Cancel"))
98 {
99 // General reset CANCEL process requests
100 $process = "";
101 }
102
103
104 if($id == 45 || $id == 46 || $oldid == 45 || $oldid == 46)
105 {
106 $id = 1;
107 $oldid=0;
108 }
109
110 if($process != "" && $oldid == 1)
111 {
112 $id = 1;
113 csrf_check('addemail');
114 if(strstr($_REQUEST['newemail'], "xn--") && $_SESSION['profile']['codesign'] <= 0)
115 {
116 showheader(_("My CAcert.org Account!"));
117 echo _("Due to the possibility for punycode domain exploits we currently do not allow any certificates to sign punycode domains or email addresses.");
118 showfooter();
119 exit;
120 }
121 if(trim(mysql_real_escape_string(stripslashes($_REQUEST['newemail']))) == "")
122 {
123 showheader(_("My CAcert.org Account!"));
124 printf(_("Not a valid email address. Can't continue."));
125 showfooter();
126 exit;
127 }
128 $oldid=0;
129 $_REQUEST['email'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['newemail'])));
130 if(check_email_exists($_REQUEST['email'])==true)
131 {
132 showheader(_("My CAcert.org Account!"));
133 printf(_("The email address '%s' is already in a different account. Can't continue."), sanitizeHTML($_REQUEST['email']));
134 showfooter();
135 exit;
136 }
137 $checkemail = checkEmail($_REQUEST['newemail']);
138 if($checkemail != "OK")
139 {
140 showheader(_("My CAcert.org Account!"));
141 if (substr($checkemail, 0, 1) == "4")
142 {
143 echo "<p>"._("The mail server responsible for your domain indicated a temporary failure. This may be due to anti-SPAM measures, such as greylisting. Please try again in a few minutes.")."</p>\n";
144 } else {
145 echo "<p>"._("Email Address given was invalid, or a test connection couldn't be made to your server, or the server rejected the email address as invalid")."</p>\n";
146 }
147 echo "<p>$checkemail</p>\n";
148 showfooter();
149 exit;
150 }
151 $hash = make_hash();
152 $query = "insert into `email` set `email`='".mysql_real_escape_string($_REQUEST['email'])."',`memid`='".intval($_SESSION['profile']['id'])."',`created`=NOW(),`hash`='$hash'";
153 mysql_query($query);
154 $emailid = mysql_insert_id();
155
156 $body = _("Below is the link you need to open to verify your email address. Once your address is verified you will be able to start issuing certificates to your heart's content!")."\n\n";
157 $body .= "http://".$_SESSION['_config']['normalhostname']."/verify.php?type=email&emailid=$emailid&hash=$hash\n\n";
158 $body .= _("Best regards")."\n"._("CAcert.org Support!");
159
160 sendmail($_REQUEST['email'], "[CAcert.org] "._("Email Probe"), $body, "support@cacert.org", "", "", "CAcert Support");
161
162 showheader(_("My CAcert.org Account!"));
163 printf(_("The email address '%s' has been added to the system, however before any certificates for this can be issued you need to open the link in a browser that has been sent to your email address."), sanitizeHTML($_REQUEST['email']));
164 showfooter();
165 exit;
166 }
167
168 if(array_key_exists("makedefault",$_REQUEST) && $_REQUEST['makedefault'] != "" && $oldid == 2)
169 {
170 $id = 2;
171 $emailid = intval($_REQUEST['emailid']);
172 $query = "select * from `email` where `id`='$emailid' and `memid`='".intval($_SESSION['profile']['id'])."' and `hash` = '' and `deleted`=0";
173 $res = mysql_query($query);
174 if(mysql_num_rows($res) <= 0)
175 {
176 showheader(_("Error!"));
177 echo _("You currently don't have access to the email address you selected, or you haven't verified it yet.");
178 showfooter();
179 exit;
180 }
181 $row = mysql_fetch_assoc($res);
182 $body = sprintf(_("Hi %s,"),$_SESSION['profile']['fname'])."\n\n";
183 $body .= _("You are receiving this email because you or someone else ".
184 "has changed the default email on your account.")."\n\n";
185
186 $body .= _("Best regards")."\n"._("CAcert.org Support!");
187
188 sendmail($_SESSION['profile']['email'], "[CAcert.org] "._("Default Account Changed"), $body,
189 "support@cacert.org", "", "", "CAcert Support");
190
191 $_SESSION['profile']['email'] = $row['email'];
192 $query = "update `users` set `email`='".mysql_real_escape_string($row['email'])."' where `id`='".intval($_SESSION['profile']['id'])."'";
193 mysql_query($query);
194 showheader(_("My CAcert.org Account!"));
195 printf(_("Your default email address has been updated to '%s'."), sanitizeHTML($row['email']));
196 showfooter();
197 exit;
198 }
199
200 if($process != "" && $oldid == 2)
201 {
202 $id = 2;
203 csrf_check("chgdef");
204 showheader(_("My CAcert.org Account!"));
205 $delcount = 0;
206 if(array_key_exists('delid',$_REQUEST) && is_array($_REQUEST['delid']))
207 {
208 $deltitle=false;
209 foreach($_REQUEST['delid'] as $id)
210 {
211 if (!$deltitle) {
212 echo _('The following email addresses have been removed:')."<br>\n";
213 $deltitle=true;
214 }
215 $id = intval($id);
216 $query = "select * from `email` where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."' and
217 `email`!='".mysql_real_escape_string($_SESSION['profile']['email'])."'";
218 $res = mysql_query($query);
219 if(mysql_num_rows($res) > 0)
220 {
221 $row = mysql_fetch_assoc($res);
222 echo $row['email']."<br>\n";
223 account_email_delete($row['id']);
224 $delcount++;
225 }
226 }
227 }
228 else
229 {
230 echo _("You did not select any email accounts for removal.");
231 }
232 if(0 == $delcount)
233 {
234 echo _("You did not select any accounts to be removed, or you attempted to remove the default account. No action was taken.");
235 }
236
237 showfooter();
238 exit;
239 }
240
241 if($process != "" && $oldid == 3)
242 {
243 if(!array_key_exists('CCA',$_REQUEST))
244 {
245 showheader(_("My CAcert.org Account!"));
246 echo _("You did not accept the CAcert Community Agreement (CCA), hit the back button and try again.");
247 showfooter();
248 exit;
249 }
250
251 if(!(array_key_exists('addid',$_REQUEST) && is_array($_REQUEST['addid'])) && $_REQUEST['SSO'] != '1')
252 {
253 showheader(_("My CAcert.org Account!"));
254 echo _("I didn't receive a valid Certificate Request, hit the back button and try again.");
255 showfooter();
256 exit;
257 }
258
259 $_SESSION['_config']['SSO'] = intval($_REQUEST['SSO']);
260
261 $_SESSION['_config']['addid'] = $_REQUEST['addid'];
262 if($_SESSION['profile']['points'] >= 50)
263 $_SESSION['_config']['incname'] = intval($_REQUEST['incname']);
264 if(array_key_exists('codesign',$_REQUEST) && $_REQUEST['codesign'] != 0 && ($_SESSION['profile']['codesign'] == 0 || $_SESSION['profile']['points'] < 100))
265 {
266 $_REQUEST['codesign'] = 0;
267 }
268 if($_SESSION['profile']['points'] >= 100 && $_SESSION['profile']['codesign'] > 0 && array_key_exists('codesign',$_REQUEST) && $_REQUEST['codesign'] == 1)
269 {
270 if($_SESSION['_config']['incname'] < 1 || $_SESSION['_config']['incname'] > 4)
271 $_SESSION['_config']['incname'] = 1;
272 }
273 if(array_key_exists('codesign',$_REQUEST) && $_REQUEST['codesign'] == 1 && $_SESSION['profile']['points'] >= 100)
274 $_SESSION['_config']['codesign'] = 1;
275 else
276 $_SESSION['_config']['codesign'] = 0;
277
278 if(array_key_exists('login',$_REQUEST) && $_REQUEST['login'] == 1)
279 $_SESSION['_config']['disablelogin'] = 0;
280 else
281 $_SESSION['_config']['disablelogin'] = 1;
282
283 $_SESSION['_config']['rootcert'] = 1;
284 if($_SESSION['profile']['points'] >= 50)
285 {
286 $_SESSION['_config']['rootcert'] = intval($_REQUEST['rootcert']);
287 if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
288 $_SESSION['_config']['rootcert'] = 1;
289 }
290 $csr = "";
291 if(trim($_REQUEST['optionalCSR']) == "")
292 {
293 $id = 4;
294 } else {
295 $oldid = 4;
296 $_REQUEST['keytype'] = "MS";
297 $csr = clean_csr($_REQUEST['optionalCSR']);
298 }
299 if(trim($_REQUEST['description']) != ""){
300 $_SESSION['_config']['description']= trim(mysql_real_escape_string(stripslashes($_REQUEST['description'])));
301 }else{
302 $_SESSION['_config']['description']= "";
303 }
304 }
305
306 if($oldid == 4)
307 {
308 if($_REQUEST['keytype'] == "NS")
309 {
310 $spkac=""; if(array_key_exists('SPKAC',$_REQUEST) && preg_match("/^[a-zA-Z0-9+=\/]+$/", trim(str_replace("\n", "", str_replace("\r", "",$_REQUEST['SPKAC']))))) $spkac=trim(str_replace("\n", "", str_replace("\r", "",$_REQUEST['SPKAC'])));
311
312 if($spkac=="" || $spkac == "deadbeef")
313 {
314 $id = 4;
315 showheader(_("My CAcert.org Account!"));
316 echo _("I didn't receive a valid Certificate Request, please try a different browser.");
317 showfooter();
318 exit;
319 }
320 $count = 0;
321 $emails = "";
322 $addys = array();
323 $defaultemail="";
324 if(is_array($_SESSION['_config']['addid']))
325 foreach($_SESSION['_config']['addid'] as $id)
326 {
327 $res = mysql_query("select * from `email` where `memid`='".intval($_SESSION['profile']['id'])."' and `id`='".intval($id)."'");
328 if(mysql_num_rows($res) > 0)
329 {
330 $row = mysql_fetch_assoc($res);
331 if(!$emails)
332 $defaultemail = $row['email'];
333 $emails .= "$count.emailAddress = ".$row['email']."\n";
334 $count++;
335 $addys[] = intval($row['id']);
336 }
337 }
338 if($count <= 0 && $_SESSION['_config']['SSO'] != 1)
339 {
340 $id = 4;
341 showheader(_("My CAcert.org Account!"));
342 echo _("You submitted invalid email addresses, or email address you no longer have control of. Can't continue with certificate request.");
343 showfooter();
344 exit;
345 }
346 $user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'"));
347 if($_SESSION['_config']['SSO'] == 1)
348 $emails .= "$count.emailAddress = ".$user['uniqueID']."\n";
349
350 if(strlen($user['mname']) == 1)
351 $user['mname'] .= '.';
352 if(!array_key_exists('incname',$_SESSION['_config']) || $_SESSION['_config']['incname'] <= 0 || $_SESSION['_config']['incname'] > 4)
353 {
354 $emails .= "commonName = CAcert WoT User\n";
355 }
356 else
357 {
358 if($_SESSION['_config']['incname'] == 1)
359 $emails .= "commonName = ".$user['fname']." ".$user['lname']."\n";
360 if($_SESSION['_config']['incname'] == 2)
361 $emails .= "commonName = ".$user['fname']." ".$user['mname']." ".$user['lname']."\n";
362 if($_SESSION['_config']['incname'] == 3)
363 $emails .= "commonName = ".$user['fname']." ".$user['lname']." ".$user['suffix']."\n";
364 if($_SESSION['_config']['incname'] == 4)
365 $emails .= "commonName = ".$user['fname']." ".$user['mname']." ".$user['lname']." ".$user['suffix']."\n";
366 }
367 if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
368 $_SESSION['_config']['rootcert'] = 1;
369
370 $emails .= "SPKAC = $spkac";
371 if (($weakKey = checkWeakKeySPKAC($emails)) !== "")
372 {
373 $id = 4;
374 showheader(_("My CAcert.org Account!"));
375 echo $weakKey;
376 showfooter();
377 exit;
378 }
379
380 write_user_agreement(intval($_SESSION['profile']['id']), "CCA", "certificate creation", "", 1);
381
382 $query = "insert into emailcerts set
383 `CN`='$defaultemail',
384 `keytype`='NS',
385 `memid`='".intval($_SESSION['profile']['id'])."',
386 `created`=FROM_UNIXTIME(UNIX_TIMESTAMP()),
387 `codesign`='".intval($_SESSION['_config']['codesign'])."',
388 `disablelogin`='".($_SESSION['_config']['disablelogin']?1:0)."',
389 `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
390 `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
391 mysql_query($query);
392 $emailid = mysql_insert_id();
393 if(is_array($addys))
394 foreach($addys as $addy)
395 mysql_query("insert into `emaillink` set `emailcertsid`='$emailid', `emailid`='$addy'");
396 $CSRname=generatecertpath("csr","client",$emailid);
397 $fp = fopen($CSRname, "w");
398 fputs($fp, $emails);
399 fclose($fp);
400 $challenge=$_SESSION['spkac_hash'];
401 $res=`openssl spkac -verify -in $CSRname`;
402 if(!strstr($res,"Challenge String: ".$challenge))
403 {
404 $id = $oldid;
405 showheader(_("My CAcert.org Account!"));
406 echo _("The challenge-response code of your certificate request did not match. Can't continue with certificaterequest.");
407 showfooter();
408 exit;
409 }
410 mysql_query("update `emailcerts` set `csr_name`='$CSRname' where `id`='".intval($emailid)."'");
411 } else if($_REQUEST['keytype'] == "MS" || $_REQUEST['keytype'] == "VI") {
412 if($csr == "")
413 $csr = "-----BEGIN CERTIFICATE REQUEST-----\n".clean_csr($_REQUEST['CSR'])."\n-----END CERTIFICATE REQUEST-----\n";
414
415 if (($weakKey = checkWeakKeyCSR($csr)) !== "")
416 {
417 $id = 4;
418 showheader(_("My CAcert.org Account!"));
419 echo $weakKey;
420 showfooter();
421 exit;
422 }
423
424 $tmpfname = tempnam("/tmp", "id4CSR");
425 $fp = fopen($tmpfname, "w");
426 fputs($fp, $csr);
427 fclose($fp);
428
429 $addys = array();
430 $defaultemail = "";
431 $csrsubject="";
432
433 $user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'"));
434 if(strlen($user['mname']) == 1)
435 $user['mname'] .= '.';
436 if($_SESSION['_config']['incname'] <= 0 || $_SESSION['_config']['incname'] > 4)
437 $csrsubject = "/CN=CAcert WoT User";
438 if($_SESSION['_config']['incname'] == 1)
439 $csrsubject = "/CN=".$user['fname']." ".$user['lname'];
440 if($_SESSION['_config']['incname'] == 2)
441 $csrsubject = "/CN=".$user['fname']." ".$user['mname']." ".$user['lname'];
442 if($_SESSION['_config']['incname'] == 3)
443 $csrsubject = "/CN=".$user['fname']." ".$user['lname']." ".$user['suffix'];
444 if($_SESSION['_config']['incname'] == 4)
445 $csrsubject = "/CN=".$user['fname']." ".$user['mname']." ".$user['lname']." ".$user['suffix'];
446 if(is_array($_SESSION['_config']['addid']))
447 foreach($_SESSION['_config']['addid'] as $id)
448 {
449 $res = mysql_query("select * from `email` where `memid`='".intval($_SESSION['profile']['id'])."' and `id`='".intval($id)."'");
450 if(mysql_num_rows($res) > 0)
451 {
452 $row = mysql_fetch_assoc($res);
453 if($defaultemail == "")
454 $defaultemail = $row['email'];
455 $csrsubject .= "/emailAddress=".$row['email'];
456 $addys[] = $row['id'];
457 }
458 }
459 if($_SESSION['_config']['SSO'] == 1)
460 $csrsubject .= "/emailAddress = ".$user['uniqueID'];
461
462 $tmpname = tempnam("/tmp", "id4csr");
463 $do = `/usr/bin/openssl req -in $tmpfname -out $tmpname`; // -subj "$csr"`;
464 @unlink($tmpfname);
465 $csr = "";
466 $fp = fopen($tmpname, "r");
467 while($data = fgets($fp, 4096))
468 $csr .= $data;
469 fclose($fp);
470 @unlink($tmpname);
471 if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
472 $_SESSION['_config']['rootcert'] = 1;
473
474 if($csr == "")
475 {
476 $id = 4;
477 showheader(_("My CAcert.org Account!"));
478 echo _("I didn't receive a valid Certificate Request, hit the back button and try again.");
479 showfooter();
480 exit;
481 }
482 $query = "insert into emailcerts set
483 `CN`='$defaultemail',
484 `keytype`='".sanitizeHTML($_REQUEST['keytype'])."',
485 `memid`='".intval($_SESSION['profile']['id'])."',
486 `created`=FROM_UNIXTIME(UNIX_TIMESTAMP()),
487 `subject`='".mysql_real_escape_string($csrsubject)."',
488 `codesign`='".intval($_SESSION['_config']['codesign'])."',
489 `disablelogin`='".($_SESSION['_config']['disablelogin']?1:0)."',
490 `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
491 `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
492 mysql_query($query);
493 $emailid = mysql_insert_id();
494 if(is_array($addys))
495 foreach($addys as $addy)
496 mysql_query("insert into `emaillink` set `emailcertsid`='$emailid', `emailid`='".mysql_real_escape_string($addy)."'");
497 $CSRname=generatecertpath("csr","client",$emailid);
498 $fp = fopen($CSRname, "w");
499 fputs($fp, $csr);
500 fclose($fp);
501 mysql_query("update `emailcerts` set `csr_name`='$CSRname' where `id`='$emailid'");
502 }
503 waitForResult("emailcerts", $emailid, 4);
504 $query = "select * from `emailcerts` where `id`='$emailid' and `crt_name` != ''";
505 $res = mysql_query($query);
506 if(mysql_num_rows($res) <= 0)
507 {
508 $id = 4;
509 showheader(_("My CAcert.org Account!"));
510 printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions."), "<a href='http://wiki.cacert.org/wiki/FAQ/CertificateRenewal'>", "</a>");
511 showfooter();
512 exit;
513 } else {
514 $id = 6;
515 $cert = $emailid;
516 $_REQUEST['cert']=$emailid;
517 }
518 }
519
520 if($oldid == 7)
521 {
522 csrf_check("adddomain");
523 if(strstr($_REQUEST['newdomain'],"\x00"))
524 {
525 showheader(_("My CAcert.org Account!"));
526 echo _("Due to the possibility for nullbyte domain exploits we currently do not allow any domain names with nullbytes.");
527 showfooter();
528 exit;
529 }
530
531 list($newdomain) = explode(" ", $_REQUEST['newdomain'], 2); // Ignore the rest
532 while($newdomain['0'] == '-')
533 $newdomain = substr($newdomain, 1);
534 if(strstr($newdomain, "xn--") && $_SESSION['profile']['codesign'] <= 0)
535 {
536 showheader(_("My CAcert.org Account!"));
537 echo _("Due to the possibility for punycode domain exploits we currently do not allow any certificates to sign punycode domains or email addresses.");
538 showfooter();
539 exit;
540 }
541
542 $newdom = trim(escapeshellarg($newdomain));
543 $newdomain = mysql_real_escape_string(trim($newdomain));
544
545 $res1 = mysql_query("select * from `orgdomains` where `domain`='$newdomain'");
546 $query = "select * from `domains` where `domain`='$newdomain' and `deleted`=0";
547 $res2 = mysql_query($query);
548 if(mysql_num_rows($res1) > 0 || mysql_num_rows($res2))
549 {
550 $oldid=0;
551 $id = 7;
552 showheader(_("My CAcert.org Account!"));
553 printf(_("The domain '%s' is already in a different account and is listed as valid. Can't continue."), sanitizeHTML($newdomain));
554 showfooter();
555 exit;
556 }
557 }
558
559 if($oldid == 7)
560 {
561 $oldid=0;
562 $id = 8;
563 $addy = array();
564 $adds = array();
565 if(strtolower(substr($newdom, -4, 3)) != ".jp")
566 $adds = explode("\n", trim(`/usr/bin/whois $newdom|grep "@"`));
567 if(substr($newdomain, -4) == ".org" || substr($newdomain, -5) == ".info")
568 {
569 if(is_array($adds))
570 foreach($adds as $line)
571 {
572 $bits = explode(":", $line, 2);
573 $line = trim($bits[1]);
574 if(!in_array($line, $addy) && $line != "")
575 $addy[] = trim(mysql_real_escape_string(stripslashes($line)));
576 }
577 } else {
578 if(is_array($adds))
579 foreach($adds as $line)
580 {
581 $line = trim(str_replace("\t", " ", $line));
582 $line = trim(str_replace("(", "", $line));
583 $line = trim(str_replace(")", " ", $line));
584 $line = trim(str_replace(":", " ", $line));
585
586 $bits = explode(" ", $line);
587 foreach($bits as $bit)
588 {
589 if(strstr($bit, "@"))
590 $line = $bit;
591 }
592 if(!in_array($line, $addy) && $line != "")
593 $addy[] = trim(mysql_real_escape_string(stripslashes($line)));
594 }
595 }
596
597 $rfc = array("root@$newdomain", "hostmaster@$newdomain", "postmaster@$newdomain", "admin@$newdomain", "webmaster@$newdomain");
598 foreach($rfc as $sub)
599 if(!in_array($sub, $addy))
600 $addy[] = $sub;
601 $_SESSION['_config']['addy'] = $addy;
602 $_SESSION['_config']['domain'] = mysql_real_escape_string($newdomain);
603 }
604
605 if($process != "" && $oldid == 8)
606 {
607 csrf_check('ctcinfo');
608 $oldid=0;
609 $id = 8;
610
611 $authaddy = trim(mysql_real_escape_string(stripslashes($_REQUEST['authaddy'])));
612
613 if($authaddy == "" || !is_array($_SESSION['_config']['addy']))
614 {
615 showheader(_("My CAcert.org Account!"));
616 echo _("The address you submitted isn't a valid authority address for the domain.");
617 showfooter();
618 exit;
619 }
620
621 if(!in_array($authaddy, $_SESSION['_config']['addy']))
622 {
623 showheader(_("My CAcert.org Account!"));
624 echo _("The address you submitted isn't a valid authority address for the domain.");
625 showfooter();
626 exit;
627 }
628
629 $query = "select * from `domains` where `domain`='".mysql_real_escape_string($_SESSION['_config']['domain'])."' and `deleted`=0";
630 $res = mysql_query($query);
631 if(mysql_num_rows($res) > 0)
632 {
633 showheader(_("My CAcert.org Account!"));
634 printf(_("The domain '%s' is already in a different account and is listed as valid. Can't continue."), sanitizeHTML($_SESSION['_config']['domain']));
635 showfooter();
636 exit;
637 }
638 $checkemail = checkEmail($authaddy);
639 if($checkemail != "OK")
640 {
641 showheader(_("My CAcert.org Account!"));
642 //echo "<p>"._("Email Address given was invalid, or a test connection couldn't be made to your server, or the server rejected the email address as invalid")."</p>\n";
643 if (substr($checkemail, 0, 1) == "4")
644 {
645 echo "<p>"._("The mail server responsible for your domain indicated a temporary failure. This may be due to anti-SPAM measures, such as greylisting. Please try again in a few minutes.")."</p>\n";
646 } else {
647 echo "<p>"._("Email Address given was invalid, or a test connection couldn't be made to your server, or the server rejected the email address as invalid")."</p>\n";
648 }
649 echo "<p>$checkemail</p>\n";
650 showfooter();
651 exit;
652 }
653
654 $hash = make_hash();
655 $query = "insert into `domains` set `domain`='".mysql_real_escape_string($_SESSION['_config']['domain'])."',
656 `memid`='".intval($_SESSION['profile']['id'])."',`created`=NOW(),`hash`='$hash'";
657 mysql_query($query);
658 $domainid = mysql_insert_id();
659
660 $body = sprintf(_("Below is the link you need to open to verify your domain '%s'. Once your address is verified you will be able to start issuing certificates to your heart's content!"),$_SESSION['_config']['domain'])."\n\n";
661 $body .= "http://".$_SESSION['_config']['normalhostname']."/verify.php?type=domain&domainid=$domainid&hash=$hash\n\n";
662 $body .= _("Best regards")."\n"._("CAcert.org Support!");
663
664 sendmail($authaddy, "[CAcert.org] "._("Email Probe"), $body, "support@cacert.org", "", "", "CAcert Support");
665
666 showheader(_("My CAcert.org Account!"));
667 printf(_("The domain '%s' has been added to the system, however before any certificates for this can be issued you need to open the link in a browser that has been sent to your email address."), $_SESSION['_config']['domain']);
668 showfooter();
669 exit;
670 }
671
672 if($process != "" && $oldid == 9)
673 {
674 $id = 9;
675 showheader(_("My CAcert.org Account!"));
676 if(array_key_exists('delid',$_REQUEST) && is_array($_REQUEST['delid']))
677 {
678 echo _("The following domains have been removed:")."<br>
679 ("._("Any valid certificates will be revoked as well").")<br>\n";
680
681 foreach($_REQUEST['delid'] as $id)
682 {
683 $id = intval($id);
684 $query = "select * from `domains` where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'";
685 $res = mysql_query($query);
686 if(mysql_num_rows($res) > 0)
687 {
688 $row = mysql_fetch_assoc($res);
689 echo $row['domain']."<br>\n";
690 account_domain_delete($row['id']);
691 }
692
693 }
694 }
695 else
696 {
697 echo _("You did not select any domains for removal.");
698 }
699
700 showfooter();
701 exit;
702 }
703
704 if($process != "" && $oldid == 10)
705 {
706 if(!array_key_exists('CCA',$_REQUEST))
707 {
708 showheader(_("My CAcert.org Account!"));
709 echo _("You did not accept the CAcert Community Agreement (CCA), hit the back button and try again.");
710 showfooter();
711 exit;
712 }
713
714 $CSR = clean_csr($_REQUEST['CSR']);
715 if(strpos($CSR,"---BEGIN")===FALSE)
716 {
717 // In case the CSR is missing the ---BEGIN lines, add them automatically:
718 $CSR = "-----BEGIN CERTIFICATE REQUEST-----\n".$CSR."\n-----END CERTIFICATE REQUEST-----\n";
719 }
720
721 if (($weakKey = checkWeakKeyCSR($CSR)) !== "")
722 {
723 showheader(_("My CAcert.org Account!"));
724 echo $weakKey;
725 showfooter();
726 exit;
727 }
728
729 if(trim($_REQUEST['description']) != ""){
730 $_SESSION['_config']['description']= trim(mysql_real_escape_string(stripslashes($_REQUEST['description'])));
731 }else{
732 $_SESSION['_config']['description']= "";
733 }
734
735 $_SESSION['_config']['tmpfname'] = tempnam("/tmp", "id10CSR");
736 $fp = fopen($_SESSION['_config']['tmpfname'], "w");
737 fputs($fp, $CSR);
738 fclose($fp);
739 $CSR = $_SESSION['_config']['tmpfname'];
740 $_SESSION['_config']['subject'] = trim(`/usr/bin/openssl req -text -noout -in "$CSR"|tr -d "\\0"|grep "Subject:"`);
741 $bits = explode(",", trim(`/usr/bin/openssl req -text -noout -in "$CSR"|tr -d "\\0"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:`));
742 foreach($bits as $val)
743 {
744 $_SESSION['_config']['subject'] .= "/subjectAltName=".trim($val);
745 }
746 $id = 11;
747
748 $_SESSION['_config']['0.CN'] = $_SESSION['_config']['0.subjectAltName'] = "";
749 extractit();
750 getcn();
751 getalt();
752
753 if($_SESSION['_config']['0.CN'] == "" && $_SESSION['_config']['0.subjectAltName'] == "")
754 {
755 showheader(_("My CAcert.org Account!"));
756 echo _("CommonName field was blank. This is usually caused by entering your own name when openssl prompt's you for 'YOUR NAME', or if you try to issue certificates for domains you haven't already verified, as such this process can't continue.");
757 showfooter();
758 exit;
759 }
760
761 $_SESSION['_config']['rootcert'] = 1;
762 if($_SESSION['profile']['points'] >= 50)
763 {
764 $_SESSION['_config']['rootcert'] = intval($_REQUEST['rootcert']);
765 if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
766 $_SESSION['_config']['rootcert'] = 1;
767 }
768 }
769
770 if($process != "" && $oldid == 11)
771 {
772 if(!file_exists($_SESSION['_config']['tmpfname']))
773 {
774 showheader(_("My CAcert.org Account!"));
775 printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions."), "<a href='http://wiki.cacert.org/wiki/FAQ/CertificateRenewal'>", "</a>");
776 showfooter();
777 exit;
778 }
779
780 if (($weakKey = checkWeakKeyCSR(file_get_contents(
781 $_SESSION['_config']['tmpfname']))) !== "")
782 {
783 showheader(_("My CAcert.org Account!"));
784 echo $weakKey;
785 showfooter();
786 exit;
787 }
788
789 $id = 11;
790 if($_SESSION['_config']['0.CN'] == "" && $_SESSION['_config']['0.subjectAltName'] == "")
791 {
792 showheader(_("My CAcert.org Account!"));
793 echo _("CommonName field was blank. This is usually caused by entering your own name when openssl prompt's you for 'YOUR NAME', or if you try to issue certificates for domains you haven't already verified, as such this process can't continue.");
794 showfooter();
795 exit;
796 }
797
798 $subject = buildSubjectFromSession();
799
800 if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
801 $_SESSION['_config']['rootcert'] = 1;
802
803 write_user_agreement(intval($_SESSION['profile']['id']), "CCA", "certificate creation", "", 1);
804
805 if(array_key_exists('0',$_SESSION['_config']['rowid']) && $_SESSION['_config']['rowid']['0'] > 0)
806 {
807 $query = "insert into `domaincerts` set
808 `CN`='".mysql_real_escape_string($_SESSION['_config']['rows']['0'])."',
809 `domid`='".mysql_real_escape_string($_SESSION['_config']['rowid']['0'])."',
810 `created`=NOW(),`subject`='".mysql_real_escape_string($subject)."',
811 `rootcert`='".mysql_real_escape_string($_SESSION['_config']['rootcert'])."',
812 `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
813 } elseif(array_key_exists('0',$_SESSION['_config']['altid']) && $_SESSION['_config']['altid']['0'] > 0) {
814 $query = "insert into `domaincerts` set
815 `CN`='".mysql_real_escape_string($_SESSION['_config']['altrows']['0'])."',
816 `domid`='".mysql_real_escape_string($_SESSION['_config']['altid']['0'])."',
817 `created`=NOW(),`subject`='".mysql_real_escape_string($subject)."',
818 `rootcert`='".mysql_real_escape_string($_SESSION['_config']['rootcert'])."',
819 `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
820 } else {
821 showheader(_("My CAcert.org Account!"));
822 echo _("Domain not verified.");
823 showfooter();
824 exit;
825 }
826
827 mysql_query($query);
828 $CSRid = mysql_insert_id();
829
830 if(is_array($_SESSION['_config']['rowid']))
831 foreach($_SESSION['_config']['rowid'] as $dom)
832 mysql_query("insert into `domlink` set `certid`='$CSRid', `domid`='$dom'");
833 if(is_array($_SESSION['_config']['altid']))
834 foreach($_SESSION['_config']['altid'] as $dom)
835 mysql_query("insert into `domlink` set `certid`='$CSRid', `domid`='$dom'");
836
837 $CSRname=generatecertpath("csr","server",$CSRid);
838 rename($_SESSION['_config']['tmpfname'], $CSRname);
839 chmod($CSRname,0644);
840 mysql_query("update `domaincerts` set `CSR_name`='$CSRname' where `id`='$CSRid'");
841 waitForResult("domaincerts", $CSRid, 11);
842 $query = "select * from `domaincerts` where `id`='$CSRid' and `crt_name` != ''";
843 $res = mysql_query($query);
844 if(mysql_num_rows($res) <= 0)
845 {
846 $id = 11;
847 showheader(_("My CAcert.org Account!"));
848 printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions."), "<a href='http://wiki.cacert.org/wiki/FAQ/CertificateRenewal'>", "</a>");
849 showfooter();
850 exit;
851 } else {
852 $id = 15;
853 $cert = $CSRid;
854 $_REQUEST['cert']=$CSRid;
855 }
856 }
857
858 if($oldid == 12 && array_key_exists('renew',$_REQUEST) && $_REQUEST['renew'] != "")
859 {
860 csrf_check('srvcerchange');
861 $id = 12;
862 showheader(_("My CAcert.org Account!"));
863 if(is_array($_REQUEST['revokeid']))
864 {
865 echo _("Now renewing the following certificates:")."<br>\n";
866 foreach($_REQUEST['revokeid'] as $id)
867 {
868 $id = intval($id);
869 echo _("Processing request")." $id:<br/>";
870 $query = "select *,UNIX_TIMESTAMP(`domaincerts`.`revoked`) as `revoke` from `domaincerts`,`domains`
871 where `domaincerts`.`id`='$id' and
872 `domaincerts`.`domid`=`domains`.`id` and
873 `domains`.`memid`='".intval($_SESSION['profile']['id'])."'";
874 $res = mysql_query($query);
875 if(mysql_num_rows($res) <= 0)
876 {
877 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br/>\n", $id);
878 continue;
879 }
880
881 $row = mysql_fetch_assoc($res);
882
883 if (($weakKey = checkWeakKeyX509(file_get_contents(
884 $row['crt_name']))) !== "")
885 {
886 echo $weakKey, "<br/>\n";
887 continue;
888 }
889
890 mysql_query("update `domaincerts` set `renewed`='1' where `id`='$id'");
891 $query = "insert into `domaincerts` set
892 `domid`='".$row['domid']."',
893 `CN`='".mysql_real_escape_string($row['CN'])."',
894 `subject`='".mysql_real_escape_string($row['subject'])."',".
895 //`csr_name`='".$row['csr_name']."', // RACE CONDITION
896 "`created`='".$row['created']."',
897 `modified`=NOW(),
898 `rootcert`='".$row['rootcert']."',
899 `type`='".$row['type']."',
900 `pkhash`='".$row['pkhash']."',
901 `description`='".$row['description']."'";
902 mysql_query($query);
903 $newid = mysql_insert_id();
904 $newfile=generatecertpath("csr","server",$newid);
905 copy($row['csr_name'], $newfile);
906 $_SESSION['_config']['subject'] = trim(`/usr/bin/openssl req -text -noout -in "$newfile"|tr -d "\\0"|grep "Subject:"`);
907 $bits = explode(",", trim(`/usr/bin/openssl req -text -noout -in "$newfile"|tr -d "\\0"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:`));
908 foreach($bits as $val)
909 {
910 $_SESSION['_config']['subject'] .= "/subjectAltName=".trim($val);
911 }
912 $_SESSION['_config']['0.CN'] = $_SESSION['_config']['0.subjectAltName'] = "";
913 extractit();
914 getcn();
915 getalt();
916
917 if($_SESSION['_config']['0.CN'] == "" && $_SESSION['_config']['0.subjectAltName'] == "")
918 {
919 echo _("CommonName field was blank. This is usually caused by entering your own name when openssl prompt's you for 'YOUR NAME', or if you try to issue certificates for domains you haven't already verified, as such this process can't continue.");
920 continue;
921 }
922
923 $subject = buildSubjectFromSession();
924 $subject = mysql_real_escape_string($subject);
925 mysql_query("update `domaincerts` set `subject`='$subject',`csr_name`='$newfile' where `id`='$newid'");
926
927 echo _("Renewing").": ".sanitizeHTML($_SESSION['_config']['0.CN'])."<br>\n";
928 waitForResult("domaincerts", $newid,$oldid,0);
929 $query = "select * from `domaincerts` where `id`='$newid' and `crt_name` != ''";
930 $res = mysql_query($query);
931 if(mysql_num_rows($res) <= 0)
932 {
933 printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions."), "<a href='http://wiki.cacert.org/wiki/FAQ/CertificateRenewal'>", "</a>");
934 } else {
935 $drow = mysql_fetch_assoc($res);
936 $cert = `/usr/bin/openssl x509 -in $drow[crt_name]`;
937 echo "<pre>\n$cert\n</pre>\n";
938 }
939 }
940 }
941 else
942 {
943 echo _("You did not select any certificates for renewal.");
944 }
945
946 showfooter();
947 exit;
948 }
949
950 if($oldid == 12 && array_key_exists('revoke',$_REQUEST) && $_REQUEST['revoke'] != "")
951 {
952 csrf_check('srvcerchange');
953 $id = 12;
954 showheader(_("My CAcert.org Account!"));
955 if(is_array($_REQUEST['revokeid']))
956 {
957 echo _("Now revoking the following certificates:")."<br>\n";
958 foreach($_REQUEST['revokeid'] as $id)
959 {
960 $id = intval($id);
961 $query = "select *,UNIX_TIMESTAMP(`domaincerts`.`revoked`) as `revoke` from `domaincerts`,`domains`
962 where `domaincerts`.`id`='$id' and
963 `domaincerts`.`domid`=`domains`.`id` and
964 `domains`.`memid`='".intval($_SESSION['profile']['id'])."'";
965 $res = mysql_query($query);
966 if(mysql_num_rows($res) <= 0)
967 {
968 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br>\n", $id);
969 continue;
970 }
971 $row = mysql_fetch_assoc($res);
972 if($row['revoke'] > 0)
973 {
974 printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."<br>\n", $row['CN']);
975 continue;
976 }
977 mysql_query("update `domaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'");
978 printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'<br/>', htmlspecialchars($row['CN']), htmlspecialchars($row['serial']));
979 }
980
981 // TRANSLATORS: Please don't translate "Certificate Revocation List (CRL)", it's a technical term
982 echo '<br/>'._('All listed certificates will be added to the Certificate Revocation List (CRL) soon.').'<br/>';
983
984 }
985 else
986 {
987 echo _("You did not select any certificates for revocation.");
988 }
989
990 if(array_key_exists('delid',$_REQUEST) && is_array($_REQUEST['delid']))
991 {
992 echo _("Now deleting the following pending requests:")."<br>\n";
993 foreach($_REQUEST['delid'] as $id)
994 {
995 $id = intval($id);
996 $query = "select *,UNIX_TIMESTAMP(`domaincerts`.`expire`) as `expired` from `domaincerts`,`domains`
997 where `domaincerts`.`id`='$id' and
998 `domaincerts`.`domid`=`domains`.`id` and
999 `domains`.`memid`='".intval($_SESSION['profile']['id'])."'";
1000 $res = mysql_query($query);
1001 if(mysql_num_rows($res) <= 0)
1002 {
1003 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br>\n", $id);
1004 continue;
1005 }
1006 $row = mysql_fetch_assoc($res);
1007 if($row['expired'] > 0)
1008 {
1009 printf(_("Couldn't remove the request for `%s`, request had already been processed.")."<br>\n", $row['CN']);
1010 continue;
1011 }
1012 mysql_query("delete from `domaincerts` where `id`='$id'");
1013 @unlink($row['csr_name']);
1014 @unlink($row['crt_name']);
1015 printf(_("Removed a pending request for '%s'")."<br>\n", $row['CN']);
1016 }
1017 }
1018 showfooter();
1019 exit;
1020 }
1021
1022 if($oldid == 12 && array_key_exists('change',$_REQUEST) && $_REQUEST['change'] != "")
1023 {
1024 showheader(_("My CAcert.org Account!"));
1025 foreach($_REQUEST as $id => $val)
1026 {
1027 if(substr($id,0,14)=="check_comment_")
1028 {
1029 $cid = intval(substr($id,14));
1030 $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid])));
1031 mysql_query("update `domaincerts` set `description`='$comment' where `id`='$cid'");
1032 }
1033 }
1034 echo(_("Certificate settings have been changed.")."<br/>\n");
1035 showfooter();
1036 exit;
1037 }
1038
1039
1040 if($oldid == 5 && array_key_exists('renew',$_REQUEST) && $_REQUEST['renew'] != "")
1041 {
1042 showheader(_("My CAcert.org Account!"));
1043 if(is_array($_REQUEST['revokeid']))
1044 {
1045 echo _("Now renewing the following certificates:")."<br>\n";
1046 foreach($_REQUEST['revokeid'] as $id)
1047 {
1048 $id = intval($id);
1049 $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `emailcerts`
1050 where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'";
1051 $res = mysql_query($query);
1052 if(mysql_num_rows($res) <= 0)
1053 {
1054 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br>\n", $id);
1055 continue;
1056 }
1057
1058 $row = mysql_fetch_assoc($res);
1059
1060 if (($weakKey = checkWeakKeyX509(file_get_contents(
1061 $row['crt_name']))) !== "")
1062 {
1063 echo $weakKey, "<br/>\n";
1064 continue;
1065 }
1066
1067 mysql_query("update `emailcerts` set `renewed`='1' where `id`='$id'");
1068 $query = "insert into emailcerts set
1069 `memid`='".$row['memid']."',
1070 `CN`='".mysql_real_escape_string($row['CN'])."',
1071 `subject`='".mysql_real_escape_string($row['subject'])."',
1072 `keytype`='".$row['keytype']."',
1073 `csr_name`='".$row['csr_name']."',
1074 `created`='".$row['created']."',
1075 `modified`=NOW(),
1076 `disablelogin`='".$row['disablelogin']."',
1077 `codesign`='".$row['codesign']."',
1078 `rootcert`='".$row['rootcert']."',
1079 `description`='".$row['description']."'";
1080 mysql_query($query);
1081 $newid = mysql_insert_id();
1082 $newfile=generatecertpath("csr","client",$newid);
1083 copy($row['csr_name'], $newfile);
1084 mysql_query("update `emailcerts` set `csr_name`='$newfile' where `id`='$newid'");
1085 $res = mysql_query("select * from `emaillink` where `emailcertsid`='".$row['id']."'");
1086 while($r2 = mysql_fetch_assoc($res))
1087 {
1088 mysql_query("insert into `emaillink` set `emailid`='".$r2['emailid']."',
1089 `emailcertsid`='$newid'");
1090 }
1091 waitForResult("emailcerts", $newid,$oldid,0);
1092 $query = "select * from `emailcerts` where `id`='$newid' and `crt_name` != ''";
1093 $res = mysql_query($query);
1094 if(mysql_num_rows($res) <= 0)
1095 {
1096 printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions."), "<a href='http://wiki.cacert.org/wiki/FAQ/CertificateRenewal'>", "</a>");
1097 } else {
1098 printf(_("Certificate for '%s' has been renewed."), $row['CN']);
1099 echo "<br/>\n<a href='account.php?id=6&cert=$newid' target='_new'>".
1100 _("Click here")."</a> "._("to install your certificate.")."<br/><br/>\n";
1101 }
1102 }
1103 }
1104 else
1105 {
1106 echo _("You did not select any certificates for renewal.")."<br/>";
1107 }
1108
1109 showfooter();
1110 exit;
1111 }
1112
1113 if($oldid == 5 && array_key_exists('revoke',$_REQUEST) && $_REQUEST['revoke'] != "")
1114 {
1115 $id = 5;
1116 showheader(_("My CAcert.org Account!"));
1117 if(array_key_exists('revokeid',$_REQUEST) && is_array($_REQUEST['revokeid']))
1118 {
1119 echo _("Now revoking the following certificates:")."<br>\n";
1120 foreach($_REQUEST['revokeid'] as $id)
1121 {
1122 $id = intval($id);
1123 $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `emailcerts`
1124 where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'";
1125 $res = mysql_query($query);
1126 if(mysql_num_rows($res) <= 0)
1127 {
1128 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br>\n", $id);
1129 continue;
1130 }
1131 $row = mysql_fetch_assoc($res);
1132 if($row['revoke'] > 0)
1133 {
1134 printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."<br>\n", $row['CN']);
1135 continue;
1136 }
1137 mysql_query("update `emailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'");
1138 printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'<br/>', htmlspecialchars($row['CN']), htmlspecialchars($row['serial']));
1139 }
1140
1141 // TRANSLATORS: Please don't translate "Certificate Revocation List (CRL)", it's a technical term
1142 echo '<br/>'._('All listed certificates will be added to the Certificate Revocation List (CRL) soon.').'<br/>';
1143 }
1144 else
1145 {
1146 echo _("You did not select any certificates for revocation.");
1147 }
1148
1149 if(array_key_exists('delid',$_REQUEST) && is_array($_REQUEST['delid']))
1150 {
1151 echo _("Now deleting the following pending requests:")."<br>\n";
1152 foreach($_REQUEST['delid'] as $id)
1153 {
1154 $id = intval($id);
1155 $query = "select *,UNIX_TIMESTAMP(`expire`) as `expired` from `emailcerts`
1156 where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'";
1157 $res = mysql_query($query);
1158 if(mysql_num_rows($res) <= 0)
1159 {
1160 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br>\n", $id);
1161 continue;
1162 }
1163 $row = mysql_fetch_assoc($res);
1164 if($row['expired'] > 0)
1165 {
1166 printf(_("Couldn't remove the request for `%s`, request had already been processed.")."<br>\n", $row['CN']);
1167 continue;
1168 }
1169 mysql_query("delete from `emailcerts` where `id`='$id'");
1170 @unlink($row['csr_name']);
1171 @unlink($row['crt_name']);
1172 printf(_("Removed a pending request for '%s'")."<br>\n", $row['CN']);
1173 }
1174 }
1175 showfooter();
1176 exit;
1177 }
1178
1179 if($oldid == 5 && array_key_exists('change',$_REQUEST) && $_REQUEST['change'] != "")
1180 {
1181 showheader(_("My CAcert.org Account!"));
1182 foreach($_REQUEST as $id => $val)
1183 {
1184 if(substr($id,0,5)=="cert_")
1185 {
1186 $cid = intval(substr($id,5));
1187 $dis=(array_key_exists('disablelogin_'.$cid,$_REQUEST) && $_REQUEST['disablelogin_'.$cid]=="1")?"0":"1";
1188 mysql_query("update `emailcerts` set `disablelogin`='$dis' where `id`='$cid' and `memid`='".intval($_SESSION['profile']['id'])."'");
1189 }
1190 if(substr($id,0,14)=="check_comment_")
1191 {
1192 $cid = intval(substr($id,14));
1193 if(!empty($_REQUEST['check_comment_'.$cid])) {
1194 $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid])));
1195 mysql_query("update `emailcerts` set `description`='$comment' where `id`='$cid' and `memid`='".intval($_SESSION['profile']['id'])."'");
1196 }
1197 }
1198 }
1199 echo(_("Certificate settings have been changed.")."<br/>\n");
1200 showfooter();
1201 exit;
1202 }
1203
1204 if($oldid == 13 && $process != "" && $showdetails!="")
1205 {
1206 csrf_check("perschange");
1207 $_SESSION['_config']['user'] = $_SESSION['profile'];
1208
1209 $_SESSION['_config']['user']['Q1'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['Q1']))));
1210 $_SESSION['_config']['user']['Q2'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['Q2']))));
1211 $_SESSION['_config']['user']['Q3'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['Q3']))));
1212 $_SESSION['_config']['user']['Q4'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['Q4']))));
1213 $_SESSION['_config']['user']['Q5'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['Q5']))));
1214 $_SESSION['_config']['user']['A1'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A1']))));
1215 $_SESSION['_config']['user']['A2'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A2']))));
1216 $_SESSION['_config']['user']['A3'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A3']))));
1217 $_SESSION['_config']['user']['A4'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A4']))));
1218 $_SESSION['_config']['user']['A5'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A5']))));
1219
1220 if($_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q2'] ||
1221 $_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q3'] ||
1222 $_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q4'] ||
1223 $_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q5'] ||
1224 $_SESSION['_config']['user']['Q2'] == $_SESSION['_config']['user']['Q3'] ||
1225 $_SESSION['_config']['user']['Q2'] == $_SESSION['_config']['user']['Q4'] ||
1226 $_SESSION['_config']['user']['Q2'] == $_SESSION['_config']['user']['Q5'] ||
1227 $_SESSION['_config']['user']['Q3'] == $_SESSION['_config']['user']['Q4'] ||
1228 $_SESSION['_config']['user']['Q3'] == $_SESSION['_config']['user']['Q5'] ||
1229 $_SESSION['_config']['user']['Q4'] == $_SESSION['_config']['user']['Q5'] ||
1230 $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q1'] ||
1231 $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q2'] ||
1232 $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q3'] ||
1233 $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q4'] ||
1234 $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q5'] ||
1235 $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['Q3'] ||
1236 $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['Q4'] ||
1237 $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['Q5'] ||
1238 $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['Q4'] ||
1239 $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['Q5'] ||
1240 $_SESSION['_config']['user']['A4'] == $_SESSION['_config']['user']['Q5'] ||
1241 $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A2'] ||
1242 $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A3'] ||
1243 $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A4'] ||
1244 $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A5'] ||
1245 $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['A3'] ||
1246 $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['A4'] ||
1247 $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['A5'] ||
1248 $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['A4'] ||
1249 $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['A5'] ||
1250 $_SESSION['_config']['user']['A4'] == $_SESSION['_config']['user']['A5'])
1251 {
1252 $_SESSION['_config']['errmsg'] .= _("For your own security you must enter 5 different password questions and answers. You aren't allowed to duplicate questions, set questions as answers or use the question as the answer.")."<br>\n";
1253 $id = $oldid;
1254 $oldid=0;
1255 }
1256
1257 if($_SESSION['_config']['user']['Q1'] == "" || $_SESSION['_config']['user']['Q2'] == "" ||
1258 $_SESSION['_config']['user']['Q3'] == "" || $_SESSION['_config']['user']['Q4'] == "" ||
1259 $_SESSION['_config']['user']['Q5'] == "")
1260 {
1261 $_SESSION['_config']['errmsg'] .= _("For your own security you must enter 5 lost password questions and answers.")."<br>";
1262 $id = $oldid;
1263 $oldid=0;
1264 }
1265 }
1266
1267 if($oldid == 13 && $process != "")
1268 {
1269 $ddquery = "select sum(`points`) as `total` from `notary` where `to`='".intval($_SESSION['profile']['id'])."' and `deleted` = 0 group by `to`";
1270 $ddres = mysql_query($ddquery);
1271 $ddrow = mysql_fetch_assoc($ddres);
1272 $_SESSION['profile']['points'] = $ddrow['total'];
1273
1274 if($_SESSION['profile']['points'] == 0)
1275 {
1276 $_SESSION['_config']['user']['fname'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['fname']))));
1277 $_SESSION['_config']['user']['mname'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['mname']))));
1278 $_SESSION['_config']['user']['lname'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['lname']))));
1279 $_SESSION['_config']['user']['suffix'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['suffix']))));
1280 $_SESSION['_config']['user']['day'] = intval($_REQUEST['day']);
1281 $_SESSION['_config']['user']['month'] = intval($_REQUEST['month']);
1282 $_SESSION['_config']['user']['year'] = intval($_REQUEST['year']);
1283
1284 if($_SESSION['_config']['user']['fname'] == "" || $_SESSION['_config']['user']['lname'] == "")
1285 {
1286 $_SESSION['_config']['errmsg'] .= _("First and Last name fields can not be blank.")."<br>";
1287 $id = $oldid;
1288 $oldid=0;
1289 }
1290 if($_SESSION['_config']['user']['year'] < 1900 || $_SESSION['_config']['user']['month'] < 1 || $_SESSION['_config']['user']['month'] > 12 ||
1291 $_SESSION['_config']['user']['day'] < 1 || $_SESSION['_config']['user']['day'] > 31)
1292 {
1293 $_SESSION['_config']['errmsg'] .= _("Invalid date of birth")."<br>\n";
1294 $id = $oldid;
1295 $oldid=0;
1296 }
1297 }
1298 }
1299
1300 if($oldid == 13 && $process != "")
1301 {
1302 if($_SESSION['profile']['points'] == 0)
1303 {
1304 $query = "update `users` set `fname`='".$_SESSION['_config']['user']['fname']."',
1305 `mname`='".$_SESSION['_config']['user']['mname']."',
1306 `lname`='".$_SESSION['_config']['user']['lname']."',
1307 `suffix`='".$_SESSION['_config']['user']['suffix']."',
1308 `dob`='".$_SESSION['_config']['user']['year']."-".$_SESSION['_config']['user']['month']."-".$_SESSION['_config']['user']['day']."'
1309 where `id`='".intval($_SESSION['profile']['id'])."'";
1310 mysql_query($query);
1311 }
1312 if ($showdetails!="") {
1313 $query = "update `users` set `Q1`='".$_SESSION['_config']['user']['Q1']."',
1314 `Q2`='".$_SESSION['_config']['user']['Q2']."',
1315 `Q3`='".$_SESSION['_config']['user']['Q3']."',
1316 `Q4`='".$_SESSION['_config']['user']['Q4']."',
1317 `Q5`='".$_SESSION['_config']['user']['Q5']."',
1318 `A1`='".$_SESSION['_config']['user']['A1']."',
1319 `A2`='".$_SESSION['_config']['user']['A2']."',
1320 `A3`='".$_SESSION['_config']['user']['A3']."',
1321 `A4`='".$_SESSION['_config']['user']['A4']."',
1322 `A5`='".$_SESSION['_config']['user']['A5']."'
1323 where `id`='".intval($_SESSION['profile']['id'])."'";
1324 mysql_query($query);
1325 }
1326
1327 //!!!Should be rewritten
1328 $_SESSION['_config']['user']['otphash'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['otphash']))));
1329 $_SESSION['_config']['user']['otppin'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['otppin']))));
1330 if($_SESSION['_config']['user']['otphash'] != "" && $_SESSION['_config']['user']['otppin'] != "")
1331 {
1332 $query = "update `users` set `otphash`='".mysql_real_escape_string($_SESSION['_config']['user']['otphash'])."',
1333 `otppin`='".mysql_real_escape_string($_SESSION['_config']['user']['otppin'])."' where `id`='".intval($_SESSION['profile']['id'])."'";
1334 mysql_query($query);
1335 }
1336
1337 $_SESSION['_config']['user']['set'] = 0;
1338 $_SESSION['profile'] = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'"));
1339 $_SESSION['profile']['loggedin'] = 1;
1340
1341 $ddquery = "select sum(`points`) as `total` from `notary` where `to`='".intval($_SESSION['profile']['id'])."' and `deleted` = 0 group by `to`";
1342 $ddres = mysql_query($ddquery);
1343 $ddrow = mysql_fetch_assoc($ddres);
1344 $_SESSION['profile']['points'] = $ddrow['total'];
1345
1346
1347 $id = 13;
1348 showheader(_("My CAcert.org Account!"));
1349 echo _("Your details have been updated with the database.");
1350 showfooter();
1351 exit;
1352 }
1353
1354 if($oldid == 14 && $process != "")
1355 {
1356 $_SESSION['_config']['user']['oldpass'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['oldpassword'])));
1357 $_SESSION['_config']['user']['pword1'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['pword1'])));
1358 $_SESSION['_config']['user']['pword2'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['pword2'])));
1359
1360 $id = 14;
1361 csrf_check("pwchange");
1362
1363 showheader(_("My CAcert.org Account!"));
1364 if($_SESSION['_config']['user']['pword1'] == "" || $_SESSION['_config']['user']['pword1'] != $_SESSION['_config']['user']['pword2'])
1365 {
1366 echo '<h3 style="color:red">', _("Failure: Pass Phrase not Changed"),
1367 '</h3>', "\n";
1368 echo _("New Pass Phrases specified don't match or were blank.");
1369 } else {
1370 $score = checkpw($_SESSION['_config']['user']['pword1'], $_SESSION['profile']['email'], $_SESSION['profile']['fname'],
1371 $_SESSION['profile']['mname'], $_SESSION['profile']['lname'], $_SESSION['profile']['suffix']);
1372
1373 if($_SESSION['_config']['hostname'] != $_SESSION['_config']['securehostname'])
1374 {
1375 $match = mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."' and
1376 (`password`=old_password('".$_SESSION['_config']['user']['oldpass']."') or
1377 `password`=sha1('".$_SESSION['_config']['user']['oldpass']."'))");
1378 $rc = mysql_num_rows($match);
1379 } else {
1380 $rc = 1;
1381 }
1382
1383 if(strlen($_SESSION['_config']['user']['pword1']) < 6) {
1384 echo '<h3 style="color:red">',
1385 _("Failure: Pass Phrase not Changed"), '</h3>', "\n";
1386 echo _("The Pass Phrase you submitted was too short.");
1387 } else if($score < 3) {
1388 echo '<h3 style="color:red">',
1389 _("Failure: Pass Phrase not Changed"), '</h3>', "\n";
1390 printf(_("The Pass Phrase you submitted failed to contain enough differing characters and/or contained words from your name and/or email address. Only scored %s points out of 6."), $score);
1391 } else if($rc <= 0) {
1392 echo '<h3 style="color:red">',
1393 _("Failure: Pass Phrase not Changed"), '</h3>', "\n";
1394 echo _("You failed to correctly enter your current Pass Phrase.");
1395 } else {
1396 mysql_query("update `users` set `password`=sha1('".$_SESSION['_config']['user']['pword1']."')
1397 where `id`='".intval($_SESSION['profile']['id'])."'");
1398 echo '<h3>', _("Pass Phrase Changed Successfully"), '</h3>', "\n";
1399 echo _("Your Pass Phrase has been updated and your primary email account has been notified of the change.");
1400 $body = sprintf(_("Hi %s,"),$_SESSION['profile']['fname'])."\n\n";
1401 $body .= _("You are receiving this email because you or someone else ".
1402 "has changed the password on your account.")."\n\n";
1403
1404 $body .= _("Best regards")."\n"._("CAcert.org Support!");
1405
1406 sendmail($_SESSION['profile']['email'], "[CAcert.org] "._("Password Update Notification"), $body,
1407 "support@cacert.org", "", "", "CAcert Support");
1408 }
1409 }
1410 showfooter();
1411 exit;
1412 }
1413
1414 if($oldid == 16)
1415 {
1416 $id = 16;
1417 $_SESSION['_config']['emails'] = array();
1418
1419 foreach($_REQUEST['emails'] as $val)
1420 {
1421 $val = mysql_real_escape_string(stripslashes(trim($val)));
1422 $bits = explode("@", $val);
1423 $count = count($bits);
1424 if($count != 2)
1425 continue;
1426
1427 if(checkownership($bits[1]) == false)
1428 continue;
1429
1430 if(!is_array($_SESSION['_config']['row']))
1431 continue;
1432 else if($_SESSION['_config']['row']['id'] > 0)
1433 $_SESSION['_config']['domids'][] = $_SESSION['_config']['row']['id'];
1434
1435 if($val != "")
1436 $_SESSION['_config']['emails'][] = $val;
1437 }
1438 $_SESSION['_config']['name'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['name'])));
1439 $_SESSION['_config']['OU'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['OU'])));
1440
1441
1442 if(trim($_REQUEST['description']) != ""){
1443 $_SESSION['_config']['description']= trim(mysql_real_escape_string(stripslashes($_REQUEST['description'])));
1444 }else{
1445 $_SESSION['_config']['description']= "";
1446 }
1447 }
1448
1449 if($oldid == 16 && (intval(count($_SESSION['_config']['emails'])) + 0) <= 0)
1450 {
1451 $id = 16;
1452 showheader(_("My CAcert.org Account!"));
1453 echo _("I couldn't match any emails against your organisational account.");
1454 showfooter();
1455 exit;
1456 }
1457
1458 if($oldid == 16 && $process != "")
1459 {
1460 if(array_key_exists('codesign',$_REQUEST) && $_REQUEST['codesign'] && $_SESSION['profile']['codesign'] && ($_SESSION['profile']['points'] >= 100))
1461 {
1462 $_REQUEST['codesign'] = 1;
1463 $_SESSION['_config']['codesign'] = 1;
1464 }
1465 else
1466 {
1467 $_REQUEST['codesign'] = 0;
1468 $_SESSION['_config']['codesign'] = 0;
1469 }
1470
1471 $_SESSION['_config']['rootcert'] = intval($_REQUEST['rootcert']);
1472 if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
1473 $_SESSION['_config']['rootcert'] = 1;
1474
1475 if(trim($_REQUEST['description']) != ""){
1476 $_SESSION['_config']['description']= trim(mysql_real_escape_string(stripslashes($_REQUEST['description'])));
1477 }else{
1478 $_SESSION['_config']['description']= "";
1479 }
1480
1481 if(@count($_SESSION['_config']['emails']) > 0)
1482 $id = 17;
1483 }
1484
1485 if($oldid == 17)
1486 {
1487 $org = $_SESSION['_config']['row'];
1488 if($_REQUEST['keytype'] == "NS")
1489 {
1490 $spkac=""; if(preg_match("/^[a-zA-Z0-9+=\/]+$/", trim(str_replace("\n", "", str_replace("\r", "",$_REQUEST['SPKAC']))))) $spkac=trim(str_replace("\n", "", str_replace("\r", "",$_REQUEST['SPKAC'])));
1491
1492 if($spkac == "" || strlen($spkac) < 128)
1493 {
1494 $id = 17;
1495 showheader(_("My CAcert.org Account!"));
1496 echo _("I didn't receive a valid Certificate Request, hit the back button and try again.");
1497 showfooter();
1498 exit;
1499 }
1500
1501 $count = 0;
1502 $emails = "";
1503 $addys = array();
1504 if(is_array($_SESSION['_config']['emails']))
1505 foreach($_SESSION['_config']['emails'] as $_REQUEST['email'])
1506 {
1507 if(!$emails)
1508 $defaultemail = $_REQUEST['email'];
1509 $emails .= "$count.emailAddress = $_REQUEST[email]\n";
1510 $count++;
1511 }
1512 if($_SESSION['_config']['name'] != "")
1513 $emails .= "commonName = ".$_SESSION['_config']['name']."\n";
1514 if($_SESSION['_config']['OU'])
1515 $emails .= "organizationalUnitName = ".$_SESSION['_config']['OU']."\n";
1516 if($org['O'])
1517 $emails .= "organizationName = ".$org['O']."\n";
1518 if($org['L'])
1519 $emails .= "localityName = ".$org['L']."\n";
1520 if($org['ST'])
1521 $emails .= "stateOrProvinceName = ".$org['ST']."\n";
1522 if($org['C'])
1523 $emails .= "countryName = ".$org['C']."\n";
1524 if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
1525 $_SESSION['_config']['rootcert'] = 1;
1526
1527
1528 $emails .= "SPKAC = $spkac";
1529 if (($weakKey = checkWeakKeySPKAC($emails)) !== "")
1530 {
1531 $id = 17;
1532 showheader(_("My CAcert.org Account!"));
1533 echo $weakKey;
1534 showfooter();
1535 exit;
1536 }
1537
1538 $query = "insert into `orgemailcerts` set
1539 `CN`='$defaultemail',
1540 `ou`='".mysql_real_escape_string($_SESSION['_config']['OU'])."',
1541 `keytype`='NS',
1542 `orgid`='".intval($org['orgid'])."',
1543 `created`=FROM_UNIXTIME(UNIX_TIMESTAMP()),
1544 `codesign`='".intval($_SESSION['_config']['codesign'])."',
1545 `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
1546 `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
1547 mysql_query($query);
1548 $emailid = mysql_insert_id();
1549
1550 foreach($_SESSION['_config']['domids'] as $addy)
1551 mysql_query("insert into `domemaillink` set `emailcertsid`='$emailid', `emailid`='$addy'");
1552
1553 $CSRname=generatecertpath("csr","orgclient",$emailid);
1554 $fp = fopen($CSRname, "w");
1555 fputs($fp, $emails);
1556 fclose($fp);
1557 $challenge=$_SESSION['spkac_hash'];
1558 $res=`openssl spkac -verify -in $CSRname`;
1559 if(!strstr($res,"Challenge String: ".$challenge))
1560 {
1561 $id = $oldid;
1562 showheader(_("My CAcert.org Account!"));
1563 echo _("The challenge-response code of your certificate request did not match. Can't continue with certificaterequest.");
1564 showfooter();
1565 exit;
1566 }
1567 mysql_query("update `orgemailcerts` set `csr_name`='$CSRname' where `id`='$emailid'");
1568 } else if($_REQUEST['keytype'] == "MS" || $_REQUEST['keytype']=="VI") {
1569 $csr = "-----BEGIN CERTIFICATE REQUEST-----\n".clean_csr($_REQUEST['CSR'])."-----END CERTIFICATE REQUEST-----\n";
1570
1571 if (($weakKey = checkWeakKeyCSR($csr)) !== "")
1572 {
1573 $id = 17;
1574 showheader(_("My CAcert.org Account!"));
1575 echo $weakKey;
1576 showfooter();
1577 exit;
1578 }
1579
1580 $tmpfname = tempnam("/tmp", "id17CSR");
1581 $fp = fopen($tmpfname, "w");
1582 fputs($fp, $csr);
1583 fclose($fp);
1584
1585 $addys = array();
1586 $defaultemail = "";
1587 $csrsubject="";
1588
1589 if($_SESSION['_config']['name'] != "")
1590 $csrsubject = "/CN=".$_SESSION['_config']['name'];
1591 if(is_array($_SESSION['_config']['emails']))
1592 foreach($_SESSION['_config']['emails'] as $_REQUEST['email'])
1593 {
1594 if($defaultemail == "")
1595 $defaultemail = $_REQUEST['email'];
1596 $csrsubject .= "/emailAddress=$_REQUEST[email]";
1597 }
1598 if($_SESSION['_config']['OU'])
1599 $csrsubject .= "/organizationalUnitName=".$_SESSION['_config']['OU'];
1600 if($org['O'])
1601 $csrsubject .= "/organizationName=".$org['O'];
1602 if($org['L'])
1603 $csrsubject .= "/localityName=".$org['L'];
1604 if($org['ST'])
1605 $csrsubject .= "/stateOrProvinceName=".$org['ST'];
1606 if($org['C'])
1607 $csrsubject .= "/countryName=".$org['C'];
1608
1609 $tmpname = tempnam("/tmp", "id17csr");
1610 $do = `/usr/bin/openssl req -in $tmpfname -out $tmpname`;
1611 @unlink($tmpfname);
1612 $csr = "";
1613 $fp = fopen($tmpname, "r");
1614 while($data = fgets($fp, 4096))
1615 $csr .= $data;
1616 fclose($fp);
1617 @unlink($tmpname);
1618
1619 if($csr == "")
1620 {
1621 showheader(_("My CAcert.org Account!"));
1622 echo _("I didn't receive a valid Certificate Request, hit the back button and try again.");
1623 showfooter();
1624 exit;
1625 }
1626 if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
1627 $_SESSION['_config']['rootcert'] = 1;
1628
1629 $query = "insert into `orgemailcerts` set
1630 `CN`='$defaultemail',
1631 `ou`='".mysql_real_escape_string($_SESSION['_config']['OU'])."',
1632 `keytype`='" . sanitizeHTML($_REQUEST['keytype']) . "',
1633 `orgid`='".intval($org['orgid'])."',
1634 `created`=FROM_UNIXTIME(UNIX_TIMESTAMP()),
1635 `subject`='".mysql_real_escape_string($csrsubject)."',
1636 `codesign`='".intval($_SESSION['_config']['codesign'])."',
1637 `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
1638 `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
1639 mysql_query($query);
1640 $emailid = mysql_insert_id();
1641
1642 foreach($_SESSION['_config']['domids'] as $addy)
1643 mysql_query("insert into `domemaillink` set `emailcertsid`='$emailid', `emailid`='$addy'");
1644
1645 $CSRname=generatecertpath("csr","orgclient",$emailid);
1646 $fp = fopen($CSRname, "w");
1647 fputs($fp, $csr);
1648 fclose($fp);
1649 mysql_query("update `orgemailcerts` set `csr_name`='$CSRname' where `id`='$emailid'");
1650 }
1651 waitForResult("orgemailcerts", $emailid,$oldid);
1652 $query = "select * from `orgemailcerts` where `id`='$emailid' and `crt_name` != ''";
1653 $res = mysql_query($query);
1654 if(mysql_num_rows($res) <= 0)
1655 {
1656 showheader(_("My CAcert.org Account!"));
1657 printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions."), "<a href='http://wiki.cacert.org/wiki/FAQ/CertificateRenewal'>", "</a>");
1658 showfooter();
1659 exit;
1660 } else {
1661 $id = 19;
1662 $cert = $emailid;
1663 $_REQUEST['cert']=$emailid;
1664 }
1665 }
1666
1667 if($oldid == 18 && array_key_exists('renew',$_REQUEST) && $_REQUEST['renew'] != "")
1668 {
1669 csrf_check('clicerchange');
1670 showheader(_("My CAcert.org Account!"));
1671 if(is_array($_REQUEST['revokeid']))
1672 {
1673 $id = 18;
1674 echo _("Now renewing the following certificates:")."<br>\n";
1675 foreach($_REQUEST['revokeid'] as $id)
1676 {
1677 echo "Renewing certificate #$id ...\n<br/>";
1678 $id = intval($id);
1679 $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `orgemailcerts`, `org`
1680 where `orgemailcerts`.`id`='$id' and `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
1681 `org`.`orgid`=`orgemailcerts`.`orgid`";
1682 $res = mysql_query($query);
1683 if(mysql_num_rows($res) <= 0)
1684 {
1685 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br>\n", $id);
1686 continue;
1687 }
1688
1689 $row = mysql_fetch_assoc($res);
1690
1691 if (($weakKey = checkWeakKeyX509(file_get_contents(
1692 $row['crt_name']))) !== "")
1693 {
1694 echo $weakKey, "<br/>\n";
1695 continue;
1696 }
1697
1698 mysql_query("update `orgemailcerts` set `renewed`='1' where `id`='$id'");
1699 if($row['revoke'] > 0)
1700 {
1701 printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."<br>\n", $row['CN']);
1702 continue;
1703 }
1704 $query = "insert into `orgemailcerts` set
1705 `orgid`='".$row['orgid']."',
1706 `CN`='".$row['CN']."',
1707 `ou`='".$row['ou']."',
1708 `subject`='".$row['subject']."',
1709 `keytype`='".$row['keytype']."',
1710 `csr_name`='".$row['csr_name']."',
1711 `created`='".$row['created']."',
1712 `modified`=NOW(),
1713 `codesign`='".$row['codesign']."',
1714 `rootcert`='".$row['rootcert']."',
1715 `description`='".$row['description']."'";
1716 mysql_query($query);
1717 $newid = mysql_insert_id();
1718 $newfile=generatecertpath("csr","orgclient",$newid);
1719 copy($row['csr_name'], $newfile);
1720 mysql_query("update `orgemailcerts` set `csr_name`='$newfile' where `id`='$newid'");
1721 waitForResult("orgemailcerts", $newid,$oldid,0);
1722 $query = "select * from `orgemailcerts` where `id`='$newid' and `crt_name` != ''";
1723 $res = mysql_query($query);
1724 if(mysql_num_rows($res) > 0)
1725 {
1726 printf(_("Certificate for '%s' has been renewed."), $row['CN']);
1727 echo "<a href='account.php?id=19&cert=$newid' target='_new'>".
1728 _("Click here")."</a> "._("to install your certificate.");
1729 }
1730 echo("<br/>");
1731 }
1732 }
1733 else
1734 {
1735 echo _("You did not select any certificates for renewal.");
1736 }
1737 showfooter();
1738 exit;
1739 }
1740
1741 if($oldid == 18 && array_key_exists('revoke',$_REQUEST) && $_REQUEST['revoke'] != "")
1742 {
1743 csrf_check('clicerchange');
1744 $id = 18;
1745 showheader(_("My CAcert.org Account!"));
1746 if(is_array($_REQUEST['revokeid']))
1747 {
1748 echo _("Now revoking the following certificates:")."<br>\n";
1749 foreach($_REQUEST['revokeid'] as $id)
1750 {
1751 $id = intval($id);
1752 $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `orgemailcerts`, `org`
1753 where `orgemailcerts`.`id`='".intval($id)."' and `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
1754 `org`.`orgid`=`orgemailcerts`.`orgid`";
1755 $res = mysql_query($query);
1756 if(mysql_num_rows($res) <= 0)
1757 {
1758 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br>\n", $id);
1759 continue;
1760 }
1761 $row = mysql_fetch_assoc($res);
1762 if($row['revoke'] > 0)
1763 {
1764 printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."<br>\n", $row['CN']);
1765 continue;
1766 }
1767 mysql_query("update `orgemailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'");
1768 printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'<br/>', htmlspecialchars($row['CN']), htmlspecialchars($row['serial']));
1769 }
1770
1771 // TRANSLATORS: Please don't translate "Certificate Revocation List (CRL)", it's a technical term
1772 echo '<br/>'._('All listed certificates will be added to the Certificate Revocation List (CRL) soon.').'<br/>';
1773 }
1774 else
1775 {
1776 echo _("You did not select any certificates for revocation.");
1777 }
1778
1779 if(array_key_exists('delid',$_REQUEST) && is_array($_REQUEST['delid']))
1780 {
1781 echo _("Now deleting the following pending requests:")."<br>\n";
1782 foreach($_REQUEST['delid'] as $id)
1783 {
1784 $id = intval($id);
1785 $query = "select *,UNIX_TIMESTAMP(`expire`) as `expired` from `orgemailcerts`, `org`
1786 where `orgemailcerts`.`id`='".intval($id)."' and `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
1787 `org`.`orgid`=`orgemailcerts`.`orgid`";
1788 $res = mysql_query($query);
1789 if(mysql_num_rows($res) <= 0)
1790 {
1791 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br>\n", $id);
1792 continue;
1793 }
1794 $row = mysql_fetch_assoc($res);
1795 if($row['expired'] > 0)
1796 {
1797 printf(_("Couldn't remove the request for `%s`, request had already been processed.")."<br>\n", $row['CN']);
1798 continue;
1799 }
1800 mysql_query("delete from `orgemailcerts` where `id`='$id'");
1801 @unlink($row['csr_name']);
1802 @unlink($row['crt_name']);
1803 printf(_("Removed a pending request for '%s'")."<br>\n", $row['CN']);
1804 }
1805 }
1806 showfooter();
1807 exit;
1808 }
1809
1810 if($oldid == 18 && array_key_exists('change',$_REQUEST) && $_REQUEST['change'] != "")
1811 {
1812 showheader(_("My CAcert.org Account!"));
1813 foreach($_REQUEST as $id => $val)
1814 {
1815 if(substr($id,0,14)=="check_comment_")
1816 {
1817 $cid = intval(substr($id,14));
1818 $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid])));
1819 mysql_query("update `orgemailcerts` set `description`='$comment' where `id`='$cid'");
1820 }
1821 }
1822 echo(_("Certificate settings have been changed.")."<br/>\n");
1823 showfooter();
1824 exit;
1825 }
1826
1827 if($oldid == 18 && array_key_exists('filter',$_REQUEST) && $_REQUEST['filter']!= "")
1828 {
1829 $id=18;
1830 $_SESSION['_config']['orgfilterid']=$_REQUEST['orgfilterid'];
1831 $_SESSION['_config']['sorting']=$_REQUEST['sorting'];
1832 $_SESSION['_config']['status']=$_REQUEST['status'];
1833 }
1834
1835 if($oldid == 18 && array_key_exists('reset',$_REQUEST) && $_REQUEST['reset']!= "")
1836 {
1837 $id=18;
1838 $_SESSION['_config']['orgfilterid']=0;
1839 $_SESSION['_config']['sorting']=0;
1840 $_SESSION['_config']['status']=0;
1841 }
1842
1843 if($process != "" && $oldid == 20)
1844 {
1845 $CSR = clean_csr($_REQUEST['CSR']);
1846
1847 if (($weakKey = checkWeakKeyCSR($CSR)) !== "")
1848 {
1849 $id = 20;
1850 showheader(_("My CAcert.org Account!"));
1851 echo $weakKey;
1852 showfooter();
1853 exit;
1854 }
1855
1856 if(trim($_REQUEST['description']) != ""){
1857 $_SESSION['_config']['description']= trim(mysql_real_escape_string(stripslashes($_REQUEST['description'])));
1858 }else{
1859 $_SESSION['_config']['description']= "";
1860 }
1861
1862 $_SESSION['_config']['tmpfname'] = tempnam("/tmp", "id20CSR");
1863 $fp = fopen($_SESSION['_config']['tmpfname'], "w");
1864 fputs($fp, $CSR);
1865 fclose($fp);
1866 $CSR = $_SESSION['_config']['tmpfname'];
1867 $_SESSION['_config']['subject'] = trim(`/usr/bin/openssl req -text -noout -in "$CSR"|tr -d "\\0"|grep "Subject:"`);
1868 $bits = explode(",", trim(`/usr/bin/openssl req -text -noout -in "$CSR"|tr -d "\\0"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:`));
1869 foreach($bits as $val)
1870 {
1871 $_SESSION['_config']['subject'] .= "/subjectAltName=".trim($val);
1872 }
1873 $id = 21;
1874
1875 $_SESSION['_config']['0.CN'] = $_SESSION['_config']['0.subjectAltName'] = "";
1876 extractit();
1877 getcn2();
1878 getalt2();
1879
1880 $query = "select * from `orginfo`,`org`,`orgdomains` where
1881 `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
1882 `org`.`orgid`=`orginfo`.`id` and
1883 `org`.`orgid`=`orgdomains`.`orgid` and
1884 `orgdomains`.`domain`='".mysql_real_escape_string($_SESSION['_config']['0.CN'])."'";
1885 $_SESSION['_config']['CNorg'] = mysql_fetch_assoc(mysql_query($query));
1886 $query = "select * from `orginfo`,`org`,`orgdomains` where
1887 `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
1888 `org`.`orgid`=`orginfo`.`id` and
1889 `org`.`orgid`=`orgdomains`.`orgid` and
1890 `orgdomains`.`domain`='".mysql_real_escape_string($_SESSION['_config']['0.subjectAltName'])."'";
1891 $_SESSION['_config']['SANorg'] = mysql_fetch_assoc(mysql_query($query));
1892 //echo "<pre>"; print_r($_SESSION['_config']); die;
1893
1894 if($_SESSION['_config']['0.CN'] == "" && $_SESSION['_config']['0.subjectAltName'] == "")
1895 {
1896 $id = 20;
1897 showheader(_("My CAcert.org Account!"));
1898 echo _("CommonName field was blank. This is usually caused by entering your own name when openssl prompt's you for 'YOUR NAME', or if you try to issue certificates for domains you haven't already verified, as such this process can't continue.");
1899 showfooter();
1900 exit;
1901 }
1902
1903 $_SESSION['_config']['rootcert'] = intval($_REQUEST['rootcert']);
1904 if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
1905 $_SESSION['_config']['rootcert'] = 1;
1906 }
1907
1908 if($process != "" && $oldid == 21)
1909 {
1910 $id = 21;
1911
1912 if(!file_exists($_SESSION['_config']['tmpfname']))
1913 {
1914 showheader(_("My CAcert.org Account!"));
1915 printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions."), "<a href='http://wiki.cacert.org/wiki/FAQ/CertificateRenewal'>", "</a>");
1916 showfooter();
1917 exit;
1918 }
1919
1920 if (($weakKey = checkWeakKeyCSR(file_get_contents(
1921 $_SESSION['_config']['tmpfname']))) !== "")
1922 {
1923 showheader(_("My CAcert.org Account!"));
1924 echo $weakKey;
1925 showfooter();
1926 exit;
1927 }
1928
1929 if($_SESSION['_config']['0.CN'] == "" && $_SESSION['_config']['0.subjectAltName'] == "")
1930 {
1931 showheader(_("My CAcert.org Account!"));
1932 echo _("CommonName field was blank. This is usually caused by entering your own name when openssl prompt's you for 'YOUR NAME', or if you try to issue certificates for domains you haven't already verified, as such this process can't continue.");
1933 showfooter();
1934 exit;
1935 }
1936
1937 if($_SESSION['_config']['rowid']['0'] > 0)
1938 {
1939 $query = "select * from `org`,`orginfo` where
1940 `orginfo`.`id`='".intval($_SESSION['_config']['rowid']['0'])."' and
1941 `orginfo`.`id`=`org`.`orgid` and
1942 `org`.`memid`='".intval($_SESSION['profile']['id'])."'";
1943 } else {
1944 $query = "select * from `org`,`orginfo` where
1945 `orginfo`.`id`='".intval($_SESSION['_config']['altid']['0'])."' and
1946 `orginfo`.`id`=`org`.`orgid` and
1947 `org`.`memid`='".intval($_SESSION['profile']['id'])."'";
1948 }
1949 $org = mysql_fetch_assoc(mysql_query($query));
1950 $csrsubject = "";
1951
1952 if($_SESSION['_config']['OU'])
1953 $csrsubject .= "/organizationalUnitName=".$_SESSION['_config']['OU'];
1954 if($org['O'])
1955 $csrsubject .= "/organizationName=".$org['O'];
1956 if($org['L'])
1957 $csrsubject .= "/localityName=".$org['L'];
1958 if($org['ST'])
1959 $csrsubject .= "/stateOrProvinceName=".$org['ST'];
1960 if($org['C'])
1961 $csrsubject .= "/countryName=".$org['C'];
1962 //if($org['contact'])
1963 // $csrsubject .= "/emailAddress=".trim($org['contact']);
1964
1965 $csrsubject .= buildSubjectFromSession();
1966
1967 $type="";
1968 if($_REQUEST["ocspcert"]!="" && $_SESSION['profile']['admin'] == 1) $type="8";
1969 if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
1970 $_SESSION['_config']['rootcert'] = 1;
1971
1972 if($_SESSION['_config']['rowid']['0'] > 0)
1973 {
1974 $query = "insert into `orgdomaincerts` set
1975 `CN`='".mysql_real_escape_string($_SESSION['_config']['rows']['0'])."',
1976 `orgid`='".intval($org['id'])."',
1977 `created`=NOW(),
1978 `subject`='".mysql_real_escape_string($csrsubject)."',
1979 `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
1980 `type`='".$type."',
1981 `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
1982 } else {
1983 $query = "insert into `orgdomaincerts` set
1984 `CN`='".mysql_real_escape_string($_SESSION['_config']['altrows']['0'])."',
1985 `orgid`='".intval($org['id'])."',
1986 `created`=NOW(),
1987 `subject`='".mysql_real_escape_string($csrsubject)."',
1988 `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
1989 `type`='".$type."',
1990 `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
1991 }
1992 mysql_query($query);
1993 $CSRid = mysql_insert_id();
1994
1995 $CSRname=generatecertpath("csr","orgserver",$CSRid);
1996 rename($_SESSION['_config']['tmpfname'], $CSRname);
1997 chmod($CSRname,0644);
1998 mysql_query("update `orgdomaincerts` set `CSR_name`='$CSRname' where `id`='$CSRid'");
1999 if(is_array($_SESSION['_config']['rowid']))
2000 foreach($_SESSION['_config']['rowid'] as $id)
2001 mysql_query("insert into `orgdomlink` set `orgdomid`='".intval($id)."', `orgcertid`='$CSRid'");
2002 if(is_array($_SESSION['_config']['altid']))
2003 foreach($_SESSION['_config']['altid'] as $id)
2004 mysql_query("insert into `orgdomlink` set `orgdomid`='".intval($id)."', `orgcertid`='$CSRid'");
2005 waitForResult("orgdomaincerts", $CSRid,$oldid);
2006 $query = "select * from `orgdomaincerts` where `id`='$CSRid' and `crt_name` != ''";
2007 $res = mysql_query($query);
2008 if(mysql_num_rows($res) <= 0)
2009 {
2010 showheader(_("My CAcert.org Account!"));
2011 printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions.")." CSRid: $CSRid", "<a href='http://wiki.cacert.org/wiki/FAQ/CertificateRenewal'>", "</a>");
2012 showfooter();
2013 exit;
2014 } else {
2015 $id = 23;
2016 $cert = $CSRid;
2017 $_REQUEST['cert']=$CSRid;
2018 }
2019 }
2020
2021 if($oldid == 22 && array_key_exists('renew',$_REQUEST) && $_REQUEST['renew'] != "")
2022 {
2023 csrf_check('orgsrvcerchange');
2024 showheader(_("My CAcert.org Account!"));
2025 if(is_array($_REQUEST['revokeid']))
2026 {
2027 echo _("Now renewing the following certificates:")."<br>\n";
2028 foreach($_REQUEST['revokeid'] as $id)
2029 {
2030 $id = intval($id);
2031 $query = "select *,UNIX_TIMESTAMP(`orgdomaincerts`.`revoked`) as `revoke` from
2032 `orgdomaincerts`,`org`
2033 where `orgdomaincerts`.`id`='$id' and
2034 `orgdomaincerts`.`orgid`=`org`.`orgid` and
2035 `org`.`memid`='".intval($_SESSION['profile']['id'])."'";
2036 $res = mysql_query($query);
2037 if(mysql_num_rows($res) <= 0)
2038 {
2039 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br>\n", $id);
2040 continue;
2041 }
2042
2043 $row = mysql_fetch_assoc($res);
2044
2045 if (($weakKey = checkWeakKeyX509(file_get_contents(
2046 $row['crt_name']))) !== "")
2047 {
2048 echo $weakKey, "<br/>\n";
2049 continue;
2050 }
2051
2052 mysql_query("update `orgdomaincerts` set `renewed`='1' where `id`='$id'");
2053 if($row['revoke'] > 0)
2054 {
2055 printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."<br>\n", $row['CN']);
2056 continue;
2057 }
2058 $query = "insert into `orgdomaincerts` set
2059 `orgid`='".$row['orgid']."',
2060 `CN`='".$row['CN']."',
2061 `csr_name`='".$row['csr_name']."',
2062 `created`='".$row['created']."',
2063 `modified`=NOW(),
2064 `subject`='".$row['subject']."',
2065 `type`='".$row['type']."',
2066 `rootcert`='".$row['rootcert']."',
2067 `description`='".$row['description']."'";
2068 mysql_query($query);
2069 $newid = mysql_insert_id();
2070 //echo "NewID: $newid<br/>\n";
2071 $newfile=generatecertpath("csr","orgserver",$newid);
2072 copy($row['csr_name'], $newfile);
2073 mysql_query("update `orgdomaincerts` set `csr_name`='$newfile' where `id`='$newid'");
2074 echo _("Renewing").": ".$row['CN']."<br>\n";
2075 $res = mysql_query("select * from `orgdomlink` where `orgcertid`='".$row['id']."'");
2076 while($r2 = mysql_fetch_assoc($res))
2077 mysql_query("insert into `orgdomlink` set `orgdomid`='".$r2['id']."', `orgcertid`='$newid'");
2078 waitForResult("orgdomaincerts", $newid,$oldid,0);
2079 $query = "select * from `orgdomaincerts` where `id`='$newid' and `crt_name` != ''";
2080 $res = mysql_query($query);
2081 if(mysql_num_rows($res) <= 0)
2082 {
2083 printf(_("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions.")." newid: $newid", "<a href='http://wiki.cacert.org/wiki/FAQ/CertificateRenewal'>", "</a>");
2084 } else {
2085 $drow = mysql_fetch_assoc($res);
2086 $cert = `/usr/bin/openssl x509 -in $drow[crt_name]`;
2087 echo "<pre>\n$cert\n</pre>\n";
2088 }
2089 }
2090 }
2091 else
2092 {
2093 echo _("You did not select any certificates for renewal.");
2094 }
2095 showfooter();
2096 exit;
2097 }
2098
2099 if($oldid == 22 && array_key_exists('revoke',$_REQUEST) && $_REQUEST['revoke'] != "")
2100 {
2101 csrf_check('orgsrvcerchange');
2102 showheader(_("My CAcert.org Account!"));
2103 if(is_array($_REQUEST['revokeid']))
2104 {
2105 echo _("Now revoking the following certificates:")."<br>\n";
2106 foreach($_REQUEST['revokeid'] as $id)
2107 {
2108 $id = intval($id);
2109 $query = "select *,UNIX_TIMESTAMP(`orgdomaincerts`.`revoked`) as `revoke` from
2110 `orgdomaincerts`,`org`
2111 where `orgdomaincerts`.`id`='$id' and
2112 `orgdomaincerts`.`orgid`=`org`.`orgid` and
2113 `org`.`memid`='".intval($_SESSION['profile']['id'])."'";
2114 $res = mysql_query($query);
2115 if(mysql_num_rows($res) <= 0)
2116 {
2117 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br>\n", $id);
2118 continue;
2119 }
2120 $row = mysql_fetch_assoc($res);
2121 if($row['revoke'] > 0)
2122 {
2123 printf(_("It would seem '%s' has already been revoked. I'll skip this for now.")."<br>\n", $row['CN']);
2124 continue;
2125 }
2126 mysql_query("update `orgdomaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'");
2127 printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'<br/>', htmlspecialchars($row['CN']), htmlspecialchars($row['serial']));
2128 }
2129
2130 // TRANSLATORS: Please don't translate "Certificate Revocation List (CRL)", it's a technical term
2131 echo '<br/>'._('All listed certificates will be added to the Certificate Revocation List (CRL) soon.').'<br/>';
2132 }
2133 else
2134 {
2135 echo _("You did not select any certificates for revocation.");
2136 }
2137
2138 if(array_key_exists('delid',$_REQUEST) && is_array($_REQUEST['delid']))
2139 {
2140 echo _("Now deleting the following pending requests:")."<br>\n";
2141 foreach($_REQUEST['delid'] as $id)
2142 {
2143 $id = intval($id);
2144 $query = "select *,UNIX_TIMESTAMP(`orgdomaincerts`.`expire`) as `expired` from
2145 `orgdomaincerts`,`org`
2146 where `orgdomaincerts`.`id`='$id' and
2147 `orgdomaincerts`.`orgid`=`org`.`orgid` and
2148 `org`.`memid`='".intval($_SESSION['profile']['id'])."'";
2149 $res = mysql_query($query);
2150 if(mysql_num_rows($res) <= 0)
2151 {
2152 printf(_("Invalid ID '%s' presented, can't do anything with it.")."<br>\n", $id);
2153 continue;
2154 }
2155 $row = mysql_fetch_assoc($res);
2156 if($row['expired'] > 0)
2157 {
2158 printf(_("Couldn't remove the request for `%s`, request had already been processed.")."<br>\n", $row['CN']);
2159 continue;
2160 }
2161 mysql_query("delete from `orgdomaincerts` where `id`='$id'");
2162 @unlink($row['csr_name']);
2163 @unlink($row['crt_name']);
2164 printf(_("Removed a pending request for '%s'")."<br>\n", $row['CN']);
2165 }
2166 }
2167 showfooter();
2168 exit;
2169 }
2170
2171 if($oldid == 22 && array_key_exists('change',$_REQUEST) && $_REQUEST['change'] != "")
2172 {
2173 showheader(_("My CAcert.org Account!"));
2174 foreach($_REQUEST as $id => $val)
2175 {
2176 if(substr($id,0,14)=="check_comment_")
2177 {
2178 $cid = intval(substr($id,14));
2179 $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid])));
2180 mysql_query("update `orgdomaincerts` set `description`='$comment' where `id`='$cid'");
2181 }
2182 }
2183 echo(_("Certificate settings have been changed.")."<br/>\n");
2184 showfooter();
2185 exit;
2186 }
2187
2188 if($oldid == 22 && array_key_exists('filter',$_REQUEST) && $_REQUEST['filter']!= "")
2189 {
2190 $id=22;
2191 $_SESSION['_config']['dorgfilterid']=$_REQUEST['dorgfilterid'];
2192 $_SESSION['_config']['dsorting']=$_REQUEST['dsorting'];
2193 $_SESSION['_config']['dstatus']=$_REQUEST['dstatus'];
2194 }
2195
2196 if($oldid == 22 && array_key_exists('reset',$_REQUEST) && $_REQUEST['reset']!= "")
2197 {
2198 $id=22;
2199 $_SESSION['_config']['dorgfilterid']=0;
2200 $_SESSION['_config']['dsorting']=0;
2201 $_SESSION['_config']['dstatus']=0;
2202 }
2203
2204
2205 if(($id == 24 || $oldid == 24 || $id == 25 || $oldid == 25 || $id == 26 || $oldid == 26 ||
2206 $id == 27 || $oldid == 27 || $id == 28 || $oldid == 28 || $id == 29 || $oldid == 29 ||
2207 $id == 30 || $oldid == 30 || $id == 31 || $oldid == 31) &&
2208 $_SESSION['profile']['orgadmin'] != 1)
2209 {
2210 showheader(_("My CAcert.org Account!"));
2211 echo _("You don't have access to this area.");
2212 showfooter();
2213 exit;
2214 }
2215
2216 if($oldid == 24 && $process != "")
2217 {
2218 $id = intval($oldid);
2219 $_SESSION['_config']['O'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['O'])));
2220 $_SESSION['_config']['contact'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['contact'])));
2221 $_SESSION['_config']['L'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['L'])));
2222 $_SESSION['_config']['ST'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['ST'])));
2223 $_SESSION['_config']['C'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['C'])));
2224 $_SESSION['_config']['comments'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['comments'])));
2225
2226 if($_SESSION['_config']['O'] == "" || $_SESSION['_config']['contact'] == "")
2227 {
2228 $_SESSION['_config']['errmsg'] = _("Organisation Name and Contact Email are required fields.");
2229 } else {
2230 mysql_query("insert into `orginfo` set `O`='".$_SESSION['_config']['O']."',
2231 `contact`='".$_SESSION['_config']['contact']."',
2232 `L`='".$_SESSION['_config']['L']."',
2233 `ST`='".$_SESSION['_config']['ST']."',
2234 `C`='".$_SESSION['_config']['C']."',
2235 `comments`='".$_SESSION['_config']['comments']."'");
2236 showheader(_("My CAcert.org Account!"));
2237 printf(_("'%s' has just been successfully added as an organisation to the database."), sanitizeHTML($_SESSION['_config']['O']));
2238 showfooter();
2239 exit;
2240 }
2241 }
2242
2243 if($oldid == 27 && $process != "")
2244 {
2245 csrf_check('orgdetchange');
2246 $id = intval($oldid);
2247 $_SESSION['_config']['O'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['O'])));
2248 $_SESSION['_config']['contact'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['contact'])));
2249 $_SESSION['_config']['L'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['L'])));
2250 $_SESSION['_config']['ST'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['ST'])));
2251 $_SESSION['_config']['C'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['C'])));
2252 $_SESSION['_config']['comments'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['comments'])));
2253
2254 if($_SESSION['_config']['O'] == "" || $_SESSION['_config']['contact'] == "")
2255 {
2256 $_SESSION['_config']['errmsg'] = _("Organisation Name and Contact Email are required fields.");
2257 } else {
2258 mysql_query("update `orginfo` set `O`='".$_SESSION['_config']['O']."',
2259 `contact`='".$_SESSION['_config']['contact']."',
2260 `L`='".$_SESSION['_config']['L']."',
2261 `ST`='".$_SESSION['_config']['ST']."',
2262 `C`='".$_SESSION['_config']['C']."',
2263 `comments`='".$_SESSION['_config']['comments']."'
2264 where `id`='".intval($_SESSION['_config']['orgid'])."'");
2265 showheader(_("My CAcert.org Account!"));
2266 printf(_("'%s' has just been successfully updated in the database."), sanitizeHTML($_SESSION['_config']['O']));
2267 showfooter();
2268 exit;
2269 }
2270 }
2271
2272 if($oldid == 28 && $process != "" && array_key_exists("domainname",$_REQUEST))
2273 {
2274 $domain = $_SESSION['_config']['domain'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['domainname'])));
2275 $res1 = mysql_query("select * from `orgdomains` where `domain`='$domain'");
2276 if(mysql_num_rows($res1) > 0)
2277 {
2278 $_SESSION['_config']['errmsg'] = sprintf(_("The domain '%s' is already in a different account and is listed as valid. Can't continue."), sanitizeHTML($domain));
2279 $id = $oldid;
2280 $oldid=0;
2281 }
2282 }
2283
2284 if($oldid == 28 && $_SESSION['_config']['orgid'] <= 0)
2285 {
2286 $oldid=0;
2287 $id = 25;
2288 }
2289
2290 if($oldid == 28 && $process != "" && array_key_exists("orgid",$_SESSION["_config"]))
2291 {
2292 mysql_query("insert into `orgdomains` set `orgid`='".intval($_SESSION['_config']['orgid'])."', `domain`='$domain'");
2293 showheader(_("My CAcert.org Account!"));
2294 printf(_("'%s' has just been successfully added to the database."), sanitizeHTML($domain));
2295 echo "<br><br><a href='account.php?id=26&orgid=".intval($_SESSION['_config']['orgid'])."'>"._("Click here")."</a> "._("to continue.");
2296 showfooter();
2297 exit;
2298 }
2299
2300 if($oldid == 29 && $process != "")
2301 {
2302 $domain = mysql_real_escape_string(stripslashes(trim($_REQUEST['domainname'])));
2303
2304 $res1 = mysql_query("select * from `orgdomains` where `domain` like '$domain' and `id`!='".intval($domid)."'");
2305 $res2 = mysql_query("select * from `domains` where `domain` like '$domain' and `deleted`=0");
2306 if(mysql_num_rows($res1) > 0 || mysql_num_rows($res2) > 0)
2307 {
2308 $_SESSION['_config']['errmsg'] = sprintf(_("The domain '%s' is already in a different account and is listed as valid. Can't continue."), sanitizeHTML($domain));
2309 $id = $oldid;
2310 $oldid=0;
2311 }
2312 }
2313
2314 if(($oldid == 29 || $oldid == 30) && $process != "") // _("Cancel") is handled in front of account.php
2315 {
2316 $query = "select `orgdomaincerts`.`id` as `id` from `orgdomlink`, `orgdomaincerts`, `orgdomains` where
2317 `orgdomlink`.`orgdomid`=`orgdomains`.`id` and
2318 `orgdomaincerts`.`id`=`orgdomlink`.`orgcertid` and
2319 `orgdomains`.`id`='".intval($domid)."'";
2320 $res = mysql_query($query);
2321 while($row = mysql_fetch_assoc($res))
2322 mysql_query("update `orgdomaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='".$row['id']."'");
2323
2324 $query = "select `orgemailcerts`.`id` as `id` from `orgemailcerts`, `orgemaillink`, `orgdomains` where
2325 `orgemaillink`.`domid`=`orgdomains`.`id` and
2326 `orgemailcerts`.`id`=`orgemaillink`.`emailcertsid` and
2327 `orgdomains`.`id`='".intval($domid)."'";
2328 $res = mysql_query($query);
2329 while($row = mysql_fetch_assoc($res))
2330 mysql_query("update `orgemailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='".intval($row['id'])."'");
2331 }
2332
2333 if($oldid == 29 && $process != "")
2334 {
2335 $row = mysql_fetch_assoc(mysql_query("select * from `orgdomains` where `id`='".intval($domid)."'"));
2336 mysql_query("update `orgdomains` set `domain`='$domain' where `id`='".intval($domid)."'");
2337 showheader(_("My CAcert.org Account!"));
2338 printf(_("'%s' has just been successfully updated in the database."), sanitizeHTML($domain));
2339 echo "<br><br><a href='account.php?id=26&orgid=".intval($orgid)."'>"._("Click here")."</a> "._("to continue.");
2340 showfooter();
2341 exit;
2342 }
2343
2344 if($oldid == 30 && $process != "")
2345 {
2346 $row = mysql_fetch_assoc(mysql_query("select * from `orgdomains` where `id`='".intval($domid)."'"));
2347 $domain = $row['domain'];
2348 mysql_query("delete from `orgdomains` where `id`='".intval($domid)."'");
2349 showheader(_("My CAcert.org Account!"));
2350 printf(_("'%s' has just been successfully deleted from the database."), sanitizeHTML($domain));
2351 echo "<br><br><a href='account.php?id=26&orgid=".intval($orgid)."'>"._("Click here")."</a> "._("to continue.");
2352 showfooter();
2353 exit;
2354 }
2355
2356 if($oldid == 30)
2357 {
2358 $id = 26;
2359 $orgid = 0;
2360 }
2361
2362 if($oldid == 31 && $process != "")
2363 {
2364 $query = "select * from `orgdomains` where `orgid`='".intval($_SESSION['_config']['orgid'])."'";
2365 $dres = mysql_query($query);
2366 while($drow = mysql_fetch_assoc($dres))
2367 {
2368 $query = "select `orgdomaincerts`.`id` as `id` from `orgdomlink`, `orgdomaincerts`, `orgdomains` where
2369 `orgdomlink`.`orgdomid`=`orgdomains`.`id` and
2370 `orgdomaincerts`.`id`=`orgdomlink`.`orgcertid` and
2371 `orgdomains`.`id`='".intval($drow['id'])."'";
2372 $res = mysql_query($query);
2373 while($row = mysql_fetch_assoc($res))
2374 {
2375 mysql_query("update `orgdomaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='".intval($row['id'])."'");
2376 mysql_query("delete from `orgdomaincerts` where `orgid`='".intval($row['id'])."'");
2377 mysql_query("delete from `orgdomlink` where `domid`='".intval($row['id'])."'");
2378 }
2379
2380 $query = "select `orgemailcerts`.`id` as `id` from `orgemailcerts`, `orgemaillink`, `orgdomains` where
2381 `orgemaillink`.`domid`=`orgdomains`.`id` and
2382 `orgemailcerts`.`id`=`orgemaillink`.`emailcertsid` and
2383 `orgdomains`.`id`='".intval($drow['id'])."'";
2384 $res = mysql_query($query);
2385 while($row = mysql_fetch_assoc($res))
2386 {
2387 mysql_query("update `orgemailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='".intval($row['id'])."'");
2388 mysql_query("delete from `orgemailcerts` where `id`='".intval($row['id'])."'");
2389 mysql_query("delete from `orgemaillink` where `domid`='".intval($row['id'])."'");
2390 }
2391 }
2392 mysql_query("delete from `org` where `orgid`='".intval($_SESSION['_config']['orgid'])."'");
2393 mysql_query("delete from `orgdomains` where `orgid`='".intval($_SESSION['_config']['orgid'])."'");
2394 mysql_query("delete from `orginfo` where `id`='".intval($_SESSION['_config']['orgid'])."'");
2395 }
2396
2397 if($oldid == 31)
2398 {
2399 $id = 25;
2400 $orgid = 0;
2401 }
2402
2403 if($id == 32 || $oldid == 32 || $id == 33 || $oldid == 33 || $id == 34 || $oldid == 34)
2404 {
2405 $query = "select * from `org` where `memid`='".intval($_SESSION['profile']['id'])."' and `masteracc`='1'";
2406 $_macc = mysql_num_rows(mysql_query($query));
2407 if($_SESSION['profile']['orgadmin'] != 1 && $_macc <= 0)
2408 {
2409 showheader(_("My CAcert.org Account!"));
2410 echo _("You don't have access to this area.");
2411 showfooter();
2412 exit;
2413 }
2414 }
2415
2416 if($id == 35 || $oldid == 35)
2417 {
2418 $query = "select 1 from `org` where `memid`='".intval($_SESSION['profile']['id'])."'";
2419 $is_orguser = mysql_num_rows(mysql_query($query));
2420 if($_SESSION['profile']['orgadmin'] != 1 && $is_orguser <= 0)
2421 {
2422 showheader(_("My CAcert.org Account!"));
2423 echo _("You don't have access to this area.");
2424 showfooter();
2425 exit;
2426 }
2427 }
2428
2429 if($id == 33 && $_SESSION['profile']['orgadmin'] != 1)
2430 {
2431 $orgid = intval($_SESSION['_config']['orgid']);
2432 $query = "select * from `org` where `orgid`='$orgid' and `memid`='".intval($_SESSION['profile']['id'])."' and `masteracc`='1'";
2433 $res = mysql_query($query);
2434 if(mysql_num_rows($res) <= 0)
2435 {
2436 $id = 35;
2437 }
2438 }
2439
2440 if($oldid == 33 && $process != "")
2441 {
2442 csrf_check('orgadmadd');
2443 if($_SESSION['profile']['orgadmin'] == 1)
2444 $masteracc = $_SESSION['_config'][masteracc] = intval($_REQUEST['masteracc']);
2445 else
2446 $masteracc = $_SESSION['_config'][masteracc] = 0;
2447 $_REQUEST['email'] = $_SESSION['_config']['email'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['email'])));
2448 $OU = $_SESSION['_config']['OU'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['OU'])));
2449 $comments = $_SESSION['_config']['comments'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['comments'])));
2450 $res = mysql_query("select * from `users` where `email`='".$_REQUEST['email']."' and `deleted`=0");
2451 if(mysql_num_rows($res) <= 0)
2452 {
2453 $id = $oldid;
2454 $oldid=0;
2455 $_SESSION['_config']['errmsg'] = sprintf(_("Wasn't able to match '%s' against any user in the system"), sanitizeHTML($_REQUEST['email']));
2456 } else {
2457 $row = mysql_fetch_assoc($res);
2458 if ( !is_assurer(intval($row['id'])) )
2459 {
2460 $id = $oldid;
2461 $oldid=0;
2462 $_SESSION['_config']['errmsg'] =
2463 _("The user is not an Assurer yet");
2464 } else {
2465 mysql_query(
2466 "insert into `org`
2467 set `memid`='".intval($row['id'])."',
2468 `orgid`='".intval($_SESSION['_config']['orgid'])."',
2469 `masteracc`='$masteracc',
2470 `OU`='$OU',
2471 `comments`='$comments'");
2472 }
2473 }
2474 }
2475
2476 if(($oldid == 34 || $id == 34) && $_SESSION['profile']['orgadmin'] != 1)
2477 {
2478 $orgid = intval($_SESSION['_config']['orgid']);
2479 $res = mysql_query("select * from `org` where `orgid`='$orgid' and `memid`='".intval($_SESSION['profile']['id'])."' and `masteracc`='1'");
2480 if(mysql_num_rows($res) <= 0)
2481 $id = 32;
2482 }
2483
2484 if($oldid == 34 && $process != "")
2485 {
2486 $orgid = intval($_SESSION['_config']['orgid']);
2487 $memid = intval($_REQUEST['memid']);
2488 $query = "delete from `org` where `orgid`='$orgid' and `memid`='$memid'";
2489 mysql_query($query);
2490 }
2491
2492 if($oldid == 34 || $oldid == 33)
2493 {
2494 $oldid=0;
2495 $id = 32;
2496 $orgid = 0;
2497 }
2498
2499 if($id == 36)
2500 {
2501 $row = mysql_fetch_assoc(mysql_query("select * from `alerts` where `memid`='".intval($_SESSION['profile']['id'])."'"));
2502 $_REQUEST['general'] = $row['general'];
2503 $_REQUEST['country'] = $row['country'];
2504 $_REQUEST['regional'] = $row['regional'];
2505 $_REQUEST['radius'] = $row['radius'];
2506 }
2507
2508 if($oldid == 36)
2509 {
2510 $rc = mysql_num_rows(mysql_query("select * from `alerts` where `memid`='".intval($_SESSION['profile']['id'])."'"));
2511 if($rc > 0)
2512 {
2513 $query = "update `alerts` set `general`='".intval(array_key_exists('general',$_REQUEST)?$_REQUEST['general']:0)."',
2514 `country`='".intval(array_key_exists('country',$_REQUEST)?$_REQUEST['country']:0)."',
2515 `regional`='".intval(array_key_exists('regional',$_REQUEST)?$_REQUEST['regional']:0)."',
2516 `radius`='".intval(array_key_exists('radius',$_REQUEST)?$_REQUEST['radius']:0)."'
2517 where `memid`='".intval($_SESSION['profile']['id'])."'";
2518 } else {
2519 $query = "insert into `alerts` set `general`='".intval(array_key_exists('general',$_REQUEST)?$_REQUEST['general']:0)."',
2520 `country`='".intval(array_key_exists('country',$_REQUEST)?$_REQUEST['country']:0)."',
2521 `regional`='".intval(array_key_exists('regional',$_REQUEST)?$_REQUEST['regional']:0)."',
2522 `radius`='".intval(array_key_exists('radius',$_REQUEST)?$_REQUEST['radius']:0)."',
2523 `memid`='".intval($_SESSION['profile']['id'])."'";
2524 }
2525 mysql_query($query);
2526 $id = $oldid;
2527 $oldid=0;
2528 }
2529
2530 if($oldid == 41 && $_REQUEST['action'] == 'default')
2531 {
2532 csrf_check("mainlang");
2533 $lang = mysql_real_escape_string($_REQUEST['lang']);
2534 foreach(L10n::$translations as $key => $val)
2535 {
2536 if($key == $lang)
2537 {
2538 mysql_query("update `users` set `language`='$lang' where `id`='".intval($_SESSION['profile']['id'])."'");
2539 $_SESSION['profile']['language'] = $lang;
2540 showheader(_("My CAcert.org Account!"));
2541 echo _("Your language setting has been updated.");
2542 showfooter();
2543 exit;
2544 }
2545 }
2546
2547 showheader(_("My CAcert.org Account!"));
2548 echo _("You tried to use an invalid language.");
2549 showfooter();
2550 exit;
2551 }
2552
2553 if($oldid == 41 && $_REQUEST['action'] == 'addsec')
2554 {
2555 csrf_check("seclang");
2556 $addlang = mysql_real_escape_string($_REQUEST['addlang']);
2557 // Does the language exist?
2558 mysql_query("insert into `addlang` set `userid`='".intval($_SESSION['profile']['id'])."', `lang`='$addlang'");
2559 showheader(_("My CAcert.org Account!"));
2560 echo _("Your language setting has been updated.");
2561 showfooter();
2562 exit;
2563 }
2564
2565 if($oldid == 41 && $_REQUEST['action'] == 'dellang')
2566 {
2567 csrf_check("seclang");
2568 $remove = mysql_real_escape_string($_REQUEST['remove']);
2569 mysql_query("delete from `addlang` where `userid`='".intval($_SESSION['profile']['id'])."' and `lang`='$remove'");
2570 showheader(_("My CAcert.org Account!"));
2571 echo _("Your language setting has been updated.");