BigJohnny
09-25-2010, 11:23 PM
My PHP skills aren't so hot, and this script that USED TO work, but has not ever been changed, no longer works now.
This is for Live Feedback Registration and vB 3.8.3. It's the email verification function. It always ends up failing to connect to legitimate email address'.
If anyone could just look over the code real quick and see if anything stands out I'd really appreciate it. I'd like to get this working.
Everything else but the email check works just fine.
email_check.php
<?php
define('NO_REGISTER_GLOBALS', 1);
define('SKIP_SESSIONCREATE', 1);
define('NOCOOKIES', 1);
define('DIE_QUIETLY', 1);
//define('SKIP_DEFAULTDATASTORE', 1);
define('DIR', dirname(__FILE__));
require_once './global.php';
$vbulletin->input->clean_array_gpc('p', array('email' => TYPE_STR));
if($vbulletin->GPC['email'] != '')
{
$email = htmlspecialchars_uni(trim(convert_urlencoded_unico de($vbulletin->GPC['email'])));
$verify = (!ini_get('safe_mode')) ? verifyMailAddy($email) : 0;
header('Content-Type: text/plain;');
require_once(DIR . '/includes/functions_user.php');
switch(true)
{
case is_banned_email($email) == 1:
echo 2;
break;
case $verify != 0;
echo $verify;
break;
case $vbulletin->options['requireuniqueemail'] &&
$existingemail = $db->query_first("
SELECT
email
FROM
" . TABLE_PREFIX . "user
WHERE
email = '" . $db->escape_string($email) . "'
")
:
echo 1;
break;
default;
echo 0;
}
}
function verifyMailAddy($email)
{
list($user_name, $domain) = split('@',$email);
if(function_exists('getmxrr'))
{
$mail_exchanger = (getmxrr($domain, $mx)) ? $mx[0] : $domain;
}
else
{
$mx = windoz_getmxrr($domain);
$mail_exchanger = (!$mx) ? $domain : $mx;
}
if($connect = @fsockopen($mail_exchanger, 25, $errno, $errstr, 15))
{
$receive = fgets($connect, 128);
if(substr($receive, 0, 3) == '220')
{
fputs($connect, "HELO ".$_SERVER['HTTP_HOST']."\r\n");
$receive = fgets($connect, 128);
if(substr($receive, 0, 3) == '554')
{
//Server rejected query.
fputs($connect, "QUIT\r\n");
fclose($connect);
return 3;
}
fputs($connect, "MAIL FROM: <{$email}>\r\n");
$mail_from = fgets( $connect, 128 );
fputs($connect, "RCPT TO: <{$email}>\r\n");
$mail_to = fgets($connect, 128);
fputs($connect, "QUIT\r\n");
fclose($connect);
if(substr($mail_to, 0, 3) != '250')
{
//Server rejected address
return 5;
}
}
else
{
//No response from server
return 4;
}
}
else
{
//Can not connect E-Mail server.
return 3;
}
//Good, but no guarantee that they don't have an accept all email addy.
return 0;
}
function windoz_getmxrr($domain)
{
if(!empty($domain))
{
$domain = escapeshellcmd($domain);
exec("nslookup -type=MX $domain",$receive_data);
foreach($receive_data as $data_line)
{
if(preg_match("#^$domain#", $data_line))
{
if(preg_match('#^.*MX preference = (\d{1,10}), mail exchanger = (.*)$#siU', $data_line, $match))
{
return $match[2];
}
}
}
return false;
}
return false;
}
?>
live_feedback_system.js
//Live Feedback Registration 1.31
var currentSelect = '';
function _loadTextDoc(url, query_string, callback) {
entry_check = new vB_AJAX_Handler(true);
entry_check.onreadystatechange(callback);
entry_check.send(url, query_string);
}
function _processNameInput() {
if(entry_check.handler.readyState == 4) {
if(entry_check.handler.status == 200) {
liveCheck('', entry_check.handler.responseText);
}
}
}
function liveCheck(input, response, min_user_length) {
var namecheck = fetch_object('nameCheck');
if(response != ''){
switch (response){
case '3':_replaceText(namecheck, lfsr_username_invalid_semicolon, 'namebad');break;
case '2':_replaceText(namecheck, lfsr_username_invalid_censored, 'namebad');break;
case '1':_replaceText(namecheck, lfsr_username_not_available, 'namebad');break;
case '0':_replaceText(namecheck, lfsr_username_available, 'namegood');break;
}
} else {
if(input.length >= parseInt(min_user_length, '10')){
_loadTextDoc('username_check.php', 'username='+PHP.urlencode(input), _processNameInput);
} else {
if(input.length >= 1){
_replaceText(namecheck, lfsr_username_too_short, 'nametooshort');
} else {
_replaceText(namecheck, lfsr_username_choose, 'namechoose');
}
}
}
}
function match_fields(id,type){
fieldcheck = fetch_object(id);
if(type == 'password'){
field1 = document.forms.register.password;
field2 = document.forms.register.passwordconfirm;
matchAllow = false; //temp
}else{
field1 = document.forms.register.email;
field2 = document.forms.register.emailconfirm;
}
if(!matchAllow){
switch (true){
case field1.value == '' || field2.value == '':
_replaceText(fieldcheck, lfsr_match_fill_both, 'nametooshort');
break;
case field1.value != field2.value:
_replaceText(fieldcheck, lfsr_match_false, 'namebad');
break;
default:_replaceText(fieldcheck, lfsr_match_true, 'namegood');break;
}
}
}
function _processRefererInput() {
if(entry_check.handler.readyState == 4) {
if(entry_check.handler.status == 200) {
checkReferer('', entry_check.handler.responseText);
}
}
}
function checkReferer(input, response, min_user_length){
referer_check = fetch_object('lfsreferer');
var field1 = document.forms.register.referrername;
if(response != ''){
switch (response){
case '1':_replaceText(referer_check, lfsr_username_member_true, 'namegood');break;
default:_replaceText(referer_check, lfsr_username_member_false, 'namebad');;break;
}
} else {
switch (true){
case input.length >= parseInt(min_user_length, '10'):
_loadTextDoc('username_check.php', 'username='+PHP.urlencode(input), _processRefererInput);
break;
case input.length >= 1:
_replaceText(referer_check, lfsr_username_member_false, 'namebad');
break;
}
}
}
function _processEmailInput(){
if(entry_check.handler.readyState == 4) {
if(entry_check.handler.status == 200) {
checkEmail('', entry_check.handler.responseText);
}
}
}
function checkEmail(input, response){
email_check = fetch_object('lfseconfirm');
matchAllow = true;
switch(true){
case response == '':
if(currentSelect != input){
if(email_check.firstChild != lfsr_email_validation_progress && input != ''){
_replaceText(email_check, lfsr_email_validation_progress, 'emailtooshort');
}
switch (true){
case /^[A-z0-9\.!#\$%&\'\*\+-\/=\?\{|}~]+@([0-9.]+|([^\s]+\.+[A-z]{2,6}))$/.test(input):
_loadTextDoc('email_check.php', 'email='+PHP.urlencode(input), _processEmailInput);
currentSelect = input;
break;
case input.length >= 1:
_replaceText(email_check, lfsr_email_invalid, 'emailbad');
break;
}
}
break;
case response != '':
switch (response){
case '5':_replaceText(email_check, lfsr_email_reject+' '+lfsr_email_submit_valid, 'emailbad');break;
case '4':_replaceText(email_check, lfsr_email_no_responce, 'emailbad');break;
case '3':_replaceText(email_check, lfsr_email_no_connect+' '+lfsr_email_submit_valid, 'emailbad');;break;
case '2':_replaceText(email_check, lfsr_email_banned, 'emailbad');break;
case '1':_replaceText(email_check, lfsr_email_exists, 'emailbad');break;
case '0':_replaceText(email_check, lfsr_email_valid, 'emailgood');matchAllow = false;break;
}
break;
}
}
function pwSuggest(){
var email_check_on = fetch_object('lfseconfirm');
if (email_check_on.className == 'warning'){
_replaceText(email_check_on, '', '');
}
suggest = fetch_object('pw_suggest');
suggestText = fetch_object('pw_suggest_text');
var pwsize=Math.floor(Math.random()*8)+7;
chars = '+-*abcdefghijklmn!op$qrst~uvwxyz@;ABCDEFGHIJ^KLMNOP_ QRSTUV#&WXYZ1234.567890%';
pass = '';
for(x=0;x<pwsize;x++){
pass += chars.charAt(Math.floor(Math.random() * 72));
}
_replaceText(suggestText, lfsr_password_suggest, 'pwsuggest');
_replaceText(suggest, pass, 'pwsuggest');
}
function livePassCheck(pw, pwsug){
var pwlength = pw.length;
if (pwlength == 1){
//_replaceText(fetch_object('pw_strength_title'), 'Password Strength:', '');
_replaceText(fetch_object('pw_guideline'), lfsr_password_guid, 'pwwarning');
suggest = fetch_object('pw_suggest');
}
if (pwlength == 0){
if(pwsug != 0){
pwSuggest();
}
//_replaceText(fetch_object('pw_strength_title'), 'Password Strength:', '');
_replaceText(fetch_object('pw_guideline'), '', '');
}
if(pwlength > 0){
var boost = 0;
if(pwlength > 9){pwlength = 9;}
var numnum = pw.replace (/[\d]/g,'');
var num = (pw.length - numnum.length);
if(num > 3){num = 3;}
if(num == 2){num = 3;}else if(num == 3){num = 4;}
var symbols = pw.replace (/\W/g,'');
var symb = (pw.length - symbols.length);
if(symb > 3){symb = 3;}
if(symb == 2){symb = 4;}else if(symb == 3){symb = 6;}
var numup = pw.replace (/[A-Z]/g,'');
var up = (pw.length - numup.length);
if(up > 3){up = 3;}
if(up == 2){up = 3;
} else if(up == 3){up = 4;}
var numlow = pw.replace (/[A-Z]/g,'');
var low = (pw.length - numlow.length);
if(low > 3){low = 3;}
if(low == 2){low = 3;
} else if(low == 3){low = 4;}
if(num >= 1 && symb >= 1 && up >= 1 && low >= 1){boost+=2;}
if(num >= 3 && symb >= 4 && up >= 3 && low >= 3){boost+=4;}
if(num >= 4 && symb >= 6 && up >= 4 && low >= 4){boost+=6;}
var pwstr = pwlength + num + symb + up + low + boost;
if(pwstr < 0){pwstr = 0;}
if(pwstr > 100){pwstr = 100;}
switch(true){
case pwstr < 10:_replaceText(fetch_object('lfspwconfirm'), lfsr_password_strength_very_weak, 'pw_veryweak');break;
case pwstr < 15:_replaceText(fetch_object('lfspwconfirm'), lfsr_password_strength_weak, 'pw_weak');break;
case pwstr < 20:_replaceText(fetch_object('lfspwconfirm'), lfsr_password_strength_mediocre, 'pw_mediocre');break;
case pwstr < 27:_replaceText(fetch_object('lfspwconfirm'), lfsr_password_strength_strong, 'pw_strong');break;
case pwstr > 26:_replaceText(fetch_object('lfspwconfirm'), lfsr_password_strength_verystrong, 'pw_verystrong');break;
}
}else{
_replaceText(fetch_object('lfspwconfirm'), '', '');
}
}
function _replaceText(el, text, class_name, colspan, width) {
if(el.firstChild){
el.removeChild(el.firstChild);
if(el.firstChild){
el.removeChild(el.firstChild);
}
}
el.appendChild(document.createTextNode(text));
el.className = class_name;
}
function loadDefault(){_replaceText(fetch_object('lfseconfi rm'), lfsr_email_default, 'warning');}
This is for Live Feedback Registration and vB 3.8.3. It's the email verification function. It always ends up failing to connect to legitimate email address'.
If anyone could just look over the code real quick and see if anything stands out I'd really appreciate it. I'd like to get this working.
Everything else but the email check works just fine.
email_check.php
<?php
define('NO_REGISTER_GLOBALS', 1);
define('SKIP_SESSIONCREATE', 1);
define('NOCOOKIES', 1);
define('DIE_QUIETLY', 1);
//define('SKIP_DEFAULTDATASTORE', 1);
define('DIR', dirname(__FILE__));
require_once './global.php';
$vbulletin->input->clean_array_gpc('p', array('email' => TYPE_STR));
if($vbulletin->GPC['email'] != '')
{
$email = htmlspecialchars_uni(trim(convert_urlencoded_unico de($vbulletin->GPC['email'])));
$verify = (!ini_get('safe_mode')) ? verifyMailAddy($email) : 0;
header('Content-Type: text/plain;');
require_once(DIR . '/includes/functions_user.php');
switch(true)
{
case is_banned_email($email) == 1:
echo 2;
break;
case $verify != 0;
echo $verify;
break;
case $vbulletin->options['requireuniqueemail'] &&
$existingemail = $db->query_first("
SELECT
FROM
" . TABLE_PREFIX . "user
WHERE
email = '" . $db->escape_string($email) . "'
")
:
echo 1;
break;
default;
echo 0;
}
}
function verifyMailAddy($email)
{
list($user_name, $domain) = split('@',$email);
if(function_exists('getmxrr'))
{
$mail_exchanger = (getmxrr($domain, $mx)) ? $mx[0] : $domain;
}
else
{
$mx = windoz_getmxrr($domain);
$mail_exchanger = (!$mx) ? $domain : $mx;
}
if($connect = @fsockopen($mail_exchanger, 25, $errno, $errstr, 15))
{
$receive = fgets($connect, 128);
if(substr($receive, 0, 3) == '220')
{
fputs($connect, "HELO ".$_SERVER['HTTP_HOST']."\r\n");
$receive = fgets($connect, 128);
if(substr($receive, 0, 3) == '554')
{
//Server rejected query.
fputs($connect, "QUIT\r\n");
fclose($connect);
return 3;
}
fputs($connect, "MAIL FROM: <{$email}>\r\n");
$mail_from = fgets( $connect, 128 );
fputs($connect, "RCPT TO: <{$email}>\r\n");
$mail_to = fgets($connect, 128);
fputs($connect, "QUIT\r\n");
fclose($connect);
if(substr($mail_to, 0, 3) != '250')
{
//Server rejected address
return 5;
}
}
else
{
//No response from server
return 4;
}
}
else
{
//Can not connect E-Mail server.
return 3;
}
//Good, but no guarantee that they don't have an accept all email addy.
return 0;
}
function windoz_getmxrr($domain)
{
if(!empty($domain))
{
$domain = escapeshellcmd($domain);
exec("nslookup -type=MX $domain",$receive_data);
foreach($receive_data as $data_line)
{
if(preg_match("#^$domain#", $data_line))
{
if(preg_match('#^.*MX preference = (\d{1,10}), mail exchanger = (.*)$#siU', $data_line, $match))
{
return $match[2];
}
}
}
return false;
}
return false;
}
?>
live_feedback_system.js
//Live Feedback Registration 1.31
var currentSelect = '';
function _loadTextDoc(url, query_string, callback) {
entry_check = new vB_AJAX_Handler(true);
entry_check.onreadystatechange(callback);
entry_check.send(url, query_string);
}
function _processNameInput() {
if(entry_check.handler.readyState == 4) {
if(entry_check.handler.status == 200) {
liveCheck('', entry_check.handler.responseText);
}
}
}
function liveCheck(input, response, min_user_length) {
var namecheck = fetch_object('nameCheck');
if(response != ''){
switch (response){
case '3':_replaceText(namecheck, lfsr_username_invalid_semicolon, 'namebad');break;
case '2':_replaceText(namecheck, lfsr_username_invalid_censored, 'namebad');break;
case '1':_replaceText(namecheck, lfsr_username_not_available, 'namebad');break;
case '0':_replaceText(namecheck, lfsr_username_available, 'namegood');break;
}
} else {
if(input.length >= parseInt(min_user_length, '10')){
_loadTextDoc('username_check.php', 'username='+PHP.urlencode(input), _processNameInput);
} else {
if(input.length >= 1){
_replaceText(namecheck, lfsr_username_too_short, 'nametooshort');
} else {
_replaceText(namecheck, lfsr_username_choose, 'namechoose');
}
}
}
}
function match_fields(id,type){
fieldcheck = fetch_object(id);
if(type == 'password'){
field1 = document.forms.register.password;
field2 = document.forms.register.passwordconfirm;
matchAllow = false; //temp
}else{
field1 = document.forms.register.email;
field2 = document.forms.register.emailconfirm;
}
if(!matchAllow){
switch (true){
case field1.value == '' || field2.value == '':
_replaceText(fieldcheck, lfsr_match_fill_both, 'nametooshort');
break;
case field1.value != field2.value:
_replaceText(fieldcheck, lfsr_match_false, 'namebad');
break;
default:_replaceText(fieldcheck, lfsr_match_true, 'namegood');break;
}
}
}
function _processRefererInput() {
if(entry_check.handler.readyState == 4) {
if(entry_check.handler.status == 200) {
checkReferer('', entry_check.handler.responseText);
}
}
}
function checkReferer(input, response, min_user_length){
referer_check = fetch_object('lfsreferer');
var field1 = document.forms.register.referrername;
if(response != ''){
switch (response){
case '1':_replaceText(referer_check, lfsr_username_member_true, 'namegood');break;
default:_replaceText(referer_check, lfsr_username_member_false, 'namebad');;break;
}
} else {
switch (true){
case input.length >= parseInt(min_user_length, '10'):
_loadTextDoc('username_check.php', 'username='+PHP.urlencode(input), _processRefererInput);
break;
case input.length >= 1:
_replaceText(referer_check, lfsr_username_member_false, 'namebad');
break;
}
}
}
function _processEmailInput(){
if(entry_check.handler.readyState == 4) {
if(entry_check.handler.status == 200) {
checkEmail('', entry_check.handler.responseText);
}
}
}
function checkEmail(input, response){
email_check = fetch_object('lfseconfirm');
matchAllow = true;
switch(true){
case response == '':
if(currentSelect != input){
if(email_check.firstChild != lfsr_email_validation_progress && input != ''){
_replaceText(email_check, lfsr_email_validation_progress, 'emailtooshort');
}
switch (true){
case /^[A-z0-9\.!#\$%&\'\*\+-\/=\?\{|}~]+@([0-9.]+|([^\s]+\.+[A-z]{2,6}))$/.test(input):
_loadTextDoc('email_check.php', 'email='+PHP.urlencode(input), _processEmailInput);
currentSelect = input;
break;
case input.length >= 1:
_replaceText(email_check, lfsr_email_invalid, 'emailbad');
break;
}
}
break;
case response != '':
switch (response){
case '5':_replaceText(email_check, lfsr_email_reject+' '+lfsr_email_submit_valid, 'emailbad');break;
case '4':_replaceText(email_check, lfsr_email_no_responce, 'emailbad');break;
case '3':_replaceText(email_check, lfsr_email_no_connect+' '+lfsr_email_submit_valid, 'emailbad');;break;
case '2':_replaceText(email_check, lfsr_email_banned, 'emailbad');break;
case '1':_replaceText(email_check, lfsr_email_exists, 'emailbad');break;
case '0':_replaceText(email_check, lfsr_email_valid, 'emailgood');matchAllow = false;break;
}
break;
}
}
function pwSuggest(){
var email_check_on = fetch_object('lfseconfirm');
if (email_check_on.className == 'warning'){
_replaceText(email_check_on, '', '');
}
suggest = fetch_object('pw_suggest');
suggestText = fetch_object('pw_suggest_text');
var pwsize=Math.floor(Math.random()*8)+7;
chars = '+-*abcdefghijklmn!op$qrst~uvwxyz@;ABCDEFGHIJ^KLMNOP_ QRSTUV#&WXYZ1234.567890%';
pass = '';
for(x=0;x<pwsize;x++){
pass += chars.charAt(Math.floor(Math.random() * 72));
}
_replaceText(suggestText, lfsr_password_suggest, 'pwsuggest');
_replaceText(suggest, pass, 'pwsuggest');
}
function livePassCheck(pw, pwsug){
var pwlength = pw.length;
if (pwlength == 1){
//_replaceText(fetch_object('pw_strength_title'), 'Password Strength:', '');
_replaceText(fetch_object('pw_guideline'), lfsr_password_guid, 'pwwarning');
suggest = fetch_object('pw_suggest');
}
if (pwlength == 0){
if(pwsug != 0){
pwSuggest();
}
//_replaceText(fetch_object('pw_strength_title'), 'Password Strength:', '');
_replaceText(fetch_object('pw_guideline'), '', '');
}
if(pwlength > 0){
var boost = 0;
if(pwlength > 9){pwlength = 9;}
var numnum = pw.replace (/[\d]/g,'');
var num = (pw.length - numnum.length);
if(num > 3){num = 3;}
if(num == 2){num = 3;}else if(num == 3){num = 4;}
var symbols = pw.replace (/\W/g,'');
var symb = (pw.length - symbols.length);
if(symb > 3){symb = 3;}
if(symb == 2){symb = 4;}else if(symb == 3){symb = 6;}
var numup = pw.replace (/[A-Z]/g,'');
var up = (pw.length - numup.length);
if(up > 3){up = 3;}
if(up == 2){up = 3;
} else if(up == 3){up = 4;}
var numlow = pw.replace (/[A-Z]/g,'');
var low = (pw.length - numlow.length);
if(low > 3){low = 3;}
if(low == 2){low = 3;
} else if(low == 3){low = 4;}
if(num >= 1 && symb >= 1 && up >= 1 && low >= 1){boost+=2;}
if(num >= 3 && symb >= 4 && up >= 3 && low >= 3){boost+=4;}
if(num >= 4 && symb >= 6 && up >= 4 && low >= 4){boost+=6;}
var pwstr = pwlength + num + symb + up + low + boost;
if(pwstr < 0){pwstr = 0;}
if(pwstr > 100){pwstr = 100;}
switch(true){
case pwstr < 10:_replaceText(fetch_object('lfspwconfirm'), lfsr_password_strength_very_weak, 'pw_veryweak');break;
case pwstr < 15:_replaceText(fetch_object('lfspwconfirm'), lfsr_password_strength_weak, 'pw_weak');break;
case pwstr < 20:_replaceText(fetch_object('lfspwconfirm'), lfsr_password_strength_mediocre, 'pw_mediocre');break;
case pwstr < 27:_replaceText(fetch_object('lfspwconfirm'), lfsr_password_strength_strong, 'pw_strong');break;
case pwstr > 26:_replaceText(fetch_object('lfspwconfirm'), lfsr_password_strength_verystrong, 'pw_verystrong');break;
}
}else{
_replaceText(fetch_object('lfspwconfirm'), '', '');
}
}
function _replaceText(el, text, class_name, colspan, width) {
if(el.firstChild){
el.removeChild(el.firstChild);
if(el.firstChild){
el.removeChild(el.firstChild);
}
}
el.appendChild(document.createTextNode(text));
el.className = class_name;
}
function loadDefault(){_replaceText(fetch_object('lfseconfi rm'), lfsr_email_default, 'warning');}