Edit File by line
/home/barbar84/www/wp-conte.../plugins/minioran.../helper
File: utility.php
<?php
[0] Fix | Delete
[1] Fix | Delete
class MoMmpUtility
[2] Fix | Delete
{
[3] Fix | Delete
[4] Fix | Delete
public static function icr()
[5] Fix | Delete
{
[6] Fix | Delete
$email = get_option('mo_wpns_admin_email');
[7] Fix | Delete
$customerKey = get_option('mo_wpns_admin_customer_key');
[8] Fix | Delete
if( ! $email || ! $customerKey || ! is_numeric( trim( $customerKey ) ) )
[9] Fix | Delete
return 0;
[10] Fix | Delete
else
[11] Fix | Delete
return 1;
[12] Fix | Delete
}
[13] Fix | Delete
[14] Fix | Delete
public static function check_empty_or_null( $value )
[15] Fix | Delete
{
[16] Fix | Delete
if( ! isset( $value ) || empty( $value ) )
[17] Fix | Delete
return true;
[18] Fix | Delete
return false;
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
public static function is_curl_installed()
[22] Fix | Delete
{
[23] Fix | Delete
if (in_array ('curl', get_loaded_extensions()))
[24] Fix | Delete
return 1;
[25] Fix | Delete
else
[26] Fix | Delete
return 0;
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
public static function is_extension_installed($name)
[30] Fix | Delete
{
[31] Fix | Delete
if (in_array ($name, get_loaded_extensions()))
[32] Fix | Delete
return true;
[33] Fix | Delete
else
[34] Fix | Delete
return false;
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
public static function get_client_ip()
[38] Fix | Delete
{
[39] Fix | Delete
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
[40] Fix | Delete
return sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
[41] Fix | Delete
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
[42] Fix | Delete
return sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
[43] Fix | Delete
} else {
[44] Fix | Delete
return sanitize_text_field($_SERVER['REMOTE_ADDR']);
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
return '';
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
public static function check_if_valid_email($email)
[51] Fix | Delete
{
[52] Fix | Delete
$emailarray = explode("@",$email);
[53] Fix | Delete
if(sizeof($emailarray)==2)
[54] Fix | Delete
return in_array(trim($emailarray[1]), MoMmpConstants::$domains);
[55] Fix | Delete
else
[56] Fix | Delete
return false;
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
[60] Fix | Delete
[61] Fix | Delete
public static function check_if_strong_password_enabled_for_user_role($userroles)
[62] Fix | Delete
{
[63] Fix | Delete
$enforce_strong_pass = get_option('mo_wpns_enforce_strong_passswords_for_accounts');
[64] Fix | Delete
[65] Fix | Delete
switch($enforce_strong_pass)
[66] Fix | Delete
{
[67] Fix | Delete
case "all":
[68] Fix | Delete
return true;
[69] Fix | Delete
break;
[70] Fix | Delete
case "admin":
[71] Fix | Delete
if(!in_array("administrator", $userroles))
[72] Fix | Delete
return false;
[73] Fix | Delete
break;
[74] Fix | Delete
case "user":
[75] Fix | Delete
if(in_array("administrator", $userroles))
[76] Fix | Delete
return false;
[77] Fix | Delete
break;
[78] Fix | Delete
}
[79] Fix | Delete
return true;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
public static function get_current_url()
[83] Fix | Delete
{
[84] Fix | Delete
$protocol = (!empty($_SERVER['HTTPS']) && sanitize_text_field($_SERVER['HTTPS']) !== 'off' || sanitize_text_field($_SERVER['SERVER_PORT']) == 443) ? "https://" : "http://";
[85] Fix | Delete
$url = $protocol . sanitize_text_field($_SERVER['HTTP_HOST']) . sanitize_text_field($_SERVER['REQUEST_URI']);
[86] Fix | Delete
return $url;
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
//Function to handle recptcha
[90] Fix | Delete
function verify_recaptcha($response)
[91] Fix | Delete
{
[92] Fix | Delete
$error = new WP_Error();
[93] Fix | Delete
if(!empty($response))
[94] Fix | Delete
{
[95] Fix | Delete
if(!mo_mmp_reCaptcha::recaptcha_verify($response))
[96] Fix | Delete
$error->add('recaptcha_error', __( '<strong>ERROR</strong> : Invalid Captcha. Please verify captcha again.'));
[97] Fix | Delete
else
[98] Fix | Delete
return true;
[99] Fix | Delete
}
[100] Fix | Delete
else
[101] Fix | Delete
$error->add('recaptcha_error', __( '<strong>ERROR</strong> : Please verify the captcha.'));
[102] Fix | Delete
return $error;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
[106] Fix | Delete
function sendIpBlockedNotification($ipAddress, $reason)
[107] Fix | Delete
{
[108] Fix | Delete
global $MoMmpUtility;
[109] Fix | Delete
$subject = 'User with IP address '.$ipAddress.' is blocked | '.get_bloginfo();
[110] Fix | Delete
$toEmail = get_option('admin_email_address');
[111] Fix | Delete
$content = "";
[112] Fix | Delete
if(get_option('custom_admin_template'))
[113] Fix | Delete
{
[114] Fix | Delete
$content = get_option('custom_admin_template');
[115] Fix | Delete
$content = str_replace("##ipaddress##",$ipAddress,$content);
[116] Fix | Delete
}
[117] Fix | Delete
else
[118] Fix | Delete
$content = $this->getMessageContent($reason,$ipAddress);
[119] Fix | Delete
if(isset($content))
[120] Fix | Delete
return $this->wp_mail_send_notification($toEmail,$subject,$content);
[121] Fix | Delete
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
function wp_mail_send_notification($toEmail,$subject,$content){
[125] Fix | Delete
$headers = array('Content-Type: text/html; charset=UTF-8');
[126] Fix | Delete
wp_mail( $toEmail, $subject, $content, $headers);
[127] Fix | Delete
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
[131] Fix | Delete
function sendNotificationToUserForUnusualActivities($username, $ipAddress, $reason)
[132] Fix | Delete
{
[133] Fix | Delete
$content = "";
[134] Fix | Delete
//check if email not already sent
[135] Fix | Delete
if(get_option($ipAddress.$reason)){
[136] Fix | Delete
return json_encode(array("status"=>'SUCCESS','statusMessage'=>'SUCCESS'));
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
global $MoMmpUtility;
[140] Fix | Delete
[141] Fix | Delete
$user = get_user_by( 'login', $username );
[142] Fix | Delete
if($user && !empty($user->user_email))
[143] Fix | Delete
$toEmail = $user->user_email;
[144] Fix | Delete
else
[145] Fix | Delete
return;
[146] Fix | Delete
[147] Fix | Delete
$mo_wpns_config = new MoMmpHandler();
[148] Fix | Delete
if($mo_wpns_config->is_email_sent_to_user($username,$ipAddress))
[149] Fix | Delete
return;
[150] Fix | Delete
[151] Fix | Delete
$fromEmail = get_option('mo_wpns_admin_email');
[152] Fix | Delete
$subject = 'Sign in from new location for your user account | '.get_bloginfo();
[153] Fix | Delete
[154] Fix | Delete
if(get_option('custom_user_template'))
[155] Fix | Delete
{
[156] Fix | Delete
$content = get_option('custom_user_template');
[157] Fix | Delete
$content = str_replace("##ipaddress##",$ipAddress,$content);
[158] Fix | Delete
$content = str_replace("##username##",$username,$content);
[159] Fix | Delete
}
[160] Fix | Delete
else
[161] Fix | Delete
$content = $this->getMessageContent($reason,$ipAddress,$username,$fromEmail);
[162] Fix | Delete
[163] Fix | Delete
return $this->wp_mail_send_notification($toEmail,$subject,$content,$fromEmail);
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
//Check if null what will be the message
[167] Fix | Delete
function getMessageContent($reason,$ipAddress,$username=null,$fromEmail=null)
[168] Fix | Delete
{
[169] Fix | Delete
switch($reason)
[170] Fix | Delete
{
[171] Fix | Delete
case MoMmpConstants::LOGIN_ATTEMPTS_EXCEEDED:
[172] Fix | Delete
$content = "Hello,<br><br>The user with IP Address <b>".$ipAddress."</b> has exceeded allowed failed login attempts on your website <b>".get_bloginfo()."</b> and we have blocked his IP address for further access to website.<br><br>You can login to your WordPress dashaboard to check more details.<br><br>Thanks,<br>miniOrange" ;
[173] Fix | Delete
return $content;
[174] Fix | Delete
case MoMmpConstants::IP_RANGE_BLOCKING:
[175] Fix | Delete
$content = "Hello,<br><br>The user's IP Address <b>".$ipAddress."</b> was found in IP Range specified by you in Advanced IP Blocking and we have blocked his IP address for further access to your website <b>".get_bloginfo()."</b>.<br><br>You can login to your WordPress dashaboard to check more details.<br><br>Thanks,<br>miniOrange" ;
[176] Fix | Delete
return $content;
[177] Fix | Delete
case MoMmpConstants::LOGGED_IN_FROM_NEW_IP:
[178] Fix | Delete
$content = "Hello ".$username.",<br><br>Your account was logged in from new IP Address <b>".$ipAddress."</b> on website <b>".get_bloginfo()."</b>. Please <a href='mailto:".$fromEmail."'>contact us</a> if you don't recognise this activity.<br><br>Thanks,<br>".get_bloginfo() ;
[179] Fix | Delete
return $content;
[180] Fix | Delete
case MoMmpConstants::FAILED_LOGIN_ATTEMPTS_FROM_NEW_IP:
[181] Fix | Delete
$subject = 'Someone trying to access you account | '.get_bloginfo();
[182] Fix | Delete
$content = "Hello ".$username.",<br><br>Someone tried to login to your account from new IP Address <b>".$ipAddress."</b> on website <b>".get_bloginfo()."</b> with failed login attempts. Please <a href='mailto:".$fromEmail."'>contact us</a> if you don't recognise this activity.<br><br>Thanks,<br>".get_bloginfo() ;
[183] Fix | Delete
return $content;
[184] Fix | Delete
default:
[185] Fix | Delete
if(is_null($username))
[186] Fix | Delete
$content = "Hello,<br><br>The user with IP Address <b>".$ipAddress."</b> has exceeded allowed trasaction limit on your website <b>".get_bloginfo()."</b> and we have blocked his IP address for further access to website.<br><br>You can login to your WordPress dashaboard to check more details.<br><br>Thanks,<br>miniOrange" ;
[187] Fix | Delete
else
[188] Fix | Delete
$content = "Hello ".$username.",<br><br>Your account was logged in from new IP Address <b>".$ipAddress."</b> on website <b>".get_bloginfo()."</b>. Please <a href='mailto:".$fromEmail."'>contact us</a> if you don't recognise this activity.<br><br>Thanks,<br>".get_bloginfo() ;
[189] Fix | Delete
return $content;
[190] Fix | Delete
}
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
function getCurrentBrowser()
[194] Fix | Delete
{
[195] Fix | Delete
$useragent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
[196] Fix | Delete
if(empty($useragent))
[197] Fix | Delete
return false;
[198] Fix | Delete
[199] Fix | Delete
$useragent = strtolower($useragent);
[200] Fix | Delete
if(strpos($useragent, 'edge') !== false)
[201] Fix | Delete
return 'edge';
[202] Fix | Delete
else if(strpos($useragent, 'opr') !== false)
[203] Fix | Delete
return 'opera';
[204] Fix | Delete
else if(strpos($useragent, 'chrome') !== false || strpos($useragent, 'CriOS') !== false)
[205] Fix | Delete
return 'chrome';
[206] Fix | Delete
else if(strpos($useragent, 'firefox') !== false)
[207] Fix | Delete
return 'firefox';
[208] Fix | Delete
else if(strpos($useragent, 'msie') !== false || strpos($useragent, 'trident') !==false)
[209] Fix | Delete
return 'ie';
[210] Fix | Delete
else if(strpos($useragent, 'safari') !== false)
[211] Fix | Delete
return 'safari';
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
}
[215] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function