Skip to content

Commit 29a629a

Browse files
Settings improvements (#238)
- Add button to test current vaas configuration - Rename app settings to be more intuitive
1 parent 5ac7583 commit 29a629a

File tree

12 files changed

+94
-34
lines changed

12 files changed

+94
-34
lines changed

LICENSES/AGPL-3.0-only.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ An older license, called the Affero General Public License and published by Affe
2323

2424
The precise terms and conditions for copying, distribution and modification follow.
2525

26-
TERMS AND CONDITIONS
26+
TERMS AND CONDITIONS
2727

2828
0. Definitions.
2929

@@ -219,14 +219,14 @@ If you develop a new program, and you want it to be of the greatest possible use
219219

220220
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
221221

222-
<one line to give the program's name and a brief idea of what it does.>
223-
Copyright (C) <year> <name of author>
222+
<one line to give the program's name and a brief idea of what it does.>
223+
Copyright (C) <year> <name of author>
224224

225-
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
225+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
226226

227-
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
227+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
228228

229-
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
229+
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
230230

231231
Also add information on how to contact you by electronic and paper mail.
232232

LICENSES/CC0-1.0.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,22 @@ Related Rights"). Copyright and Related Rights include, but are not
4343
limited to, the following:
4444

4545
i. the right to reproduce, adapt, distribute, perform, display,
46-
communicate, and translate a Work;
46+
communicate, and translate a Work;
4747
ii. moral rights retained by the original author(s) and/or performer(s);
4848
iii. publicity and privacy rights pertaining to a person's image or
49-
likeness depicted in a Work;
49+
likeness depicted in a Work;
5050
iv. rights protecting against unfair competition in regards to a Work,
51-
subject to the limitations in paragraph 4(a), below;
51+
subject to the limitations in paragraph 4(a), below;
5252
v. rights protecting the extraction, dissemination, use and reuse of data
53-
in a Work;
53+
in a Work;
5454
vi. database rights (such as those arising under Directive 96/9/EC of the
55-
European Parliament and of the Council of 11 March 1996 on the legal
56-
protection of databases, and under any national implementation
57-
thereof, including any amended or successor version of such
58-
directive); and
55+
European Parliament and of the Council of 11 March 1996 on the legal
56+
protection of databases, and under any national implementation
57+
thereof, including any amended or successor version of such
58+
directive); and
5959
vii. other similar, equivalent or corresponding rights throughout the
60-
world based on applicable law or treaty, and any national
61-
implementations thereof.
60+
world based on applicable law or treaty, and any national
61+
implementations thereof.
6262

6363
2. Waiver. To the greatest extent permitted by, but not in contravention
6464
of, applicable law, Affirmer hereby overtly, fully, permanently,

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ appstore: build
129129
--exclude="$(source_build_directory)/psalm.xml" \
130130
--exclude="$(source_build_directory)/webpack.config.json" \
131131
--exclude="$(source_build_directory)/stylelint.config.json" \
132+
--exclude="$(source_build_directory)/empty-skeleton.config.php" \
132133
--exclude="$(source_build_directory)/scoper.inc.php" \
133134
--exclude="$(source_build_directory)/renovate.json" \
134135
--exclude="$(source_build_directory)/renovate.json.license" \

appinfo/routes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
['name' => 'settings#getSendMailSummaryOfMaliciousFiles', 'url'
2727
=> '/getSendMailSummaryOfMaliciousFiles', 'verb' => 'GET'],
2828
['name' => 'settings#setSendMailSummaryOfMaliciousFiles', 'url'
29-
=> '/setSendMailSummaryOfMaliciousFiles', 'verb' => 'POST']
29+
=> '/setSendMailSummaryOfMaliciousFiles', 'verb' => 'POST'],
30+
['name' => 'settings#testsettings', 'url' => '/testsettings', 'verb' => 'POST']
3031
]
3132
];

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
},
3131
"scripts": {
3232
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './nextcloud-server/*' -not -path './node_modules/*' -print0 | xargs -0 -n1 php -l",
33-
"cs:check": "rm -rf node_modules/ nextcloud-server/ || true && ./vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.dist.php .",
34-
"cs:fix": "rm -rf node_modules/ nextcloud-server/ || true && ./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php .",
35-
"psalm": "rm -rf node_modules/ || true && vendor/psalm/phar/psalm.phar",
36-
"psalm:check": "rm -rf node_modules/ || true && composer run psalm -- --threads=1 --monochrome --no-progress --output-format=github --show-info=true",
37-
"psalm:fix": "rm -rf node_modules/ || true && composer run psalm -- --alter --issues=MissingOverrideAttribute,ClassMustBeFinal,PossiblyUnusedMethod,MissingParamType",
38-
"psalm:clear": "vendor/psalm/phar/psalm.phar --clear-cache && vendor/psalm/phar/psalm.phar --clear-global-cache"
33+
"cs:check": "./vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.dist.php .",
34+
"cs:fix": "./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php .",
35+
"psalm": "./vendor/psalm/phar/psalm.phar",
36+
"psalm:check": "composer run psalm -- --threads=1 --monochrome --no-progress --output-format=github --show-info=true",
37+
"psalm:fix": "composer run psalm -- --alter --issues=MissingOverrideAttribute,ClassMustBeFinal,PossiblyUnusedMethod,MissingParamType",
38+
"psalm:clear": "./vendor/psalm/phar/psalm.phar --clear-cache && vendor/psalm/phar/psalm.phar --clear-global-cache"
3939
},
4040
"config": {
4141
"allow-plugins": {

lib/Controller/SettingsController.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,37 @@
77
namespace OCA\GDataVaas\Controller;
88

99
use OCA\GDataVaas\Service\TagService;
10+
use OCA\GDataVaas\Service\VerdictService;
1011
use OCP\AppFramework\Controller;
1112
use OCP\AppFramework\Http\JSONResponse;
1213
use OCP\DB\Exception;
1314
use OCP\IAppConfig;
1415
use OCP\IRequest;
1516
use OCP\Mail\IMailer;
17+
use VaasSdk\Exceptions\VaasAuthenticationException;
18+
use VaasSdk\Options\VaasOptions;
19+
use VaasSdk\Vaas;
20+
use VaasSdk\Verdict;
1621

1722
class SettingsController extends Controller {
1823
private IAppConfig $config;
1924
private TagService $tagService;
2025
private IMailer $mailer;
26+
private VerdictService $verdictService;
2127

2228
public function __construct(
2329
$appName,
2430
IRequest $request,
2531
IAppConfig $config,
2632
TagService $tagService,
2733
IMailer $mailer,
34+
VerdictService $verdictService,
2835
) {
2936
parent::__construct($appName, $request);
3037
$this->config = $config;
3138
$this->tagService = $tagService;
3239
$this->mailer = $mailer;
40+
$this->verdictService = $verdictService;
3341
}
3442

3543
public function setconfig(
@@ -154,4 +162,28 @@ public function setSendMailSummaryOfMaliciousFiles(bool $sendMailSummaryOfMalici
154162
$this->config->setValueBool($this->appName, 'notifyAdminEnabled', $sendMailSummaryOfMaliciousFiles);
155163
return new JSONResponse(['status' => 'success']);
156164
}
165+
166+
public function testSettings(string $tokenEndpoint, string $vaasUrl): JSONResponse {
167+
try {
168+
$authenticator = $this->verdictService->getAuthenticator($this->verdictService->authMethod, $tokenEndpoint);
169+
$options = new VaasOptions(true, true, $vaasUrl);
170+
$vaas = Vaas::builder()
171+
->withAuthenticator($authenticator)
172+
->withOptions($options)
173+
->build();
174+
$verdict = $vaas->forUrlAsync('https://www.gdata.de')->await();
175+
if ($verdict->verdict === Verdict::CLEAN) {
176+
return new JSONResponse(['status' => 'success']);
177+
}
178+
return new JSONResponse(['status' => 'error', 'message' => 'Test URL verdict: ' . $verdict->verdict->value]);
179+
} catch (VaasAuthenticationException $e) {
180+
return new JSONResponse([
181+
'status' => 'error',
182+
'message' => 'Authentication failed. Please also check your login details above and save them before
183+
taking the test. ' . $e->getMessage()
184+
]);
185+
} catch (\Exception $e) {
186+
return new JSONResponse(['status' => 'error', 'message' => $e->getMessage()]);
187+
}
188+
}
157189
}

lib/Service/VerdictService.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class VerdictService {
2828
private string $password;
2929
private string $clientId;
3030
private string $clientSecret;
31-
private string $authMethod;
31+
public string $authMethod;
3232
private string $tokenEndpoint;
3333
private string $vaasUrl;
3434
private IAppConfig $appConfig;
@@ -212,31 +212,33 @@ public function createAndConnectVaas(): Vaas {
212212
}
213213
$options = new VaasOptions(true, true, $this->vaasUrl);
214214
return Vaas::builder()
215-
->withAuthenticator($this->getAuthenticator($this->authMethod))
215+
->withAuthenticator($this->getAuthenticator($this->authMethod, $this->tokenEndpoint))
216216
->withOptions($options)
217217
->build();
218218
}
219219

220220
/**
221221
* @param string $authMethod
222+
* @param string $tokenEndpoint
222223
* @return ClientCredentialsGrantAuthenticator|ResourceOwnerPasswordGrantAuthenticator
223224
* @throws VaasAuthenticationException
224225
*/
225226
public function getAuthenticator(
226227
string $authMethod,
228+
string $tokenEndpoint,
227229
): ClientCredentialsGrantAuthenticator|ResourceOwnerPasswordGrantAuthenticator {
228230
if ($authMethod === 'ResourceOwnerPassword') {
229231
return new ResourceOwnerPasswordGrantAuthenticator(
230232
'nextcloud-customer',
231233
$this->username,
232234
$this->password,
233-
$this->tokenEndpoint
235+
$tokenEndpoint
234236
);
235237
} elseif ($authMethod === 'ClientCredentials') {
236238
return new ClientCredentialsGrantAuthenticator(
237239
$this->clientId,
238240
$this->clientSecret,
239-
$this->tokenEndpoint
241+
$tokenEndpoint
240242
);
241243
} else {
242244
throw new VaasAuthenticationException('Invalid auth method: ' . $authMethod);

lib/Settings/VaasAdminSection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(
1717

1818
#[\Override]
1919
public function getName(): string {
20-
return 'Verdict-as-a-Service';
20+
return 'G DATA Antivirus';
2121
}
2222

2323
#[\Override]

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
1919
<directory name="lib" />
2020
<ignoreFiles>
2121
<directory name="vendor" />
22+
<directory name="nextcloud-server" />
2223
</ignoreFiles>
2324
</projectFiles>
2425
<extraFiles>

src/admin-settings.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ document.addEventListener('DOMContentLoaded', async () => {
3838

3939
const authSubmit = document.querySelector('#auth_submit');
4040
const authSubmitAdvanced = document.querySelector('#auth_submit_advanced');
41+
const testSettings = document.querySelector('#test-settings');
4142
const resetAllTags = document.querySelector('#reset');
4243
const autoScanFiles = document.querySelector('#auto_scan_files');
4344
const prefixMalicious = document.querySelector('#prefixMalicious');
@@ -91,6 +92,24 @@ document.addEventListener('DOMContentLoaded', async () => {
9192
}
9293
});
9394

95+
testSettings.addEventListener('click', async (e) => {
96+
e.preventDefault();
97+
const tokenEndpoint = document.querySelector('#token_endpoint').value;
98+
const vaasUrl = document.querySelector('#vaas_url').value;
99+
100+
const response = await postData(OC.generateUrl('apps/gdatavaas/testsettings'), {
101+
tokenEndpoint,
102+
vaasUrl
103+
});
104+
const msgElement = document.querySelector('#auth_save_msg_advanced');
105+
106+
if (response.status === "success") {
107+
msgElement.textContent = 'Authentication successful and VaaS backend reachable.';
108+
} else {
109+
msgElement.textContent = response.message || 'An error occurred during the test.';
110+
}
111+
});
112+
94113
authSubmitAdvanced.addEventListener('click', async (e) => {
95114
e.preventDefault();
96115
const tokenEndpoint = document.querySelector('#token_endpoint').value;

0 commit comments

Comments
 (0)