| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Based on the current path and domain name, determine which option index we should use. |
| 5 |
* |
| 6 |
* @param array $options |
| 7 |
* @return integer |
| 8 |
*/ |
| 9 |
function patchstack_get_active_domain( $options ) |
| 10 |
{ |
| 11 |
// Essential server variables must be set. |
| 12 |
if ( ! isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) { |
| 13 |
return $options[0]; |
| 14 |
} |
| 15 |
|
| 16 |
// Give priority to home_url, then site_url. |
| 17 |
foreach ( [ 'home_url', 'site_url'] as $base ) { |
| 18 |
// Attempt to match against substring match. |
| 19 |
foreach ( $options as $option ) { |
| 20 |
// Only needed if the site is under a different folder path. |
| 21 |
if ( strpos( $option[$base], '/' ) === false ) { |
| 22 |
continue; |
| 23 |
} |
| 24 |
|
| 25 |
// Make sure there's a substring match. |
| 26 |
if ( substr( $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 0, strlen( $option[$base] ) ) == $option[$base] ) { |
| 27 |
return $option; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
// Attempt to match against just the hostname. |
| 32 |
foreach ( $options as $option ) { |
| 33 |
if ( strpos( $option[$base], '/' ) === false && $_SERVER['HTTP_HOST'] == $option[$base]) { |
| 34 |
return $option; |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
// Return first options set by default. |
| 40 |
return $options[0]; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Given the option values, determine if the WAF should run. |
| 45 |
* |
| 46 |
* @param array $options |
| 47 |
* @return boolean |
| 48 |
*/ |
| 49 |
function patchstack_get_should_run( $options ) |
| 50 |
{ |
| 51 |
if ( $options['patchstack_license_activated'] == 0 ) { |
| 52 |
return false; |
| 53 |
} |
| 54 |
|
| 55 |
if ( $options['patchstack_basic_firewall'] != 1 ) { |
| 56 |
return false; |
| 57 |
} |
| 58 |
|
| 59 |
if ( $options['patchstack_license_free'] == 1 ) { |
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
$rules = base64_decode( $options['patchstack_firewall_rules_v3_ap'] ); |
| 64 |
if ( $rules == '' || $rules == '[]' ) { |
| 65 |
return false; |
| 66 |
} |
| 67 |
|
| 68 |
return true; |
| 69 |
} |
| 70 |
|