Commit Graph

183 Commits (6bc71b201dafd552a46b8e9ab5ee8f1ee5577c17)

Author SHA1 Message Date
Jose M. Guisado e16f36cdef #915 Fix create image payload parsing
Commit 141b0797e1 introduced command scheduling rest api to
ogserver. Part of this changeset included
og_json_parse_create_image as a utility funtion to parse the json
payload of a "create image" command.

og_json_parse_create_image did not include the parsing of optional
parameters "description", "center_id" and "group_id". New components
like ogCP or ogCLI use these parameters.

Fix this by adding a struct og_image member to the struct og_msg_params
and assigning it when processing a "create image" command.

This could be extended to further payload parsing for image related
commands in the future.
2021-10-19 07:54:35 +00:00
Javier Sánchez Parra 36f02324e0 #915 Add POST /image/delete method
Delete operation for images stored in the server. It deletes an image
from the database and filesystem, thus images must exists in both places.

POST /image/delete
{
	"image": "3"
}
2021-10-04 17:44:50 +02:00
Jose M. Guisado 2d68f8a0ec #1061 add timeout to pending scheduled commands
Pending schedule commands can deny ogLive boot of clients due
to filling of pending cmd queue with commands such as "Iniciar Sesión".

For example: Using RemotePC to serve clients that do not boot into
ogLive will fill up the pending command queue with "Iniciar Sesión".

Introduce a safety timeout for pending (scheduled) commands to
avoid this situation.
2021-09-06 12:32:38 +02:00
Jose M. Guisado 8190c6f6df #1051 Initialize task_id once in og_cmd_post_schedule_command
Fixes task_id re-initialization in commit 33d8cecfe.

Task id is to be initialized with the "session" value and can be done
out of the for loop it was before. Avoiding unnecesary snprintf's with
the same value.
2021-07-22 16:06:26 +02:00
Jose M. Guisado 261d490c4e #1052 Populate session column when adding actions
If the scope of a command, procedure or task is related to a group of
computers then actions associated with that schedule can share the same
session value.

og_dbi_add_action was not initializing session value, as it is only used
for visualization purposes in the legacy web interface.

This patch enables og_dbi_add_action to populate session column by
assigning it the id value of the first action related to the scope.

Example: Power off command for a room scope of 4 clients will result in
4 actions, a power off for each client. The first action id will determine
the session value for the rest.
2021-07-22 15:52:12 +02:00
Jose M. Guisado 33d8cecfe1 #1051 Fix command schedule for several clients
A single command can be schedule for several clients.

Commit 141b0797e1 introduces a regression when scheduling a command for
several clients, the command only executes successfuly for the first
one.

Fix it by reintroducing the usage of the 'session' column to group
a single command into several actions (one for each client), the web
console interface already expects this 'session' column to be set
accordingly.
2021-07-21 17:55:55 +02:00
Javier Sánchez Parra 7325a8629e #915 Add POST /task/add method
Adds the possibility to create a task with procedures and other tasks
integrated as steps.

Note: "steps" parameter is optional and "steps" array object order
defines execution order.

Request:
POST /task/add
{
  "center": "1",
  "name": "task",
  "description": "My task",
  "steps": [
             {
               "procedure": 4
             },
             {
               "task": 1
             },
             {
               "procedure": 24
             }
           ]
}

Response:
200 OK

This commit also add task case to procedure's step processing.
Otherwise, gcc prints the following warning:

src/rest.c: In function ‘og_procedure_add_steps’:
src/rest.c:4089:17: warning: enumeration value ‘OG_STEP_TASK’ not handled in switch [-Wswitch]
 4089 |                 switch (step->type) {
      |                 ^~~~~~
2021-07-01 09:20:46 +02:00
Javier Sánchez Parra a496da17ea #915 Add POST /procedure/update method
Adds the possibility to update a procedure with commands and other
procedures integrated as steps.

Note: "steps" parameter is optional and "steps" array object order
defines execution order. Also, if the body has empty steps, the
procedure loses its previous steps.

Request:
POST /procedure/update
{
  "procedure": "34",
  "center": "1",
  "name": "procedure-edited",
  "description": "My procedure edited",
  "steps": [
             {
               "command": "wol",
               "params": { "type": "broadcast" }
             },
             {
               "procedure": 24
             },
             {
               "command": "reboot",
               "params": {}
             }
           ]
}

Response:
200 OK
2021-06-29 11:48:33 +02:00
Javier Sánchez Parra cf7d0742a3 Fix procedure id retrieving in steps creation
Otherwise, procedure id is always zero.

Fixes: 1fdb7e6d1c
2021-06-29 11:48:28 +02:00
Javier Sánchez Parra 66ba6d045e #915 Filter queued commands by id
ogServer searches queued commands (formerly actions) in the DB by
session. This can lead to problems because session is not an uniquely
identifier but an identifier that several commands can share to group
them.

This commit changes query filter from session to id, ensuring correct
results

This reverts commit d9b6aadf66.
2021-06-16 12:16:37 +02:00
Javier Sánchez Parra c03b87dcc6 #915 Add POST /procedure/run method
Add ogServer support procedure execution. Now users can send a procedure
and a list of clients to ogServer, then ogServer breaks down the
procedure into commands (formerly actions) and queues them for each
indicated client.

TODO: Do not reply 200 OK when the procedure do not exist.

Request:
POST /procedure/run
{
  "clients": ["192.168.56.11", "192.168.56.12"],
  "procedure": "33"
}

Response:
200 OK
2021-06-15 12:11:16 +02:00
Jose M. Guisado 830c321062 #915 Add procedure/delete
Delete operation for procedures stored in the database.

POST /procedure/delete
{
	"id": "7"
}

If no procedure is found returns 200 OK but a syslog call is issued to
warn so. Such behavior will likely change in the future.
2021-06-11 11:34:59 +02:00
Jose M. Guisado d9b6aadf66 #915 Revert filtering actions by id to "sesion" in og_dbi_queue_command
Commit 141b079 introduced a slight change in how rows from table
"acciones" are filtered when queuing a command, from "sesion" column to
"idaccion" column.

This seemed reasonable, as id column is the one autoincrementing. But
remotepc queued commands inserting actions id using a timestamp instead
of the action row id.

See c17ffa5d03/admin/WebConsole/rest/remotepc.php (L188)

Revert said change as long as remotepc keeps such behavior.
2021-06-10 17:36:51 +02:00
Javier Sánchez Parra 1fdb7e6d1c #915 Add commands and procedures to procedure creation
Adds the possibility to create a procedure with commands and other
procedures integrated as steps.

Note: "steps" parameter is optional and "steps" array object order
defines execution order.

Request:
POST /procedure/add
{
  "center": "1",
  "name": "procedure",
  "description": "My procedure",
  "steps": [
             {
               "command": "wol",
               "params": { "type": "broadcast" }
             },
             {
               "procedure": 22
             },
             {
               "command": "poweroff",
               "params": {}
             }
           ]
}

Response:
200 OK

This commit also updates unit tests for /procedure/add POST method to
include steps.
2021-06-10 17:00:01 +02:00
Jose M. Guisado 141b0797e1 #915 Add schedule/command
Enables ogserver to schedule commands (also referred as actions in
legacy web console jargon).

This feature enables ogserver to write in the "acciones" table in order
to have full capabilities for command scheduling purposes, thus not
depending in the legacy web console to insert into "acciones" table.
2021-06-09 13:41:28 +02:00
Javier Sánchez Parra 41fad11408 #942 Add POST /procedure/add method
This method adds a procedure associated with a center to the database.
Required payload parameters are center and name, description is
optional.

Note: ogServer does not allow to add more than one procedure with the
same name and center.

Request:
POST /procedure/add
{
  "center": "1"
  "name": "procedure1"
  "description": "My procedure"
}

Response:
200 OK

This commit also adds unit tests for /procedure/add POST method.
2021-05-31 13:01:47 +02:00
Javier Sánchez Parra bc9424724d Add REST POST /room/delete method
This method deletes a room (lab) from the DB and deletes on cascade
computers and computers partitions.

Note: if the room id do not exists in the database, ogserver still
tries to delete it and replies with 200 OK.

Request:
POST /room/delete
{
  "id": "1"
}

Response:
200 OK
2021-05-10 13:39:38 +02:00
Javier Sánchez Parra b48707333f #942 Add REST POST /center/delete method
This method deletes a center from the DB and deletes on cascade
rooms/labs, computers and computers partitions.

Note: if the center id do not exists in the database, ogserver still
tries to delete it and replies with 200 OK.

Request:
POST /center/delete
{
  "id": "1"
}

Response:
200 OK
2021-05-10 12:07:53 +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
Jose M. Guisado 927d42bdf8 #1043 don't create wol entries when client is connected
Avoids multiple entries of a same client like

{"clients": [{"addr": "192.168.2.230", "state": "WOL_SENT"}, {"addr": "192.168.2.230", "state": "OPG"}]

These can arise when ogserver processes a WoL request for an already
connected client.

When processing the WoL request, search for the target address in the
clients list, if found we avoid creating the wol entry.
2021-04-29 13:11:34 +02:00
OpenGnSys Support Team 1f13855e41 #1043 add WOL_SENT state
WOL_SENT tells that WakeOnLan was sent to computer, after 60 seconds,
if computer does not boot, this state is released.
2021-04-29 11:52:32 +02:00
OpenGnSys Support Team c05f1345e7 #1043 add function to append client to json tree
og_json_client_append() adds a client objet to the json tree.
2021-04-29 11:52:04 +02:00
Javier Sánchez Parra 29e7641e91 #915 Add /room/add POST method
Adds POST method to add rooms (labs), required payload parameters are
name, netmask and center; any additional attributes are optional.

Required JSON:
        { "center": 0,
          "name": "classroom10",
          "netmask": "255.255.255.0" }

Full JSON:
        { "center": 0,
          "name": "classroom11",
          "netmask": "255.255.255.0",
          "group": 0,
          "location": "First floor",
          "gateway": "192.168.56.1",
          "ntp": "hora.cica.es",
          "dns": "1.1.1.1",
          "remote": True }

This commit also adds unit tests for /room/add POST method.
2021-04-20 12:05:42 +02:00
Javier Sánchez Parra 49fc6c5c5c #915 increase maximum API REST response size
GET /scope could generate a response larger than 64 Kbytes.
Rise the maximum API REST response size to 256 Kbytes.
2021-04-19 12:01:39 +02:00
Javier Sánchez Parra 90eab86796 #915 fix "response too large" error path
Otherwise, ogServer sends "200 OK" after a "500 Internal Server Error
error" response.
2021-04-19 12:01:16 +02:00
Javier Sánchez Parra 2c6cef71d8 #915 validate response json size
Otherwise, copying response json to response buffer could lead to stack
smashing is the json response is too large.

stdout example:
*** stack smashing detected ***: <unknown> terminated
2021-04-19 12:00:27 +02:00
Jose M. Guisado 0212091e7f #915 Add /center/add POST method
Adds POST method to add centers (organizational unit), required payload
parameter is the name, and an additional comment is optional.

	{"name": "ACME"}

	{"name": "ACME", "comment": "Some comment"}
2021-04-08 11:12:23 +02:00
Javier Sánchez Parra 8015f85b04 #915 Add GET /oglive/test REST API function
This function returns the installed and available ogLiveS in the server
to be booted from.

Request:
GET /oglive/list
NO BODY

Response
200 OK
{
  "oglive": [
    {
      "distribution": "bionic",
      "kernel": "5.4.0-40-generic",
      "architecture": "amd64",
      "revision": "r20200629",
      "directory": "ogLive-5.4.0-r20200629",
      "iso": "ogLive-bionic-5.4.0-40-generic-amd64-r20200629.85eceaf.iso"
    },
    {
      "distribution": "bionic",
      "kernel": "5.0.0-27-generic",
      "architecture": "amd64",
      "revision": "r20190830",
      "directory": "ogLive-5.0.0-r20190830",
      "iso": "ogLive-bionic-5.0.0-27-generic-amd64-r20190830.7208cc9.iso"
    }
  ],
  "default": 0
}

This commit also adds tests for GET /oglive/test.
2021-04-05 18:00:56 +02:00
Diego Crespo Quinta d9e1521a16 #1004 Add GET /images test
Fix incorrect error if json is missing.
2021-03-30 16:11:45 +02:00
OpenGnSys Support Team a71cba4df1 #990 fix crash in wol with malformed IP address
==28831== 1 errors in context 1 of 2:
==28831== Invalid read of size 1
==28831==    at 0x55AC6FD: inet_aton (inet_addr.c:127)
==28831==    by 0x10ECCA: WakeUp (ogAdmServer.c:337)
==28831==    by 0x10EED6: Levanta (ogAdmServer.c:292)
==28831==    by 0x11651E: og_cmd_wol (rest.c:498)
==28831==    by 0x11651E: og_client_state_process_payload_rest (rest.c:3970)
==28831==    by 0x110CF3: og_client_read_cb (core.c:143)
==28831==    by 0x4E41D72: ev_invoke_pending (in /usr/lib/x86_64-linux-gnu/libev.so.4.0.0)
==28831==    by 0x4E453DD: ev_run (in /usr/lib/x86_64-linux-gnu/libev.so.4.0.0)
==28831==    by 0x10E3E5: ev_loop (ev.h:835)
==28831==    by 0x10E3E5: main (main.c:100)
==28831==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

Use number of matching ip addresses in the database, skip if zero.
2021-03-30 13:58:31 +02:00
Javier Sánchez Parra e6c2c26f09 #990 Use lab netmask to calculate broadcast address
ogServer gets netmask address from computer (ordenadores) table, see
commit a35b7c4. Netmask field is empty in most cases, is only filled
when the user adds computers with dhcpd.conf syntax and cannot be edited
in computer properties view.

Labs/rooms (aulas) table also have netmask field, WebConsole backend
ensures it is not empty and can be edited in lab properties view.

Get netmask from labs table to ensure it is not empty.
2021-03-17 19:50:40 +01:00
Jose M. Guisado 41bc66d0e7 #997 Fix og_tm_hours_mask
Tests for e68fefe were made after 00pm (12:00) so we did not cover <12:00 cases
for immediate commands that are logged (scheduled for the exact moment
they are processed and ignored the fact they are stale so they are executed
right away)

In addition, libdbi was complaining about the data type used to
represent the hours, they were not being inserted properly. From syslog:

	failed to query database (og_dbi_schedule_create:3288) 1264: Out of
	range value for column 'horas' at row 1

Fix og_tm_hours_mask so <12:00 immediate schedule is handled correctly.
Change return type to uint16_t, as the 'hours' column type is smallint(4)

Fixes e68fefe ("#997 Set stale check flag when processing schedule/create")
2021-03-15 12:17:56 +01:00
Jose M. Guisado 8b7b5f33a1 #997 Use stale check flag in schedule/update
Commit e68fefe introduced 'check_stale' flag to better distinguish
real scheduled actions that do not execute if they are stale from
immediate actions that we want them to be logged in the action queue
(by creating a decoy schedule for the exact moment they are processed,
meaning that we ignore if the are stale).

Add this feature into schedule update too, in order to avoid executing
stale commands that were not meant to, ie. real scheduled commands.

Follows e68fefe ("Set stale check flag when processing schedule/create")
2021-03-15 12:17:56 +01:00
OpenGnSys Support Team e7e80cdde6 #942 return error if API REST parser fails
Return error if json parser fails, ignore unknown json attributes.
Missing uninitialized error value.
2021-03-15 12:17:56 +01:00
Jose M. Guisado 829f8d8ac9 #997 Remove unnecessary strdup in og_dbi_queue_*
After executing an scheduled command/proc/task valgrind reported
leaks inside og_dbi_queue_{command,procedure,task}. String
duplication is not being freed after using them.

==21281== 36 bytes in 1 blocks are definitely lost in loss record 470 of
592
...
==21281==    by 0x113DCB: og_dbi_queue_procedure (rest.c:2748)
==21281==    by 0x113F91: og_dbi_queue_task (rest.c:2804)
==21281==    by 0x114392: og_schedule_run (rest.c:2916)
==21281==    by 0x112059: og_agent_timer_cb (schedule.c:441)
...
==21281==    by 0x10E2A5: main (main.c:100)

These strdup are not necessary because the dbi result is not freed
before using them, it's safe to use the dbi result's reference to
this string.

Fix previous memleaks when executing scheduled commands, procedures
and tasks.
2021-03-11 14:39:07 +01:00
Jose M. Guisado e68fefeac7 #997 Set stale check flag when processing schedule/create
If you schedule a command in the past, the scheduler executes such
command immediately.

When expanding a schedule that result in commands that run weekly,
commands in the past are also executed, which is not expected.

Fix this by using the check_stale flag (formerly on_start) so
commands in the past that result from expansions are skipped.
2021-03-11 12:22:36 +01:00
Jose M. Guisado 76e6375720 #1004 Fix memleak in og_cmd_images
image_json object is created to store the json representation of
an image returned by the database. This object is going to be appended
to a json list that will compose the overall root json object.

Use json_array_append_new to let "images" steal the reference of
image_json so when further decref(root) there is no json reference
hanging around.
2021-02-24 14:33:22 +01:00
OpenGnSys Support Team 1c52b78e72 #942 memleak in og_send_request() 2021-02-23 12:35:53 +01:00
OpenGnSys Support Team 9b708e0a7b #942 memleak in error path
Fix memleaks in error path.

json_decref() checks for null objects.
2021-02-23 12:32:57 +01:00
Jose M. Guisado a46b69b590 #990 Fix og_cmd_wol memory leak
Allocated strings using dbi_result_get_string_copy are not being freed
after using them. This patch fix this memory leak.

Fixes: e4cb91b ("#990 wol: migrate mac and netmask query to ogServer")
2021-02-23 10:49:12 +01:00
OpenGnSys Support Team 3b3405bc2f #1019 UAF in schedule run
Otherwise accessing IP address results in use-after-free.
2021-02-23 10:48:13 +01:00
Javier Sánchez Parra ed0d86b010 #1019 Fix queued Wake on LAN
UMA and UPV report that Wake on LAN command (in queue mode) does not
work.

We improved WoL command, now ogServer calculates the broadcast address
of the network to which the client belongs. To calculate this address
ogServer needs the IP and the netmask of the client. We updated ogServer
to retrieve the netmask from the database in non-queue mode, but we forgot
to add this in queue mode.

This patch adds netmask retrieving to queued WoL.
2021-02-22 11:05:34 +01:00
Jose M. Guisado e4cb91b5f6 #990 wol: migrate mac and netmask query to ogServer
ogServer WoL rest function is expecting ip, mac and netmask from the
request's payload. This makes the client responsible for providing such
data.

ogServer should be the owner of the database, this patch adjusts the
parameter expected in a request payload for /wol action so clients only
need to provide the ips and wol type (broadcast, unicast).

Database is expected to contain valid data for the netmask and mac of
target computers.
2021-02-15 16:26:21 +01:00
Jose M. Guisado 4d2e1dd31c #1004 Fix client setup disk size showing as 0
og_cmd_get_client_setup is querying the database for computers disk
setup information. This includes the size of a disk or a partition,
which are stored as BIGINT in the database.

Using dbi_result_get_int will result in an error as libdbi expects to
store this kind of data type in a long long instead of an int.

Fix disk size variable declaration and use the correct dbi_result_get
function for this particular data column.
2021-02-09 13:13:53 +01:00
Javier Sánchez Parra 6a7a846e6e #1019 Fix setup legacy string parser
UMA reports that the setup command (in queue mode) does not work.

WebConsole stores queued commands in the database using the deprecated
SocketHidra legacy string format and ogServer parses them with sscanf().
The setup command has a new field "ttp" since commit 0dd3edd, however,
the ogServer legacy parser was not updated to use this new field.

This patch adds legacy setup support to work with GPT tables. Add new field
table type to legacy setup that expects a string with "MSDOS" or "GPT".
2021-02-08 22:38:25 +01:00
Javier Sánchez Parra 0e4857a538 #1019 Fix restore-image legacy string parser
UMA reports that the restore image command (in queue mode) does not work,
the non-queue mode works fine though.

WebConsole stores queued commands in the database using the deprecated
SocketHidra legacy string format and ogServer parses them with sscanf().
The restore-image command has the field "ptc" which stores a string
with whitespaces, however, ogServer expects no whitespaces ("%s").

Update parser to read until carriage return, whitespaces included.
2021-02-08 22:36:29 +01:00
Jose M. Guisado 85d092864c #802 add uefi folder for post_modes pxe template lookup
When executing og_cmd_post_modes ogServer is looking up for the template
related to the mode coming as a parameter. This lookup is only done for
the bios boot mode. (ie. /opt/opengnsys/tftpboot/menu.lst/templates/)

Templates can be created for a given boot mode, for example you can
create a UEFI-only template (it.
/opt/opengnsys/tftpboot/grub/templates).

When a UEFI only template was coming as a parameter to og_cmd_post_modes
the file can't be located because the UEFI template folder is never
tested.

Add UEFI folder to the lookup of pxe templates, try this folder if bios
mode fails.

PS: Later on a bash script "setclientmode" is to be executed, which will
take its own way of updating these pxe files (ie. templates/../), this
script updates every boot mode if an available template is found.
2021-01-13 09:58:22 +01:00
Javier Sánchez Parra 6d628dc1b2 #1010 Fix /software missing body in queued mode
ogServer do not send /software parameters to ogClient in queued mode.

Add parameters as JSON body.
2020-12-02 14:11:55 +01:00
Javier Sánchez Parra 8d914564c8 #1010 Adapt ogServer to send GET /software
ogClient changed /software from POST to GET.

Adapt ogServer to work with ogClient /software new method.
2020-12-02 14:11:49 +01:00
Diego Crespo Quinta aeb53bd351 #915 Test GET /scopes
And fix ogserver, report error if GET /scopes have a JSON body.
2020-12-01 19:29:37 +01:00
Javier Sánchez Parra 0dd3edd27c #1008 Add support to work with GPT tables
ogServer /setup do not support to indicate which table type the user
want to use. It always supposes that the partition table is MBR/MSDOS.

Add ogServer support to work with GPT tables. Add new field table type
to /setup that expects a string with "MSDOS" or "GPT".

Example old JSON:
{
  "clients": [...],
  "disk": "1",
  "cache": "0",
  "cache_size": "0",
  "partition_setup": [...]
}

Example new JSON:
{
  "clients": [...],
  "type": "GPT",
  "disk": "1",
  "cache": "0",
  "cache_size": "0",
  "partition_setup": [...]
}
2020-11-27 12:52:21 +01:00
Roberto Hueso Gómez 7f5ab4ac35 #942 Add GET /session REST API function
This function returns the installed and available OSs in a client to be
booted from.

Request:
GET /session
{
  "client": ["192.168.56.11"]
}

Response
200 OK
{
  "sessions": [
    {
      "disk": 1,
      "name": "Ubuntu 18.04.4 LTS",
      "partition": 1
    }
  ]
}
2020-10-20 15:34:15 +02:00
Roberto Hueso Gómez 2958d23db2 #942 Use client's IP as filter in GET /hardware
This patch uses client's IP instead of scope ID as a filter for the
request.

Request:
GET /hardware
{
  "client": ["192.168.56.11"]
}

Response:
200 OK
{
  "hardware": [
    {
      "description": "BIOS",
      "type": "Tipo de proceso de arranque"
    },
    {
      "description": "QEMU Standard PC (i440FX + PIIX, 1996)  v.pc-i440fx-5.1",
      "type": "Marca y modelo del equipo"
    },
    {
      "description": "Intel Corp. Intel Core Processor (Haswell, no TSX, IBRS) 2GHz v.pc-i440fx-5.1",
      "type": "Microprocesadores"
    },
    {
      "description": "QEMU  2049MiB  (DIMM 0)",
      "type": "Memorias"
    },
    {
      "description": "Red Hat, Inc. Virtio network device  v.00",
      "type": "Tarjetas de Red"
    }
  ]
}
2020-10-20 13:44:44 +02:00
Roberto Hueso Gómez 25c1c16e99 #942 Add GET /software REST API function
This function retrieves a list of the software installed in a specific
disk and partition of a client. This list can be updated by using POST
/software beforehand.

Request:
GET /software
{
  "client": ["192.168.56.11"],
  "disk": 1,
  "partition": 1
}

Response:
200 OK
{
  "software": [
    "grub-pc-bin 2",
    "grub-pc 2.02",
    "grub2-common 2.02",
    "groff-base 1.22.3",
    "gpg 2.2.4",
    "gnupg-utils 2.2.4",
    "gnupg-l10n 2.2.4",
    "gnupg 2.2.4",
    "gnome-video-effects 0.4.3",
    "gnome-user-guide 3.28.2+git20180715",
    "gnome-user-docs 3.28.2+git20180715",
    "gnome-todo-common 3.28.1",
    "gnome-mines 3.28.0",
    "gnome-menus 3.13.3",
    "gnome-mahjongg 3.22.0",
    "gnome-keyring-pkcs11 3.28.0.2",
    "gnome-keyring 3.28.0.2",
    "gnome-initial-setup 3.28.0",
    "accountsservice 0.6.45"
  ]
}
2020-10-16 14:40:33 +02:00
Roberto Hueso Gómez d8b78bb922 #942 Extend GET /images function
This extension removes replaces the field 'filename' for 'name' and adds
new fields (software_id, type and id). These new fields are useful when
restoring an image.

Request:
GET /images

Response:
200 OK
{
  "disk": {
    "free": 37091418112,
    "total": 52573995008
  },
  "images": [
    {
      "datasize": 5939200000,
      "id": 25,
      "modified": "Wed Oct 14 11:49:00 2020",
      "name": "archlinux",
      "permissions": "744",
      "size": 1844222333,
      "software_id": 19,
      "type": 1
    }
  ]
}
2020-10-14 17:31:43 +02:00
Roberto Hueso Gómez d2f20d0be0 #942 Create DB image when calling POST /image/create
In case the DB entry for an image does not exist when POST /image/create
is called, this patch takes care of calling it.

This adds few optional json parameters to the POST /image/create API. If
optional parameters are included then this patch creates the DB entry,
otherwise it just creates the actual image and updates the existing
entry.

Request:
POST /image/create
{
  "clients":["192.168.56.11"],
  "disk":"1",
  "partition":"1",
  "name":"archlinux",
  "repository":"192.168.56.10",
  "id":"24",
  "code":"131",
  "description":"This is a test",
  "group_id":0,
  "center_id":1
}
Response:
200 OK
2020-10-14 12:05:25 +02:00
Roberto Hueso Gómez 24c8b940e6 Add REST POST /client/delete method
This method deletes a client from the DB.

Request:
POST /client/delete
{
  "clients": ["192.168.56.30"]
}

Response:
200 OK

Co-authored-by: Javier Sánchez Parra <jsanchez@soleta.eu>
2020-10-08 12:56:32 +02: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
OpenGnSys Support Team 3cea4bb763 #988 rename og_server_cfg to cfg
to avoid clash with existing variable cfg in client.c
2020-10-07 11:11:04 +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 403e7c323b #1004 Add GET /images
This commit adds GET /images to the ogServer REST API.

This call returns information of all the images in ogServer.

Example response:

{
  "images": [
    {
      "filename": "ubuntu.img",
      "datasize": 2150400000,
      "size": 613476223,
      "modified": "Wed Sep 23 10:37:36 2020",
      "permissions": "744"
    },
    {
      "filename": "test.img",
      "datasize": 2150400000,
      "size": 613236475,
      "modified": "Tue Sep 29 08:57:47 2020",
      "permissions": "744"
    }
  ],
  "disk": {
    "total": 52573995008,
    "free": 39624544256
  }
}
2020-09-29 12:43:07 +02:00
Roberto Hueso Gómez 65a14e56d3 #942 Add POST /client/add HTTP REST method
This method adds a new client. This new client's IP cannot be duplicated
in the DB.

Request:
POST /client/add
{
  "boot": "19pxeADMIN",
  "center": 0,
  "hardware_id": 0,
  "id": 2,
  "ip": "192.168.56.12",
  "livedir": "ogLive",
  "mac": "0800270E6512",
  "maintenance": true,
  "name": "pc12",
  "netdriver": "generic",
  "netiface": "eth1",
  "netmask": "255.255.255.0",
  "remote": false,
  "repo_id": 1,
  "room": 1,
  "serial_number": ""
}

Response:
200 OK
2020-09-24 17:03:56 +02:00
Roberto Hueso Gómez af47a082ad #1004 Add GET /client/info HTTP REST method
This method provides information about a specific client. The request
must contain exactly 1 client's IP.

Request:
GET /client/info
{"client": ["192.168.56.12"]}

Response:
200 OK
{
  "boot": "19pxeADMIN",
  "center": 0,
  "hardware_id": 0,
  "id": 2,
  "ip": "192.168.56.12",
  "livedir": "ogLive",
  "mac": "0800280E6871",
  "maintenance": true,
  "name": "pc12",
  "netdriver": "generic",
  "netiface": "eth1",
  "netmask": "255.255.255.0",
  "remote": false,
  "repo_id": 1,
  "room": 1,
  "serial_number": ""
}
2020-09-22 15:24:38 +02:00
Roberto Hueso Gómez ff71a2ad6e Fix size of og_cmd_get_client_setup() return array
The return array needs to store 1 extra element for the disk setup.
2020-09-15 15:00:17 +02:00
Roberto Hueso Gómez b59ff7c604 #1004 Add GET /client/setup HTTP REST method
This method provides the partitions setup for a specific client. The
request must contain exactly 1 client's IP.

Request:
GET /client/setup
{'client': ['192.168.56.12']}

Response:
200 OK
{
  "partitions": [
    {
      "disk": 1,
      "partition": 0,
      "code": 0,
      "size": 20971520,
      "used_size": 0,
      "filesystem": 0,
      "os": 0,
      "image": 0,
      "software": 0
    }
  ]
}
2020-09-14 12:13:06 +02:00
OpenGnSys Support Team a1aaad46fb #980 do not report busy client if probing is pending
og_client_status() should not report busy when probing is going on.
2020-08-21 18:10:39 +02:00
Roberto Hueso Gómez 91c3a285ba #980 Add 'ip' field in GET /scopes request
The 'ip' field is added to the json for scopes that have an IP (i.e.
computers).
2020-08-14 12:55:18 +02:00
Roberto Hueso Gómez 4ae9903dc3 #980 Select POST /mode clients by ip instead of scope name
This patch selects clients whose modes need to be changed in the current
request. This patch makes POST /mode consistent with the rest of the
REST API where clients are selected and filtered by ip.
2020-08-14 12:50:24 +02:00
OpenGnSys Support Team ca545d39bd #998 disable incremental image API
This API is not supported by ogClient yet and it uses the obsolete socket hydra API.
2020-08-14 12:48:21 +02:00
OpenGnSys Support Team 1855b68af3 #980 fix compile warning in og_set_client_mode
CC       src/rest.o
src/rest.c: In function ‘og_cmd_post_modes.isra.27’:
src/rest.c:966:4: warning: ‘%s’ directive output may be truncated writing up to 4096 bytes into a region of size between 3018 and 4041 -Wformat-truncation=]
    "MODE_FILE='%s'\nMAC='%s'\nDATA='%s'\n"
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/rest.c:1085:7:
       template_name, scope_name);
       ~~~~~~~~~~~~~
src/rest.c:967:33: note: format string is defined here
    "MODE='PERM'\nTEMPLATE_NAME='%s'",
                                 ^~
src/rest.c:965:2: note: ‘snprintf’ output 57 or more bytes (assuming 5176) into a destination of size 4096
  snprintf(cmd_params, sizeof(cmd_params),
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    "MODE_FILE='%s'\nMAC='%s'\nDATA='%s'\n"
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    "MODE='PERM'\nTEMPLATE_NAME='%s'",
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    mode, mac, params, template_name);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-08-06 10:45:03 +02:00
OpenGnSys Support Team 5286c93d69 #980 error reporting in setclientmode
Add syslog and use exit()
2020-08-06 10:36:44 +02:00
Irina Gomez 139633a334 #986 Fixs error in 'Advanced Netboot' caused by loss information from ogserver process owner (author Roberto Hueso Gómez). 2020-08-05 14:21:16 +02:00
Roberto Hueso Gómez b8a509b1dd #980 Change GET and POST /modes URI to /mode
This patch changes the URI since it is semantically more correct to use
the singular.
2020-08-03 13:14:44 +02:00
Roberto Hueso Gómez 532b0819c4 #980 Fix POST /modes to use 'setclientmode' script
Now POST /modes does not only write to the database, it also uses the
external bash script 'setclientmode' to generate configured PXE
templates for each machine.

NOTE: This fix requires that room and computer names are unique in the
OpenGnsys DB. This behaviour is inherited from the previous
'setclientmode' script but, eventually, it should be replaced for an
actual scope selector.
2020-07-29 20:17:34 +02:00
Roberto Hueso Gómez a8eccba706 Add GET /hardware REST request
This patch implements HTTP GET /hardware request which returns a list of
the hardware associated with a particular computer.

Request: GET /hardware
{
  "scope": {
    "id": 6,
    "type": "computer"
  }
}

Response: 200 OK
{
  "hardware": [
    {
      "type": "Microprocesadores",
      "description": "CPU arch:x86 target:x86_64 cores:4"
    },
    {
      "type": "Memorias",
      "description": "QEMU 4096MiB"
    },
    {
      "type": "Tarjetas gráficas",
      "description": "Red Hat, Inc Virtio GPU"
    },
    {
      "type": "Tarjetas de Red",
      "description": "Intel Corporation 82540EM Gigabit Ethernet Controller
                      QEMU Virtual Machine"
    },
    {
      "type": "Controladores IDE",
      "description": "Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
                      Qemu virtual machine"
    }
  ]
}
2020-07-08 17:08:46 +02:00
Roberto Hueso Gómez 33b0c6f694 Add POST /modes REST request
This patch implements HTTP POST /modes request which can change the mode of any
particular scope.

Request: POST /modes
{
  "scope": {"id": 1,
            "type": "computer"},
  "mode": "pxe"
}
Response: 200 OK
2020-07-06 17:27:33 +02:00
Javier Sánchez Parra 06af0c26f4 #990 Use client broadcast address on WoL
Some universities have computers in a different subnet where the
ogServer is, but ogServer WoL functionality only supported to send
packet to its own subnets. This commit solves this.

Now ogServer sends two WoL packets per client, one with the broadcast
address of the interface indicated in the config file, the other with
the broadcast address calculated with the address and netmask of the
client.

To ensure that the second WoL works correctly you must configure
correctly the IP and netmask of the clients. Also, you have to configure
the network of your organization to route WoL packet to the correct
subnet.
2020-07-03 14:11:35 +02:00
Roberto Hueso Gómez f520a57f58 #980 Refactor GET /scopes backend
This improves style and fixes some memleaks.

Co-authored-by: OpenGnSys Support Team <soporte-og@soleta.eu>
2020-07-02 12:14:19 +02:00
OpenGnSys Support Team e54c5ca411 #980 Fix memleak in og_cmd_get_modes()
Missing closedir() call.
2020-06-30 19:40:12 +02:00
Roberto Hueso Gómez 76c0a05f28 #980 Fix memleak in og_cmd_scope_get
If either root or children_root fail to be created but the other one does not,
then reserved memory for the successful one would not be freed.
2020-06-30 16:50:11 +02:00
Roberto Hueso Gómez 608709f620 #980 Add GET /modes REST request
This patch implements HTTP GET /modes request which returns all modes available
for clients:

Request: GET /modes HTTP/1.0
Response: 200 OK
{
  "modes": [
    "pxe",
    "10",
    "13",
    "00unknown",
    "11",
    "19pxeADMIN",
    "12"
  ]
}
2020-06-30 16:49:11 +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