本文整理汇总了PHP中ITSEC_Lib::get_ip方法的典型用法代码示例。如果您正苦于以下问题:PHP ITSEC_Lib::get_ip方法的具体用法?PHP ITSEC_Lib::get_ip怎么用?PHP ITSEC_Lib::get_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITSEC_Lib
的用法示例。
在下文中一共展示了ITSEC_Lib::get_ip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sanitize_settings
protected function sanitize_settings()
{
$this->sanitize_setting('bool', 'default', __('Default Blacklist', 'better-wp-security'));
$this->sanitize_setting('bool', 'enable_ban_lists', __('Ban Lists', 'better-wp-security'));
$this->sanitize_setting('newline-separated-ips', 'host_list', __('Ban Hosts', 'better-wp-security'));
if (is_array($this->settings['host_list'])) {
require_once ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-ip-tools.php';
$whitelisted_hosts = array();
$current_ip = ITSEC_Lib::get_ip();
foreach ($this->settings['host_list'] as $host) {
if (is_user_logged_in() && ITSEC_Lib_IP_Tools::intersect($current_ip, ITSEC_Lib_IP_Tools::ip_wild_to_ip_cidr($host))) {
$this->set_can_save(false);
/* translators: 1: input name, 2: invalid host */
$this->add_error(sprintf(__('The following host in %1$s matches your current IP and cannot be banned: %2$s', 'better-wp-security'), __('Ban Hosts', 'better-wp-security'), $host));
continue;
}
if (ITSEC_Lib::is_ip_whitelisted($host)) {
$whitelisted_hosts[] = $host;
}
}
if (!empty($whitelisted_hosts)) {
$this->set_can_save(false);
/* translators: 1: input name, 2: invalid host list */
$this->add_error(wp_sprintf(_n('The following IP in %1$s is whitelisted and cannot be banned: %2$l', 'The following IPs in %1$s are whitelisted and cannot be banned: %2$l', count($whitelisted_hosts), 'better-wp-security'), __('Ban Hosts', 'better-wp-security'), $whitelisted_hosts));
}
}
$this->sanitize_setting(array($this, 'sanitize_agent_list_entry'), 'agent_list', __('Ban User Agents', 'better-wp-security'));
}
示例2: is_ip_whitelisted
/**
* Determines whether a given IP address is whitelisted
*
* @param string $ip_to_check ip to check
* @param array $white_ips ip list to compare to if not yet saved to options
* @param boolean $current whether to whitelist the current ip or not (due to saving, etc)
*
* @return boolean true if whitelisted or false
*/
public static function is_ip_whitelisted($ip_to_check, $white_ips = null, $current = false)
{
$ip_to_check = trim($ip_to_check);
if ($white_ips === null) {
$global_settings = get_site_option('itsec_global');
$white_ips = isset($global_settings['lockout_white_list']) ? $global_settings['lockout_white_list'] : array();
}
if ($current === true) {
$white_ips[] = ITSEC_Lib::get_ip();
//add current user ip to whitelist to check automatically
}
foreach ($white_ips as $white_ip) {
$converted_white_ip = ITSEC_Lib::ip_wild_to_mask($white_ip);
$check_range = ITSEC_Lib::cidr_to_range($converted_white_ip);
$ip_range = ITSEC_Lib::cidr_to_range($ip_to_check);
if (sizeof($check_range) === 2) {
//range to check
$check_min = ip2long($check_range[0]);
$check_max = ip2long($check_range[1]);
if (sizeof($ip_range) === 2) {
$ip_min = ip2long($ip_range[0]);
$ip_max = ip2long($ip_range[1]);
/**
* Checks cover the following scenarios:
* - min-a, min-b, max-a, max-b : min-b is in a range and min-a is in b range
* - min-b, min-a, max-b, max-a : max-b is in a range and max-a is in b range
* - min-a, min-b, max-b, max-a : range b is encapsulated by range a
* - min-b, min-a, max-a, max-b : range a is encapsulated by range b
*/
if ($check_min <= $ip_min && $ip_min <= $check_max || $check_min <= $ip_max && $ip_max <= $check_max || $ip_min <= $check_min && $check_min <= $ip_max || $ip_min <= $check_max && $check_max <= $ip_max) {
return true;
}
} else {
$ip = ip2long($ip_range[0]);
if ($check_min <= $ip && $ip <= $check_max) {
return true;
}
}
} else {
//single ip to check
$check = ip2long($check_range[0]);
if (sizeof($ip_range) === 2) {
$ip_min = ip2long($ip_range[0]);
$ip_max = ip2long($ip_range[1]);
if ($ip_min <= $check && $check <= $ip_max) {
return true;
}
} else {
$ip = ip2long($ip_range[0]);
if ($check == $ip) {
return true;
}
}
}
}
return false;
}
示例3: scan
public static function scan()
{
global $itsec_logger;
$results = self::get_scan_results();
if (is_array($results) && isset($results['cached']) && $results['cached']) {
return $results;
}
$user = wp_get_current_user();
$itsec_logger->log_event('malware', 3, $results, ITSEC_Lib::get_ip(), $user->user_login, $user->ID);
return $results;
}
示例4: run_active_check
/**
* Execute away mode functionality
*
* @return void
*/
public function run_active_check()
{
global $itsec_logger;
//execute lockout if applicable
if (self::is_active()) {
$itsec_logger->log_event('away_mode', 5, array(__('A host was prevented from accessing the dashboard due to away-mode restrictions being in effect', 'better-wp-security')), ITSEC_Lib::get_ip(), '', '', '', '');
wp_redirect(get_option('siteurl'));
wp_clear_auth_cookie();
die;
}
}
示例5: is_ip_whitelisted
/**
* Determines whether a given IP address is whitelisted
*
* @param string $ip_to_check ip to check
* @param array $white_ips ip list to compare to if not yet saved to options
* @param boolean $current whether to whitelist the current ip or not (due to saving, etc)
*
* @return boolean true if whitelisted or false
*/
public static function is_ip_whitelisted($ip_to_check, $white_ips = null, $current = false)
{
$ip_to_check = trim($ip_to_check);
if ($white_ips === null) {
$global_settings = get_site_option('itsec_global');
$white_ips = isset($global_settings['lockout_white_list']) ? $global_settings['lockout_white_list'] : array();
}
if ($current === true) {
$white_ips[] = ITSEC_Lib::get_ip();
//add current user ip to whitelist to check automatically
}
foreach ($white_ips as $white_ip) {
$converted_white_ip = ITSEC_Lib::ip_wild_to_mask($white_ip);
$check_range = ITSEC_Lib::cidr_to_range($converted_white_ip);
$ip_range = ITSEC_Lib::cidr_to_range($ip_to_check);
if (sizeof($check_range) === 2) {
//range to check
$check_min = ip2long($check_range[0]);
$check_max = ip2long($check_range[1]);
if (sizeof($ip_range) === 2) {
$ip_min = ip2long($ip_range[0]);
$ip_max = ip2long($ip_range[1]);
if ($check_min < $ip_min && $ip_min < $check_max || $check_min < $ip_max && $ip_max < $check_max) {
return true;
}
} else {
$ip = ip2long($ip_range[0]);
if ($check_min < $ip && $ip < $check_max) {
return true;
}
}
} else {
//single ip to check
$check = ip2long($check_range[0]);
if (sizeof($ip_range) === 2) {
$ip_min = ip2long($ip_range[0]);
$ip_max = ip2long($ip_range[1]);
if ($ip_min < $check && $check < $ip_max) {
return true;
}
} else {
$ip = ip2long($ip_range[0]);
if ($check == $ip) {
return true;
}
}
}
}
return false;
}
示例6: execute_brute_force_no_password
/**
* Sends to lockout class when login form isn't completely filled out
*
* @param object $user user or wordpress error
* @param string $username username attempted
* @param string $password password attempted
*
* @return user object or WordPress error
*/
public function execute_brute_force_no_password($user, $username = '', $password = '')
{
global $itsec_lockout, $itsec_logger;
if (isset($_POST['wp-submit']) && (empty($username) || empty($password))) {
$user_id = username_exists(sanitize_text_field($username));
if ($user_id === false || $user_id === NULL) {
$itsec_lockout->check_lockout(false, $username);
} else {
$itsec_lockout->check_lockout($user_id);
}
$itsec_logger->log_event('brute_force', 5, array(), ITSEC_Lib::get_ip(), sanitize_text_field($username), intval($user_id));
$itsec_lockout->do_lockout('brute_force', sanitize_text_field($username));
}
return $user;
}
示例7: check_404
/**
* If the page is a WordPress 404 error log it and register for lockout
*
* @return void
*/
public function check_404()
{
global $itsec_logger, $itsec_lockout;
if (!is_404()) {
return;
}
$uri = explode('?', $_SERVER['REQUEST_URI']);
if (!is_array($this->settings['white_list']) || in_array($uri[0], $this->settings['white_list'])) {
// Invalid settings or white listed page.
return;
}
$itsec_logger->log_event('four_oh_four', 3, array('query_string' => isset($uri[1]) ? esc_sql($uri[1]) : ''), ITSEC_Lib::get_ip(), '', '', esc_sql($uri[0]), isset($_SERVER['HTTP_REFERER']) ? esc_sql($_SERVER['HTTP_REFERER']) : '');
$path_info = pathinfo($uri[0]);
if (!isset($path_info['extension']) || is_array($this->settings['types']) && !in_array('.' . $path_info['extension'], $this->settings['types'])) {
$itsec_lockout->do_lockout('four_oh_four');
}
}
示例8: execute_brute_force_no_password
/**
* Sends to lockout class when login form isn't completely filled out
*
* @param object $user user or wordpress error
* @param string $username username attempted
* @param string $password password attempted
*
* @return user object or WordPress error
*/
public function execute_brute_force_no_password($user, $username = '', $password = '')
{
global $itsec_lockout, $itsec_logger;
if (isset($this->settings['auto_ban_admin']) && $this->settings['auto_ban_admin'] === true && trim(sanitize_text_field($username)) == 'admin') {
$itsec_logger->log_event('brute_force', 5, array(), ITSEC_Lib::get_ip(), sanitize_text_field($username));
$itsec_lockout->do_lockout('brute_force_admin_user', sanitize_text_field($username));
}
if (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST === true || isset($_POST['wp-submit']) && (empty($username) || empty($password))) {
$user_id = username_exists(sanitize_text_field($username));
if ($user_id === false || $user_id === NULL) {
$itsec_lockout->check_lockout(false, $username);
} else {
$itsec_lockout->check_lockout($user_id);
}
$itsec_logger->log_event('brute_force', 5, array(), ITSEC_Lib::get_ip(), sanitize_text_field($username), intval($user_id));
$itsec_lockout->do_lockout('brute_force', sanitize_text_field($username));
}
return $user;
}
示例9: check_404
/**
* If the page is a WordPress 404 error log it and register for lockout
*
* @return void
*/
public function check_404()
{
global $itsec_logger, $itsec_lockout;
if ($this->settings['enabled'] === true && is_404()) {
$uri = explode('?', $_SERVER['REQUEST_URI']);
if (isset($this->settings['white_list']) && !is_array($this->settings['white_list'])) {
$this->settings['white_list'] = explode(PHP_EOL, $this->settings['white_list']);
} elseif (!isset($this->settings['white_list'])) {
$this->settings['white_list'] = array();
}
if (in_array($uri[0], $this->settings['white_list']) === false) {
$itsec_logger->log_event('four_oh_four', 3, array('query_string' => isset($uri[1]) ? esc_sql($uri[1]) : ''), ITSEC_Lib::get_ip(), '', '', esc_sql($uri[0]), isset($_SERVER['HTTP_REFERER']) ? esc_sql($_SERVER['HTTP_REFERER']) : '');
$path_info = pathinfo($uri[0]);
if (!isset($path_info['extension']) || isset($this->settings['types']) && is_array($this->settings['types']) && in_array('.' . $path_info['extension'], $this->settings['types']) === false) {
$itsec_lockout->do_lockout('four_oh_four');
}
}
}
}
示例10: xmlrpc_login_error
/**
* Execute brute force against xml_rpc login
*
* @Since 4.4
*
* @param mixed $error WordPress error
*
* @return mixed WordPress error
*/
public function xmlrpc_login_error($error)
{
global $itsec_lockout, $itsec_logger;
if (isset($this->settings['auto_ban_admin']) && $this->settings['auto_ban_admin'] === true && trim(sanitize_text_field($this->username)) == 'admin') {
$itsec_logger->log_event('brute_force', 5, array(), ITSEC_Lib::get_ip(), $this->username);
$itsec_lockout->do_lockout('brute_force_admin_user', $this->username);
} else {
$user_id = username_exists($this->username);
if ($user_id === false || $user_id === null) {
$itsec_lockout->check_lockout(false, $this->username);
} else {
$itsec_lockout->check_lockout($user_id);
}
$itsec_logger->log_event('brute_force', 5, array(), ITSEC_Lib::get_ip(), $this->username, intval($user_id));
$itsec_lockout->do_lockout('brute_force', $this->username);
}
return $error;
}
示例11: execute_away_mode
/**
* Execute away mode functionality
*
* @return void
*/
public function execute_away_mode()
{
global $itsec_logger;
//execute lockout if applicable
if ($this->check_away()) {
$itsec_logger->log_event('away_mode', 5, array(__('A host was prevented from accessing the dashboard due to away-mode restrictions being in effect', 'it-l10n-ithemes-security-pro')), ITSEC_Lib::get_ip(), '', '', '', '');
wp_redirect(get_option('siteurl'));
wp_clear_auth_cookie();
}
}
示例12: _e
?>
</h4>
<ul>
<li><?php
_e('Public IP Address', 'it-l10n-better-wp-security');
?>
: <strong><a target="_blank"
title="<?php
_e('Get more information on this address', 'it-l10n-better-wp-security');
?>
"
href="http://whois.domaintools.com/<?php
echo ITSEC_Lib::get_ip();
?>
"><?php
echo ITSEC_Lib::get_ip();
?>
</a></strong>
</li>
<li><?php
_e('User Agent', 'it-l10n-better-wp-security');
?>
:
<strong><?php
echo filter_var($_SERVER['HTTP_USER_AGENT'], FILTER_SANITIZE_STRING);
?>
</strong></li>
</ul>
</li>
<li>
示例13: validate_captcha
/**
* Validates the captcha code
*
* @since 1.13
*
* @return int status of captcha
*/
public static function validate_captcha() {
global $itsec_lockout, $itsec_logger;
$settings = get_site_option( 'itsec_recaptcha' );
if ( ! isset( $settings['site_key'] ) ) {
return - 2;
}
if ( ! isset( $_POST['g-recaptcha-response'] ) || empty( $_POST['g-recaptcha-response'] ) ) {
$itsec_logger->log_event(
'recaptcha',
5,
array(),
ITSEC_Lib::get_ip(),
'',
'',
esc_sql( $_SERVER['REQUEST_URI'] ),
isset( $_SERVER['HTTP_REFERER'] ) ? esc_sql( $_SERVER['HTTP_REFERER'] ) : ''
);
$itsec_lockout->do_lockout( 'recaptcha' );
return - 1; //captcha form not submitted
} else {
$url = add_query_arg(
array(
'secret' => $settings['secret_key'],
'response' => esc_attr( $_POST['g-recaptcha-response'] ),
'remoteip' => ITSEC_Lib::get_ip(),
),
'https://www.google.com/recaptcha/api/siteverify'
);
$response = wp_remote_get( $url );
if ( ! is_wp_error( $response ) ) {
$status = json_decode( $response['body'] );
if ( isset( $status->success ) ) {
return 1; //captcha validated successfully
} else {
$itsec_logger->log_event(
'recaptcha',
5,
array(),
ITSEC_Lib::get_ip(),
'',
'',
esc_sql( $_SERVER['REQUEST_URI'] ),
isset( $_SERVER['HTTP_REFERER'] ) ? esc_sql( $_SERVER['HTTP_REFERER'] ) : ''
);
$itsec_lockout->do_lockout( 'recaptcha' );
return 0; //incorrect captcha entered
}
} else {
return - 2; //captcha couldn't be validated
}
}
}
示例14: itsec_temp_whitelist_ajax
/**
* Process ajax request to set temp whitelist
*
* @since 4.3
*
* @return void
*/
public function itsec_temp_whitelist_ajax()
{
global $itsec_globals;
if (!isset($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field($_POST['nonce']), 'itsec_temp_whitelist_nonce')) {
die;
}
$add_temp = false;
$current_ip = ITSEC_Lib::get_ip();
$temp_ip = get_site_option('itsec_temp_whitelist_ip');
if ($temp_ip !== false) {
if ($temp_ip['exp'] < $itsec_globals['current_time']) {
delete_site_option('itsec_temp_whitelist_ip');
$add_temp = true;
}
} else {
$add_temp = true;
}
if ($add_temp === false) {
die('error');
} else {
$response = array('ip' => ITSEC_Lib::get_ip(), 'exp' => $itsec_globals['current_time'] + 86400);
add_site_option('itsec_temp_whitelist_ip', $response);
$response['exp'] = date('Y-m-d H:i:s', $response['exp']);
$response['message1'] = __('Your IP Address', 'it-l10n-better-wp-security');
$response['message2'] = __('is whitelisted until', 'it-l10n-better-wp-security');
die(json_encode($response));
}
}
示例15: is_ip_whitelisted
/**
* Determines whether a given IP address is whitelisted
*
* @param string $ip_to_check ip to check (can be in CIDR notation)
* @param array $white_ips ip list to compare to if not yet saved to options
* @param boolean $current whether to whitelist the current ip or not (due to saving, etc)
*
* @return boolean true if whitelisted or false
*/
public static function is_ip_whitelisted($ip_to_check, $white_ips = null, $current = false)
{
if (!class_exists('ITSEC_Lib_IP_Tools')) {
$itsec_core = ITSEC_Core::get_instance();
require_once dirname($itsec_core->get_plugin_file()) . '/core/lib/class-itsec-lib-ip-tools.php';
}
if ($white_ips === null) {
$global_settings = get_site_option('itsec_global');
$white_ips = isset($global_settings['lockout_white_list']) ? $global_settings['lockout_white_list'] : array();
}
if ($current === true) {
$white_ips[] = ITSEC_Lib::get_ip();
//add current user ip to whitelist to check automatically
}
foreach ($white_ips as $white_ip) {
if (ITSEC_Lib_IP_Tools::intersect($ip_to_check, ITSEC_Lib_IP_Tools::ip_wild_to_ip_cidr($white_ip))) {
return true;
}
}
return false;
}