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