diff options
Diffstat (limited to 'admin/Sources/Services')
29 files changed, 1468 insertions, 163 deletions
diff --git a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp index 1b806a91..9c6fc419 100644 --- a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp +++ b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp @@ -602,7 +602,7 @@ bool actualizaConfiguracion(Database db, Table tbl, char *cfg, int ido) lon += sprintf(tbPar + lon, "(%s, %s),", disk, par); - sprintf(sqlstr, "SELECT numdisk, numpar, codpar, tamano, uso, idsistemafichero, idnombreso" + sprintf(sqlstr, "SELECT numdisk, numpar, tamano, uso, idsistemafichero, idnombreso" " FROM ordenadores_particiones" " WHERE idordenador=%d AND numdisk=%s AND numpar=%s", ido, disk, par); @@ -627,32 +627,25 @@ bool actualizaConfiguracion(Database db, Table tbl, char *cfg, int ido) } } else { // Existe el registro swu = true; // Se supone que algún dato ha cambiado - if (!tbl.Get("codpar", dato)) { // Toma dato + if (!tbl.Get("tamano", dato)) { // Toma dato tbl.GetErrorErrStr(msglog); // Error al acceder al registro og_info(msglog); return false; } - if (strtol(cpt, NULL, 16) == dato) {// Parámetro tipo de partición (hexadecimal) igual al almacenado (decimal) - if (!tbl.Get("tamano", dato)) { // Toma dato + if (atoi(tam) == dato) { // Parámetro tamaño igual al almacenado + if (!tbl.Get("idsistemafichero", dato)) { // Toma dato tbl.GetErrorErrStr(msglog); // Error al acceder al registro og_info(msglog); return false; } - if (atoi(tam) == dato) {// Parámetro tamaño igual al almacenado - if (!tbl.Get("idsistemafichero", dato)) { // Toma dato + if (idsfi == dato) { // Parámetro sistema de fichero igual al almacenado + if (!tbl.Get("idnombreso", dato)) { // Toma dato tbl.GetErrorErrStr(msglog); // Error al acceder al registro og_info(msglog); return false; } - if (idsfi == dato) {// Parámetro sistema de fichero igual al almacenado - if (!tbl.Get("idnombreso", dato)) { // Toma dato - tbl.GetErrorErrStr(msglog); // Error al acceder al registro - og_info(msglog); - return false; - } - if (idsoi == dato) {// Parámetro sistema de fichero distinto al almacenado - swu = false; // Todos los parámetros de la partición son iguales, no se actualiza - } + if (idsoi == dato) { // Parámetro sistema operativo distinto al almacenado + swu = false; // Todos los parámetros de la partición son iguales, no se actualiza } } } @@ -670,9 +663,10 @@ bool actualizaConfiguracion(Database db, Table tbl, char *cfg, int ido) cpt, tam, uso, idsfi, idsoi, ido, disk, par); } else { // Actualizar porcentaje de uso. sprintf(sqlstr, "UPDATE ordenadores_particiones SET " + " codpar=0x%s," " uso=%s" " WHERE idordenador=%d AND numdisk=%s AND numpar=%s", - uso, ido, disk, par); + cpt, uso, ido, disk, par); } if (!db.Execute(sqlstr, tbl)) { db.GetErrorErrStr(msglog); @@ -1068,13 +1062,25 @@ static bool respuestaEstandar(TRAMA *ptrTrama, char *iph, char *ido, Database db struct tm* st; int idaccion; - ids = copiaParametro("ids",ptrTrama); // Toma identificador de la sesión + ids = copiaParametro("ids",ptrTrama); + res = copiaParametro("res",ptrTrama); - if (ids == NULL) // No existe seguimiento de la acción + if (ids == NULL) { + if (atoi(res) == ACCION_FALLIDA) { + liberaMemoria(res); + return false; + } + liberaMemoria(res); return true; + } - if (atoi(ids) == 0){ // No existe seguimiento de la acción + if (atoi(ids) == 0) { liberaMemoria(ids); + if (atoi(res) == ACCION_FALLIDA) { + liberaMemoria(res); + return false; + } + liberaMemoria(res); return true; } @@ -1103,7 +1109,6 @@ static bool respuestaEstandar(TRAMA *ptrTrama, char *iph, char *ido, Database db sprintf(fechafin, "%d/%d/%d %d:%d:%d", st->tm_year + 1900, st->tm_mon + 1, st->tm_mday, st->tm_hour, st->tm_min, st->tm_sec); - res = copiaParametro("res",ptrTrama); // Toma resultado der = copiaParametro("der",ptrTrama); // Toma descripción del error (si hubiera habido) sprintf(sqlstr, @@ -1121,10 +1126,10 @@ static bool respuestaEstandar(TRAMA *ptrTrama, char *iph, char *ido, Database db } liberaMemoria(der); - + if (atoi(res) == ACCION_FALLIDA) { liberaMemoria(res); - return false; // Error en la ejecución del comando + return false; } liberaMemoria(res); @@ -1439,27 +1444,6 @@ static bool RESPUESTA_Arrancar(TRAMA* ptrTrama, struct og_client *cli) return true; } // ________________________________________________________________________________________________________ -// Función: Apagar -// -// Descripción: -// Procesa el comando Apagar -// Parámetros: -// - socket_c: Socket de la consola al envió el mensaje -// - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros -// Devuelve: -// true: Si el proceso es correcto -// false: En caso de ocurrir algún error -// ________________________________________________________________________________________________________ -static bool Apagar(TRAMA* ptrTrama, struct og_client *cli) -{ - if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { - respuestaConsola(og_client_socket(cli), ptrTrama, false); - return false; - } - respuestaConsola(og_client_socket(cli), ptrTrama, true); - return true; -} -// ________________________________________________________________________________________________________ // Función: RESPUESTA_Apagar // // Descripción: @@ -1598,27 +1582,6 @@ static bool RESPUESTA_IniciarSesion(TRAMA* ptrTrama, struct og_client *cli) return true; } // ________________________________________________________________________________________________________ -// Función: CrearImagen -// -// Descripción: -// Crea una imagen de una partición de un disco y la guarda o bien en un repositorio -// Parámetros: -// - socket_c: Socket de la consola al envió el mensaje -// - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros -// Devuelve: -// true: Si el proceso es correcto -// false: En caso de ocurrir algún error -// ________________________________________________________________________________________________________ -static bool CrearImagen(TRAMA* ptrTrama, struct og_client *cli) -{ - if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { - respuestaConsola(og_client_socket(cli), ptrTrama, false); - return false; - } - respuestaConsola(og_client_socket(cli), ptrTrama, true); - return true; -} -// ________________________________________________________________________________________________________ // Función: RESPUESTA_CrearImagen // // Descripción: @@ -1902,27 +1865,6 @@ static bool RESPUESTA_CrearSoftIncremental(TRAMA* ptrTrama, struct og_client *cl return true; } // ________________________________________________________________________________________________________ -// Función: RestaurarImagen -// -// Descripción: -// Restaura una imagen en una partición -// Parámetros: -// - socket_c: Socket de la consola al envió el mensaje -// - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros -// Devuelve: -// true: Si el proceso es correcto -// false: En caso de ocurrir algún error -// ________________________________________________________________________________________________________ -static bool RestaurarImagen(TRAMA* ptrTrama, struct og_client *cli) -{ - if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { - respuestaConsola(og_client_socket(cli), ptrTrama, false); - return false; - } - respuestaConsola(og_client_socket(cli), ptrTrama, true); - return true; -} -// ________________________________________________________________________________________________________ // Función: RestaurarImagenBasica // // Descripción: @@ -2246,27 +2188,6 @@ static bool RESPUESTA_EjecutarScript(TRAMA* ptrTrama, struct og_client *cli) return true; } // ________________________________________________________________________________________________________ -// Función: InventarioHardware -// -// Descripción: -// Solicita al cliente un inventario de su hardware -// Parámetros: -// - socket_c: Socket de la consola al envió el mensaje -// - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros -// Devuelve: -// true: Si el proceso es correcto -// false: En caso de ocurrir algún error -// ________________________________________________________________________________________________________ -static bool InventarioHardware(TRAMA* ptrTrama, struct og_client *cli) -{ - if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { - respuestaConsola(og_client_socket(cli), ptrTrama, false); - return false; - } - respuestaConsola(og_client_socket(cli), ptrTrama, true); - return true; -} -// ________________________________________________________________________________________________________ // Función: RESPUESTA_InventarioHardware // // Descripción: @@ -2618,27 +2539,6 @@ bool cuestionPerfilHardware(Database db, Table tbl, char *idc, char *ido, return true; } // ________________________________________________________________________________________________________ -// Función: InventarioSoftware -// -// Descripción: -// Solicita al cliente un inventario de su software -// Parámetros: -// - socket_c: Socket de la consola al envió el mensaje -// - ptrTrama: Trama recibida por el servidor con el contenido y los parámetros -// Devuelve: -// true: Si el proceso es correcto -// false: En caso de ocurrir algún error -// ________________________________________________________________________________________________________ -static bool InventarioSoftware(TRAMA* ptrTrama, struct og_client *cli) -{ - if (!enviaComando(ptrTrama, CLIENTE_OCUPADO)) { - respuestaConsola(og_client_socket(cli), ptrTrama, false); - return false; - } - respuestaConsola(og_client_socket(cli), ptrTrama, true); - return true; -} -// ________________________________________________________________________________________________________ // Función: RESPUESTA_InventarioSoftware // // Descripción: @@ -3162,17 +3062,14 @@ static struct { { "ComandosPendientes", ComandosPendientes, }, { "DisponibilidadComandos", DisponibilidadComandos, }, { "RESPUESTA_Arrancar", RESPUESTA_Arrancar, }, - { "Apagar", Apagar, }, { "RESPUESTA_Apagar", RESPUESTA_Apagar, }, { "RESPUESTA_Reiniciar", RESPUESTA_Reiniciar, }, { "RESPUESTA_IniciarSesion", RESPUESTA_IniciarSesion, }, - { "CrearImagen", CrearImagen, }, { "RESPUESTA_CrearImagen", RESPUESTA_CrearImagen, }, { "CrearImagenBasica", CrearImagenBasica, }, { "RESPUESTA_CrearImagenBasica", RESPUESTA_CrearImagenBasica, }, { "CrearSoftIncremental", CrearSoftIncremental, }, { "RESPUESTA_CrearSoftIncremental", RESPUESTA_CrearSoftIncremental, }, - { "RestaurarImagen", RestaurarImagen, }, { "RESPUESTA_RestaurarImagen", RESPUESTA_RestaurarImagen }, { "RestaurarImagenBasica", RestaurarImagenBasica, }, { "RESPUESTA_RestaurarImagenBasica", RESPUESTA_RestaurarImagenBasica, }, @@ -3182,9 +3079,7 @@ static struct { { "RESPUESTA_Configurar", RESPUESTA_Configurar, }, { "EjecutarScript", EjecutarScript, }, { "RESPUESTA_EjecutarScript", RESPUESTA_EjecutarScript, }, - { "InventarioHardware", InventarioHardware, }, { "RESPUESTA_InventarioHardware", RESPUESTA_InventarioHardware, }, - { "InventarioSoftware", InventarioSoftware }, { "RESPUESTA_InventarioSoftware", RESPUESTA_InventarioSoftware, }, { "enviaArchivo", enviaArchivo, }, { "recibeArchivo", recibeArchivo, }, @@ -3350,6 +3245,30 @@ static int og_client_state_process_payload(struct og_client *cli) } #define OG_CLIENTS_MAX 4096 +#define OG_PARTITION_MAX 4 + +struct og_partition { + const char *number; + const char *code; + const char *size; + const char *filesystem; + const char *format; +}; + +struct og_sync_params { + const char *sync; + const char *diff; + const char *remove; + const char *compress; + const char *cleanup; + const char *cache; + const char *cleanup_cache; + const char *remove_dst; + const char *diff_id; + const char *diff_name; + const char *path; + const char *method; +}; struct og_msg_params { const char *ips_array[OG_CLIENTS_MAX]; @@ -3359,8 +3278,58 @@ struct og_msg_params { char run_cmd[4096]; const char *disk; const char *partition; + const char *repository; + const char *name; + const char *id; + const char *code; + const char *type; + const char *profile; + const char *cache; + const char *cache_size; + bool echo; + struct og_partition partition_setup[OG_PARTITION_MAX]; + struct og_sync_params sync_setup; + uint64_t flags; }; +#define OG_REST_PARAM_ADDR (1UL << 0) +#define OG_REST_PARAM_MAC (1UL << 1) +#define OG_REST_PARAM_WOL_TYPE (1UL << 2) +#define OG_REST_PARAM_RUN_CMD (1UL << 3) +#define OG_REST_PARAM_DISK (1UL << 4) +#define OG_REST_PARAM_PARTITION (1UL << 5) +#define OG_REST_PARAM_REPO (1UL << 6) +#define OG_REST_PARAM_NAME (1UL << 7) +#define OG_REST_PARAM_ID (1UL << 8) +#define OG_REST_PARAM_CODE (1UL << 9) +#define OG_REST_PARAM_TYPE (1UL << 10) +#define OG_REST_PARAM_PROFILE (1UL << 11) +#define OG_REST_PARAM_CACHE (1UL << 12) +#define OG_REST_PARAM_CACHE_SIZE (1UL << 13) +#define OG_REST_PARAM_PART_0 (1UL << 14) +#define OG_REST_PARAM_PART_1 (1UL << 15) +#define OG_REST_PARAM_PART_2 (1UL << 16) +#define OG_REST_PARAM_PART_3 (1UL << 17) +#define OG_REST_PARAM_SYNC_SYNC (1UL << 18) +#define OG_REST_PARAM_SYNC_DIFF (1UL << 19) +#define OG_REST_PARAM_SYNC_REMOVE (1UL << 20) +#define OG_REST_PARAM_SYNC_COMPRESS (1UL << 21) +#define OG_REST_PARAM_SYNC_CLEANUP (1UL << 22) +#define OG_REST_PARAM_SYNC_CACHE (1UL << 23) +#define OG_REST_PARAM_SYNC_CLEANUP_CACHE (1UL << 24) +#define OG_REST_PARAM_SYNC_REMOVE_DST (1UL << 25) +#define OG_REST_PARAM_SYNC_DIFF_ID (1UL << 26) +#define OG_REST_PARAM_SYNC_DIFF_NAME (1UL << 27) +#define OG_REST_PARAM_SYNC_PATH (1UL << 28) +#define OG_REST_PARAM_SYNC_METHOD (1UL << 29) +#define OG_REST_PARAM_ECHO (1UL << 30) + +static bool og_msg_params_validate(const struct og_msg_params *params, + const uint64_t flags) +{ + return (params->flags & flags) == flags; +} + static int og_json_parse_clients(json_t *element, struct og_msg_params *params) { unsigned int i; @@ -3376,6 +3345,153 @@ static int og_json_parse_clients(json_t *element, struct og_msg_params *params) params->ips_array[params->ips_array_len++] = json_string_value(k); + + params->flags |= OG_REST_PARAM_ADDR; + } + + return 0; +} + +static int og_json_parse_string(json_t *element, const char **str) +{ + if (json_typeof(element) != JSON_STRING) + return -1; + + *str = json_string_value(element); + return 0; +} + +static int og_json_parse_bool(json_t *element, bool *value) +{ + if (json_typeof(element) == JSON_TRUE) + *value = true; + else if (json_typeof(element) == JSON_FALSE) + *value = false; + else + return -1; + + return 0; +} + +static int og_json_parse_sync_params(json_t *element, + struct og_msg_params *params) +{ + const char *key; + json_t *value; + int err = 0; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "sync")) { + err = og_json_parse_string(value, ¶ms->sync_setup.sync); + params->flags |= OG_REST_PARAM_SYNC_SYNC; + } else if (!strcmp(key, "diff")) { + err = og_json_parse_string(value, ¶ms->sync_setup.diff); + params->flags |= OG_REST_PARAM_SYNC_DIFF; + } else if (!strcmp(key, "remove")) { + err = og_json_parse_string(value, ¶ms->sync_setup.remove); + params->flags |= OG_REST_PARAM_SYNC_REMOVE; + } else if (!strcmp(key, "compress")) { + err = og_json_parse_string(value, ¶ms->sync_setup.compress); + params->flags |= OG_REST_PARAM_SYNC_COMPRESS; + } else if (!strcmp(key, "cleanup")) { + err = og_json_parse_string(value, ¶ms->sync_setup.cleanup); + params->flags |= OG_REST_PARAM_SYNC_CLEANUP; + } else if (!strcmp(key, "cache")) { + err = og_json_parse_string(value, ¶ms->sync_setup.cache); + params->flags |= OG_REST_PARAM_SYNC_CACHE; + } else if (!strcmp(key, "cleanup_cache")) { + err = og_json_parse_string(value, ¶ms->sync_setup.cleanup_cache); + params->flags |= OG_REST_PARAM_SYNC_CLEANUP_CACHE; + } else if (!strcmp(key, "remove_dst")) { + err = og_json_parse_string(value, ¶ms->sync_setup.remove_dst); + params->flags |= OG_REST_PARAM_SYNC_REMOVE_DST; + } else if (!strcmp(key, "diff_id")) { + err = og_json_parse_string(value, ¶ms->sync_setup.diff_id); + params->flags |= OG_REST_PARAM_SYNC_DIFF_ID; + } else if (!strcmp(key, "diff_name")) { + err = og_json_parse_string(value, ¶ms->sync_setup.diff_name); + params->flags |= OG_REST_PARAM_SYNC_DIFF_NAME; + } else if (!strcmp(key, "path")) { + err = og_json_parse_string(value, ¶ms->sync_setup.path); + params->flags |= OG_REST_PARAM_SYNC_PATH; + } else if (!strcmp(key, "method")) { + err = og_json_parse_string(value, ¶ms->sync_setup.method); + params->flags |= OG_REST_PARAM_SYNC_METHOD; + } + + if (err != 0) + return err; + } + return err; +} + +#define OG_PARAM_PART_NUMBER (1UL << 0) +#define OG_PARAM_PART_CODE (1UL << 1) +#define OG_PARAM_PART_FILESYSTEM (1UL << 2) +#define OG_PARAM_PART_SIZE (1UL << 3) +#define OG_PARAM_PART_FORMAT (1UL << 4) + +static int og_json_parse_partition(json_t *element, + struct og_msg_params *params, + unsigned int i) +{ + struct og_partition *part = ¶ms->partition_setup[i]; + uint64_t flags = 0UL; + const char *key; + json_t *value; + int err = 0; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "partition")) { + err = og_json_parse_string(value, &part->number); + flags |= OG_PARAM_PART_NUMBER; + } else if (!strcmp(key, "code")) { + err = og_json_parse_string(value, &part->code); + flags |= OG_PARAM_PART_CODE; + } else if (!strcmp(key, "filesystem")) { + err = og_json_parse_string(value, &part->filesystem); + flags |= OG_PARAM_PART_FILESYSTEM; + } else if (!strcmp(key, "size")) { + err = og_json_parse_string(value, &part->size); + flags |= OG_PARAM_PART_SIZE; + } else if (!strcmp(key, "format")) { + err = og_json_parse_string(value, &part->format); + flags |= OG_PARAM_PART_FORMAT; + } + + if (err < 0) + return err; + } + + if (flags != (OG_PARAM_PART_NUMBER | + OG_PARAM_PART_CODE | + OG_PARAM_PART_FILESYSTEM | + OG_PARAM_PART_SIZE | + OG_PARAM_PART_FORMAT)) + return -1; + + params->flags |= (OG_REST_PARAM_PART_0 << i); + + return err; +} + +static int og_json_parse_partition_setup(json_t *element, + struct og_msg_params *params) +{ + unsigned int i; + json_t *k; + + if (json_typeof(element) != JSON_ARRAY) + return -1; + + for (i = 0; i < json_array_size(element) && i < OG_PARTITION_MAX; ++i) { + k = json_array_get(element, i); + + if (json_typeof(k) != JSON_OBJECT) + return -1; + + if (og_json_parse_partition(k, params, i) != 0) + return -1; } return 0; } @@ -3419,6 +3535,9 @@ static int og_cmd_post_clients(json_t *element, struct og_msg_params *params) break; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) + return -1; + return og_cmd_legacy_send(params, "Sondeo", CLIENTE_APAGADO); } @@ -3505,12 +3624,16 @@ static int og_json_parse_target(json_t *element, struct og_msg_params *params) params->ips_array[params->ips_array_len] = json_string_value(value); + + params->flags |= OG_REST_PARAM_ADDR; } else if (!strcmp(key, "mac")) { if (json_typeof(value) != JSON_STRING) return -1; params->mac_array[params->ips_array_len] = json_string_value(value); + + params->flags |= OG_REST_PARAM_MAC; } } @@ -3556,6 +3679,8 @@ static int og_json_parse_type(json_t *element, struct og_msg_params *params) else if (!strcmp(type, "broadcast")) params->wol_type = "1"; + params->flags |= OG_REST_PARAM_WOL_TYPE; + return 0; } @@ -3579,6 +3704,11 @@ static int og_cmd_wol(json_t *element, struct og_msg_params *params) break; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_MAC | + OG_REST_PARAM_WOL_TYPE)) + return -1; + if (!Levanta((char **)params->ips_array, (char **)params->mac_array, params->ips_array_len, (char *)params->wol_type)) return -1; @@ -3594,6 +3724,8 @@ static int og_json_parse_run(json_t *element, struct og_msg_params *params) snprintf(params->run_cmd, sizeof(params->run_cmd), "%s", json_string_value(element)); + params->flags |= OG_REST_PARAM_RUN_CMD; + return 0; } @@ -3612,19 +3744,36 @@ static int og_cmd_run_post(json_t *element, struct og_msg_params *params) json_object_foreach(element, key, value) { if (!strcmp(key, "clients")) err = og_json_parse_clients(value, params); - if (!strcmp(key, "run")) + else if (!strcmp(key, "run")) err = og_json_parse_run(value, params); + else if (!strcmp(key, "echo")) { + err = og_json_parse_bool(value, ¶ms->echo); + params->flags |= OG_REST_PARAM_ECHO; + } if (err < 0) break; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_RUN_CMD | + OG_REST_PARAM_ECHO)) + return -1; + for (i = 0; i < params->ips_array_len; i++) { len = snprintf(iph + strlen(iph), sizeof(iph), "%s;", params->ips_array[i]); } - len = snprintf(buf, sizeof(buf), "nfn=ConsolaRemota\riph=%s\rscp=%s\r", - iph, params->run_cmd); + + if (params->echo) { + len = snprintf(buf, sizeof(buf), + "nfn=ConsolaRemota\riph=%s\rscp=%s\r", + iph, params->run_cmd); + } else { + len = snprintf(buf, sizeof(buf), + "nfn=EjecutarScript\riph=%s\rscp=%s\r", + iph, params->run_cmd); + } msg = og_msg_alloc(buf, len); if (!msg) @@ -3673,6 +3822,9 @@ static int og_cmd_run_get(json_t *element, struct og_msg_params *params, return err; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) + return -1; + array = json_array(); if (!array) return -1; @@ -3731,27 +3883,6 @@ static int og_cmd_run_get(json_t *element, struct og_msg_params *params, return 0; } -static int og_json_parse_disk(json_t *element, struct og_msg_params *params) -{ - if (json_typeof(element) != JSON_STRING) - return -1; - - params->disk = json_string_value(element); - - return 0; -} - -static int og_json_parse_partition(json_t *element, - struct og_msg_params *params) -{ - if (json_typeof(element) != JSON_STRING) - return -1; - - params->partition = json_string_value(element); - - return 0; -} - static int og_cmd_session(json_t *element, struct og_msg_params *params) { char buf[4096], iph[4096]; @@ -3768,15 +3899,22 @@ static int og_cmd_session(json_t *element, struct og_msg_params *params) if (!strcmp(key, "clients")) { err = og_json_parse_clients(value, params); } else if (!strcmp(key, "disk")) { - err = og_json_parse_disk(value, params); + err = og_json_parse_string(value, ¶ms->disk); + params->flags |= OG_REST_PARAM_DISK; } else if (!strcmp(key, "partition")) { - err = og_json_parse_partition(value, params); + err = og_json_parse_string(value, ¶ms->partition); + params->flags |= OG_REST_PARAM_PARTITION; } if (err < 0) return err; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_DISK | + OG_REST_PARAM_PARTITION)) + return -1; + for (i = 0; i < params->ips_array_len; i++) { snprintf(iph + strlen(iph), sizeof(iph), "%s;", params->ips_array[i]); @@ -3815,6 +3953,9 @@ static int og_cmd_poweroff(json_t *element, struct og_msg_params *params) break; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) + return -1; + return og_cmd_legacy_send(params, "Apagar", CLIENTE_OCUPADO); } @@ -3835,6 +3976,9 @@ static int og_cmd_refresh(json_t *element, struct og_msg_params *params) break; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) + return -1; + return og_cmd_legacy_send(params, "Actualizar", CLIENTE_APAGADO); } @@ -3855,6 +3999,9 @@ static int og_cmd_reboot(json_t *element, struct og_msg_params *params) break; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) + return -1; + return og_cmd_legacy_send(params, "Reiniciar", CLIENTE_OCUPADO); } @@ -3875,6 +4022,9 @@ static int og_cmd_stop(json_t *element, struct og_msg_params *params) break; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) + return -1; + return og_cmd_legacy_send(params, "Purgar", CLIENTE_APAGADO); } @@ -3895,29 +4045,618 @@ static int og_cmd_hardware(json_t *element, struct og_msg_params *params) break; } + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) + return -1; + return og_cmd_legacy_send(params, "InventarioHardware", CLIENTE_OCUPADO); } static int og_cmd_software(json_t *element, struct og_msg_params *params) { + char buf[4096] = {}; + int err = 0, len; + const char *key; + json_t *value; + TRAMA *msg; + + if (json_typeof(element) != JSON_OBJECT) + return -1; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "clients")) + err = og_json_parse_clients(value, params); + else if (!strcmp(key, "disk")) { + err = og_json_parse_string(value, ¶ms->disk); + params->flags |= OG_REST_PARAM_DISK; + } + else if (!strcmp(key, "partition")) { + err = og_json_parse_string(value, ¶ms->partition); + params->flags |= OG_REST_PARAM_PARTITION; + } + + if (err < 0) + break; + } + + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_DISK | + OG_REST_PARAM_PARTITION)) + return -1; + + len = snprintf(buf, sizeof(buf), + "nfn=InventarioSoftware\rdsk=%s\rpar=%s\r", + params->disk, params->partition); + + msg = og_msg_alloc(buf, len); + if (!msg) + return -1; + + og_send_cmd((char **)params->ips_array, params->ips_array_len, + CLIENTE_OCUPADO, msg); + + og_msg_free(msg); + + return 0; +} + +static int og_cmd_create_image(json_t *element, struct og_msg_params *params) +{ + char buf[4096] = {}; + int err = 0, len; + const char *key; + json_t *value; + TRAMA *msg; + + if (json_typeof(element) != JSON_OBJECT) + return -1; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "disk")) { + err = og_json_parse_string(value, ¶ms->disk); + params->flags |= OG_REST_PARAM_DISK; + } else if (!strcmp(key, "partition")) { + err = og_json_parse_string(value, ¶ms->partition); + params->flags |= OG_REST_PARAM_PARTITION; + } else if (!strcmp(key, "name")) { + err = og_json_parse_string(value, ¶ms->name); + params->flags |= OG_REST_PARAM_NAME; + } else if (!strcmp(key, "repository")) { + err = og_json_parse_string(value, ¶ms->repository); + params->flags |= OG_REST_PARAM_REPO; + } else if (!strcmp(key, "clients")) { + err = og_json_parse_clients(value, params); + } else if (!strcmp(key, "id")) { + err = og_json_parse_string(value, ¶ms->id); + params->flags |= OG_REST_PARAM_ID; + } else if (!strcmp(key, "code")) { + err = og_json_parse_string(value, ¶ms->code); + params->flags |= OG_REST_PARAM_CODE; + } + + if (err < 0) + break; + } + + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_DISK | + OG_REST_PARAM_PARTITION | + OG_REST_PARAM_CODE | + OG_REST_PARAM_ID | + OG_REST_PARAM_NAME | + OG_REST_PARAM_REPO)) + return -1; + + len = snprintf(buf, sizeof(buf), + "nfn=CrearImagen\rdsk=%s\rpar=%s\rcpt=%s\ridi=%s\rnci=%s\ripr=%s\r", + params->disk, params->partition, params->code, + params->id, params->name, params->repository); + + msg = og_msg_alloc(buf, len); + if (!msg) + return -1; + + og_send_cmd((char **)params->ips_array, params->ips_array_len, + CLIENTE_OCUPADO, msg); + + og_msg_free(msg); + + return 0; +} + +static int og_cmd_restore_image(json_t *element, struct og_msg_params *params) +{ + char buf[4096] = {}; + int err = 0, len; + const char *key; + json_t *value; + TRAMA *msg; + + if (json_typeof(element) != JSON_OBJECT) + return -1; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "disk")) { + err = og_json_parse_string(value, ¶ms->disk); + params->flags |= OG_REST_PARAM_DISK; + } else if (!strcmp(key, "partition")) { + err = og_json_parse_string(value, ¶ms->partition); + params->flags |= OG_REST_PARAM_PARTITION; + } else if (!strcmp(key, "name")) { + err = og_json_parse_string(value, ¶ms->name); + params->flags |= OG_REST_PARAM_NAME; + } else if (!strcmp(key, "repository")) { + err = og_json_parse_string(value, ¶ms->repository); + params->flags |= OG_REST_PARAM_REPO; + } else if (!strcmp(key, "clients")) { + err = og_json_parse_clients(value, params); + } else if (!strcmp(key, "type")) { + err = og_json_parse_string(value, ¶ms->type); + params->flags |= OG_REST_PARAM_TYPE; + } else if (!strcmp(key, "profile")) { + err = og_json_parse_string(value, ¶ms->profile); + params->flags |= OG_REST_PARAM_PROFILE; + } else if (!strcmp(key, "id")) { + err = og_json_parse_string(value, ¶ms->id); + params->flags |= OG_REST_PARAM_ID; + } + + if (err < 0) + break; + } + + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_DISK | + OG_REST_PARAM_PARTITION | + OG_REST_PARAM_NAME | + OG_REST_PARAM_REPO | + OG_REST_PARAM_TYPE | + OG_REST_PARAM_PROFILE | + OG_REST_PARAM_ID)) + return -1; + + len = snprintf(buf, sizeof(buf), + "nfn=RestaurarImagen\ridi=%s\rdsk=%s\rpar=%s\rifs=%s\r" + "nci=%s\ripr=%s\rptc=%s\r", + params->id, params->disk, params->partition, + params->profile, params->name, + params->repository, params->type); + + msg = og_msg_alloc(buf, len); + if (!msg) + return -1; + + og_send_cmd((char **)params->ips_array, params->ips_array_len, + CLIENTE_OCUPADO, msg); + + og_msg_free(msg); + + return 0; +} + +static int og_cmd_setup(json_t *element, struct og_msg_params *params) +{ + char buf[4096] = {}; + int err = 0, len; + const char *key; + json_t *value; + TRAMA *msg; + + if (json_typeof(element) != JSON_OBJECT) + return -1; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "clients")) { + err = og_json_parse_clients(value, params); + } else if (!strcmp(key, "disk")) { + err = og_json_parse_string(value, ¶ms->disk); + params->flags |= OG_REST_PARAM_DISK; + } else if (!strcmp(key, "cache")) { + err = og_json_parse_string(value, ¶ms->cache); + params->flags |= OG_REST_PARAM_CACHE; + } else if (!strcmp(key, "cache_size")) { + err = og_json_parse_string(value, ¶ms->cache_size); + params->flags |= OG_REST_PARAM_CACHE_SIZE; + } else if (!strcmp(key, "partition_setup")) { + err = og_json_parse_partition_setup(value, params); + } + + if (err < 0) + break; + } + + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_DISK | + OG_REST_PARAM_CACHE | + OG_REST_PARAM_CACHE_SIZE | + OG_REST_PARAM_PART_0 | + OG_REST_PARAM_PART_1 | + OG_REST_PARAM_PART_2 | + OG_REST_PARAM_PART_3)) + return -1; + + len = snprintf(buf, sizeof(buf), + "nfn=Configurar\rdsk=%s\rcfg=dis=%s*che=%s*tch=%s!", + params->disk, params->disk, params->cache, params->cache_size); + + for (unsigned int i = 0; i < OG_PARTITION_MAX; ++i) { + const struct og_partition *part = ¶ms->partition_setup[i]; + + len += snprintf(buf + strlen(buf), sizeof(buf), + "par=%s*cpt=%s*sfi=%s*tam=%s*ope=%s%%", + part->number, part->code, part->filesystem, part->size, part->format); + } + + msg = og_msg_alloc(buf, len + 1); + if (!msg) + return -1; + + og_send_cmd((char **)params->ips_array, params->ips_array_len, + CLIENTE_OCUPADO, msg); + + og_msg_free(msg); + + return 0; +} + +static int og_cmd_run_schedule(json_t *element, struct og_msg_params *params) +{ const char *key; json_t *value; int err = 0; + json_object_foreach(element, key, value) { + if (!strcmp(key, "clients")) + err = og_json_parse_clients(value, params); + + if (err < 0) + break; + } + + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR)) + return -1; + + og_cmd_legacy_send(params, "EjecutaComandosPendientes", CLIENTE_OCUPADO); + + return 0; +} + +static int og_cmd_create_basic_image(json_t *element, struct og_msg_params *params) +{ + char buf[4096] = {}; + int err = 0, len; + const char *key; + json_t *value; + TRAMA *msg; + + if (json_typeof(element) != JSON_OBJECT) + return -1; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "clients")) { + err = og_json_parse_clients(value, params); + } else if (!strcmp(key, "disk")) { + err = og_json_parse_string(value, ¶ms->disk); + params->flags |= OG_REST_PARAM_DISK; + } else if (!strcmp(key, "partition")) { + err = og_json_parse_string(value, ¶ms->partition); + params->flags |= OG_REST_PARAM_PARTITION; + } else if (!strcmp(key, "code")) { + err = og_json_parse_string(value, ¶ms->code); + params->flags |= OG_REST_PARAM_CODE; + } else if (!strcmp(key, "id")) { + err = og_json_parse_string(value, ¶ms->id); + params->flags |= OG_REST_PARAM_ID; + } else if (!strcmp(key, "name")) { + err = og_json_parse_string(value, ¶ms->name); + params->flags |= OG_REST_PARAM_NAME; + } else if (!strcmp(key, "repository")) { + err = og_json_parse_string(value, ¶ms->repository); + params->flags |= OG_REST_PARAM_REPO; + } else if (!strcmp(key, "sync_params")) { + err = og_json_parse_sync_params(value, params); + } + + if (err < 0) + break; + } + + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_DISK | + OG_REST_PARAM_PARTITION | + OG_REST_PARAM_CODE | + OG_REST_PARAM_ID | + OG_REST_PARAM_NAME | + OG_REST_PARAM_REPO | + OG_REST_PARAM_SYNC_SYNC | + OG_REST_PARAM_SYNC_DIFF | + OG_REST_PARAM_SYNC_REMOVE | + OG_REST_PARAM_SYNC_COMPRESS | + OG_REST_PARAM_SYNC_CLEANUP | + OG_REST_PARAM_SYNC_CACHE | + OG_REST_PARAM_SYNC_CLEANUP_CACHE | + OG_REST_PARAM_SYNC_REMOVE_DST)) + return -1; + + len = snprintf(buf, sizeof(buf), + "nfn=CrearImagenBasica\rdsk=%s\rpar=%s\rcpt=%s\ridi=%s\r" + "nci=%s\ripr=%s\rrti=\rmsy=%s\rwhl=%s\reli=%s\rcmp=%s\rbpi=%s\r" + "cpc=%s\rbpc=%s\rnba=%s\r", + params->disk, params->partition, params->code, params->id, + params->name, params->repository, params->sync_setup.sync, + params->sync_setup.diff, params->sync_setup.remove, + params->sync_setup.compress, params->sync_setup.cleanup, + params->sync_setup.cache, params->sync_setup.cleanup_cache, + params->sync_setup.remove_dst); + + msg = og_msg_alloc(buf, len); + if (!msg) + return -1; + + og_send_cmd((char **)params->ips_array, params->ips_array_len, + CLIENTE_OCUPADO, msg); + + og_msg_free(msg); + + return 0; +} + +static int og_cmd_create_incremental_image(json_t *element, struct og_msg_params *params) +{ + char buf[4096] = {}; + int err = 0, len; + const char *key; + json_t *value; + TRAMA *msg; + if (json_typeof(element) != JSON_OBJECT) return -1; json_object_foreach(element, key, value) { if (!strcmp(key, "clients")) err = og_json_parse_clients(value, params); + else if (!strcmp(key, "disk")) { + err = og_json_parse_string(value, ¶ms->disk); + params->flags |= OG_REST_PARAM_DISK; + } else if (!strcmp(key, "partition")) { + err = og_json_parse_string(value, ¶ms->partition); + params->flags |= OG_REST_PARAM_PARTITION; + } else if (!strcmp(key, "id")) { + err = og_json_parse_string(value, ¶ms->id); + params->flags |= OG_REST_PARAM_ID; + } else if (!strcmp(key, "name")) { + err = og_json_parse_string(value, ¶ms->name); + params->flags |= OG_REST_PARAM_NAME; + } else if (!strcmp(key, "repository")) { + err = og_json_parse_string(value, ¶ms->repository); + params->flags |= OG_REST_PARAM_REPO; + } else if (!strcmp(key, "sync_params")) { + err = og_json_parse_sync_params(value, params); + } if (err < 0) break; } - return og_cmd_legacy_send(params, "InventarioSoftware", - CLIENTE_OCUPADO); + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_DISK | + OG_REST_PARAM_PARTITION | + OG_REST_PARAM_ID | + OG_REST_PARAM_NAME | + OG_REST_PARAM_REPO | + OG_REST_PARAM_SYNC_SYNC | + OG_REST_PARAM_SYNC_PATH | + OG_REST_PARAM_SYNC_DIFF | + OG_REST_PARAM_SYNC_DIFF_ID | + OG_REST_PARAM_SYNC_DIFF_NAME | + OG_REST_PARAM_SYNC_REMOVE | + OG_REST_PARAM_SYNC_COMPRESS | + OG_REST_PARAM_SYNC_CLEANUP | + OG_REST_PARAM_SYNC_CACHE | + OG_REST_PARAM_SYNC_CLEANUP_CACHE | + OG_REST_PARAM_SYNC_REMOVE_DST)) + return -1; + + len = snprintf(buf, sizeof(buf), + "nfn=CrearSoftIncremental\rdsk=%s\rpar=%s\ridi=%s\rnci=%s\r" + "rti=%s\ripr=%s\ridf=%s\rncf=%s\rmsy=%s\rwhl=%s\reli=%s\rcmp=%s\r" + "bpi=%s\rcpc=%s\rbpc=%s\rnba=%s\r", + params->disk, params->partition, params->id, params->name, + params->sync_setup.path, params->repository, params->sync_setup.diff_id, + params->sync_setup.diff_name, params->sync_setup.sync, + params->sync_setup.diff, params->sync_setup.remove_dst, + params->sync_setup.compress, params->sync_setup.cleanup, + params->sync_setup.cache, params->sync_setup.cleanup_cache, + params->sync_setup.remove_dst); + + msg = og_msg_alloc(buf, len); + if (!msg) + return -1; + + og_send_cmd((char **)params->ips_array, params->ips_array_len, + CLIENTE_OCUPADO, msg); + + og_msg_free(msg); + + return 0; +} + +static int og_cmd_restore_basic_image(json_t *element, struct og_msg_params *params) +{ + char buf[4096] = {}; + int err = 0, len; + const char *key; + json_t *value; + TRAMA *msg; + + if (json_typeof(element) != JSON_OBJECT) + return -1; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "clients")) { + err = og_json_parse_clients(value, params); + } else if (!strcmp(key, "disk")) { + err = og_json_parse_string(value, ¶ms->disk); + params->flags |= OG_REST_PARAM_DISK; + } else if (!strcmp(key, "partition")) { + err = og_json_parse_string(value, ¶ms->partition); + params->flags |= OG_REST_PARAM_PARTITION; + } else if (!strcmp(key, "id")) { + err = og_json_parse_string(value, ¶ms->id); + params->flags |= OG_REST_PARAM_ID; + } else if (!strcmp(key, "name")) { + err = og_json_parse_string(value, ¶ms->name); + params->flags |= OG_REST_PARAM_NAME; + } else if (!strcmp(key, "repository")) { + err = og_json_parse_string(value, ¶ms->repository); + params->flags |= OG_REST_PARAM_REPO; + } else if (!strcmp(key, "profile")) { + err = og_json_parse_string(value, ¶ms->profile); + params->flags |= OG_REST_PARAM_PROFILE; + } else if (!strcmp(key, "type")) { + err = og_json_parse_string(value, ¶ms->type); + params->flags |= OG_REST_PARAM_TYPE; + } else if (!strcmp(key, "sync_params")) { + err = og_json_parse_sync_params(value, params); + } + + if (err < 0) + break; + } + + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_DISK | + OG_REST_PARAM_PARTITION | + OG_REST_PARAM_ID | + OG_REST_PARAM_NAME | + OG_REST_PARAM_REPO | + OG_REST_PARAM_PROFILE | + OG_REST_PARAM_TYPE | + OG_REST_PARAM_SYNC_PATH | + OG_REST_PARAM_SYNC_METHOD | + OG_REST_PARAM_SYNC_SYNC | + OG_REST_PARAM_SYNC_DIFF | + OG_REST_PARAM_SYNC_REMOVE | + OG_REST_PARAM_SYNC_COMPRESS | + OG_REST_PARAM_SYNC_CLEANUP | + OG_REST_PARAM_SYNC_CACHE | + OG_REST_PARAM_SYNC_CLEANUP_CACHE | + OG_REST_PARAM_SYNC_REMOVE_DST)) + return -1; + + len = snprintf(buf, sizeof(buf), + "nfn=RestaurarImagenBasica\rdsk=%s\rpar=%s\ridi=%s\rnci=%s\r" + "ipr=%s\rifs=%s\rrti=%s\rmet=%s\rmsy=%s\rtpt=%s\rwhl=%s\r" + "eli=%s\rcmp=%s\rbpi=%s\rcpc=%s\rbpc=%s\rnba=%s\r", + params->disk, params->partition, params->id, params->name, + params->repository, params->profile, params->sync_setup.path, + params->sync_setup.method, params->sync_setup.sync, params->type, + params->sync_setup.diff, params->sync_setup.remove, + params->sync_setup.compress, params->sync_setup.cleanup, + params->sync_setup.cache, params->sync_setup.cleanup_cache, + params->sync_setup.remove_dst); + + msg = og_msg_alloc(buf, len); + if (!msg) + return -1; + + og_send_cmd((char **)params->ips_array, params->ips_array_len, + CLIENTE_OCUPADO, msg); + + og_msg_free(msg); + + return 0; +} + +static int og_cmd_restore_incremental_image(json_t *element, struct og_msg_params *params) +{ + char buf[4096] = {}; + int err = 0, len; + const char *key; + json_t *value; + TRAMA *msg; + + if (json_typeof(element) != JSON_OBJECT) + return -1; + + json_object_foreach(element, key, value) { + if (!strcmp(key, "clients")) { + err = og_json_parse_clients(value, params); + } else if (!strcmp(key, "disk")) { + err = og_json_parse_string(value, ¶ms->disk); + params->flags |= OG_REST_PARAM_DISK; + } else if (!strcmp(key, "partition")) { + err = og_json_parse_string(value, ¶ms->partition); + params->flags |= OG_REST_PARAM_PARTITION; + } else if (!strcmp(key, "id")) { + err = og_json_parse_string(value, ¶ms->id); + params->flags |= OG_REST_PARAM_ID; + } else if (!strcmp(key, "name")) { + err = og_json_parse_string(value, ¶ms->name); + params->flags |= OG_REST_PARAM_NAME; + } else if (!strcmp(key, "repository")) { + err = og_json_parse_string(value, ¶ms->repository); + params->flags |= OG_REST_PARAM_REPO; + } else if (!strcmp(key, "profile")) { + err = og_json_parse_string(value, ¶ms->profile); + params->flags |= OG_REST_PARAM_PROFILE; + } else if (!strcmp(key, "type")) { + err = og_json_parse_string(value, ¶ms->type); + params->flags |= OG_REST_PARAM_TYPE; + } else if (!strcmp(key, "sync_params")) { + err = og_json_parse_sync_params(value, params); + } + + if (err < 0) + break; + } + + if (!og_msg_params_validate(params, OG_REST_PARAM_ADDR | + OG_REST_PARAM_DISK | + OG_REST_PARAM_PARTITION | + OG_REST_PARAM_ID | + OG_REST_PARAM_NAME | + OG_REST_PARAM_REPO | + OG_REST_PARAM_PROFILE | + OG_REST_PARAM_TYPE | + OG_REST_PARAM_SYNC_DIFF_ID | + OG_REST_PARAM_SYNC_DIFF_NAME | + OG_REST_PARAM_SYNC_PATH | + OG_REST_PARAM_SYNC_METHOD | + OG_REST_PARAM_SYNC_SYNC | + OG_REST_PARAM_SYNC_DIFF | + OG_REST_PARAM_SYNC_REMOVE | + OG_REST_PARAM_SYNC_COMPRESS | + OG_REST_PARAM_SYNC_CLEANUP | + OG_REST_PARAM_SYNC_CACHE | + OG_REST_PARAM_SYNC_CLEANUP_CACHE | + OG_REST_PARAM_SYNC_REMOVE_DST)) + return -1; + + len = snprintf(buf, sizeof(buf), + "nfn=RestaurarSoftIncremental\rdsk=%s\rpar=%s\ridi=%s\rnci=%s\r" + "ipr=%s\rifs=%s\ridf=%s\rncf=%s\rrti=%s\rmet=%s\rmsy=%s\r" + "tpt=%s\rwhl=%s\reli=%s\rcmp=%s\rbpi=%s\rcpc=%s\rbpc=%s\r" + "nba=%s\r", + params->disk, params->partition, params->id, params->name, + params->repository, params->profile, params->sync_setup.diff_id, + params->sync_setup.diff_name, params->sync_setup.path, + params->sync_setup.method, params->sync_setup.sync, params->type, + params->sync_setup.diff, params->sync_setup.remove, + params->sync_setup.compress, params->sync_setup.cleanup, + params->sync_setup.cache, params->sync_setup.cleanup_cache, + params->sync_setup.remove_dst); + + msg = og_msg_alloc(buf, len); + if (!msg) + return -1; + + og_send_cmd((char **)params->ips_array, params->ips_array_len, + CLIENTE_OCUPADO, msg); + + og_msg_free(msg); + + return 0; } static int og_client_method_not_found(struct og_client *cli) @@ -4142,6 +4881,83 @@ static int og_client_state_process_payload_rest(struct og_client *cli) return og_client_bad_request(cli); } err = og_cmd_software(root, ¶ms); + } else if (!strncmp(cmd, "image/create/basic", + strlen("image/create/basic"))) { + if (method != OG_METHOD_POST) + return og_client_method_not_found(cli); + + if (!root) { + syslog(LOG_ERR, "command create with no payload\n"); + return og_client_bad_request(cli); + } + err = og_cmd_create_basic_image(root, ¶ms); + } else if (!strncmp(cmd, "image/create/incremental", + strlen("image/create/incremental"))) { + if (method != OG_METHOD_POST) + return og_client_method_not_found(cli); + + if (!root) { + syslog(LOG_ERR, "command create with no payload\n"); + return og_client_bad_request(cli); + } + err = og_cmd_create_incremental_image(root, ¶ms); + } else if (!strncmp(cmd, "image/create", strlen("image/create"))) { + if (method != OG_METHOD_POST) + return og_client_method_not_found(cli); + + if (!root) { + syslog(LOG_ERR, "command create with no payload\n"); + return og_client_bad_request(cli); + } + err = og_cmd_create_image(root, ¶ms); + } else if (!strncmp(cmd, "image/restore/basic", + strlen("image/restore/basic"))) { + if (method != OG_METHOD_POST) + return og_client_method_not_found(cli); + + if (!root) { + syslog(LOG_ERR, "command create with no payload\n"); + return og_client_bad_request(cli); + } + err = og_cmd_restore_basic_image(root, ¶ms); + } else if (!strncmp(cmd, "image/restore/incremental", + strlen("image/restore/incremental"))) { + if (method != OG_METHOD_POST) + return og_client_method_not_found(cli); + + if (!root) { + syslog(LOG_ERR, "command create with no payload\n"); + return og_client_bad_request(cli); + } + err = og_cmd_restore_incremental_image(root, ¶ms); + } else if (!strncmp(cmd, "image/restore", strlen("image/restore"))) { + if (method != OG_METHOD_POST) + return og_client_method_not_found(cli); + + if (!root) { + syslog(LOG_ERR, "command create with no payload\n"); + return og_client_bad_request(cli); + } + err = og_cmd_restore_image(root, ¶ms); + } else if (!strncmp(cmd, "setup", strlen("setup"))) { + if (method != OG_METHOD_POST) + return og_client_method_not_found(cli); + + if (!root) { + syslog(LOG_ERR, "command create with no payload\n"); + return og_client_bad_request(cli); + } + err = og_cmd_setup(root, ¶ms); + } else if (!strncmp(cmd, "run/schedule", strlen("run/schedule"))) { + if (method != OG_METHOD_POST) + return og_client_method_not_found(cli); + + if (!root) { + syslog(LOG_ERR, "command create with no payload\n"); + return og_client_bad_request(cli); + } + + err = og_cmd_run_schedule(root, ¶ms); } else { syslog(LOG_ERR, "unknown command: %.32s ...\n", cmd); err = og_client_not_found(cli); @@ -4151,7 +4967,7 @@ static int og_client_state_process_payload_rest(struct og_client *cli) json_decref(root); if (err < 0) - return err; + return og_client_bad_request(cli); err = og_client_ok(cli, buf_reply); if (err < 0) { diff --git a/admin/Sources/Services/ogAdmServer/tests/create_basic_image.json b/admin/Sources/Services/ogAdmServer/tests/create_basic_image.json new file mode 100644 index 00000000..8000219a --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/create_basic_image.json @@ -0,0 +1 @@ +{"clients":["192.168.56.11"],"disk":"1","partition":"1","code":"131","id":"8","name":"debianbasica","repository":"192.168.56.10","sync_params":{"sync":"1","diff":"0","remove":"1","compress":"0","cleanup":"0","cache":"0","cleanup_cache":"0","remove_dst":"0"}} diff --git a/admin/Sources/Services/ogAdmServer/tests/create_image.json b/admin/Sources/Services/ogAdmServer/tests/create_image.json new file mode 100644 index 00000000..bd4ab215 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/create_image.json @@ -0,0 +1 @@ +{ "clients" : [ "192.168.2.1" ], "disk" : "1", "partition" : "1", "code" : "1", "id" : "1", "name" : "test", "repository" : "192.168.2.4" } diff --git a/admin/Sources/Services/ogAdmServer/tests/create_incremental_image.json b/admin/Sources/Services/ogAdmServer/tests/create_incremental_image.json new file mode 100644 index 00000000..94b3a4d0 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/create_incremental_image.json @@ -0,0 +1 @@ +{"clients":["192.168.56.11"], "disk":"1", "partition":"1", "id":"3", "name":"basica1", "repository":"192.168.56.10", "sync_params":{"sync":"1", "path":"", "diff":"0", "diff_id":"4", "diff_name":"p2", "remove":"1", "compress":"0", "cleanup":"0", "cache":"0", "cleanup_cache":"0", "remove_dst":"0"}} diff --git a/admin/Sources/Services/ogAdmServer/tests/restore_basic_image.json b/admin/Sources/Services/ogAdmServer/tests/restore_basic_image.json new file mode 100644 index 00000000..255507c0 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/restore_basic_image.json @@ -0,0 +1 @@ +{"clients":["192.168.56.11"],"disk":"1","partition":"1","id":"9","name":"test","repository":"192.168.56.10","profile":"17","type":"UNICAST","sync_params":{"path":"","method":"1","sync":"1","diff":"0","remove":"1","compress":"0","cleanup":"0","cache":"0","cleanup_cache":"0","remove_dst":"0"}} diff --git a/admin/Sources/Services/ogAdmServer/tests/restore_image.json b/admin/Sources/Services/ogAdmServer/tests/restore_image.json new file mode 100644 index 00000000..bf2982ab --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/restore_image.json @@ -0,0 +1 @@ +{ "clients" : [ "192.168.56.11" ], "disk" : "1", "partition" : "1", "name" : "test", "repository" : "192.168.56.10", "type" : "UNICAST", "profile": "1", "id": "1"} diff --git a/admin/Sources/Services/ogAdmServer/tests/restore_incremental_image.json b/admin/Sources/Services/ogAdmServer/tests/restore_incremental_image.json new file mode 100644 index 00000000..66dfd0a2 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/restore_incremental_image.json @@ -0,0 +1 @@ +{"clients":["192.168.56.11"],"disk":"1","partition":"1","id":"9","name":"test","repository":"192.168.56.10","profile":"17","type":"UNICAST","sync_params":{"diff_id":"1","diff_name":"test","path":"","method":"1","sync":"1","diff":"0","remove":"1","compress":"0","cleanup":"0","cache":"0","cleanup_cache":"0","remove_dst":"0"}} diff --git a/admin/Sources/Services/ogAdmServer/tests/run-tests.sh b/admin/Sources/Services/ogAdmServer/tests/run-tests.sh index f22df02a..893e0264 100755 --- a/admin/Sources/Services/ogAdmServer/tests/run-tests.sh +++ b/admin/Sources/Services/ogAdmServer/tests/run-tests.sh @@ -12,3 +12,11 @@ curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/stop -d @stop.js curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/refresh -d @refresh.json curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/hardware -d @post_clients.json curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/software -d @post_clients.json +curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/create -d @create_image.json +curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/restore -d @restore_image.json +curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/setup -d @setup_image.json +curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/create/basic -d @create_basic_image.json +curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/create/incremental -d @create_incremental_image.json +curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/restore/basic -d @restore_basic_image.json +curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/image/restore/incremental -d @restore_incremental_image.json +curl -X POST -H "Authorization: $API_KEY" http://127.0.0.1:8888/run/schedule -d @run_schedule.json diff --git a/admin/Sources/Services/ogAdmServer/tests/run_schedule.json b/admin/Sources/Services/ogAdmServer/tests/run_schedule.json new file mode 100644 index 00000000..60a10349 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/run_schedule.json @@ -0,0 +1 @@ +{"clients":["192.168.56.11"]} diff --git a/admin/Sources/Services/ogAdmServer/tests/setup_image.json b/admin/Sources/Services/ogAdmServer/tests/setup_image.json new file mode 100644 index 00000000..0135e207 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/setup_image.json @@ -0,0 +1 @@ +{ "clients" : [ "192.168.56.11" ], "disk" : "1", "cache" : "1", "cache_size" : "0", "partition_setup": [{"partition": "1", "code": "LINUX", "filesystem": "EMPTY", "size": "498688", "format": "0"}, {"partition": "2", "code": "LINUX-SWAP", "filesystem": "EMPTY", "size": "199987", "format": "0"}, {"partition": "3", "code": "LINUX", "filesystem": "EMPTY", "size": "31053824", "format": "0"}, {"partition": "4", "code": "EMPTY", "filesystem": "EMPTY", "size": "0", "format": "0"}]} diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0002_post_clients.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0002_post_clients.py index 1aae349e..3e0d4e5d 100644 --- a/admin/Sources/Services/ogAdmServer/tests/units/test_0002_post_clients.py +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0002_post_clients.py @@ -12,5 +12,13 @@ class TestPostClientsMethods(unittest.TestCase): returned = requests.post(self.url, headers=self.headers, json=self.json) self.assertEqual(returned.status_code, 200) + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + returned = requests.post(self.url, headers=self.headers, json={}) + self.assertEqual(returned.status_code, 400) + if __name__ == '__main__': unittest.main() diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0003_post_wol.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0003_post_wol.py index e997aff6..5c8c012a 100644 --- a/admin/Sources/Services/ogAdmServer/tests/units/test_0003_post_wol.py +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0003_post_wol.py @@ -13,6 +13,19 @@ class TestPostWolMethods(unittest.TestCase): returned = requests.post(self.url, headers=self.headers, json=self.json) self.assertEqual(returned.status_code, 200) + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + for parameter in self.json: + malformed_payload = self.json.copy() + malformed_payload.pop(parameter) + returned = requests.post(self.url, + headers=self.headers, + json=malformed_payload) + self.assertEqual(returned.status_code, 400) + def test_get(self): returned = requests.get(self.url, headers=self.headers) self.assertEqual(returned.status_code, 405) diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0004_post_shell_run.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0004_post_shell_run.py index 2a330be9..11779da4 100644 --- a/admin/Sources/Services/ogAdmServer/tests/units/test_0004_post_shell_run.py +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0004_post_shell_run.py @@ -6,12 +6,27 @@ class TestPostShellRunMethods(unittest.TestCase): def setUp(self): self.url = 'http://localhost:8888/shell/run' self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} - self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], 'run' : 'ls' } + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], + 'run' : 'ls', + 'echo': True} def test_post(self): returned = requests.post(self.url, headers=self.headers, json=self.json) self.assertEqual(returned.status_code, 200) + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + for parameter in self.json: + malformed_payload = self.json.copy() + malformed_payload.pop(parameter) + returned = requests.post(self.url, + headers=self.headers, + json=malformed_payload) + self.assertEqual(returned.status_code, 400) + def test_get(self): returned = requests.get(self.url, headers=self.headers) self.assertEqual(returned.status_code, 405) diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0005_post_shell_output.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0005_post_shell_output.py index 1c6f7a3a..dec9ccd0 100644 --- a/admin/Sources/Services/ogAdmServer/tests/units/test_0005_post_shell_output.py +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0005_post_shell_output.py @@ -12,6 +12,14 @@ class TestPostShellOutputMethods(unittest.TestCase): returned = requests.post(self.url, headers=self.headers, json=self.json) self.assertEqual(returned.status_code, 200) + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + returned = requests.post(self.url, headers=self.headers, json={}) + self.assertEqual(returned.status_code, 400) + def test_get(self): returned = requests.get(self.url, headers=self.headers) self.assertEqual(returned.status_code, 405) diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0006_post_session.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0006_post_session.py index 544ae2ab..ba6179f2 100644 --- a/admin/Sources/Services/ogAdmServer/tests/units/test_0006_post_session.py +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0006_post_session.py @@ -13,6 +13,19 @@ class TestPostSessionMethods(unittest.TestCase): returned = requests.post(self.url, headers=self.headers, json=self.json) self.assertEqual(returned.status_code, 200) + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + for parameter in self.json: + malformed_payload = self.json.copy() + malformed_payload.pop(parameter) + returned = requests.post(self.url, + headers=self.headers, + json=malformed_payload) + self.assertEqual(returned.status_code, 400) + def test_get(self): returned = requests.get(self.url, headers=self.headers) self.assertEqual(returned.status_code, 405) diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0007_post_poweroff.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0007_post_poweroff.py index d2d5b15d..3c262656 100644 --- a/admin/Sources/Services/ogAdmServer/tests/units/test_0007_post_poweroff.py +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0007_post_poweroff.py @@ -12,6 +12,14 @@ class TestPostPoweroffMethods(unittest.TestCase): returned = requests.post(self.url, headers=self.headers, json=self.json) self.assertEqual(returned.status_code, 200) + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + returned = requests.post(self.url, headers=self.headers, json={}) + self.assertEqual(returned.status_code, 400) + def test_get(self): returned = requests.get(self.url, headers=self.headers) self.assertEqual(returned.status_code, 405) diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0008_post_reboot.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0008_post_reboot.py index 5ac4dc24..6705e87f 100644 --- a/admin/Sources/Services/ogAdmServer/tests/units/test_0008_post_reboot.py +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0008_post_reboot.py @@ -12,6 +12,14 @@ class TestPostRebootMethods(unittest.TestCase): returned = requests.post(self.url, headers=self.headers, json=self.json) self.assertEqual(returned.status_code, 200) + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + returned = requests.post(self.url, headers=self.headers, json={}) + self.assertEqual(returned.status_code, 400) + def test_get(self): returned = requests.get(self.url, headers=self.headers) self.assertEqual(returned.status_code, 405) diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0009_post_stop.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0009_post_stop.py index 7aa96ff8..68b1b7c6 100644 --- a/admin/Sources/Services/ogAdmServer/tests/units/test_0009_post_stop.py +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0009_post_stop.py @@ -12,6 +12,14 @@ class TestPostStopMethods(unittest.TestCase): returned = requests.post(self.url, headers=self.headers, json=self.json) self.assertEqual(returned.status_code, 200) + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + returned = requests.post(self.url, headers=self.headers, json={}) + self.assertEqual(returned.status_code, 400) + def test_get(self): returned = requests.get(self.url, headers=self.headers) self.assertEqual(returned.status_code, 405) diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0010_post_refresh.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0010_post_refresh.py index 745bdbe5..0df3c60f 100644 --- a/admin/Sources/Services/ogAdmServer/tests/units/test_0010_post_refresh.py +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0010_post_refresh.py @@ -12,6 +12,14 @@ class TestPostRefreshMethods(unittest.TestCase): returned = requests.post(self.url, headers=self.headers, json=self.json) self.assertEqual(returned.status_code, 200) + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + returned = requests.post(self.url, headers=self.headers, json={}) + self.assertEqual(returned.status_code, 400) + def test_get(self): returned = requests.get(self.url, headers=self.headers) self.assertEqual(returned.status_code, 405) diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0011_post_hardware.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0011_post_hardware.py index 6d9c16a9..1f3e1604 100644 --- a/admin/Sources/Services/ogAdmServer/tests/units/test_0011_post_hardware.py +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0011_post_hardware.py @@ -12,6 +12,14 @@ class TestPostHardwareMethods(unittest.TestCase): returned = requests.post(self.url, headers=self.headers, json=self.json) self.assertEqual(returned.status_code, 200) + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + returned = requests.post(self.url, headers=self.headers, json={}) + self.assertEqual(returned.status_code, 400) + def test_get(self): returned = requests.get(self.url, headers=self.headers) self.assertEqual(returned.status_code, 405) diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0012_post_software.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0012_post_software.py index 049a3ec8..3a00d467 100644 --- a/admin/Sources/Services/ogAdmServer/tests/units/test_0012_post_software.py +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0012_post_software.py @@ -6,12 +6,27 @@ class TestPostSoftwareMethods(unittest.TestCase): def setUp(self): self.url = 'http://localhost:8888/software' self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} - self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ] } + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], + 'disk' : '0', + 'partition' : '1' } def test_post(self): returned = requests.post(self.url, headers=self.headers, json=self.json) self.assertEqual(returned.status_code, 200) + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + for parameter in self.json: + malformed_payload = self.json.copy() + malformed_payload.pop(parameter) + returned = requests.post(self.url, + headers=self.headers, + json=malformed_payload) + self.assertEqual(returned.status_code, 400) + def test_get(self): returned = requests.get(self.url, headers=self.headers) self.assertEqual(returned.status_code, 405) diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0016_post_image_create.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0016_post_image_create.py new file mode 100644 index 00000000..fb6eb975 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0016_post_image_create.py @@ -0,0 +1,39 @@ +import requests +import unittest + +class TestPostCreateImageMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/image/create' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], + 'disk' : '1', + 'partition' : '1', + 'code' : '1', + 'id' : '1', + 'name' : 'test', + 'repository' : '192.168.2.4' } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + for parameter in self.json: + malformed_payload = self.json.copy() + malformed_payload.pop(parameter) + returned = requests.post(self.url, + headers=self.headers, + json=malformed_payload) + self.assertEqual(returned.status_code, 400) + + def test_get(self): + returned = requests.get(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 405) + +if __name__ == '__main__': + unittest.main() diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0017_post_image_restore.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0017_post_image_restore.py new file mode 100644 index 00000000..1bdeacb5 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0017_post_image_restore.py @@ -0,0 +1,40 @@ +import requests +import unittest + +class TestPostRestoreImageMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/image/restore' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], + 'disk' : '1', + 'partition' : '1', + 'name' : 'test', + 'repository' : '192.168.56.10', + 'type' : 'UNICAST', + 'profile': '1', + 'id': '1' } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + for parameter in self.json: + malformed_payload = self.json.copy() + malformed_payload.pop(parameter) + returned = requests.post(self.url, + headers=self.headers, + json=malformed_payload) + self.assertEqual(returned.status_code, 400) + + def test_get(self): + returned = requests.get(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 405) + +if __name__ == '__main__': + unittest.main() diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0018_post_setup.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0018_post_setup.py new file mode 100644 index 00000000..16fc1d4e --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0018_post_setup.py @@ -0,0 +1,56 @@ +import requests +import unittest + +class TestPostSetupMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/setup' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], + 'disk' : '1', + 'cache' : '1', + 'cache_size' : '0', + 'partition_setup': [{'partition': '1', + 'code': 'LINUX', + 'filesystem': 'EMPTY', + 'size': '498688', + 'format': '0'}, + {'partition': '2', + 'code': 'LINUX-SWAP', + 'filesystem': 'EMPTY', + 'size': '199987', + 'format': '0'}, + {'partition': '3', + 'code': 'LINUX', + 'filesystem': 'EMPTY', + 'size': '31053824', + 'format': '0'}, + {'partition': '4', + 'code': 'EMPTY', + 'filesystem': 'EMPTY', + 'size': '0', + 'format': '0'}] } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + for parameter in self.json: + malformed_payload = self.json.copy() + malformed_payload.pop(parameter) + returned = requests.post(self.url, + headers=self.headers, + json=malformed_payload) + self.assertEqual(returned.status_code, 400) + + def test_get(self): + returned = requests.get(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 405) + +if __name__ == '__main__': + unittest.main() diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0019_post_image_create_basic.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0019_post_image_create_basic.py new file mode 100644 index 00000000..9d05b99d --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0019_post_image_create_basic.py @@ -0,0 +1,47 @@ +import requests +import unittest + +class TestPostCreateBasicImageMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/image/create/basic' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], + 'disk': '1', + 'partition': '1', + 'code': '131', + 'id': '8', + 'name': 'debianbasica', + 'repository': '192.168.56.10', + 'sync_params':{'sync': '1', + 'diff': '0', + 'remove': '1', + 'compress': '0', + 'cleanup': '0', + 'cache': '0', + 'cleanup_cache': '0', + 'remove_dst': '0'} } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + for parameter in self.json: + malformed_payload = self.json.copy() + malformed_payload.pop(parameter) + returned = requests.post(self.url, + headers=self.headers, + json=malformed_payload) + self.assertEqual(returned.status_code, 400) + + def test_get(self): + returned = requests.get(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 405) + +if __name__ == '__main__': + unittest.main() diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0020_post_image_create_incremental.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0020_post_image_create_incremental.py new file mode 100644 index 00000000..c677e270 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0020_post_image_create_incremental.py @@ -0,0 +1,49 @@ +import requests +import unittest + +class TestPostCreateIncrementalImageMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/image/create/incremental' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], + 'disk': '1', + 'partition': '1', + 'id': '3', + 'name': 'basica1', + 'repository': '192.168.56.10', + 'sync_params':{'sync': '1', + 'path': '', + 'diff': '0', + 'diff_id': '4', + 'diff_name': 'p2', + 'remove': '1', + 'compress': '0', + 'cleanup': '0', + 'cache': '0', + 'cleanup_cache': '0', + 'remove_dst': '0'} } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + for parameter in self.json: + malformed_payload = self.json.copy() + malformed_payload.pop(parameter) + returned = requests.post(self.url, + headers=self.headers, + json=malformed_payload) + self.assertEqual(returned.status_code, 400) + + def test_get(self): + returned = requests.get(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 405) + +if __name__ == '__main__': + unittest.main() diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0021_post_image_restore_basic.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0021_post_image_restore_basic.py new file mode 100644 index 00000000..efe8a61c --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0021_post_image_restore_basic.py @@ -0,0 +1,50 @@ +import requests +import unittest + +class TestPostRestoreBasicImageMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/image/restore/basic' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], + 'disk': '1', + 'partition': '1', + 'id': '9', + 'name': 'test', + 'repository': '192.168.56.10', + 'profile': '17', + 'type': 'UNICAST', + 'sync_params':{'path': '', + 'method': '1', + 'sync': '1', + 'diff': '0', + 'remove': '1', + 'compress': '0', + 'cleanup': '0', + 'cache': '0', + 'cleanup_cache': '0', + 'remove_dst': '0'} } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + for parameter in self.json: + malformed_payload = self.json.copy() + malformed_payload.pop(parameter) + returned = requests.post(self.url, + headers=self.headers, + json=malformed_payload) + self.assertEqual(returned.status_code, 400) + + def test_get(self): + returned = requests.get(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 405) + +if __name__ == '__main__': + unittest.main() diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0022_post_image_restore_incremental.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0022_post_image_restore_incremental.py new file mode 100644 index 00000000..ad7727f1 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0022_post_image_restore_incremental.py @@ -0,0 +1,52 @@ +import requests +import unittest + +class TestPostRestoreIncrementalImageMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/image/restore/incremental' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], + 'disk': '1', + 'partition': '1', + 'id': '9', + 'name': 'test', + 'repository': '192.168.56.10', + 'profile': '17', + 'type': 'UNICAST', + 'sync_params':{'diff_id': '1', + 'diff_name': 'test', + 'path': '', + 'method': '1', + 'sync': '1', + 'diff': '0', + 'remove': '1', + 'compress': '0', + 'cleanup': '0', + 'cache': '0', + 'cleanup_cache': '0', + 'remove_dst': '0'} } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + for parameter in self.json: + malformed_payload = self.json.copy() + malformed_payload.pop(parameter) + returned = requests.post(self.url, + headers=self.headers, + json=malformed_payload) + self.assertEqual(returned.status_code, 400) + + def test_get(self): + returned = requests.get(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 405) + +if __name__ == '__main__': + unittest.main() diff --git a/admin/Sources/Services/ogAdmServer/tests/units/test_0023_post_run_schedule.py b/admin/Sources/Services/ogAdmServer/tests/units/test_0023_post_run_schedule.py new file mode 100644 index 00000000..3b923049 --- /dev/null +++ b/admin/Sources/Services/ogAdmServer/tests/units/test_0023_post_run_schedule.py @@ -0,0 +1,28 @@ +import requests +import unittest + +class TestPostRunScheduleMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/run/schedule' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ] } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_no_payload(self): + returned = requests.post(self.url, headers=self.headers, json=None) + self.assertEqual(returned.status_code, 400) + + def test_malformed_payload(self): + returned = requests.post(self.url, headers=self.headers, json={}) + self.assertEqual(returned.status_code, 400) + + def test_get(self): + returned = requests.get(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 405) + +if __name__ == '__main__': + unittest.main() |