<?php
/*
 * Email Link Protection
 *
 * Copyright (c) 2004 Colin Viebrock <colin@viebrock.ca>
 *
 * Usage of the works is permitted provided that this
 * instrument is retained with the works, so that any entity
 * that uses the works is notified of this instrument.
 *
 * DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
 */

$args explode('/'$_SERVER['PATH_INFO'] );

/*
 *    [0] is empty because of the leading slash 
 *    [1] is the first half of the email address
 *    [2] is the second half of the email address
 *    [3] is the subject (optional)
 */

/*    First, check that they aren't trying to leech our resources
 *    and validate email address that aren't in my list of allowed
 *    domains.
 */

$allowed = array(
    
'viebrock.ca'
);


/*    If they are, then send them an error (and optionally log 
 *    the attempt).
 */

if (!in_array$args[2], $allowed )) {
    
header('HTTP/1.0 403 Forbidden');
    echo 
'<h1>403 Forbidden</h1>';

    
$msg = array(
        
strftime('%Y-%m-%d %T'),
        
$args[1] . '@' $args[2],
        empty(
$args[3]) ? '-' $args[3],
        empty(
$_SERVER['HTTP_REFERER']) ? '-' $_SERVER['HTTP_REFERER']
    );

    @
file_put_contents(
        
'/home/cmv/logs/email_leech.log',
        
join ("\t"$msg) . "\n",
        
FILE_APPEND
    
);

    exit;
}



/*    Start Turing protection code *********************
 *
 *    Remove this block of code if you don't want Turing Protection
 *    added to your email protection, as described at:
 *    http://viebrock.ca/code/10/turing-protection
 */

session_start();
if (!
$_SESSION['turing_pass']) {
    
$_SESSION['turing_redirect'] = $_SERVER['PHP_SELF'];
    
Header('Location: /turing.php');
    exit;
}
unset(
$_SESSION['turing_pass']);

/*    End Turing protection code ************************/




if (isset($args[1]) && isset($args[2]) ) {

    
$loc 'mailto:' $args[1] . '@' $args[2];

    if (isset(
$args[3])) {
        
$loc .= '?subject=' urldecode($args[3]);
    }

    
Header('Location: ' $loc );

}

exit;