PluginProbe ʕ •ᴥ•ʔ
SiteGuard WP Plugin / 1.5.0
SiteGuard WP Plugin v1.5.0
1.8.7 1.8.6 1.8.6-beta1 1.8.6-beta2 1.8.4 1.8.5 1.8.3 1.8.2 1.8.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.4.3 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.11 1.7.12 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.0-beta1 1.8.0-beta2 1.8.0-beta3 1.8.0-beta4
siteguard / classes / siteguard-base.php
siteguard / classes Last commit date
siteguard-admin-filter.php 6 years ago siteguard-base.php 8 years ago siteguard-captcha.php 8 years ago siteguard-config.php 9 years ago siteguard-disable-pingback.php 9 years ago siteguard-disable-xmlrpc.php 9 years ago siteguard-htaccess.php 8 years ago siteguard-login-alert.php 8 years ago siteguard-login-history.php 8 years ago siteguard-login-lock.php 8 years ago siteguard-rename-login.php 6 years ago siteguard-updates-notify.php 8 years ago siteguard-waf-exclude-rule.php 9 years ago
siteguard-base.php
98 lines
1 <?php
2
3 function siteguard_error_log( $message ) {
4 $logfile = SITEGUARD_PATH . 'error.log';
5 $f = @fopen( $logfile, 'a+' );
6 if ( false != $f ) {
7 fwrite( $f, date_i18n( 'Y/m/d H:i:s:' ) . $message . "\n" );
8 fclose( $f );
9 }
10 }
11
12 function siteguard_error_dump( $title, $obj ) {
13 ob_start();
14 var_dump( $obj );
15 $msg = ob_get_contents( );
16 ob_end_clean( );
17 siteguard_error_log( "$title: $msg" );
18 }
19
20 function siteguard_check_multisite( ) {
21 if ( ! is_multisite() ) {
22 return true;
23 }
24 $message = esc_html__( 'It does not support the multisite function of WordPress.', 'siteguard' );
25 $error = new WP_Error( 'siteguard', $message );
26 return $error;
27 }
28
29 class SiteGuard_Base {
30 public static $ip_mode_items = array( '0', '1', '2', '3' );
31 function __construct() {
32 }
33 function is_switch_value( $value ) {
34 if ( '0' === $value || '1' === $value ) {
35 return true;
36 }
37 return false;
38 }
39 function check_module( $name, $default = false ) {
40 return true;
41 # It does not work WP-CLI
42 #if ( isset( $_SERVER['SERVER_SOFTWARE'] ) ) {
43 # return ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false);
44 #} else {
45 # return $default;
46 #}
47
48 # It does not work in FastCGI well.
49 #$module = 'mod_' . $name;
50 #return apache_mod_loaded( $module, $default );
51 #if ( function_exists('phpinfo') ) {
52 # ob_start( );
53 # phpinfo(8);
54 # $phpinfo = ob_get_clean( );
55 # if ( false !== strpos( $phpinfo, $module ) ) {
56 # return true;
57 # }
58 #}
59 #return $default;
60 }
61
62 function get_ip( ) {
63 global $siteguard_config;
64 $ip_mode = $siteguard_config->get( 'ip_mode' );
65 if ( ! in_array( $ip_mode, SiteGuard_Base::$ip_mode_items ) ) {
66 $ip_mode = '0';
67 $siteguard_config->set( 'ip_mode', $ip_mode );
68 $siteguard_config->update( );
69 }
70 $ip_mode_num = intval( $ip_mode );
71 $remote_addr = '127.0.0.1';
72 if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
73 $remote_addr = $_SERVER['REMOTE_ADDR'];
74 }
75 if ( '0' === $ip_mode ) {
76 return $remote_addr;
77 }
78 if ( ! isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
79 return $remote_addr;
80 }
81 $xff = $_SERVER['HTTP_X_FORWARDED_FOR'];
82 if ( empty( $xff ) ) {
83 return $remote_addr;
84 }
85 $ips = explode( ',', $xff );
86 $count = count( $ips );
87 $idx = $count - $ip_mode_num;
88 if ( $idx < 0 ) {
89 return $remote_addr;
90 }
91 $ip = $ips[ $idx ];
92 if ( ! filter_var($ip, FILTER_VALIDATE_IP ) ) {
93 return $remote_addr;
94 }
95 return $ip;
96 }
97 }
98