summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* #1065 src: add linux modeJose M. Guisado2021-11-154-1/+51
| | | | | | | | | | | | | | | | | | | | | ogClient can run in "linux" mode. In addition to live or virtual. Serves as a substitute to the legacy ogagent, which has not received any updates since 2020/07/23. Linux mode initially supports remote reboot and poweroff. Requires updated ogServer with the Linux ogclient state. ogClient can be set up to run in linux mode by specifying it in ogclient.json: { "opengnsys": { "ip": "192.168.56.10", "port": 8889, "log": "DEBUG", "mode": "linux", ... }
* #1056 stop thread if connection with server is lostOpenGnSys Support Team2021-11-111-0/+1
| | | | | | | | | | | | | | | | Abort command if the connection with the server is lost. Otherwise, a race condition that leaves ogServer and ogClient out-of-sync might occur: 1. ogClient is busy running a command (on the worker thread), for example, image/restore. 2. ogServer is stopped OR ogClient loses connection with ogServer (due to transient network problem). 3. ogClient reconnects and ogServer sends a refresh command. 4. ogClient worker thread finishes and it sends a reply to image/restore. 5. ogServer gets confused because it expects a reply to the refresh command, not the old image/restore.
* #1059 virtual: replace qmp polling for event listeningJose M. Guisado2021-09-013-8/+322
| | | | | | | | | | | | | | Polling for a qmp port availability is undesirable, as QEMU only handles one connection to the qmp port at a time, ogClient may interfere with cloneer-manager. Check vm thread now connects to a separate qmp tcp socket, listening for a shutdown guest event. When ogClient is run just after ogVDI installation (before guest installation) it will try to connect until it's possible, ie: after an iso is specified and a qemu vm is started that exposes the appropiate qmp tcp port.
* #1056 stop request processing on connection closureOpenGnSys Support Team2021-07-151-1/+1
| | | | | | If server closes the connection, close the socket, reconnect and stop processing. self.connect() already cleans up the internal state, including the socket state.
* #1056 add cleanup method and use itOpenGnSys Support Team2021-07-151-10/+8
| | | | add method to clean up interval socket state and use it
* #1000 Fix HTTP request header length parsingJavier Sánchez Parra2021-07-131-3/+4
| | | | | | | | | | | | | | | | | | | OgClient miscalculates the body size of the request. ogServer delimits HTTP headers with "\r\n\r\n" to comply with RFC 2616. But ogClient searches for the first "\r\n" delimiter, hence, ogClient stops at the first HTTP header field instead of at the end of the header. Hence, it incorrectly assumes the body starts after the first "\r\n". This commit updates ogClient to search for the "\r\n\r\n" delimiter. Example: POST /shell/run HTTP/1.1\r\n <-- ogClient considers body starts here (WRONG!) Content-Length: 952\r\n Content-Type: application/json\r\n \r\n <-- Here is where the body starts {"json-body":...}
* #1037 Add disk typeJavier Sánchez Parra2021-05-261-0/+1
| | | | | | | Add ogClient support to receive, parse and send disk type data from the cloning engine when refreshing disks configuration. See also commits with #1037 in ogServer and WebConsole repo.
* ogClient is AGPLv3+OpenGnSys Support Team2021-05-147-29/+17
| | | | Update license header in files.
* #995 Add link speed in probe responsesJose M. Guisado2021-05-043-5/+41
| | | | | | | | Separates probe method into separate ogclient modes (virtual, vdi) so future supported OS can easily have a tailored probe responses. Link speed is retrieved using a minimal ethtool command sent using fcntl module from python.
* #980 Broken TCP connection times out after 120 seconds through keepaliveOpenGnSys Support Team2021-04-231-0/+5
| | | | | Enable TCP keepalive to detect if the ogServer is gone (hard reset). If no reply after 120 seconds, then release the connection to the server.
* #1000 live: check imageCreate for non-zero return codev1.2.0Jose M. Guisado2020-12-151-0/+3
| | | | | | | | | When running image_create operation an underlying script "imageCreate" is called using the subprocess python module. This script may fail, for example if the repository in which the image is to be stored has no sufficent capacity. Check for non-zero when the imageCreate process has finished.
* Rename 'linux' folder and operations to 'live'Jose M. Guisado2020-12-033-3/+3
| | | | | | | | | | | ogLive related operations are named inside a 'Linux' folder, also its python class is named OgLinuxOperations. Rename every 'linux' occurrence with live to further clarify this folder and operations. - OgLinuxOperations -> OgLiveOperations - src/linux/ -> src/live/ Fixes: 1377acee ('Rename 'linux' mode to 'live' mode')