Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/undo-ransomware/ransomware_detection.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Held <ilovemilk@wusa.io>2019-06-16 18:20:44 +0300
committerMatthias Held <ilovemilk@wusa.io>2019-06-16 18:20:44 +0300
commit38f0257d15eedd3d8b1764cd4d05e0137d4164a4 (patch)
treec5c7fde82c33cdb086e272c58eb28c45c058593a
parent5b44c2ca136e12a0c03cd34dec20f86a94522dde (diff)
add detection controller and service
-rw-r--r--appinfo/routes.php3
-rw-r--r--lib/AppInfo/Application.php14
-rw-r--r--lib/Controller/DetectionController.php80
-rw-r--r--lib/Model/Detection.php42
-rw-r--r--lib/Service/DetectionService.php37
-rw-r--r--lib/Service/FileOperationService.php1
-rw-r--r--lib/Service/IServiceWatcher.php1
-rw-r--r--lib/Service/ServiceWatcher.php1
8 files changed, 176 insertions, 3 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 18fb003..cb1a588 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -21,5 +21,8 @@ return [
// Service controller
['name' => 'service#findAll', 'url' => '/api/{apiVersion}/service', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1']],
['name' => 'service#find', 'url' => '/api/{apiVersion}/service/{id}', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1']],
+ // Detection controller
+ ['name' => 'detection#findAll', 'url' => '/api/{apiVersion}/detection', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1']],
+ ['name' => 'detection#find', 'url' => '/api/{apiVersion}/detection/{id}', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1']],
],
];
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 09afaaa..77d3e1b 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -27,7 +27,9 @@ use OCA\RansomwareDetection\Entropy\Entropy;
use OCA\RansomwareDetection\StorageWrapper;
use OCA\RansomwareDetection\Service\FileOperationService;
use OCA\RansomwareDetection\Service\ServiceWatcher;
+use OCA\RansomwareDetection\Service\DetectionService;
use OCA\RansomwareDetection\Controller\ServiceController;
+use OCA\RansomwareDetection\Controller\DetectionController;
use OCA\RansomwareDetection\Mapper\FileOperationMapper;
use OCP\AppFramework\App;
use OCP\Files\Storage\IStorage;
@@ -68,6 +70,10 @@ class Application extends App
return new ServiceWatcher();
});
+ $container->registerService('DetectionService', function ($c) {
+ return new DetectionService();
+ });
+
// controller
$container->registerService('ServiceController', function ($c) {
return new ServiceController(
@@ -77,6 +83,14 @@ class Application extends App
);
});
+ $container->registerService('DetectionController', function ($c) {
+ return new DetectionController(
+ $c->query('AppName'),
+ $c->query('Request'),
+ $c->query('DetectionService')
+ );
+ });
+
// entropy
$container->registerService('Entropy', function ($c) {
return new Entropy(
diff --git a/lib/Controller/DetectionController.php b/lib/Controller/DetectionController.php
new file mode 100644
index 0000000..dc0a527
--- /dev/null
+++ b/lib/Controller/DetectionController.php
@@ -0,0 +1,80 @@
+<?php
+
+/**
+ * @copyright Copyright (c) 2018 Matthias Held <matthias.held@uni-konstanz.de>
+ * @author Matthias Held <matthias.held@uni-konstanz.de>
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\RansomwareDetection\Controller;
+
+use OCA\RansomwareDetection\AppInfo\Application;
+use OCA\RansomwareDetection\Service\DetectionService;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
+use OCP\AppFramework\Controller;
+use OCP\IConfig;
+use OCP\IUserSession;
+use OCP\IRequest;
+
+class DetectionController extends Controller
+{
+ /** @var DetectionService */
+ protected $detectionService;
+
+ /**
+ * @param string $appName
+ * @param IRequest $request
+ * @param DetectionService $detectionService
+ */
+ public function __construct(
+ $appName,
+ IRequest $request,
+ DetectionService $detectionService
+ ) {
+ parent::__construct($appName, $request);
+
+ $this->detectionService = $detectionService;
+ }
+
+ /**
+ * List detections.
+ *
+ * @NoCSRFRequired
+ * @NoAdminRequired
+ *
+ * @return JSONResponse
+ */
+ public function findAll() {
+ $detections = $this->detectionService->getDetections();
+
+ return new JSONResponse($detections, Http::STATUS_OK);
+ }
+
+ /**
+ * Find detection with $id.
+ *
+ * @NoCSRFRequired
+ * @NoAdminRequired
+ *
+ * @return JSONResponse
+ */
+ public function find($id) {
+ $detection = $this->detectionService->getDetection($id);
+
+ return new JSONResponse($detection, Http::STATUS_OK);
+ }
+} \ No newline at end of file
diff --git a/lib/Model/Detection.php b/lib/Model/Detection.php
new file mode 100644
index 0000000..7c65de2
--- /dev/null
+++ b/lib/Model/Detection.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * @copyright Copyright (c) 2019 Matthias Held <matthias.held@uni-konstanz.de>
+ * @author Matthias Held <matthias.held@uni-konstanz.de>
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\RansomwareDetection\Model;
+
+class Detection implements \JsonSerializable {
+ private $fileOperations;
+
+ public function __construct($fileOperations) {
+ $this->fileOperations = $fileOperations;
+ }
+
+ public function getFileOperations() {
+ return $this->fileOperations;
+ }
+
+ public function setFileOperations($fileOperations) {
+ $this->fileOperations = $fileOperations;
+ }
+
+ public function jsonSerialize()
+ {
+ return get_object_vars($this);
+ }
+} \ No newline at end of file
diff --git a/lib/Service/DetectionService.php b/lib/Service/DetectionService.php
new file mode 100644
index 0000000..6be605a
--- /dev/null
+++ b/lib/Service/DetectionService.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * @copyright Copyright (c) 2019 Matthias Held <matthias.held@uni-konstanz.de>
+ * @author Matthias Held <matthias.held@uni-konstanz.de>
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\RansomwareDetection\Service;
+
+use OCA\RansomwareDetection\Model\Detection;
+
+class DetectionService {
+
+ public function getDetections() {
+ return [
+ new Detection(array()),
+ new Detection(array())
+ ];
+ }
+
+ public function getDetection() {
+ return new Detection(array());
+ }
+} \ No newline at end of file
diff --git a/lib/Service/FileOperationService.php b/lib/Service/FileOperationService.php
index fb31e81..63cce8f 100644
--- a/lib/Service/FileOperationService.php
+++ b/lib/Service/FileOperationService.php
@@ -1,5 +1,4 @@
<?php
-
/**
* @copyright Copyright (c) 2017 Matthias Held <matthias.held@uni-konstanz.de>
* @author Matthias Held <matthias.held@uni-konstanz.de>
diff --git a/lib/Service/IServiceWatcher.php b/lib/Service/IServiceWatcher.php
index c5fab04..b9b727f 100644
--- a/lib/Service/IServiceWatcher.php
+++ b/lib/Service/IServiceWatcher.php
@@ -1,5 +1,4 @@
<?php
-
/**
* @copyright Copyright (c) 2019 Matthias Held <matthias.held@uni-konstanz.de>
* @author Matthias Held <matthias.held@uni-konstanz.de>
diff --git a/lib/Service/ServiceWatcher.php b/lib/Service/ServiceWatcher.php
index 69351cd..6ed2d0e 100644
--- a/lib/Service/ServiceWatcher.php
+++ b/lib/Service/ServiceWatcher.php
@@ -1,5 +1,4 @@
<?php
-
/**
* @copyright Copyright (c) 2019 Matthias Held <matthias.held@uni-konstanz.de>
* @author Matthias Held <matthias.held@uni-konstanz.de>