Skip to content

Commit 329be88

Browse files
37 hitting f5 on the full scan page will trigger a full scan (#39)
* add the all flag to the `cron event run` command * bugfix: full scan loop * bugfix: fixes the duplicate key bug when finding the same fil multiple times * automated release --------- Co-authored-by: PT-ATA No One <[email protected]>
1 parent 7d6de1b commit 329be88

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed

.github/workflows/github-release.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,35 @@ jobs:
104104
uses: actions/download-artifact@master
105105
with:
106106
name: plugin-zip
107+
108+
- name: install subversion
109+
run: |
110+
sudo apt-get update
111+
sudo apt-get -y install subversion
112+
113+
- name: checkout svn
114+
run: |
115+
svn co https://plugins.svn.wordpress.org/gdata-antivirus/ svn/gdata-antivirus
116+
117+
- name: unzip
118+
run: unzip gdata-antivirus-${{needs.get-version.outputs.plugin_version}}.zip -d svn/gdata-antivirus-${{needs.get-version.outputs.plugin_version}}
119+
120+
- name: check version changelog
121+
run: |
122+
grep "= ${{needs.get-version.outputs.plugin_version}} =" svn/gdata-antivirus-${{needs.get-version.outputs.plugin_version}}/Readme.txt
123+
124+
- name: copy files
125+
run: |
126+
rm -rf svn/gdata-antivirus/trunk/*
127+
cp -r svn/gdata-antivirus-${{needs.get-version.outputs.plugin_version}}/* svn/gdata-antivirus/trunk/
128+
svn update svn/gdata-antivirus/trunk/*
129+
svn cp svn/gdata-antivirus/trunk/ svn/gdata-antivirus/tags/${{needs.get-version.outputs.plugin_version}}
130+
131+
- name: commit
132+
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'beta')
133+
run: |
134+
svn ci -m 'release ${{needs.get-version.outputs.plugin_version}}' --username ${{ secrets.SVN_USERNAME }} --password ${{ secrets.SVN_PASSWORD }} svn/gdata-antivirus
135+
107136
- name: Release
108137
uses: softprops/action-gh-release@v2
109138
with:

Infrastructure/Database/FindingsQuery.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public function create(): void {
2929
detection VARCHAR(128) NOT NULL,
3030
sha256 VARCHAR(64) NOT NULL,
3131
request_id VARCHAR(256) NOT NULL,
32+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
33+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
3234
UNIQUE KEY file_path (file_path)
3335
)' . $charset_collate . ';';
3436

@@ -68,14 +70,38 @@ public function table_exists(): bool {
6870
return false;
6971
}
7072

73+
private function exits( string $file_path ): bool {
74+
global $wpdb;
75+
76+
if (!$this->table_exists()) {
77+
return false;
78+
}
79+
return $wpdb->get_var(
80+
$wpdb->prepare('SELECT COUNT(*) FROM %i WHERE file_path = %s', $this->get_table_name(), $file_path)
81+
) > 0;
82+
}
83+
7184
public function add( DetectedFile $detected_file ): void {
7285
global $wpdb;
86+
assert($wpdb instanceof wpdb);
7387

7488
if (! $this->table_exists()) {
7589
return;
7690
}
7791

7892
try {
93+
if ($this->exits($detected_file->path)) {
94+
$wpdb->update(
95+
$this->get_table_name(),
96+
array(
97+
'detection' => $detected_file->detection,
98+
'sha256' => $detected_file->sha256,
99+
'request_id' => $detected_file->request_id
100+
),
101+
array( 'file_path' => $detected_file->path )
102+
);
103+
return;
104+
}
79105
$wpdb->insert(
80106
$this->get_table_name(),
81107
array(
@@ -121,7 +147,7 @@ public function get_all(): array {
121147
return array();
122148
}
123149
return $wpdb->get_results(
124-
$wpdb->prepare('SELECT file_path, detection, sha256, request_id FROM %i', $this->get_table_name()),
150+
$wpdb->prepare('SELECT file_path, detection, sha256, request_id, updated_at FROM %i', $this->get_table_name()),
125151
ARRAY_A
126152
);
127153
}

PluginPage/Findings/FindingsMenuPage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ public function findings_list(): void {
135135
<th scope="col" id="title_file" class="manage-column column-title column-primary">
136136
File
137137
</th>
138+
<th scope="col" id="title_file" class="manage-column column-title column-primary">
139+
Last seen
140+
</th>
138141
<th scope="col" id="title_detection" class="manage-column column-title column-primary">
139142
Detection
140143
</th>
@@ -168,6 +171,11 @@ public function findings_list(): void {
168171
echo esc_html($finding['file_path']);
169172
?>
170173
</td>
174+
<td>
175+
<?php
176+
echo esc_html($finding['updated_at']);
177+
?>
178+
</td>
171179
<td>
172180
<?php
173181
echo esc_html($finding['detection']);

PluginPage/FullScan/FullScanMenuPage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ private function setup_scheduled_scan() {
5757
$schedule_start = get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', '01:00');
5858
$next = wp_next_scheduled('gdatacyberdefenseag_antivirus_scheduled_full_scan');
5959

60-
if (! $full_scan_enabled && $next) {
60+
if ($full_scan_enabled !== true && $next) {
6161
wp_unschedule_event($next, 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
6262
return;
6363
}
6464

65-
if ($full_scan_enabled && ! $next) {
65+
if ($full_scan_enabled === true && ! $next) {
6666
$timestamp = strtotime($schedule_start);
6767
$this->logger->debug('schedule start timestamp: ' . $timestamp);
6868
wp_schedule_event($timestamp, 'daily', 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
6969
return;
7070
}
7171
$nextschedule_start = gmdate('H:i', $next);
72-
if ($nextschedule_start !== $schedule_start) {
72+
if ($full_scan_enabled === true && $nextschedule_start !== $schedule_start) {
7373
wp_unschedule_event($next, 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
7474
$timestamp = strtotime($schedule_start);
7575
wp_schedule_event($timestamp, 'daily', 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
@@ -246,7 +246,7 @@ public function full_scan(): void {
246246
if ($file_path->isDir()) {
247247
continue;
248248
}
249-
// For testing purposes, we only scan files with eicar in the name
249+
// // For testing purposes, we only scan files with eicar in the name
250250
// if (str_contains($file_path->getPathname(), "eicar") === false) {
251251
// continue;
252252
// }

Readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ Please do not commit the code while in live mode. Just run the script again and
7878

7979
If you want to run the cron event directly user this command.
8080

81-
`docker exec --user www-data -it gdata-antivirus-app-1 bash -c "XDEBUG_CONFIG='client_port=9080 client_host=172.19.0.1' wp --debug cron event run gdatacyberdefenseag_antivirus_scan_batch"`
81+
`docker exec --user www-data -it gdata-antivirus-app-1 bash -c "XDEBUG_CONFIG='client_port=9080 client_host=172.19.0.1' wp --debug cron event run --all"`
82+
83+
To debug the the cli you also have to configure xdebug to connect to your container ip.
8284

8385
## Disclaimer
8486

Readme.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ While the released code is hosted on the WordPress svn, we develop the plugin on
5656

5757
== Changelog ==
5858

59+
= 2.1.0 =
60+
* bugfix: [full scan runs in loop](https://github.com/GDATASoftwareAG/wordpress-gdata-antivirus/issues/37)
61+
* bugifx: fails on duplicate key when detecting the same file twice
62+
5963
= 2.0.9 =
6064
* bugfix: reconnect on long running scans
6165
* add detection and sha256 name to upload detection

0 commit comments

Comments
 (0)