summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-05-31 12:08:57 +0200
committerJose M. Guisado <jguisado@soleta.eu>2022-06-01 08:51:19 +0200
commita0a3470682852d5f72967553d5debe41e86eca78 (patch)
tree7b3155246a1c5ffee6ed4f5dd442cc6196a4a260 /src/rest.c
parentc0573b9ef05bc1c22a6b5b71c2f73ba18a8696f1 (diff)
#1074 rest: set_mode: add support for different ogserver addresses
Add foreign key "identornos" from table "entornos" to table "ordenadores". A row in table "entornos" represent a valid ogServer address. Multiple ogServer valid addresses can exist when running several instances or a single ogServer instance is exposed to different networks. Can't delete rows in "entornos" table nor update their id (primary key) if the row has any associated clients ({ON UPDATE/ON DELETE} RESTRICT). Allows assigning different but valid ogServer IPs to clients. Enabling support for multiple instances of ogServer (e.g: load balancing) or exposing a single ogServer instance to different networks (e.g: VLAN). Look up for the valid ogServer IP of a given client when changing a client's mode (og_set_client_mode). Determines valid ogServer IP using a JOIN statement. JOIN entornos USING(identorno) Reuses the fetched ip using a statement variable. @serverip:=entornos.ipserveradm For example, for a two VLAN setup: vlan1 ogserver: 192.168.56.10 vlan2 ogserver: 192.168.57.10 The "entornos" table should look like: identorno ipserveradm ... --------- ----------- ... 1 192.168.56.10 ... 2 192.168.57.10 ... And computers in the "ordenadores" table might look like: idordenador identorno ... ---------- --------- ... 1 1 ... 2 1 ... 3 2 ... 4 2 ... ... ... ... Additionally, splits the SQL query for better readability. Co-authored-by: Jose Guisado <jguisado@soleta.eu>
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/rest.c b/src/rest.c
index 5f6d3ec..f0953b2 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -1082,7 +1082,35 @@ static int og_set_client_mode(struct og_dbi *dbi, const char *mac,
int fd;
result = dbi_conn_queryf(dbi->conn,
- "SELECT ' LANG=%s', ' ip=', CONCAT_WS(':', ordenadores.ip, (SELECT (@serverip:=ipserveradm) FROM entornos LIMIT 1), aulas.router, aulas.netmask, ordenadores.nombreordenador, ordenadores.netiface, 'none'), ' group=', REPLACE(TRIM(aulas.nombreaula), ' ', '_'), ' ogrepo=', (@repoip:=IFNULL(repositorios.ip, '')), ' oglive=', @serverip, ' oglog=', @serverip, ' ogshare=', @serverip, ' oglivedir=', ordenadores.oglivedir, ' ogprof=', IF(ordenadores.idordenador=aulas.idordprofesor, 'true', 'false'), IF(perfileshard.descripcion<>'', CONCAT(' hardprofile=', REPLACE(TRIM(perfileshard.descripcion), ' ', '_')), ''), IF(aulas.ntp<>'', CONCAT(' ogntp=', aulas.ntp), ''), IF(aulas.dns<>'', CONCAT(' ogdns=', aulas.dns), ''), IF(aulas.proxy<>'', CONCAT(' ogproxy=', aulas.proxy), ''), IF(entidades.ogunit=1 AND NOT centros.directorio='', CONCAT(' ogunit=', centros.directorio), ''), CASE WHEN menus.resolucion IS NULL THEN '' WHEN menus.resolucion <= '999' THEN CONCAT(' vga=', menus.resolucion) WHEN menus.resolucion LIKE '%:%' THEN CONCAT(' video=', menus.resolucion) ELSE menus.resolucion END FROM ordenadores JOIN aulas USING(idaula) JOIN centros USING(idcentro) JOIN entidades USING(identidad) LEFT JOIN repositorios USING(idrepositorio) LEFT JOIN perfileshard USING(idperfilhard) LEFT JOIN menus USING(idmenu) WHERE ordenadores.mac='%s'", getenv("LANG"), mac);
+ "SELECT ' LANG=%s', "
+ "' ip=', CONCAT_WS(':', ordenadores.ip, (@serverip:=entornos.ipserveradm), aulas.router, aulas.netmask, ordenadores.nombreordenador, ordenadores.netiface, 'none'), "
+ "' group=', REPLACE(TRIM(aulas.nombreaula), ' ', '_'), "
+ "' ogrepo=', (@repoip:=IFNULL(repositorios.ip, '')), "
+ "' oglive=', @serverip, "
+ "' oglog=', @serverip, "
+ "' ogshare=', @serverip, "
+ "' oglivedir=', ordenadores.oglivedir, "
+ "' ogprof=', IF(ordenadores.idordenador=aulas.idordprofesor, 'true', 'false'), "
+ "IF(perfileshard.descripcion<>'', CONCAT(' hardprofile=', REPLACE(TRIM(perfileshard.descripcion), ' ', '_')), ''), "
+ "IF(aulas.ntp<>'', CONCAT(' ogntp=', aulas.ntp), ''), "
+ "IF(aulas.dns<>'', CONCAT(' ogdns=', aulas.dns), ''), "
+ "IF(aulas.proxy<>'', CONCAT(' ogproxy=', aulas.proxy), ''), "
+ "IF(entidades.ogunit=1 AND NOT centros.directorio='', CONCAT(' ogunit=', centros.directorio), ''), "
+ "CASE WHEN menus.resolucion IS NULL THEN '' "
+ "WHEN menus.resolucion <= '999' THEN CONCAT(' vga=', menus.resolucion) "
+ "WHEN menus.resolucion LIKE '%:%' THEN CONCAT(' video=', menus.resolucion) "
+ "ELSE menus.resolucion END "
+
+ "FROM ordenadores "
+ "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) "
+
+ "WHERE ordenadores.mac='%s'", getenv("LANG"), mac);
if (dbi_result_get_numrows(result) != 1) {
dbi_conn_error(dbi->conn, &msglog);