2006-08-14 06:16:55 +00:00
#!/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 .
*/
include_once ( " /home/cacert/www/includes/mysql.php " );
$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`,
`emailcerts` . `subject` , `emailcerts` . `crt_name` ,
( 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' ] == " " )
{
$row [ 'crt_name' ] = str_replace ( " ../ " , " /home/cacert/www/ " , $row [ 'crt_name' ]);
$subject = `openssl x509 -in '$row[crt_name]' -text -noout|grep Subject:` ;
$bits = explode ( " / " , $subject );
foreach ( $bits as $val )
{
$sub = explode ( " = " , trim ( $val ));
if ( $sub [ '0' ] == " emailAddress " )
{
$row [ 'subject' ] = $sub [ '1' ];
break ;
}
}
}
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 " ;
$body .= _ ( " You are receieving this email as you are the listed contact for: " ) . " \n \n " ;
$body .= $row [ 'subject' ] . " \n \n " ;
$body .= sprintf ( _ ( " Your certificate is set to expire in approximately %s days time, you can renew this by going to the following URL: " ), $row [ 'daysleft' ]) . " \n \n " ;
$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 )
{
$query = " SELECT `domaincerts`.`id`, `users`.`fname`, `users`.`lname`, `users`.`email`,
`domains` . `memid` , `domaincerts` . `subject` , `domaincerts` . `crt_name` ,
`domaincerts` . `CN` ,
( UNIX_TIMESTAMP ( `domaincerts` . `expire` ) - UNIX_TIMESTAMP ( NOW ())) / 86400 AS `daysleft`
FROM `users` , `domaincerts` , `domlink` , `domains`
WHERE 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 `users` . `id` = `domains` . `memid` AND
`domlink` . `certid` = `domaincerts` . `id` AND `domains` . `id` = `domlink` . `domid` " ;
$res = mysql_query ( $query );
while ( $row = mysql_fetch_assoc ( $res ))
{
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 " ;
$body .= _ ( " You are receieving this email as you are the listed contact for: " ) . " \n \n " ;
$body .= $row [ 'CN' ] . " \n \n " ;
$body .= sprintf ( _ ( " Your certificate is set to expire in approximately %s days time, you can renew this by going to the following URL: " ), $row [ 'daysleft' ]) . " \n \n " ;
$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 );
}
}
?>