PluginProbe ʕ •ᴥ•ʔ
SiteGuard WP Plugin / 1.8.8
SiteGuard WP Plugin v1.8.8
1.8.9 1.8.8 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 3 months ago siteguard-base.php 3 weeks ago siteguard-captcha.php 2 months ago siteguard-config.php 1 year ago siteguard-disable-author-query.php 2 months ago siteguard-disable-pingback.php 3 months ago siteguard-disable-xmlrpc.php 3 months ago siteguard-htaccess.php 3 weeks ago siteguard-login-alert.php 3 months ago siteguard-login-history.php 2 months ago siteguard-login-lock.php 2 months ago siteguard-rename-login.php 3 weeks ago siteguard-updates-notify.php 2 months ago siteguard-waf-exclude-rule.php 3 months ago
siteguard-base.php
156 lines
1 <?php
2
3 function siteguard_error_log( $message ) {
4 // Use PHP's error_log() so logs go to the server-configured destination
5 // (typically outside the web root) instead of a plugin-directory file
6 // that would be exposed on Nginx (no .htaccess support).
7 error_log( '[SiteGuard] ' . $message );
8 }
9
10 function siteguard_error_dump( $title, $obj ) {
11 ob_start();
12 var_dump( $obj );
13 $msg = ob_get_contents();
14 ob_end_clean();
15 siteguard_error_log( "$title: $msg" );
16 }
17
18 function siteguard_rand( $min = null, $max = null ) {
19 $ret = 0;
20 if ( $min === null or $max === null ) {
21 $ret = mt_rand();
22 } else {
23 $ret = mt_rand( $min, $max );
24 }
25 return $ret;
26 }
27
28 /**
29 * Whether the current request is the plugin's own .htaccess self-test request.
30 *
31 * The self-test asks the server for a file inside a temporary directory under
32 * ABSPATH. When that file cannot be served — the directory was already removed,
33 * or the rewrite under test is ignored — the request falls through to
34 * WordPress, which boots the plugin as usual. Such a request must not perform
35 * any .htaccess bookkeeping of its own: the run that issued it is in the middle
36 * of rebuilding the very state it would inspect, and re-entering upgrade() from
37 * here starts another self-test, and another WordPress boot, and so on.
38 *
39 * @return bool
40 */
41 function siteguard_is_self_test_request() {
42 if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
43 return false;
44 }
45 return ( false !== strpos( (string) $_SERVER['REQUEST_URI'], SiteGuard_Htaccess::TEST_DIR_PREFIX ) );
46 }
47
48 function siteguard_check_multisite() {
49 if ( ! is_multisite() ) {
50 return true;
51 }
52 $message = esc_html__( 'This plugin does not support WordPress multisite.', 'siteguard' );
53 $error = new WP_Error( 'siteguard', $message );
54 return $error;
55 }
56
57 class SiteGuard_Base {
58 function __construct() {
59 }
60 function is_switch_value( $value ) {
61 if ( '0' === $value || '1' === $value ) {
62 return true;
63 }
64 return false;
65 }
66 function cvt_camma2ret( $value ) {
67 $result = str_replace( ' ', '', $value );
68 return str_replace( ',', "\r\n", $result );
69 }
70 function cvt_ret2camma( $exclude ) {
71 $result = str_replace( ' ', '', $exclude );
72 $result = str_replace( ',', '', $result );
73 $result = preg_replace( '/(\r\n){2,}/', "\r\n", $result );
74 $result = preg_replace( '/\r\n$/', '', $result );
75 $result = str_replace( "\r\n", ',', $result );
76 $result = str_replace( "\r", ',', $result );
77 return str_replace( "\n", ',', $result );
78 }
79 function check_module( $name, $default = false ) {
80 return true;
81 // It does not work WP-CLI
82 // if ( isset( $_SERVER['SERVER_SOFTWARE'] ) ) {
83 // return ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false);
84 // } else {
85 // return $default;
86 // }
87
88 // It does not work in FastCGI well.
89 // $module = 'mod_' . $name;
90 // return apache_mod_loaded( $module, $default );
91 // if ( function_exists('phpinfo') ) {
92 // ob_start( );
93 // phpinfo(8);
94 // $phpinfo = ob_get_clean( );
95 // if ( false !== strpos( $phpinfo, $module ) ) {
96 // return true;
97 // }
98 // }
99 // return $default;
100 }
101 function is_private_ip( $ip ) {
102 $private_ips = array(
103 '10.0.0.0,10.255.255.255',
104 '172.16.0.0,172.31.255.255',
105 '192.168.0.0,192.168.255.255',
106 );
107
108 $long_ip = ip2long( $ip );
109 if ( -1 !== $long_ip && false !== $long_ip ) {
110 $long_ip = sprintf( '%u', $long_ip );
111 foreach ( $private_ips as $private_ip ) {
112 list( $start, $end ) = explode( ',', $private_ip );
113 $long_start = ip2long( $start );
114 $long_start = sprintf( '%u', $long_start );
115 $long_end = ip2long( $end );
116 $long_end = sprintf( '%u', $long_end );
117 if ( $long_ip >= $long_start && $long_ip <= $long_end ) {
118 return true;
119 }
120 }
121 }
122 return false;
123 }
124 function get_server_ip() {
125 if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
126 $ip = sanitize_text_field( $_SERVER['SERVER_ADDR'] );
127 if ( preg_match( '/^[0-9.:]+$/', $ip ) ) {
128 return $ip;
129 }
130 }
131
132 $host = parse_url( home_url(), PHP_URL_HOST );
133 if ( false !== $host && null !== $host ) {
134 putenv( 'RES_OPTIONS=retrans:1 retry:1 timeout:2 attempts:1' );
135 $ip = @gethostbyname( $host );
136 if ( $ip !== $host && '127.0.0.1' !== $ip && '::1' !== $ip ) {
137 if ( preg_match( '/^[0-9.:]+$/', $ip ) ) {
138 return $ip;
139 }
140 }
141 }
142 return false;
143 }
144 function get_ip() {
145 if (
146 ! isset( $_SERVER['REMOTE_ADDR'] )
147 || ! is_string( $_SERVER['REMOTE_ADDR'] )
148 || '' === $_SERVER['REMOTE_ADDR']
149 ) {
150 siteguard_error_log( 'Your webserver is misconfigured. REMOTE_ADDR is not set.' );
151 return '0.0.0.0';
152 }
153 return sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
154 }
155 }
156