Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added two environment variables, MODE and MX_WHITELIST. #33

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions includes/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,27 @@ function signmail($to, $subject, $message, $from, $replyto = "")

function checkEmail($email)
{
if ( is_devmode() ) {
return "OK" ;
}

$myemail = mysql_real_escape_string($email);
if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\+\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email))
{
list($username,$domain)=explode('@',$email,2);

/*
* Check if the MX_WHITELIST environment variable is set,
* and, if so, see if it contains the domain name for
* this e-mail address.
*/
if ( strlen( getenv( "MX_WHITELIST" )) > 0 ) {
$whitelist_arr = explode( ",", getenv( "MX_WHITELIST" )) ;
if ( in_array( $domain, $whitelist_arr ) ) {
return "OK" ;
}
}

$mxhostrr = array();
$mxweight = array();
if( !getmxrr($domain, $mxhostrr, $mxweight) ) {
Expand Down Expand Up @@ -592,10 +609,10 @@ function checkEmail($email)
{
$fp_opt = array(
'ssl' => array(
'verify_peer' => false, // Opportunistic Encryption
'verify_peer_name' => false, // Opportunistic Encryption
)
);
'verify_peer' => false, // Opportunistic Encryption
'verify_peer_name' => false, // Opportunistic Encryption
)
);
$fp_ctx = stream_context_create($fp_opt);
$fp = @stream_socket_client("tcp://$domain:25",$errno,$errstr,5,STREAM_CLIENT_CONNECT,$fp_ctx);
if($fp)
Expand Down Expand Up @@ -678,7 +695,7 @@ function checkEmail($email)
}
}
$query = "insert into `pinglog` set `when`=NOW(), `uid`='".intval($_SESSION['profile']['id'])."',
`email`='$myemail', `result`='Failed to make a connection to the mail server'";
`email`='$myemail', `result`='Failed to make a connection to the mail server'";
mysql_query($query);
return _("Failed to make a connection to the mail server");
}
Expand Down Expand Up @@ -819,6 +836,40 @@ function sanitizeFilename($text)
return($text);
}

/**
* Test whether the MODE environment variable
* is set to DEV.
*/
function is_devmode() {
return( getenv( "MODE" ) == "DEV" ) ;
}

/**
* Test whether the MODE environment variable
* is set to PROD.
*
* If it is not set at all, assume PROD.
*/
function is_prodmode() {
$prod_mode == false ;

$is_prod = getenv( "MODE" ) == "PROD" ;
if ( ! $is_prod && ! ( getenv( "MODE" ) == "DEV" ) ) {
$prod_mode = true ;
}

return $prod_mode ;
}

/**
* Test whether the MODE environment variable
* is set to TEST.
*/
function is_testmode() {
return ( getenv( "MODE" ) == "TEST" ) ;
}



// returns text message to be shown to the user given the result of is_no_assurer
function no_assurer_text($Status)
Expand Down