Skip to content

Commit

Permalink
37 hitting f5 on the full scan page will trigger a full scan (#39)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
unglaublicherdude and ata-no-one authored Nov 6, 2024
1 parent 7d6de1b commit 329be88
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 6 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/github-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,35 @@ jobs:
uses: actions/download-artifact@master
with:
name: plugin-zip

- name: install subversion
run: |
sudo apt-get update
sudo apt-get -y install subversion
- name: checkout svn
run: |
svn co https://plugins.svn.wordpress.org/gdata-antivirus/ svn/gdata-antivirus
- name: unzip
run: unzip gdata-antivirus-${{needs.get-version.outputs.plugin_version}}.zip -d svn/gdata-antivirus-${{needs.get-version.outputs.plugin_version}}

- name: check version changelog
run: |
grep "= ${{needs.get-version.outputs.plugin_version}} =" svn/gdata-antivirus-${{needs.get-version.outputs.plugin_version}}/Readme.txt
- name: copy files
run: |
rm -rf svn/gdata-antivirus/trunk/*
cp -r svn/gdata-antivirus-${{needs.get-version.outputs.plugin_version}}/* svn/gdata-antivirus/trunk/
svn update svn/gdata-antivirus/trunk/*
svn cp svn/gdata-antivirus/trunk/ svn/gdata-antivirus/tags/${{needs.get-version.outputs.plugin_version}}
- name: commit
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'beta')
run: |
svn ci -m 'release ${{needs.get-version.outputs.plugin_version}}' --username ${{ secrets.SVN_USERNAME }} --password ${{ secrets.SVN_PASSWORD }} svn/gdata-antivirus
- name: Release
uses: softprops/action-gh-release@v2
with:
Expand Down
28 changes: 27 additions & 1 deletion Infrastructure/Database/FindingsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public function create(): void {
detection VARCHAR(128) NOT NULL,
sha256 VARCHAR(64) NOT NULL,
request_id VARCHAR(256) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY file_path (file_path)
)' . $charset_collate . ';';

Expand Down Expand Up @@ -68,14 +70,38 @@ public function table_exists(): bool {
return false;
}

private function exits( string $file_path ): bool {
global $wpdb;

if (!$this->table_exists()) {
return false;
}
return $wpdb->get_var(
$wpdb->prepare('SELECT COUNT(*) FROM %i WHERE file_path = %s', $this->get_table_name(), $file_path)
) > 0;
}

public function add( DetectedFile $detected_file ): void {
global $wpdb;
assert($wpdb instanceof wpdb);

if (! $this->table_exists()) {
return;
}

try {
if ($this->exits($detected_file->path)) {
$wpdb->update(
$this->get_table_name(),
array(
'detection' => $detected_file->detection,
'sha256' => $detected_file->sha256,
'request_id' => $detected_file->request_id
),
array( 'file_path' => $detected_file->path )
);
return;
}
$wpdb->insert(
$this->get_table_name(),
array(
Expand Down Expand Up @@ -121,7 +147,7 @@ public function get_all(): array {
return array();
}
return $wpdb->get_results(
$wpdb->prepare('SELECT file_path, detection, sha256, request_id FROM %i', $this->get_table_name()),
$wpdb->prepare('SELECT file_path, detection, sha256, request_id, updated_at FROM %i', $this->get_table_name()),
ARRAY_A
);
}
Expand Down
8 changes: 8 additions & 0 deletions PluginPage/Findings/FindingsMenuPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public function findings_list(): void {
<th scope="col" id="title_file" class="manage-column column-title column-primary">
File
</th>
<th scope="col" id="title_file" class="manage-column column-title column-primary">
Last seen
</th>
<th scope="col" id="title_detection" class="manage-column column-title column-primary">
Detection
</th>
Expand Down Expand Up @@ -168,6 +171,11 @@ public function findings_list(): void {
echo esc_html($finding['file_path']);
?>
</td>
<td>
<?php
echo esc_html($finding['updated_at']);
?>
</td>
<td>
<?php
echo esc_html($finding['detection']);
Expand Down
8 changes: 4 additions & 4 deletions PluginPage/FullScan/FullScanMenuPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ private function setup_scheduled_scan() {
$schedule_start = get_option('gdatacyberdefenseag_antivirus_options_full_scan_schedule_start', '01:00');
$next = wp_next_scheduled('gdatacyberdefenseag_antivirus_scheduled_full_scan');

if (! $full_scan_enabled && $next) {
if ($full_scan_enabled !== true && $next) {
wp_unschedule_event($next, 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
return;
}

if ($full_scan_enabled && ! $next) {
if ($full_scan_enabled === true && ! $next) {
$timestamp = strtotime($schedule_start);
$this->logger->debug('schedule start timestamp: ' . $timestamp);
wp_schedule_event($timestamp, 'daily', 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
return;
}
$nextschedule_start = gmdate('H:i', $next);
if ($nextschedule_start !== $schedule_start) {
if ($full_scan_enabled === true && $nextschedule_start !== $schedule_start) {
wp_unschedule_event($next, 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
$timestamp = strtotime($schedule_start);
wp_schedule_event($timestamp, 'daily', 'gdatacyberdefenseag_antivirus_scheduled_full_scan');
Expand Down Expand Up @@ -246,7 +246,7 @@ public function full_scan(): void {
if ($file_path->isDir()) {
continue;
}
// For testing purposes, we only scan files with eicar in the name
// // For testing purposes, we only scan files with eicar in the name
// if (str_contains($file_path->getPathname(), "eicar") === false) {
// continue;
// }
Expand Down
4 changes: 3 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ Please do not commit the code while in live mode. Just run the script again and

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

`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"`
`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"`

To debug the the cli you also have to configure xdebug to connect to your container ip.

## Disclaimer

Expand Down
4 changes: 4 additions & 0 deletions Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ While the released code is hosted on the WordPress svn, we develop the plugin on

== Changelog ==

= 2.1.0 =
* bugfix: [full scan runs in loop](https://github.com/GDATASoftwareAG/wordpress-gdata-antivirus/issues/37)
* bugifx: fails on duplicate key when detecting the same file twice

= 2.0.9 =
* bugfix: reconnect on long running scans
* add detection and sha256 name to upload detection
Expand Down

0 comments on commit 329be88

Please sign in to comment.