Skip to content

Commit 2c4735f

Browse files
Add additional settings (#239)
- Control scan timeout - Control usage of cache - Control usage of hash lookup
1 parent 29a629a commit 2c4735f

File tree

12 files changed

+106
-41
lines changed

12 files changed

+106
-41
lines changed

.devcontainer/devcontainer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
"customizations": {
99
"vscode": {
1010
"extensions": [
11-
"junstyle.php-cs-fixer",
1211
"stylelint.vscode-stylelint",
1312
"jetmartin.bats",
14-
"recca0120.vscode-phpunit"
13+
"ms-azuretools.vscode-containers",
14+
"github.vscode-github-actions",
15+
"ms-vscode.makefile-tools",
16+
"ms-vscode-remote.remote-containers",
17+
"DEVSENSE.phptools-vscode",
18+
"redhat.vscode-yaml"
1519
]
1620
}
1721
},

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ local: build
101101
docker stop nextcloud-container || true
102102
docker container rm nextcloud-container || true
103103
docker run --rm -d -p 8080:80 --name nextcloud-container -e SERVER_BRANCH="v31.0.8" -v .:/var/www/html/apps-extra/gdatavaas ghcr.io/juliusknorr/nextcloud-dev-php84:latest
104+
composer install
104105

105106
# Builds the app for production and prepares it for the appstore under ./build/artifacts
106107
.PHONY: appstore

appinfo/routes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
=> '/getSendMailSummaryOfMaliciousFiles', 'verb' => 'GET'],
2828
['name' => 'settings#setSendMailSummaryOfMaliciousFiles', 'url'
2929
=> '/setSendMailSummaryOfMaliciousFiles', 'verb' => 'POST'],
30-
['name' => 'settings#testsettings', 'url' => '/testsettings', 'verb' => 'POST']
30+
['name' => 'settings#testsettings', 'url' => '/testsettings', 'verb' => 'POST'],
31+
['name' => 'settings#getCache', 'url' => '/getCache', 'verb' => 'GET'],
32+
['name' => 'settings#getHashlookup', 'url' => '/getHashlookup', 'verb' => 'GET']
3133
]
3234
];

css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ select {
2525
box-sizing: border-box;
2626
}
2727

28+
.basic_settings_table .input_field input[type=checkbox] {
29+
margin: 8px 0 8px 50px;
30+
}
31+
2832
input.toggle-round {
2933
display: none;
3034
}

lib/Controller/SettingsController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function setconfig(
5151
$doNotScanThis,
5252
$notifyMails,
5353
$maxScanSize,
54+
$timeout,
55+
bool $cache,
56+
bool $hashlookup,
5457
): JSONResponse {
5558
if (!empty($notifyMails)) {
5659
$mails = explode(',', preg_replace('/\s+/', '', $notifyMails));
@@ -63,6 +66,9 @@ public function setconfig(
6366
if ((int)$maxScanSize < 1) {
6467
return new JSONResponse(['status' => 'error', 'message' => 'Invalid max scan size: ' . $maxScanSize]);
6568
}
69+
if ((int)$timeout < 1) {
70+
return new JSONResponse(['status' => 'error', 'message' => 'Invalid timeout: ' . $timeout]);
71+
}
6672
$this->config->setValueString($this->appName, 'username', $username);
6773
$this->config->setValueString($this->appName, 'password', $password);
6874
$this->config->setValueString($this->appName, 'clientId', $clientId);
@@ -73,6 +79,9 @@ public function setconfig(
7379
$this->config->setValueString($this->appName, 'doNotScanThis', $doNotScanThis);
7480
$this->config->setValueString($this->appName, 'notifyMails', $notifyMails);
7581
$this->config->setValueInt($this->appName, 'maxScanSizeInMB', (int)$maxScanSize);
82+
$this->config->setValueInt($this->appName, 'timeout', (int)$timeout);
83+
$this->config->setValueBool($this->appName, 'cache', $cache);
84+
$this->config->setValueBool($this->appName, 'hashlookup', $hashlookup);
7685
return new JSONResponse(['status' => 'success']);
7786
}
7887

@@ -186,4 +195,12 @@ public function testSettings(string $tokenEndpoint, string $vaasUrl): JSONRespon
186195
return new JSONResponse(['status' => 'error', 'message' => $e->getMessage()]);
187196
}
188197
}
198+
199+
public function getCache(): JSONResponse {
200+
return new JSONResponse(['status' => $this->config->getValueBool($this->appName, 'cache', true)]);
201+
}
202+
203+
public function getHashlookup(): JSONResponse {
204+
return new JSONResponse(['status' => $this->config->getValueBool($this->appName, 'hashlookup', true)]);
205+
}
189206
}

lib/Service/VerdictService.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,12 @@ public function createAndConnectVaas(): Vaas {
210210
$this->vaasUrl = 'https://' . substr($this->vaasUrl, 6);
211211
}
212212
}
213-
$options = new VaasOptions(true, true, $this->vaasUrl);
213+
$options = new VaasOptions(
214+
useHashLookup: $this->appConfig->getValueBool(Application::APP_ID, 'hashlookup', true),
215+
useCache: $this->appConfig->getValueBool(Application::APP_ID, 'cache', true),
216+
vaasUrl: $this->vaasUrl,
217+
timeout: $this->appConfig->getValueInt(Application::APP_ID, 'timeout', 300)
218+
);
214219
return Vaas::builder()
215220
->withAuthenticator($this->getAuthenticator($this->authMethod, $this->tokenEndpoint))
216221
->withOptions($options)

lib/Settings/VaasAdmin.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ public function getForm(): TemplateResponse {
5757
=> $this->config->getValueBool(Application::APP_ID, 'sendMailOnVirusUpload'),
5858
'notifyAdminEnabled' => $this->config->getValueBool(Application::APP_ID, 'notifyAdminEnabled'),
5959
'maxScanSizeInMB'
60-
=> $this->config->getValueInt(Application::APP_ID, 'maxScanSizeInMB', 256)
60+
=> $this->config->getValueInt(Application::APP_ID, 'maxScanSizeInMB', 256),
61+
'timeout' => $this->config->getValueInt(Application::APP_ID, 'timeout', 300),
62+
'cache' => $this->config->getValueBool(Application::APP_ID, 'cache', true),
63+
'hashlookup' => $this->config->getValueBool(Application::APP_ID, 'hashlookup', true),
6164
];
6265

6366
return new TemplateResponse(Application::APP_ID, 'admin', $params);

src/admin-settings.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ document.addEventListener('DOMContentLoaded', async () => {
6666
const doNotScanThis = document.querySelector('#doNotScanThis').value;
6767
const notifyMails = document.querySelector('#notify_mails').value;
6868
const maxScanSize = document.querySelector('#max-scan-size').value;
69+
const timeout = document.querySelector('#timeout').value;
70+
const cache = document.querySelector('#cache').checked;
71+
const hashlookup = document.querySelector('#hashlookup').checked;
6972

7073
const response = await postData(OC.generateUrl('apps/gdatavaas/setconfig'), {
7174
username: username,
@@ -77,7 +80,10 @@ document.addEventListener('DOMContentLoaded', async () => {
7780
scanOnlyThis,
7881
doNotScanThis,
7982
notifyMails,
80-
maxScanSize
83+
maxScanSize,
84+
timeout,
85+
cache,
86+
hashlookup
8187
});
8288
const msgElement = document.querySelector('#auth_save_msg');
8389

@@ -203,4 +209,7 @@ document.addEventListener('DOMContentLoaded', async () => {
203209
scanCounter.textContent = ' N/A';
204210
console.log('Error getting files counter:', filesCounter['message']);
205211
}
212+
213+
document.querySelector('#cache').checked = (await getData(OC.generateUrl('apps/gdatavaas/getCache'))).status;
214+
document.querySelector('#hashlookup').checked = (await getData(OC.generateUrl('apps/gdatavaas/getHashlookup'))).status;
206215
});

src/files-action.js

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,42 @@ registerFileAction(new FileAction({
1515
},
1616
iconSvgInline: () => Magnifier,
1717
async exec(file) {
18-
const fileId = file.fileid;
19-
let response = await fetch(OC.generateUrl('/apps/gdatavaas/scan'), {
20-
method: 'POST',
21-
headers: {
22-
'Content-Type': 'application/json',
23-
'requesttoken': oc_requesttoken
24-
},
25-
body: JSON.stringify({
26-
fileId: fileId
27-
})
28-
});
29-
let vaasVerdict = await response.json();
30-
if (response.status === 200) {
31-
switch (vaasVerdict['verdict']) {
32-
case 'Malicious':
33-
showError(t('gdatavaas', 'The file "' + file.basename + '" has been scanned with G DATA as verdict Malicious'));
34-
break;
35-
case 'Clean':
36-
showSuccess(t('gdatavaas', 'The file "' + file.basename + '" has been scanned with G DATA as verdict Clean'));
37-
break;
38-
case 'Pup':
39-
showWarning(t('gdatavaas', 'The file "' + file.basename + '" has been scanned with G DATA as ' +
40-
'verdict PUP (Potentially unwanted program)'));
41-
break;
42-
}
43-
} else {
44-
try {
45-
showError(t('gdatavaas', vaasVerdict.error));
46-
} catch (e) {
47-
showError(t('gdatavaas', 'An unknown error occurred while scanning the file'));
18+
try {
19+
const fileId = file.fileid;
20+
let response = await fetch(OC.generateUrl('/apps/gdatavaas/scan'), {
21+
method: 'POST',
22+
headers: {
23+
'Content-Type': 'application/json',
24+
'requesttoken': oc_requesttoken
25+
},
26+
body: JSON.stringify({
27+
fileId: fileId
28+
})
29+
});
30+
let vaasVerdict = await response.json();
31+
if (response.status === 200) {
32+
switch (vaasVerdict['verdict']) {
33+
case 'Malicious':
34+
showError(t('gdatavaas', 'The file "' + file.basename + '" has been scanned with G DATA as verdict Malicious'));
35+
break;
36+
case 'Clean':
37+
showSuccess(t('gdatavaas', 'The file "' + file.basename + '" has been scanned with G DATA as verdict Clean'));
38+
break;
39+
case 'Pup':
40+
showWarning(t('gdatavaas', 'The file "' + file.basename + '" has been scanned with G DATA as ' +
41+
'verdict PUP (Potentially unwanted program)'));
42+
break;
43+
}
44+
} else {
45+
try {
46+
showError(t('gdatavaas', vaasVerdict.error));
47+
} catch (e) {
48+
showError(t('gdatavaas', 'An unknown error occurred while scanning the file'));
49+
}
4850
}
4951
}
52+
catch (e) {
53+
showError(t('gdatavaas', 'An error occurred while trying to scan the file: ') + e);
54+
}
5055
},
5156
}))

templates/admin.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<h6>You may use self registration and create a new username and password by yourself <a href="https://vaas.gdata.de/login" target="_blank">here</a> for free.</h6>
2020
<table class="basic_settings_table">
2121
<tr class="basic_settings">
22-
<td><div title="<?php p($l->t('If you have registered yourself with your e-mail address and a password, select "Resource Owner Password Flow" here, if you have received a client id and a client secret from G DATA CyberDefense AG, use "Client Credentials Flow". You can ignore the other fields.'));?>" class="visible"><label for="auth_method"><?php p($l->t('Authentication Method'));?></label></div></td>
22+
<td><div title="<?php p($l->t('If you have registered yourself with your e-mail address and a password, select "Resource Owner Password Flow" here, if you have received a client id and a client secret from G DATA CyberDefense AG, use "Client Credentials Flow". You can ignore the other fields.'));?>" class="visible"><label for="authMethod"><?php p($l->t('Authentication Method'));?></label></div></td>
2323
<td class="input_field">
2424
<select id="authMethod" name="authMethod">
2525
<option value="ClientCredentials" <?php if ($_['authMethod'] === 'ClientCredentials') {
@@ -66,6 +66,22 @@
6666
<td><div title="<?php p($l->t('The maximum scan size for files to be scanned in MB. Files above this limit are tagged as “Won\'t Scan”.'));?>" class="visible"><label for="max-scan-size"><?php p($l->t('Maximum scan size'));?></label></div></td>
6767
<td class="input_field"><input id="max-scan-size" type="number" min="0" name="max-scan-size" value="<?php p($_['maxScanSizeInMB']); ?>"/></td>
6868
</tr>
69+
<tr class="timeout">
70+
<td><div title="<?php p($l->t('The timeout determines how long a file scan may take in seconds before it is canceled. Please note: If the timeout is set too short, it will restrict the scanning of large files, which take a little longer.'));?>" class="visible"><label for="timeout"><?php p($l->t('Timeout'));?></label></div></td>
71+
<td class="input_field"><input id="timeout" type="number" min="0" name="timeout" value="<?php p($_['timeout']); ?>"/></td>
72+
</tr>
73+
<tr class="cache">
74+
<td><div title="<?php p($l->t('If this option is disabled, each file is always scanned again and no results are cached.'));?>" class="visible"><label for="cache"><?php p($l->t('Cache'));?></label></div></td>
75+
<td class="input_field"><input id="cache" type="checkbox" name="cache" <?php if ($_['cache']) {
76+
p('checked');
77+
} ?>/></td>
78+
</tr>
79+
<tr class="hashlookup">
80+
<td><div title="<?php p($l->t('During a hash lookup, the SHA256 checksum is transmitted to the G DATA Cloud before the scan to check whether a result is already available, thereby saving unnecessary network traffic, resource load, and time.'));?>" class="visible"><label for="hashlookup"><?php p($l->t('Hash lookup'));?></label></div></td>
81+
<td class="input_field"><input id="hashlookup" type="checkbox" name="hashlookup" <?php if ($_['hashlookup']) {
82+
p('checked');
83+
} ?>/></td>
84+
</tr>
6985
</table>
7086
<input class="submit-button" id="auth_submit" type="submit" value="<?php p($l->t('Save'));?>" />
7187
<span id="auth_save_msg"></span>

0 commit comments

Comments
 (0)