summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* utils: add fs.pyJose M. Guisado2023-02-081-1/+66
| | | | | | | | | | | Adds utility module which wraps several mkfs.* calls as a subprocess. The main utility function is mkfs(fs, disk, partition, label), which subsequently calls the corresponding mkfs_*(partition_device) function. mkfs() supports specifying a drive label where supported. Other modules using fs.py should call mkfs() only.
* live: add parttypes.pyJose M. Guisado2023-02-081-0/+55
| | | | | | | | | | | | | Adds parttypes.py module with utility functions to get partition types (parttypes) from python-libfdisk. Supports standard partition types, either DOS or GPT. DOS labels use a hex code to define partition types, python-libfdisk exposes get_parttype_from_code to look up for DOS partition types from a given hexcode. GPT label uses a string (UUID) for each supported partition type, python-libfdisk exposes get_parttype_from_string to look up for GPT partition types from a given string.
* live: clear ogbrowser log before image_createv1.2.4Jose M. Guisado2022-12-051-0/+1
| | | | | Remove any previous unrelated log message shown in the "real time log" html page before executing this command.
* log: add file handler for ogLive "real time log"Jose M. Guisado2022-12-051-0/+9
| | | | | | | | | | | Clients running in ogLive can show log messages via a lighttp server. Particularly, a html page named "real time log" consists of <text-area> tags with the contents of two particular text files /tmp/session.log and /tmp/command.log Adds a Python logging handler in order to write ogClient log messages into /tmp/session.log. This way ogClient logs are show in the "real time log" html page too.
* live: clear ogbrowser logs before image_restoreJose M. Guisado2022-12-011-1/+7
| | | | | | | | | | Clears content of blue text areas in the real time log view before executing a restore image operation. Adds private function _ogbrowser_clear_logs, this function writes to a couple of text files present in the ogLive environment. The contents of this file are printed out to the blue text areas in the "real time log" view.
* live: improve error pathsv1.2.3Jose M. Guisado2022-11-172-5/+22
| | | | | | | | | | | | | Fix error paths in live operations which do not reset the "browser" to the main page (one with the menu). Add error logging messages when: * _restartBrowser fails. * ogChangeRepo fails. Improve checksum fetch error handling. For example, when an invalid repository IP is specified.
* log: declare samba handler only in live modeJavier Sánchez Parra2022-11-021-9/+20
| | | | | | ogClient in linux mode only write its logs to syslog and the console. Also, raise exception if mode its not supported.
* log: import fcntl only on linuxJavier Sánchez Parra2022-11-021-67/+73
| | | | | Otherwise, ogClient do not work on Windows because fcntl module do not exists on Windows.
* live: support native unicast cache image restoreJose M. Guisado2022-11-021-3/+32
| | | | | | | | | | | | | UNICAST-CACHE consist of: 1. Checking if the target image is already present at the opengnsys cache partition. If so, check for integrity (local and remote checksum). If the image is not present in the cache partition, download the target image into it. 2. Restore the image from cache partition. This commit add support for this operation natively from ogClient Python's code.
* tiptorrent: improve raised exceptions for tip_client_getJose M. Guisado2022-09-291-4/+2
| | | | | | Raise exception when tiptorrent-client subprocess runs normally but exits with non-zero code. (For example, if download file allocation failed)
* live: don't use python open() when reading imageJose M. Guisado2022-09-231-5/+3
| | | | | | | | Specifies the image path in the lzop subprocess string. It might be interesting to study efficient mechanisms to read large binary files in python before using open() with default parameters for buffered binary reading.
* live: rewrite image_restoreJose M. Guisado2022-09-143-21/+99
| | | | | | | | Integrates image restore command into native ogClient code. Further reduces the need for external Bash scripts. After a succesful image restore, OS configuration is still using external Bash script "osConfigure/osConfigureCustom".
* utils: add tiptorrent.pyJose M. Guisado2022-09-141-0/+90
| | | | | Utility and wrapper functions related to the usage of tiptorrent. To be used by the image restore command.
* utils: add get_partition_deviceJose M. Guisado2022-09-141-0/+17
| | | | | Maps a disk and partition number to the corresponding device path ('/dev/sdXY', '/dev/nvmeXnYpZ', ...)
* image_restore: fix ogCopyEfiBootLoaderJose M. Guisado2022-09-142-4/+5
| | | | | | | | | ogCopyEfiBootloader is an invalid legacy bash function name. Rename to the correct function name 'ogCopyEfiBootLoader' and rename utility python wrapper too. Fixes: 0bd037c1a409c65fbcb01355ee0dd6dca770330e
* utils: minor fix for ogReduceFs and ogExtendFsJose M. Guisado2022-09-142-12/+11
| | | | | | | | | | Do not return the subprocess result for ogReduceFs/ogExtendFs. ogReduceFs works with or without the target filesystem mounted. ogExtendFs requires the target filesystem to be mounted. 'ogMount' legacy script invocation should be replaced by a better mount/umount wrapper.
* image_create: add legacy ogCopyEfiBootloaderJose M. Guisado2022-09-142-0/+11
| | | | | | | | | | | | | | Use legacy script that saves the Windows-specific content from the ESP to the image target filesystem. Current image restore solution from OpenGnsys scripts expect the EFI partition to be stored in the target system partition. (Only for Windows 10) For example, storing the ESP in the NTFS partition of a Windows image. Expect use of bash script ogCopyEfiBootloader until further integration is merged.
* image_create: partial integration into pythonv1.2.2Jose M. Guisado2022-08-243-26/+162
| | | | | | | | | | | Integrates some parts of this operation into native code, eg: the md5 checksum computation. Wraps non native processes and commands using the subprocess module. For example, legacy.py stores bash commands pending integration. Supports python >=3.6, expected until more modern ogLives are put into production environments.
* refresh: use '0' if disk has no labelJose M. Guisado2022-08-221-1/+4
| | | | | | | | If disk has no label, python-libfdisk returns None when accessing cxt.label Fixes bug when running refresh on computers whose disk/s have no label.
* live: enable details for libfdisk context objectv1.2.1Jose M. Guisado2022-06-081-1/+1
| | | | | | | Enables details in libfidsk context constructor call. Ensures size are displayed as bytes (and not as a human readable string). Avoids further arithmetical errors (e.g: converting from bytes to KB)
* live: remove unused parseGetConf functionJose M. Guisado2022-06-081-27/+0
| | | | | | parseGetConf was necessary for parsing output from OpenGnsys script "getConfiguration", which has been replaced since commit 1ab981a539f3 ("live: replace getConfiguration with refresh")
* src: improve loggingJose M. Guisado2022-06-087-25/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | Adds new logging handler redirecting messages to the log file located in the Samba shared directory (applies to live mode clients, i.e: ogLive) Parses log level configuration from ogclient.json. See: { "opengnsys": { ... "log": "INFO", ... } ... } Adds --debug option to set root logger level to DEBUG when starting ogClient. Overrides log level from config file. In addition: - Replaces any occurence of print with a corresponding logging function. - Unsets log level for handlers, use root logger level instead. - Default level for root logger is INFO. - Replaces level from response log messages to debug (ogRest)
* live: replace getConfiguration with refreshJose M. Guisado2022-06-011-10/+4
| | | | | | | Old refresh was a wrapper around getConfiguration bash script. New refresh operation does what getConfiguration used to do externally. See commit 097769b971f64f93004a87393721a289fe3db13f.
* live: assume VFAT is always FAT32Javier Sánchez Parra2022-06-011-0/+3
| | | | | fdisk reports VFAT, however, OpenGnsys does not have such entry in the filesystem table. Add an alias to FAT32 as a workaround.
* utils: mount_mkdir success if target is a mountpointJose M. Guisado2022-06-011-0/+6
| | | | | | | | Returns true if target is already a mountpoint. Does not call mount. It's possible that another device might be mounted in the target mountpoint. A future check between the source and target for equal device major:minor must be added.
* live: generate cache.txt file in refreshJose M. Guisado2022-06-012-0/+71
| | | | | | | | | | | | | Generates a cache.txt file if a cache partition is detected. OpenGnsys stores information about stored images in its 'cache' partition via a text file. The file is stored in a samba shared directory, mounted at '/opt/opengnsys/log/' in a live client. The file name is '{ip}.cache.txt'. Previously, the generation of this file was delegated to external bash scripts.
* probe: detect 64 bit operating systemsJose M. Guisado2022-05-092-2/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | OpenGnsys partition images store OS information, including the OS name appended with "64 bits" when the OS is meant for 64 bit machines. The detected OS name when probing (refresh) is important, if it differs from what's stored in the DB OpenGnsys will wipe last image restored information when running a refresh. See actualizaConfiguracion from legacy ogserver (ogAdmServer.c) code: dato = dbi_result_get_uint(result, "idnombreso"); if (idsoi == dato) { swu = false; } ... if (swu) { result_update = dbi_conn_queryf(dbi->conn, "UPDATE ordenadores_particiones SET " " codpar=0x%s," " tamano=%s," " uso=%s," " idsistemafichero=%d," " idnombreso=%d," " idimagen=0," " idperfilsoft=0," " fechadespliegue=NULL" " WHERE idordenador=%d AND numdisk=%s AND numpar=%s",
* Add link speed to refresh responseJavier Sánchez Parra2022-05-091-1/+4
| | | | | Probe response already has client's link speed, but this API is deprecated.
* utils: fix winreghives path stringJose M. Guisado2022-04-281-1/+1
| | | | | | | Adds missing slash in the windows reghives path f-string. When calling os_probe inside refresh (live/ogOperations) the mountpoint is passed without a trailing slash.
* live: detect cache partitions in new refreshJose M. Guisado2022-04-282-3/+23
| | | | | | | Detects OpenGnsys cache partition when building the partition setup of a live system. OpenGnsys labels a Linux/ext4 partition as "CACHE".
* live: get partition number using partno attributeJose M. Guisado2022-04-271-6/+7
| | | | | | | | | | | | Removes a workaround enumaration of the partitions of a given libfdisk context. Use Partition class partno attribute. This enables detecting non contiguous partitions, like: /dev/sda /dev/sda1 /dev/sda2 /dev/sda4
* utils: decode probing subprocess stdoutJose M. Guisado2022-04-271-2/+2
| | | | | | Cannot replace str ('\n') when stdout is a bytes object. Also fixes some typos (i.e: proc_releaseid stdout was used twice).
* live: use utils.py and fdisk in refresh operationJose M. Guisado2022-04-211-12/+71
| | | | | | | | | | | | Use python binding for libfdisk to retrieve disk label and partition information [1]. Use utils.py for the rest of the process. This change aims to drop dependency with external script 'getConfiguration' from the OpenGnsys scripting ecosystem. Keeps the same json payload structure for the refresh response. [1] https://git.48k.eu/python-libfdisk/
* live: use utils.py for probe operationJose M. Guisado2022-04-211-22/+4
| | | | Import ethtool function from utils.py
* Add partcodes.py to src/liveJose M. Guisado2022-04-211-0/+25
| | | | | | | | | | | | partcodes.py is used for mapping GPT partition UIIDs to hexcode/decimal values. OpenGnsys stores partition types in the database using the decimal value of this hexcode. The hexcode used for GPT partition UUID is the same as defined internally in gdisk [1]. [1] https://sourceforge.net/p/gptfdisk/code/ci/master/tree/parttypes.cc#l75
* Add utils modulesJose M. Guisado2022-04-215-0/+273
| | | | | | | | | | | | | | | | | | | | | | | | * disk.py Disk discovery * fs.py Uses psutil to fetch fs usage information * menu.py ogBrowser menu generation * net.py: gets nic status information IP address, MAC address and ethernet speed. * probe.py: probes mountpoints for operating systems Uses hivexget command to try fetching Windows installation information. Looks for /etc/os-release for probing linux systems.
* Revert "#1065 linux: add systray icon"Jose M. Guisado2022-02-031-53/+0
| | | | This reverts commit 69d214f63b2aa8ef60489d56468393b70795124a.
* #1065 Init event socket according to modeJose M. Guisado2022-02-021-1/+3
| | | | | | | Commit 700aa89ea99 introduced the use of getattr when getting event socket to avoid errors in case it was not initialized. Prefer to initialize accordingly inside the ogClient class constructor.
* #1065 Use getattr when retrieving event socketJose M. Guisado2022-02-011-1/+1
| | | | | | | | | | | | | | If ogClient does not run on windows or linux mode, it does not create a datagram event socket. If ogClient runs in virtual or live mode this will cause an error when calling get_event_socket because the class instance has no member "event_sock". Use getattr when retrieving the event socket from ogClient class, if there is no event socket, then return None. Fixes 2465ef25b741 (Add event datagram socket)
* #1065 windows: use shutdown for poweroff and reboot operationsJose M. Guisado2021-12-101-8/+2
| | | | | | | | | | | Running ogClient as a service (non interactive user) breaks poweroff and reboot using ExitWindowsEx function in user32.dll. Spawn a subshell using os.system and use the 'shutdown' command instead. This is a terminating command, we don't need fine grain from subprocess module.
* #1065 Init config_path according to platformJose M. Guisado2021-12-101-5/+1
| | | | | | | | | | Commit 2dbcd18c06dd breaks interfaceAdm path for live operations. Keep OG_PATH to the value prior to commit 2dbcd18c06dd. Check platform before reading config file. If platform is different from linux then look for cfg/ogclient.json in current folder and do not use OG_PATH.
* #1065 Add event datagram socketJose M. Guisado2021-11-292-1/+32
| | | | | | | | | | ogClient can receive events via a datagram socket opened at 55885. This socket is only opened when in windows or linux mode, for event reporting from within the system. Events reported this way are sent back to ogServer via a 103 Early Hints HTTP message. Information regarding the event is sent in the response's payload.
* #1065 Fix windows not reattempting refused connectionsJose M. Guisado2021-11-231-1/+5
| | | | | | | | | Windows does not report a refused connection the same way as Linux. Unsuccesful connect socket will be kept in the exceptfds, and won't be in the readable nor writable fds. The socket in this state will have SO_ERROR set to ECONNREFUSED. On the other hand, Linux does not use exceptfds for such case.
* #1065 Support pyinstaller for WindowsJose M. Guisado2021-11-221-1/+2
| | | | | | | | | Add required function call before running any process with multiprocessing. This is required for windows executables to work properly when using pyinstaller. See: https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing
* #1065 windows: add poweroff and rebootJose M. Guisado2021-11-191-0/+9
| | | | | | Uses ExitWindowsEx from user32.dll. Library is loaded using ctypes. See https://stackoverflow.com/a/50824776
* #1065 revisit config_path initializationJose M. Guisado2021-11-181-1/+4
| | | | | | | If current platform is Linux (either live, virtual or linux) expect /opt/opengnsys/ogclient/cfg/ to contain ogclient.json. If current platform is not Linux then we fallback to current directory.
* #1065 Add windows modeJose M. Guisado2021-11-184-2/+118
| | | | | | | | | | | | Add agent mode for windows platform. Subprocess module for shell/run is cross-platform an no change was needed. The subprocess will run with the same privilege as its parent, ogclient. TODO: Provide a windows installer. As of now, an administrator needs to install python and required libraries for this mode to be usable.
* #1065 Use logging module instead of syslogJose M. Guisado2021-11-182-14/+85
| | | | | | | | | | | | | | | | | | | | | | | | We can't use syslog if we want to execute ogClient in the Windows platform. Use the native logging library so we can attach different handlers depending on the mode ogClient is executing. Logging configuration is done via a python dict. There is a different dict for linux and windows. These dicts define the configuration of the root logger, handlers and formatters used. As of now, it is only expected to use the root logger for everything logging related. The root logger is obtained via: LOGGER = logging.getLogger() More info about handlers, formatters and loggers: https://docs.python.org/3/howto/logging.html Logging configuration is done at startup, just after parsing the json (knowing ogclient mode). If json parsing goes bad, ogclient will only print a message to stdout.
* #1065 linux: add shell run operationJose M. Guisado2021-11-151-2/+19
| | | | | | | | | - Executed script runs with same privilege as ogClient process. - Uses subprocess.run instead of subprocess.Popen, it's a bit simpler. We can't specify executable, though. Shouldn't need so in Linux mode. - Uses shell=True, keep in mind security considerations listed at: https://docs.python.org/3/library/subprocess.html#security-considerations (shlex.quote can be used for unix shells)
* #1065 linux: add systray iconJose M. Guisado2021-11-151-0/+52
| | | | | | Adds a systray icon for linux mode. Uses pystray module. Expects a favicon.ico stored in the same folder as the main ogclient python script, but if not found a placeholder image is used.