From 219ee3cc3480a5dfb97ad25953e0e81b7dad4bd1 Mon Sep 17 00:00:00 2001 From: Yurii Nazarenko Date: Fri, 7 Jun 2024 16:47:16 +0200 Subject: [PATCH] #33, Move mounting loader disk to the scripts level --- Makefile | 2 +- src/conf/privilege_ | 10 ++++++++++ src/src/appWindow.js | 2 -- src/src/tabs/main.js | 1 - src/ui/getAddons.cgi | 22 +++++++++++++++++++--- src/ui/getConfig.cgi | 14 +++++++++++++- 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 640916f..22cbbf3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SPK_NAME = rr-manager SPK_VERS = 2.0 -SPK_REV = 42 +SPK_REV = 43 SPK_ICON = src/rr-manager.png DSM_UI_DIR = ui diff --git a/src/conf/privilege_ b/src/conf/privilege_ index 356a0b1..2f7780c 100644 --- a/src/conf/privilege_ +++ b/src/conf/privilege_ @@ -26,5 +26,15 @@ "action": "postinst", "run-as": "package" } + ], + "executable": [ + { + "relpath": "ui/getConfig.cgi", + "run-as": "package" + }, + { + "relpath": "ui/getAddons.cgi", + "run-as": "package" + } ] } \ No newline at end of file diff --git a/src/src/appWindow.js b/src/src/appWindow.js index 76074d4..d225b8f 100644 --- a/src/src/appWindow.js +++ b/src/src/appWindow.js @@ -65,11 +65,9 @@ export default }, onOpen: function (a) { - this.apiProvider.runScheduledTask('MountLoaderDisk'); SYNOCOMMUNITY.RRManager.AppWindow.superclass.onOpen.call(this, a); }, onDestroy: function (e) { - this.apiProvider.runScheduledTask('UnMountLoaderDisk'); SYNOCOMMUNITY.RRManager.AppWindow.superclass.onDestroy.call(this); } }); \ No newline at end of file diff --git a/src/src/tabs/main.js b/src/src/tabs/main.js index 1d1c1b5..a091b39 100644 --- a/src/src/tabs/main.js +++ b/src/src/tabs/main.js @@ -164,7 +164,6 @@ export default const self = this; if (this.loaded) return; self.appWin.setStatusBusy(null, null, 50); - // self.apiProvider.runScheduledTask('MountLoaderDisk'); (async () => { const [systemInfo, packages, rrCheckVersion] = await Promise.all([ self.apiProvider.getSytemInfo(), diff --git a/src/ui/getAddons.cgi b/src/ui/getAddons.cgi index 99993a4..842e5d3 100644 --- a/src/ui/getAddons.cgi +++ b/src/ui/getAddons.cgi @@ -4,6 +4,7 @@ import os import json import sys import cgi +import subprocess from pathlib import Path path_root = Path(__file__).parents[1] sys.path.append(str(path_root)+'/libs') @@ -25,9 +26,8 @@ def read_user_config(): return "{}" -userConfig = read_user_config() -def read_manifests_in_subdirs(parent_directory): +def read_manifests_in_subdirs(parent_directory,userConfig): manifests = [] for subdir in next(os.walk(parent_directory))[1]: # Iterates through each subdirectory @@ -57,11 +57,27 @@ user = f.read().strip() ADDONS_PATH = '/mnt/p3/addons/' response = {} +def callMountLoaderScript(action): + process = subprocess.Popen(['/usr/bin/rr-loaderdisk.sh', action], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) + +def mountLoader(): + callMountLoaderScript('mountLoaderDisk') + +def unmountLoader(): + callMountLoaderScript('unmountLoaderDisk') + if len(user) > 0: - addons = read_manifests_in_subdirs(ADDONS_PATH) + # call function to mount the loader by calling the following bash /usr/bin/rr-loaderdisk.sh mountLoaderDisk + mountLoader() + userConfig = read_user_config() + addons = read_manifests_in_subdirs(ADDONS_PATH,userConfig) response['result'] = addons response['success'] = True response['total'] = len(addons) + # call function to unmount the loader by calling the following bash /usr/bin/rr-loaderdisk.sh unmountLoaderDisk + unmountLoader() else: response["status"] = "not authenticated" diff --git a/src/ui/getConfig.cgi b/src/ui/getConfig.cgi index b06d3ae..1dd1c2d 100644 --- a/src/ui/getConfig.cgi +++ b/src/ui/getConfig.cgi @@ -3,6 +3,7 @@ import os import json import sys +import subprocess from pathlib import Path path_root = Path(__file__).parents[1] @@ -63,7 +64,16 @@ def read_rr_awaiting_update(fileName): except e: return "healthy" - +def callMountLoaderScript(action): + process = subprocess.Popen(['/usr/bin/rr-loaderdisk.sh', action], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) + +def mountLoader(): + callMountLoaderScript('mountLoaderDisk') + +def unmountLoader(): + callMountLoaderScript('unmountLoaderDisk') # Authenticate the user f = os.popen('/usr/syno/synoman/webman/modules/authenticate.cgi', 'r') user = f.read().strip() @@ -71,6 +81,7 @@ user = f.read().strip() response = {} if len(user) > 0: + mountLoader() response["status"] = "authenticated" response["user"] = user @@ -83,6 +94,7 @@ if len(user) > 0: response["rr_manager_privilege"] = read_rrmanager_privilege('/var/packages/rr-manager/conf/privilege') # response["rr_manager_resource"] = read_rrmanager_privilege('/var/packages/rr-manager/conf/resource') response["rr_health"] = read_rr_awaiting_update(response["rr_manager_config"].get("RR_UPDATE_PROGRESS_FILE")) + unmountLoader() else: response["status"] = "not authenticated"