2006-08-14 06:16:55 +00:00
|
|
|
#!/usr/bin/php -q
|
|
|
|
<? /*
|
2008-04-06 19:45:09 +00:00
|
|
|
LibreSSL - CAcert web application
|
|
|
|
Copyright (C) 2004-2008 CAcert Inc.
|
2006-08-14 06:16:55 +00:00
|
|
|
|
2008-04-06 19:45:09 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
2006-08-14 06:16:55 +00:00
|
|
|
|
2008-04-06 19:45:09 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2006-08-14 06:16:55 +00:00
|
|
|
|
2008-04-06 19:45:09 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-08-14 06:16:55 +00:00
|
|
|
*/
|
|
|
|
|
2012-03-29 14:24:05 +00:00
|
|
|
require_once(dirname(__FILE__).'/../../includes/mysql.php');
|
2006-08-14 06:16:55 +00:00
|
|
|
|
|
|
|
$days = array("1" => "3", "15" => "2", "30" => "1", "45" => "0");
|
|
|
|
|
|
|
|
foreach($days as $day => $warning)
|
|
|
|
{
|
|
|
|
$query = "SELECT `emailcerts`.`id`,`users`.`fname`,`users`.`lname`,`users`.`email`,`emailcerts`.`memid`,
|
2013-06-11 10:04:47 +00:00
|
|
|
`emailcerts`.`subject`, `emailcerts`.`crt_name`,`emailcerts`.`CN`, `emailcerts`.`serial`,
|
2006-08-14 06:16:55 +00:00
|
|
|
(UNIX_TIMESTAMP(`emailcerts`.`expire`) - UNIX_TIMESTAMP(NOW())) / 86400 as `daysleft`
|
|
|
|
FROM `users`,`emailcerts`
|
|
|
|
WHERE UNIX_TIMESTAMP(`emailcerts`.`expire`) - UNIX_TIMESTAMP(NOW()) > -7 * 86400 and
|
|
|
|
UNIX_TIMESTAMP(`emailcerts`.`expire`) - UNIX_TIMESTAMP(NOW()) < $day * 86400 and
|
|
|
|
`emailcerts`.`renewed`=0 and `emailcerts`.`warning` <= '$warning' and
|
|
|
|
`emailcerts`.`revoked`=0 and `users`.`id`=`emailcerts`.`memid`";
|
|
|
|
$res = mysql_query($query);
|
|
|
|
while($row = mysql_fetch_assoc($res))
|
|
|
|
{
|
|
|
|
if($row['subject'] == "")
|
|
|
|
{
|
2006-11-23 22:22:31 +00:00
|
|
|
$row['crt_name'] = str_replace("../", "www/", $row['crt_name']);
|
|
|
|
$row['crt_name'] = "/home/cacert/".$row['crt_name'];
|
2014-04-19 07:32:11 +00:00
|
|
|
$crt_name = escapeshellarg($row['crt_name']);
|
|
|
|
$subject = `openssl x509 -in $crt_name -text -noout|grep Subject:`;
|
2006-08-14 06:16:55 +00:00
|
|
|
$bits = explode("/", $subject);
|
|
|
|
foreach($bits as $val)
|
|
|
|
{
|
|
|
|
$sub = explode("=", trim($val));
|
|
|
|
if($sub['0'] == "emailAddress")
|
|
|
|
{
|
2006-11-23 22:22:31 +00:00
|
|
|
$row['subject'] = "/CN=".$row['CN']."/emailAddress=".$sub['1'];
|
2006-08-14 06:16:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-23 22:22:31 +00:00
|
|
|
if($row['subject'] == "")
|
|
|
|
$row['subject'] = "/CN=".$row['CN'];
|
2006-08-16 09:27:39 +00:00
|
|
|
$row['daysleft'] = ceil($row['daysleft']);
|
2006-08-14 06:16:55 +00:00
|
|
|
$body = sprintf(_("Hi %s"), $row['fname']).",\n\n";
|
2007-10-10 09:13:32 +00:00
|
|
|
$body .= _("You are receiving this email as you are the listed contact for:")."\n\n";
|
2006-08-14 06:16:55 +00:00
|
|
|
$body .= $row['subject']."\n\n";
|
2013-06-11 10:04:47 +00:00
|
|
|
$body .= sprintf(_("Your certificate with the serial number %s is ".
|
|
|
|
"set to expire in approximately %s days time. You can ".
|
|
|
|
"renew it by going to the following URL:"),
|
|
|
|
$row['serial'],
|
|
|
|
$row['daysleft'])."\n\n";
|
2006-08-14 06:16:55 +00:00
|
|
|
$body .= "https://www.cacert.org/account.php?id=5\n\n";
|
|
|
|
$body .= _("Best Regards")."\n"._("CAcert Support");
|
|
|
|
sendmail($row['email'], "[CAcert.org] "._("Your Certificate is about to expire"), $body, "support@cacert.org", "", "", "CAcert Support");
|
|
|
|
echo $row['fname']." ".$row['lname']." <".$row['email']."> (memid: ".$row['memid']." Subj: ".$row['subject']." timeleft: ".$row['daysleft'].")\n";
|
|
|
|
$query = "update `emailcerts` set `warning`='".($warning+1)."' where `id`='".$row['id']."'";
|
|
|
|
mysql_query($query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($days as $day => $warning)
|
|
|
|
{
|
2013-06-11 10:04:47 +00:00
|
|
|
$select_clause =
|
|
|
|
"`domaincerts`.`id`,
|
|
|
|
`users`.`fname`, `users`.`lname`, `users`.`email`,
|
|
|
|
`domains`.`memid`,
|
|
|
|
`domaincerts`.`subject`, `domaincerts`.`crt_name`,
|
|
|
|
`domaincerts`.`CN`,
|
|
|
|
`domaincerts`.`serial`,
|
|
|
|
(UNIX_TIMESTAMP(`domaincerts`.`expire`) -
|
|
|
|
UNIX_TIMESTAMP(NOW())) / 86400 AS `daysleft`";
|
|
|
|
$where_clause =
|
|
|
|
"UNIX_TIMESTAMP(`domaincerts`.`expire`) -
|
|
|
|
UNIX_TIMESTAMP(NOW()) > -7 * 86400
|
|
|
|
AND UNIX_TIMESTAMP(`domaincerts`.`expire`) -
|
|
|
|
UNIX_TIMESTAMP(NOW()) < $day * 86400
|
|
|
|
AND `domaincerts`.`renewed` = 0
|
|
|
|
AND `domaincerts`.`warning` <= '$warning'
|
|
|
|
AND `domaincerts`.`revoked` = 0
|
|
|
|
AND `domains`.`memid` = `users`.`id`";
|
|
|
|
$query =
|
|
|
|
"SELECT $select_clause
|
|
|
|
FROM `users`, `domaincerts`, `domains`
|
|
|
|
WHERE $where_clause
|
|
|
|
AND `domaincerts`.`domid` = `domains`.`id`
|
|
|
|
UNION DISTINCT
|
|
|
|
SELECT $select_clause
|
|
|
|
FROM `users`,
|
|
|
|
`domaincerts` LEFT JOIN `domlink` ON
|
|
|
|
(`domaincerts`.`id` = `domlink`.`certid`),
|
|
|
|
`domains`
|
|
|
|
WHERE $where_clause
|
|
|
|
AND `domlink`.`domid` = `domains`.`id`";
|
2006-08-14 06:16:55 +00:00
|
|
|
$res = mysql_query($query);
|
|
|
|
while($row = mysql_fetch_assoc($res))
|
|
|
|
{
|
2006-11-23 22:22:31 +00:00
|
|
|
if($row['subject'] == "")
|
|
|
|
$row['subject'] = $row['CN'];
|
|
|
|
|
2006-08-16 09:27:39 +00:00
|
|
|
$row['daysleft'] = ceil($row['daysleft']);
|
2006-08-14 06:16:55 +00:00
|
|
|
$body = sprintf(_("Hi %s"), $row['fname']).",\n\n";
|
2007-10-10 09:13:32 +00:00
|
|
|
$body .= _("You are receiving this email as you are the listed contact for:")."\n\n";
|
2006-08-16 18:34:25 +00:00
|
|
|
$body .= $row['subject']."\n\n";
|
2013-06-11 10:04:47 +00:00
|
|
|
$body .= sprintf(_("Your certificate with the serial number %s is ".
|
|
|
|
"set to expire in approximately %s days time. You can ".
|
|
|
|
"renew it by going to the following URL:"),
|
|
|
|
$row['serial'],
|
|
|
|
$row['daysleft'])."\n\n";
|
2006-08-14 06:16:55 +00:00
|
|
|
$body .= "https://www.cacert.org/account.php?id=12\n\n";
|
|
|
|
$body .= _("Best Regards")."\n"._("CAcert Support");
|
|
|
|
sendmail($row['email'], "[CAcert.org] "._("Your Certificate is about to expire"), $body, "support@cacert.org", "", "", "CAcert Support");
|
|
|
|
echo $row['fname']." ".$row['lname']." <".$row['email']."> (memid: ".$row['memid']." Subj: ".$row['CN']." timeleft: ".$row['daysleft'].")\n";
|
|
|
|
$query = "update `domaincerts` set `warning`='".($warning+1)."' where `id`='".$row['id']."'";
|
|
|
|
mysql_query($query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|