[3.2][BETA] Live Email Validate (LEV)

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
orynider
Registered User
Posts: 165
Joined: Wed Nov 16, 2005 12:48 pm
Location: Arad, România
Name: Florin Bodin
Contact:

[3.2][BETA] Live Email Validate (LEV)

Post by orynider » Mon Aug 06, 2018 6:33 pm

MOD Name: Live Email Validate (LEV)
Author: Wulf_9
original autor: memberlist.php?mode=viewprofile&u=174156
based on http://www.phpbb.com/community/viewtopic.php?t=280755
based on http://www.phpbb.com/community/viewtopi ... &t=1392575

MOD Description: When a user signs up or edits their email address, this MOD will
attempt to verify it via the DNS MX records and a test SMTP session,
returning true or false as appropriate. In the event of failure, some
server responses are displayed if DEBUG is set to true in constants.php

Code: Select all

#
#-----[ OPEN ]------------------------------------------
# original autor: https://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=174156
# based on http://www.phpbb.com/community/viewtopic.php?t=280755
# based on http://www.phpbb.com/community/viewtopic.php?f=72&t=1392575
#
includes/functions_user.php

#
#-----[ FIND ]------------------------------------------
#
/**
* Check to see if email address is a valid address and contains a MX record
*
* @param string $email The email to check
*
* @return mixed Either false if validation succeeded or a string which will be used as the error message (with the variable name appended)
*/

#
#-----[ BEFORE, ADD ]------------------------------------------
#
/* +MOD: Live Email Validate (LEV)
*
* test SMTP mail delivery
*/
function probe_smtp_mailbox($email, $hostname)
{
	global $config, $user, $phpEx;
	@set_time_limit(30);
	
	if ($connect = fsockopen($hostname, 25, $errno, $errstr, 15))
	{
		usleep(888);
		$out = fgetss($connect, 1024);

	    if (preg_match('#^220#', $out))
	    {
	      fputs($connect, "HELO " . $config['server_name'] . "\r\n");

	      while (preg_match('#^220#', $out))
	      {
	        $out = fgetss($connect, 1024);
	      }

	      fputs($connect, "VRFY <" . $email . ">\r\n");
	      $verify = fgetss($connect, 1024);

	      fputs($connect, "MAIL FROM: <" . $config['board_email'] . ">\r\n");
	      $from = fgetss($connect, 1024);

	      fputs($connect, "RCPT TO: <" . $email . ">\r\n");
	      $to = fgetss($connect, 1024);

	      fputs($connect, "QUIT\r\n");
	      fclose($connect);
		  //$user->lang['Email_unverified'] = "Unverified E-Mail Adress";
		  //$user->lang['No_connection'] = "No Connection";
		  
	      if (preg_match('#^250#', $from) && preg_match('#^250#', $to) && !preg_match('#^550#', $verify))
	      {
	        $result = false;
	      }
	      else
	      {
	      	$result = "Unverified E-Mail Adress";
	      }
	    }
	    @fclose($connect);
	}
	else
	{
		$result = "No Connection";
	}
	return $result;
}

// Try to find an MX record that matches the hostname - Unix
function check_smtp_addr_unix($email)
{
  list($username, $domain) = explode('@', $email);

  if (checkdnsrr($domain, 'MX'))
  {
    getmxrr($domain, $mxhosts);
    $result = probe_smtp_mailbox($email, $mxhosts[0]);

    if (isset($result['error']) && ($result['error'] == false))
    {
    	return $result;
    }

    for ($i = 1; $i < count($mxhosts); $i++)
    {
		$result = probe_smtp_mailbox($email, $mxhosts[$i]);
		if (isset($result['error']) && ($result['error'] == false))
		{
			return $result;
		}
    }
    return $result;
  }
  else
  {
  	return (probe_smtp_mailbox($email, $domain));
  }
}

// Try to find an MX record that matches the hostname - Win32
function check_smtp_addr_win($email)
{
  list($username, $domain) = explode('@', $email);
  exec("nslookup -type=MX $domain", $outputs);

  foreach ($outputs as $hostname)
  {
    if (@strpos($domain, $hostname))
    {
      $result =  probe_smtp_mailbox($email, $domain);

      if ($result['error'] == false)
      {
      	return $result;
      }
    }
  }

  if (isset($result))
  {
  	return $result;
  }
  else
  {
  	return (probe_smtp_mailbox($email, $domain));
  }
}
/*
* -MOD: Live Email Validate (LEV)
*/

#
#-----[ FIND ]------------------------------------------
#
	// Check MX record.
	// The idea for this is from reading the UseBB blog/announcement. :)
	if ($config['email_check_mx'])
	{
		list(, $domain) = explode('@', $email);

		if (phpbb_checkdnsrr($domain, 'A') === false && phpbb_checkdnsrr($domain, 'MX') === false)
		{
			return 'DOMAIN_NO_MX_RECORD';
		}
#
#-----[ AFTER, ADD ]------------------------------------
#
		/* +MOD: Live Email Validate (LEV)
		*
		*	global $HTTP_SERVER_VARS;
		*/
		global $request;
		if ($request->is_set('SERVER_SOFTWARE', \phpbb\request\request_interface::SERVER))
		{
			$SERVER_SOFTWARE = $request->variable('SERVER_SOFTWARE', '', true, \phpbb\request\request_interface::SERVER);
		}
		else if (!isset($SERVER_SOFTWARE))
		{
			$server_software = $request->server('SERVER_SOFTWARE', '');
		}

		if (empty($server_software))
		{
			$server_software = $SERVER_SOFTWARE;
		}		
		
		$system = preg_match("/Microsoft|Win32|IIS|WebSTAR|Xitami/", $server_software) ? $result = check_smtp_addr_win($email) : $result = check_smtp_addr_unix($email);
		if ($result == true)
		{
			return $result;
		}
		/*
		* -MOD: Live Email Validate (LEV)
		*/	
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
		



User avatar
jackennils
Registered User
Posts: 186
Joined: Mon Jun 01, 2009 7:48 pm

Re: [3.2][BETA] Live Email Validate (LEV)

Post by jackennils » Mon Aug 06, 2018 7:27 pm

This is not an extension, I think.

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1940
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: [3.2][BETA] Live Email Validate (LEV)

Post by kinerity » Mon Aug 06, 2018 7:51 pm

orynider, please see the 3.2 Extensions page for information about writing extensions. If you would like to request this be converted to an extension, I can move this to the Extension Requests forum - just let me know. ;)
Kailey Truscott - Community Team

User avatar
orynider
Registered User
Posts: 165
Joined: Wed Nov 16, 2005 12:48 pm
Location: Arad, România
Name: Florin Bodin
Contact:

Re: [3.2][BETA] Live Email Validate (LEV)

Post by orynider » Mon Aug 06, 2018 9:54 pm

It's more a snipped then an extension and I see no way this functions can be moved to a extension in "ext/" folder since functions_user.php does not have a function holder class that we can extend from an extension.

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: No registered users and 5 guests