162 lines
6.9 KiB
PHP
Executable file
162 lines
6.9 KiB
PHP
Executable file
#!/usr/bin/php -q
|
|
<? /*
|
|
Copyright (C) 2004 by Duane Groth <duane_at_CAcert_dot_org>
|
|
|
|
This file is part of CAcert.
|
|
|
|
CAcert has been released under a CAcert Source License
|
|
which can be found included with these source files or can
|
|
be downloaded from the internet from the following address:
|
|
http://www.cacert.org/src-lic.php
|
|
|
|
CAcert is distributed WITHOUT ANY WARRANTY; without even
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
PARTICULAR PURPOSE. See the License for more details.
|
|
*/
|
|
|
|
$monarr = array("Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6,
|
|
"Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12);
|
|
|
|
include_once("../includes/mysql.php");
|
|
|
|
$query = "select * from `domaincerts` where `crt_name`=''";
|
|
$res = mysql_query($query);
|
|
while($row = mysql_fetch_assoc($res))
|
|
{
|
|
$query = "select * from `domains`,`users` where `domains`.`id`='".$row['domid']."' and
|
|
`users`.`id`=`domains`.`memid`";
|
|
$user = mysql_fetch_assoc(mysql_query($query));
|
|
|
|
if($user['language'] != "")
|
|
{
|
|
$userlang = $user['language'];
|
|
putenv("LANG=".$_SESSION['_config']['translations'][$userlang]);
|
|
setlocale(LC_ALL, $_SESSION['_config']['translations'][$userlang]);
|
|
} else {
|
|
putenv("LANG=en_AU");
|
|
setlocale(LC_ALL, "en_AU");
|
|
}
|
|
|
|
$days = 180;
|
|
|
|
if(intval($user['memid']) > 0)
|
|
{
|
|
$drow = mysql_fetch_assoc(mysql_query("select sum(`points`) as `total` from `notary`
|
|
where `to`='".$user['memid']."' group by `to`"));
|
|
if($drow['total'] >= 50)
|
|
$days = 730;
|
|
}
|
|
|
|
$row['crt_name'] = "../crt/server-".$row['id'].".crt";
|
|
$do = `/usr/bin/openssl ca -config /etc/ssl/openssl-server.cnf -in $row[csr_name] -out $row[crt_name] -days $days -key test -batch > /dev/null 2>&1`;
|
|
$dom = mysql_fetch_assoc(mysql_query("select * from `domains` where `id`='$row[domid]'"));
|
|
$user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='$dom[memid]'"));
|
|
if(filesize($row[crt_name]) > 0 && intval($user['id']) > 0)
|
|
{
|
|
$end = trim(`/usr/bin/openssl x509 -in $row[crt_name] -noout -enddate`);
|
|
$bits = explode("=", $end, 2);
|
|
$end = trim($bits[1]);
|
|
|
|
while(strstr($end, " "))
|
|
$end = str_replace(" ", " ", $end);
|
|
$bits = explode(" ", $end);
|
|
$month = $bits['0'];
|
|
$month = $monarr[$month];
|
|
$day = $bits['1'];
|
|
$time = $bits['2'];
|
|
$year = $bits['3'];
|
|
$bits = explode(":", $time);
|
|
$hour = $bits['0'];
|
|
$min = $bits['1'];
|
|
$sec = $bits['2'];
|
|
$date = gmmktime($hour, $min, $sec, $month, $day, $year);
|
|
$cert = trim(`/usr/bin/openssl x509 -in $row[crt_name]`);
|
|
$bits = explode("=", trim(`/usr/bin/openssl x509 -serial -noout -in $row[crt_name]`), 2);
|
|
$serial = $bits['1'];
|
|
$query = "update `domaincerts` set `crt_name`='".$row['crt_name']."',
|
|
`modified`=FROM_UNIXTIME(UNIX_TIMESTAMP()),
|
|
`serial`='$serial', `expire`=FROM_UNIXTIME($date) where `id`='".$row['id']."'";
|
|
mysql_query($query);
|
|
$body = _("Hi")." ".$user['fname'].",\n\n";
|
|
$body .= sprintf(_("Below you will find your certificate for %s.")."\n\n", $row['CN']);
|
|
$body .= _("Best regards")."\n"._("CAcert.org Support!")."\n\n".$cert;
|
|
mail($user['email'], "[CAcert.org] "._("Server Certificate"), $body, "From: CAcert-Support <duane@cacert.org>");
|
|
} else {
|
|
$query = "delete from `domaincerts` where `id`='".$row['id']."'";
|
|
mysql_query($query);
|
|
}
|
|
}
|
|
|
|
$query = "select * from `domaincerts` where `revoked`='1970-01-01 10:00:01'";
|
|
$res = mysql_query($query);
|
|
while($row = mysql_fetch_assoc($res))
|
|
{
|
|
$do = `/usr/bin/openssl ca -config /etc/ssl/openssl-server.cnf -key test -batch -revoke $row[crt_name] > /dev/null 2>&1`;
|
|
$do = `/usr/bin/openssl ca -config /etc/ssl/openssl-server.cnf -key test -batch -gencrl -crldays 7 -crlexts crl_ext -out /tmp/cacert-revoke.crl > /dev/null 2>&1`;
|
|
$do = `/usr/bin/openssl crl -in /tmp/cacert-revoke.crl -outform DER -out ../www/revoke.crl > /dev/null 2>&1`;
|
|
$dom = mysql_fetch_assoc(mysql_query("select * from `domains` where `id`='".$row['domid']."'"));
|
|
$user = mysql_fetch_assoc(mysql_query("select * from `users` where `id`='".$dom['memid']."'"));
|
|
if($user['language'] != "")
|
|
{
|
|
$userlang = $user['language'];
|
|
putenv("LANG=".$_SESSION['_config']['translations'][$userlang]);
|
|
setlocale(LC_ALL, $_SESSION['_config']['translations'][$userlang]);
|
|
} else {
|
|
putenv("LANG=en_AU");
|
|
setlocale(LC_ALL, "en_AU");
|
|
}
|
|
mysql_query("update `domaincerts` set `revoked`=FROM_UNIXTIME(UNIX_TIMESTAMP()) where `id`='".$row['id']."'");
|
|
$body = _("Hi")." ".$user['fname'].",\n\n";
|
|
$body .= sprintf(_("Your certificate for %s has been revoked, as per request.")."\n\n", $row['CN']);
|
|
$body .= _("Best regards")."\n"._("CAcert.org Support!");
|
|
mail($user['email'], "[CAcert.org] ".sprintf(_("Certificate for %s has been revoked"), $row['CN']), $body, "From: CAcert-Support <duane@cacert.org>");
|
|
}
|
|
|
|
$query = "select * from `orgdomaincerts` where `crt_name`=''";
|
|
$res = mysql_query($query);
|
|
while($row = mysql_fetch_assoc($res))
|
|
{
|
|
$row['crt_name'] = "../crt/orgserver-".$row['id'].".crt";
|
|
$days = 730;
|
|
$do = `/usr/bin/openssl ca -config /etc/ssl/openssl-server-org.cnf -in $row[csr_name] -out $row[crt_name] -days $days -key test -batch -subj '$row[subject]' > /dev/null 2>&1`;
|
|
if(filesize($row[crt_name]) > 0)
|
|
{
|
|
$end = trim(`/usr/bin/openssl x509 -in $row[crt_name] -noout -enddate`);
|
|
$bits = explode("=", $end, 2);
|
|
$end = trim($bits[1]);
|
|
|
|
while(strstr($end, " "))
|
|
$end = str_replace(" ", " ", $end);
|
|
$bits = explode(" ", $end);
|
|
$month = $bits[0];
|
|
$month = $monarr[$month];
|
|
$day = $bits[1];
|
|
$time = $bits[2];
|
|
$year = $bits[3];
|
|
$bits = explode(":", $time);
|
|
$hour = $bits[0];
|
|
$min = $bits[1];
|
|
$sec = $bits[2];
|
|
$date = gmmktime($hour, $min, $sec, $month, $day, $year);
|
|
$cert = trim(`/usr/bin/openssl x509 -in $row[crt_name]`);
|
|
$bits = explode("=", trim(`/usr/bin/openssl x509 -serial -noout -in $row[crt_name]`), 2);
|
|
$serial = $bits[1];
|
|
$query = "update `orgdomaincerts` set `crt_name`='$row[crt_name]', `modified`=FROM_UNIXTIME(UNIX_TIMESTAMP()),
|
|
`serial`='$serial', `expire`=FROM_UNIXTIME($date) where `id`='".$row['id']."'";
|
|
mysql_query($query);
|
|
} else {
|
|
$query = "delete from `orgdomaincerts` where `id`='".$row['id']."'";
|
|
mysql_query($query);
|
|
}
|
|
}
|
|
|
|
$query = "select * from `orgdomaincerts` where `revoked`='1970-01-01 10:00:01'";
|
|
$res = mysql_query($query);
|
|
while($row = mysql_fetch_assoc($res))
|
|
{
|
|
$do = `/usr/bin/openssl ca -config /etc/ssl/openssl-server-org.cnf -key test -batch -revoke $row[crt_name] > /dev/null 2>&1`;
|
|
$do = `/usr/bin/openssl ca -config /etc/ssl/openssl-server-org.cnf -key test -batch -gencrl -crldays 7 -crlexts crl_ext -out /tmp/cacert-revoke.crl > /dev/null 2>&1`;
|
|
$do = `/usr/bin/openssl crl -in /tmp/cacert-revoke.crl -outform DER -out ../www/revoke.crl > /dev/null 2>&1`;
|
|
mysql_query("update `orgdomaincerts` set `revoked`=FROM_UNIXTIME(UNIX_TIMESTAMP()) where `id`='$row[id]'");
|
|
}
|
|
?>
|