Commit 4eef22f2 authored by Vitaly Lipatov's avatar Vitaly Lipatov

initial commit

parents
svcCheckEmail.cp1251.js: svcCheckEmail.js
iconv -f utf8 -t cp1251 <$< >$@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="//eterfund.ru/js/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="//eterfund.ru/api/email/svcCheckEmail.js"></script>
<style type="text/css">
form {
width: 100%;
position: absolute;
text-align: center;
top: 30%;
}
</style>
</head>
</html>
<body>
<form action="" method="post">
E-mail: <input type="text" name="email" value="" class="svcCheckEmail" />
<input type="button" value="Отправить" />
</form>
</body>
body {
margin: 0;
padding: 0;
}
.svcCheckEmail.bg-true {
background: white url("svcCheckEmail_true.png") right no-repeat;
}
.svcCheckEmail.bg-false {
background: white url("svcCheckEmail_false.png") right no-repeat;
}
.svcCheckEmail.bg-loader {
background: white url("svcCheckEmail_loader.gif") right no-repeat;
}
#svcCheckEmail_notice {
width: 100%;
height: 51px;
top: 0;
position: fixed;
z-index: 999999;
margin: 0;
margin-top: -51px;
padding: 0;
}
#svcCheckEmail_notice.red {
background: url('svcCheckEmail_noticeBg_red.png') 0 0 repeat-x;
color: #a20510;
}
#svcCheckEmail_notice.green {
background: url('svcCheckEmail_noticeBg_green.png') 0 0 repeat-x;
color: #2f7c00;
}
#svcCheckEmail_notice.yellow {
background: url('svcCheckEmail_noticeBg_yellow.png') 0 0 repeat-x;
color: #a39709;
}
#svcCheckEmail_notice .notice_center_auto {
margin: 0 auto;
width: 900px;
padding: 15px 25px;
}
#svcCheckEmail_notice .notice_center_auto #notice_text {
float:left;
font: normal 14px arial;
}
#svcCheckEmail_notice .notice_center_auto #notice_close_btn.red {
background: url('svcCheckEmail_closeBtn_red.png') 0 0 no-repeat;
}
#svcCheckEmail_notice .notice_center_auto #notice_close_btn.green {
background: url('svcCheckEmail_closeBtn_green.png') 0 0 no-repeat;
}
#svcCheckEmail_notice .notice_center_auto #notice_close_btn.yellow {
background: url('svcCheckEmail_closeBtn_yellow.png') 0 0 no-repeat;
}
#svcCheckEmail_notice .notice_center_auto #notice_close_btn {
cursor: pointer;
float: right;
width: 11px;
height: 10px;
margin-top: 3px;
}
\ No newline at end of file
var noticeTimer, noticeShow = false;
function getEMail()
{
var emailInput = $('.svcCheckEmail');
var email = emailInput.val();
try {
email = email.trim();
} catch(e) {
//
}
return email;
}
function closeNotice() {
if(noticeShow === true) {
clearTimeout(noticeTimer);
emailNotice.animate({ marginTop: '-=51px' }, 300);
noticeShow = false;
}
}
function showNotice(type, message) {
if(!document.getElementById('svcCheckEmail_notice')) {
var notice = '<div id="svcCheckEmail_notice"><div class="notice_center_auto">';
notice += '<div id="notice_text"></div>';
notice += '<div id="notice_close_btn" onclick="closeNotice();">&nbsp;</div>';
notice += '</div></div>';
emailNotice = $(notice);
$('body').prepend(emailNotice);
}
$('#notice_text').html(message);
emailNotice.removeClass().addClass(type);
$('#notice_close_btn').removeClass().addClass(type);
if(noticeShow === false) {
emailNotice.animate({ marginTop: '+=51px' }, 300);
noticeShow = true;
}
clearTimeout(noticeTimer);
noticeTimer = setTimeout(function() {
emailNotice.animate({ marginTop: '-=51px' }, 300);
noticeShow = false;
}, 3000);
}
// Добавляем CSS и расставляем вызов
$(function() {
$('<link />').attr({
rel: 'stylesheet',
type: 'text/css',
href: '//eterfund.ru/api/email/svcCheckEmail.css'
}).appendTo('head');
var prev_emailCheck, checkDoneStatus = 'empty';
var emailInput = $('.svcCheckEmail');
var emailNotice, emailForm = emailInput.closest('form');
emailForm.submit(function() {
if(getEMail() == '') {
return true;
}
if(checkDoneStatus == 'empty') {
emailInput.blur();
}
if(checkDoneStatus != 'done') {
if(checkDoneStatus == 'fail') {
showNotice('red', 'Введённый вами адрес недоступен. Пожалуйста, укажите корректный e-mail.');
}
return false;
}
closeNotice();
return true;
});
emailInput.blur(function() {
var email = getEMail();
var regex = /^([^@\s]+)@(([a-zA-Z0-9\_\-]+\.)+([a-zA-Z]{2}|aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|post|pro|tel|travel|xxx))$/;
emailInput.val(email);
if(prev_emailCheck == email) {
return false;
}
prev_emailCheck = email;
checkDoneStatus = 'fail';
if(email.length == 0) {
if(noticeShow === true) {
clearTimeout(noticeTimer);
emailNotice.css({ marginTop: '-51px' });
noticeShow = false;
}
emailInput.removeClass('bg-loader').removeClass('bg-true').removeClass('bg-false');
return false;
}
inputHeight = parseInt(emailInput.height()) + parseInt(emailInput.css('margin-top')) + parseInt(emailInput.css('margin-bottom'));
showNotice('yellow', 'Идёт проверка адреса e-mail, это может занять несколько секунд.');
checkDoneStatus = 'check';
emailInput.removeClass('bg-true').removeClass('bg-false').addClass('bg-loader');
clearTimeout(noticeTimer);
if(email.length < 5 || !regex.test(email)) {
showNotice('red', 'Неверный формат email. Адрес должен иметь вид: <b>имя_пользователя@имя_домена</b> (например <b>somebody@example.com</b>)');
emailInput.removeClass('bg-loader').addClass('bg-false');
checkDoneStatus = 'fail';
return false;
}
$.ajax({
url: '//eterfund.ru/api/email/svcCheckEmail.php',
type: 'GET',
data: {
email: email
},
error: function() {
showNotice('red', 'Ошибка связи с сервером, проверка адреса не удалась.');
emailInput.removeClass('bg-loader').addClass('bg-true');
checkDoneStatus = 'true';
},
success: function(response) {
try {
response = JSON.parse(response);
if(response.status === false) {
switch (response.error) {
case 'dns_records_not_found':
noticeText = 'Проверьте e-mail, такой домен не обнаружен.';
break;
case 'typed_domain':
noticeText = 'Обнаружена опечатка в домене. Проверьте внимательно указанный вами e-mail.';
break;
case 'wrong_email_format':
noticeText = 'Что-то не так в написании адреса. Возможно, указаны лишние точки или пробелы.';
break;
default:
noticeText = 'Введённый вами адрес недоступен. Пожалуйста, укажите корректный e-mail.';
break;
}
showNotice('red', noticeText);
emailInput.removeClass('bg-loader').addClass('bg-false');
checkDoneStatus = 'fail';
}
else {
showNotice('green', 'Email адрес указан верно.');
emailInput.removeClass('bg-loader').addClass('bg-true');
document.CheckEmailHash = response.hash;
checkDoneStatus = 'done';
}
} catch (e) {
showNotice('yellow', 'Не удалось проверить адрес e-mail.');
emailInput.removeClass('bg-loader').addClass('bg-true');
checkDoneStatus = 'done';
}
}
});
return true;
});
});
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type');
error_reporting(0);
function typeddomain($domain)
{
$blacklist = array("meil.ru", "maile.ru", "meil.ru","wail.ru","maiil.ru","maij.ru","mfil.ru","yandeks.ru","yandexs.ru","jandex.ru","yahdex.ru","yanbex.ru","ayndex.ru","yndex.ru","yanddex.ru","gmal.com","gmeil.com","gmauil.com","rabler.ru","ramdler.ru","ranbler.ru","gmail.ru","gmal.com");
return in_array($domain, $blacklist);
}
// TODO: что за повтор???
// http://stackoverflow.com/questions/15699101/get-the-client-ip-address-using-php
// Function to get the client IP address
function get_client_ip_env() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
// Function to get the client IP address
function get_client_ip() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
function calc_hash($domain, $ip, $email)
{
return md5($domain.$ip.$email);
}
$email = isset($argv[1]) ? $argv[1] : $_GET['email'];
$http_referer = $_SERVER['HTTP_REFERER'];
$site_domain = parse_url($http_referer, PHP_URL_HOST);
$ip_from = get_client_ip();
// TODO: improve domain list? drop it?
if(mb_strlen($email, 'utf8') > 5 &&
preg_match('/^([^@\s]+)@(([a-zA-Z0-9\_\-]+\.)+([a-zA-Z]{2}|aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|post|pro|tel|travel))$/', $email, $matches)) {
$response = array(
'email' => $matches[0],
'username' => $matches[1],
'domain' => $matches[2],
'ip_from' => $ip_from,
'hash' => calc_hash($site_domain, $ip_from, $matches[0]),
'status' => true,
'error' => null
);
if(typeddomain($matches[2])) {
$response['status'] = false;
$response['error'] = 'typed_domain';
}
if(checkdnsrr($matches[2]) === false) {
$response['status'] = false;
$response['error'] = 'dns_records_not_found';
}
// TODO: Referer: http://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&tl=ar&u=http://azbyka.ru/znakomstva/
$referer = $http_referer ? $http_referer : 'Unknown';
$referer_host = $http_referer ? str_ireplace('www.', '', parse_url($referer, PHP_URL_HOST)) : 'unknown_host';
$data = 'Date: '.date('d/m/Y H:i:s').
' | IP: '.$ip_from.
' | Referer: '.$referer.
' | Query e-mail: '.$response['email'].
' | Username: '.($response['username'] ? $response['username'] : 'null').
' | Domain: '.($response['domain'] ? $response['domain'] : 'null').
' | Status: '.($response['status'] ? 'true' : 'false').
' | Hash: '.$response['hash'].
' | Error: '.($response['error'] ? $response['error'] : 'null').
PHP_EOL;
file_put_contents(dirname(__FILE__).'/logs/'.$referer_host.'.'.($response['status'] ? 'ok' : 'error').'.log', $data, FILE_APPEND);
}
else {
$response = array(
'email' => $email,
'username' => null,
'domain' => null,
'ip_from' => $ip_from,
'hash' => null,
'status' => false,
'error' => 'wrong_email_format'
);
}
echo json_encode($response);
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment