Merge branch 'release' into bug-1131 bug-1131
authorBenny Baumann <BenBE@geshi.org>
Tue, 16 Dec 2014 20:03:54 +0000 (21:03 +0100)
committerBenny Baumann <BenBE@geshi.org>
Tue, 16 Dec 2014 20:08:25 +0000 (21:08 +0100)
Conflicts:
pages/wot/6.php
www/policy/CAcertCommunityAgreement.php

The conflict in the CCA document page was introduced due to the rename of the file.
This instance can be safely ignored, as bug 1131 introduces a new version
superseeding the old document.

The instance in pages/wot/6.php is a bit more complicated, but basically
results from a change of bug 1137 and the modified paths to the policy documents.

232 files changed:
CommModule/client.pl
CommModule/usbclient.pl
includes/account.php
includes/account_stuff.php
includes/general.php
includes/keygen.php
includes/lib/account.php
includes/lib/check_weak_key.php
includes/lib/general.php
includes/lib/l10n.php
includes/loggedin.php
includes/notary.inc.php
includes/wot.inc.php [deleted file]
locale/Makefile
pages/account/10.php
pages/account/11.php
pages/account/12.php
pages/account/13.php
pages/account/15.php
pages/account/16.php
pages/account/17.php
pages/account/18.php
pages/account/19.php
pages/account/20.php
pages/account/21.php
pages/account/22.php
pages/account/23.php
pages/account/3.php
pages/account/43.php
pages/account/44.php
pages/account/5.php
pages/account/50.php
pages/account/52.php
pages/account/55.php
pages/account/56.php
pages/account/57.php
pages/account/58.php
pages/account/59.php [new file with mode: 0644]
pages/account/6.php
pages/account/8.php
pages/gpg/0.php
pages/gpg/2.php
pages/index/0.php
pages/index/1.php
pages/index/21.php
pages/index/52.php [new file with mode: 0644]
pages/wot/1.php
pages/wot/10.php
pages/wot/15.php
pages/wot/4.php
pages/wot/5.php
pages/wot/6.php
pages/wot/9.php
scripts/21de-ate-essen-email.txt [deleted file]
scripts/21de-ate-essen-mail.php.txt [deleted file]
scripts/22de-ate-aachen-email.txt [deleted file]
scripts/22de-ate-aachen-mail.php.txt [deleted file]
scripts/23au-ate-canberra-email.txt [deleted file]
scripts/23au-ate-canberra-mail.php.txt [deleted file]
scripts/24de-blit2010-email.txt [deleted file]
scripts/24de-blit2010-mail.php.txt [deleted file]
scripts/25de-ate-hamburg-mail.php.txt [deleted file]
scripts/25de-ate-hamburg-mail.txt [deleted file]
scripts/26us-lisa2010-email.txt [deleted file]
scripts/26us-lisa2010-mail.php.txt [deleted file]
scripts/27au-ate-melbourne-email.txt [deleted file]
scripts/27au-ate-melbourne-mail.php.txt [deleted file]
scripts/28au-ate-melbourne-email.txt [deleted file]
scripts/28au-ate-melbourne-mail.php.txt [deleted file]
scripts/29au-ate-brisbane-email.txt [deleted file]
scripts/29au-ate-brisbane-mail.php.txt [deleted file]
scripts/30de-ate-muenchen-email.txt [deleted file]
scripts/30de-ate-muenchen-mail.php.txt [deleted file]
scripts/31de-lt2011-berlin-email.txt [deleted file]
scripts/31de-lt2011-berlin-mail.php.txt [deleted file]
scripts/32de-ate-bonn-email.txt [deleted file]
scripts/32de-ate-bonn-mail.php.txt [deleted file]
scripts/33us-ate-wdc-email.txt [deleted file]
scripts/33us-ate-wdc-mail.php.txt [deleted file]
scripts/34us-ate-wdc-email.txt [deleted file]
scripts/34us-ate-wdc-mail.php.txt [deleted file]
scripts/35us-ate-ny-email.txt [deleted file]
scripts/35us-ate-ny-mail.php.txt [deleted file]
scripts/36us-ate-ny-email.txt [deleted file]
scripts/36us-ate-ny-mail.php.txt [deleted file]
scripts/37de-blit2011-email.txt [deleted file]
scripts/37de-blit2011-mail.php.txt [deleted file]
scripts/38us-fudcon2012-email.txt [deleted file]
scripts/38us-fudcon2012-mail.php.txt [deleted file]
scripts/39uk-ate-manchester-email.txt [deleted file]
scripts/39uk-ate-manchester-mail.php.txt [deleted file]
scripts/40de-ate-hamburg-email.txt [deleted file]
scripts/40de-ate-hamburg-mail.php.txt [deleted file]
scripts/41de-ate-jena-email.txt [deleted file]
scripts/41de-ate-jena-mail.php.txt [deleted file]
scripts/42de-ate-leipzig-email.txt [deleted file]
scripts/42de-ate-leipzig-mail.php.txt [deleted file]
scripts/43de-ate-karlsruhe-email.txt [deleted file]
scripts/43de-ate-karlsruhe-mail.php.txt [deleted file]
scripts/44de-ate-duesseldorf-email.txt [deleted file]
scripts/44de-ate-duesseldorf-mail.php.txt [deleted file]
scripts/45au-ate-melbourne-email.txt [deleted file]
scripts/45au-ate-melbourne-mail.php.txt [deleted file]
scripts/46us-ate-raleigh-email.txt [deleted file]
scripts/46us-ate-raleigh-mail.php.txt [deleted file]
scripts/47us-fudcon-lawrence-email.txt [deleted file]
scripts/47us-fudcon-lawrence-mail.php.txt [deleted file]
scripts/48de-ate-kiel-email.txt [deleted file]
scripts/48de-ate-kiel-mail.php.txt [deleted file]
scripts/49de-lt2013-berlin-email.txt [new file with mode: 0644]
scripts/49de-lt2013-berlin-mail.php.txt [new file with mode: 0644]
scripts/50de-ate-luebeck-email.txt [new file with mode: 0644]
scripts/50de-ate-luebeck-mail.php.txt [new file with mode: 0644]
scripts/51at-ate-graz-email.txt [new file with mode: 0644]
scripts/51at-ate-graz-mail.php.txt [new file with mode: 0644]
scripts/52at-ate-wien-email.txt [new file with mode: 0644]
scripts/52at-ate-wien-mail.php.txt [new file with mode: 0644]
scripts/53de-ate-amberg-email.txt [new file with mode: 0644]
scripts/53de-ate-amberg-mail.php.txt [new file with mode: 0644]
scripts/54at-ate-linz-email.txt [new file with mode: 0644]
scripts/54at-ate-linz-mail.php.txt [new file with mode: 0644]
scripts/55de-ate-wiesbaden-email.txt [new file with mode: 0644]
scripts/55de-ate-wiesbaden-mail.php.txt [new file with mode: 0644]
scripts/56at-ate-oberwart-email.txt [new file with mode: 0644]
scripts/56at-ate-oberwart-mail.php.txt [new file with mode: 0644]
scripts/57at-ate-graz-email.txt [new file with mode: 0644]
scripts/57at-ate-graz-mail.php.txt [new file with mode: 0644]
scripts/58at-ate-wien-email.txt [new file with mode: 0644]
scripts/58at-ate-wien-mail.php.txt [new file with mode: 0644]
scripts/areacheck.php [deleted file]
scripts/ate-bi-email.txt [deleted file]
scripts/ate-bi-mail.php [deleted file]
scripts/ate-d-email.txt [deleted file]
scripts/ate-d-mail.php.txt [deleted file]
scripts/ate-de09-email.txt [deleted file]
scripts/ate-de09-mail.php.txt [deleted file]
scripts/ate-de11-email.txt [deleted file]
scripts/ate-de11-mail.php.txt [deleted file]
scripts/ate-f-email.txt [deleted file]
scripts/ate-f-mail.php.txt [deleted file]
scripts/ate-goteborg-s16-email.txt [deleted file]
scripts/ate-goteborg-s16-mail.php.txt [deleted file]
scripts/ate-hh-email.txt [deleted file]
scripts/ate-hh-mail.php.txt [deleted file]
scripts/ate-l-email.txt [deleted file]
scripts/ate-l-mail.php.txt [deleted file]
scripts/ate-m-email.txt [deleted file]
scripts/ate-m-mail.php.txt [deleted file]
scripts/ate-nl01-email.txt [deleted file]
scripts/ate-nl01-mail.php.txt [deleted file]
scripts/ate-s-email.txt [deleted file]
scripts/ate-s-mail.php.txt [deleted file]
scripts/ate-sydney-au20-email.txt [deleted file]
scripts/ate-sydney-au20-mail.php.txt [deleted file]
scripts/ate-us02-email.txt [deleted file]
scripts/ate-us02-mail.php.txt [deleted file]
scripts/blit-de15-email.txt [deleted file]
scripts/blit-de15-mail.php.txt [deleted file]
scripts/cebitemail.txt [deleted file]
scripts/cron/permissionreview.php
scripts/cron/refresh_stats.php [new file with mode: 0755]
scripts/cron/removedead.php
scripts/cron/warning.php
scripts/db_migrations/version3.sh [new file with mode: 0755]
scripts/db_migrations/version4.sh [new file with mode: 0755]
scripts/db_migrations/version5.sh [new file with mode: 0755]
scripts/gpgfillmissingemail.php
scripts/koelnemail.txt [deleted file]
scripts/lisa-us13-email.txt [deleted file]
scripts/lisa-us13-mail.php.txt [deleted file]
scripts/mail-weak-keys.php
scripts/mailing archive/45au-ate-melbourne-email.txt [new file with mode: 0644]
scripts/mailing archive/45au-ate-melbourne-mail.php.txt [new file with mode: 0644]
scripts/mailing archive/46us-ate-raleigh-email.txt [new file with mode: 0644]
scripts/mailing archive/46us-ate-raleigh-mail.php.txt [new file with mode: 0644]
scripts/mailing archive/47us-fudcon-lawrence-email.txt [new file with mode: 0644]
scripts/mailing archive/47us-fudcon-lawrence-mail.php.txt [new file with mode: 0644]
scripts/mailing archive/48de-ate-kiel-email.txt [new file with mode: 0644]
scripts/mailing archive/48de-ate-kiel-mail.php.txt [new file with mode: 0644]
scripts/mailing archive/oa01-allowance.php.txt [new file with mode: 0644]
scripts/mailing archive/oa01-allowance.txt [new file with mode: 0644]
scripts/mailing archive/oa02-mailingtextCats.txt [new file with mode: 0644]
scripts/mailing archive/oa02-mailingtextPoints.txt [new file with mode: 0644]
scripts/mailing archive/oa02-mailingtextPointsCats.txt [new file with mode: 0644]
scripts/mailing archive/oa02-orgainformation.php.txt [new file with mode: 0644]
scripts/mailing archive/thawte_DE.txt [new file with mode: 0644]
scripts/mailing archive/thawte_EN.txt [new file with mode: 0644]
scripts/mailing archive/thawte_ES.txt [new file with mode: 0644]
scripts/mailing archive/thawte_FR.txt [new file with mode: 0644]
scripts/mailing archive/thawte_NL.txt [new file with mode: 0644]
scripts/mailing archive/thawte_RU.txt [new file with mode: 0644]
scripts/mission-hills-ca-us17-email.txt [deleted file]
scripts/mission-hills-ca-us17-mail.php.txt [deleted file]
scripts/nearest.php [deleted file]
scripts/oa01-allowance.php.txt [deleted file]
scripts/oa01-allowance.txt [deleted file]
scripts/oa02-mailingtextCats.txt [deleted file]
scripts/oa02-mailingtextPoints.txt [deleted file]
scripts/oa02-mailingtextPointsCats.txt [deleted file]
scripts/oa02-orgainformation.php.txt [deleted file]
scripts/osd-copenhagen-dk18-email.txt [deleted file]
scripts/osd-copenhagen-dk18-mail.php.txt [deleted file]
scripts/ost-de14-email.txt [deleted file]
scripts/ost-de14-mail.php.txt [deleted file]
scripts/scale8x-los-angeles-ca-us19-email.txt [deleted file]
scripts/scale8x-los-angeles-ca-us19-mail.php.txt [deleted file]
scripts/scanforexponents.php
scripts/send_heartbleed.php [new file with mode: 0644]
scripts/send_policy_cca_20140916.php [new file with mode: 0644]
scripts/sfd-de12-email.txt [deleted file]
scripts/sfd-de12-mail.php.txt [deleted file]
scripts/thawte_DE.txt [deleted file]
scripts/thawte_EN.txt [deleted file]
scripts/thawte_ES.txt [deleted file]
scripts/thawte_FR.txt [deleted file]
scripts/thawte_NL.txt [deleted file]
scripts/thawte_RU.txt [deleted file]
stamp/common.php
stamp/style.css
www/api/ccsr.php
www/api/cemails.php
www/disputes.php
www/gpg.php
www/images/btn_paynowCC_LG.gif
www/images/btn_subscribeCC_LG.gif [new file with mode: 0644]
www/index.php
www/keygenIE.js
www/policy/CAcertCommunityAgreement.php
www/sqldump.php
www/stats.php
www/styles/default.css
www/wot.php

index bf92b27..25e6a73 100755 (executable)
@@ -31,7 +31,7 @@ use DBI;
 use Locale::gettext;
 use IO::Socket;
 use MIME::Base64;
-use Digest::SHA1 qw(sha1_hex);
+use Digest::SHA qw(sha1_hex);
 
 #Protocol version:
 my $ver=1;
@@ -441,7 +441,7 @@ sub calculateDays($)
 {
   if($_[0])
   {
-    my @sum = $dbh->selectrow_array("select sum(`points`) as `total` from `notary` where `to`='".$_[0]."' group by `to`");
+    my @sum = $dbh->selectrow_array("select sum(`points`) as `total` from `notary` where `to`='".$_[0]."' and `deleted`=0 group by `to`");
     SysLog("Summe: $sum[0]\n") if($debug);
 
     return ($sum[0]>=50)?730:180;
@@ -834,8 +834,15 @@ sub HandleCerts($$)
 
       my $days=$org?($server?(365*2):365):calculateDays($row{"memid"});
 
+      my $md_id = 0;
+      $md_id = 1 if( $row{'md'} eq "md5");
+      $md_id = 2 if( $row{'md'} eq "sha1");
+      $md_id = 3 if( $row{'md'} eq "rmd160");
+      $md_id = 8 if( $row{'md'} eq "sha256");
+      $md_id = 9 if( $row{'md'} eq "sha384");
+      $md_id =10 if( $row{'md'} eq "sha512");
 
-      $crt=Request($ver,1,1,$row{'rootcert'}-1,$profile,$row{'md'}eq"sha1"?2:0,$days,$row{'keytype'}eq"NS"?1:0,$content,$SAN,$subject);
+      $crt=Request($ver,1,1,$row{'rootcert'}-1,$profile,$md_id,$days,$row{'keytype'}eq"NS"?1:0,$content,$SAN,$subject);
       if(length($crt))
       {
         if($crt=~m/^-----BEGIN CERTIFICATE-----/)
index 3cbe2c3..6cbc111 100755 (executable)
@@ -425,7 +425,7 @@ sub calculateDays($)
 {
   if($_[0])
   {
-    my @sum = $dbh->selectrow_array("select sum(`points`) as `total` from `notary` where `to`='".$_[0]."' group by `to`");
+    my @sum = $dbh->selectrow_array("select sum(`points`) as `total` from `notary` where `to`='".$_[0]."' and `deleted`=0 group by `to`");
     SysLog("Summe: $sum[0]\n") if($debug);
 
     return ($sum[0]>=50)?730:180;
index 4aed5ed..6dacf2d 100644 (file)
 */
        require_once("../includes/loggedin.php");
        require_once("../includes/lib/l10n.php");
-       require_once('lib/check_weak_key.php');
+       require_once("../includes/lib/check_weak_key.php");
+       require_once("../includes/notary.inc.php");
 
        loadem("account");
 
-       $id = 0; if(array_key_exists("id",$_REQUEST)) $id=intval($_REQUEST['id']);
-       $oldid = 0; if(array_key_exists("oldid",$_REQUEST)) $oldid=intval($_REQUEST['oldid']);
-       $process = ""; if(array_key_exists("process",$_REQUEST)) $process=$_REQUEST['process'];
+/**
+ * Build a subject string as needed by the signer
+ *
+ * @param array(string) $domains
+ *     First domain is used as CN and repeated in subjectAltName. Duplicates
+ *     should already been removed
+ *
+ * @param bool $include_xmpp_addr
+ *     [default: true] Whether to include the XmppAddr in the subjectAltName.
+ *     This is needed if the Jabber server is jabber.example.com but a Jabber ID
+ *     on that server would be alice@example.com
+ *
+ * @return string
+ */
+function buildSubject(array $domains, $include_xmpp_addr = true) {
+       $subject = "/CN=${domains[0]}";
+
+       foreach ($domains as $domain) {
+               $subject .= "/subjectAltName=DNS:$domain";
+
+               if ($include_xmpp_addr) {
+                       $subject .= "/subjectAltName=otherName:1.3.6.1.5.5.7.8.5;UTF8:$domain";
+               }
+       }
+
+       return $subject;
+}
+
+/**
+ * Builds the subject string from the session variables
+ * $_SESSION['_config']['rows'] and $_SESSION['_config']['altrows']
+ *
+ * @return string
+ */
+function buildSubjectFromSession() {
+       $domains = array();
+
+       if (is_array($_SESSION['_config']['rows'])) {
+               $domains = array_merge($domains, $_SESSION['_config']['rows']);
+       }
+
+       if (is_array($_SESSION['_config']['altrows']))
+               foreach ($_SESSION['_config']['altrows'] as $row) {
+                       if (substr($row, 0, 4) === "DNS:") {
+                               $domains[] = substr($row, 4);
+                       }
+               }
+
+       return buildSubject(array_unique($domains));
+}
+
+       $id = array_key_exists("id",$_REQUEST) ? intval($_REQUEST['id']) : 0;
+       $oldid = array_key_exists("oldid",$_REQUEST) ? intval($_REQUEST['oldid']) : 0;
+       $process = array_key_exists("process",$_REQUEST) ? $_REQUEST['process'] : "";
+//     $showdetalis refers to Secret Question and Answers from account/13.php
+       $showdetails = array_key_exists("showdetails",$_REQUEST) ? intval($_REQUEST['showdetails']) : 0;
+
+       $cert = array_key_exists('cert',$_REQUEST) ? intval($_REQUEST['cert']) : 0;
+       $orgid = array_key_exists('orgid',$_REQUEST) ? intval($_REQUEST['orgid']) : 0;
+       $memid = array_key_exists('memid',$_REQUEST) ? intval($_REQUEST['memid']) : 0;
+       $domid = array_key_exists('domid',$_REQUEST) ? intval($_REQUEST['domid']) : 0;
 
-       $cert=0; if(array_key_exists('cert',$_REQUEST)) $cert=intval($_REQUEST['cert']);
-       $orgid=0; if(array_key_exists('orgid',$_REQUEST)) $orgid=intval($_REQUEST['orgid']);
-       $memid=0; if(array_key_exists('memid',$_REQUEST)) $memid=intval($_REQUEST['memid']);
-       $domid=0; if(array_key_exists('domid',$_REQUEST)) $domid=intval($_REQUEST['domid']);
+       $actionrequest = array_key_exists('action',$_REQUEST) ? $_REQUEST['action'] : "";
+
+       $ticketno = array_key_exists('ticketno',$_REQUEST) ? $_REQUEST['ticketno'] : "";
+       $ticketvalidation = FALSE;
 
 
        if(!$_SESSION['mconn'])
                }
                $oldid=0;
                $_REQUEST['email'] = trim(mysql_real_escape_string(stripslashes($_REQUEST['newemail'])));
-               $query = "select * from `email` where `email`='".$_REQUEST['email']."' and `deleted`=0";
-               $res = mysql_query($query);
-               if(mysql_num_rows($res) > 0)
+               if(check_email_exists($_REQUEST['email'])==true)
                {
                        showheader(_("My CAcert.org Account!"));
                        printf(_("The email address '%s' is already in a different account. Can't continue."), sanitizeHTML($_REQUEST['email']));
                        exit;
                }
                $hash = make_hash();
-               $query = "insert into `email` set `email`='".$_REQUEST['email']."',`memid`='".$_SESSION['profile']['id']."',`created`=NOW(),`hash`='$hash'";
+               $query = "insert into `email` set `email`='".$_REQUEST['email']."',`memid`='".intval($_SESSION['profile']['id'])."',`created`=NOW(),`hash`='$hash'";
                mysql_query($query);
                $emailid = mysql_insert_id();
 
        {
                $id = 2;
                $emailid = intval($_REQUEST['emailid']);
-               $query = "select * from `email` where `id`='$emailid' and `memid`='".$_SESSION['profile']['id']."' and `hash` = '' and `deleted`=0";
+               $query = "select * from `email` where `id`='$emailid' and `memid`='".intval($_SESSION['profile']['id'])."' and `hash` = '' and `deleted`=0";
                $res = mysql_query($query);
                if(mysql_num_rows($res) <= 0)
                {
                                "support@cacert.org", "", "", "CAcert Support");
 
                $_SESSION['profile']['email'] = $row['email'];
-               $query = "update `users` set `email`='".$row['email']."' where `id`='".$_SESSION['profile']['id']."'";
+               $query = "update `users` set `email`='".mysql_real_escape_string($row['email'])."' where `id`='".intval($_SESSION['profile']['id'])."'";
                mysql_query($query);
                showheader(_("My CAcert.org Account!"));
                printf(_("Your default email address has been updated to '%s'."), sanitizeHTML($row['email']));
                $delcount = 0;
                if(array_key_exists('delid',$_REQUEST) && is_array($_REQUEST['delid']))
                {
+                       $deltitle=false;
                        foreach($_REQUEST['delid'] as $id)
                        {
-                               if (0==$delcount) {
+                               if (!$deltitle) {
                                        echo _('The following email addresses have been removed:')."<br>\n";
+                                       $deltitle=true;
                                }
                                $id = intval($id);
                                $query = "select * from `email` where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."' and
-                                               `email`!='".$_SESSION['profile']['email']."'";
+                                               `email`!='".mysql_real_escape_string($_SESSION['profile']['email'])."'";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) > 0)
                                {
                                        $row = mysql_fetch_assoc($res);
                                        echo $row['email']."<br>\n";
-                                       $query = "select `emailcerts`.`id`
-                                                       from `emaillink`,`emailcerts` where
-                                                       `emailid`='$id' and `emaillink`.`emailcertsid`=`emailcerts`.`id` and
-                                                       `revoked`=0 and UNIX_TIMESTAMP(`expire`)-UNIX_TIMESTAMP() > 0
-                                                       group by `emailcerts`.`id`";
-                                       $dres = mysql_query($query);
-                                       while($drow = mysql_fetch_assoc($dres))
-                                               mysql_query("update `emailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='".$drow['id']."'");
-
-                                       $query = "update `email` set `deleted`=NOW() where `id`='$id'";
-                                       mysql_query($query);
+                                       account_email_delete($row['id']);
                                        $delcount++;
                                }
                        }
                }
                if(0 == $delcount)
                {
-                       echo _("You failed to select any accounts to be removed, or you attempted to remove the default account. No action was taken.");
+                       echo _("You did not select any accounts to be removed, or you attempted to remove the default account. No action was taken.");
                }
 
                showfooter();
 
        if($process != "" && $oldid == 3)
        {
+               if(!array_key_exists('CCA',$_REQUEST))
+               {
+                       showheader(_("My CAcert.org Account!"));
+                       echo _("You did not accept the CAcert Community Agreement (CCA), hit the back button and try again.");
+                       showfooter();
+                       exit;
+               }
+
                if(!(array_key_exists('addid',$_REQUEST) && is_array($_REQUEST['addid'])) && $_REQUEST['SSO'] != '1')
                {
                        showheader(_("My CAcert.org Account!"));
                        if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
                                $_SESSION['_config']['rootcert'] = 1;
                }
+
+               $_SESSION['_config']['hash_alg'] = HashAlgorithms::clean($_REQUEST['hash_alg']);
+
                $csr = "";
                if(trim($_REQUEST['optionalCSR']) == "")
                {
                        $_REQUEST['keytype'] = "MS";
                        $csr = clean_csr($_REQUEST['optionalCSR']);
                }
+
+               $_SESSION['_config']['description']= trim(stripslashes($_REQUEST['description']));
        }
 
        if($oldid == 4)
                        if(is_array($_SESSION['_config']['addid']))
                        foreach($_SESSION['_config']['addid'] as $id)
                        {
-                               $res = mysql_query("select * from `email` where `memid`='".$_SESSION['profile']['id']."' and `id`='".intval($id)."'");
+                               $res = mysql_query("select * from `email` where `memid`='".intval($_SESSION['profile']['id'])."' and `id`='".intval($id)."'");
                                if(mysql_num_rows($res) > 0)
                                {
                                        $row = mysql_fetch_assoc($res);
                                showfooter();
                                exit;
                        }
-                       $user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".$_SESSION['profile']['id']."'"));
+                       $user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'"));
                        if($_SESSION['_config']['SSO'] == 1)
                                $emails .= "$count.emailAddress = ".$user['uniqueID']."\n";
 
                                exit;
                        }
 
+                       write_user_agreement(intval($_SESSION['profile']['id']), "CCA", "certificate creation", "", 1);
+
                        $query = "insert into emailcerts set
                                                `CN`='$defaultemail',
                                                `keytype`='NS',
                                                `created`=FROM_UNIXTIME(UNIX_TIMESTAMP()),
                                                `codesign`='".intval($_SESSION['_config']['codesign'])."',
                                                `disablelogin`='".($_SESSION['_config']['disablelogin']?1:0)."',
-                                               `rootcert`='".intval($_SESSION['_config']['rootcert'])."'";
+                                               `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
+                                               `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."',
+                                               `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
                        mysql_query($query);
                        $emailid = mysql_insert_id();
                        if(is_array($addys))
                        fputs($fp, $emails);
                        fclose($fp);
                        $challenge=$_SESSION['spkac_hash'];
-                        $res=`openssl spkac -verify -in $CSRname`;
-                        if(!strstr($res,"Challenge String: ".$challenge))
-                        {
-                                $id = $oldid;
-                                showheader(_("My CAcert.org Account!"));
-                                echo _("The challenge-response code of your certificate request did not match. Can't continue with certificaterequest.");
-                                showfooter();
-                                exit;
-                        }
+                       $CSRname_esc = escapeshellarg($CSRname);
+                       $res=shell_exec("openssl spkac -verify -in $CSRname_esc");
+                       if(!strstr($res,"Challenge String: ".$challenge))
+                       {
+                               $id = $oldid;
+                               showheader(_("My CAcert.org Account!"));
+                               echo _("The challenge-response code of your certificate request did not match. Can't continue with certificaterequest.");
+                               showfooter();
+                               exit;
+                       }
                        mysql_query("update `emailcerts` set `csr_name`='$CSRname' where `id`='".intval($emailid)."'");
                } else if($_REQUEST['keytype'] == "MS" || $_REQUEST['keytype'] == "VI") {
                        if($csr == "")
                        $csrsubject="";
 
                        $user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'"));
-                        if(strlen($user['mname']) == 1)
-                                $user['mname'] .= '.';
+                       if(strlen($user['mname']) == 1)
+                               $user['mname'] .= '.';
                        if($_SESSION['_config']['incname'] <= 0 || $_SESSION['_config']['incname'] > 4)
                                $csrsubject = "/CN=CAcert WoT User";
                        if($_SESSION['_config']['incname'] == 1)
                                $csrsubject .= "/emailAddress = ".$user['uniqueID'];
 
                        $tmpname = tempnam("/tmp", "id4csr");
-                       $do = `/usr/bin/openssl req -in $tmpfname -out $tmpname`; // -subj "$csr"`;
+                       $tmpfname_esc = escapeshellarg($tmpfname);
+                       $tmpname_esc = escapeshellarg($tmpname);
+                       $do = shell_exec("/usr/bin/openssl req -in $tmpfname_esc -out $tmpname_esc"); // -subj "$csr";
                        @unlink($tmpfname);
                        $csr = "";
                        $fp = fopen($tmpname, "r");
                        $query = "insert into emailcerts set
                                                `CN`='$defaultemail',
                                                `keytype`='".sanitizeHTML($_REQUEST['keytype'])."',
-                                               `memid`='".$_SESSION['profile']['id']."',
+                                               `memid`='".intval($_SESSION['profile']['id'])."',
                                                `created`=FROM_UNIXTIME(UNIX_TIMESTAMP()),
                                                `subject`='".mysql_real_escape_string($csrsubject)."',
-                                               `codesign`='".$_SESSION['_config']['codesign']."',
+                                               `codesign`='".intval($_SESSION['_config']['codesign'])."',
                                                `disablelogin`='".($_SESSION['_config']['disablelogin']?1:0)."',
-                                               `rootcert`='".$_SESSION['_config']['rootcert']."'";
+                                               `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
+                                               `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."',
+                                               `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
                        mysql_query($query);
                        $emailid = mysql_insert_id();
                        if(is_array($addys))
                csrf_check("adddomain");
                if(strstr($_REQUEST['newdomain'],"\x00"))
                {
-                        showheader(_("My CAcert.org Account!"));
-                        echo _("Due to the possibility for nullbyte domain exploits we currently do not allow any domain names with nullbytes.");
-                        showfooter();
-                        exit;
+                       showheader(_("My CAcert.org Account!"));
+                       echo _("Due to the possibility for nullbyte domain exploits we currently do not allow any domain names with nullbytes.");
+                       showfooter();
+                       exit;
                }
 
                list($newdomain) = explode(" ", $_REQUEST['newdomain'], 2); // Ignore the rest
                $addy = array();
                $adds = array();
                if(strtolower(substr($newdom, -4, 3)) != ".jp")
-                       $adds = explode("\n", trim(`/usr/bin/whois $newdom|grep "@"`));
+                       $adds = explode("\n", trim(shell_exec("/usr/bin/whois $newdom|grep \"@\"")));
                if(substr($newdomain, -4) == ".org" || substr($newdomain, -5) == ".info")
                {
                        if(is_array($adds))
 
                $hash = make_hash();
                $query = "insert into `domains` set `domain`='".mysql_real_escape_string($_SESSION['_config']['domain'])."',
-                                       `memid`='".$_SESSION['profile']['id']."',`created`=NOW(),`hash`='$hash'";
+                                       `memid`='".intval($_SESSION['profile']['id'])."',`created`=NOW(),`hash`='$hash'";
                mysql_query($query);
                $domainid = mysql_insert_id();
 
                        foreach($_REQUEST['delid'] as $id)
                        {
                                $id = intval($id);
-                               $query = "select * from `domains` where `id`='$id' and `memid`='".$_SESSION['profile']['id']."'";
+                               $query = "select * from `domains` where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) > 0)
                                {
                                        $row = mysql_fetch_assoc($res);
                                        echo $row['domain']."<br>\n";
-
-                                       $dres = mysql_query(
-                                               "select `domaincerts`.`id`
-                                                       from `domaincerts`
-                                                       where `domaincerts`.`domid` = '$id'
-                                               union distinct
-                                               select `domaincerts`.`id`
-                                                       from `domaincerts`, `domlink`
-                                                       where `domaincerts`.`id` = `domlink`.`certid`
-                                                       and `domlink`.`domid` = '$id'");
-                                       while($drow = mysql_fetch_assoc($dres))
-                                       {
-                                               mysql_query(
-                                                       "update `domaincerts`
-                                                               set `revoked`='1970-01-01 10:00:01'
-                                                               where `id` = '".$drow['id']."'
-                                                               and `revoked` = 0
-                                                               and UNIX_TIMESTAMP(`expire`) -
-                                                                               UNIX_TIMESTAMP() > 0");
-                                       }
-
-                                       mysql_query(
-                                               "update `domains`
-                                                       set `deleted`=NOW()
-                                                       where `id` = '$id'");
+                                       account_domain_delete($row['id']);
                                }
+
                        }
                }
                else
 
        if($process != "" && $oldid == 10)
        {
+               if(!array_key_exists('CCA',$_REQUEST))
+               {
+                       showheader(_("My CAcert.org Account!"));
+                       echo _("You did not accept the CAcert Community Agreement (CCA), hit the back button and try again.");
+                       showfooter();
+                       exit;
+               }
+
                $CSR = clean_csr($_REQUEST['CSR']);
                if(strpos($CSR,"---BEGIN")===FALSE)
                {
-                 // In case the CSR is missing the ---BEGIN lines, add them automatically:
-                 $CSR = "-----BEGIN CERTIFICATE REQUEST-----\n".$CSR."\n-----END CERTIFICATE REQUEST-----\n";
+                       // In case the CSR is missing the ---BEGIN lines, add them automatically:
+                       $CSR = "-----BEGIN CERTIFICATE REQUEST-----\n".$CSR."\n-----END CERTIFICATE REQUEST-----\n";
                }
 
                if (($weakKey = checkWeakKeyCSR($CSR)) !== "")
                        exit;
                }
 
+               $_SESSION['_config']['description']= trim(stripslashes($_REQUEST['description']));
+
                $_SESSION['_config']['tmpfname'] = tempnam("/tmp", "id10CSR");
                $fp = fopen($_SESSION['_config']['tmpfname'], "w");
                fputs($fp, $CSR);
                fclose($fp);
-               $CSR = $_SESSION['_config']['tmpfname'];
-               $_SESSION['_config']['subject'] = trim(`/usr/bin/openssl req -text -noout -in "$CSR"|tr -d "\\0"|grep "Subject:"`);
-               $bits = explode(",", trim(`/usr/bin/openssl req -text -noout -in "$CSR"|tr -d "\\0"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:`));
+               $CSR = escapeshellarg($_SESSION['_config']['tmpfname']);
+               $_SESSION['_config']['subject'] = trim(shell_exec("/usr/bin/openssl req -text -noout -in $CSR |tr -d \"\\0\"|grep \"Subject:\""));
+               $bits = explode(",", trim(shell_exec("/usr/bin/openssl req -text -noout -in $CSR |tr -d \"\\0\"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:")));
                foreach($bits as $val)
                {
                        $_SESSION['_config']['subject'] .= "/subjectAltName=".trim($val);
                        if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
                                $_SESSION['_config']['rootcert'] = 1;
                }
+
+               $_SESSION['_config']['hash_alg'] = HashAlgorithms::clean($_REQUEST['hash_alg']);
        }
 
        if($process != "" && $oldid == 11)
                        exit;
                }
 
-               $subject = "";
-               $count = 0;
-               $supressSAN=0;
-                if($_SESSION["profile"]["id"] == 104074) $supressSAN=1;
+               $subject = buildSubjectFromSession();
 
-               if(is_array($_SESSION['_config']['rows']))
-                       foreach($_SESSION['_config']['rows'] as $row)
-                       {
-                               $count++;
-                               if($count <= 1)
-                               {
-                                       $subject .= "/CN=$row";
-                                       if(!$supressSAN) $subject .= "/subjectAltName=DNS:$row";
-                                       if(!$supressSAN) $subject .= "/subjectAltName=otherName:1.3.6.1.5.5.7.8.5;UTF8:$row";
-                               } else {
-                                       if(!$supressSAN) $subject .= "/subjectAltName=DNS:$row";
-                                       if(!$supressSAN) $subject .= "/subjectAltName=otherName:1.3.6.1.5.5.7.8.5;UTF8:$row";
-                               }
-                       }
-               if(is_array($_SESSION['_config']['altrows']))
-                       foreach($_SESSION['_config']['altrows'] as $row)
-                       {
-                               if(substr($row, 0, 4) == "DNS:")
-                               {
-                                       $row = substr($row, 4);
-                                       if(!$supressSAN) $subject .= "/subjectAltName=DNS:$row";
-                                       if(!$supressSAN) $subject .= "/subjectAltName=otherName:1.3.6.1.5.5.7.8.5;UTF8:$row";
-                               }
-                       }
                if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
                        $_SESSION['_config']['rootcert'] = 1;
 
+               write_user_agreement(intval($_SESSION['profile']['id']), "CCA", "certificate creation", "", 1);
+
                if(array_key_exists('0',$_SESSION['_config']['rowid']) && $_SESSION['_config']['rowid']['0'] > 0)
                {
                        $query = "insert into `domaincerts` set
                                                `CN`='".mysql_real_escape_string($_SESSION['_config']['rows']['0'])."',
                                                `domid`='".mysql_real_escape_string($_SESSION['_config']['rowid']['0'])."',
                                                `created`=NOW(),`subject`='".mysql_real_escape_string($subject)."',
-                                               `rootcert`='".mysql_real_escape_string($_SESSION['_config']['rootcert'])."'";
+                                               `rootcert`='".mysql_real_escape_string($_SESSION['_config']['rootcert'])."',
+                                               `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."',
+                                               `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
                } elseif(array_key_exists('0',$_SESSION['_config']['altid']) && $_SESSION['_config']['altid']['0'] > 0) {
                        $query = "insert into `domaincerts` set
                                                `CN`='".mysql_real_escape_string($_SESSION['_config']['altrows']['0'])."',
                                                `domid`='".mysql_real_escape_string($_SESSION['_config']['altid']['0'])."',
                                                `created`=NOW(),`subject`='".mysql_real_escape_string($subject)."',
-                                               `rootcert`='".mysql_real_escape_string($_SESSION['_config']['rootcert'])."'";
+                                               `rootcert`='".mysql_real_escape_string($_SESSION['_config']['rootcert'])."',
+                                               `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."',
+                                               `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
                } else {
                        showheader(_("My CAcert.org Account!"));
                        echo _("Domain not verified.");
                        showfooter();
                        exit;
-
                }
 
                mysql_query($query);
                                $query = "select *,UNIX_TIMESTAMP(`domaincerts`.`revoked`) as `revoke` from `domaincerts`,`domains`
                                                where `domaincerts`.`id`='$id' and
                                                `domaincerts`.`domid`=`domains`.`id` and
-                                               `domains`.`memid`='".$_SESSION['profile']['id']."'";
+                                               `domains`.`memid`='".intval($_SESSION['profile']['id'])."'";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                                {
 
                                mysql_query("update `domaincerts` set `renewed`='1' where `id`='$id'");
                                $query = "insert into `domaincerts` set
-                                               `domid`='".$row['domid']."',
+                                               `domid`='".intval($row['domid'])."',
                                                `CN`='".mysql_real_escape_string($row['CN'])."',
                                                `subject`='".mysql_real_escape_string($row['subject'])."',".
                                                //`csr_name`='".$row['csr_name']."', // RACE CONDITION
-                                               "`created`='".$row['created']."',
+                                               "`created`='".mysql_real_escape_string($row['created'])."',
                                                `modified`=NOW(),
-                                               `rootcert`='".$row['rootcert']."',
-                                               `type`='".$row['type']."',
-                                               `pkhash`='".$row['pkhash']."'";
+                                               `rootcert`='".intval($row['rootcert'])."',
+                                               `type`='".intval($row['type'])."',
+                                               `pkhash`='".mysql_real_escape_string($row['pkhash'])."',
+                                               `description`='".mysql_real_escape_string($row['description'])."'";
                                mysql_query($query);
                                $newid = mysql_insert_id();
                                $newfile=generatecertpath("csr","server",$newid);
                                copy($row['csr_name'], $newfile);
-                               $_SESSION['_config']['subject'] = trim(`/usr/bin/openssl req -text -noout -in "$newfile"|tr -d "\\0"|grep "Subject:"`);
-                               $bits = explode(",", trim(`/usr/bin/openssl req -text -noout -in "$newfile"|tr -d "\\0"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:`));
+                               $newfile_esc = escapeshellarg($newfile);
+                               $_SESSION['_config']['subject'] = trim(shell_exec("/usr/bin/openssl req -text -noout -in $newfile_esc |tr -d \"\\0\"|grep \"Subject:\""));
+                               $bits = explode(",", trim(shell_exec("/usr/bin/openssl req -text -noout -in $newfile_esc |tr -d \"\\0\"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:")));
                                foreach($bits as $val)
                                {
                                        $_SESSION['_config']['subject'] .= "/subjectAltName=".trim($val);
                                        continue;
                                }
 
-                               $subject = "";
-                               $count = 0;
-                               if(is_array($_SESSION['_config']['rows']))
-                                       foreach($_SESSION['_config']['rows'] as $row)
-                                       {
-                                               $count++;
-                                               if($count <= 1)
-                                               {
-                                                       $subject .= "/CN=$row";
-                                                       if(!strstr($subject, "=$row/") &&
-                                                               substr($subject, -strlen("=$row")) != "=$row")
-                                                               $subject .= "/subjectAltName=$row";
-                                               } else {
-                                                       if(!strstr($subject, "=$row/") &&
-                                                               substr($subject, -strlen("=$row")) != "=$row")
-                                                               $subject .= "/subjectAltName=$row";
-                                               }
-                                       }
-                               if(is_array($_SESSION['_config']['altrows']))
-                                       foreach($_SESSION['_config']['altrows'] as $row)
-                                               if(!strstr($subject, "=$row/") &&
-                                                       substr($subject, -strlen("=$row")) != "=$row")
-                                                       $subject .= "/subjectAltName=$row";
+                               $subject = buildSubjectFromSession();
                                $subject = mysql_real_escape_string($subject);
                                mysql_query("update `domaincerts` set `subject`='$subject',`csr_name`='$newfile' where `id`='$newid'");
 
                                        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>");
                                } else {
                                        $drow = mysql_fetch_assoc($res);
-                                       $cert = `/usr/bin/openssl x509 -in $drow[crt_name]`;
+                                       $crt_name = escapeshellarg($drow['crt_name']);
+                                       $cert = shell_exec("/usr/bin/openssl x509 -in $crt_name");
                                        echo "<pre>\n$cert\n</pre>\n";
                                }
                        }
                {
                        echo _("You did not select any certificates for renewal.");
                }
+
                showfooter();
                exit;
        }
                                $query = "select *,UNIX_TIMESTAMP(`domaincerts`.`revoked`) as `revoke` from `domaincerts`,`domains`
                                                where `domaincerts`.`id`='$id' and
                                                `domaincerts`.`domid`=`domains`.`id` and
-                                               `domains`.`memid`='".$_SESSION['profile']['id']."'";
+                                               `domains`.`memid`='".intval($_SESSION['profile']['id'])."'";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                                {
                                        continue;
                                }
                                mysql_query("update `domaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'");
-                               printf(_("Certificate for '%s' has been revoked.")."<br>\n", $row['CN']);
+                               printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'<br/>', htmlspecialchars($row['CN']), htmlspecialchars($row['serial']));
                        }
+
+                       // TRANSLATORS: Please don't translate "Certificate Revocation List (CRL)", it's a technical term
+                       echo '<br/>'._('All listed certificates will be added to the Certificate Revocation List (CRL) soon.').'<br/>';
+
                }
                else
                {
                                $query = "select *,UNIX_TIMESTAMP(`domaincerts`.`expire`) as `expired` from `domaincerts`,`domains`
                                                where `domaincerts`.`id`='$id' and
                                                `domaincerts`.`domid`=`domains`.`id` and
-                                               `domains`.`memid`='".$_SESSION['profile']['id']."'";
+                                               `domains`.`memid`='".intval($_SESSION['profile']['id'])."'";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                                {
                exit;
        }
 
+       if($oldid == 12 && array_key_exists('change',$_REQUEST) && $_REQUEST['change'] != "")
+       {
+               showheader(_("My CAcert.org Account!"));
+               foreach($_REQUEST as $id => $val)
+               {
+                       if(substr($id,0,14)=="check_comment_")
+                       {
+                               $cid = intval(substr($id,14));
+                               $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid])));
+                               mysql_query("update `domaincerts` set `description`='$comment' where `id`='$cid'");
+                       }
+               }
+               echo(_("Certificate settings have been changed.")."<br/>\n");
+               showfooter();
+               exit;
+       }
+
+
        if($oldid == 5 && array_key_exists('renew',$_REQUEST) && $_REQUEST['renew'] != "")
        {
                showheader(_("My CAcert.org Account!"));
                        {
                                $id = intval($id);
                                $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `emailcerts`
-                                               where `id`='$id' and `memid`='".$_SESSION['profile']['id']."'";
+                                               where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                                {
 
                                mysql_query("update `emailcerts` set `renewed`='1' where `id`='$id'");
                                $query = "insert into emailcerts set
-                                               `memid`='".$row['memid']."',
+                                               `memid`='".intval($row['memid'])."',
                                                `CN`='".mysql_real_escape_string($row['CN'])."',
                                                `subject`='".mysql_real_escape_string($row['subject'])."',
-                                               `keytype`='".$row['keytype']."',
-                                               `csr_name`='".$row['csr_name']."',
-                                               `created`='".$row['created']."',
+                                               `keytype`='".mysql_real_escape_string($row['keytype'])."',
+                                               `csr_name`='".mysql_real_escape_string($row['csr_name'])."',
+                                               `created`='".mysql_real_escape_string($row['created'])."',
                                                `modified`=NOW(),
-                                               `disablelogin`='".$row['disablelogin']."',
-                                               `codesign`='".$row['codesign']."',
-                                               `rootcert`='".$row['rootcert']."'";
+                                               `disablelogin`='".intval($row['disablelogin'])."',
+                                               `codesign`='".intval($row['codesign'])."',
+                                               `rootcert`='".intval($row['rootcert'])."',
+                                               `description`='".mysql_real_escape_string($row['description'])."'";
                                mysql_query($query);
                                $newid = mysql_insert_id();
                                $newfile=generatecertpath("csr","client",$newid);
                        {
                                $id = intval($id);
                                $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `emailcerts`
-                                               where `id`='$id' and `memid`='".$_SESSION['profile']['id']."'";
+                                               where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                                {
                                        continue;
                                }
                                mysql_query("update `emailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'");
-                               printf(_("Certificate for '%s' has been revoked.")."<br>\n", $row['CN']);
+                               printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'<br/>', htmlspecialchars($row['CN']), htmlspecialchars($row['serial']));
                        }
+
+                       // TRANSLATORS: Please don't translate "Certificate Revocation List (CRL)", it's a technical term
+                       echo '<br/>'._('All listed certificates will be added to the Certificate Revocation List (CRL) soon.').'<br/>';
                }
                else
                {
                        {
                                $id = intval($id);
                                $query = "select *,UNIX_TIMESTAMP(`expire`) as `expired` from `emailcerts`
-                                               where `id`='$id' and `memid`='".$_SESSION['profile']['id']."'";
+                                               where `id`='$id' and `memid`='".intval($_SESSION['profile']['id'])."'";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                                {
 
        if($oldid == 5 && array_key_exists('change',$_REQUEST) && $_REQUEST['change'] != "")
        {
-         showheader(_("My CAcert.org Account!"));
-         //echo _("Now changing the settings for the following certificates:")."<br>\n";
-         foreach($_REQUEST as $id => $val)
-         {
-           //echo $id."<br/>";
-           if(substr($id,0,5)=="cert_")
-           {
-             $id = intval(substr($id,5));
-             $dis=(array_key_exists('disablelogin_'.$id,$_REQUEST) && $_REQUEST['disablelogin_'.$id]=="1")?"0":"1";
-             //echo "$id -> ".$_REQUEST['disablelogin_'.$id]."<br/>\n";
-             mysql_query("update `emailcerts` set `disablelogin`='$dis' where `id`='$id' and `memid`='".$_SESSION['profile']['id']."'");
-             //$row = mysql_fetch_assoc($res);
-           }
-         }
-         echo(_("Certificate settings have been changed.")."<br/>\n");
-         showfooter();
-         exit;
+               showheader(_("My CAcert.org Account!"));
+               foreach($_REQUEST as $id => $val)
+               {
+                       if(substr($id,0,5)=="cert_")
+                       {
+                               $cid = intval(substr($id,5));
+                               $dis=(array_key_exists('disablelogin_'.$cid,$_REQUEST) && $_REQUEST['disablelogin_'.$cid]=="1")?"0":"1";
+                               mysql_query("update `emailcerts` set `disablelogin`='$dis' where `id`='$cid' and `memid`='".intval($_SESSION['profile']['id'])."'");
+                       }
+                       if(substr($id,0,14)=="check_comment_")
+                       {
+                               $cid = intval(substr($id,14));
+                               if(!empty($_REQUEST['check_comment_'.$cid])) {
+                                       $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid])));
+                                       mysql_query("update `emailcerts` set `description`='$comment' where `id`='$cid' and `memid`='".intval($_SESSION['profile']['id'])."'");
+                               }
+                       }
+               }
+               echo(_("Certificate settings have been changed.")."<br/>\n");
+               showfooter();
+               exit;
        }
 
-
-       if($oldid == 13 && $process != "")
+       if($oldid == 13 && $process != "" && $showdetails!="")
        {
                csrf_check("perschange");
                $_SESSION['_config']['user'] = $_SESSION['profile'];
                $_SESSION['_config']['user']['A4'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A4']))));
                $_SESSION['_config']['user']['A5'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['A5']))));
 
-                if($_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q2'] ||
-                        $_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q3'] ||
-                        $_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q4'] ||
-                        $_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q5'] ||
-                        $_SESSION['_config']['user']['Q2'] == $_SESSION['_config']['user']['Q3'] ||
-                        $_SESSION['_config']['user']['Q2'] == $_SESSION['_config']['user']['Q4'] ||
-                        $_SESSION['_config']['user']['Q2'] == $_SESSION['_config']['user']['Q5'] ||
-                        $_SESSION['_config']['user']['Q3'] == $_SESSION['_config']['user']['Q4'] ||
-                        $_SESSION['_config']['user']['Q3'] == $_SESSION['_config']['user']['Q5'] ||
-                        $_SESSION['_config']['user']['Q4'] == $_SESSION['_config']['user']['Q5'] ||
-                        $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q1'] ||
-                        $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q2'] ||
-                        $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q3'] ||
-                        $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q4'] ||
-                        $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q5'] ||
-                        $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['Q3'] ||
-                        $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['Q4'] ||
-                        $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['Q5'] ||
-                        $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['Q4'] ||
-                        $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['Q5'] ||
-                        $_SESSION['_config']['user']['A4'] == $_SESSION['_config']['user']['Q5'] ||
-                        $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A2'] ||
-                        $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A3'] ||
-                        $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A4'] ||
-                        $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A5'] ||
-                        $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['A3'] ||
-                        $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['A4'] ||
-                        $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['A5'] ||
-                        $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['A4'] ||
-                        $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['A5'] ||
-                        $_SESSION['_config']['user']['A4'] == $_SESSION['_config']['user']['A5'])
-                {
-                        $_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";
-                        $id = $oldid;
+               if($_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q2'] ||
+                               $_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q3'] ||
+                               $_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q4'] ||
+                               $_SESSION['_config']['user']['Q1'] == $_SESSION['_config']['user']['Q5'] ||
+                               $_SESSION['_config']['user']['Q2'] == $_SESSION['_config']['user']['Q3'] ||
+                               $_SESSION['_config']['user']['Q2'] == $_SESSION['_config']['user']['Q4'] ||
+                               $_SESSION['_config']['user']['Q2'] == $_SESSION['_config']['user']['Q5'] ||
+                               $_SESSION['_config']['user']['Q3'] == $_SESSION['_config']['user']['Q4'] ||
+                               $_SESSION['_config']['user']['Q3'] == $_SESSION['_config']['user']['Q5'] ||
+                               $_SESSION['_config']['user']['Q4'] == $_SESSION['_config']['user']['Q5'] ||
+                               $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q1'] ||
+                               $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q2'] ||
+                               $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q3'] ||
+                               $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q4'] ||
+                               $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['Q5'] ||
+                               $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['Q3'] ||
+                               $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['Q4'] ||
+                               $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['Q5'] ||
+                               $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['Q4'] ||
+                               $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['Q5'] ||
+                               $_SESSION['_config']['user']['A4'] == $_SESSION['_config']['user']['Q5'] ||
+                               $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A2'] ||
+                               $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A3'] ||
+                               $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A4'] ||
+                               $_SESSION['_config']['user']['A1'] == $_SESSION['_config']['user']['A5'] ||
+                               $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['A3'] ||
+                               $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['A4'] ||
+                               $_SESSION['_config']['user']['A2'] == $_SESSION['_config']['user']['A5'] ||
+                               $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['A4'] ||
+                               $_SESSION['_config']['user']['A3'] == $_SESSION['_config']['user']['A5'] ||
+                               $_SESSION['_config']['user']['A4'] == $_SESSION['_config']['user']['A5'])
+               {
+                       $_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";
+                       $id = $oldid;
                        $oldid=0;
-                }
+               }
 
                if($_SESSION['_config']['user']['Q1'] == "" || $_SESSION['_config']['user']['Q2'] == "" ||
                        $_SESSION['_config']['user']['Q3'] == "" || $_SESSION['_config']['user']['Q4'] == "" ||
 
        if($oldid == 13 && $process != "")
        {
-               $ddquery = "select sum(`points`) as `total` from `notary` where `to`='".$_SESSION['profile']['id']."' group by `to`";
+               $ddquery = "select sum(`points`) as `total` from `notary` where `to`='".intval($_SESSION['profile']['id'])."' and `deleted` = 0 group by `to`";
                $ddres = mysql_query($ddquery);
                $ddrow = mysql_fetch_assoc($ddres);
                $_SESSION['profile']['points'] = $ddrow['total'];
                                                `lname`='".$_SESSION['_config']['user']['lname']."',
                                                `suffix`='".$_SESSION['_config']['user']['suffix']."',
                                                `dob`='".$_SESSION['_config']['user']['year']."-".$_SESSION['_config']['user']['month']."-".$_SESSION['_config']['user']['day']."'
-                                               where `id`='".$_SESSION['profile']['id']."'";
+                                               where `id`='".intval($_SESSION['profile']['id'])."'";
                        mysql_query($query);
                }
-               $query = "update `users` set `Q1`='".$_SESSION['_config']['user']['Q1']."',
-                                               `Q2`='".$_SESSION['_config']['user']['Q2']."',
-                                               `Q3`='".$_SESSION['_config']['user']['Q3']."',
-                                               `Q4`='".$_SESSION['_config']['user']['Q4']."',
-                                               `Q5`='".$_SESSION['_config']['user']['Q5']."',
-                                               `A1`='".$_SESSION['_config']['user']['A1']."',
-                                               `A2`='".$_SESSION['_config']['user']['A2']."',
-                                               `A3`='".$_SESSION['_config']['user']['A3']."',
-                                               `A4`='".$_SESSION['_config']['user']['A4']."',
-                                               `A5`='".$_SESSION['_config']['user']['A5']."'
-                                               where `id`='".$_SESSION['profile']['id']."'";
-               mysql_query($query);
-
-               //!!!Should be rewritten
-               $_SESSION['_config']['user']['otphash'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['otphash']))));
-               $_SESSION['_config']['user']['otppin'] = trim(mysql_real_escape_string(stripslashes(strip_tags($_REQUEST['otppin']))));
-               if($_SESSION['_config']['user']['otphash'] != "" && $_SESSION['_config']['user']['otppin'] != "")
-               {
-                       $query = "update `users` set `otphash`='".$_SESSION['_config']['user']['otphash']."',
-                                               `otppin`='".$_SESSION['_config']['user']['otppin']."' where `id`='".$_SESSION['profile']['id']."'";
+               if ($showdetails!="") {
+                       $query = "update `users` set `Q1`='".$_SESSION['_config']['user']['Q1']."',
+                                                       `Q2`='".$_SESSION['_config']['user']['Q2']."',
+                                                       `Q3`='".$_SESSION['_config']['user']['Q3']."',
+                                                       `Q4`='".$_SESSION['_config']['user']['Q4']."',
+                                                       `Q5`='".$_SESSION['_config']['user']['Q5']."',
+                                                       `A1`='".$_SESSION['_config']['user']['A1']."',
+                                                       `A2`='".$_SESSION['_config']['user']['A2']."',
+                                                       `A3`='".$_SESSION['_config']['user']['A3']."',
+                                                       `A4`='".$_SESSION['_config']['user']['A4']."',
+                                                       `A5`='".$_SESSION['_config']['user']['A5']."'
+                                                       where `id`='".intval($_SESSION['profile']['id'])."'";
                        mysql_query($query);
                }
 
                $_SESSION['_config']['user']['set'] = 0;
-               $_SESSION['profile'] = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".$_SESSION['profile']['id']."'"));
+               $_SESSION['profile'] = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."'"));
                $_SESSION['profile']['loggedin'] = 1;
 
-               $ddquery = "select sum(`points`) as `total` from `notary` where `to`='".$_SESSION['profile']['id']."' group by `to`";
+               $ddquery = "select sum(`points`) as `total` from `notary` where `to`='".intval($_SESSION['profile']['id'])."' and `deleted` = 0 group by `to`";
                $ddres = mysql_query($ddquery);
                $ddrow = mysql_fetch_assoc($ddres);
                $_SESSION['profile']['points'] = $ddrow['total'];
 
                        if($_SESSION['_config']['hostname'] != $_SESSION['_config']['securehostname'])
                        {
-                               $match = mysql_query("select * from `users` where `id`='".$_SESSION['profile']['id']."' and
+                               $match = mysql_query("select * from `users` where `id`='".intval($_SESSION['profile']['id'])."' and
                                                (`password`=old_password('".$_SESSION['_config']['user']['oldpass']."') or
                                                `password`=sha1('".$_SESSION['_config']['user']['oldpass']."'))");
                                $rc = mysql_num_rows($match);
                                echo _("You failed to correctly enter your current Pass Phrase.");
                        } else {
                                mysql_query("update `users` set `password`=sha1('".$_SESSION['_config']['user']['pword1']."')
-                                               where `id`='".$_SESSION['profile']['id']."'");
+                                               where `id`='".intval($_SESSION['profile']['id'])."'");
                                echo '<h3>', _("Pass Phrase Changed Successfully"), '</h3>', "\n";
                                echo _("Your Pass Phrase has been updated and your primary email account has been notified of the change.");
                                $body  = sprintf(_("Hi %s,"),$_SESSION['profile']['fname'])."\n\n";
                                $_SESSION['_config']['emails'][] = $val;
                }
                $_SESSION['_config']['name'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['name'])));
-               $_SESSION['_config']['OU'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['OU'])));
+               $_SESSION['_config']['OU'] = stripslashes(trim($_REQUEST['OU']));
+
+               $_SESSION['_config']['description']= trim(stripslashes($_REQUEST['description']));
        }
 
        if($oldid == 16 && (intval(count($_SESSION['_config']['emails'])) + 0) <= 0)
 
        if($oldid == 16 && $process != "")
        {
-
                if(array_key_exists('codesign',$_REQUEST) && $_REQUEST['codesign'] && $_SESSION['profile']['codesign'] && ($_SESSION['profile']['points'] >= 100))
                {
                        $_REQUEST['codesign'] = 1;
                if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
                        $_SESSION['_config']['rootcert'] = 1;
 
+               $_SESSION['_config']['hash_alg'] = HashAlgorithms::clean($_REQUEST['hash_alg']);
+
+               $_SESSION['_config']['description']= trim(stripslashes($_REQUEST['description']));
+
                if(@count($_SESSION['_config']['emails']) > 0)
                        $id = 17;
        }
                        if($_SESSION['_config']['name'] != "")
                                $emails .= "commonName = ".$_SESSION['_config']['name']."\n";
                        if($_SESSION['_config']['OU'])
-                               $emails .= "organizationalUnitName = ".$_SESSION['_config']['OU']."\n";
+                               $emails .= "organizationalUnitName = ".mysql_real_escape_string($_SESSION['_config']['OU'])."\n";
                        if($org['O'])
                                $emails .= "organizationName = ".$org['O']."\n";
                        if($org['L'])
                        if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
                                $_SESSION['_config']['rootcert'] = 1;
 
+
                        $emails .= "SPKAC = $spkac";
                        if (($weakKey = checkWeakKeySPKAC($emails)) !== "")
                        {
 
                        $query = "insert into `orgemailcerts` set
                                                `CN`='$defaultemail',
+                                               `ou`='".mysql_real_escape_string($_SESSION['_config']['OU'])."',
                                                `keytype`='NS',
-                                               `orgid`='".$org['orgid']."',
+                                               `orgid`='".intval($org['orgid'])."',
                                                `created`=FROM_UNIXTIME(UNIX_TIMESTAMP()),
-                                               `codesign`='".$_SESSION['_config']['codesign']."',
-                                               `rootcert`='".$_SESSION['_config']['rootcert']."'";
+                                               `codesign`='".intval($_SESSION['_config']['codesign'])."',
+                                               `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
+                                               `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."',
+                                               `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
                        mysql_query($query);
                        $emailid = mysql_insert_id();
 
                        fputs($fp, $emails);
                        fclose($fp);
                        $challenge=$_SESSION['spkac_hash'];
-                        $res=`openssl spkac -verify -in $CSRname`;
-                        if(!strstr($res,"Challenge String: ".$challenge))
-                        {
-                                $id = $oldid;
-                                showheader(_("My CAcert.org Account!"));
-                                echo _("The challenge-response code of your certificate request did not match. Can't continue with certificaterequest.");
-                                showfooter();
-                                exit;
-                        }
+                       $CSRname_esc = escapeshellarg($CSRname);
+                       $res=shell_exec("openssl spkac -verify -in $CSRname_esc");
+                       if(!strstr($res,"Challenge String: ".$challenge))
+                       {
+                               $id = $oldid;
+                               showheader(_("My CAcert.org Account!"));
+                               echo _("The challenge-response code of your certificate request did not match. Can't continue with certificaterequest.");
+                               showfooter();
+                               exit;
+                       }
                        mysql_query("update `orgemailcerts` set `csr_name`='$CSRname' where `id`='$emailid'");
                } else if($_REQUEST['keytype'] == "MS" || $_REQUEST['keytype']=="VI") {
-                       $csr = "-----BEGIN CERTIFICATE REQUEST-----\n".clean_csr($_REQUEST['CSR'])."-----END CERTIFICATE REQUEST-----\n";
+                       $csr = clean_csr($_REQUEST['CSR']);
+                       if(strpos($csr,"---BEGIN") === FALSE)
+                       {
+                               // In case the CSR is missing the ---BEGIN lines, add them automatically:
+                               $csr = "-----BEGIN CERTIFICATE REQUEST-----\n".$csr."\n-----END CERTIFICATE REQUEST-----\n";
+                       }
 
                        if (($weakKey = checkWeakKeyCSR($csr)) !== "")
                        {
                                $csrsubject .= "/countryName=".$org['C'];
 
                        $tmpname = tempnam("/tmp", "id17csr");
-                       $do = `/usr/bin/openssl req -in $tmpfname -out $tmpname`;
+                       $tmpfname_esc = escapeshellarg($tmpfname);
+                       $tmpname_esc = escapeshellarg($tmpname);
+                       $do = shell_exec("/usr/bin/openssl req -in $tmpfname_esc -out $tmpname_esc");
                        @unlink($tmpfname);
                        $csr = "";
                        $fp = fopen($tmpname, "r");
 
                        $query = "insert into `orgemailcerts` set
                                                `CN`='$defaultemail',
+                                               `ou`='".mysql_real_escape_string($_SESSION['_config']['OU'])."',
                                                `keytype`='" . sanitizeHTML($_REQUEST['keytype']) . "',
-                                               `orgid`='".$org['orgid']."',
+                                               `orgid`='".intval($org['orgid'])."',
                                                `created`=FROM_UNIXTIME(UNIX_TIMESTAMP()),
-                                               `subject`='$csrsubject',
-                                               `codesign`='".$_SESSION['_config']['codesign']."',
-                                               `rootcert`='".$_SESSION['_config']['rootcert']."'";
+                                               `subject`='".mysql_real_escape_string($csrsubject)."',
+                                               `codesign`='".intval($_SESSION['_config']['codesign'])."',
+                                               `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
+                                               `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."',
+                                               `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
                        mysql_query($query);
                        $emailid = mysql_insert_id();
 
                                echo "Renewing certificate #$id ...\n<br/>";
                                $id = intval($id);
                                $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `orgemailcerts`, `org`
-                                               where `orgemailcerts`.`id`='$id' and `org`.`memid`='".$_SESSION['profile']['id']."' and
+                                               where `orgemailcerts`.`id`='$id' and `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
                                                `org`.`orgid`=`orgemailcerts`.`orgid`";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                                        continue;
                                }
                                $query = "insert into `orgemailcerts` set
-                                               `orgid`='".$row['orgid']."',
-                                               `CN`='".$row['CN']."',
-                                               `subject`='".$row['subject']."',
-                                               `keytype`='".$row['keytype']."',
-                                               `csr_name`='".$row['csr_name']."',
-                                               `created`='".$row['created']."',
+                                               `orgid`='".intval($row['orgid'])."',
+                                               `CN`='".mysql_real_escape_string($row['CN'])."',
+                                               `ou`='".mysql_real_escape_string($row['ou'])."',
+                                               `subject`='".mysql_real_escape_string($row['subject'])."',
+                                               `keytype`='".mysql_real_escape_string($row['keytype'])."',
+                                               `csr_name`='".mysql_real_escape_string($row['csr_name'])."',
+                                               `created`='".mysql_real_escape_string($row['created'])."',
                                                `modified`=NOW(),
-                                               `codesign`='".$row['codesign']."',
-                                               `rootcert`='".$row['rootcert']."'";
+                                               `codesign`='".intval($row['codesign'])."',
+                                               `rootcert`='".intval($row['rootcert'])."',
+                                               `description`='".mysql_real_escape_string($row['description'])."'";
                                mysql_query($query);
                                $newid = mysql_insert_id();
                                $newfile=generatecertpath("csr","orgclient",$newid);
                        {
                                $id = intval($id);
                                $query = "select *,UNIX_TIMESTAMP(`revoked`) as `revoke` from `orgemailcerts`, `org`
-                                               where `orgemailcerts`.`id`='$id' and `org`.`memid`='".$_SESSION['profile']['id']."' and
+                                               where `orgemailcerts`.`id`='".intval($id)."' and `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
                                                `org`.`orgid`=`orgemailcerts`.`orgid`";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                                        continue;
                                }
                                mysql_query("update `orgemailcerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'");
-                               printf(_("Certificate for '%s' has been revoked.")."<br>\n", $row['CN']);
+                               printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'<br/>', htmlspecialchars($row['CN']), htmlspecialchars($row['serial']));
                        }
+
+                       // TRANSLATORS: Please don't translate "Certificate Revocation List (CRL)", it's a technical term
+                       echo '<br/>'._('All listed certificates will be added to the Certificate Revocation List (CRL) soon.').'<br/>';
                }
                else
                {
                        {
                                $id = intval($id);
                                $query = "select *,UNIX_TIMESTAMP(`expire`) as `expired` from `orgemailcerts`, `org`
-                                               where `orgemailcerts`.`id`='$id' and `org`.`memid`='".$_SESSION['profile']['id']."' and
+                                               where `orgemailcerts`.`id`='".intval($id)."' and `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
                                                `org`.`orgid`=`orgemailcerts`.`orgid`";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                exit;
        }
 
+       if($oldid == 18 && array_key_exists('change',$_REQUEST) && $_REQUEST['change'] != "")
+       {
+               showheader(_("My CAcert.org Account!"));
+               foreach($_REQUEST as $id => $val)
+               {
+                       if(substr($id,0,14)=="check_comment_")
+                       {
+                               $cid = intval(substr($id,14));
+                               $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid])));
+                               mysql_query("update `orgemailcerts` set `description`='$comment' where `id`='$cid'");
+                       }
+               }
+               echo(_("Certificate settings have been changed.")."<br/>\n");
+               showfooter();
+               exit;
+       }
+
+       if($oldid == 18 && array_key_exists('filter',$_REQUEST) && $_REQUEST['filter']!= "")
+       {
+               $id=18;
+               $_SESSION['_config']['orgfilterid']=$_REQUEST['orgfilterid'];
+               $_SESSION['_config']['sorting']=$_REQUEST['sorting'];
+               $_SESSION['_config']['status']=$_REQUEST['status'];
+       }
+
+       if($oldid == 18 && array_key_exists('reset',$_REQUEST) && $_REQUEST['reset']!= "")
+       {
+               $id=18;
+               $_SESSION['_config']['orgfilterid']=0;
+               $_SESSION['_config']['sorting']=0;
+               $_SESSION['_config']['status']=0;
+       }
+
        if($process != "" && $oldid == 20)
        {
                $CSR = clean_csr($_REQUEST['CSR']);
                        exit;
                }
 
+               $_SESSION['_config']['description']= trim(stripslashes($_REQUEST['description']));
+
                $_SESSION['_config']['tmpfname'] = tempnam("/tmp", "id20CSR");
                $fp = fopen($_SESSION['_config']['tmpfname'], "w");
                fputs($fp, $CSR);
                fclose($fp);
-               $CSR = $_SESSION['_config']['tmpfname'];
-               $_SESSION['_config']['subject'] = trim(`/usr/bin/openssl req -text -noout -in "$CSR"|tr -d "\\0"|grep "Subject:"`);
-               $bits = explode(",", trim(`/usr/bin/openssl req -text -noout -in "$CSR"|tr -d "\\0"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:`));
+               $CSR = escapeshellarg($_SESSION['_config']['tmpfname']);
+               $_SESSION['_config']['subject'] = trim(shell_exec("/usr/bin/openssl req -text -noout -in $CSR |tr -d \"\\0\"|grep \"Subject:\""));
+               $bits = explode(",", trim(shell_exec("/usr/bin/openssl req -text -noout -in $CSR |tr -d \"\\0\"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:")));
                foreach($bits as $val)
                {
                        $_SESSION['_config']['subject'] .= "/subjectAltName=".trim($val);
                getalt2();
 
                $query = "select * from `orginfo`,`org`,`orgdomains` where
-                               `org`.`memid`='".$_SESSION['profile']['id']."' and
+                               `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
                                `org`.`orgid`=`orginfo`.`id` and
                                `org`.`orgid`=`orgdomains`.`orgid` and
-                               `orgdomains`.`domain`='".$_SESSION['_config']['0.CN']."'";
+                               `orgdomains`.`domain`='".mysql_real_escape_string($_SESSION['_config']['0.CN'])."'";
                $_SESSION['_config']['CNorg'] = mysql_fetch_assoc(mysql_query($query));
                $query = "select * from `orginfo`,`org`,`orgdomains` where
-                               `org`.`memid`='".$_SESSION['profile']['id']."' and
+                               `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
                                `org`.`orgid`=`orginfo`.`id` and
                                `org`.`orgid`=`orgdomains`.`orgid` and
-                               `orgdomains`.`domain`='".$_SESSION['_config']['0.subjectAltName']."'";
+                               `orgdomains`.`domain`='".mysql_real_escape_string($_SESSION['_config']['0.subjectAltName'])."'";
                $_SESSION['_config']['SANorg'] = mysql_fetch_assoc(mysql_query($query));
 //echo "<pre>"; print_r($_SESSION['_config']); die;
 
                $_SESSION['_config']['rootcert'] = intval($_REQUEST['rootcert']);
                if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
                        $_SESSION['_config']['rootcert'] = 1;
+
+               $_SESSION['_config']['hash_alg'] = HashAlgorithms::clean($_REQUEST['hash_alg']);
        }
 
        if($process != "" && $oldid == 21)
                        exit;
                }
 
-                if($_SESSION['_config']['rowid']['0'] > 0)
-                {
+               if($_SESSION['_config']['rowid']['0'] > 0)
+               {
                        $query = "select * from `org`,`orginfo` where
-                                       `orginfo`.`id`='".$_SESSION['_config']['rowid']['0']."' and
+                                       `orginfo`.`id`='".intval($_SESSION['_config']['rowid']['0'])."' and
                                        `orginfo`.`id`=`org`.`orgid` and
-                                       `org`.`memid`='".$_SESSION['profile']['id']."'";
+                                       `org`.`memid`='".intval($_SESSION['profile']['id'])."'";
                } else {
                        $query = "select * from `org`,`orginfo` where
-                                       `orginfo`.`id`='".$_SESSION['_config']['altid']['0']."' and
+                                       `orginfo`.`id`='".intval($_SESSION['_config']['altid']['0'])."' and
                                        `orginfo`.`id`=`org`.`orgid` and
-                                       `org`.`memid`='".$_SESSION['profile']['id']."'";
+                                       `org`.`memid`='".intval($_SESSION['profile']['id'])."'";
                }
                $org = mysql_fetch_assoc(mysql_query($query));
                $csrsubject = "";
                //if($org['contact'])
                //      $csrsubject .= "/emailAddress=".trim($org['contact']);
 
-               if(is_array($_SESSION['_config']['rows']))
-                       foreach($_SESSION['_config']['rows'] as $row)
-                               $csrsubject .= "/commonName=$row";
-               $SAN="";
-               if(is_array($_SESSION['_config']['altrows']))
-                       foreach($_SESSION['_config']['altrows'] as $subalt)
-                       {
-                               if($SAN != "")
-                                       $SAN .= ",";
-                               $SAN .= "$subalt";
-                       }
-
-               if($SAN != "")
-                       $csrsubject .= "/subjectAltName=".$SAN;
+               $csrsubject .= buildSubjectFromSession();
 
                $type="";
                if($_REQUEST["ocspcert"]!="" && $_SESSION['profile']['admin'] == 1) $type="8";
                if($_SESSION['_config']['rootcert'] < 1 || $_SESSION['_config']['rootcert'] > 2)
                        $_SESSION['_config']['rootcert'] = 1;
 
-                if($_SESSION['_config']['rowid']['0'] > 0)
-                {
-                        $query = "insert into `orgdomaincerts` set
-                                               `CN`='".$_SESSION['_config']['rows']['0']."',
-                                               `orgid`='".$org['id']."',
-                                                `created`=NOW(),
-                                               `subject`='$csrsubject',
-                                               `rootcert`='".$_SESSION['_config']['rootcert']."',
-                                               `type`='$type'";
-                } else {
-                        $query = "insert into `orgdomaincerts` set
-                                               `CN`='".$_SESSION['_config']['altrows']['0']."',
-                                               `orgid`='".$org['id']."',
-                                                `created`=NOW(),
-                                               `subject`='$csrsubject',
-                                               `rootcert`='".$_SESSION['_config']['rootcert']."',
-                                               `type`='$type'";
-                }
-                mysql_query($query);
+               if($_SESSION['_config']['rowid']['0'] > 0)
+               {
+                       $query = "insert into `orgdomaincerts` set
+                                       `CN`='".mysql_real_escape_string($_SESSION['_config']['rows']['0'])."',
+                                       `orgid`='".intval($org['id'])."',
+                                       `created`=NOW(),
+                                       `subject`='".mysql_real_escape_string($csrsubject)."',
+                                       `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
+                                       `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."',
+                                       `type`='".$type."',
+                                       `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
+               } else {
+                       $query = "insert into `orgdomaincerts` set
+                                       `CN`='".mysql_real_escape_string($_SESSION['_config']['altrows']['0'])."',
+                                       `orgid`='".intval($org['id'])."',
+                                       `created`=NOW(),
+                                       `subject`='".mysql_real_escape_string($csrsubject)."',
+                                       `rootcert`='".intval($_SESSION['_config']['rootcert'])."',
+                                       `md`='".mysql_real_escape_string($_SESSION['_config']['hash_alg'])."',
+                                       `type`='".$type."',
+                                       `description`='".mysql_real_escape_string($_SESSION['_config']['description'])."'";
+               }
+               mysql_query($query);
                $CSRid = mysql_insert_id();
 
                $CSRname=generatecertpath("csr","orgserver",$CSRid);
                mysql_query("update `orgdomaincerts` set `CSR_name`='$CSRname' where `id`='$CSRid'");
                if(is_array($_SESSION['_config']['rowid']))
                        foreach($_SESSION['_config']['rowid'] as $id)
-                               mysql_query("insert into `orgdomlink` set `orgdomid`='$id', `orgcertid`='$CSRid'");
+                               mysql_query("insert into `orgdomlink` set `orgdomid`='".intval($id)."', `orgcertid`='$CSRid'");
                if(is_array($_SESSION['_config']['altid']))
                        foreach($_SESSION['_config']['altid'] as $id)
-                               mysql_query("insert into `orgdomlink` set `orgdomid`='$id', `orgcertid`='$CSRid'");
+                               mysql_query("insert into `orgdomlink` set `orgdomid`='".intval($id)."', `orgcertid`='$CSRid'");
                waitForResult("orgdomaincerts", $CSRid,$oldid);
                $query = "select * from `orgdomaincerts` where `id`='$CSRid' and `crt_name` != ''";
                $res = mysql_query($query);
                                                `orgdomaincerts`,`org`
                                                where `orgdomaincerts`.`id`='$id' and
                                                `orgdomaincerts`.`orgid`=`org`.`orgid` and
-                                               `org`.`memid`='".$_SESSION['profile']['id']."'";
+                                               `org`.`memid`='".intval($_SESSION['profile']['id'])."'";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                                {
                                        continue;
                                }
                                $query = "insert into `orgdomaincerts` set
-                                               `orgid`='".$row['orgid']."',
-                                               `CN`='".$row['CN']."',
-                                               `csr_name`='".$row['csr_name']."',
-                                               `created`='".$row['created']."',
+                                               `orgid`='".intval($row['orgid'])."',
+                                               `CN`='".mysql_real_escape_string($row['CN'])."',
+                                               `csr_name`='".mysql_real_escape_string($row['csr_name'])."',
+                                               `created`='".mysql_real_escape_string($row['created'])."',
                                                `modified`=NOW(),
-                                               `subject`='".$row['subject']."',
-                                               `type`='".$row['type']."',
-                                               `rootcert`='".$row['rootcert']."'";
+                                               `subject`='".mysql_real_escape_string($row['subject'])."',
+                                               `type`='".intval($row['type'])."',
+                                               `rootcert`='".intval($row['rootcert'])."',
+                                               `description`='".mysql_real_escape_string($row['description'])."'";
                                mysql_query($query);
                                $newid = mysql_insert_id();
                                //echo "NewID: $newid<br/>\n";
                                echo _("Renewing").": ".$row['CN']."<br>\n";
                                $res = mysql_query("select * from `orgdomlink` where `orgcertid`='".$row['id']."'");
                                while($r2 = mysql_fetch_assoc($res))
-                                       mysql_query("insert into `orgdomlink` set `orgdomid`='".$r2['id']."', `orgcertid`='$newid'");
+                                       mysql_query("insert into `orgdomlink` set `orgdomid`='".intval($r2['orgdomid'])."', `orgcertid`='$newid'");
                                waitForResult("orgdomaincerts", $newid,$oldid,0);
                                $query = "select * from `orgdomaincerts` where `id`='$newid' and `crt_name` != ''";
                                $res = mysql_query($query);
                                        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>");
                                } else {
                                        $drow = mysql_fetch_assoc($res);
-                                       $cert = `/usr/bin/openssl x509 -in $drow[crt_name]`;
+                                       $crtname = escapeshellarg($drow['crt_name']);
+                                       $cert = shell_exec("/usr/bin/openssl x509 -in $crtname");
                                        echo "<pre>\n$cert\n</pre>\n";
                                }
                        }
                                                `orgdomaincerts`,`org`
                                                where `orgdomaincerts`.`id`='$id' and
                                                `orgdomaincerts`.`orgid`=`org`.`orgid` and
-                                               `org`.`memid`='".$_SESSION['profile']['id']."'";
+                                               `org`.`memid`='".intval($_SESSION['profile']['id'])."'";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                                {
                                        continue;
                                }
                                mysql_query("update `orgdomaincerts` set `revoked`='1970-01-01 10:00:01' where `id`='$id'");
-                               printf(_("Certificate for '%s' has been revoked.")."<br>\n", $row['CN']);
+                               printf(_("Certificate for '%s' with the serial no '%s' has been revoked.").'<br/>', htmlspecialchars($row['CN']), htmlspecialchars($row['serial']));
                        }
+
+                       // TRANSLATORS: Please don't translate "Certificate Revocation List (CRL)", it's a technical term
+                       echo '<br/>'._('All listed certificates will be added to the Certificate Revocation List (CRL) soon.').'<br/>';
                }
                else
                {
                                                `orgdomaincerts`,`org`
                                                where `orgdomaincerts`.`id`='$id' and
                                                `orgdomaincerts`.`orgid`=`org`.`orgid` and
-                                               `org`.`memid`='".$_SESSION['profile']['id']."'";
+                                               `org`.`memid`='".intval($_SESSION['profile']['id'])."'";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) <= 0)
                                {
                exit;
        }
 
+       if($oldid == 22 && array_key_exists('change',$_REQUEST) && $_REQUEST['change'] != "")
+       {
+               showheader(_("My CAcert.org Account!"));
+               foreach($_REQUEST as $id => $val)
+               {
+                       if(substr($id,0,14)=="check_comment_")
+                       {
+                               $cid = intval(substr($id,14));
+                               $comment=trim(mysql_real_escape_string(stripslashes($_REQUEST['comment_'.$cid])));
+                               mysql_query("update `orgdomaincerts` set `description`='$comment' where `id`='$cid'");
+                       }
+               }
+               echo(_("Certificate settings have been changed.")."<br/>\n");
+               showfooter();
+               exit;
+       }
+
+       if($oldid == 22 && array_key_exists('filter',$_REQUEST) && $_REQUEST['filter']!= "")
+       {
+               $id=22;
+               $_SESSION['_config']['dorgfilterid']=$_REQUEST['dorgfilterid'];
+               $_SESSION['_config']['dsorting']=$_REQUEST['dsorting'];
+               $_SESSION['_config']['dstatus']=$_REQUEST['dstatus'];
+       }
+
+       if($oldid == 22 && array_key_exists('reset',$_REQUEST) && $_REQUEST['reset']!= "")
+       {
+               $id=22;
+               $_SESSION['_config']['dorgfilterid']=0;
+               $_SESSION['_config']['dsorting']=0;
+               $_SESSION['_config']['dstatus']=0;
+       }
+
+
        if(($id == 24 || $oldid == 24 || $id == 25 || $oldid == 25 || $id == 26 || $oldid == 26 ||
                $id == 27 || $oldid == 27 || $id == 28 || $oldid == 28 || $id == 29 || $oldid == 29 ||
                $id == 30 || $oldid == 30 || $id == 31 || $oldid == 31) &&
                                                `ST`='".$_SESSION['_config']['ST']."',
                                                `C`='".$_SESSION['_config']['C']."',
                                                `comments`='".$_SESSION['_config']['comments']."'
-                                       where `id`='".$_SESSION['_config']['orgid']."'");
+                                       where `id`='".intval($_SESSION['_config']['orgid'])."'");
                        showheader(_("My CAcert.org Account!"));
                        printf(_("'%s' has just been successfully updated in the database."), sanitizeHTML($_SESSION['_config']['O']));
                        showfooter();
        {
                csrf_check('orgadmadd');
                if($_SESSION['profile']['orgadmin'] == 1)
-                       $masteracc = $_SESSION['_config'][masteracc] = intval($_REQUEST['masteracc']);
+                       $masteracc = $_SESSION['_config']['masteracc'] = intval($_REQUEST['masteracc']);
                else
-                       $masteracc = $_SESSION['_config'][masteracc] = 0;
+                       $masteracc = $_SESSION['_config']['masteracc'] = 0;
                $_REQUEST['email'] = $_SESSION['_config']['email'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['email'])));
-               $OU = $_SESSION['_config']['OU'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['OU'])));
+               $_SESSION['_config']['OU'] = stripslashes(trim($_REQUEST['OU']));
                $comments = $_SESSION['_config']['comments'] = mysql_real_escape_string(stripslashes(trim($_REQUEST['comments'])));
                $res = mysql_query("select * from `users` where `email`='".$_REQUEST['email']."' and `deleted`=0");
                if(mysql_num_rows($res) <= 0)
                                                set `memid`='".intval($row['id'])."',
                                                        `orgid`='".intval($_SESSION['_config']['orgid'])."',
                                                        `masteracc`='$masteracc',
-                                                       `OU`='$OU',
+                                                       `OU`='".mysql_real_escape_string($_SESSION['_config']['OU'])."',
                                                        `comments`='$comments'");
                        }
                }
        if(($oldid == 34 || $id == 34) && $_SESSION['profile']['orgadmin'] != 1)
        {
                $orgid = intval($_SESSION['_config']['orgid']);
-               $res = mysql_query("select * from `org` where `orgid`='$orgid' and `memid`='".$_SESSION['profile']['id']."' and `masteracc`='1'");
+               $res = mysql_query("select * from `org` where `orgid`='$orgid' and `memid`='".intval($_SESSION['profile']['id'])."' and `masteracc`='1'");
                if(mysql_num_rows($res) <= 0)
                        $id = 32;
        }
                {
                        if($key == $lang)
                        {
-                               mysql_query("update `users` set `language`='$lang' where `id`='".$_SESSION['profile']['id']."'");
+                               mysql_query("update `users` set `language`='$lang' where `id`='".intval($_SESSION['profile']['id'])."'");
                                $_SESSION['profile']['language'] = $lang;
                                showheader(_("My CAcert.org Account!"));
                                echo _("Your language setting has been updated.");
        }
 
        if($oldid == 54 || ($id == 53 && array_key_exists('action',$_REQUEST) && $_REQUEST['action'] != "") ||
-                    ($id == 54 && array_key_exists('action',$_REQUEST) && $_REQUEST['action'] != "" &&
+                       ($id == 54 && array_key_exists('action',$_REQUEST) && $_REQUEST['action'] != "" &&
                        $_REQUEST['action'] != "aliases" && $_REQUEST['action'] != "edit" && $_REQUEST['action'] != "add"))
        {
                $id = 53;
                $locid = intval(array_key_exists('locid',$_REQUEST)?$_REQUEST['locid']:0);
                $name = array_key_exists('name',$_REQUEST)?mysql_real_escape_string(strip_tags($_REQUEST['name'])):"";
                $long = array_key_exists('longitude',$_REQUEST)?ereg_replace("[^-0-9\.]","",$_REQUEST['longitude']):"";
-               $lat =  array_key_exists('latitude', $_REQUEST)?ereg_replace("[^-0-9\.]","",$_REQUEST['latitude']):"";
+               $lat = array_key_exists('latitude', $_REQUEST)?ereg_replace("[^-0-9\.]","",$_REQUEST['latitude']):"";
                $action = array_key_exists('action',$_REQUEST)?$_REQUEST['action']:"";
 
                if($locid > 0 && $action == "edit")
                $oldid=0;
        }
 
-       if($oldid == 43 && $_REQUEST['action'] == "updatedob")
+       //check if ticket number was entered
+       if ( $id == 43 || $oldid == 43 || $id == 44 || $oldid == 44 ) {
+               if ($ticketno != "" ) {
+                       $ticketno = trim($_REQUEST['ticketno']);
+                       $ticketvalidation = valid_ticket_number($ticketno);
+               }
+
+               $_SESSION['ticketno'] = $ticketno;
+       }
+
+       if($oldid == 43 && $actionrequest == "updatedob" && $ticketvalidation == TRUE)
        {
                $id = 43;
                $oldid=0;
+               $userid = intval($_REQUEST['userid']);
+               if (!write_se_log($userid, $_SESSION['profile']['id'],'SE Name/DOB Change',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $fname = mysql_real_escape_string($_REQUEST['fname']);
                $mname = mysql_real_escape_string($_REQUEST['mname']);
                $lname = mysql_real_escape_string($_REQUEST['lname']);
                $day = intval($_REQUEST['day']);
                $month = intval($_REQUEST['month']);
                $year = intval($_REQUEST['year']);
-               $userid = intval($_REQUEST['userid']);
-               $query = "select `fname`,`mname`,`lname`,`suffix`,`dob` from `users` where `id`='$userid'";
-               $details = mysql_fetch_assoc(mysql_query($query));
-               $query = "insert into `adminlog` set `when`=NOW(),`old-lname`='${details['lname']}',`old-dob`='${details['dob']}',
-                               `new-lname`='$lname',`new-dob`='$year-$month-$day',`uid`='$userid',`adminid`='".$_SESSION['profile']['id']."'";
-               mysql_query($query);
                $query = "update `users` set `fname`='$fname',`mname`='$mname',`lname`='$lname',`suffix`='$suffix',`dob`='$year-$month-$day' where `id`='$userid'";
                mysql_query($query);
+       }elseif($oldid == 43 && $actionrequest == "updatedob" && $ticketvalidation == FALSE){
+               $id = 43;
+               $oldid=0;
+               $_SESSION['ticketmsg']='No action (name/dob change) taken. Ticket number is missing!';
+       }
+
+       if($oldid == 43 && $actionrequest == 'revokecert' && $ticketvalidation == TRUE)
+       {
+               $userid = intval($_REQUEST['userid']);
+               if (!write_se_log($userid, $_SESSION['profile']['id'], 'SE Revoke all certificates',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
+               revoke_all_private_cert($userid);
+               $id=43;
+       }elseif($oldid == 43 && $actionrequest == "revokecert" && $ticketvalidation == FALSE){
+               $id = 43;
+               $oldid=0;
+               $_SESSION['ticketmsg']='No certificates revokes. Ticket number is missing!';
        }
 
        if($oldid == 48 && $_REQUEST['domain'] == "")
 
        if($id == 44)
        {
-               if($_REQUEST['userid'] != "")
-                       $_REQUEST['userid'] = intval($_REQUEST['userid']);
+               $_REQUEST['userid'] = intval($_REQUEST['userid']);
                $row = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_REQUEST['userid'])."'"));
                if($row['email'] == "")
                        $id = 42;
                        $_REQUEST['email'] = $row['email'];
        }
 
-       if($oldid == 44)
+       if($oldid == 44 && $ticketvalidation == TRUE)
        {
                showheader(_("My CAcert.org Account!"));
                if(intval($_REQUEST['userid']) <= 0)
                {
                        echo _("No such user found.");
                } else {
+                       if (!write_se_log(intval($_REQUEST['userid']), $_SESSION['profile']['id'],'SE reset password',$ticketno)) {
+                               showheader(_("Something went wrong"));
+                               echo _("Writing to the admin log failed. Can't continue.");
+                               showfooter();
+                               exit;
+                       }
                        mysql_query("update `users` set `password`=sha1('".mysql_real_escape_string(stripslashes($_REQUEST['newpass']))."') where `id`='".intval($_REQUEST['userid'])."'");
                        $row = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_REQUEST['userid'])."'"));
                        printf(_("The password for %s has been updated successfully in the system."), sanitizeHTML($row['email']));
 
-
+               $my_translation = L10n::get_translation();
+               L10n::set_recipient_language(intval($_REQUEST['userid']));
                        $body  = sprintf(_("Hi %s,"),$row['fname'])."\n\n";
                        $body .= _("You are receiving this email because a CAcert administrator ".
                                        "has changed the password on your account.")."\n\n";
 
                        sendmail($row['email'], "[CAcert.org] "._("Password Update Notification"), $body,
                                                "support@cacert.org", "", "", "CAcert Support");
-
+               L10n::set_translation($my_translation);
                }
+
                showfooter();
                exit;
+       }elseif($oldid == 44 && $ticketvalidation == FALSE){
+               $_SESSION['ticketmsg']='No password reset taken. Ticket number is missing!';
        }
 
+
        if($process != "" && $oldid == 45)
        {
                $CSR = clean_csr($CSR);
                $_SESSION['_config']['CSR'] = $CSR;
-               $_SESSION['_config']['subject'] = trim(`echo "$CSR"|/usr/bin/openssl req -text -noout|tr -d "\\0"|grep "Subject:"`);
-               $bits = explode(",", trim(`echo "$CSR"|/usr/bin/openssl req -text -noout|tr -d "\\0"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:`));
+               runCommand("/usr/bin/openssl req -text -noout|tr -d \"\\0\"|grep \"Subject:\"", $CSR, $CSRSubjects);
+               runCommand("/usr/bin/openssl req -text -noout|tr -d \"\\0\"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:", $CSR, $CSRAlts);
+               $_SESSION['_config']['subject'] = trim($CSRSubjects);
+               $bits = explode(",", trim($CSRAlts));
                foreach($bits as $val)
                {
                        $_SESSION['_config']['subject'] .= "/subjectAltName=".trim($val);
        if($process != "" && $oldid == 46)
        {
                $CSR = clean_csr($_SESSION['_config']['CSR']);
-               $_SESSION['_config']['subject'] = trim(`echo "$CSR"|/usr/bin/openssl req -text -noout|tr -d "\\0"|grep "Subject:"`);
-               $bits = explode(",", trim(`echo "$CSR"|/usr/bin/openssl req -text -noout|tr -d "\\0"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:`));
+               runCommand("/usr/bin/openssl req -text -noout|tr -d \"\\0\"|grep \"Subject:\"", $CSR, $CSRSubjects);
+               runCommand("/usr/bin/openssl req -text -noout|tr -d \"\\0\"|grep -A1 'X509v3 Subject Alternative Name:'|grep DNS:", $CSR, $CSRAlts);
+
+               $_SESSION['_config']['subject'] = trim($CSRSubjects);
+               $bits = explode(",", trim($CSRAlts));
                foreach($bits as $val)
                {
                        $_SESSION['_config']['subject'] .= "/subjectAltName=".trim($val);
                $CSRid = mysql_insert_id();
 
                foreach($_SESSION['_config']['rowid'] as $dom)
-                       mysql_query("insert into `domlink` set `certid`='$CSRid', `domid`='$dom'");
+                       mysql_query("insert into `domlink` set `certid`='$CSRid', `domid`='".intval($dom)."'");
                if(is_array($_SESSION['_config']['altid']))
                foreach($_SESSION['_config']['altid'] as $dom)
-                       mysql_query("insert into `domlink` set `certid`='$CSRid', `domid`='$dom'");
+                       mysql_query("insert into `domlink` set `certid`='$CSRid', `domid`='".intval($dom)."'");
 
                $CSRname=generatecertpath("csr","server",$CSRid);
                $fp = fopen($CSRname, "w");
                }
        }
 
-       if($id == 43 && array_key_exists('tverify',$_REQUEST) && $_REQUEST['tverify'] > 0)
+       /* presently not needed
+       if($id == 43 && array_key_exists('tverify',$_REQUEST) && $_REQUEST['tverify'] > 0 && $ticketvalidation==TRUE)
        {
                $memid = $_REQUEST['userid'] = intval($_REQUEST['tverify']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change tverify status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `users` where `id`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = !$row['tverify'];
                mysql_query("update `users` set `tverify`='$ver' where `id`='$memid'");
+       }elseif($id == 43 && array_key_exists('tverify',$_REQUEST) && $_REQUEST['tverify'] > 0 && $ticketvalidation==FALSE){
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
+       */
 
-  if($id == 43 && array_key_exists('assurer',$_REQUEST) && $_REQUEST['assurer'] > 0)
-  {
-    csrf_check('admsetassuret');
-    $memid = $_REQUEST['userid'] = intval($_REQUEST['assurer']);
-    $query = "select * from `users` where `id`='$memid'";
-    $row = mysql_fetch_assoc(mysql_query($query));
-    $ver = !$row['assurer'];
-    mysql_query("update `users` set `assurer`='$ver' where `id`='$memid'");
-  }
+       if($id == 43 && array_key_exists('assurer',$_REQUEST) && $_REQUEST['assurer'] > 0 && $ticketvalidation == TRUE)
+       {
+               csrf_check('admsetassuret');
+               $memid = $_REQUEST['userid'] = intval($_REQUEST['assurer']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change assurer status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
+               $query = "select * from `users` where `id`='$memid'";
+               $row = mysql_fetch_assoc(mysql_query($query));
+               $ver = !$row['assurer'];
+               mysql_query("update `users` set `assurer`='$ver' where `id`='$memid'");
+       }elseif($id == 43 && array_key_exists('assurer',$_REQUEST) && $_REQUEST['assurer'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['assurer']);
+               $_SESSION['ticketmsg']='No action (Change assurer status) taken. Ticket number is missing!';
+       }
 
-  if($id == 43 && array_key_exists('assurer_blocked',$_REQUEST) && $_REQUEST['assurer_blocked'] > 0)
-  {
-    $memid = $_REQUEST['userid'] = intval($_REQUEST['assurer_blocked']);
-    $query = "select * from `users` where `id`='$memid'";
-    $row = mysql_fetch_assoc(mysql_query($query));
-    $ver = !$row['assurer_blocked'];
-    mysql_query("update `users` set `assurer_blocked`='$ver' where `id`='$memid'");
-  }
+       if($id == 43 && array_key_exists('assurer_blocked',$_REQUEST) && $_REQUEST['assurer_blocked'] > 0 && $ticketvalidation == TRUE)
+       {
+               $memid = $_REQUEST['userid'] = intval($_REQUEST['assurer_blocked']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change assurer blocked status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
+               $query = "select * from `users` where `id`='$memid'";
+               $row = mysql_fetch_assoc(mysql_query($query));
+               $ver = !$row['assurer_blocked'];
+               mysql_query("update `users` set `assurer_blocked`='$ver' where `id`='$memid'");
+       }elseif($id == 43 && array_key_exists('assurer_blocked',$_REQUEST) && $_REQUEST['assurer_blocked'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['assurer_blocked']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
+       }
 
-       if($id == 43 && array_key_exists('locked',$_REQUEST) && $_REQUEST['locked'] > 0)
+       if($id == 43 && array_key_exists('locked',$_REQUEST) && $_REQUEST['locked'] > 0 && $ticketvalidation == TRUE)
        {
                csrf_check('admactlock');
                $memid = $_REQUEST['userid'] = intval($_REQUEST['locked']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change locked status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `users` where `id`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = !$row['locked'];
                mysql_query("update `users` set `locked`='$ver' where `id`='$memid'");
+       }elseif($id == 43 && array_key_exists('locked',$_REQUEST) && $_REQUEST['locked'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['locked']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
 
-       if($id == 43 && array_key_exists('codesign',$_REQUEST) && $_REQUEST['codesign'] > 0)
+       if($id == 43 && array_key_exists('codesign',$_REQUEST) && $_REQUEST['codesign'] > 0 && $ticketvalidation == TRUE)
        {
                csrf_check('admcodesign');
                $memid = $_REQUEST['userid'] = intval($_REQUEST['codesign']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change codesign status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `users` where `id`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = !$row['codesign'];
                mysql_query("update `users` set `codesign`='$ver' where `id`='$memid'");
+       }elseif($id == 43 && array_key_exists('codesign',$_REQUEST) && $_REQUEST['codesign'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['codesign']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
 
-       if($id == 43 && array_key_exists('orgadmin',$_REQUEST) && $_REQUEST['orgadmin'] > 0)
+       if($id == 43 && array_key_exists('orgadmin',$_REQUEST) && $_REQUEST['orgadmin'] > 0 && $ticketvalidation == TRUE)
        {
                csrf_check('admorgadmin');
                $memid = $_REQUEST['userid'] = intval($_REQUEST['orgadmin']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change org assuer status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `users` where `id`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = !$row['orgadmin'];
                mysql_query("update `users` set `orgadmin`='$ver' where `id`='$memid'");
+       }elseif($id == 43 && array_key_exists('orgadmin',$_REQUEST) && $_REQUEST['orgadmin'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['orgadmin']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
 
-       if($id == 43 && array_key_exists('ttpadmin',$_REQUEST) && $_REQUEST['ttpadmin'] > 0)
+       if($id == 43 && array_key_exists('ttpadmin',$_REQUEST) && $_REQUEST['ttpadmin'] > 0 && $ticketvalidation == TRUE)
        {
                csrf_check('admttpadmin');
                $memid = $_REQUEST['userid'] = intval($_REQUEST['ttpadmin']);
+               if(!write_se_log($memid, $_SESSION['profile']['id'],'SE Change ttp admin status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `users` where `id`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = !$row['ttpadmin'];
                mysql_query("update `users` set `ttpadmin`='$ver' where `id`='$memid'");
+       }elseif($id == 43 && array_key_exists('ttpadmin',$_REQUEST) && $_REQUEST['ttpadmin'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['ttpadmin']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
 
-       if($id == 43 && array_key_exists('adadmin',$_REQUEST) && $_REQUEST['adadmin'] > 0)
+       if($id == 43 && array_key_exists('adadmin',$_REQUEST) && $_REQUEST['adadmin'] > 0 && $ticketvalidation == TRUE)
        {
                $memid = $_REQUEST['userid'] = intval($_REQUEST['adadmin']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change advertising admin status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `users` where `id`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = $row['adadmin'] + 1;
                if($ver > 2)
                        $ver = 0;
                mysql_query("update `users` set `adadmin`='$ver' where `id`='$memid'");
+       }elseif($id == 43 && array_key_exists('adadmin',$_REQUEST) && $_REQUEST['adadmin'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['adadmin']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
 
-       if($id == 43 && array_key_exists('locadmin',$_REQUEST) && $_REQUEST['locadmin'] > 0)
+       if($id == 43 && array_key_exists('locadmin',$_REQUEST) && $_REQUEST['locadmin'] > 0 && $ticketvalidation == TRUE)
        {
                $memid = $_REQUEST['userid'] = intval($_REQUEST['locadmin']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change location admin status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `users` where `id`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = !$row['locadmin'];
                mysql_query("update `users` set `locadmin`='$ver' where `id`='$memid'");
+       }elseif($id == 43 && array_key_exists('locadmin',$_REQUEST) && $_REQUEST['locadmin'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['locadmin']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
 
-       if($id == 43 && array_key_exists('admin',$_REQUEST) && $_REQUEST['admin'] > 0)
+       if($id == 43 && array_key_exists('admin',$_REQUEST) && $_REQUEST['admin'] > 0 && $ticketvalidation == TRUE)
        {
                csrf_check('admsetadmin');
                $memid = $_REQUEST['userid'] = intval($_REQUEST['admin']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change SE status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `users` where `id`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = !$row['admin'];
                mysql_query("update `users` set `admin`='$ver' where `id`='$memid'");
+       }elseif($id == 43 && array_key_exists('admin',$_REQUEST) && $_REQUEST['admin'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['admin']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
 
-       if($id == 43 && array_key_exists('general',$_REQUEST) && $_REQUEST['general'] > 0)
+       if($id == 43 && array_key_exists('general',$_REQUEST) && $_REQUEST['general'] > 0 && $ticketvalidation == TRUE)
        {
                $memid = $_REQUEST['userid'] = intval($_REQUEST['general']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change general status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `alerts` where `memid`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = !$row['general'];
                mysql_query("update `alerts` set `general`='$ver' where `memid`='$memid'");
+       }elseif($id == 43 && array_key_exists('general',$_REQUEST) && $_REQUEST['general'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['general']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
 
-       if($id == 43 && array_key_exists('country',$_REQUEST) && $_REQUEST['country'] > 0)
+       if($id == 43 && array_key_exists('country',$_REQUEST) && $_REQUEST['country'] > 0 && $ticketvalidation == TRUE)
        {
                $memid = $_REQUEST['userid'] = intval($_REQUEST['country']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change country status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `alerts` where `memid`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = !$row['country'];
                mysql_query("update `alerts` set `country`='$ver' where `memid`='$memid'");
+       }elseif($id == 43 && array_key_exists('country',$_REQUEST) && $_REQUEST['country'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['country']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
 
-       if($id == 43 && array_key_exists('regional',$_REQUEST) && $_REQUEST['regional'] > 0)
+       if($id == 43 && array_key_exists('regional',$_REQUEST) && $_REQUEST['regional'] > 0 && $ticketvalidation == TRUE)
        {
                $memid = $_REQUEST['userid'] = intval($_REQUEST['regional']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change regional status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `alerts` where `memid`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = !$row['regional'];
                mysql_query("update `alerts` set `regional`='$ver' where `memid`='$memid'");
+       }elseif($id == 43 && array_key_exists('regional',$_REQUEST) && $_REQUEST['regional'] > 0 && $ticketvalidation == FALSE){
+               $_REQUEST['userid'] = intval($_REQUEST['regional']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
 
-       if($id == 43 && array_key_exists('radius',$_REQUEST) && $_REQUEST['radius'] > 0)
+       if($id == 43 && array_key_exists('radius',$_REQUEST) && $_REQUEST['radius'] > 0 && $ticketvalidation == TRUE)
        {
                $memid = $_REQUEST['userid'] = intval($_REQUEST['radius']);
+               if (!write_se_log($memid, $_SESSION['profile']['id'],'SE Change radius status',$ticketno)) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       showfooter();
+                       exit;
+               }
                $query = "select * from `alerts` where `memid`='$memid'";
                $row = mysql_fetch_assoc(mysql_query($query));
                $ver = !$row['radius'];
                mysql_query("update `alerts` set `radius`='$ver' where `memid`='$memid'");
+       }elseif($id == 43 && array_key_exists('radius',$_REQUEST) && $_REQUEST['radius'] > 0 && $ticketvalidation == false){
+               $_REQUEST['userid'] = intval($_REQUEST['radius']);
+               $_SESSION['ticketmsg']='No action taken. Ticket number is missing!';
        }
 
        if($id == 50)
        {
-               if(array_key_exists('userid',$_REQUEST) && $_REQUEST['userid'] != "")
+               if(array_key_exists('userid',$_REQUEST) && $_REQUEST['userid'] !== "") {
                        $_REQUEST['userid'] = intval($_REQUEST['userid']);
+               }
 
                $row = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($_REQUEST['userid'])."'"));
-               if($row['email'] == "")
+               if($row['email'] == "") {
                        $id = 42;
-               else
+               } else {
                        $_REQUEST['email'] = $row['email'];
+               }
        }
 
        if($oldid == 50)
        if($oldid == 50 && $process != "")
        {
                $_REQUEST['userid'] = intval($_REQUEST['userid']);
-               $res = mysql_query("select * from `users` where `id`='".intval($_REQUEST['userid'])."'");
-               if(mysql_num_rows($res) > 0)
-               {
-                       $query = "update `domaincerts`,`domains` SET `domaincerts`.`revoked`='1970-01-01 10:00:01'
-                                       WHERE `domaincerts`.`domid` = `domains`.`id` AND `domains`.`memid`='".intval($_REQUEST['userid'])."'";
-                       mysql_query($query);
-                       $query = "update `domains` SET `deleted`=NOW() WHERE `domains`.`memid`='".intval($_REQUEST['userid'])."'";
-                       mysql_query($query);
-                       $query = "update `emailcerts` SET `revoked`='1970-01-01 10:00:01' WHERE `memid`='".intval($_REQUEST['userid'])."'";
-                       mysql_query($query);
-                       $query = "update `email` SET `deleted`=NOW() WHERE `memid`='".intval($_REQUEST['userid'])."'";
-                       mysql_query($query);
-                       $query = "delete from `org` WHERE `memid`='".intval($_REQUEST['userid'])."'";
-                       mysql_query($query);
-                       $query = "update `users` SET `deleted`=NOW() WHERE `id`='".intval($_REQUEST['userid'])."'";
-                       mysql_query($query);
+               if (trim($_REQUEST['arbitrationno'])==""){
+                       showheader(_("My CAcert.org Account!"));
+                       echo _("You did not enter an arbitration number entry.");
+                       printf('<br/><a href="account.php?id=43&amp;userid=' . intval($_REQUEST['userid']) . '">' . _('Back to previous page.') .'</a>');
+                       showfooter();
+                       exit;
                }
-       }
-
-       if(($id == 51 || $id == 52 || $oldid == 52) && $_SESSION['profile']['tverify'] <= 0)
-       {
-               showheader(_("My CAcert.org Account!"));
-               echo _("You don't have access to this area.");
-               showfooter();
-               exit;
-       }
-
-       if($oldid == 52)
-       {
-               $uid = intval($_REQUEST['uid']);
-               $query = "select * from `tverify` where `id`='$uid' and `modified`=0";
-               $rc = mysql_num_rows(mysql_query($query));
-               if($rc <= 0)
-               {
+               if ( 1 !== preg_match('/^[a-z]\d{8}\.\d+\.\d+$/i',trim($_REQUEST['arbitrationno'])) ) {
                        showheader(_("My CAcert.org Account!"));
-                       echo _("Unable to find a valid tverify request for this ID.");
+                       printf(_("'%s' is not a valid arbitration number entry."), sanitizeHTML(trim($_REQUEST['arbitrationno'])));
+                       printf('<br/><a href="account.php?id=43&amp;userid=' . intval($_REQUEST['userid']) . '">' . _('Back to previous page.') .'</a>');
                        showfooter();
                        exit;
                }
-       }
-
-       if($oldid == 52)
-       {
-               $query = "select * from `tverify-vote` where `tverify`='$uid' and `memid`='".$_SESSION['profile']['id']."'";
-               $rc = mysql_num_rows(mysql_query($query));
-               if($rc > 0)
-               {
+               if (check_email_exists(trim($_REQUEST['arbitrationno']).'@cacert.org')) {
                        showheader(_("My CAcert.org Account!"));
-                       echo _("You have already voted on this request.");
+                       printf(_("The email address '%s' is already in a different account. Can't continue."), sanitizeHTML($_REQUEST['arbitrationno'].'@cacert.org'));
+                       printf('<br/><a href="account.php?id=43&amp;userid=' . intval($_REQUEST['userid']) . '">' . _('Back to previous page.') .'</a>');
                        showfooter();
                        exit;
                }
-       }
-
-       if($oldid == 52 && ($_REQUEST['agree'] != "" || $_REQUEST['disagree'] != ""))
-       {
-               $vote = -1;
-               if($_REQUEST['agree'] != "")
-                       $vote = 1;
-
-               $query = "insert into `tverify-vote` set
-                               `tverify`='$uid',
-                               `memid`='".$_SESSION['profile']['id']."',
-                               `when`=NOW(), `vote`='$vote',
-                               `comment`='".mysql_real_escape_string($_REQUEST['comment'])."'";
-               mysql_query($query);
-
-               $rc = mysql_num_rows(mysql_query("select * from `tverify-vote` where `tverify`='$uid' and `vote`='1'"));
-               if($rc >= 8)
-               {
-                       mysql_query("update `tverify` set `modified`=NOW() where `id`='$uid'");
-                       $tverify = mysql_fetch_assoc(mysql_query("select * from `tverify` where `id`='$uid'"));
-                       $memid = $tverify['memid'];
-                       $user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='$memid'"));
-                       $tmp = mysql_fetch_assoc(mysql_query("select sum(`points`) as `points` from `notary` where `to`='$memid'"));
-
-                       $points = 0;
-                       if($tverify['URL'] != "" && $tverify['photoid'] != "")
-                               $points = 150 - intval($tmp['points']);
-                       if($tverify['URL'] != "" && $tverify['photoid'] == "")
-                               $points = 90 - intval($tmp['points']);
-                       if($tverify['URL'] == "" && $tverify['photoid'] == "")
-                               $points = 50 - intval($tmp['points']);
-
-                       if($points < 0)
-                               $points = 0;
-
-                       if($points > 0)
-                       {
-                               mysql_query("insert into `notary` set `from`='0', `to`='$memid', `points`='$points',
-                                               `method`='Thawte Points Transfer', `when`=NOW()");
-                               fix_assurer_flag($memid);
-                       }
-                       $totalpoints = intval($tmp['points']) + $points;
-
-                       $body  = _("Your request to have points transfered was successful. You were issued $points points as a result, and you now have $totalpoints in total")."\n\n"._("The following comments were made by reviewers")."\n\n";
-                       $res = mysql_query("select * from `tverify-vote` where `tverify`='$uid' and `vote`='1'");
-                       while($row = mysql_fetch_assoc($res))
-                               $body .= $row['comment']."\n";
-                       $body .= "\n";
-
-                       $body .= _("Best regards")."\n";
-                       $body .= _("CAcert Support Team");
-                       sendmail($user['email'], "[CAcert.org] Thawte Notary Points Transfer", $body, "website-form@cacert.org", "support@cacert.org", "", "CAcert Tverify");
+               if (check_client_cert_running(intval($_REQUEST['userid']),1) ||
+                       check_server_cert_running(intval($_REQUEST['userid']),1) ||
+                       check_gpg_cert_running(intval($_REQUEST['userid']),1)) {
+                       showheader(_("My CAcert.org Account!"));
+                       printf(_("The CCA retention time for at least one certificate is not over. Can't continue."));
+                       printf('<br/><a href="account.php?id=43&amp;userid=' . intval($_REQUEST['userid']) . '">' . _('Back to previous page.') .'</a>');
+                       showfooter();
+                       exit;
                }
-
-               $rc = mysql_num_rows(mysql_query("select * from `tverify-vote` where `tverify`='$uid' and `vote`='-1'"));
-               if($rc >= 4)
-               {
-                       mysql_query("update `tverify` set `modified`=NOW() where `id`='$uid'");
-                       $tverify = mysql_fetch_assoc(mysql_query("select * from `tverify` where `id`='$uid'"));
-                       $memid = $tverify['memid'];
-                       $user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='$memid'"));
-
-                       $body  = _("Unfortunately your request for a points increase has been denied, below is the comments from people that reviewed your request as to why they rejected your application.")."\n\n";
-                       $res = mysql_query("select * from `tverify-vote` where `tverify`='$uid' and `vote`='-1'");
-                       while($row = mysql_fetch_assoc($res))
-                               $body .= $row['comment']."\n";
-                       $body .= "\n";
-
-                       $body .= _("You are welcome to try submitting another request at any time in the future, please make sure you take the reviewer comments into consideration or you risk having your application rejected again.")."\n\n";
-
-                       $body .= _("Best regards")."\n";
-                       $body .= _("CAcert Support Team");
-                       sendmail($user['email'], "[CAcert.org] Thawte Notary Points Transfer", $body, "website-form@cacert.org", "support@cacert.org", "", "CAcert Tverify");
+               if (check_is_orgadmin(intval($_REQUEST['userid']),1)) {
+                       showheader(_("My CAcert.org Account!"));
+                       printf(_("The user is listed as Organisation Administrator. Can't continue."));
+                       printf('<br/><a href="account.php?id=43&amp;userid=' . intval($_REQUEST['userid']) . '">' . _('Back to previous page.') .'</a>');
+                       showfooter();
+                       exit;
                }
+               if (!write_se_log(intval($_REQUEST['userid']), $_SESSION['profile']['id'], 'SE Account delete', trim($_REQUEST['arbitrationno']))) {
+                       showheader(_("Something went wrong"));
+                       echo _("Writing to the admin log failed. Can't continue.");
+                       printf('<br/><a href="account.php?id=43&amp;userid=' . intval($_REQUEST['userid']) . '">' . _('Back to previous page.') .'</a>');
+                       showfooter();
+                       exit;
+               }
+               account_delete(intval($_REQUEST['userid']), trim($_REQUEST['arbitrationno']), $_SESSION['profile']['id']);
+       }
 
+       if(($id == 51 || $id == 52 || $oldid == 52))
+       {
                showheader(_("My CAcert.org Account!"));
-               echo _("Your vote has been accepted.");
+               echo _("You don't have access to this area.\nThe Tverify programme is terminated as of 16th November 2010" );
                showfooter();
                exit;
        }
 
+       if($id == 59){
+               if (!($oldid == 43 && $_SESSION['profile']['admin'] == 1) &&
+                   !($oldid == 13 && intval($_REQUEST['userid']) == $_SESSION['profile']['id']))
+               {
+                       showheader(_("My CAcert.org Account!"));
+                       echo _("You do not have access to this page.");
+                       showfooter();
+                       exit;
+               }
+       }
+
+
        if(intval($cert) > 0)
                $_SESSION['_config']['cert'] = intval($cert);
        if(intval($orgid) > 0)
index b9544e0..0fda2f1 100644 (file)
@@ -22,6 +22,7 @@
        function showheader($title = "CAcert.org", $title2 = "")
        {
                global $id, $PHP_SELF;
+       $PHP_SELF = &$_SERVER['PHP_SELF'];
        $expand="";
        $tmpid = $id;
        if($PHP_SELF == "/wot.php")
 
        switch($tmpid)
        {
-               case 1:
-               case 2: $expand = " explode('emailacc');"; break;
-               case 3:
-               case 4:
-               case 5:
-               case 6: $expand = " explode('clicerts');"; break;
-               case 7:
-               case 8:
-               case 9: $expand = " explode('domains');"; break;
-               case 10:
-               case 11:
-               case 12:
-               case 15: $expand = " explode('servercert');"; break;
-               case 13:
-               case 14:
-               case 36:
-               case 41:
+               case 1:                                                 // Add email address
+               case 2: $expand = " explode('emailacc');"; break;       // View email addresses
+               case 3:                                                 // Add Client certificate
+               case 4:                                                 // Confirm Client Certificate Request
+               case 5:                                                 // View Client Certificates
+               case 6: $expand = " explode('clicerts');"; break;       // Client Certificate page
+               case 7:                                                 // Add new domain
+               case 8:                                                 // Confirm Domain page
+               case 9: $expand = " explode('domains');"; break;        // View Domains
+               case 10:                                                // Add Server Certifiacte
+               case 11:                                                // Confirm Server Certificate Rewust
+               case 12:                                                // View Server Cerificate
+               case 15: $expand = " explode('servercert');"; break;    // Server Certificate page
+               case 13:                                                // ViewEdit
+               case 14:                                                // Change password
+               case 36:                                                // My Alert settings
+               case 41:                                                // Language Settings
+               case 55:                                                // Trainings
+               case 59:                                                // Account History
                case 507:
-               case 508:
-               case 513: $expand = " explode('mydetails');"; break;
-               case 16:
-               case 17:
-               case 18:
-               case 19: $expand = " explode('clientorg');"; break;
-               case 20:
-               case 21:
-               case 22:
-               case 23: $expand = " explode('serverorg');"; break;
-               case 24:
-               case 25:
-               case 26:
-               case 27:
-               case 28:
-               case 29:
-               case 30:
+               case 508:                                               // My Listing
+               case 510:                                               // Old points calculation
+               case 515:                                               // New points calculation
+               case 513: $expand = " explode('mydetails');"; break;    // My Location
+               case 16:                                                // Add Org Client Cert
+               case 17:                                                // Confirm Org Client Certificate Request
+               case 18:                                                // View Org Client Certificate
+               case 19: $expand = " explode('clientorg');"; break;     // Org Cleint Cert page
+               case 20:                                                // Add Org Server Cert
+               case 21:                                                // Conform Org Server Cert Request
+               case 22:                                                // View Org Server Certs
+               case 23: $expand = " explode('serverorg');"; break;     // Org Server Certificate page
+               case 24:                                                // Add new Organisation
+               case 25:                                                // View Organisation List
+               case 26:                                                // View Organisation Domains
+               case 27:                                                // Edit Org Account
+               case 28:                                                // View Add Org Domain
+               case 29:                                                // Edit Org Domain
+               case 30:                                                // Delete Org Domain
                case 31:
-               case 32:
-               case 33:
-               case 34:
-               case 35: $expand = " explode('orgadmin');"; break;
+               case 32:                                                // View Org Admin
+               case 33:                                                // Add Org Admin
+               case 34:                                                // Delete Org Admin
+               case 60:                                                // View Organisation Account History
+               case 35: $expand = " explode('orgadmin');"; break;      // View Org Admin Organisation List
                case 42:
                case 43:
                case 44:
                case 50:
                case 54:
                case 53: $expand = " explode('sysadmin');"; break;
-               case 500:
+               case 500:                                               // CAcert Web of Trust
                case 501:
-               case 502:
-               case 503:
-               case 504:
-               case 505:
+               case 502:                                               // Become an Assurer
+               case 503:                                               // CAcert Web of Trust Roles
+               case 504:                                               // TTP
+               case 505:                                               // Assurer Some one
                case 506:
                case 509:
-               case 510:
                case 511:
-               case 512: $expand = " explode('WoT');"; break;
+               case 512: $expand = " explode('WoT');"; break;          // Find Assurer
                case 1000:
                case 1001:
-               case 1002:
+               case 1002:                                              // View GPG key
                case 1003:
                case 1004:
                case 1005:
                case 1008:
                case 1009:
                case 1010: $expand = " explode('gpg');"; break;
-               case 1500:
-               case 1501:
-               case 1502:
+               case 1500:                                              // Dipute
+               case 1501:                                              // Dispute Email Request
+               case 1502:                                              // ViewEdit
                case 1503:
                case 1504:
                case 1505:
@@ -172,9 +177,11 @@ function hideall() {
     </div>
     <div class="relatedLinks">
       <h3 class="pointer" onclick="explode('mydetails')">+ <?=_("My Details")?></h3>
-      <ul class="menu" id="mydetails"><li><a href="account.php?id=13"><?=_("Edit")?></a></li><li><a href="account.php?id=14"><?=_("Change Password")?></a></li><li><a href="account.php?id=41"><?=_("Default Language")?></a></li><li><a href="wot.php?id=8"><?=_("My Listing")?></a></li><li><a href="wot.php?id=13"><?=_("My Location")?></a></li><li><a href="account.php?id=36"><?=_("My Alert Settings")?></a></li><li><a href="wot.php?id=10"><?=_("My Points")?></a></li><?
+      <ul class="menu" id="mydetails"><li><a href="account.php?id=13"><?=_("View/Edit")?></a></li><li><a href="account.php?id=14"><?=_("Change Password")?></a></li><li><a href="account.php?id=41"><?=_("Default Language")?></a></li><li><a href="wot.php?id=8"><?=_("My Listing")?></a></li><li><a href="wot.php?id=13"><?=_("My Location")?></a></li><li><a href="account.php?id=36"><?=_("My Alert Settings")?></a></li><li><a href="account.php?id=55"><?=_("My Trainings")?></a></li><li><a href="wot.php?id=10"><?=_("My Points")?></a></li><?
+/* to delete
        if($_SESSION['profile']['id'] == 1 || $_SESSION['profile']['id'] == 5897)
                echo "<li><a href='sqldump.php'>SQL Dump</a></li>";
+*/
        ?></ul>
     </div>
     <div class="relatedLinks">
@@ -217,7 +224,7 @@ function hideall() {
 <? } ?>
     <div class="relatedLinks">
       <h3 class="pointer" onclick="explode('WoT')">+ <?=_("CAcert Web of Trust")?></h3>
-      <ul class="menu" id="WoT"><li><a href="wot.php?id=0"><?=_("About")?></a></li><li><a href="wot.php?id=12"><?=_("Find an Assurer")?></a></li><li><a href="wot.php?id=3"><?=_("Rules")?></a></li><li><? if($_SESSION['profile']['assurer'] != 1) { ?><a href="wot.php?id=2"><?=_("Becoming an Assurer")?></a><? } else { ?><a href="wot.php?id=5"><?=_("Assure Someone")?></a><? } ?></li><li><a href="wot.php?id=4"><?=_("Trusted ThirdParties")?></a></li><? if($_SESSION['profile']['points'] >= 500) { ?><li><a href="wot.php?id=11"><div style="white-space:nowrap"><?=_("Organisation Assurance")?></div></a></li><? } ?><li><a href="account.php?id=55"><?=_("Training")?></a></li></ul>
+      <ul class="menu" id="WoT"><li><a href="wot.php?id=0"><?=_("About")?></a></li><li><a href="wot.php?id=12"><?=_("Find an Assurer")?></a></li><li><a href="wot.php?id=3"><?=_("Rules")?></a></li><li><? if($_SESSION['profile']['assurer'] != 1) { ?><a href="wot.php?id=2"><?=_("Becoming an Assurer")?></a><? } else { ?><a href="wot.php?id=5"><?=_("Assure Someone")?></a><? } ?></li><li><a href="wot.php?id=4"><?=_("Trusted ThirdParties")?></a></li><? if($_SESSION['profile']['points'] >= 500) { ?><li><a href="wot.php?id=11"><div style="white-space:nowrap"><?=_("Organisation Assurance")?></div></a></li><? } ?></ul>
     </div>
     <div class="relatedLinks">
       <h3 class="pointer" onclick="explode('WoTForms')">+ <?=_("CAP Forms")?></h3><?
@@ -281,7 +288,7 @@ function hideall() {
   <div id="siteInfo"><a href="//wiki.cacert.org/FAQ/AboutUs"><?=_("About Us")?></a> | <a href="account.php?id=38"><?=_("Donations")?></a> | <a href="http://wiki.cacert.org/wiki/CAcertIncorporated"><?=_("Association Membership")?></a> |
        <a href="/policy/PrivacyPolicy.html"><?=_("Privacy Policy")?></a> | <a href="account.php?id=40"><?=_("Contact Us")?></a>
                | &copy;2002-<?=date("Y")?> <?=_("by CAcert")?></div>
-</div>  
-</body>             
+</div>
+</body>
 </html><?
        }
index bcbe38d..17b449b 100644 (file)
        session_name("cacert");
        session_start();
 
-       session_register("_config");
-       session_register("profile");
-       session_register("signup");
-       session_register("lostpw");
+//     session_register("_config");
+//     session_register("profile");
+//     session_register("signup");
+//     session_register("lostpw");
 //     if($_SESSION['profile']['id'] > 0)
 //             session_regenerate_id();
 
@@ -57,7 +57,7 @@
                exit;
        }
 
-       if(array_key_exists('HTTP_HOST',$_SERVER) && 
+       if(array_key_exists('HTTP_HOST',$_SERVER) &&
                        ($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] ||
                        $_SERVER['HTTP_HOST'] == $_SESSION['_config']['tverify']))
        {
        L10n::detect_language();
        L10n::init_gettext();
 
-        if(array_key_exists('profile',$_SESSION) && is_array($_SESSION['profile']) && array_key_exists('id',$_SESSION['profile']) && $_SESSION['profile']['id'] > 0)
+       if(array_key_exists('profile',$_SESSION) && is_array($_SESSION['profile']) && array_key_exists('id',$_SESSION['profile']) && $_SESSION['profile']['id'] > 0)
        {
-               $locked = mysql_fetch_assoc(mysql_query("select `locked` from `users` where `id`='".$_SESSION['profile']['id']."'"));
+               $locked = mysql_fetch_assoc(mysql_query("select `locked` from `users` where `id`='".intval($_SESSION['profile']['id'])."'"));
                if($locked['locked'] == 0)
                {
-                       $query = "select sum(`points`) as `total` from `notary` where `to`='".$_SESSION['profile']['id']."' group by `to`";
+                       $query = "select sum(`points`) as `total` from `notary` where `to`='".intval($_SESSION['profile']['id'])."' and `deleted` = 0 group by `to`";
                        $res = mysql_query($query);
                        $row = mysql_fetch_assoc($res);
                        $_SESSION['profile']['points'] = $row['total'];
                        $points++;
 
                //echo "Points due to length and charset: $points<br/>";
-               
+
                // check for historical password proposal
                if ($pwd === "Fr3d Sm|7h") {
                        return 0;
                }
-               
+
                return $points;
        }
 
        function checkpw($pwd, $email, $fname, $mname, $lname, $suffix)
        {
                $points = checkpwlight($pwd);
-               
+
                if(@strstr(strtolower($pwd), strtolower($email)))
                        $points--;
 
                //echo "Points due to name matches: $points<br/>";
 
                $shellpwd = escapeshellarg($pwd);
-               $do = `grep $shellpwd /usr/share/dict/american-english`;
+               $do = shell_exec("grep -F -- $shellpwd /usr/share/dict/american-english");
                if($do)
                        $points--;
 
        {
                $bits = explode(": ", $_SESSION['_config']['subject'], 2);
                $bits = str_replace(", ", "|", str_replace("/", "|", array_key_exists('1',$bits)?$bits['1']:""));
-               $bits = explode("|", $bits);    
+               $bits = explode("|", $bits);
 
                $_SESSION['_config']['cnc'] = $_SESSION['_config']['subaltc'] = 0;
                $_SESSION['_config']['OU'] = "";
                                        $dom = $bits[$i];
                                $_SESSION['_config']['row'] = "";
                                $dom = mysql_real_escape_string($dom);
-                               $query = "select * from domains where `memid`='".$_SESSION['profile']['id']."' and `domain` like '$dom' and `deleted`=0 and `hash`=''";
+                               $query = "select * from domains where `memid`='".intval($_SESSION['profile']['id'])."' and `domain` like '$dom' and `deleted`=0 and `hash`=''";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) > 0)
                                {
                                        $dom = $bits[$i];
                                $_SESSION['_config']['altrow'] = "";
                                $dom = mysql_real_escape_string($dom);
-                               $query = "select * from domains where `memid`='".$_SESSION['profile']['id']."' and `domain` like '$dom' and `deleted`=0 and `hash`=''";
+                               $query = "select * from domains where `memid`='".intval($_SESSION['profile']['id'])."' and `domain` like '$dom' and `deleted`=0 and `hash`=''";
                                $res = mysql_query($query);
                                if(mysql_num_rows($res) > 0)
                                {
                                $_SESSION['_config']['row'] = "";
                                $dom = mysql_real_escape_string($dom);
                                $query = "select *, `orginfo`.`id` as `id` from `orginfo`,`orgdomains`,`org` where
-                                               `org`.`memid`='".$_SESSION['profile']['id']."' and
+                                               `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
                                                `org`.`orgid`=`orginfo`.`id` and
                                                `orgdomains`.`orgid`=`orginfo`.`id` and
                                                `orgdomains`.`domain`='$dom'";
                                $_SESSION['_config']['altrow'] = "";
                                $dom = mysql_real_escape_string($dom);
                                $query = "select * from `orginfo`,`orgdomains`,`org` where
-                                               `org`.`memid`='".$_SESSION['profile']['id']."' and
+                                               `org`.`memid`='".intval($_SESSION['profile']['id'])."' and
                                                `org`.`orgid`=`orginfo`.`id` and
                                                `orgdomains`.`orgid`=`orginfo`.`id` and
                                                `orgdomains`.`domain`='$dom'";
                                $dom = $bits[$i];
                        $dom = mysql_real_escape_string($dom);
                        $query = "select * from `org`,`orgdomains`,`orginfo`
-                                       where `org`.`memid`='".$_SESSION['profile']['id']."'
+                                       where `org`.`memid`='".intval($_SESSION['profile']['id'])."'
                                        and `orgdomains`.`orgid`=`org`.`orgid`
                                        and `orginfo`.`id`=`org`.`orgid`
                                        and `orgdomains`.`domain`='$dom'";
                if($id <= 0)
                        $id = $_SESSION['profile']['id'];
 
-               $query = "select sum(`points`) as `points` from `notary` where `to`='$id' group by `to`";
+               $query = "select sum(`points`) as `points` from `notary` where `to`='$id' and `deleted` = 0 group by `to`";
                $row = mysql_fetch_assoc(mysql_query($query));
                $points = $row['points'];
 
                $dob = date("Y-m-d", mktime(0,0,0,date("m"),date("d"),date("Y")-18));
-               $query = "select * from `users` where `id`='".$_SESSION['profile']['id']."' and `dob` < '$dob'";
+               $query = "select * from `users` where `id`='".intval($_SESSION['profile']['id'])."' and `dob` < '$dob'";
                if(mysql_num_rows(mysql_query($query)) < 1)
                {
                        if($points >= 100)
                return(0);
        }
 
-       function hex2bin($data)
+       function gpg_hex2bin($data)
        {
                while(strstr($data, "\\x"))
                {
                $fp = fopen($tmpfname, "w");
                fputs($fp, $message);
                fclose($fp);
-               $do = `/usr/bin/gpg --homedir /home/gpg --clearsign "$tmpfname"|/usr/sbin/sendmail "$to"`;
+               $to_esc = escapeshellarg($to);
+               $do = shell_exec("/usr/bin/gpg --homedir /home/gpg --clearsign \"$tmpfname\"|/usr/sbin/sendmail ".$to_esc);
                @unlink($tmpfname);
        }
 
                $myemail = mysql_real_escape_string($email);
                if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\+\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email))
                {
-                       list($username,$domain)=split('@',$email);
-                       $dom = escapeshellarg($domain);
-                       $line = trim(`dig +short MX $dom 2>&1`);
-#echo $email."-$dom-$line-\n";
-#echo `dig +short mx heise.de 2>&1`."-<br>\n";
-
-                       $list = explode("\n", $line);
-                       foreach($list as $row)
-                               list($pri, $mxhosts[]) = explode(" ", substr(trim($row), 0, -1));
-                       $mxhosts[] = $domain;
-#print_r($mxhosts); die;
+                       list($username,$domain)=explode('@',$email,2);
+                       $mxhostrr = array();
+                       $mxweight = array();
+                       if( !getmxrr($domain, $mxhostrr, $mxweight) ) {
+                               $mxhostrr = array($domain);
+                               $mxweight = array(0);
+                       } else if ( empty($mxhostrr) ) {
+                               $mxhostrr = array($domain);
+                               $mxweight = array(0);
+                       }
+
+                       $mxhostprio = array();
+                       for($i = 0; $i < count($mxhostrr); $i++) {
+                               $mx_host = trim($mxhostrr[$i], '.');
+                               $mx_prio = $mxweight[$i];
+                               if(empty($mxhostprio[$mx_prio])) {
+                                       $mxhostprio[$mx_prio] = array();
+                               }
+                               $mxhostprio[$mx_prio][] = $mx_host;
+                       }
+
+                       array_walk($mxhostprio, function(&$mx) { shuffle($mx); } );
+                       ksort($mxhostprio);
+
+                       $mxhosts = array();
+                       foreach($mxhostprio as $mx_prio => $mxhostnames) {
+                               foreach($mxhostnames as $mx_host) {
+                                       $mxhosts[] = $mx_host;
+                               }
+                       }
+
                        foreach($mxhosts as $key => $domain)
                        {
-                               $fp = @fsockopen($domain,25,$errno,$errstr,5);
+                               $fp_opt = array(
+                                       'ssl' => array(
+                                               'verify_peer'   => false,       // Opportunistic Encryption
+                                               )
+                                       );
+                               $fp_ctx = stream_context_create($fp_opt);
+                               $fp = @stream_socket_client("tcp://$domain:25",$errno,$errstr,5,STREAM_CLIENT_CONNECT,$fp_ctx);
                                if($fp)
                                {
-                               
-                                       $line = fgets($fp, 4096);
-                                        while(substr($line, 0, 4) == "220-")
-                                               $line = fgets($fp, 4096);
-                                       if(substr($line, 0, 3) != "220")
+                                       stream_set_blocking($fp, true);
+
+                                       $has_starttls = false;
+
+                                       do {
+                                               $line = fgets($fp, 4096);
+                                       } while(substr($line, 0, 4) == "220-");
+                                       if(substr($line, 0, 3) != "220") {
+                                               fclose($fp);
                                                continue;
-                                       fputs($fp, "HELO www.cacert.org\r\n");
-                                       $line = fgets($fp, 4096);
-                                       while(substr($line, 0, 3) == "220")
+                                       }
+
+                                       fputs($fp, "EHLO www.cacert.org\r\n");
+                                       do {
                                                $line = fgets($fp, 4096);
-                                       if(substr($line, 0, 3) != "250")
+                                               $has_starttls |= substr(trim($line),4) == "STARTTLS";
+                                       } while(substr($line, 0, 4) == "250-");
+                                       if(substr($line, 0, 3) != "250") {
+                                               fclose($fp);
                                                continue;
-                                       fputs($fp, "MAIL FROM:<returns@cacert.org>\r\n");
-                                       $line = fgets($fp, 4096);
+                                       }
+
+                                       if($has_starttls) {
+                                               fputs($fp, "STARTTLS\r\n");
+                                               do {
+                                                       $line = fgets($fp, 4096);
+                                               } while(substr($line, 0, 4) == "220-");
+                                               if(substr($line, 0, 3) != "220") {
+                                                       fclose($fp);
+                                                       continue;
+                                               }
+
+                                               stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
+
+                                               fputs($fp, "EHLO www.cacert.org\r\n");
+                                               do {
+                                                       $line = fgets($fp, 4096);
+                                               } while(substr($line, 0, 4) == "250-");
+                                               if(substr($line, 0, 3) != "250") {
+                                                       fclose($fp);
+                                                       continue;
+                                               }
+                                       }
 
-                                       if(substr($line, 0, 3) != "250")
+                                       fputs($fp, "MAIL FROM:<returns@cacert.org>\r\n");
+                                       do {
+                                               $line = fgets($fp, 4096);
+                                       } while(substr($line, 0, 4) == "250-");
+                                       if(substr($line, 0, 3) != "250") {
+                                               fclose($fp);
                                                continue;
+                                       }
+
                                        fputs($fp, "RCPT TO:<$email>\r\n");
-                                       $line = trim(fgets($fp, 4096));
+                                       do {
+                                               $line = fgets($fp, 4096);
+                                       } while(substr($line, 0, 4) == "250-");
+                                       if(substr($line, 0, 3) != "250") {
+                                               fclose($fp);
+                                               continue;
+                                       }
+
                                        fputs($fp, "QUIT\r\n");
                                        fclose($fp);
 
                                        $line = mysql_real_escape_string(trim(strip_tags($line)));
                                        $query = "insert into `pinglog` set `when`=NOW(), `email`='$myemail', `result`='$line'";
-                                       if(is_array($_SESSION['profile'])) $query.=", `uid`='".$_SESSION['profile']['id']."'";
+                                       if(is_array($_SESSION['profile'])) $query.=", `uid`='".intval($_SESSION['profile']['id'])."'";
                                        mysql_query($query);
 
                                        if(substr($line, 0, 3) != "250")
                                }
                        }
                }
-               $query = "insert into `pinglog` set `when`=NOW(), `uid`='".$_SESSION['profile']['id']."',
+               $query = "insert into `pinglog` set `when`=NOW(), `uid`='".intval($_SESSION['profile']['id'])."',
                                `email`='$myemail', `result`='Failed to make a connection to the mail server'";
                mysql_query($query);
                return _("Failed to make a connection to the mail server");
                return $ticket;
        }
 
-       function sanitizeHTML($input) 
+       function sanitizeHTML($input)
        {
-               return htmlentities(strip_tags($input), ENT_QUOTES);
+               return htmlentities(strip_tags($input), ENT_QUOTES, 'ISO-8859-1');
                //In case of problems, please use the following line again:
                //return htmlentities(strip_tags(utf8_decode($input)), ENT_QUOTES);
                //return htmlspecialchars(strip_tags($input));
                $text=preg_replace("/[^\w-.@]/","",$text);
                return($text);
        }
-       
+
 
        // returns text message to be shown to the user given the result of is_no_assurer
        function no_assurer_text($Status)
                        $name="../$type/$kind/".intval($id/1000)."/$kind-".intval($id).".$type";
                        if (!is_dir("../csr")) { mkdir("../csr",0777); }
                        if (!is_dir("../crt")) { mkdir("../crt",0777); }
-                       
+
                        if (!is_dir("../csr/$kind")) { mkdir("../csr/$kind",0777); }
                        if (!is_dir("../crt/$kind")) { mkdir("../crt/$kind",0777); }
                        if (!is_dir("../csr/$kind/".intval($id/1000))) { mkdir("../csr/$kind/".intval($id/1000)); }
index 09ec7f9..15dee8a 100644 (file)
@@ -75,7 +75,7 @@ if (array_key_exists('HTTP_USER_AGENT',$_SERVER) && strstr($_SERVER['HTTP_USER_A
                        <p style="color:red"><?php
                                printf(_('Please note that RSA key sizes smaller than %d bit '.
                                        'will not be accepted by CAcert.'),
-                                       1024)?>
+                                       2048)?>
                        </p>
                </fieldset>
 
@@ -121,7 +121,7 @@ if (array_key_exists('HTTP_USER_AGENT',$_SERVER) && strstr($_SERVER['HTTP_USER_A
                        <input type="hidden" name="keytype" value="NS">
                        <?=_("Keysize:")?> <keygen name="SPKAC" challenge="<? $_SESSION['spkac_hash']=make_hash(); echo $_SESSION['spkac_hash']; ?>">
 
-                       <input type="submit" name="submit" value="<?=_("Create Certificate Request")?>">
+                       <input type="submit" name="submit" value="<?=_("Generate key pair within browser")?>">
                        <input type="hidden" name="oldid" value="<?=intval($id)?>">
                </form>
        </p>
index e311668..dd8afd3 100644 (file)
 
 /**
  * Function to recalculate the cached Assurer status
- * 
+ *
  * @param int $userID
  *     if the user ID is not given the flag will be recalculated for all users
- * 
+ *
  * @return bool
  *     false if there was an error on fixing the flag. This does NOT return the
  *     new value of the flag
@@ -30,7 +30,7 @@
 function fix_assurer_flag($userID = NULL)
 {
        // Update Assurer-Flag on users table if 100 points and CATS passed.
-       // 
+       //
        // We may have some performance issues here if no userID is given
        // there are ~150k assurances and ~220k users currently
        // but the exists-clause on cats_passed should be a good filter
@@ -46,20 +46,21 @@ function fix_assurer_flag($userID = NULL)
                                WHERE `cp`.`variant_id` = `cv`.`id`
                                        AND `cv`.`type_id` = 1
                                        AND `cp`.`user_id` = `u`.`id`
-                       ) 
+                       )
                        AND (
                                SELECT SUM(`points`) FROM `notary` AS `n`
                                WHERE `n`.`to` = `u`.`id`
                                        AND (`n`.`expire` > now()
-                                       OR `n`.`expire` IS NULL)
+                                            OR `n`.`expire` IS NULL)
+                                       AND `n`.`deleted` = 0
                        ) >= 100';
-       
+
        $query = mysql_query($sql);
        if (!$query) {
                return false;
        }
        // Challenge has been passed and non-expired points >= 100
-       
+
        // Reset flag if requirements are not met
        //
        // Also a bit performance critical but assurer flag is only set on
@@ -86,13 +87,64 @@ function fix_assurer_flag($userID = NULL)
                                                        `n`.`expire` > now()
                                                        OR `n`.`expire` IS NULL
                                                )
+                                               AND `n`.`deleted` = 0
                                ) < 100
                        )';
-       
+
        $query = mysql_query($sql);
        if (!$query) {
                return false;
        }
-       
+
        return true;
-}
\ No newline at end of file
+}
+
+/**
+ * Supported hash algorithms for signing certificates
+ */
+class HashAlgorithms {
+       /**
+        * Default hash algorithm identifier for signing
+        * @var string
+        */
+       public static $default = 'sha256';
+
+       /**
+        * Get display strings for the supported hash algorithms
+        * @return array(string=>array('name'=>string, 'info'=>string))
+        *     - [$hash_identifier]['name'] = Name that should be displayed in UI
+        *     - [$hash_identifier]['info'] = Additional information that can help
+        *       with the selection of a suitable algorithm
+        */
+       public static function getInfo() {
+               return array(
+                               'sha256' => array(
+                                               'name' => 'SHA-256',
+                                               'info' => _('Currently recommended, because the other algorithms might break on some older versions of the GnuTLS library (older than 3.x) still shipped in Debian for example.'),
+                                       ),
+                               'sha384' => array(
+                                               'name' => 'SHA-384',
+                                               'info' => '',
+                                       ),
+                               'sha512' => array(
+                                               'name' => 'SHA-512',
+                                               'info' => _('Highest protection against hash collision attacks of the algorithms offered here.'),
+                                       ),
+                       );
+       }
+
+       /**
+        * Check if the input is a supported hash algorithm identifier otherwise
+        * return the identifier of the default hash algorithm
+        *
+        * @param string $hash_identifier
+        * @return string The cleaned identifier
+        */
+       public static function clean($hash_identifier) {
+               if (array_key_exists($hash_identifier, self::getInfo() )) {
+                       return $hash_identifier;
+               } else {
+                       return self::$default;
+               }
+       }
+}
index ca13ba2..dd4f3a5 100644 (file)
@@ -128,16 +128,15 @@ function checkWeakKeyText($text)
 
        if ($algorithm === "rsaEncryption")
        {
-               if (!preg_match('/^\s*RSA Public Key: \((\d+) bit\)$/m', $text,
-               $keysize))
+               if (!preg_match('/^\s*Public-Key: \((\d+) bit\)$/m', $text, $keysize))
                {
                        return failWithId("checkWeakKeyText(): Couldn't parse the RSA ".
                                                "key size.\nData:\n$text");
                } else {
                        $keysize = intval($keysize[1]);
                }
-                       
-               if ($keysize < 1024)
+
+               if ($keysize < 2048)
                {
                        return sprintf(_("The keys that you use are very small ".
                                                "and therefore insecure. Please generate stronger ".
@@ -145,14 +144,8 @@ function checkWeakKeyText($text)
                                                "found in %sthe wiki%s"),
                                        "<a href='//wiki.cacert.org/WeakKeys#SmallKey'>",
                                        "</a>");
-               } elseif ($keysize < 2048) {
-                       // not critical but log so we have some statistics about
-                       // affected users
-                       trigger_error("checkWeakKeyText(): Certificate for small ".
-                                               "key (< 2048 bit) requested", E_USER_NOTICE);
                }
-                       
-                       
+
                $debianVuln = checkDebianVulnerability($text, $keysize);
                if ($debianVuln === true)
                {
@@ -170,7 +163,7 @@ function checkWeakKeyText($text)
                                        "checkDebianVulnerability().\nKeysize: $keysize\n".
                                        "Data:\n$text");
                }
-                       
+
                if (!preg_match('/^\s*Exponent: (\d+) \(0x[0-9a-fA-F]+\)$/m', $text,
                $exponent))
                {
@@ -180,7 +173,7 @@ function checkWeakKeyText($text)
                        $exponent = $exponent[1]; // exponent might be very big =>
                        //handle as string using bc*()
 
-                       if (bccomp($exponent, "3") === 0)
+                       if (bccomp($exponent, "65537") < 0)
                        {
                                return sprintf(_("The keys you use might be insecure. ".
                                                        "Although there is currently no known attack for ".
@@ -192,9 +185,9 @@ function checkWeakKeyText($text)
                                                "<a href='//wiki.cacert.org/WeakKeys#SmallExponent'>",
                                                "</a>");
                        } elseif (!(bccomp($exponent, "65537") >= 0 &&
-                       (bccomp($exponent, "100000") === -1 ||
-                       // speed things up if way smaller than 2^256
-                       bccomp($exponent, bcpow("2", "256")) === -1) )) {
+                                       (bccomp($exponent, "100000") === -1 ||
+                                       // speed things up if way smaller than 2^256
+                                       bccomp($exponent, bcpow("2", "256")) === -1) )) {
                                // 65537 <= exponent < 2^256 recommended by NIST
                                // not critical but log so we have some statistics about
                                // affected users
@@ -203,10 +196,83 @@ function checkWeakKeyText($text)
                                E_USER_NOTICE);
                        }
                }
-       }
 
-       /* No weakness found */
-       return "";
+               // No weakness found
+               return "";
+       } // End RSA
+
+/*
+//Fails to work due to outdated OpenSSL 0.9.8o
+//For this to work OpenSSL 1.0.1f or newer is required
+//which is currently unavailable on the systems
+//If DSA2048 or longer is used the CSR hangs pending on the signer.
+       if ($algorithm ===  "dsaEncryption")
+       {
+               if (!preg_match('/^\s*Public Key Algorithm:\s+dsaEncryption\s+pub:\s+([0-9a-fA-F:\s]+)\s+P:\s+([0-9a-fA-F:\s]+)\s+Q:\s+([0-9a-fA-F:\s]+)\s+G:\s+([0-9a-fA-F:\s]+)\s+$/sm', $text, $keydetail))
+               {
+                       return failWithId("checkWeakKeyText(): Couldn't parse the DSA ".
+                                       "key size.\nData:\n$text");
+               }
+
+               $key_pub = strtr(preg_replace("/[^0-9a-fA-F]/", "", $keydetail[1]), "ABCDEF", "abcdef");
+               $key_P = strtr(preg_replace("/[^0-9a-fA-F]/", "", $keydetail[2]), "ABCDEF", "abcdef");
+               $key_Q = strtr(preg_replace("/[^0-9a-fA-F]/", "", $keydetail[3]), "ABCDEF", "abcdef");
+               $key_G = strtr(preg_replace("/[^0-9a-fA-F]/", "", $keydetail[4]), "ABCDEF", "abcdef");
+
+               //Verify the numbers provided by the client
+               $num_pub = @gmp_init($key_pub, 16);
+               $num_P = @gmp_init($key_P, 16);
+               $num_Q = @gmp_init($key_Q, 16);
+               $num_G = @gmp_init($key_G, 16);
+
+               $bit_P = ltrim(gmp_strval($num_P, 2), "0");
+               $keysize = strlen($bit_P);
+
+               if ($keysize < 2048) {
+                       return sprintf(_("The keys that you use are very small ".
+                                               "and therefore insecure. Please generate stronger ".
+                                               "keys. More information about this issue can be ".
+                                               "found in %sthe wiki%s"),
+                                       "<a href='//wiki.cacert.org/WeakKeys#SmallKey'>",
+                                       "</a>");
+               }
+
+               //Following checks based on description of key generation in Wikipedia
+               //These checks do not ensure a strong key, but at least check for enough sanity in the key material
+               // cf. https://en.wikipedia.org/wiki/Digital_Signature_Algorithm#Key_generation
+
+               //Check that P is prime
+               if(!gmp_testprime($num_P)) {
+                       return failWithId("checkWeakKeyText(): The supplied DSA ".
+                                       "key does seem to have a non-prime public modulus.\nData:\n$text");
+               }
+
+               //Check that Q is prime
+               if(!gmp_testprime($num_Q)) {
+                       return failWithId("checkWeakKeyText(): The supplied DSA ".
+                                       "key does seem to have a non-prime Q-value.\nData:\n$text");
+               }
+
+               //Check if P-1 is diviseable by Q
+               if(0 !== gmp_cmp("1", gmp_mod($num_P, $num_Q))) {
+                       return failWithId("checkWeakKeyText(): The supplied DSA ".
+                                       "key does seem to have P mod Q === 1 (i.e. P-1 is not diviseable by Q).\nData:\n$text");
+               }
+
+               //Check the numbers are all less than the public modulus P
+               if(0 <= gmp_cmp($num_Q, $num_P) || 0 <= gmp_cmp($num_G, $num_P) || 0 <= gmp_cmp($num_pub, $num_P)) {
+                       return failWithId("checkWeakKeyText(): The supplied DSA ".
+                                       "key does seem to be normalized to have Q < P, G < P and pub < P.\nData:\n$text");
+               }
+
+               // No weakness found
+               return "";
+       } // End DSA
+*/
+
+
+       return _("The keys you supplied use an unrecognized algorithm. ".
+                       "For security reasons these keys can not be signed by CAcert.");
 }
 
 /**
@@ -242,7 +308,7 @@ function checkDebianVulnerability($text, $keysize = 0)
                if ($algorithm !== "rsaEncryption") return false;
                        
                /* Extract public key size */
-               if (!preg_match('/^\s*RSA Public Key: \((\d+) bit\)$/m', $text,
+               if (!preg_match('/^\s*Public-Key: \((\d+) bit\)$/m', $text,
                $keysize))
                {
                        trigger_error("checkDebianVulnerability(): Couldn't parse the ".
@@ -272,7 +338,7 @@ function checkDebianVulnerability($text, $keysize = 0)
 
 
        /* Extract RSA modulus */
-       if (!preg_match('/^\s*Modulus \(\d+ bit\):\n'.
+       if (!preg_match('/^\s*Modulus:\n'.
                                '((?:\s*[0-9a-f][0-9a-f]:(?:\n)?)+[0-9a-f][0-9a-f])$/m',
        $text, $modulus))
        {
index 85b132d..127c6b7 100644 (file)
 
 /**
  * Checks if the user may log in and retrieve the user id
- * 
+ *
  * Usually called with $_SERVER['SSL_CLIENT_M_SERIAL'] and
  *     $_SERVER['SSL_CLIENT_I_DN_CN']
- * 
+ *
  * @param $serial string
  *     usually $_SERVER['SSL_CLIENT_M_SERIAL']
  * @param $issuer_cn string
@@ -43,7 +43,7 @@ function get_user_id_from_cert($serial, $issuer_cn)
                $row = mysql_fetch_assoc($res);
                return intval($row['memid']);
        }
-       
+
        return -1;
 }
 
@@ -71,7 +71,7 @@ function failWithId($errormessage) {
 
 /**
  * Runs a command on the shell and return it's exit code and output
- * 
+ *
  * @param string $command
  *             The command to run. Make sure that you escapeshellarg() any non-constant
  *             parts as this is executed on a shell!
@@ -85,7 +85,7 @@ function failWithId($errormessage) {
  * @param string|bool $errors
  *             The output the command wrote to STDERR (this is passed as reference),
  *             if true (default) the output will be written to the real STDERR
- * 
+ *
  * @return int|bool
  *             The exit code of the command, true if the execution of the command
  *             failed (true because then
@@ -93,38 +93,38 @@ function failWithId($errormessage) {
  */
 function runCommand($command, $input = "", &$output = null, &$errors = true) {
        $descriptorspec = array();
-       
+
        if ($input !== true) {
                $descriptorspec[0] = array("pipe", "r"); // STDIN for child
        }
-       
+
        if ($output !== true) {
                $descriptorspec[1] = array("pipe", "w"); // STDOUT for child
        }
-       
+
        if ($errors !== true) {
                $descriptorspec[2] = array("pipe", "w"); // STDERR for child
        }
-       
+
        $proc = proc_open($command, $descriptorspec, $pipes);
-       
+
        if (is_resource($proc))
        {
                if ($input !== true) {
                        fwrite($pipes[0], $input);
                        fclose($pipes[0]);
                }
-               
+
                if ($output !== true) {
                        $output = stream_get_contents($pipes[1]);
                }
-               
+
                if ($errors !== true) {
                        $errors = stream_get_contents($pipes[2]);
                }
-               
+
                return proc_close($proc);
-               
+
        } else {
                return true;
        }
@@ -145,19 +145,18 @@ function runCommand($command, $input = "", &$output = null, &$errors = true) {
                {
                        $Result |= 5;
                }
-               
-               $query = mysql_query('SELECT SUM(`points`) AS `points` FROM `notary` AS `n` WHERE `n`.`to` = \''.(int)intval($userID).'\' AND `n`.`expire` < now()');
+
+               $query = mysql_query('SELECT SUM(`points`) AS `points` FROM `notary` AS `n` WHERE `n`.`to` = \''.(int)intval($userID).'\' AND `n`.`expire` < now() and `deleted` = 0');
                $row = mysql_fetch_assoc($query);
                if ($row['points'] < 100) {
                        $Result |= 3;
                }
-               
+
                $query = mysql_query('SELECT `assurer_blocked` FROM `users` WHERE `id` = \''.(int)intval($userID).'\'');
                $row = mysql_fetch_assoc($query);
                if ($row['assurer_blocked'] > 0) {
                        $Result |= 9;
                }
-               
+
                return $Result;
        }
-       
\ No newline at end of file
index 85b7aff..4859946 100644 (file)
 class L10n {
        /**
         * These are tranlations we currently support.
-        * 
+        *
         * If another translation is added, it doesn't suffice to have gettext set
         * up, you also need to add it here, because it acts as a white list.
-        * 
+        *
         * @var array("ISO-language code" => "native name of the language")
         */
        public static $translations = array(
@@ -53,15 +53,15 @@ class L10n {
                                "zh-cn" => "&#x4e2d;&#x6587;(&#x7b80;&#x4f53;)",
                                "zh-tw" => "&#x4e2d;&#x6587;(&#33274;&#28771;)",
                        );
-       
+
        /**
         * setlocale needs a language + region code for whatever reason so here's
         * the mapping from a translation code to locales with the region that
         * seemed the most common for this language
-        * 
+        *
         * You probably never need this. Use {@link set_translation()} to change the
         * language instead of manually calling setlocale().
-        * 
+        *
         * @var array(string => string)
         */
        private static $locales = array(
@@ -101,11 +101,11 @@ class L10n {
                                "zh-cn" => "zh_CN",
                                "zh-tw" => "zh_TW",
                        );
-       
+
        /**
         * Auto-detects the language that should be used and sets it. Only works for
         * HTTP, not in a command line script.
-        * 
+        *
         * Priority:
         * <ol>
         *      <li>explicit parameter "lang" passed in HTTP (e.g. via GET)</li>
@@ -128,10 +128,10 @@ class L10n {
                                return;
                        }
                }
-               
-               
+
+
                $languages = array();
-               
+
                // parse Accept-Language header
                if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
                        $bits = explode(",", strtolower(
@@ -144,29 +144,29 @@ class L10n {
                                        $c = floatval(substr($b[1], 2));
                                else
                                        $c = 1;
-                               
+
                                if ($c != 0)
                                {
                                        $languages[trim($b[0])] = $c;
                                }
                        }
                }
-               
+
                // check if there is an explicit language given as parameter
                if(array_key_exists("lang",$_REQUEST) && trim($_REQUEST["lang"]) != "")
                {
                        // higher priority than those values in the header
                        $languages[strtolower(trim($_REQUEST["lang"]))] = 2.0;
                }
-               
+
                arsort($languages, SORT_NUMERIC);
-               
+
                // this is used to be compatible with browsers like internet
                // explorer which only provide the language code including the
                // region not without. Also handles the fallback to English (qvalues
                // may only have three digits after the .)
                $fallbacks = array("en" => 0.0005);
-               
+
                foreach($languages as $lang => $qvalue)
                {
                        // ignore any non-conforming values (that's why we don't need to
@@ -179,7 +179,7 @@ class L10n {
                        }
                        $lang_prefix = $matches[1]; // usually two-letter language code
                        $fallbacks[$lang_prefix] = $qvalue;
-                       
+
                        $chosen_translation = "";
                        if ($lang === '*') {
                                // According to the standard '*' matches anything but any
@@ -202,7 +202,7 @@ class L10n {
                                        }
                                }
                        }
-                       
+
                        if ($chosen_translation !== "")
                        {
                                if (self::set_translation($chosen_translation)) {
@@ -210,7 +210,7 @@ class L10n {
                                }
                        }
                }
-               
+
                // No translation found yet => try the prefixes
                arsort($fallbacks, SORT_NUMERIC);
                foreach ($fallbacks as $lang => $qvalue) {
@@ -218,16 +218,47 @@ class L10n {
                                return;
                        }
                }
-               
+
                // should not get here, as the fallback of "en" is provided and that
                // should always work => log an error
                trigger_error("L10n::detect_language(): could not set language",
                        E_USER_WARNING);
        }
-       
+
+       /**
+        * Normalise the translation code (e.g. from the old codes to the new)
+        *
+        * @return string
+        *              a translation code or the empty string if it can't be normalised
+        */
+       public static function normalise_translation($translation_code) {
+               // check $translation_code against whitelist
+               if (array_key_exists($translation_code, self::$translations) ) {
+                       return $translation_code;
+               }
+
+               // maybe it's a locale as previously used in the system? e.g. en_AU
+               if (preg_match('/^([a-z][a-z])_([A-Z][A-Z])$/', $translation_code, $matches) !== 1) {
+                       return '';
+               }
+
+               $lang_code = $matches[1];
+               $region_code = strtolower($matches[2]);
+
+               if (array_key_exists("${lang_code}-${region_code}", self::$translations)) {
+                       return "${lang_code}-${region_code}";
+               }
+
+               if (array_key_exists($lang_code, self::$translations)) {
+                       return $lang_code;
+               }
+
+               return '';
+       }
+
        /**
         * Get the set translation
-        * 
+        *
         * @return string
         *              a translation code or the empty string if not set
         */
@@ -238,13 +269,13 @@ class L10n {
                        return "";
                }
        }
-       
+
        /**
         * Set the translation to use.
-        * 
+        *
         * @param string $translation_code
         *              the translation code as specified in the keys of {@link $translations}
-        * 
+        *
         * @return bool
         *              <ul>
         *              <li>true if the translation has been set successfully</li>
@@ -255,27 +286,11 @@ class L10n {
         *              </ul>
         */
        public static function set_translation($translation_code) {
-               // check $translation_code against whitelist
-               if ( !array_key_exists($translation_code, self::$translations) ) {
-                       // maybe it's a locale as previously used in the system? e.g. en_AU
-                       if ( preg_match('/^([a-z][a-z])_([A-Z][A-Z])$/', $translation_code,
-                                           $matches) !== 1 ) {
-                               return false;
-                       }
-                       
-                       $lang_code = $matches[1];
-                       $region_code = strtolower($matches[2]);
-                       
-                       if ( array_key_exists("${lang_code}-${region_code}",
-                                                 self::$translations) ) {
-                               $translation_code = "${lang_code}-${region_code}";
-                       } elseif ( array_key_exists($lang_code, self::$translations) ) {
-                               $translation_code = $lang_code;
-                       } else {
-                               return false;
-                       }
+               $translation_code = self::normalise_translation($translation_code);
+               if (empty($translation_code)) {
+                       return false;
                }
-               
+
                // map translation to locale
                if ( !array_key_exists($translation_code, self::$locales) ) {
                        // weird. maybe you added a translation but haven't added a
@@ -285,7 +300,7 @@ class L10n {
                        return false;
                }
                $locale = self::$locales[$translation_code];
-               
+
                // set up locale
                if ( !putenv("LANG=$locale") ) {
                        trigger_error("L10n::set_translation(): could not set the ".
@@ -297,42 +312,42 @@ class L10n {
                                "LC_ALL to $locale", E_USER_WARNING);
                        return false;
                }
-               
-               
+
+
                // only set if we're running in a server not in a script
                if (isset($_SESSION)) {
                        // save the setting
                        $_SESSION['_config']['language'] = $translation_code;
-                       
-                       
+
+
                        // Set up the recode settings needed e.g. in PDF creation
                        $_SESSION['_config']['recode'] = "html..latin-1";
-                       
+
                        if($translation_code === "zh-cn" || $translation_code === "zh-tw")
                        {
                                $_SESSION['_config']['recode'] = "html..gb2312";
-                               
+
                        } else if($translation_code === "pl" || $translation_code === "hu") {
                                $_SESSION['_config']['recode'] = "html..ISO-8859-2";
-                               
+
                        } else if($translation_code === "ja") {
                                $_SESSION['_config']['recode'] = "html..SHIFT-JIS";
-                               
+
                        } else if($translation_code === "ru") {
                                $_SESSION['_config']['recode'] = "html..ISO-8859-5";
-                               
+
                        } else if($translation_code == "lt") { // legacy, keep for reference
                                $_SESSION['_config']['recode'] = "html..ISO-8859-13";
-                               
+
                        }
                }
-               
+
                return true;
        }
-       
+
        /**
         * Sets up the text domain used by gettext
-        * 
+        *
         * @param string $domain
         *              the gettext domain that should be used, defaults to "messages"
         */
@@ -340,4 +355,21 @@ class L10n {
                bindtextdomain($domain, $_SESSION['_config']['filepath'].'/locale');
                textdomain($domain);
        }
-}
\ No newline at end of file
+
+       public static function set_recipient_language($accountid) {
+               //returns the language of a recipient to make sure that the language is correct
+               //use together with
+               $query = "select `language` from `users` where `id`='".intval($accountid)."'";
+               $res = mysql_query($query);
+               if (mysql_num_rows($res)>=0) {
+                       $row = mysql_fetch_assoc($res);
+                       if (NULL==$row['language'] || $row['language']=='') {
+                               self::set_translation('en');
+                       } else {
+                               self::set_translation($row['language']);
+                       }
+               } else {
+                       self::set_translation('en');
+               }
+       }
+}
index 5734fad..c14f8c2 100644 (file)
 
        include_once("../includes/lib/general.php");
        require_once("../includes/lib/l10n.php");
+       include_once("../includes/mysql.php");
+       require_once('../includes/notary.inc.php');
+
+       if(!isset($_SESSION['profile']) || !is_array($_SESSION['profile'])) {
+               $_SESSION['profile'] = array( 'id' => 0, 'loggedin' => 0 );
+       }
+       if(!isset($_SESSION['profile']['id']) || !isset($_SESSION['profile']['loggedin'])) {
+               $_SESSION['profile']['id'] = 0;
+               $_SESSION['profile']['loggedin'] = 0;
+       }
 
        if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && $_SESSION['profile']['id'] > 0 && $_SESSION['profile']['loggedin'] != 0)
        {
                $uid = $_SESSION['profile']['id'];
                $_SESSION['profile']['loggedin'] = 0;
                $_SESSION['profile'] = "";
-               foreach($_SESSION as $key)
+               foreach($_SESSION as $key => $value)
                {
-                       if($key == '_config')
+                       if($key == '_config' || $key == 'mconn' || 'csrf_' == substr($key, 0, 5))
                                continue;
                        if(is_int($key) || is_string($key))
-                               unset($_SESSION[$key]);
-                       unset($$key);
-                       session_unregister($key);
+                               unset($_SESSION[$key]);
+                       unset($$key);
+                       //session_unregister($key);
                }
 
-               $_SESSION['profile'] = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='$uid'"));
+               $_SESSION['profile'] = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".intval($uid)."'"));
                if($_SESSION['profile']['locked'] == 0)
                        $_SESSION['profile']['loggedin'] = 1;
                else
                        unset($_SESSION['profile']);
        }
-  
+
        if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && ($_SESSION['profile']['id'] == 0 || $_SESSION['profile']['loggedin'] == 0))
        {
                $user_id = get_user_id_from_cert($_SERVER['SSL_CLIENT_M_SERIAL'],
                {
                        $_SESSION['profile']['loggedin'] = 0;
                        $_SESSION['profile'] = "";
-                       foreach($_SESSION as $key)
+                       foreach($_SESSION as $key => $value)
                        {
-                               if($key == '_config')
+                               if($key == '_config' || $key == 'mconn' || 'csrf_' == substr($key, 0, 5))
                                        continue;
                                if(is_int($key) || is_string($key))
-                                       unset($_SESSION[$key]);
-                               unset($$key);
-                                       session_unregister($key);
+                                       unset($_SESSION[$key]);
+                               unset($$key);
+                               //session_unregister($key);
                        }
 
                        $_SESSION['profile'] = mysql_fetch_assoc(mysql_query(
-                                       "select * from `users` where `id`='".$user_id."'"));
+                                       "select * from `users` where `id`='".intval($user_id)."'"));
                        if($_SESSION['profile']['locked'] == 0)
                                $_SESSION['profile']['loggedin'] = 1;
                        else
                } else {
                        $_SESSION['profile']['loggedin'] = 0;
                        $_SESSION['profile'] = "";
-                       foreach($_SESSION as $key)
+                       foreach($_SESSION as $key => $value)
                        {
-                               if($key == '_config')
+                               if($key == '_config' || $key == 'mconn' || 'csrf_' == substr($key, 0, 5))
                                        continue;
-                               unset($_SESSION[$key]);
-                               unset($$key);
-                               session_unregister($key);
+                               unset($_SESSION[$key]);
+                               unset($$key);
+                               //session_unregister($key);
                        }
 
-                       unset($_SESSION['_config']['oldlocation']);
-
-                       foreach($_GET as $key => $val)
-                       {
-                               if($_SESSION['_config']['oldlocation'])
-                                       $_SESSION['_config']['oldlocation'] .= "&";
-
-                               $key = str_replace(array("\n", "\r"), '', $key);
-                               $val = str_replace(array("\n", "\r"), '', $val);
-                               $_SESSION['_config']['oldlocation'] .= "$key=$val";
-                       }
-                       $_SESSION['_config']['oldlocation'] = substr($_SERVER['SCRIPT_NAME'], 1)."?".$_SESSION['_config']['oldlocation'];
-
-                       header("location: https://".$_SESSION['_config']['securehostname']."/index.php?id=4");
+                       $_SESSION['_config']['oldlocation'] = $_SERVER['REQUEST_URI'];
+                       header("Location: https://{$_SESSION['_config']['securehostname']}/index.php?id=4");
                        exit;
                }
        }
 
        if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && ($_SESSION['profile']['id'] <= 0 || $_SESSION['profile']['loggedin'] == 0))
        {
-               header("location: https://".$_SESSION['_config']['normalhostname']);
+               header("Location: https://{$_SESSION['_config']['normalhostname']}");
                exit;
        }
 
        if($_SERVER['HTTP_HOST'] == $_SESSION['_config']['securehostname'] && $_SESSION['profile']['id'] > 0 && $_SESSION['profile']['loggedin'] > 0)
        {
-               $query = "select sum(`points`) as `total` from `notary` where `to`='".$_SESSION['profile']['id']."' group by `to`";
+               $query = "select sum(`points`) as `total` from `notary` where `to`='".intval($_SESSION['profile']['id'])."' and `deleted` = 0 group by `to`";
                $res = mysql_query($query);
                $row = mysql_fetch_assoc($res);
                $_SESSION['profile']['points'] = $row['total'];
                if($_SESSION['profile']['language'] == "")
                {
                        $query = "update `users` set `language`='".L10n::get_translation()."'
-                                                       where `id`='".$_SESSION['profile']['id']."'";
+                                                       where `id`='".intval($_SESSION['profile']['id'])."'";
                        mysql_query($query);
                } else {
                        L10n::set_translation($_SESSION['profile']['language']);
                $_SESSION['profile'] = "";
                foreach($_SESSION as $key => $value)
                {
-                       unset($_SESSION[$key]);
-                       unset($$key);
-                       session_unregister($key);
+                       unset($_SESSION[$key]);
+                       unset($$key);
+                       //session_unregister($key);
                }
 
-               header("location: https://".$normalhost."/index.php");
+               header("Location: https://{$normalhost}/index.php");
                exit;
        }
 
        if($_SESSION['profile']['loggedin'] < 1)
        {
-               unset($_SESSION['_config']['oldlocation']);
-
-               foreach($_REQUEST as $key => $val)
-               {
-                       if($_SESSION['_config']['oldlocation'])
-                               $_SESSION['_config']['oldlocation'] .= "&";
+               $_SESSION['_config']['oldlocation'] = $_SERVER['REQUEST_URI'];
+               header("Location: https://{$_SERVER['HTTP_HOST']}/index.php?id=4");
+               exit;
+       }
 
-                       $key = str_replace(array("\n", "\r"), '', $key);
-                       $val = str_replace(array("\n", "\r"), '', $val);
-                       $_SESSION['_config']['oldlocation'] .= "$key=$val";
+       if (!isset($_SESSION['profile']['ccaagreement']) || !$_SESSION['profile']['ccaagreement']) {
+               $_SESSION['profile']['ccaagreement']=get_user_agreement_status($_SESSION['profile']['id'],'CCA');
+               if (!$_SESSION['profile']['ccaagreement']) {
+                       $_SESSION['_config']['oldlocation'] = $_SERVER['REQUEST_URI'];
+                       header("Location: https://{$_SERVER['HTTP_HOST']}/index.php?id=52");
+                       exit;
                }
-               $_SESSION['_config']['oldlocation'] = substr($_SERVER['SCRIPT_NAME'], 1)."?".$_SESSION['_config']['oldlocation'];
-               $hostname=$_SERVER['HTTP_HOST'];
-               $hostname = str_replace(array("\n", "\r"), '', $hostname);
-               header("location: https://".$hostname."/index.php?id=4");
-               exit;
        }
 ?>
index d6f86a8..3b8e736 100644 (file)
@@ -16,6 +16,9 @@
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
+define('NULL_DATETIME', '0000-00-00 00:00:00');
+define('THAWTE_REVOCATION_DATETIME', '2010-11-16 00:00:00');
+
        function query_init ($query)
        {
                return mysql_query($query);
        function get_number_of_assurances ($userid)
        {
                $res = query_init ("SELECT count(*) AS `list` FROM `notary`
-                       WHERE `method` = 'Face to Face Meeting' AND `from`='".intval($userid)."' ");
+                       WHERE `method` = 'Face to Face Meeting' AND `from`='".intval($userid)."' and `deleted` = 0");
+               $row = query_getnextrow($res);
+
+               return intval($row['list']);
+       }
+
+       function get_number_of_ttpassurances ($userid)
+       {
+               $res = query_init ("SELECT count(*) AS `list` FROM `notary`
+                       WHERE (`method`='Trusted Third Parties' or `method`='TTP-Assisted') AND `to`='".intval($userid)."' and `deleted` = 0");
                $row = query_getnextrow($res);
 
                return intval($row['list']);
@@ -44,7 +56,7 @@
        function get_number_of_assurees ($userid)
        {
                $res = query_init ("SELECT count(*) AS `list` FROM `notary`
-                       WHERE `method` = 'Face to Face Meeting' AND `to`='".intval($userid)."' ");
+                       WHERE `method` = 'Face to Face Meeting' AND `to`='".intval($userid)."' and `deleted` = 0");
                $row = query_getnextrow($res);
 
                return intval($row['list']);
@@ -53,7 +65,7 @@
        function get_top_assurer_position ($no_of_assurances)
        {
                $res = query_init ("SELECT count(*) AS `list` FROM `notary`
-                       WHERE `method` = 'Face to Face Meeting'
+                       WHERE `method` = 'Face to Face Meeting' and `deleted` = 0
                        GROUP BY `from` HAVING count(*) > '".intval($no_of_assurances)."'");
                return intval(query_get_number_of_rows($res)+1);
        }
        function get_top_assuree_position ($no_of_assurees)
        {
                $res = query_init ("SELECT count(*) AS `list` FROM `notary`
-                       WHERE `method` = 'Face to Face Meeting'
+                       WHERE `method` = 'Face to Face Meeting' and `deleted` = 0
                        GROUP BY `to` HAVING count(*) > '".intval($no_of_assurees)."'");
                return intval(query_get_number_of_rows($res)+1);
        }
 
-       function get_given_assurances ($userid)
+       /**
+        * Get the list of assurances given by the user
+        * @param int $userid - id of the assurer
+        * @param int $log - if set to 1 also includes deleted assurances
+        * @return resource - a MySQL result set
+        */
+       function get_given_assurances($userid, $log=0)
        {
-               $res = query_init ("select * from `notary` where `from`='".intval($userid)."' and `from` != `to` order by `id` asc");
+               $deleted='';
+               if ($log == 0) {
+                       $deleted = ' and `deleted` = 0 ';
+               }
+               $res = query_init("select * from `notary` where `from`='".intval($userid)."' and `from` != `to` $deleted order by `id` asc");
                return $res;
        }
 
-       function get_received_assurances ($userid)
+       /**
+        * Get the list of assurances received by the user
+        * @param int $userid - id of the assuree
+        * @param int $log - if set to 1 also includes deleted assurances
+        * @return resource - a MySQL result set
+        */
+       function get_received_assurances($userid, $log=0)
        {
-               $res = query_init ("select * from `notary` where `to`='".intval($userid)."' and `from` != `to` order by `id` asc ");
+               $deleted='';
+               if ($log == 0) {
+                       $deleted = ' and `deleted` = 0 ';
+               }
+               $res = query_init("select * from `notary` where `to`='".intval($userid)."' and `from` != `to` $deleted order by `id` asc  ");
                return $res;
        }
 
        function get_given_assurances_summary ($userid)
        {
-               $res = query_init ("select count(*) as number,points,awarded,method from notary where `from`='".intval($userid)."' group by points,awarded,method");
+               $res = query_init (&q