Commit Graph

619 Commits (113472d5c0115d53d2fb99288759502d196a8e93)
 

Author SHA1 Message Date
OpenGnSys Support Team 3b3fc32999 rest: missing POST /image/update in syslog
Update it so it shows in syslog, instead of unknown:

Dec 19 18:31:18 ogserver ogserver[1133]: 127.0.0.1:36538 POST /unknown clients=150.128.34.25
2023-12-21 11:58:48 +01:00
OpenGnSys Support Team cdff83d091 rest: cannot fail with image/create if it exists
legacy web console uses this REST API to refresh an existing image.

Relax check not to break things.
2023-12-19 13:34:32 +01:00
OpenGnSys Support Team f64b1c2767 rest: add POST image/update
add explicit API to update an image
2023-12-19 12:42:32 +01:00
OpenGnSys Support Team 7292c30659 rest: no assumption on description field in create/image
do not use description field to decide if this is a new image or an update.

add og_dbi_get_image() to check if the image exists. If it is not found, then
add new image entry to database.

update og_dbi_add_image() to update the image.id field.
2023-12-19 12:20:34 +01:00
OpenGnSys Support Team bad351b1d7 rest: log failed to delete entry from table
add logging to report failure to remove entry.
2023-12-18 12:20:52 +01:00
OpenGnSys Support Team b100c570a0 rest: do not exit() if execlp() fails
execlp() should not ever fail, but if it ever happens, return -1 instead of
exitting this daemon.
2023-12-15 11:12:49 +01:00
OpenGnSys Support Team 5e8e1c6467 rest: do not report error when removing image file
this file might be in a different repository, this is best effort.
2023-12-15 11:12:46 +01: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
OpenGnSys Support Team 721ab28fdf rest: expose description in GET /images
add .description field to json.
2023-12-12 10:23:46 +01:00
OpenGnSys Support Team 16d7a18441 dbi: og_computer_get_info() uses netmask field in 'room' table
netmask field in 'computers' table is never used, but ogcli still
displays it through:

 # ogcli list client --client-ip 1.2.3.4

and it shows '0' or incorrect netmask (ogCP hardcodes this field).

Update SQL query to fetch the room.netmask instead.
2023-11-30 20:58:04 +01:00
OpenGnSys Support Team edac32bb98 rest: add GET /room/info
Add GET /room/info to obtain room information, this includes the name,
gateway and netmask.

curl -X GET -H "Authorization: $API_KEY" http://127.0.0.1:8888/room/info -d '{ "id" : 1 }
2023-11-30 20:20:07 +01:00
OpenGnSys Support Team 1ce5624032 rest: fix client/info maintenance field
Use computer.maintenance instead of computer.name.

Fixes: af47a082ad ("#1004 Add GET /client/info HTTP REST method")
2023-11-30 10:04:19 +01:00
Javier Hernandez 5ff92a826e rest: add POST repository/update
Add POST repository/update request to update repository. Repository is
identified by its id, that is provided in the payload.

This can be tested with curl like:
curl -X POST -H "Authorization: $API_KEY"
http://127.0.0.1:8888/repository/update -d '{ "repo_id" : 16, "center" :
3, "name": "newName", "ip":"127.0.0.1" }'
2023-11-24 11:02:52 +01:00
OpenGnSys Support Team 0ab4721714 core: remove useless log when ogClient connects to server
The following log message is display for each ogClient that is connected to
the ogServer:

 Sent refresh to: 192.168.2.200

this tells the ogClient to send his current partition table when the connection
between ogServer <-> ogClient starts. This is not very useful, remove it.
2023-11-23 22:08:49 +01:00
OpenGnSys Support Team 56e4a01af0 rest: revisit logging
Skip logging for the following REST API invocations:

- GET /scopes
- GET /clients
- POST /clients (for legacy web console only)

The web front-end generated very frequent requests for this.

Update logging format to:

 127.0.0.1:54637 POST /wol clients=192.168.2.130

to include client IP address.
2023-11-23 22:08:49 +01:00
OpenGnSys Support Team f8eca04841 rest: fix WoL handling
Valgrind reports a memleak because og_cmd_wol() overrides params->ips_array,
then it releases params->ips_array but og_cmd_free() already does this.

Use a new_params structure to store the IPs that has been filtered through the
database query and check that buffer overrun does not happen.

Fixes: e4cb91b5f6 ("#990 wol: migrate mac and netmask query to ogServer")
2023-11-23 22:08:41 +01:00
OpenGnSys Support Team 2140012535 rest: set center in /repository/add
Set it to 1, ogCP and ogCLI never use this, and this REST API is never
used by the old web console.
2023-11-23 12:48:08 +01:00
OpenGnSys Support Team 9c69f112de rest: remove dead code in /repository/add
Remove unused code in this request and do not assume center id.
2023-11-23 10:19:36 +01:00
Javier Hernandez fc0f19fe30 rest: add /client/update
Add POST client/update request to update client, this is identified by its ip
address, with the data provided in the payload.
2023-11-23 10:16:09 +01:00
OpenGnSys Support Team e7c4e16602 main: use etc folder instead of cfg to store .json configuration file
debian packages use etc, so update source code to use this folder too.
2023-11-14 11:26:19 +01:00
OpenGnSys Support Team 944fef7b04 core: restrict rest API to 127.0.0.1
Until there is TLS support for this, frontend and ogserver needs to be in the
same box by now.
2023-11-14 11:25:42 +01:00
Javier Hernandez 485bf92216 rest: Check valid bootmode
ogserver will check that the user provided a valid bootmode. It will go
through the list of all available boot modes and check that the bootmode
provided by the user is in said list; otherwise, it will not set it.
2023-11-06 11:42:50 +01:00
Javier Hernandez fa57af3c13 rest: extract og_get_boot_modes from og_cmd_get_modes()
og_cmd_get_modes() now uses a helper function that returns a list of all boot
modes, this is for a new API REST validate that boot mode is set to something
that exists in a follow up patch.
2023-11-06 10:11:44 +01:00
Javier Hernandez 4c1995d28f rest: Add error check to delete commands
Every time a delete operation is performed it needs to be checked that a row
has been deleted. If no rows are deleted, then ogserver reports an error.

Previous to this change, it only checks that the connection to db
was succesful. For example, previously, if a user deletes a client that did
not exist, ogserver responds with no errors.

After this change, it responds with an error.

This error check has been implemented when deleting:
- A client
- An image
- A center
- A repo
- A room
- A server
2023-11-06 10:11:44 +01:00
OpenGnSys Support Team ebd31b97b0 INSTALL: generate 'configure' script 2023-10-30 11:27:06 +01:00
OpenGnSys Support Team 2fae5b08d7 add INSTALL file 2023-10-30 10:48:38 +01:00
OpenGnSys Support Team d3ad9e13e0 rest: use method not found instead of bad request for /clients requests
/clients says bad request for unsupported method, use correct error
report.
2023-10-19 10:46:23 +02:00
Jose M. Guisado 4fca62a8ee rest: extend /repository/add
POST /repository/add checks validity of the repository ip address
specified in the request payload.

/repository/add can optionally receive a center id parameter inside its
request payload. For backward compatibility, the default center id (1)
is used if no center is received inside the request payload.

POST /repository/add returns a JSON response payload containing relevant
fields from the inserted repository.

$ curl 	-D-
	\ -X POST
	\ -H "Authorization: a0e9ab768cbe93dab5b1998e952bcdb7"
  	\ --json '{"name": "helloworld", "ip": "192.168.21.21a", "center": 2}'
	\ localhost:8888/repository/add
HTTP/1.1 400 Bad Request
Content-Length: 0

$ curl 	-D-
	\ -X POST
	\ -H "Authorization: a0e9ab768cbe93dab5b1998e952bcdb7"
  	\ --json '{"name": "helloworld", "ip": "192.168.21.21a", "center": 2}'
	\ localhost:8888/repository/add
HTTP/1.1 200 OK
Content-Length: 54

{"id": 7, "ip": "192.168.21.21", "name": "helloworld"}
2023-10-11 10:28:22 +02:00
Jose M. Guisado 6f6372d0e0 src: move og_repository to dbi.h
Move struct og_repository to dbi.h and use field max length for name and
ip.

Use og_json_parse_string_copy instead of og_json_parse_string to check
maximum length against the request payload.

Fixes: 86ccc3c2e8 ("#915 Add POST /repository/add")
2023-10-10 18:09:19 +02:00
Jose M. Guisado dc68d0f135 rest: add POST /client/repo
Set a client repository in the OpenGnsys database using the endpoint
POST /client/repo.

Expects "clients" and "id" parameters in the request payload.

    POST /client/repo
    {
      "clients": [...],
      "id": "2"
    }

    Response:
    200 OK
2023-10-10 18:09:19 +02:00
Jose M. Guisado 51b70966fc rest: fix sql typo in og_set_client_mode
Replace invalid variable @ipserveradm by @serverip in the SQL query of
og_set_client_mode.

@ipserveradm is a typo as this variable does not exists. This ends up
feeding a string to the legacy setclientmode code and crashes.

This bug also caused problems when adding clients via ogCP or any other
command that required running the set client mode logic.

Fixes: e080fd5526
(rest: add "server=" boot param in set client mode)
2023-09-29 14:53:12 +02:00
Jose M. Guisado 35a3b0a1a3 schema: fix bug when og_dbi_open cannot open a connection
When og_dbi_open cannot open a connection during schema update, then
ogServer crashes.

og_dbi_open returns NULL when it cannot open a DB connection.

Do not use dbi variable if og_dbi_open is unable to open a DB
connection.

Add syslog message when database schema couldn't be updated.
2023-09-28 10:07:07 +02:00
Jose M. Guisado e080fd5526 rest: add "server=" boot param in set client mode
Store a client associated ogserver ip address in "server=" boot param.

Use this boot param to lookup for network-specific ogClient
configuration when launching ogClient during ogLive booting process.
2023-08-28 12:29:33 +02:00
Jose M. Guisado 18eb19ab42 rest: return server_id in GET /client/info
struct og_computer holds the value of "identorno" column inside the
server_id field.

Extend GET /client/info payload with server_id. This way clients can
get the associated server id when requesting client information.

{
...
"server_id": 1,
}
2023-08-23 15:35:34 +02:00
Jose M. Guisado 4cc2ca61fd dbi: add server_id to og_computer struct
Extend og_dbi_get_computer_info to fetch "identorno" column from
"ordenadores". "identorno" holds the row id value from the "entornos"
table (valid ogserver addresses).

Extend og_computer struct with a new field: "server_id" that will store
the value of "identorno" column fetched from the database.
2023-08-23 15:34:44 +02:00
Jose M. Guisado 44745a3f22 rest: add POST client/server method
Enable modification of the associated ogserver of a given client.

This API is exposed via the POST /client/server endpoint and expects a
JSON payload with an array of clients ("client":[]) and the "id" of the
ogserver ("identorno" column value inside the "entornos" table)

For example:

>>>
POST /client/server
{
  "client": [
    "10.141.10.100",
    "10.141.10.101",
    "10.141.10.104",
    "10.141.10.102"
  ],
  "id": "6"
}
<<<
HTTP/1.1 200 OK

If the ogserver id does not exist the foreign key constraint (ON UPDATE
RESTRICT) inside the "ordenadores" table will cancel the operation and
the server will reply with 400 Bad Request.

>>>
POST /client/server
{
  "client": [
    "10.141.10.100",
    "10.141.10.101",
    "10.141.10.104",
    "10.141.10.102"
  ],
  "id": "666"
}
<<<
HTTP/1.1 400 Bad Request

The OpenGnsys database stores different ip addresses for the ogServer
inside the "entornos" table. This table is related to the "ordenadores"
table using a foreign key on the "identorno" column.

i.e: Clients in the "ordenadores" table associate to an specific server
in the database using the "identorno" column (from "entornos" table).
2023-08-23 13:17:03 +02:00
Jose M. Guisado a67c1088ef rest: add DELETE operation to /server endpoint
Expose deletion of rows from "entornos" table via the /server
endpoint using the DELETE http request method.

The expected payload is the server id as a string. For example:

>>>
DELETE /server
{ "id": "4" }

<<<
200 OK

If the specified server is currently associated with any computer
("ordenadores" table) the foreign key contraint (ON DELETE RESTRICT)
will avoid the deletion and the server responds with
400 Bad Request.

>>>
DELETE /server
{ "id": "1" }

<<<
400 Bad Request
2023-08-23 11:39:19 +02:00
Jose M. Guisado b2c8c9d9ab rest: support DELETE HTTP request method
Reuse endpoints in order to add deletion operation such as "/server".
This way there is no need to declare a different if/else block in order
to parse a new URI for the new "*/delete" endpoint.

Current deletion operations are implemented using a different endpoint
name such as "/client/delete", "/center/delete" with POST request method.

Endpoints using "/delete" suffix may not be removed for backwards
compatibility. Adding HTTP method DELETE support for endpoints such as
"/center" or "/client" can use the already existing *_post_delete*
functions.
2023-08-23 11:39:19 +02:00
Jose M. Guisado 351069b591 rest: add /server GET and POST methods
DB stores different ogserver addresses in the "entornos" table.

Expose addition and deletion operations for the "entornos" table using
the /server endpoint.

GET /server returns a list of rows from the "entornos" table including
the "identorno" and "ipserveradm" columns. For example:

>>>
GET /server

<<<
200 OK
...
{
  "servers": [
    {
      "id": 1,
      "address": "10.141.10.1"
    }
  ]
}

POST /server inserts into the "entornos" table and returns the
id ("identorno") of the new row.

>>>
POST /server
{
  "address": "192.168.2.240"
}

<<<
200 OK
...
{
  "id": 2
}

If the server address already exists the response is 400 Bad Request
with no payload.

>>>
POST /server
{
  "address": "192.168.2.240"
}

<<<
400 Bad Request
2023-08-23 11:39:10 +02:00
Jose M. Guisado 74b6e3ec72 rest: add optional param "backup" for create_image
This parameter is used by ogServer to instruct target client if image
backup should be performed before image creation.

This parameter is optional to preserve backward compatibility with
webconsole (legacy web client) and avoid the need of updating any legacy
client.

Default is true if the REST request is missing this parameter.
2023-07-07 10:04:36 +02:00
Jose M. Guisado 3de8c25e4e core: log payload if sequences do not match
We need to inspect the received payload if any error is raised related
to the X-Sequence header. Not just when a malformed X-Sequence header is
detected.

Fixes: d2c19ef13d ("core: add X-Sequence header support")
2023-07-03 09:17:53 +02:00
Jose M. Guisado d2c19ef13d core: add X-Sequence header support
Add non-standard HTTP header "X-Sequence" to the header section of
requests (og_send_request) sent to a connected client.

Define a starting sequence number when creating a new instance of struct
og_client inside og_server_accept_cb. This sequence number is
incremented by one for each outgoing request from ogServer.

This sequence number is checked when receiving a response from a
connected client, if they do not match the connection is dropped.

Use sequence 0 for out-of-band commands (reboot, poweroff, stop). Any
client response with header "X-Sequence: 0" bypasses sequence check.
2023-06-13 14:04:54 +02: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 2213d005ff #915 List all database images.
ogServer "GET /images" list images that exist simultaneously in database
and in disk (/opt/opengnsys/images).

With this patch, ogServer list all images in database, exist or not in
disk. If an image exists in disk, it retrieves more information about
them.

This change is useful for environments where images are in different
machines/repositories.
2022-07-07 12:29:47 +02:00
Javier Sánchez Parra 5cf2de704c #915 Add POST /repository/delete
This method deletes a repository from the database.

Request:
POST /repository/delete
{
  "id": "10"
}

Response:
200 OK
2022-07-01 12:09:16 +02:00
Javier Sánchez Parra 86ccc3c2e8 #915 Add POST /repository/add
This method adds a new repository to the database.

Request:
POST /repository/add
{
  "name": "Repository 1",
  "ip": "192.168.56.10"
}

Response:
200 OK
2022-07-01 12:09:16 +02:00
Javier Sánchez Parra 9ecf638ba2 #915 Extend GET /repositories with param id
Add id parameter to the response. This is useful to identify
repositories that have several IPs.

Request:
GET /repositories
{
  "repositories": [
    {
      "id": 1,
      "ip": "192.168.56.10",
      "name": "Repositorio (Default)"
    }
  ]
}

Response:
200 OK

Related-to: d5e6dc0 ("#915 Add API GET /repositories")
2022-06-23 13:12:59 +02:00