summaryrefslogtreecommitdiffstats
path: root/src/live/ogOperations.py
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2023-03-20 14:24:12 +0100
committerJose M. Guisado <jguisado@soleta.eu>2023-03-27 15:48:03 +0200
commit04bb35bd86b58c0ac4d072cadeb49d0c3fc08d8a (patch)
treec36f29ffad26f6deab6eea97ff0ab669b4a8f402 /src/live/ogOperations.py
parent2172f00cde8c37decce84470512348f15e883c55 (diff)
live: rewrite software inventoryv1.2.7
Replace legacy bash script in favor of Python code. Improves error traceability and further development. The software inventory operation mounts the target partition and it fetches the list of installed software (package set). Once the operation is complete, it unmounts the target partition. For Windows, introduce hivex library python bindings for accessing Windows registry hive files (https://libguestfs.org/hivex.3.html). This operation is still processed by legacy code in the server side (ogAdmServer.c in ogServer). Legacy backend process expects the software inventory like the following example: "software": "Windows 10 Enterprise Evaluation 2004 \nIntel(R) Network Connections 24.0.0.11 24.0.0.11 ..." The os name is inserted first in this list followed by a '\n' separated string of the software packages. The legacy server code can be found in function actualizaSoftware at ogServer/src/ogAdmServer.c It is expected for software inventory payload to change in the future to a simpler solution using just a json array of strings.
Diffstat (limited to 'src/live/ogOperations.py')
-rw-r--r--src/live/ogOperations.py35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index 6b1b01f..0e31cea 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -30,6 +30,7 @@ from src.utils.probe import os_probe, cache_probe
from src.utils.disk import *
from src.utils.cache import generate_cache_txt, umount_cache, init_cache
from src.utils.tiptorrent import *
+from src.utils.inventory import get_package_set
OG_SHELL = '/bin/bash'
@@ -252,30 +253,26 @@ class OgLiveOperations:
def software(self, request, path, ogRest):
disk = request.getDisk()
partition = request.getPartition()
+ partdev = get_partition_device(int(disk), int(partition))
+ mountpoint = partdev.replace('dev', 'mnt')
+ if not mount_mkdir(partdev, mountpoint):
+ raise RuntimeError(f'Error mounting {partdev} at {mountpoint}')
+ if not os.path.ismount(mountpoint):
+ raise RuntimeError('Invalid mountpoint for software inventory')
self._restartBrowser(self._url_log)
-
- try:
- cmd = f'{ogClient.OG_PATH}interfaceAdm/InventarioSoftware {disk} ' \
- f'{partition} {path}'
-
- ogRest.proc = subprocess.Popen([cmd],
- stdout=subprocess.PIPE,
- shell=True,
- executable=OG_SHELL)
- (output, error) = ogRest.proc.communicate()
- except:
- logging.error('Exception when running software inventory subprocess')
- raise ValueError('Error: Incorrect command value')
-
+ pkgset = get_package_set(mountpoint)
self._restartBrowser(self._url)
- software = ''
- with open(path, 'r') as f:
- software = f.read()
-
+ umount(mountpoint)
logging.info('Software inventory command OK')
- return software
+
+ # Software inventory result is still processed by legacy server code
+ # (ogAdmServer.c). Legacy response format is string where each
+ # software package is separated by a newline '\n'.
+ # Each package/software line follows this format:
+ # "{package_name} {package_version}"
+ return '\n'.join(map(str,pkgset))
def hardware(self, path, ogRest):
self._restartBrowser(self._url_log)