mirror of https://git.48k.eu/ogserver
rest: update client ip in /client/update
Use idordenador as discriminator value instead of the client's ip. Update client ip if the new ip is not used by other clients.master
parent
e9a8f467f1
commit
8a23579cab
20
src/rest.c
20
src/rest.c
|
@ -2199,6 +2199,8 @@ static int og_cmd_post_client_update(json_t *element,
|
|||
computer.ip,
|
||||
sizeof(computer.ip));
|
||||
params->flags |= OG_REST_PARAM_ADDR;
|
||||
} else if (!strcmp(key, "id")) {
|
||||
err = og_json_parse_uint(value, &computer.id);
|
||||
} else if (!strcmp(key, "serial_number")) {
|
||||
err = og_json_parse_string_copy(value,
|
||||
computer.serial_number,
|
||||
|
@ -2251,8 +2253,8 @@ static int og_cmd_post_client_update(json_t *element,
|
|||
}
|
||||
|
||||
result = dbi_conn_queryf(dbi->conn,
|
||||
"SELECT ip FROM ordenadores WHERE ip='%s'",
|
||||
computer.ip);
|
||||
"SELECT ip FROM ordenadores WHERE ip='%s' AND idordenador<>'%u'",
|
||||
computer.ip, computer.id);
|
||||
if (!result) {
|
||||
dbi_conn_error(dbi->conn, &msglog);
|
||||
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
|
||||
|
@ -2260,8 +2262,8 @@ static int og_cmd_post_client_update(json_t *element,
|
|||
og_dbi_close(dbi);
|
||||
return -1;
|
||||
}
|
||||
if (dbi_result_get_numrows(result) == 0) {
|
||||
syslog(LOG_ERR, "client with that IP does not exist: %s\n",
|
||||
if (dbi_result_get_numrows(result) > 0) {
|
||||
syslog(LOG_ERR, "client with IP %s already exist\n",
|
||||
computer.ip);
|
||||
dbi_result_free(result);
|
||||
og_dbi_close(dbi);
|
||||
|
@ -2271,8 +2273,8 @@ static int og_cmd_post_client_update(json_t *element,
|
|||
dbi_result_free(result);
|
||||
|
||||
result = dbi_conn_queryf(dbi->conn,
|
||||
"SELECT ip FROM ordenadores WHERE ip<>'%s' AND mac='%s'",
|
||||
computer.ip, computer.mac);
|
||||
"SELECT ip FROM ordenadores WHERE mac='%s' AND idordenador<>'%u'",
|
||||
computer.mac, computer.id);
|
||||
if (!result) {
|
||||
dbi_conn_error(dbi->conn, &msglog);
|
||||
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
|
||||
|
@ -2294,6 +2296,7 @@ static int og_cmd_post_client_update(json_t *element,
|
|||
result = dbi_conn_queryf(dbi->conn,
|
||||
"UPDATE ordenadores"
|
||||
" SET numserie='%s',"
|
||||
" ip='%s',"
|
||||
" netdriver='%s',"
|
||||
" maintenance=%u,"
|
||||
" netiface='%s',"
|
||||
|
@ -2304,14 +2307,15 @@ static int og_cmd_post_client_update(json_t *element,
|
|||
" nombreordenador='%s',"
|
||||
" mac='%s',"
|
||||
" arranque='%s'"
|
||||
" WHERE ip='%s';",
|
||||
" WHERE idordenador='%u';",
|
||||
computer.serial_number,
|
||||
computer.ip,
|
||||
computer.netdriver, computer.maintenance,
|
||||
computer.netiface, computer.repo_id,
|
||||
computer.netmask, computer.remote,
|
||||
computer.room, computer.name,
|
||||
computer.mac, computer.boot,
|
||||
computer.ip);
|
||||
computer.id);
|
||||
if (!result) {
|
||||
dbi_conn_error(dbi->conn, &msglog);
|
||||
syslog(LOG_ERR, "failed to update client in database (%s:%d) %s\n",
|
||||
|
|
Loading…
Reference in New Issue