' . _("Your certificate request is still queued and hasn't been processed yet. Please wait, and go to Certificates -> View to see it's status." . '
')); $subject="[CAcert.org] Certificate TIMEOUT"; $body = "A certificate has timed out!\n\n"; } else { printf('' . _("Your certificate request has failed to be processed correctly, see %sthe WIKI page%s for reasons and solutions.") . " certid:$table:".intval($certid) . '
', "", ""); $subject="[CAcert.org] Certificate FAILURE"; $body = "A certificate has failed: $table $certid $id $show\n\n"; } $body .= _("Best regards")."\n"._("CAcert.org Support!"); sendmail("sw-message@cacert.org", $subject, $body, "returns@cacert.org", "", "", "CAcert Support"); if($show) showfooter(); if($show) exit; } } function generateTicket() { $query = "insert into tickets (timestamp) values (now()) "; mysql_query($query); $ticket = mysql_insert_id(); return $ticket; } function sanitizeHTML($input) { return htmlentities(strip_tags($input), ENT_QUOTES | ENT_SUBSTITUTE, 'ISO-8859-1', false); //In case of problems, please use the following line again: //return htmlentities(strip_tags(utf8_decode($input)), ENT_QUOTES); //return htmlspecialchars(strip_tags($input)); } function make_hash() { if(function_exists("dio_open")) { $rnd = dio_open("/dev/urandom",O_RDONLY); $hash = md5(dio_read($rnd,64)); dio_close($rnd); } else { $rnd = fopen("/dev/urandom", "r"); $hash = md5(fgets($rnd, 64)); fclose($rnd); } return($hash); } function csrf_check($nam, $show=1) { if(!array_key_exists('csrf',$_REQUEST) || !array_key_exists('csrf_'.$nam,$_SESSION)) { showheader(_("My CAcert.org Account!")); echo _("CSRF Hash is missing. Please try again.")."\n"; showfooter(); exit(); } if(strlen($_REQUEST['csrf'])!=32) { showheader(_("My CAcert.org Account!")); echo _("CSRF Hash is wrong. Please try again.")."\n"; showfooter(); exit(); } if(!array_key_exists($_REQUEST['csrf'],$_SESSION['csrf_'.$nam])) { showheader(_("My CAcert.org Account!")); echo _("CSRF Hash is wrong. Please try again.")."\n"; showfooter(); exit(); } } function make_csrf($nam) { $hash=make_hash(); $_SESSION['csrf_'.$nam][$hash]=1; return($hash); } function clean_csr($CSR) { $newcsr = str_replace("\r\n","\n",trim($CSR)); $newcsr = str_replace("\n\n","\n",$newcsr); return(preg_replace("/[^A-Za-z0-9\n\r\-\:\=\+\/ ]/","",$newcsr)); } function clean_gpgcsr($CSR) { return(preg_replace("/[^A-Za-z0-9\n\r\-\:\=\+\/ ]/","",trim($CSR))); } function sanitizeFilename($text) { $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) { if ($Status == 0) { $Result = _("You have passed the Assurer Challenge and collected at least 100 Assurance Points, you are an Assurer."); } elseif ($Status == 3) { $Result = _("You have passed the Assurer Challenge, but to become an Assurer you still have to reach 100 Assurance Points!"); } elseif ($Status == 5) { $Result = _("You have at least 100 Assurance Points, if you want to become an assurer try the").' '._("Assurer Challenge").'!'; } elseif ($Status == 7) { $Result = _("To become an Assurer you have to collect 100 Assurance Points and pass the").' '._("Assurer Challenge").'!'; } elseif ($Status & 8 > 0) { $Result = _("Sorry, you are not allowed to be an Assurer. Please contact").' cacert-support@lists.cacert.org'._(" if you feel that this is not corect."); } else { $Result = _("You are not an Assurer, but the reason is not stored in the database. Please contact").' cacert-support@lists.cacert.org.'; } return $Result; } function is_assurer($userID) { if (get_assurer_status($userID)) return 0; else return 1; } function get_assurer_reason($userID) { return no_assurer_text(get_assurer_status($userID)); } function generatecertpath($type,$kind,$id) { $name="../$type/$kind-".intval($id).".$type"; $newlayout=1; if($newlayout) { $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)); } if (!is_dir("../crt/$kind/".intval($id/1000))) { mkdir("../crt/$kind/".intval($id/1000)); } } return $name; } /** * Run the sql query given in $sql. * The resource returned by mysql_query is * returned by this function. * * It should be safe to replace every mysql_query * call by a mysql_extended_query call. */ function mysql_timed_query($sql) { global $sql_data_log; $query_start = microtime(true); $res = mysql_query($sql); $query_end = microtime(true); $sql_data_log[] = array("sql" => $sql, "duration" => $query_end - $query_start); return $res; } /** * Returns the given ip address truncated to /16 (ipv4) or to /48 (ipv6) */ function anonymizeIP($ip){ $bits = @inet_pton($ip); if($bits === false) { return false; } if(strlen($bits) == 4) { $bits[2] = "\0"; $bits[3] = "\0"; $newIP = @inet_ntop($bits); if($newIP !== false) { $newIP .= "/16"; } return $newIP; } else if(strlen($bits) == 16) { for($i=6;$i<16;$i++){ $bits[$i]="\0"; } $newIP = @inet_ntop($bits); if($newIP !== false) { $newIP .= "/48"; } return $newIP; } return false; }