From 7ccbf0a7acac3a8729aa260c026396255df499e9 Mon Sep 17 00:00:00 2001 From: Robert Richter Date: Mon, 15 Jun 2020 22:31:01 +0200 Subject: [PATCH] update Mo 15. Jun 22:31:01 CEST 2020 --- server/api.js | 4 ++-- server/routing.js | 4 +++- server/saver.js | 15 ++++++++++----- server/waip.js | 32 +++++++++++--------------------- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/server/api.js b/server/api.js index d83861e..3d1f0fc 100755 --- a/server/api.js +++ b/server/api.js @@ -50,7 +50,7 @@ module.exports = function (io, sql, app_cfg, saver) { var app_id = raw_data.app_id; // nur speichern wenn app_id nicht eigenen globalen app_id entspricht if (app_id != app_cfg.global.app_id) { - waip.rmld_speichern(data, remote_ip, function (result) { + saver.save_new_rmld(data, remote_ip, app_id, function (result) { if (!result) { sql.db_log('API', 'Fehler beim speichern der Rückmeldung von ' + remote_ip + ': ' + data); }; @@ -143,7 +143,7 @@ module.exports = function (io, sql, app_cfg, saver) { var app_id = raw_data.app_id; // nur speichern wenn app_id nicht eigenen globalen app_id entspricht if (app_id != app_cfg.global.app_id) { - waip.rmld_speichern(data, app_cfg.endpoint.host, function (result) { + saver.save_new_rmld(data, app_cfg.endpoint.host, app_id, function (result) { if (!result) { sql.db_log('API', 'Fehler beim speichern der Rückmeldung von ' + app_cfg.endpoint.host + ': ' + JSON.stringify(data)); }; diff --git a/server/routing.js b/server/routing.js index b7ca9a3..f4f40e6 100755 --- a/server/routing.js +++ b/server/routing.js @@ -244,8 +244,10 @@ module.exports = function (app, sql, uuidv4, app_cfg, passport, auth, udp, saver // Rueckmeldung entgegennehmen app.post('/rmld/:waip_uuid/:rmld_uuid', function (req, res) { + // Remote-IP erkennen, fuer Fehler-Auswertung + var remote_ip = req.headers["x-real-ip"] || req.headers['x-forwarded-for'] || req.connection.remoteAddress; // auf Saver verweisen - saver.save_new_rmld(req.body, null, 'web', function (result) { + saver.save_new_rmld(req.body, remote_ip, 'web', function (result) { var waip_uuid = req.body.waip_uuid; var rmld_uuid = req.body.rmld_uuid; if (result) { diff --git a/server/saver.js b/server/saver.js index ea19ecc..861719e 100755 --- a/server/saver.js +++ b/server/saver.js @@ -61,14 +61,19 @@ module.exports = function (app_cfg, sql, waip, uuidv4) { function save_new_rmld(data, remote_addr, app_id, callback) { validate_rmld(data, function (valid) { if (valid) { - + waip.rmld_speichern(data, app_id, function (result) { + if (result) { + sql.db_log('RMLD', 'Rückmeldung' + host + ' erhalten und gespeichert: ' + data); + callback && callback(result); + } else { + sql.db_log('RMLD', 'Fehler beim speichern der Rückmeldung' + host + ': ' + rueckmeldung); + callback && callback(result); + }; + }); } else { - sql.db_log('RMLD', 'Fehler: Rückmeldung von nicht valide: ' + waip_data); + sql.db_log('RMLD', 'Fehler: Rückmeldung von ' + remote_addr + ' nicht valide: ' + waip_data); }; }); - - - }; // Funktion um zu pruefen, ob Nachricht im JSON-Format ist diff --git a/server/waip.js b/server/waip.js index fe196ea..ae68bed 100755 --- a/server/waip.js +++ b/server/waip.js @@ -11,7 +11,7 @@ module.exports = function (io, sql, fs, brk, async, app_cfg, api) { sql.db_einsatz_speichern(einsatz_daten, function (waip_id) { sql.db_log('DEBUG', 'Neuen Einsatz mit der ID ' + waip_id + ' gespeichert.'); -// FIXME hier ungewollte Einsaetze ggf. wieder loeschen + // FIXME hier ungewollte Einsaetze ggf. wieder loeschen // nach dem Speichern anhand der waip_id die beteiligten Wachennummern zum Einsatz ermitteln sql.db_einsatz_get_rooms(waip_id, function (socket_rooms) { @@ -99,29 +99,19 @@ module.exports = function (io, sql, fs, brk, async, app_cfg, api) { }); }; - function rmld_speichern(rueckmeldung, host, callback) { + function rmld_speichern(rueckmeldung, app_id, callback) { // Rueckmeldung speichern und verteilen - proof.validate_rmld(rueckmeldung, function (valid) { - if (valid) { - if (!host == null) { - host = ' von ' + host; - }; - console.log(rueckmeldung); - sql.db_rmld_save(rueckmeldung, function (result) { - if (result) { - rmld_verteilen_by_uuid(rueckmeldung.waip_uuid, rueckmeldung.rmld_uuid); - sql.db_log('RMLD', 'Rückmeldung' + host + ' erhalten und gespeichert: ' + result); - callback && callback(result); - } else { - sql.db_log('RMLD', 'Fehler beim speichern der Rückmeldung' + host + ': ' + rueckmeldung); - callback && callback(result); - }; - }); + sql.db_rmld_save(rueckmeldung, function (saved) { + if (saved) { + rmld_verteilen_by_uuid(rueckmeldung.waip_uuid, rueckmeldung.rmld_uuid); + callback && callback(saved); + } else { + callback && callback(saved); }; }); // TODO TEST: Api WAIP - api.server_to_client_new_rmld(req.body, 'web'); - api.client_to_server_new_rmld(req.body, 'web'); + api.server_to_client_new_rmld(req.body, app_id); + api.client_to_server_new_rmld(req.body, app_id); }; function rmld_verteilen_by_uuid(waip_uuid, rmld_uuid) { @@ -161,7 +151,7 @@ module.exports = function (io, sql, fs, brk, async, app_cfg, api) { // Rueckmeldung an einen bestimmten Client senden if (typeof socket.id !== 'undefined') { sql.db_rmld_get_fuer_wache(waip_id, wachen_id, function (rmld_obj) { - if (rmld_obj) { + if (rmld_obj) { // Rueckmeldung nur an den einen Socket senden socket.emit('io.new_rmld', rmld_obj); sql.db_log('RMLD', 'Vorhandene Rückmeldungen an Socket ' + socket.id + ' gesendet.');