summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-08-28 12:45:46 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-08-28 15:28:47 +0200
commitcd9650108af1eb882ca11858249dc428087667ff (patch)
tree40496a1e3c277feafd9fe2997a633c19acf52f5b /src/rest.c
parent9ee9d66b7c7c8e1c4e5b70ccaf5dae74b31a91f9 (diff)
src: infer server IP when it has more than one IP address
infer server IP for a given client. User does not have to attach a client to a given server IP anymore through ordenadores.identorno. this simplifies previous work to allow a server to have more than one IP address a0a347068285 ('#1074 rest: set_mode: add support for different ogserver addresses') 44745a3f2287 ('rest: add POST client/server method') POST /client/server is removed, it is only used by ogcli and explicit association between server and client is not required. server_id json attribute is also removed in GET client/info.
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c123
1 files changed, 9 insertions, 114 deletions
diff --git a/src/rest.c b/src/rest.c
index f714e0f..9c5cbb5 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -1508,7 +1508,6 @@ struct og_boot_mode_params {
const char *dns;
const char *proxy;
const char *ip;
- const char *ipserveradm;
const char *nombreaula;
const char *oglivedir;
const char *hardprofile;
@@ -1527,6 +1526,7 @@ static int og_get_client_mode_params(struct og_dbi *dbi, const char *mac, char *
{
char repository_ip[OG_DB_IP_MAXLEN + 1] = {};
struct og_boot_mode_params boot_params = {};
+ char server_ip[OG_DB_IP_MAXLEN + 1] = {};
const char *res_prefix = " vga=";
const char *res_value = "788";
char *lang = getenv("LANG");
@@ -1537,7 +1537,6 @@ static int og_get_client_mode_params(struct og_dbi *dbi, const char *mac, char *
result = dbi_conn_queryf(dbi->conn,
"SELECT "
"ordenadores.ip AS ip, "
- "entornos.ipserveradm AS ipserveradm, "
"aulas.router AS router, "
"aulas.netmask AS netmask, "
"ordenadores.nombreordenador AS nombreordenador, "
@@ -1557,7 +1556,6 @@ static int og_get_client_mode_params(struct og_dbi *dbi, const char *mac, char *
"JOIN aulas USING(idaula) "
"JOIN centros USING(idcentro) "
"JOIN entidades USING(identidad) "
- "JOIN entornos USING(identorno) "
"LEFT JOIN repositorios USING(idrepositorio) "
"LEFT JOIN perfileshard USING(idperfilhard) "
"LEFT JOIN menus USING(idmenu) "
@@ -1581,7 +1579,6 @@ static int og_get_client_mode_params(struct og_dbi *dbi, const char *mac, char *
}
boot_params.ip = dbi_result_get_string_copy(result, "ip");
- boot_params.ipserveradm = dbi_result_get_string_copy(result, "ipserveradm");
boot_params.router = dbi_result_get_string_copy(result, "router");
boot_params.netmask = dbi_result_get_string_copy(result, "netmask");
boot_params.nombreordenador = dbi_result_get_string_copy(result, "nombreordenador");
@@ -1606,6 +1603,11 @@ static int og_get_client_mode_params(struct og_dbi *dbi, const char *mac, char *
dbi_result_free(result);
+ if (og_dbi_get_server_ip(dbi, boot_params.ip, server_ip) < 0) {
+ err = -1;
+ goto err_out;
+ }
+
if (og_dbi_get_repository_ip(dbi, boot_params.repoid, boot_params.ip,
repository_ip) < 0) {
err = -1;
@@ -1616,13 +1618,13 @@ static int og_get_client_mode_params(struct og_dbi *dbi, const char *mac, char *
" LANG=%s ip=%s:%s:%s:%s:%s:%s:none group=%s ogrepo=%s oglive=%s oglog=%s ogshare=%s oglivedir=%s ogprof=%s server=%s"
"%s%s%s%s%s%s%s%s%s%s%s%s",
lang,
- boot_params.ip, boot_params.ipserveradm, boot_params.router, boot_params.netmask, boot_params.nombreordenador, boot_params.netiface,
+ boot_params.ip, server_ip, boot_params.router, boot_params.netmask, boot_params.nombreordenador, boot_params.netiface,
boot_params.nombreaula,
repository_ip,
- boot_params.ipserveradm, boot_params.ipserveradm, boot_params.ipserveradm,
+ server_ip, server_ip, server_ip,
boot_params.oglivedir,
boot_params.is_prof ? "true" : "false",
- boot_params.ipserveradm,
+ server_ip,
boot_params.hardprofile[0] ? " hardprofile=" : "", boot_params.hardprofile[0] ? boot_params.hardprofile: "",
boot_params.ntp[0] ? " ogntp=" : "", boot_params.ntp[0] ? boot_params.ntp : "",
boot_params.dns[0] ? " ogdns=" : "", boot_params.dns[0] ? boot_params.dns : "",
@@ -1631,7 +1633,6 @@ static int og_get_client_mode_params(struct og_dbi *dbi, const char *mac, char *
res_prefix, res_value);
err_out:
free((void *)boot_params.ip);
- free((void *)boot_params.ipserveradm);
free((void *)boot_params.router);
free((void *)boot_params.netmask);
free((void *)boot_params.nombreordenador);
@@ -1895,29 +1896,6 @@ static int og_cmd_get_client_setup(json_t *element,
return 0;
}
-static int og_dbi_update_client_entorno(struct og_dbi *dbi,
- const char *mac,
- const char *server_id)
-{
- const char *msglog;
- dbi_result result;
-
- result = dbi_conn_queryf(dbi->conn,
- "UPDATE ordenadores SET identorno=%s "
- "WHERE mac='%s'",
- server_id, mac);
-
- if (!result) {
- dbi_conn_error(dbi->conn, &msglog);
- syslog(LOG_ERR, "failed to update client's server (%s:%d) %s\n",
- __func__, __LINE__, msglog);
- return -1;
- }
-
- dbi_result_free(result);
- return 0;
-}
-
static int og_dbi_update_client_repo(struct og_dbi *dbi,
const char *mac,
const char *repo_id)
@@ -2009,74 +1987,6 @@ static int og_cmd_post_client_repo(json_t *element,
return 0;
}
-static int og_cmd_post_client_server(json_t *element,
- struct og_msg_params *params,
- char *buffer_reply)
-{
- char ips_str[(OG_DB_IP_MAXLEN + 1) * OG_CLIENTS_MAX + 1] = {};
- const char *key, *msglog, *mac;
- int ips_str_len = 0;
- struct og_dbi *dbi;
- dbi_result result;
- int err = 0, i;
- json_t *value;
-
- json_object_foreach(element, key, value) {
- if (!strcmp(key, "clients")) {
- err = og_json_parse_clients(value, params);
- } else if (!strcmp(key, "id")) {
- err = og_json_parse_string(value, &params->id);
- params->flags |= OG_REST_PARAM_ID;
- }
-
- if (err < 0)
- return err;
- }
-
- if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR |
- OG_REST_PARAM_ID))
- return -1;
-
- dbi = og_dbi_open(&ogconfig.db);
- if (!dbi) {
- syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
- __func__, __LINE__);
- return -1;
- }
-
- for (i = 0; i < params->ips_array_len; ++i) {
- ips_str_len += snprintf(ips_str + ips_str_len,
- sizeof(ips_str) - ips_str_len,
- "'%s',", params->ips_array[i]);
- }
- ips_str[ips_str_len - 1] = '\0';
-
- result = dbi_conn_queryf(dbi->conn,
- "SELECT mac FROM ordenadores "
- "WHERE ip IN (%s)", ips_str);
- 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;
- }
-
- while (dbi_result_next_row(result)) {
- mac = dbi_result_get_string(result, "mac");
- err = og_dbi_update_client_entorno(dbi, mac, params->id);
- if (err != 0) {
- dbi_result_free(result);
- og_dbi_close(dbi);
- return -1;
- }
- }
-
- dbi_result_free(result);
- og_dbi_close(dbi);
- return 0;
-}
-
static int og_cmd_get_center_info(json_t *element,
struct og_msg_params *params,
char *buffer_reply)
@@ -2190,7 +2100,6 @@ static int og_cmd_get_client_info(json_t *element,
json_string(computer.serial_number));
json_object_set_new(root, "hardware_id",
json_integer(computer.hardware_id));
- json_object_set_new(root, "server_id", json_integer(computer.server_id));
json_object_set_new(root, "netdriver", json_string(computer.netdriver));
json_object_set_new(root, "maintenance", json_boolean(computer.maintenance));
json_object_set_new(root, "netiface", json_string(computer.netiface));
@@ -8561,20 +8470,6 @@ int og_client_state_process_payload_rest(struct og_client *cli)
}
err = og_cmd_get_client_setup(root, &params, buf_reply);
- } else if (!strncmp(cmd, "client/server", strlen("client/server"))) {
- switch (method) {
- case OG_METHOD_POST:
- if (!root) {
- syslog(LOG_ERR, "client post server command with no payload\n");
- err = og_client_bad_request(cli);
- goto err_process_rest_payload;
- }
- err = og_cmd_post_client_server(root, &params, buf_reply);
- break;
- default:
- err = og_client_method_not_found(cli);
- goto err_process_rest_payload;
- }
} else if (!strncmp(cmd, "client/info",
strlen("client/info"))) {
if (method != OG_METHOD_GET) {