Commit Graph

49 Commits (760a82af2ced2365a8626af146ff2668b806c62f)

Author SHA1 Message Date
OpenGnSys Support Team 760a82af2c rest: remove unused probe
unused since 87be2ce08
2024-09-30 14:41:49 +02:00
OpenGnSys Support Team 3c395ecea2 client: move image list to cache data to consolidate it
Move list of images in the cache to cache_data. Add new functions to
initialize cache data (image list) and release it.
2024-09-25 14:49:17 +02:00
Alejandro Sirgo Rica c7bfc370ae src: add used_size and free_size to partition data
Extend database table ordenadores_particiones to add new "used_size" and "free_size" fields.

  FIELD       TYPE
| tamano    | bigint   |
| uso       | tinyint  |
| used_size | bigint   |
| free_size | bigint   |

"tamano" is the field storing the total size of the partition.
"uso" is a field storing the integer percentage of use, it is preserved for backwards compatibility with scritps that access the database.
"used_size" and "free_size" contain the used and free partition
size in bytes.

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'}
    ]
  }
}

Parse the new "free_size" and "used_size" fields of each partition data in the response payload of /refresh

Parse "free_size" and "used_size" fields of the cache data in the reponse payload of /image/restore, /cache/delete and /cache/fetch

Replace "used_size" field of GET /client/setup with the value
of the new database field "used_size"
2024-09-25 12:09:32 +02:00
OpenGnSys Support Team b74a05cf38 client: log error on refresh
Report failure when trying to refresh client information.
2024-09-23 13:51:14 +02:00
OpenGnSys Support Team bdf4c60411 client: remove redundant refresh validation
json parser already validates attributes must be set on.
2024-09-23 13:51:14 +02:00
OpenGnSys Support Team 5d97a721d0 ogAdmServer: replace old actualizaConfiguracion
Reimplement the legacy funcion actualizaConfiguracion with
og_update_client_config in src/client.c

if disk does not exist, add it, otherwise update disk contents.

if partition size, code, filesystem or os is different, reset image id,
otherwise update partition usage only.

delete partitions that are gone at the end.
2024-09-23 13:51:07 +02:00
OpenGnSys Support Team ad31c3832d rest: remove scheduler code
Put ogserver into diet, remove this feature, including pending command queue.
2024-09-17 17:46:07 +02:00
Alejandro Sirgo Rica e3a73a504f rest: add GET /efi
Add GET /efi request to obtain information about the client's
boot entries.

Field inside the /refresh payload
'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.

GET /efi resquest payload structure:
{
    'clients': ['10.141.10.21', '10.141.10.22']
}

GET /efi response's structure:
{
  'clients': [
    {
      'ip': '10.141.10.21',
      'entries': [
        {
          "order": 0,
          "name": "Boot0000",
          "active": false,
          "description": "grub"
        },
        {
          "order": 1,
          "name": "Boot0001",
          "active": true,
          "description": "UEFI: PXE IP4 Realtek PCIe GBE Family Controller"
        }
      ]
    },
    {
      'ip': '10.141.10.22',
      'entries': []
    }
  ]
}

The client with ip 10.141.10.22 is a BIOS system.

If an entry does not appear in the boot order it won't have the
'order' field.
2024-09-11 14:09:51 +02:00
OpenGnSys Support Team 5eba9f4e1b rest: allow repository to have more than one IP address
Repository can have more than one single IP address.

* Add alias field to database to represent the extra IPs that are attached to
  the repository, update schema and add version 9.
* Use og_dbi_get_repository_ip() to infer the repository IP address.
* Add helper functions (src/repo.c) to build a list of repositories and update
  rest API to use it.
2024-08-21 21:58:48 +02:00
Alejandro Sirgo Rica d383ff1c1a rest: add cache/fetch
Add POST cache/fetch request to request download of images in
the client's cache.

Resquest payload structure:
{
    'clients': ['10.141.10.21', '10.141.10.22']
    'image': 'windows.img'
    'type': 'TIPTORRENT'
    'repository': '12.141.10.2'
}

The clients listed in the 'clients' field will receive a
cache/fetch POST request with the payload received by the server
without the 'clients' field.
The clients respond with the contents of their cache so the server
can update the database.
2024-08-09 10:47:18 +02:00
OpenGnSys Support Team a675dbb083 client: split revision query when updating image information
a simple cleanup to help diagnose problems, not behaviour change expected.
2024-07-19 14:23:30 +02:00
OpenGnSys Support Team 88330288e6 client: fortify check for mandatory cmd json field in shell/output
Revisit 6cbe69e89e ("rest: add cmd to shell/output") to reject response with
no 'cmd' field, otherwise strdup() crashes when dealing with NULL string.

Set retcode to zero, otherwise this value remains uninitialized if no retcode
json field is provided by the client.
2024-07-15 11:56:26 +02:00
OpenGnSys Support Team 3f02d64104 rest: add checksum to GET /images
Add a new checksum attribute to GET /images, extend database to add a new
checksum field to images table.
2024-07-05 13:32:31 +02:00
OpenGnSys Support Team 6a65b72114 rest: add timestamp to shell/output
Provide a timestamp that tells when the command output from client was received.
2024-06-21 15:12:39 +02:00
OpenGnSys Support Team 6cbe69e89e rest: add cmd to shell/output
Add "cmd" field to json that provides the original command string, so it is
provided with the output and the return code.
2024-06-21 15:05:26 +02:00
OpenGnSys Support Team 12d5caf6a6 rest: add retcode to shell/output
Add retcode field to specify return code of shell invocation.
2024-06-21 14:12:02 +02:00
Alejandro Sirgo Rica 51f275a867 client: update cache after image/restore
Update the database with the new cache contents sent by the
client after an image/restore operation.

Resquest response structure:
{
    ...
    'cache': [
        {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'},
        {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'}
    ]
    ...
}

Parse the contents of the 'cache' field to update the data of
the client's cache in the database.
This is one of the required changes the make cache/list coherent
and prevent cache desync between the server and clients.
2024-05-30 11:31:42 +02:00
Alejandro Sirgo Rica 111f077d17 rest: add cache/delete
Add POST cache/delete request to request deletion of images in
the client's cache.

Resquest payload structure:
{
    'clients': ['10.141.10.21', '10.141.10.22']
    'images': ['windows.img', 'linux.img']
}

The clients listed in the 'clients' field will receive a
cache/delete POST request with the 'clients' field removed and
only containing 'images' from the payload received by the server.
Each client will try to delete as many images as available in
their cache from the list of files in 'images'.
The clients will give response with the contents of the cache so
the server can update the database.
2024-05-30 11:16:25 +02:00
Alejandro Sirgo Rica efb5f27585 client: store image cache data in database
Parse the 'cache' field of the refresh payload sent by the clients.

Cache field structure in the payload:
{
    ...
    'cache': [
        {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'},
        {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'},
    ]
    ...
}

Store that data in the 'cache' table of the  database so it can
be obtained later on.
The table contains the following fields:
- clientid: the numeric identifier of the client.
- imagename: name of the image in cache.
- size: size in bytes of the image in cache.
- checksum: checksum of the image in cache.
2024-05-30 11:16:13 +02:00
OpenGnSys Support Team a3af24d94a src: replace old function to update image information
replace old legacy code, no functional changes are intended.
2024-05-29 17:19:20 +02:00
OpenGnSys Support Team ee09056908 client: parse permissions and lastupdate in /image/create response from client
Use permissions and last update from client.

update src/schema.c to add a new database version.
2023-12-12 17:02:44 +01:00
OpenGnSys Support Team e3b8f3d2f9 client: stub to parse size field in /image/create response from client
Still incomplete, src/schema.c needs to be update to add a new field to the
'imagenes' table in the database.
2023-12-12 11:30:31 +01:00
Jose M. Guisado 92f83c0385 client: harden og_resp_refresh
Harden refresh response logic. Check for necessary JSON fields inside
the payload.

Check if serial_number is null before calling strlen, prevent ogServer
from a malformed refresh response with missing serial_number.

Refresh uses legacy function actualizaConfiguracion that takes a long
string with the computers configuration (serialno, partitions, disks,
link speed and status). Check for an empty string before executing any
legacy code inside actualizaConfiguracion.
2023-06-07 18:32:33 +02:00
Jose M. Guisado 8cf02475ba client: increase software inventory buffer size
Large software inventory is truncated because it does not fit into the
existing buffer.

Software inventory response payload consists of a string with each
component delimited by '\n'. Large software inventories can consist of
more than 8192 bytes.

Avoid truncating any large software inventory by increasing the buffer
size where this string is stored.
2023-04-20 10:08:52 +02:00
Javier Sánchez Parra 25e21f435d Log ogClient sessions in ogagent.log
Otherwise, administrators can not read the logging history from
WebConsole.
2022-11-02 13:59:28 +01:00
Javier Sánchez Parra 9b6171300b #915 Fix conditional jump depending on uninitialised value
Valgrind says:

==9452== 1 errors in context 1 of 38:
==9452== Conditional jump or move depends on uninitialised value(s)
==9452==    at 0x11BD1E: og_resp_refresh (client.c:383)
==9452==    by 0x11CF2A: og_agent_state_process_response (client.c:822)
==9452==    by 0x112FCE: og_agent_read_cb (core.c:254)
==9452==    by 0x4E41D72: ev_invoke_pending (in /usr/lib/x86_64-linux-gnu/libev.so.4.0.0)
==9452==    by 0x4E453DD: ev_run (in /usr/lib/x86_64-linux-gnu/libev.so.4.0.0)
==9452==    by 0x1107CD: ev_loop (ev.h:835)
==9452==    by 0x1107CD: main (main.c:108)
==9452==  Uninitialised value was created by a stack allocation
==9452==    at 0x11BB02: og_resp_refresh (client.c:348)

Fixes: f03425e ("#915 Add support for link speed in the refresh response")
2022-05-18 16:50:24 +02:00
Javier Sánchez Parra df5161ebc3 #915 Add last_cmd to GET /clients API
"last_cmd" json object contains information of the last command executed
by the correspondent client. For now, it only includes "result" string
property, which stores "success" if the last command finished correctly
or "failure" on the contrary.

To populate "result" property, this commit also adds "last_cmd_result"
enum attribute to og_client struct. Client response processing fills
this attribute according to its success.

Clients in WOL_SENT state always have last_cmd->result = "unknown".

Request: GET /clients

Response: 200 OK
{
  "clients": [
    {
      "addr": "10.141.10.102",
      "state": "WOL_SENT",
      "last_cmd": {
        "result": "unknown"
      }
    },
    {
      "addr": "10.141.10.101",
      "state": "OPG",
      "speed": 1000,
      "last_cmd": {
        "result": "success"
      }
    },
    {
      "addr": "10.141.10.100",
      "state": "OPG",
      "speed": 1000,
      "last_cmd": {
        "result": "failure"
      }
    }
  ]
}
2022-05-18 16:50:14 +02:00
Javier Sánchez Parra f03425e6ae #915 Add support for link speed in the refresh response
Add ogServer support for parsing and storing the link speed from
ogClient's refresh response.

Probe response already has client's link speed, but this API is
deprecated.
2022-05-09 12:18:56 +02:00
OpenGnSys Support Team b8b3839bba #915 remove temporary file to store shell output
Remove legacy behaviour, store it in the client object instead of a temporary
file.
2022-01-18 10:48:59 +01:00
OpenGnSys Support Team 6e70916005 #915 remove shim code to update database after image restore command
Make direct call to dbi API to update database instead.
2021-12-22 17:30:04 +01:00
Jose M. Guisado ff9dbd9033 #1065 split og_status_session_toggle
Handles non usual situations like a client sending more than
one event of same type.

When toggling, receiving two events of the same type is the
same as receiving two different ones (eg. start, then stop).

Split into _session_start and _session_stop in order to check
valid client status.
2021-12-03 09:14:07 +01:00
Jose M. Guisado 772811e76f #1065 Add support for client events
ogServer supports events from clients in an agent mode
(linux/windows).

Client sends event information (eg. user login/logout)
via a 103 Early Hints http response message.
2021-12-01 15:14:24 +01:00
Jose M. Guisado b6b1040997 #1065 client: add support for ogclient win state
ogClient can be run in windows mode, enabling connection with ogServer
when running on a Windows machine.

Don't expect the same payload in windows mode as a in live or virtual.
Client in windows mode does not send partition setup information, only
the status/state. (same case for linux mode)
2021-11-17 10:36:50 +01:00
Jose M. Guisado 5a3fd51261 #1065 client: add support for ogclient linux state
ogClient can be run in linux mode, intended for exposing some
ogServer commands when running in a linux distribution.

When connecting with a client in linux mode, do not expect a full
partition setup response. Just expect a 'status', and then accept
the connection without updating any partition information in
the database.
2021-11-17 09:07:57 +01:00
OpenGnSys Support Team ac3ce22c35 #1064 revisit error handling from ogClient
200 => successful command, run next pending command
202 => successful command in progress, do not run next pending command
403 => server sent a malformed HTTP header, should not ever happen,
       close connection (server is buggy?).
500 => client fails to run command, report error and run next pending command
503 => client is busy, report error and do not run next pending command

Anything else, should not ever happen (client is buggy?), close connection with
client.

On error, when processing response from ogClient, do not close the connection,
instead annotate in the database that command was not successful and run next
pending command.

*Only* if client replies status code 500 set last_cmd to UNSPEC so its state is
not BSY as reported by og_client_status function and pending cmds can be
sent.
2021-11-12 11:06:13 +01:00
Javier Sánchez Parra 12d8fff3ef #1037 Add disk type
Add ogServer support for parsing and storing in the DB disk type data
from ogClient refresh response.

See also commits with #1037 in ogClient and WebConsole repo.
2021-05-26 17:19:30 +02:00
OpenGnSys Support Team d3e9b5727a #980 ignore unknown attributes
If ogClient sends an unknown attribute, ignore it.
2021-05-04 18:29:15 +02:00
Jose M. Guisado 40d4279b31 #995 Add link speed parsing to client probe response
If a probe response contains speedinformation, parse and store
it inside the client struct. Speed is interpreted as an unsigned
integer representing Mbit/s.
2021-05-04 18:13:35 +02:00
OpenGnSys Support Team a7cce8d442 ogServer is AGPLv3+
Update license header in files.
2021-05-04 17:59:11 +02:00
OpenGnSys Support Team 0d9d72eb42 #980 memleak in json ogclient path 2021-02-23 12:35:16 +01:00
Javier Sánchez Parra 24e6fbf1de #1008 Restore support for 4 disks and 16 partitions
ogServer expects to receive information of 1 disk and 4 partitions
from ogClient. Previous ogServer versions support several disks and
partitions.

Add ogServer support for 4 disks and 16 partitions.
2020-11-18 13:10:34 +01:00
OpenGnSys Support Team fe1ce97c50 #988 remove legacy configuration
Use og_server_cfg everywhere. Convert port to string to make it easy for the
dbi API since it expects a string. Remove legacy example configuration file.
2020-10-07 11:17:00 +02:00
Roberto Hueso Gómez f537dafa77 #941 Use fixed length strings in og_computer and og_dbi_get_computer_info
This patch is a refactor for og_computer and og_dbi_get_computer_info.
It now uses fixed lenght strings to make it more reliable and avoid
errors if the DB is not returning a null ended string.
2020-10-06 16:04:17 +02:00
Javier Sánchez Parra a67f27a092 #1004 Fix integer overflow in datasize
ogClient datasize is now in bytes, update format to fix a possible overflow.
2020-09-29 12:43:07 +02:00
Roberto Hueso Gómez cbd9421bae #941 Extend og_dbi_get_computer_info(...)
For the strings in og_computer we do not need to know the max size in
advance but instead we need to free up memmory using
og_dbi_free_computer_info(...) function.
2020-09-22 15:20:57 +02:00
OpenGnSys Support Team d7e2022bdd #941 pass og_dbi to og_dbi_get_computer_info()
Reuse the existing dbi handler, instead of opening a new one.
2020-09-18 15:38:16 +02:00
OpenGnSys Support Team 3cb98c7187 #941 move og_dbi_get_computer_info() to dbi
Move this function to the dbi.{h,c} files.
2020-09-18 15:34:30 +02:00
Javier Sánchez Parra 0efc182c9b #1004 Handle new fields in /image/create response
ogClient now includes more information regarding the new image. This patch
modifies ogServer to support new elements sent in ogClient /image/create
response and store them in the database.

Example of new /image/create response:

{
  "disk": "1",
  "partition": "1",
  "code": "131",
  "id": "1",
  "name": "ubuntu",
  "repository": "192.168.56.10",
  "software": "Ubuntu 18.04.5 LTS \naccountsservice 0.6.45\n...",
  "clonator": "PARTCLONE",
  "compressor": "LZOP",
  "filesystem": "EXTFS",
  "datasize": 2100000
}

New fields are "clonator", "compressor", "filesystem" and "datasize".
2020-09-10 14:48:26 +02:00
OpenGnSys Support Team 37e91b2ebb #971 rename sources folder to src
Use the same folder as in ogClient.
2020-06-26 20:13:42 +02:00