本文整理汇总了PHP中ITSEC_Lib类的典型用法代码示例。如果您正苦于以下问题:PHP ITSEC_Lib类的具体用法?PHP ITSEC_Lib怎么用?PHP ITSEC_Lib使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ITSEC_Lib类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ssl_redirect
/**
* Redirects to or from SSL where appropriate
*
* @return void
*/
function ssl_redirect()
{
global $post;
$hide_options = get_site_option('itsec_hide_backend');
if (isset($hide_options['enabled']) && $hide_options['enabled'] === true && $_SERVER['REQUEST_URI'] == ITSEC_Lib::get_home_root() . $hide_options['slug']) {
return;
}
if (is_singular() && $this->settings['frontend'] == 1) {
$require_ssl = get_post_meta($post->ID, 'itsec_enable_ssl', true);
$bwps_ssl = get_post_meta($post->ID, 'bwps_enable_ssl', true);
if ($bwps_ssl == 1) {
$require_ssl = 1;
delete_post_meta($post->ID, 'bwps_enable_ssl');
update_post_meta($post->ID, 'itsec_enable_ssl', true);
} elseif ($bwps_ssl != 1) {
delete_post_meta($post->ID, 'bwps_enable_ssl');
if ($require_ssl != 1) {
delete_post_meta($post->ID, 'itsec_enable_ssl');
}
}
if ($require_ssl == 1 && $this->is_ssl() === false || $require_ssl != 1 && $this->is_ssl() === true) {
$href = ($_SERVER['SERVER_PORT'] == '443' ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
wp_redirect($href, 302);
}
} else {
if ($this->settings['frontend'] == 2 && !$this->is_ssl() || ($this->settings['frontend'] == 0 || $this->settings['frontend'] == 1) && $this->is_ssl()) {
$href = ($_SERVER['SERVER_PORT'] == '443' ? 'http' : 'https') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
wp_redirect($href, 302);
}
}
}
示例2: run
function run($core)
{
$this->core = $core;
$this->settings = get_site_option('itsec_malware');
$this->module_path = ITSEC_Lib::get_module_path(__FILE__);
add_action('itsec_add_admin_meta_boxes', array($this, 'add_admin_meta_boxes'));
//add meta boxes to admin page
add_action('itsec_admin_init', array($this, 'initialize_admin'));
//initialize admin area
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
//enqueue scripts for admin page
add_action('wp_ajax_itsec_malware_request_url_scan_ajax', array($this, 'wp_ajax_itsec_malware_request_url_scan_ajax'));
//Execute manual homepage scan request
add_action('wp_ajax_itsec_malware_get_scan_results_ajax', array($this, 'wp_ajax_itsec_malware_get_scan_results_ajax'));
//Execute manual homepage scan report
add_filter('itsec_add_dashboard_status', array($this, 'dashboard_status'));
//add information for plugin status
add_filter('itsec_tracking_vars', array($this, 'tracking_vars'));
add_filter('itsec_logger_displays', array($this, 'itsec_logger_displays'));
//adds logs metaboxes
//manually save options on multisite
if (is_multisite()) {
add_action('itsec_admin_init', array($this, 'save_network_options'));
//save multisite options
}
}
示例3: 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'));
}
示例4: get_files
/**
* Returns directory contents
*
* @since 4.3
*
* @param string $dir the directory to scan
* @param string $parent the parent directory (if needed
*
* @return array
*/
private function get_files($dir = '', $parent = null)
{
if ($parent === null) {
$parent = ITSEC_Lib::get_home_path();
}
$rel_dir = trim(sanitize_text_field($dir));
$directory = trim(trailingslashit(urldecode(trailingslashit(sanitize_text_field($parent)) . $rel_dir)));
$dir_contents = array();
if (file_exists($directory)) {
$files = scandir($directory);
natcasesort($files);
if (count($files) > 2) {
/* The 2 accounts for . and .. */
//two loops keep directories sorted before files
// All dirs
foreach ($files as $file) {
if (file_exists($directory . $file) && $file != '.' && $file != '..' && is_dir($directory . $file)) {
//echo $dir . ', ' . $directory . PHP_EOL;
$dir_contents[$file] = $this->get_files($file, $directory);
}
}
// All files
foreach ($files as $file) {
if (file_exists($directory . $file) && $file != '.' && $file != '..' && !is_dir($directory . $file)) {
//echo $file . PHP_EOL;
$dir_contents[] = $file;
}
}
}
}
return $dir_contents;
}
示例5: build_rewrite_rules
/**
* Build rewrite rules
*
* @since 4.0
*
* @param array $input options to build rules from
*
* @return array rules to write
*/
public static function build_rewrite_rules($input = null)
{
$home_root = ITSEC_Lib::get_home_root();
$server_type = ITSEC_Lib::get_server();
//Get the server type to build the right rules
//Get the rules from the database if input wasn't sent
if ($input === null) {
$input = get_site_option('itsec_hide_backend');
}
$rules = '';
//initialize all rules to blank string
//don't add any rules if the module hasn't been enabled
if ($input['enabled'] == true) {
if ($server_type == 'nginx') {
$rules .= "\t# " . __('Rules to hide the dashboard', 'it-l10n-ithemes-security-pro') . PHP_EOL . "\trewrite ^(" . $home_root . ")?" . $input['slug'] . "/?\$ " . $home_root . "wp-login.php?\$query_string break;" . PHP_EOL;
} else {
$rules .= "\t# " . __('Rules to hide the dashboard', 'it-l10n-ithemes-security-pro') . PHP_EOL . "\tRewriteRule ^(" . $home_root . ")?" . $input['slug'] . "/?\$ " . $home_root . "wp-login.php [QSA,L]" . PHP_EOL;
}
if ($input['register'] != 'wp-register.php') {
if ($server_type == 'nginx') {
$rules .= "\trewrite ^(" . $home_root . ")?" . $input['register'] . "/?\$ " . $home_root . $input['slug'] . "?action=register break;" . PHP_EOL;
} else {
$rules .= "\tRewriteRule ^(" . $home_root . ")?" . $input['register'] . "/?\$ /wplogin?action=register [QSA,L]" . PHP_EOL;
}
}
}
if (strlen($rules) > 0) {
$rules = explode(PHP_EOL, $rules);
} else {
$rules = false;
}
//create a proper array for writing
return array('type' => 'htaccess', 'priority' => 9, 'name' => 'Hide Backend', 'rules' => $rules);
}
示例6: execute_upgrade
/**
* Execute module upgrade
*
* @since 4.0
*
* @return void
*/
public function execute_upgrade($itsec_old_version)
{
if ($itsec_old_version < 4000) {
global $itsec_bwps_options;
ITSEC_Lib::create_database_tables();
$current_options = get_site_option('itsec_tweaks');
if ($current_options === false) {
$current_options = $this->defaults;
}
$current_options['protect_files'] = isset($itsec_bwps_options['st_ht_files']) && $itsec_bwps_options['st_ht_files'] == 1 ? true : false;
$current_options['directory_browsing'] = isset($itsec_bwps_options['st_ht_browsing']) && $itsec_bwps_options['st_ht_browsing'] == 1 ? true : false;
$current_options['request_methods'] = isset($itsec_bwps_options['st_ht_request']) && $itsec_bwps_options['st_ht_request'] == 1 ? true : false;
$current_options['suspicious_query_strings'] = isset($itsec_bwps_options['st_ht_query']) && $itsec_bwps_options['st_ht_query'] == 1 ? true : false;
$current_options['non_english_characters'] = isset($itsec_bwps_options['st_ht_foreign']) && $itsec_bwps_options['st_ht_foreign'] == 1 ? true : false;
$current_options['long_url_strings'] = isset($itsec_bwps_options['st_longurl']) && $itsec_bwps_options['st_longurl'] == 1 ? true : false;
$current_options['write_permissions'] = isset($itsec_bwps_options['st_fileperm']) && $itsec_bwps_options['st_fileperm'] == 1 ? true : false;
$current_options['wlwmanifest_header'] = isset($itsec_bwps_options['st_manifest']) && $itsec_bwps_options['st_manifest'] == 1 ? true : false;
$current_options['edituri_header'] = isset($itsec_bwps_options['st_edituri']) && $itsec_bwps_options['st_edituri'] == 1 ? true : false;
$current_options['theme_updates'] = isset($itsec_bwps_options['st_themenot']) && $itsec_bwps_options['st_themenot'] == 1 ? true : false;
$current_options['plugin_updates'] = isset($itsec_bwps_options['st_pluginnot']) && $itsec_bwps_options['st_pluginnot'] == 1 ? true : false;
$current_options['core_updates'] = isset($itsec_bwps_options['st_corenot']) && $itsec_bwps_options['st_corenot'] == 1 ? true : false;
$current_options['comment_spam'] = isset($itsec_bwps_options['st_comment']) && $itsec_bwps_options['st_comment'] == 1 ? true : false;
$current_options['login_errors'] = isset($itsec_bwps_options['st_loginerror']) && $itsec_bwps_options['st_loginerror'] == 1 ? true : false;
update_site_option('itsec_tweaks', $current_options);
add_site_option('itsec_rewrites_changed', true);
add_site_option('itsec_config_changed', true);
}
if ($itsec_old_version < 4035) {
add_site_option('itsec_rewrites_changed', true);
}
}
示例7: run
function run( $core ) {
$this->defaults = array(
'enabled' => false,
'email_notifications' => true,
'email_contacts' => array(),
);
$this->core = $core;
$this->settings = get_site_option( 'itsec_malware_scheduling' );
$this->module_path = ITSEC_Lib::get_module_path( __FILE__ );
if ( ! is_array( $this->settings ) ) {
$this->settings = array();
}
$this->settings = array_merge( $this->defaults, $this->settings );
add_action( 'itsec_add_admin_meta_boxes', array( $this, 'itsec_add_admin_meta_boxes' ) ); //add meta boxes to admin page
add_action( 'itsec_admin_init', array( $this, 'itsec_admin_init' ) ); //initialize admin area
add_filter( 'itsec_add_dashboard_status', array( $this, 'dashboard_status' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); //enqueue scripts for admin page
add_action( 'wp_ajax_itsec_jquery_malware_filetree_ajax', array( $this, 'wp_ajax_itsec_jquery_malware_filetree_ajax' ) );
//manually save options on multisite
if ( is_multisite() ) {
add_action( 'itsec_admin_init', array( $this, 'itsec_admin_init_multisite' ) ); //save multisite options
}
}
示例8: run
function run( $core ) {
$this->core = $core;
$this->module_path = ITSEC_Lib::get_module_path( __FILE__ );
add_action( 'admin_init', array( $this, 'admin_init' ) );
}
示例9: 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;
}
示例10: run
function run($core)
{
$this->settings = true;
$this->core = $core;
$this->module_path = ITSEC_Lib::get_module_path(__FILE__);
add_action('itsec_add_admin_meta_boxes', array($this, 'itsec_add_admin_meta_boxes'));
//add meta boxes to admin page
add_action('itsec_admin_init', array($this, 'itsec_admin_init'));
//initialize admin area
}
示例11: run
function run()
{
$this->settings = get_site_option('itsec_privilege');
$this->module_path = ITSEC_Lib::get_module_path(__FILE__);
add_action('admin_init', array($this, 'admin_init'));
add_action('edit_user_profile', array($this, 'edit_user_profile'));
add_action('edit_user_profile_update', array($this, 'edit_user_profile_update'));
add_action('init', array($this, 'init'), 1);
add_action('switch_blog', array($this, 'init'));
}
示例12: render_settings
protected function render_settings($form)
{
?>
<div class="itsec-warning-message"><?php
printf(__('<span>Warning:</span> The changes made by this tool could cause compatibility issues with some plugins, themes, or customizations. Ensure that you <a href="%s">create a database backup</a> before using this tool.', 'better-wp-security'), esc_url(ITSEC_Core::get_backup_creation_page_url()));
?>
</div>
<table class="form-table itsec-settings-section">
<?php
if (username_exists('admin')) {
?>
<tr>
<th scope="row"><label for="itsec-admin-user-new_username"><?php
_e('New Admin Username', 'better-wp-security');
?>
</label></th>
<td>
<?php
$form->add_text('new_username', array('class' => 'code'));
?>
<br />
<p class="description"><?php
_e('Enter a new username to replace "admin." Please note that if you are logged in as admin you will have to log in again.', 'better-wp-security');
?>
</p>
</td>
</tr>
<?php
}
?>
<?php
if (ITSEC_Lib::user_id_exists(1)) {
?>
<tr>
<th scope="row"><label for="itsec-admin-user-change_id"><?php
_e('Change User ID 1', 'better-wp-security');
?>
</label></th>
<td>
<?php
$form->add_checkbox('change_id');
?>
<label for="itsec-admin-user-change_id"><?php
_e('Change the ID of the user with ID 1.', 'better-wp-security');
?>
</label>
</td>
</tr>
<?php
}
?>
</table>
<?php
}
示例13: 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;
}
示例14: filter_nginx_server_config_modification
public static function filter_nginx_server_config_modification($modification, $settings)
{
$home_root = ITSEC_Lib::get_home_root();
$modification .= "\n";
$modification .= "\t# " . __('Enable the hide backend feature - Security > Settings > Hide Login Area > Hide Backend', 'better-wp-security') . "\n";
$modification .= "\trewrite ^({$home_root})?{$settings['slug']}/?\$ {$home_root}wp-login.php?\$query_string break;\n";
if ('wp-register.php' != $settings['register']) {
$modification .= "\trewrite ^({$home_root})?{$settings['register']}/?\$ {$home_root}{$settings['slug']}?action=register break;\n";
}
return $modification;
}
示例15: 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;
}
}