Skip to content

Commit 3ff8511

Browse files
fix initialization problem
1 parent aa869fe commit 3ff8511

File tree

4 files changed

+109
-74
lines changed

4 files changed

+109
-74
lines changed

PluginPage/FullScan/FullScanMenuPage.php

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313

1414
if (! class_exists('FullScanMenuPage')) {
15-
class FullScanMenuPage {
15+
class FullScanMenuPage
16+
{
1617
private ScanClient $scan_client;
1718
private AdminNotices $admin_notices;
1819
private LoggerInterface $logger;
@@ -32,27 +33,28 @@ public function __construct(
3233
$this->findings = $findings;
3334
$this->scans = $scans;
3435

35-
register_activation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this->scans, 'create' ));
36-
register_deactivation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array( $this->scans, 'remove' ));
36+
register_activation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array($this->scans, 'create'));
37+
register_deactivation_hook(GDATACYBERDEFENCEAG_ANTIVIRUS_PLUGIN_WITH_CLASSES__FILE__, array($this->scans, 'remove'));
3738

3839
if (! $vaas_options->credentials_configured()) {
3940
return;
4041
}
4142
$this->scan_client = $scan_client;
4243
$this->admin_notices = $admin_notices;
43-
add_action('init', array( $this, 'setup_fields' ));
44-
add_action('admin_menu', array( $this, 'setup_menu' ));
45-
add_action('admin_post_full_scan', array( $this, 'full_scan_interactive' ));
46-
add_action('gdatacyberdefenseag_antivirus_scheduled_full_scan', array( $this, 'full_scan' ));
44+
add_action('init', array($this, 'setup_fields'));
45+
add_action('admin_menu', array($this, 'setup_menu'));
46+
add_action('admin_post_full_scan', array($this, 'full_scan_interactive'));
47+
add_action('gdatacyberdefenseag_antivirus_scheduled_full_scan', array($this, 'full_scan'));
4748
add_action(
4849
'gdatacyberdefenseag_antivirus_scan_batch',
49-
array( $this, 'scan_batch' ),
50+
array($this, 'scan_batch'),
5051
);
5152

5253
$this->setup_scheduled_scan();
5354
}
5455

55-
private function setup_scheduled_scan() {
56+
private function setup_scheduled_scan()
57+
{
5658
$full_scan_enabled = (bool) get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false);
5759
$schedule_start = get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', '01:00');
5860
$next = wp_next_scheduled('gdatacyberdefenseag_antivirus_scheduled_full_scan');
@@ -76,14 +78,15 @@ private function setup_scheduled_scan() {
7678
}
7779
}
7880

79-
public function setup_fields(): void {
81+
public function setup_fields(): void
82+
{
8083
register_setting(
8184
'gdatacyberdefenseag_antivirus_options_full_scan_run',
8285
'gdatacyberdefenseag_antivirus_options_full_scan_batch_size',
8386
array(
8487
'type' => 'number',
8588
'default' => 100,
86-
'sanitize_callback' => array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size_validation' ),
89+
'sanitize_callback' => array($this, 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size_validation'),
8790
)
8891
);
8992
register_setting(
@@ -92,7 +95,7 @@ public function setup_fields(): void {
9295
array(
9396
'type' => 'string',
9497
'default' => '01:00',
95-
'sanitize_callback' => array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_validation' ),
98+
'sanitize_callback' => array($this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_validation'),
9699
)
97100
);
98101
register_setting(
@@ -105,34 +108,35 @@ public function setup_fields(): void {
105108
);
106109
}
107110

108-
public function setup_menu(): void {
111+
public function setup_menu(): void
112+
{
109113
add_settings_section(
110114
'gdatacyberdefenseag_antivirus_options_full_scan',
111115
esc_html__('Full Scan', 'gdata-antivirus'),
112-
array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_text' ),
116+
array($this, 'gdatacyberdefenseag_antivirus_options_full_scan_text'),
113117
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG
114118
);
115119

116120
add_settings_field(
117121
'gdatacyberdefenseag_antivirus_options_full_scan_batch_size',
118122
esc_html__('Batch Size', 'gdata-antivirus'),
119-
array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size_text' ),
123+
array($this, 'gdatacyberdefenseag_antivirus_options_full_scan_batch_size_text'),
120124
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
121125
'gdatacyberdefenseag_antivirus_options_full_scan'
122126
);
123127

124128
add_settings_field(
125129
'gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled',
126130
esc_html__('Scheduled Scan enabled', 'gdata-antivirus'),
127-
array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled_text' ),
131+
array($this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled_text'),
128132
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
129133
'gdatacyberdefenseag_antivirus_options_full_scan'
130134
);
131135

132136
add_settings_field(
133137
'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start',
134138
esc_html__('Scheduled Scan starting Hour', 'gdata-antivirus'),
135-
array( $this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_text' ),
139+
array($this, 'gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_text'),
136140
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
137141
'gdatacyberdefenseag_antivirus_options_full_scan'
138142
);
@@ -143,11 +147,12 @@ public function setup_menu(): void {
143147
'Full scan',
144148
'manage_options',
145149
GDATACYBERDEFENCEAG_ANTIVIRUS_MENU_FULL_SCAN_SLUG,
146-
array( $this, 'full_scan_menu' )
150+
array($this, 'full_scan_menu')
147151
);
148152
}
149153

150-
public function gdatacyberdefenseag_antivirus_options_full_scan_batch_size_validation( $value ) {
154+
public function gdatacyberdefenseag_antivirus_options_full_scan_batch_size_validation($value)
155+
{
151156
$option = get_option('gdatacyberdefenseag_antivirus_options_full_scan_batch_size', 100);
152157
if (0 === $value) {
153158
$value = $option;
@@ -168,7 +173,8 @@ public function gdatacyberdefenseag_antivirus_options_full_scan_batch_size_valid
168173
return $value;
169174
}
170175

171-
public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_validation( $value ) {
176+
public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_validation($value)
177+
{
172178
$option = get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', '01:00');
173179
$full_scan_enabled = get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false);
174180

@@ -186,30 +192,35 @@ public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_v
186192
return $value;
187193
}
188194

189-
public function gdatacyberdefenseag_antivirus_options_full_scan_text() {
195+
public function gdatacyberdefenseag_antivirus_options_full_scan_text()
196+
{
190197
echo '<p>' . esc_html__('Here you can set options for the full scan', 'gdata-antivirus') . '</p>';
191198
}
192199

193-
public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled_text() {
200+
public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled_text()
201+
{
194202
$full_scan_enabled = (bool) get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false);
195203
echo "<input id='gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled' name='gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled' type='checkbox' value='true' " . checked(true, $full_scan_enabled, false) . "' />";
196204
}
197205

198-
public function gdatacyberdefenseag_antivirus_options_full_scan_batch_size_text() {
206+
public function gdatacyberdefenseag_antivirus_options_full_scan_batch_size_text()
207+
{
199208
$batch_size = get_option('gdatacyberdefenseag_antivirus_options_full_scan_batch_size', 100);
200209
echo "<input id='gdatacyberdefenseag_antivirus_options_full_scan_batch_size' name='gdatacyberdefenseag_antivirus_options_full_scan_batch_size' type='text' value='" . esc_attr($batch_size) . "' />";
201210
}
202211

203-
public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_text() {
212+
public function gdatacyberdefenseag_antivirus_options_full_scan_schedule_start_text()
213+
{
204214
$schedule_start = get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', '01:00');
205215
$full_scan_enabled =
206216
(bool) get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_enabled', false);
207217
$this->logger->debug('schedule_start: ' . $schedule_start);
208218

209-
echo "<input id='gdatacyberdefenseag_antivirus_options_full_scan_schedule_start' name='gdatacyberdefenseag_antivirus_options_full_scan_schedule_start' type='text' value='" . esc_attr($schedule_start) . "' " . ( $full_scan_enabled ? '' : 'disabled' ) . '/>';
219+
echo "<input id='gdatacyberdefenseag_antivirus_options_full_scan_schedule_start' name='gdatacyberdefenseag_antivirus_options_full_scan_schedule_start' type='text' value='" . esc_attr($schedule_start) . "' " . ($full_scan_enabled ? '' : 'disabled') . '/>';
210220
}
211221

212-
public function full_scan_interactive(): void {
222+
public function full_scan_interactive(): void
223+
{
213224
if (! isset($_POST['gdata-antivirus-full-scan-nonce'])) {
214225
wp_die(
215226
esc_html__('Invalid nonce specified', 'gdata-antivirus'),
@@ -232,15 +243,16 @@ public function full_scan_interactive(): void {
232243
wp_safe_redirect(wp_get_referer());
233244
}
234245

235-
public function full_scan(): void {
246+
public function full_scan(): void
247+
{
236248
$this->admin_notices->add_notice(__('Full Scan started', 'gdata-antivirus'));
237249

238250
$batch_size = get_option('gdatacyberdefenseag_antivirus_options_full_scan_batch_size', 100);
239251
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ABSPATH, \FilesystemIterator::SKIP_DOTS));
240252
$files = array();
241253
$this->scans->reset();
242254
foreach ($it as $file_path) {
243-
if (! ( $file_path instanceof \SplFileInfo )) {
255+
if (! ($file_path instanceof \SplFileInfo)) {
244256
continue;
245257
}
246258
if ($file_path->isDir()) {
@@ -255,17 +267,18 @@ public function full_scan(): void {
255267
if (count($files) >= $batch_size) {
256268
$this->scans->increase_scheduled();
257269

258-
wp_schedule_single_event(time(), 'gdatacyberdefenseag_antivirus_scan_batch', array( 'files' => $files ));
270+
wp_schedule_single_event(time(), 'gdatacyberdefenseag_antivirus_scan_batch', array('files' => $files));
259271
$files = array();
260272
}
261273
}
262274
if (count($files) > 0) {
263275
$this->scans->increase_scheduled();
264-
wp_schedule_single_event(time(), 'gdatacyberdefenseag_antivirus_scan_batch', array( 'files' => $files ));
276+
wp_schedule_single_event(time(), 'gdatacyberdefenseag_antivirus_scan_batch', array('files' => $files));
265277
}
266278
}
267279

268-
public function scan_batch( array $files ): void {
280+
public function scan_batch(array $files): void
281+
{
269282
$this->scan_client->connect();
270283
try {
271284
foreach ($files as $file) {
@@ -282,22 +295,23 @@ public function scan_batch( array $files ): void {
282295
$vaas_verdict = $scan_client->scan_file($file);
283296
if ($vaas_verdict->Verdict === \VaasSdk\Message\Verdict::MALICIOUS) {
284297
$this->logger->debug('add to findings ' . $file);
285-
$this->findings->add(new DetectedFile($file, $vaas_verdict->Detection, $vaas_verdict->Sha256, $vaas_verdict->Guid));
298+
$this->findings->add(new DetectedFile($file, $vaas_verdict->detection, $vaas_verdict->sha256));
286299
}
287300
}
288-
} finally {
301+
} finally {
289302
$this->scans->increase_finished();
290303
if ($this->scans->scheduled_count() <= $this->scans->finished_count()) {
291304
$this->admin_notices->add_notice(__('Full Scan finished', 'gdata-antivirus'));
292305
$this->scans->reset();
293306
}
294-
}
307+
}
295308
}
296309

297-
public function full_scan_menu(): void {
310+
public function full_scan_menu(): void
311+
{
298312
settings_errors('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start');
299313
settings_errors('gdatacyberdefenseag_antivirus_options_full_scan_batch_size');
300-
?>
314+
?>
301315
<h2>Full Scan Settings</h2>
302316
<form action="options.php" method="post">
303317
<?php
@@ -309,32 +323,32 @@ public function full_scan_menu(): void {
309323
<?php
310324
$scheduled_scans = $this->scans->scheduled_count();
311325
$finished_scans = $this->scans->finished_count();
312-
$cron_jobs = wp_get_ready_cron_jobs();
313-
$still_running=false;
314-
foreach($cron_jobs as $key => $cron) {
315-
foreach($cron as $name =>$job) {
316-
if ($name=='gdatacyberdefenseag_antivirus_scan_batch') {
317-
$still_running=true;
318-
break;
319-
}
320-
}
321-
}
326+
$cron_jobs = wp_get_ready_cron_jobs();
327+
$still_running = false;
328+
foreach ($cron_jobs as $key => $cron) {
329+
foreach ($cron as $name => $job) {
330+
if ($name == 'gdatacyberdefenseag_antivirus_scan_batch') {
331+
$still_running = true;
332+
break;
333+
}
334+
}
335+
}
322336
if ($still_running === false) {
323-
?>
337+
?>
324338
<form action="admin-post.php" method="post">
325339
<input type="hidden" name="action" value="full_scan">
326340
<?php wp_nonce_field('gdata-antivirus-full-scan', 'gdata-antivirus-full-scan-nonce'); ?>
327341
<?php submit_button(__('Run Full Scan', 'gdata-antivirus')); ?>
328342
</form>
329-
<?php
343+
<?php
330344
} else {
331-
?>
345+
?>
332346
<p>
333-
<?php
334-
echo esc_html__('Full Scan is running. ', 'gdata-antivirus') . esc_html($finished_scans) . esc_html(' of ', 'gdata-antivirus') . esc_html($scheduled_scans) . esc_html__(' batches are finished', 'gdata-antivirus');
335-
?>
336-
</p>
337-
<?php
347+
<?php
348+
echo esc_html__('Full Scan is running. ', 'gdata-antivirus') . esc_html($finished_scans) . esc_html(' of ', 'gdata-antivirus') . esc_html($scheduled_scans) . esc_html__(' batches are finished', 'gdata-antivirus');
349+
?>
350+
</p>
351+
<?php
338352
}
339353
}
340354
}

PluginPage/OnDemandScan/OnDemandScanOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class OnDemandScanOptions
1010
'client_secret' => '',
1111
'username' => '',
1212
'password' => '',
13-
'vaas_url' => 'wss://gateway.staging.vaas.gdatasecurity.de',
13+
'vaas_url' => 'https://gateway.staging.vaas.gdatasecurity.de',
1414
'token_endpoint' => 'https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token',
1515
);
1616

0 commit comments

Comments
 (0)