mirror of https://git.48k.eu/ogserver
#988 remove legacy configuration
Use og_server_cfg everywhere. Convert port to string to make it easy for the dbi API since it expects a string. Remove legacy example configuration file.master
parent
3cea4bb763
commit
fe1ce97c50
|
@ -1,8 +0,0 @@
|
|||
ServidorAdm=SERVERIP
|
||||
PUERTO=2008
|
||||
USUARIO=DBUSER
|
||||
PASSWORD=DBPASSWORD
|
||||
datasource=localhost
|
||||
CATALOG=DATABASE
|
||||
INTERFACE=eth0
|
||||
APITOKEN=REPOKEY
|
|
@ -5,8 +5,8 @@
|
|||
"api_token": "5a5ca1172136299640a9f47469237e0a"
|
||||
},
|
||||
"database" : {
|
||||
"ip": "127.0.0.1",
|
||||
"port": 3306,
|
||||
"ip" : "127.0.0.1",
|
||||
"port" : "3306",
|
||||
"name" : "opengnsys",
|
||||
"user" : "mysql",
|
||||
"pass" : "mysql"
|
||||
|
|
16
src/cfg.c
16
src/cfg.c
|
@ -58,8 +58,7 @@ static int parse_json_db(struct og_server_cfg *cfg, json_t *element)
|
|||
if (og_json_parse_string(value, &cfg->db.name) < 0)
|
||||
return -1;
|
||||
} else if (!strcmp(key, "port")) {
|
||||
if (og_json_parse_uint(value, &cfg->db.port) < 0 ||
|
||||
cfg->db.port > UINT16_MAX)
|
||||
if (og_json_parse_string(value, &cfg->db.port) < 0)
|
||||
return -1;
|
||||
} else {
|
||||
syslog(LOG_ERR, "unknown key `%s' in db\n", key);
|
||||
|
@ -188,16 +187,3 @@ int parse_json_config(const char *filename, struct og_server_cfg *cfg)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void from_json_to_legacy(struct og_server_cfg *cfg)
|
||||
{
|
||||
snprintf(servidoradm, sizeof(servidoradm), "%s", cfg->rest.ip);
|
||||
snprintf(puerto, sizeof(puerto), "%s", cfg->rest.port);
|
||||
snprintf(usuario, sizeof(usuario), "%s", cfg->db.user);
|
||||
snprintf(pasguor, sizeof(pasguor), "%s", cfg->db.pass);
|
||||
snprintf(datasource, sizeof(datasource), "%s", cfg->db.ip);
|
||||
snprintf(catalog, sizeof(catalog), "%s", cfg->db.name);
|
||||
snprintf(interface, sizeof(interface), "%s", cfg->wol.interface);
|
||||
snprintf(auth_token, sizeof(auth_token), "%s", cfg->rest.api_token);
|
||||
snprintf(db_port, sizeof(db_port), "%u", cfg->db.port);
|
||||
}
|
||||
|
|
12
src/cfg.h
12
src/cfg.h
|
@ -1,14 +1,11 @@
|
|||
#ifndef _OG_SERVER_CFG_H
|
||||
#define _OG_SERVER_CFG_H
|
||||
|
||||
#include <jansson.h>
|
||||
#include "dbi.h"
|
||||
|
||||
struct og_server_cfg {
|
||||
struct {
|
||||
const char *user;
|
||||
const char *pass;
|
||||
const char *ip;
|
||||
unsigned int port;
|
||||
const char *name;
|
||||
} db;
|
||||
struct og_dbi_config db;
|
||||
struct {
|
||||
const char *ip;
|
||||
const char *port;
|
||||
|
@ -24,7 +21,6 @@ struct og_server_cfg {
|
|||
};
|
||||
|
||||
int parse_json_config(const char *filename, struct og_server_cfg *cfg);
|
||||
void from_json_to_legacy(struct og_server_cfg *cfg);
|
||||
|
||||
extern struct og_server_cfg ogconfig;
|
||||
|
||||
|
|
13
src/client.c
13
src/client.c
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
#include "ogAdmServer.h"
|
||||
#include "cfg.h"
|
||||
#include "dbi.h"
|
||||
#include "utils.h"
|
||||
#include "list.h"
|
||||
|
@ -129,7 +130,7 @@ static int og_resp_hardware(json_t *data, struct og_client *cli)
|
|||
return -1;
|
||||
}
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -197,7 +198,7 @@ static int og_resp_software(json_t *data, struct og_client *cli)
|
|||
return -1;
|
||||
}
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -265,7 +266,7 @@ static int og_dbi_queue_autorun(uint32_t computer_id, uint32_t proc_id)
|
|||
};
|
||||
struct og_dbi *dbi;
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database "
|
||||
"(%s:%d)\n", __func__, __LINE__);
|
||||
|
@ -343,7 +344,7 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
|
|||
partitions[i].used_size);
|
||||
}
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -460,7 +461,7 @@ static int og_resp_image_create(json_t *data, struct og_client *cli)
|
|||
return -1;
|
||||
}
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -560,7 +561,7 @@ static int og_resp_image_restore(json_t *data, struct og_client *cli)
|
|||
return -1;
|
||||
}
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
|
|
@ -30,11 +30,11 @@ struct og_dbi *og_dbi_open(struct og_dbi_config *config)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
dbi_conn_set_option(dbi->conn, "host", config->host);
|
||||
dbi_conn_set_option(dbi->conn, "host", config->ip);
|
||||
dbi_conn_set_option(dbi->conn, "port", config->port);
|
||||
dbi_conn_set_option(dbi->conn, "username", config->user);
|
||||
dbi_conn_set_option(dbi->conn, "password", config->passwd);
|
||||
dbi_conn_set_option(dbi->conn, "dbname", config->database);
|
||||
dbi_conn_set_option(dbi->conn, "password", config->pass);
|
||||
dbi_conn_set_option(dbi->conn, "dbname", config->name);
|
||||
dbi_conn_set_option(dbi->conn, "encoding", "UTF-8");
|
||||
|
||||
if (dbi_conn_connect(dbi->conn) < 0) {
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
struct og_dbi_config {
|
||||
const char *user;
|
||||
const char *passwd;
|
||||
const char *host;
|
||||
const char *pass;
|
||||
const char *ip;
|
||||
const char *port;
|
||||
const char *database;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
struct og_dbi {
|
||||
|
@ -54,8 +54,6 @@ struct og_legacy_partition {
|
|||
char format[2]; /* Format is a boolean 0 or 1 => length is 2 */
|
||||
};
|
||||
|
||||
extern struct og_dbi_config dbi_config;
|
||||
|
||||
struct og_computer {
|
||||
unsigned int procedure_id;
|
||||
unsigned int hardware_id;
|
||||
|
|
|
@ -69,8 +69,6 @@ int main(int argc, char *argv[])
|
|||
if (parse_json_config(config_file, &ogconfig) < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
from_json_to_legacy(&ogconfig);
|
||||
|
||||
socket_rest = og_socket_server_init(ogconfig.rest.port);
|
||||
if (socket_rest < 0) {
|
||||
syslog(LOG_ERR, "Cannot open REST API server socket\n");
|
||||
|
|
|
@ -23,26 +23,6 @@
|
|||
#include <jansson.h>
|
||||
#include <time.h>
|
||||
|
||||
char usuario[4096]; // Usuario de acceso a la base de datos
|
||||
char pasguor[4096]; // Password del usuario
|
||||
char datasource[4096]; // Dirección IP del gestor de base de datos
|
||||
char catalog[4096]; // Nombre de la base de datos
|
||||
char interface[4096]; // Interface name
|
||||
char auth_token[4096]; // API token
|
||||
char servidoradm[4096]; // Dirección IP del servidor de administración
|
||||
char puerto[4096]; // Puerto de comunicación
|
||||
char db_port[4096];
|
||||
|
||||
struct og_dbi_config dbi_config = {
|
||||
.user = usuario,
|
||||
.passwd = pasguor,
|
||||
.host = datasource,
|
||||
.port = db_port,
|
||||
.database = catalog,
|
||||
};
|
||||
|
||||
#define OG_CMD_MAXLEN 64
|
||||
|
||||
// ________________________________________________________________________________________________________
|
||||
// Función: actualizaConfiguracion
|
||||
//
|
||||
|
|
|
@ -20,18 +20,6 @@
|
|||
#include <stdbool.h>
|
||||
#include "ogAdmLib.h"
|
||||
|
||||
extern char auth_token[4096];
|
||||
extern char usuario[4096];
|
||||
extern char pasguor[4096];
|
||||
extern char catalog[4096];
|
||||
extern char datasource[4096];
|
||||
extern char interface[4096];
|
||||
extern char api_token[4096];
|
||||
extern char servidoradm[4096];
|
||||
extern char puerto[4096];
|
||||
extern char db_port[4096];
|
||||
|
||||
struct og_client;
|
||||
struct og_dbi;
|
||||
|
||||
bool actualizaConfiguracion(struct og_dbi *,char* ,int);
|
||||
|
|
32
src/rest.c
32
src/rest.c
|
@ -985,7 +985,7 @@ static int og_cmd_post_modes(json_t *element, struct og_msg_params *params)
|
|||
}
|
||||
ips_str[ips_str_len - 1] = '\0';
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -1066,7 +1066,7 @@ static int og_cmd_get_client_setup(json_t *element,
|
|||
}
|
||||
json_object_set_new(root, "partitions", partitions_array);
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
json_decref(root);
|
||||
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
|
||||
|
@ -1177,7 +1177,7 @@ static int og_cmd_get_client_info(json_t *element,
|
|||
if (inet_aton(params->ips_array[0], &addr) == 0)
|
||||
return -1;
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -1283,7 +1283,7 @@ static int og_cmd_post_client_add(json_t *element,
|
|||
break;
|
||||
}
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -1434,7 +1434,7 @@ static int og_cmd_get_hardware(json_t *element, struct og_msg_params *params,
|
|||
return -1;
|
||||
}
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -1638,7 +1638,7 @@ static int og_cmd_images(char *buffer_reply)
|
|||
|
||||
json_object_set_new(root, "images", images);
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -2556,7 +2556,7 @@ int og_dbi_update_action(uint32_t id, bool success)
|
|||
if (!id)
|
||||
return 0;
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -2598,7 +2598,7 @@ void og_schedule_run(unsigned int task_id, unsigned int schedule_id,
|
|||
struct og_dbi *dbi;
|
||||
unsigned int i;
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -2673,7 +2673,7 @@ static int og_cmd_task_post(json_t *element, struct og_msg_params *params)
|
|||
if (!og_msg_params_validate(params, OG_REST_PARAM_TASK))
|
||||
return -1;
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -2863,7 +2863,7 @@ static int og_cmd_scope_get(json_t *element, struct og_msg_params *params,
|
|||
}
|
||||
json_object_set_new(root, "scope", array);
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -2893,7 +2893,7 @@ int og_dbi_schedule_get(void)
|
|||
const char *msglog;
|
||||
dbi_result result;
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -3156,7 +3156,7 @@ static int og_task_schedule_create(struct og_msg_params *params)
|
|||
else
|
||||
return -1;
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -3257,7 +3257,7 @@ static int og_cmd_schedule_update(json_t *element, struct og_msg_params *params)
|
|||
OG_REST_PARAM_TIME_AM_PM))
|
||||
return -1;
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -3302,7 +3302,7 @@ static int og_cmd_schedule_delete(json_t *element, struct og_msg_params *params)
|
|||
if (!og_msg_params_validate(params, OG_REST_PARAM_ID))
|
||||
return -1;
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -3348,7 +3348,7 @@ static int og_cmd_schedule_get(json_t *element, struct og_msg_params *params,
|
|||
}
|
||||
}
|
||||
|
||||
dbi = og_dbi_open(&dbi_config);
|
||||
dbi = og_dbi_open(&ogconfig.db);
|
||||
if (!dbi) {
|
||||
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||
__func__, __LINE__);
|
||||
|
@ -3468,7 +3468,7 @@ int og_client_state_process_payload_rest(struct og_client *cli)
|
|||
|
||||
body = strstr(cli->buf, "\r\n\r\n") + 4;
|
||||
|
||||
if (strcmp(cli->auth_token, auth_token)) {
|
||||
if (strcmp(cli->auth_token, ogconfig.rest.api_token)) {
|
||||
syslog(LOG_ERR, "wrong Authentication key\n");
|
||||
return og_client_not_authorized(cli);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#include "wol.h"
|
||||
#include "cfg.h"
|
||||
#include "ogAdmServer.h"
|
||||
|
||||
int wol_socket_open(void)
|
||||
|
@ -73,7 +74,7 @@ bool wake_up_broadcast(int sd, struct sockaddr_in *client,
|
|||
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
if (ifa->ifa_addr == NULL ||
|
||||
ifa->ifa_addr->sa_family != AF_INET ||
|
||||
strcmp(ifa->ifa_name, interface) != 0)
|
||||
strcmp(ifa->ifa_name, ogconfig.wol.interface) != 0)
|
||||
continue;
|
||||
|
||||
broadcast_addr =
|
||||
|
|
Loading…
Reference in New Issue