mirror of https://git.48k.eu/ogserver
rest: delete pxe files on client delete and update
call og_delete_tftpboot_file for both pxe configuration files in client/delete and client/update. Delete files for client/update only if the MAC changes.master v1.2.5-14
parent
8a23579cab
commit
075725b1fe
28
src/rest.c
28
src/rest.c
|
@ -1392,6 +1392,30 @@ static int og_remove_tftpboot_file(unsigned int boot_type, const char *mac)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int og_remove_tftpboot_files(struct og_dbi *dbi, const char *ip)
|
||||
{
|
||||
const char *msglog, *old_mac;
|
||||
dbi_result result;
|
||||
|
||||
result = dbi_conn_queryf(dbi->conn,
|
||||
"SELECT mac FROM ordenadores WHERE ip='%s'", ip);
|
||||
if (!result) {
|
||||
dbi_conn_error(dbi->conn, &msglog);
|
||||
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
|
||||
__func__, __LINE__, msglog);
|
||||
og_dbi_close(dbi);
|
||||
return -1;
|
||||
}
|
||||
if (dbi_result_next_row(result)) {
|
||||
old_mac = dbi_result_get_string(result, "mac");
|
||||
og_remove_tftpboot_file(OG_TFTP_BOOT_BIOS, old_mac);
|
||||
og_remove_tftpboot_file(OG_TFTP_BOOT_UEFI, old_mac);
|
||||
}
|
||||
|
||||
dbi_result_free(result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int og_create_boot_file(unsigned int boot_type, const char *mac,
|
||||
const char *mode, char *params)
|
||||
{
|
||||
|
@ -2293,6 +2317,8 @@ static int og_cmd_post_client_update(json_t *element,
|
|||
|
||||
dbi_result_free(result);
|
||||
|
||||
og_remove_tftpboot_files(dbi, computer.ip);
|
||||
|
||||
result = dbi_conn_queryf(dbi->conn,
|
||||
"UPDATE ordenadores"
|
||||
" SET numserie='%s',"
|
||||
|
@ -2960,6 +2986,8 @@ static int og_cmd_post_client_delete(json_t *element,
|
|||
}
|
||||
|
||||
for (i = 0; i < params->ips_array_len; i++) {
|
||||
og_remove_tftpboot_files(dbi, params->ips_array[i]);
|
||||
|
||||
result = dbi_conn_queryf(dbi->conn,
|
||||
"DELETE FROM ordenadores WHERE ip='%s'",
|
||||
params->ips_array[i]);
|
||||
|
|
Loading…
Reference in New Issue