summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Müller <marcel-mueller@gmx.de>2023-06-22 22:53:39 +0200
committerMarcel Müller <marcel-mueller@gmx.de>2023-07-10 08:21:51 +0200
commitace7be5754eb254728bc725b037f4603db48a8ae (patch)
tree1c23d7d484a0bab4554fea57a477f6864d471f35
parent152ba97d909b2822dffb7fc21b57066c1f3b7d80 (diff)
Add controller for certificate check
Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
-rw-r--r--appinfo/routes.php1
-rw-r--r--appinfo/routes/routesCertificateController.php35
-rw-r--r--lib/Controller/CertificateController.php63
3 files changed, 99 insertions, 0 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index b6a2a9966..e75d8b2c8 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -28,6 +28,7 @@ return array_merge_recursive(
include(__DIR__ . '/routes/routesAvatarController.php'),
include(__DIR__ . '/routes/routesBreakoutRoomController.php'),
include(__DIR__ . '/routes/routesCallController.php'),
+ include(__DIR__ . '/routes/routesCertificateController.php'),
include(__DIR__ . '/routes/routesChatController.php'),
include(__DIR__ . '/routes/routesCommandController.php'),
include(__DIR__ . '/routes/routesFederationController.php'),
diff --git a/appinfo/routes/routesCertificateController.php b/appinfo/routes/routesCertificateController.php
new file mode 100644
index 000000000..83e62606f
--- /dev/null
+++ b/appinfo/routes/routesCertificateController.php
@@ -0,0 +1,35 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2023 Marcel Müller <marcel.mueller@nextcloud.com>
+ *
+ * @author Marcel Müller <marcel.mueller@nextcloud.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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/>.
+ *
+ */
+
+$requirements = [
+ 'apiVersion' => 'v1',
+];
+
+return [
+ 'ocs' => [
+ /** @see \OCA\Talk\Controller\CertificateController::getCertificateExpiration() */
+ ['name' => 'Certificate#getCertificateExpiration', 'url' => '/api/{apiVersion}/certificate/expiration', 'verb' => 'GET', 'requirements' => $requirements],
+ ],
+];
diff --git a/lib/Controller/CertificateController.php b/lib/Controller/CertificateController.php
new file mode 100644
index 000000000..4d2a91600
--- /dev/null
+++ b/lib/Controller/CertificateController.php
@@ -0,0 +1,63 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Marcel Müller <marcel.mueller@nextcloud.com>
+ *
+ * @author Marcel Müller <marcel.mueller@nextcloud.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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/>.
+ *
+ */
+
+namespace OCA\Talk\Controller;
+
+use OCA\Talk\Service\CertificateService;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCSController;
+use OCP\IRequest;
+use OCP\IL10N;
+use Psr\Log\LoggerInterface;
+
+class CertificateController extends OCSController {
+ public function __construct(
+ string $appName,
+ IRequest $request,
+ protected CertificateService $certificateService,
+ protected IL10N $l,
+ protected LoggerInterface $logger,
+ ) {
+ parent::__construct($appName, $request);
+ }
+
+ public function getCertificateExpiration(string $host): DataResponse {
+ try {
+ $expirationInDays = $this->certificateService->getCertificateExpirationInDays($host);
+
+ return new DataResponse([
+ 'expiration_in_days' => $expirationInDays,
+ ]);
+ } catch (\Exception $e) {
+ $this->logger->error('Failed get certificate expiration', [
+ 'exception' => $e,
+ ]);
+
+ return new DataResponse(['message' => $this->l->t('An error occurred. Please contact your administrator.')], Http::STATUS_BAD_REQUEST);
+ }
+ }
+}