| @@ -35,17 +35,11 @@ | ||
| 35 | 35 | * @param mixed $value |
| 36 | 36 | * @return void |
| 37 | 37 | */ |
| 38 | 38 | public function update_option_extras( $option_name, $old_value, $value ) { |
| 39 | - if ( !in_array( $option_name, [ 'patchstack_prevent_default_file_access', 'patchstack_basic_firewall', 'patchstack_pingback_protection', 'patchstack_block_debug_log_access', 'patchstack_block_fake_bots', 'patchstack_index_views', 'patchstack_trace_and_track', 'patchstack_proxy_comment_posting', 'patchstack_image_hotlinking', 'patchstack_firewall_custom_rules' ] ) ) { | |
| 40 | - return; | |
| 39 | + if ( in_array( $option_name, [ 'patchstack_prevent_default_file_access', 'patchstack_basic_firewall', 'patchstack_pingback_protection', 'patchstack_block_debug_log_access', 'patchstack_block_fake_bots', 'patchstack_index_views', 'patchstack_trace_and_track', 'patchstack_proxy_comment_posting', 'patchstack_image_hotlinking', 'patchstack_firewall_custom_rules' ] ) ) { | |
| 40 | + $this->plugin->rules->post_firewall_rules(); | |
| 41 | 41 | } |
| 42 | - | |
| 43 | - if ( $old_value == $value ) { | |
| 44 | - return; | |
| 45 | - } | |
| 46 | - | |
| 47 | - $this->plugin->rules->post_firewall_rules(); | |
| 48 | 42 | } |
| 49 | 43 | |
| 50 | 44 | /** |
| 51 | 45 | * Get the turned on .htaccess firewall settings. |
| @@ -101,9 +95,9 @@ | ||
| 101 | 95 | * @param string $rules |
| 102 | 96 | * @return void |
| 103 | 97 | */ |
| 104 | 98 | public function write_rules_to_htaccess( $rules = '' ) { |
| 105 | - if ( ! $this->is_server_supported() || get_site_option( 'patchstack_disable_htaccess', 0 ) || ( defined( 'PS_DISABLE_HTACCESS' ) && PS_DISABLE_HTACCESS ) ) { | |
| 99 | + if ( ! $this->is_server_supported() || get_site_option( 'patchstack_disable_htaccess', 0 ) ) { | |
| 106 | 100 | return false; |
| 107 | 101 | } |
| 108 | 102 | |
| 109 | 103 | // Determine if the .htaccess file exists. |
| @@ -120,9 +114,9 @@ | ||
| 120 | 114 | } |
| 121 | 115 | |
| 122 | 116 | // Get the current rules. |
| 123 | 117 | $current = $old = $fs->get_contents( ABSPATH . '.htaccess' ); |
| 124 | - $current = $this->delete_all_between( '# Patchstack Firewall Start', '# Patchstack Firewall End', $current ); | |
| 118 | + $current = $this->delete_all_between( '# Patchstack Firewall Start', "# Patchstack Firewall End\r\n", $current ); | |
| 125 | 119 | |
| 126 | 120 | // If no rules, then we delete the old ones. |
| 127 | 121 | if ( $rules != '' ) { |
| 128 | 122 | $current = "# Patchstack Firewall Start\r\n<IfModule mod_rewrite.c>\r\nRewriteEngine On\r\n" . $rules . "\r\n</IfModule>\r\n# Patchstack Firewall End\r\n" . $current; |
| @@ -148,9 +142,9 @@ | ||
| 148 | 142 | * @param string $rules |
| 149 | 143 | * @return boolean |
| 150 | 144 | */ |
| 151 | 145 | public function write_to_htaccess( $rules = '' ) { |
| 152 | - if ( ! $this->is_server_supported() || get_site_option( 'patchstack_disable_htaccess', 0 ) || ( defined( 'PS_DISABLE_HTACCESS' ) && PS_DISABLE_HTACCESS ) ) { | |
| 146 | + if ( ! $this->is_server_supported() || get_site_option( 'patchstack_disable_htaccess', 0 ) ) { | |
| 153 | 147 | return false; |
| 154 | 148 | } |
| 155 | 149 | |
| 156 | 150 | require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; |
| @@ -159,22 +153,8 @@ | ||
| 159 | 153 | if ( ! $fs->exists( ABSPATH . '.htaccess' ) ) { |
| 160 | 154 | $fs->touch( ABSPATH . '.htaccess' ); |
| 161 | 155 | } |
| 162 | 156 | |
| 163 | - // Some rule adjustments. | |
| 164 | - $rewrites = [ | |
| 165 | - 'RedirectMatch 409 .(htaccess|htpasswd|errordocs|logs)$' => 'RedirectMatch 403 \.(htaccess|htpasswd|errordocs|logs)$', | |
| 166 | - "\n RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]" => '', | |
| 167 | - "\n RewriteCond %{REMOTE_ADDR} !=18.221.197.243" => '', | |
| 168 | - '^wp-includes/[^/]+.php$' => '^wp-includes/.*\.php$', | |
| 169 | - 'RewriteRule ^debug*.*log$ index.php?webarx_fpage=502 [L,QSA]' => 'RewriteRule debug\.log$ index.php?webarx_fpage=502 [L,QSA]', | |
| 170 | - '*.*' => '\.' | |
| 171 | - ]; | |
| 172 | - | |
| 173 | - foreach ($rewrites as $find => $replace) { | |
| 174 | - $rules = str_replace($find, $replace, $rules); | |
| 175 | - } | |
| 176 | - | |
| 177 | 157 | return $this->plugin->htaccess->self_check( $rules ); |
| 178 | 158 | } |
| 179 | 159 | |
| 180 | 160 | /** |
| @@ -345,16 +325,8 @@ | ||
| 345 | 325 | if ( $begin_pos === false || $end_pos === false ) { |
| 346 | 326 | return $string; |
| 347 | 327 | } |
| 348 | 328 | |
| 349 | - $end_pos += strlen( $end ); | |
| 350 | - | |
| 351 | - // Consume any trailing newline characters so the block is removed cleanly | |
| 352 | - // regardless of CRLF/LF line endings and repeated writes don't stack blank lines. | |
| 353 | - while ( isset( $string[ $end_pos ] ) && ( $string[ $end_pos ] === "\r" || $string[ $end_pos ] === "\n" ) ) { | |
| 354 | - $end_pos++; | |
| 355 | - } | |
| 356 | - | |
| 357 | - $delete = substr( $string, $begin_pos, $end_pos - $begin_pos ); | |
| 329 | + $delete = substr( $string, $begin_pos, ( $end_pos + strlen( $end ) ) - $begin_pos ); | |
| 358 | 330 | return str_replace( $delete, '', $string ); |
| 359 | 331 | } |
| 360 | 332 | } |