| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_Defender\Model\Setting; |
| 4 |
|
| 5 |
use Calotes\Model\Setting; |
| 6 |
|
| 7 |
class Scan extends Setting { |
| 8 |
public $table = 'wd_scan_settings'; |
| 9 |
|
| 10 |
/** |
| 11 |
* Enable core/plugin integrity check while perform a scan. |
| 12 |
* |
| 13 |
* @defender_property |
| 14 |
* @var bool |
| 15 |
*/ |
| 16 |
public $integrity_check = true; |
| 17 |
|
| 18 |
/** |
| 19 |
* Enable Scan WP core files. |
| 20 |
* |
| 21 |
* @defender_property |
| 22 |
* @var bool |
| 23 |
*/ |
| 24 |
public $check_core = true; |
| 25 |
|
| 26 |
/** |
| 27 |
* Enable Scan plugin files. |
| 28 |
* |
| 29 |
* @defender_property |
| 30 |
* @var bool |
| 31 |
*/ |
| 32 |
public $check_plugins = false; |
| 33 |
|
| 34 |
/** |
| 35 |
* Check the files inside wp-content by our malware signatures. |
| 36 |
* |
| 37 |
* @defender_property |
| 38 |
* @var bool |
| 39 |
*/ |
| 40 |
public $scan_malware = false; |
| 41 |
|
| 42 |
/** |
| 43 |
* Check if any plugins or themes have a known vulnerability. |
| 44 |
* |
| 45 |
* @defender_property |
| 46 |
* @var bool |
| 47 |
*/ |
| 48 |
public $check_known_vuln = true; |
| 49 |
|
| 50 |
/** |
| 51 |
* If a file is smaller than this, we wil include it to the test. |
| 52 |
* |
| 53 |
* @defender_property |
| 54 |
* @var int |
| 55 |
*/ |
| 56 |
public $filesize = 10; |
| 57 |
|
| 58 |
/** |
| 59 |
* @defender_property |
| 60 |
* @var bool |
| 61 |
*/ |
| 62 |
public $scheduled_scanning = false; |
| 63 |
|
| 64 |
/** |
| 65 |
* The frequency of scheduled scan. |
| 66 |
* |
| 67 |
* @var string |
| 68 |
* @defender_property |
| 69 |
* @sanitize_text_field |
| 70 |
* @rule in[daily,weekly,monthly] |
| 71 |
*/ |
| 72 |
public $frequency; |
| 73 |
|
| 74 |
/** |
| 75 |
* The day of scheduled scan. |
| 76 |
* |
| 77 |
* @var string |
| 78 |
* @defender_property |
| 79 |
* @sanitize_text_field |
| 80 |
*/ |
| 81 |
public $day; |
| 82 |
|
| 83 |
/** |
| 84 |
* This is for when user select scheduled scan as monthly, we will have the day number, instead of text. |
| 85 |
* |
| 86 |
* @var int |
| 87 |
* @sanitize_text_field |
| 88 |
* @defender_property |
| 89 |
*/ |
| 90 |
public $day_n; |
| 91 |
|
| 92 |
/** |
| 93 |
* Same as $day. |
| 94 |
* |
| 95 |
* @var string |
| 96 |
* @defender_property |
| 97 |
* @sanitize_text_field |
| 98 |
*/ |
| 99 |
public $time; |
| 100 |
|
| 101 |
/** |
| 102 |
* Define labels for settings key |
| 103 |
* |
| 104 |
* @param string|null $key |
| 105 |
* |
| 106 |
* @return string|array|null |
| 107 |
*/ |
| 108 |
public function labels( $key = null ) { |
| 109 |
$labels = array( |
| 110 |
'integrity_check' => __( 'File change detection', 'wpdef' ), |
| 111 |
'check_core' => __( 'Scan core files', 'wpdef' ), |
| 112 |
'check_plugins' => __( 'Scan plugin files', 'wpdef' ), |
| 113 |
'check_known_vuln' => __( 'Known vulnerabilities', 'wpdef' ), |
| 114 |
'scan_malware' => __( 'Suspicious Code', 'wpdef' ), |
| 115 |
'filesize' => __( 'Max included file size', 'wpdef' ), |
| 116 |
'scheduled_scanning' => __( 'Scheduled Scanning', 'wpdef' ), |
| 117 |
'frequency' => __( 'Frequency', 'wpdef' ), |
| 118 |
'day' => __( 'Day of the week', 'wpdef' ), |
| 119 |
'day_n' => __( 'Day of the month', 'wpdef' ), |
| 120 |
'time' => __( 'Time of day', 'wpdef' ), |
| 121 |
); |
| 122 |
|
| 123 |
if ( ! is_null( $key ) ) { |
| 124 |
return $labels[ $key ] ?? null; |
| 125 |
} |
| 126 |
|
| 127 |
return $labels; |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* @return bool |
| 132 |
*/ |
| 133 |
public function is_any_filetypes_checked() { |
| 134 |
if ( ! $this->integrity_check) { |
| 135 |
return false; |
| 136 |
} elseif ( $this->integrity_check && ! $this->check_core && ! $this->check_plugins ) { |
| 137 |
return false; |
| 138 |
} |
| 139 |
|
| 140 |
return true; |
| 141 |
} |
| 142 |
|
| 143 |
public function after_validate() { |
| 144 |
// Case#1: all child types of File change detection are unchecked BUT parent type is checked. |
| 145 |
if ( $this->integrity_check && ! $this->check_core && ! $this->check_plugins ) { |
| 146 |
$this->errors[] = __( 'You have not selected a scan type for the <strong>File change detection</strong>. Please choose at least one and save the settings again.', 'wpdef' ); |
| 147 |
|
| 148 |
return false; |
| 149 |
// Case#2: all scan types are unchecked and Scheduled Scanning is checked. |
| 150 |
} elseif ( ! $this->integrity_check && ! $this->check_known_vuln && ! $this->scan_malware |
| 151 |
&& $this->scheduled_scanning |
| 152 |
) { |
| 153 |
$this->errors[] = __( 'You have not selected a scan type. Please enable at least one scan type and save the settings again.', 'wpdef' ); |
| 154 |
|
| 155 |
return false; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
protected function before_load() { |
| 160 |
$this->frequency = 'weekly'; |
| 161 |
$this->day = 'sunday'; |
| 162 |
$this->day_n = '1'; |
| 163 |
$this->time = '4:00'; |
| 164 |
} |
| 165 |
} |
| 166 |
|