summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2021-03-17 15:29:10 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-03-17 19:50:40 +0100
commite6c2c26f09b65e4c4817ab4f77d4a08e52bd121d (patch)
tree27c5ab6b98498de54bf3664890277fe693dc378a /src
parent4bd409774c99bc9ff7425bbc24b86a337ca96d0d (diff)
#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.
Diffstat (limited to 'src')
-rw-r--r--src/rest.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/rest.c b/src/rest.c
index 04a715f..bedb3d5 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -471,8 +471,13 @@ static int og_cmd_wol(json_t *element, struct og_msg_params *params)
}
result = dbi_conn_queryf(dbi->conn,
- "SELECT ip, mac, mascara FROM ordenadores "
- "WHERE ip IN (%s)", ips_str);
+ "SELECT ordenadores.ip, ordenadores.mac, "
+ "aulas.netmask "
+ "FROM ordenadores "
+ "INNER JOIN aulas "
+ "ON ordenadores.idaula = aulas.idaula "
+ "WHERE ordenadores.ip IN (%s)",
+ ips_str);
if (!result) {
dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
@@ -484,7 +489,7 @@ static int og_cmd_wol(json_t *element, struct og_msg_params *params)
for (i = 0; dbi_result_next_row(result); i++) {
params->ips_array[i] = dbi_result_get_string_copy(result, "ip");
params->mac_array[i] = dbi_result_get_string_copy(result, "mac");
- params->netmask_array[i] = dbi_result_get_string_copy(result, "mascara");
+ params->netmask_array[i] = dbi_result_get_string_copy(result, "netmask");
}
dbi_result_free(result);
@@ -2185,8 +2190,12 @@ static int og_cmd_legacy_wol(const char *input, struct og_cmd *cmd)
}
result = dbi_conn_queryf(dbi->conn,
- "SELECT mascara FROM ordenadores "
- "WHERE ip = '%s'", cmd->ip);
+ "SELECT aulas.netmask "
+ "FROM ordenadores "
+ "INNER JOIN aulas "
+ "ON ordenadores.idaula = aulas.idaula "
+ "WHERE ordenadores.ip = '%s'",
+ cmd->ip);
if (!result) {
dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
@@ -2198,7 +2207,7 @@ static int og_cmd_legacy_wol(const char *input, struct og_cmd *cmd)
og_cmd_init(cmd, OG_METHOD_NO_HTTP, OG_CMD_WOL, NULL);
cmd->params.netmask_array[0] = dbi_result_get_string_copy(result,
- "mascara");
+ "netmask");
cmd->params.mac_array[0] = strdup(cmd->mac);
cmd->params.wol_type = strdup(wol_type);