PluginProbe ʕ •ᴥ•ʔ
SiteGuard WP Plugin / 1.7.7
SiteGuard WP Plugin v1.7.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 3 years ago siteguard-base.php 3 years ago siteguard-captcha.php 3 years ago siteguard-config.php 3 years ago siteguard-disable-author-query.php 3 years ago siteguard-disable-pingback.php 3 years ago siteguard-disable-xmlrpc.php 3 years ago siteguard-htaccess.php 3 years ago siteguard-login-alert.php 3 years ago siteguard-login-history.php 3 years ago siteguard-login-lock.php 3 years ago siteguard-rename-login.php 2 years ago siteguard-updates-notify.php 3 years ago siteguard-waf-exclude-rule.php 3 years ago
siteguard-base.php
156 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_rand( $min = null, $max = null ) {
21 $ret = 0;
22 mt_srand();
23 if ( $min === null or $max === null ) {
24 $ret = mt_rand();
25 } else {
26 $ret = mt_rand( $min, $max );
27 }
28 return $ret;
29 }
30
31 function siteguard_check_multisite() {
32 if ( ! is_multisite() ) {
33 return true;
34 }
35 $message = esc_html__( 'It does not support the multisite function of WordPress.', 'siteguard' );
36 $error = new WP_Error( 'siteguard', $message );
37 return $error;
38 }
39
40 class SiteGuard_Base {
41 function __construct() {
42 }
43 function is_switch_value( $value ) {
44 if ( '0' === $value || '1' === $value ) {
45 return true;
46 }
47 return false;
48 }
49 function cvt_camma2ret( $value ) {
50 $result = str_replace( ' ', '', $value );
51 return str_replace( ',', "\r\n", $result );
52 }
53 function cvt_ret2camma( $exclude ) {
54 $result = str_replace( ' ', '', $exclude );
55 $result = str_replace( ',', '', $result );
56 $result = preg_replace( '/(\r\n){2,}/', "\r\n", $result );
57 $result = preg_replace( '/\r\n$/', '', $result );
58 $result = str_replace( "\r\n", ',', $result );
59 $result = str_replace( "\r", ',', $result );
60 return str_replace( "\n", ',', $result );
61 }
62 function check_module( $name, $default = false ) {
63 return true;
64 // It does not work WP-CLI
65 // if ( isset( $_SERVER['SERVER_SOFTWARE'] ) ) {
66 // return ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false);
67 // } else {
68 // return $default;
69 // }
70
71 // It does not work in FastCGI well.
72 // $module = 'mod_' . $name;
73 // return apache_mod_loaded( $module, $default );
74 // if ( function_exists('phpinfo') ) {
75 // ob_start( );
76 // phpinfo(8);
77 // $phpinfo = ob_get_clean( );
78 // if ( false !== strpos( $phpinfo, $module ) ) {
79 // return true;
80 // }
81 // }
82 // return $default;
83 }
84 function is_private_ip( $ip ) {
85 $private_ips = array(
86 '10.0.0.0,10.255.255.255',
87 '172.16.0.0,172.31.255.255',
88 '192.168.0.0,192.168.255.255',
89 );
90
91 $long_ip = ip2long( $ip );
92 if ( -1 !== $long_ip && false !== $long_ip ) {
93 $long_ip = sprintf( '%u', $long_ip );
94 foreach ( $private_ips as $private_ip ) {
95 list( $start, $end ) = explode( ',', $private_ip );
96 $long_start = ip2long( $start );
97 $long_start = sprintf( '%u', $long_start );
98 $long_end = ip2long( $end );
99 $long_end = sprintf( '%u', $long_end );
100 if ( $long_ip >= $long_start && $long_ip <= $long_end ) {
101 return true;
102 }
103 }
104 }
105 return false;
106 }
107 function get_server_ip() {
108 if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
109 $ip = sanitize_text_field( $_SERVER['SERVER_ADDR'] );
110 if ( false === $this->is_private_ip( $ip ) ) {
111 if ( preg_match( '/[0-9.:]+/', $ip ) ) {
112 return $ip;
113 }
114 }
115 }
116
117 $url = 'http://inet-ip.info/ip';
118 $options = array(
119 'http' => array(
120 'method' => 'GET',
121 'timeout' => 2,
122 ),
123 );
124 $ip = file_get_contents( $url, false, stream_context_create( $options ) );
125 if ( false !== $ip ) {
126 if ( preg_match( '/[0-9.:]+/', $ip ) ) {
127 return $ip;
128 }
129 }
130
131 $host = parse_url( home_url(), PHP_URL_HOST );
132 if ( false !== $host && null !== $host ) {
133 putenv( 'RES_OPTIONS=retrans:1 retry:1 timeout:2 attempts:1' );
134 $ip = gethostbyname( $host );
135 if ( $ip !== $host ) {
136 if ( '127.0.0.1' !== $ip && '::1' !== $ip ) {
137 if ( preg_match( '/[0-9.:]+/', $ip ) ) {
138 return $ip;
139 }
140 }
141 }
142 }
143 return false;
144 }
145 function get_ip() {
146 if (
147 ! isset( $_SERVER['REMOTE_ADDR'] )
148 || ! is_string( $_SERVER['REMOTE_ADDR'] )
149 || '' === $_SERVER['REMOTE_ADDR']
150 ) {
151 throw new MyPluginBrokenEnvironment( 'Your webserver is misconfigured. REMOTE_ADDR is not set.' );
152 }
153 return sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
154 }
155 }
156