From e6c2c26f09b65e4c4817ab4f77d4a08e52bd121d Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Wed, 17 Mar 2021 15:29:10 +0100 Subject: #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. --- src/rest.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src') 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); -- cgit v1.2.3-18-g5258