PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / model / setting / class-scan.php

class-scan.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at src/model/setting/class-scan.php

222 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles scan settings.
4 *
5 * @package WP_Defender\Model\Setting
6 */
7
8 namespace WP_Defender\Model\Setting;
9
10 use Calotes\Model\Setting;
11
12 /**
13 * Model for scan settings.
14 */
15 class Scan extends Setting {
16
17 /**
18 * Option name.
19 *
20 * @var string
21 */
22 protected $table = 'wd_scan_settings';
23
24 /**
25 * Enable core/plugin integrity check while perform a scan.
26 *
27 * @defender_property
28 * @var bool
29 */
30 public $integrity_check = true;
31
32 /**
33 * Enable Scan WP core files.
34 *
35 * @defender_property
36 * @var bool
37 */
38 public $check_core = true;
39
40 /**
41 * Enable Scan plugin files.
42 *
43 * @defender_property
44 * @var bool
45 */
46 public $check_plugins = true;
47
48 /**
49 * Check the files inside wp-content by our malware signatures.
50 *
51 * @defender_property
52 * @var bool
53 */
54 public $scan_malware = true;
55
56 /**
57 * Check if any plugins or themes have a known vulnerability.
58 *
59 * @defender_property
60 * @var bool
61 */
62 public $check_known_vuln = true;
63
64 /**
65 * If a file is smaller than this, we wil include it to the test.
66 *
67 * @defender_property
68 * @var int
69 */
70 public $filesize = 10;
71
72 /**
73 * Is scheduled scanning enabled?
74 *
75 * @var bool
76 * @defender_property
77 */
78 public $scheduled_scanning = false;
79
80 /**
81 * The frequency of scheduled scan.
82 *
83 * @var string
84 * @defender_property
85 * @rule in[daily,weekly,monthly]
86 */
87 public $frequency = 'weekly';
88
89 /**
90 * The day of scheduled scan.
91 *
92 * @var string
93 * @defender_property
94 * @sanitize_text_field
95 */
96 public $day = '';
97
98 /**
99 * This is for when user select scheduled scan as monthly, we will have the day number, instead of text.
100 *
101 * @var int
102 * @defender_property
103 */
104 public int $day_n = 1;
105
106 /**
107 * Same as $day.
108 *
109 * @var string
110 * @defender_property
111 * @sanitize_text_field
112 */
113 public $time = '';
114
115 /**
116 * Quarantine file deletion/expiration cron schedule.
117 *
118 * @var string
119 * @defender_property
120 * @sanitize_text_field
121 */
122 public $quarantine_expire_schedule = 'thirty_days';
123
124 /**
125 * Enable Abandoned or outdated plugins.
126 *
127 * @defender_property
128 * @var bool
129 */
130 public $check_abandoned_plugin = true;
131
132 /**
133 * Define settings labels.
134 *
135 * @return array
136 */
137 public function labels(): array {
138 return array(
139 'integrity_check' => esc_html__( 'File change detection', 'defender-security' ),
140 'check_core' => esc_html__( 'Scan core files', 'defender-security' ),
141 'check_plugins' => esc_html__( 'Scan plugin files', 'defender-security' ),
142 'check_abandoned_plugin' => esc_html__( 'Outdated & removed plugins', 'defender-security' ),
143 'check_known_vuln' => esc_html__( 'Known vulnerabilities', 'defender-security' ),
144 'scan_malware' => esc_html__( 'Suspicious code', 'defender-security' ),
145 'filesize' => esc_html__( 'Max included file size', 'defender-security' ),
146 'scheduled_scanning' => esc_html__( 'Scheduled Scanning', 'defender-security' ),
147 'frequency' => esc_html__( 'Frequency', 'defender-security' ),
148 'day' => esc_html__( 'Day of the week', 'defender-security' ),
149 'day_n' => esc_html__( 'Day of the month', 'defender-security' ),
150 'time' => esc_html__( 'Time of day', 'defender-security' ),
151 );
152 }
153
154 /**
155 * Check different cases for 'File change detection' option.
156 *
157 * @return bool
158 */
159 public function is_checked_any_file_change_types(): bool {
160 if ( ! $this->integrity_check ) {
161 // Check the parent type.
162 return false;
163 } elseif ( $this->integrity_check && ! $this->check_core && ! $this->check_plugins ) {
164 // Check the parent and child types.
165 return false;
166 }
167
168 return true;
169 }
170
171 /**
172 * Validates the input after form submission and adds error messages if necessary.
173 *
174 * @return void
175 */
176 protected function after_validate(): void {
177 // Case#1: all child types of File change detection are unchecked BUT the parent type is checked.
178 if ( $this->integrity_check && ! $this->check_core && ! $this->check_plugins ) {
179 $this->errors[] = sprintf(
180 /* translators: %s: File change detection. */
181 esc_html__( 'You have not selected a scan type for the %s. Please choose at least one and save the settings again.', 'defender-security' ),
182 '<strong>' . esc_html__( 'File change detection', 'defender-security' ) . '</strong>'
183 );
184 // Case#2: all scan types are unchecked.
185 } elseif ( ! $this->is_enabled_any_scan_type() ) {
186 $this->errors[] = esc_html__(
187 'You have not selected a scan type. Please enable at least one scan type and save the settings again.',
188 'defender-security'
189 );
190 }
191 }
192
193 /**
194 * Initializes the object by setting default values.
195 *
196 * @return void
197 */
198 protected function before_load(): void {
199 }
200
201 /**
202 * Is enabled any scan type at least?
203 *
204 * @return bool
205 */
206 private function is_enabled_any_scan_type(): bool {
207 return $this->integrity_check
208 || $this->check_known_vuln
209 || $this->scan_malware
210 || $this->check_abandoned_plugin;
211 }
212
213 /**
214 * Is enabled Scheduled Scanning?
215 *
216 * @return bool
217 */
218 public function is_enabled_scheduled_scanning(): bool {
219 return false;
220 }
221 }
222