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