diff --git a/server/api.js b/server/api.js index 7f8ec11..2921a15 100755 --- a/server/api.js +++ b/server/api.js @@ -31,7 +31,7 @@ module.exports = function (io, sql, app_cfg, remote_api, saver) { // nur speichern wenn app_id nicht eigenen globalen app_id entspricht if (app_id != app_cfg.global.app_id) { saver.save_new_waip(data, remote_ip, app_id); - sql.db_log('API', 'Neuer Wachalarm von ' + remote_ip + ': ' + data); + sql.db_log('API', 'Neuer Wachalarm von ' + remote_ip + ': ' + JSON.stringify(data)); }; }); @@ -43,7 +43,7 @@ module.exports = function (io, sql, app_cfg, remote_api, saver) { if (app_id != app_cfg.global.app_id) { 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); + sql.db_log('API', 'Fehler beim speichern der Rückmeldung von ' + remote_ip + ': ' + JSON.stringify(data)); }; }); }; @@ -88,7 +88,7 @@ module.exports = function (io, sql, app_cfg, remote_api, saver) { if (app_id != app_cfg.global.app_id) { // nicht erwuenschte Daten ggf. enfernen (Datenschutzoption) saver.save_new_waip(data, app_cfg.endpoint.host, app_id); - sql.db_log('API', 'Neuer Wachalarm von ' + app_cfg.endpoint.host + ': ' + data); + sql.db_log('API', 'Neuer Wachalarm von ' + app_cfg.endpoint.host + ': ' + JSON.stringify(data)); }; }); diff --git a/server/saver.js b/server/saver.js index 2b2e3ab..57913d6 100755 --- a/server/saver.js +++ b/server/saver.js @@ -32,7 +32,7 @@ module.exports = function (app_cfg, sql, waip, uuidv4, io, remote_api) { steps: app_cfg.global.circumcircle, units: 'kilometers' }) - waip_data.ortsdaten.wgs84_area = JSON.stringify(new_buffer); + waip_data.ortsdaten.wgs84_area = new_buffer; }; // pruefen, ob vielleicht schon ein Einsatz mit einer UUID gespeichert ist sql.db_einsatz_get_uuid_by_enr(waip_data.einsatzdaten.nummer, function (waip_uuid) { @@ -67,9 +67,9 @@ module.exports = function (app_cfg, sql, waip, uuidv4, io, remote_api) { function save_new_rmld(data, remote_addr, app_id, callback) { validate_rmld(data, function (valid) { - if (valid) { + if (valid) { // Rueckmeldung speichern und verteilen - sql.db_rmld_save(data, function (result) { + sql.db_rmld_save(data, function (result) { if (result) { sql.db_log('RMLD', 'Rückmeldung von ' + remote_addr + ' erhalten und gespeichert: ' + JSON.stringify(data)); waip.rmld_verteilen_by_uuid(data.waip_uuid, data.rmld_uuid); @@ -92,12 +92,13 @@ module.exports = function (app_cfg, sql, waip, uuidv4, io, remote_api) { // Funktion um zu pruefen, ob Nachricht im JSON-Format ist function isValidJSON(text) { - try { - JSON.parse(text); + if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { + //the json is ok return true; - } catch (error) { + } else { + //the json is not ok return false; - } + }; }; function validate_waip(data, callback) { diff --git a/server/sql_qry.js b/server/sql_qry.js index b0d68eb..598e27e 100755 --- a/server/sql_qry.js +++ b/server/sql_qry.js @@ -10,7 +10,6 @@ module.exports = function (db, app_cfg) { function db_einsatz_speichern(content, callback) { // Einsatzdaten verarbeiten - console.log(content.ortsdaten.wgs84_area); db.run(`INSERT OR REPLACE INTO waip_einsaetze ( id, uuid, einsatznummer, alarmzeit, einsatzart, stichwort, sondersignal, besonderheiten, ort, ortsteil, strasse, objekt, objektnr, objektart, wachenfolge, wgs84_x, wgs84_y, wgs84_area) VALUES ( @@ -31,7 +30,7 @@ module.exports = function (db, app_cfg) { \'` + content.ortsdaten.wachfolge + `\', \'` + content.ortsdaten.wgs84_x + `\', \'` + content.ortsdaten.wgs84_y + `\', - \'` + content.ortsdaten.wgs84_area + `\')`, + \'` + JSON.stringify(content.ortsdaten.wgs84_area) + `\')`, function (err) { if (err == null) { // letzte Einsatz-ID ermitteln diff --git a/server/udp.js b/server/udp.js index ad8917e..8352646 100644 --- a/server/udp.js +++ b/server/udp.js @@ -20,7 +20,7 @@ module.exports = function (app_cfg, sql, saver) { function send_message(message) { udp_server.send(message, 0, message.length, app_cfg.global.udpport, 'localhost', function (err, bytes) { if (err) throw err; - sql.db_log('UDP-Testalarm an Localhost (Port ' + app_cfg.global.udpport + ') gesendet.'); + sql.db_log('WAIP', 'UDP-Testalarm an localhost:' + app_cfg.global.udpport + ') gesendet.'); }); };