From 652e340a26333b98f42318ede94ab92ac5d578d8 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Thu, 2 Nov 2023 22:21:45 +0100 Subject: [PATCH 1/3] fix: translate "Copied!" for monitoring url Signed-off-by: Daniel Kesselberg --- js/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/script.js b/js/script.js index 11fdf0fe..9a0ec8ab 100644 --- a/js/script.js +++ b/js/script.js @@ -225,7 +225,7 @@ function initMonitoringLinkToClipboard() { var clipboard = new Clipboard('.clipboardButton'); clipboard.on('success', function (e) { - OC.Notification.show('Copied!', { type: 'success' }) + OC.Notification.show(t('serverinfo', 'Copied!'), { type: 'success' }) }); clipboard.on('error', function () { var actionMsg = ''; From 728406bf42d793e631a90e2720eda97f3348a103 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Thu, 2 Nov 2023 16:47:18 +0100 Subject: [PATCH 2/3] fix: add flag to skip external requests Signed-off-by: Daniel Kesselberg --- README.md | 10 ++++++---- css/style.css | 11 +++++++++++ js/script.js | 25 +++++++++++++++++++++++++ lib/Controller/ApiController.php | 4 ++-- lib/Controller/PageController.php | 2 +- lib/Settings/AdminSettings.php | 2 +- lib/SystemStatistics.php | 12 +++++++++--- templates/settings-admin.php | 17 +++++++++++++---- 8 files changed, 68 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1bcb12fb..56c61dbd 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,16 @@ directory **nextcloud/apps/serverinfo** ## API -The API provides a lot of information information about a running Nextcloud -instance in XML or JSON format, by using the following URL. If you want to -get the information returned in JSON format, you have to append **`?format=json`** -to the URL. +The API provides a lot of information about a running Nextcloud +instance in XML or JSON format by using the following URL. + ``` https:///ocs/v2.php/apps/serverinfo/api/v1/info ``` +- To request the information in JSON append the url parameter `format=json` +- Use the url parameter `skipApps=true` to omit app updates (including available app updates will send an external request to the app store). + ### Example XML output: ``` diff --git a/css/style.css b/css/style.css index 871d1009..a48722f3 100644 --- a/css/style.css +++ b/css/style.css @@ -244,3 +244,14 @@ } } */ + +.monitoring-url-params { + margin-top: 3px; + margin-bottom: 3px; +} + +.monitoring-url-param { + display: flex; + align-items: center; + height: 24px; +} diff --git a/js/script.js b/js/script.js index 9a0ec8ab..ed207b65 100644 --- a/js/script.js +++ b/js/script.js @@ -310,3 +310,28 @@ } })(jQuery, OC); + +function updateMonitoringUrl(event) { + const $endpointUrl = document.getElementById('monitoring-endpoint-url'); + const $params = document.querySelectorAll('.update-monitoring-endpoint-url'); + + const url = new URL($endpointUrl.value) + url.searchParams.delete('format') + url.searchParams.delete('skipApps') + + for (const $param of $params) { + if ($param.name === 'format_json' && $param.checked) { + url.searchParams.set('format', 'json') + } + if ($param.name === 'skip_apps' && $param.checked) { + url.searchParams.set('skipApps', 'true') + } + } + + $endpointUrl.value = url.toString() +} + +document.addEventListener('DOMContentLoaded', function (event) { + const $params = document.querySelectorAll('.update-monitoring-endpoint-url'); + $params.forEach($param => $param.addEventListener('change', updateMonitoringUrl)); +}); diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index cd21d5e7..6a1a21c7 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -113,7 +113,7 @@ private function checkAuthorized(): bool { * @PublicPage * @BruteForceProtection(action=serverinfo) */ - public function info(): DataResponse { + public function info(bool $skipApps = false): DataResponse { if (!$this->checkAuthorized()) { $response = new DataResponse(['message' => 'Unauthorized']); $response->throttle(); @@ -122,7 +122,7 @@ public function info(): DataResponse { } return new DataResponse([ 'nextcloud' => [ - 'system' => $this->systemStatistics->getSystemStatistics(), + 'system' => $this->systemStatistics->getSystemStatistics($skipApps), 'storage' => $this->storageStatistics->getStorageStatistics(), 'shares' => $this->shareStatistics->getShareStatistics() ], diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 9dac631f..b66d2fc1 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -49,7 +49,7 @@ public function __construct(string $appName, */ public function update(): JSONResponse { $data = [ - 'system' => $this->systemStatistics->getSystemStatistics() + 'system' => $this->systemStatistics->getSystemStatistics(true) ]; return new JSONResponse($data); diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php index fa6d1358..7189480c 100644 --- a/lib/Settings/AdminSettings.php +++ b/lib/Settings/AdminSettings.php @@ -85,7 +85,7 @@ public function getForm(): TemplateResponse { 'php' => $this->phpStatistics->getPhpStatistics(), 'database' => $this->databaseStatistics->getDatabaseStatistics(), 'activeUsers' => $this->sessionStatistics->getSessionStatistics(), - 'system' => $this->systemStatistics->getSystemStatistics(), + 'system' => $this->systemStatistics->getSystemStatistics(true), 'thermalzones' => $this->os->getThermalZones() ]; diff --git a/lib/SystemStatistics.php b/lib/SystemStatistics.php index 2862ca0d..d6ea16a9 100644 --- a/lib/SystemStatistics.php +++ b/lib/SystemStatistics.php @@ -51,10 +51,11 @@ public function __construct(IConfig $config, IAppManager $appManager, Installer * * @throws \OCP\Files\InvalidPathException */ - public function getSystemStatistics(): array { + public function getSystemStatistics(bool $skipApps = false): array { $processorUsage = $this->getProcessorUsage(); $memoryUsage = $this->os->getMemory(); - return [ + + $data = [ 'version' => $this->config->getSystemValue('version'), 'theme' => $this->config->getSystemValue('theme', 'none'), 'enable_avatars' => $this->config->getSystemValue('enable_avatars', true) ? 'yes' : 'no', @@ -70,8 +71,13 @@ public function getSystemStatistics(): array { 'mem_free' => $memoryUsage->getMemAvailable() * 1024, 'swap_total' => $memoryUsage->getSwapTotal() * 1024, 'swap_free' => $memoryUsage->getSwapFree() * 1024, - 'apps' => $this->getAppsInfo() ]; + + if (!$skipApps) { + $data['apps'] = $this->getAppsInfo(); + } + + return $data; } /** diff --git a/templates/settings-admin.php b/templates/settings-admin.php index 961afa62..bee49edc 100644 --- a/templates/settings-admin.php +++ b/templates/settings-admin.php @@ -398,15 +398,24 @@ function FormatMegabytes(int $byte): string {

t('External monitoring tool')); ?>

- t('You can connect an external monitoring tool by using this end point:')); ?> + t('Use this end point to connect an external monitoring tool:')); ?>

-

- t('Appending "?format=json" at the end of the URL gives you the result in JSON.')); ?> -

+ +
+
+ + +
+
+ + +
+
+

t('To use an access token, please generate one then set it using the following command:')); ?>

occ config:app:set serverinfo token --value yourtoken
From 84d4942f58f91ae625a5505d96398d6de23b69c8 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Sat, 12 Aug 2023 15:38:56 +0200 Subject: [PATCH 3/3] fix: remove hint about your disk is full notification The serverinfo app does not provide such a feature. Signed-off-by: Daniel Kesselberg --- templates/settings-admin.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/templates/settings-admin.php b/templates/settings-admin.php index bee49edc..87313529 100644 --- a/templates/settings-admin.php +++ b/templates/settings-admin.php @@ -165,10 +165,6 @@ function FormatMegabytes(int $byte): string { -
- t('You will get a notification once one of your disks is nearly full.')); ?> -
-

t('Files:')); ?>

t('Storages:')); ?>