Commit Graph

483 Commits (ffaf2aac05cf8d3664322b6ca349a5401c70ca34)
 

Author SHA1 Message Date
Alejandro Sirgo Rica ffaf2aac05 install: add script to generate the windows metadata information file
Add create_version_file.py, running this script creates a file
version_info.txt with the data required for the Windows ogClient
binary metadata.
2024-11-28 16:58:41 +01:00
OpenGnSys Support Team 62b52ff364 src: update license header 2024-11-28 16:45:56 +01:00
Alejandro Sirgo Rica e4be5c34eb src: add support for direct command execution
Update live shell run mode for the new REST API interface.
Evaluate the "inline" field to diferentiate between execution of
script in /opt/opengnsys/shell/ and a cmd execution.

Remove usage of echo argument of the API REST.

Update Windows and Linux mode for direct command execution.
Set OutputEncoding environment variable to 'utf-8' in Windows to
unify the encoding of stdout for the invoked programs.

Decode stdout to utf-8-sig to remove potential BOM.

While at this, remove strange legacy ;|\n\r terminator.
2024-11-27 13:53:19 +01:00
Alejandro Sirgo Rica a36c4daa23 src: add user session detection implementation
Detect user login and logout for Linux and Windows.

Report an active interactive session through the /refresh response
so a new ogserver instance can update the session status.

Poll the session change in 5 second intervals in a thread. Use the
same event socket previously used by the old session detection
mechanism to notify a session change.

Use the method check_interactive_session_change in each
ogOperations.py to report the session status.
Return values:
	None: no session changes are found
	True: login
	False: logout

Windows
Verify if psutil.users() has any value.

Linux
Verify all the psutil.users() asociated to a terminal.
2024-11-26 13:02:45 +01:00
Alejandro Sirgo Rica a1bd0c36f3 linux: remove leftover prove() method 2024-11-26 13:02:45 +01:00
Alejandro Sirgo Rica c8674a4e93 windows: bind the systray process lifetime to ogClient
Add daemon=True to the systray process in order to make it close
when the ogClient process closes.
2024-11-26 13:02:45 +01:00
Alejandro Sirgo Rica 179d17cae8 windows: make the systray reference local to OgWindowsOperations 2024-11-26 13:02:45 +01:00
Alejandro Sirgo Rica bc7fe848ac windows: use a better systray default icon
Draw a blue circle as default icon in the systray. Use the same
blue color as the one shown in ogCP for an ogClient Windows instance.
2024-11-26 13:02:45 +01:00
Alejandro Sirgo Rica 525958ae85 src: update functions for every ogClient mode
Add missing ogClient mode functions and show an error in every
unimplemented function.
2024-11-26 13:02:17 +01:00
Alejandro Sirgo Rica d7658f03ab utils: disable fcntl in ogClient for Windows
Add conditional import for fcntl as it is only supported for
Linux and causes ogClient for Windows fail to start.
2024-11-15 10:47:05 +01:00
OpenGnSys Support Team 90a9ba9543 live: bogus error in logs when connecting to ogserver
This error is bogus:

 (2024-11-14 09:05:37) ogClient: [ERROR] - Partition query error for /dev/sdb: No medium found

skip if device cannot be opened instead.
2024-11-14 18:12:56 +01:00
Alejandro Sirgo Rica f5f8771b6f grub: fix failed grub configuration when a device is not found
Fix "No medium found" error aborting the grub configuration
process. Just log it and continue.
2024-11-14 18:12:56 +01:00
OpenGnSys Support Team 3b5152cdc1 tiptorrent: use absolute path to tiptorrent-client
instead of using PATH to find it
2024-11-07 19:22:47 +01:00
Alejandro Sirgo Rica a440b9da47 live: fix error report in partition and format
Fix error codepath and properly mark the operation as failed.
2024-11-05 11:20:59 +01:00
Alejandro Sirgo Rica 64f1f5403e disk: use different log message in get_disk_data and get_partition_data
Use a more specific message to differentiate the source of the error.

Add the target device to the log message.
2024-10-25 09:47:49 +02:00
OpenGnSys Support Team 7874323d46 live: use reboot --force --force to make a hard reboot in new live
this is a workaround for the new live system to make a hardware reboot
that allows UEFI to pick up, otherwise it performs a kernel reboot instead.
2024-10-24 17:46:37 +02:00
Alejandro Sirgo Rica 07b4bc1fcd postinstall: remove call to ogFixBootSector script
Remove call to ogFixBootSector function as it is possibly only
required by Windows XP and FAT filesystem.
2024-10-24 10:52:33 +02:00
Alejandro Sirgo Rica 569caa733f cache: add code to cache the oglive boot files
Add update_live_cache() implementing the legacy script
updateBootCache()

Copy the ogvmlinuz and oginitrd.img files into cache after
a partition and format command with an available cache partition.
2024-10-24 10:52:33 +02:00
OpenGnSys Support Team fc21cd988f live: always enable wol when launching ogclient
no need to wait for reboot/poweroff to enable wake-on-lan.
2024-10-24 10:46:44 +02:00
Alejandro Sirgo Rica fb707cef0b grub: move get_grub_boot_params() into grub.py
Move get_grub_boot_params() into the file related to all the grub
configuration.
2024-10-22 16:47:44 +02:00
Alejandro Sirgo Rica 373c1b2a72 grub: replace legacy grub install scripts
Translate old legacy grub scripts into grub.py
Implement ogGrubInstallMbr as install_main_grub() and
ogGrubInstallPartition as install_linux_grub().

Add grub configuration file generator through the classes
GrubConfig and MenuEntry.

Ensure EFI tree structure compatibility with legacy code.
The structure of the created folders in the ESP is non-standard,
efi binaries are usually located in the folder below the EFI/
directory.

Structure used by ogClient:

EFI/
├── grub/
│   └── Boot/
│       ├── BOOTX64.CSV
│       ├── grub.cfg
│       ├── mmx64.efi
│       ├── shimx64.efi
│       ├── BOOTX64.EFI
│       ├── grubx64.efi
│       └── ogloader.efi
...

The function _mangle_efi_folder handles the folder structure after
grub-install to comply with the location expected by ogLive.

install_linux_grub() installs a grub local to each Linux install
to enable chainloading, each grub is located in EFI/Part-xx-yy/ in
UEFI. The local linux BIOS grub in legacy scripts is unreliable,
grub-install reports a failure during the install process.

install_main_grub() installs a global grub in EFI/grub/ to show a
grub menu when the pxe boot fails. The global grub contains entries
to every installed os. No global grub is installed for BIOS
systems, a Boot partition would be required to store the grub
configuration.
2024-10-22 16:47:38 +02:00
Alejandro Sirgo Rica 2fcdf89606 disk: use cxt.label.name to dtect disk type in get_efi_partition
Use cxt.label.name instead of cxt.label to identify if the disk is
GPT or MBR. This way is more used in other parts of the codebase.
2024-10-21 16:56:05 +02:00
Alejandro Sirgo Rica b3659a30fc bios: fix use of undefined initrd_dir variable in get_vmlinuz_path
Use the intended linuz_dir instead of initrd_dir in the function
get_vmlinuz_path.
2024-10-21 12:04:23 +02:00
Alejandro Sirgo Rica 7be953dbe7 uefi: fix error message when no EFI loader
Fix log error message when _find_efi_loader does not find any
EFI loader in the ESP.
2024-10-11 12:06:37 +02:00
Alejandro Sirgo Rica 039bee2a05 bios.py: fix typo in GRUB_CMDLINE_LINUX_DEFAULT string
Check against GRUB_CMDLINE_LINUX_DEFAULT instead of
GRUB_CMDLINE_LINUE_DEFAULT.
2024-10-09 16:25:14 +02:00
Alejandro Sirgo Rica e8ddbbd075 src: isolate libfdisk operations to enable mount operations
python-libfdisk does not close file descriptor until the cxt
object goes out of scope.

Define get_partition_data and get_disk_data functions to isolate
the python-libfdisk logic and return the data as an object.

Improve error handling of libfdisk operaions in refresh.
2024-10-08 10:07:45 +02:00
Alejandro Sirgo Rica 97c836e0e4 live: improve part not found log in image_create
Report the partition number of the missing partition.
2024-10-08 10:07:45 +02:00
Alejandro Sirgo Rica f942b19eae src: fix cache mount in new ogLive
Mount cache in image_create() image_restore() and cache_fetch().

Remove init_cache() and ensure /opt/opengnsys/images/ exists
within the cache mountpoint if it does not exists in cache_mount().
2024-10-08 10:07:45 +02:00
OpenGnSys Support Team fe960010a0 live: remove useless check in compute_md5
this never returns -1 on error, an exception is rised instead
2024-10-05 08:40:55 +02:00
Alejandro Sirgo Rica 0f167cf29f src: consolidate compute_md5 functions
Add compute_md5 function in src/utils/fs.py

Remove identical md5 functions from src/live/ogOperations.py and
src/utils/tiptorrent.py

Move error checks from ogOperations.py into compute_md5 function in
src/utils/fs.py
2024-10-02 14:50:14 +02:00
Alejandro Sirgo Rica cc70274079 src: check if the system is hibernated before /image/create
Mount the system partition in readonly mode and check for the
hiberfil.sys file if the target system is a Windows.

Fail the image creation process if the target system is hibernated.
2024-10-02 14:25:04 +02:00
Alejandro Sirgo Rica a2baad8c0b ogclient: add --server-ip flag to override the server's IP
Add CLI flag to override the server IP defined in the config file.
2024-10-02 10:38:03 +02:00
OpenGnSys Support Team f1b1532f78 live: refactor poweroff and reboot
- enable WoL
- check for poweroff and reboot before checking for busybox.
- call new shutdown method
2024-10-01 22:12:17 +02:00
OpenGnSys Support Team e003ff6d8c tiptorrent: missing f-string in error
tip_client_get() needs f-string to display error
2024-10-01 17:48:07 +02:00
OpenGnSys Support Team cf9e1c96fd live: fix EBUSY error in newer kernels with mkfs
python-libfdisk does not close file descriptor to /dev/sda after completing
partitioning. This results EBUSY errors when formatting partitions with mkfs
in newer kernels. Encapsulate code to partition in method so python garbage
collection knows ctx objects can be release then close file descritor to
/dev/sda.

ogRest is not accessible from _partition(), remove check to ogRest.terminated,
actually no need to terminate inmediately when formatting is ongoing, better
leave things in consistent state when stop command is received.
2024-10-01 17:02:49 +02:00
Alejandro Sirgo Rica f0953c969a live: report correct partition size unit in setup() log
Log the correct partition size unit. Use MiB instead of MB.
2024-10-01 16:49:58 +02:00
Alejandro Sirgo Rica e30e934272 src: replace DEVICE env variable with get_ethernet_interface()
Use a python function to obtain the main net interface. Detect
the first ethernet inferface in use.
Stop using the DEVICE environment variable.
2024-10-01 15:32:54 +02:00
OpenGnSys Support Team 8f437bb954 live: remove unused probe
unused since ogserver's commit 87be2ce08 #980 Change initial probe to refresh
2024-09-30 14:42:29 +02:00
OpenGnSys Support Team 9c18ef7392 live: use busybox otherwise poweroff/reboot commands 2024-09-30 14:42:29 +02:00
Alejandro Sirgo Rica 9c2ae873f2 live: disable browser operations if the binary is missing
Add shutils.which checks before every browser operations to
skip the subprocess call if the binary is missing.
2024-09-27 14:27:00 +02:00
Alejandro Sirgo Rica 8754c21694 src: report used and free partition data in bytes
Add "used_size" and "free_size" to the partition data and the
cache data.

Old response from ogClient for /cache/delete, /cache/fetch
and /image/restore:
{
  'cache': [
    {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'},
    {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'}
  ]
}

New response:
{
  'cache': {
    'used_size': 4520232322423,
    'free_size': 48273465287452945,
    'images': [
      {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'},
      {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'}
    ]
  }
}
2024-09-25 14:35:41 +02:00
Alejandro Sirgo Rica 3b40ec7918 sw_inventory: consolidate os_probe logic
Reuse os_probe() function from probe.py and change the fallback
case to "unknown" to prevent OS id mismatch in ogserver.

The OS id mismatch causes the images to stop being associated with
partitions after the /refresh command.
2024-09-25 14:35:41 +02:00
Alejandro Sirgo Rica 51258613cc src: verify the fields of the efibootmgr json in /refresh
Don't send the efi data in the /refresh payload if efibootmgr
is missing any of the json keys.

Log the missing keys in case of missing some.
2024-09-25 14:35:41 +02:00
Alejandro Sirgo Rica 11a963c709 utils: Add windows_register_c_drive implementation
Add python implementation of the legacy ogWindowsRegisterPartition
function.

This function configures the system partition to be considered the
new C drive after a Windows image restore.

The drive letter configuration is stored in the SYSTEM hive of
the windows registry. The node MountedDevices contains all the
configuration as key-value pairs.
The C drive key \DosDevices\C: contains a different value based on
the partitioning type.

GPT
the value is DMIO:ID: followed by the 16 byte GUID of the
partition.
Example: DMIO:ID:\xc9\xfc\x1c\x86\x13\x11O\t\xa2\x9c{/\xf1\xdf\xe4)

MBR
The value is a little endian byte sequence with 2 parts.
The first 4 bytes correspond to the disk id. The second part is
the byte offset start of the partition in that disk.
Example: \xe1\\\x9cP\x00\x00\x10j\x18\x00\x00\x00

If we format the MBR value in a more readable way we get
e1 5c 9c 50 00 00 10 6a 18 00 00 00
In this case the disk ID is 509c5ce1.
The partition offset is 186a100000.

This patch adds the following helper functions to:

- get_disk_id_bytes(): to obtain the disk identifier.

- get_part_id_bytes(): to obtain a partition identifier as UUID
  for MBR or DMIO:ID format for GPT.

- get_sector_size(): to query the sector size of a specific disk.
  Read /sys/class/block/{device_name}/queue/hw_sector_size to obtain the value.
  This is MBR specific.

- get_partition_start_offset(): to query the start sector of a specific
  partition and disk. Use sfdisk with the -J argument to get fdisk data in
  json format. This is MBR specific.
2024-09-12 10:43:09 +02:00
Alejandro Sirgo Rica 595770163a live: add boot entries into /refresh payload
Add 'efi' key into the refresh payload. The value for that key
has the following structure:

'efi': {
  'entries': [
    {
      "order": 0,
      "name": "Boot0000",
      "active": false,
      "description": "grub"
    },
    {
      "order": 1,
      "name": "Boot0001",
      "active": true,
      "description": "UEFI: PXE IP4 Realtek PCIe GBE Family Controller"
    }
  ]
}

If the client is not a EFI system it won't add the 'efi' field.
If an entry is not in the boot order it won't have the 'order' field.
2024-09-10 17:23:18 +02:00
Alejandro Sirgo Rica f31e55fea4 bcd: make recovery modifications optional
Ignore recovery disable if no Recovery node is found in the BCD.
2024-09-10 15:37:08 +02:00
OpenGnSys Support Team 084650e4b1 live: use correct variable name in restore unicast cache
fe40f9c5 ('src: add POST cache/fetch method') broke unicast cache restore.

(2024-09-09 10:05:22) ogClient: [ERROR] - name 'image_name' is not defined
Traceback (most recent call last):
File "/opt/opengnsys/ogClient/src/ogRest.py", line 175, in image_restore
payload = ogRest.operations.image_restore(request, ogRest)
File "/opt/opengnsys/ogClient/src/live/ogOperations.py", line 520, in image_restore
self._restore_image_unicast(repo, name, partdev, cache)
File "/opt/opengnsys/ogClient/src/live/ogOperations.py", line 242, in _restore_image_unicast
image_path = f'{OG_CACHE_IMAGE_PATH}{image_name}.img'
NameError: name 'image_name' is not defined
2024-09-09 12:23:00 +02:00
OpenGnSys Support Team 05b7a576b0 live: incorrect indentation
f2a2f53074 ('live: remove file from cache with no checksum file') broke
indentation which breaks ogClient.
2024-09-03 19:44:43 +02:00
Alejandro Sirgo Rica 6704abc620 live: add disk index bounds check
Add disk index bounds checks for setup() and image_create().
Prevent backtrace logging when an invalid disk index is used.
2024-09-02 14:25:54 +02:00
OpenGnSys Support Team f2a2f53074 live: remove file from cache with no checksum file
Maybe result of a partial download? then, remove it to leave cache in consistent
state.
2024-09-02 13:59:36 +02:00