... |
... |
@@ -17,6 +17,25 @@ function convertDate(date) { |
17
|
17
|
.setZone('America/Sao_Paulo')
|
18
|
18
|
.toFormat('dd/MM/yyyy HH:mm:ss') ;
|
19
|
19
|
}
|
|
20
|
+
|
|
21
|
+function reportsConversion(reports) {
|
|
22
|
+ reports.forEach((row, index) => {
|
|
23
|
+ row["maxdate"] = convertDate(row["maxdate"]) ;
|
|
24
|
+ row["mindate"] = convertDate(row["mindate"]) ;
|
|
25
|
+ }) ;
|
|
26
|
+}
|
|
27
|
+
|
|
28
|
+function detailsConversion(details) {
|
|
29
|
+ details.forEach((row, index) => {
|
|
30
|
+ row["ip"] = ip.fromLong(row["ip"]) ;
|
|
31
|
+ if (row["ip6"] != null) {
|
|
32
|
+ row["ip6"] = ip.fromLong(row["ip6"]) ;
|
|
33
|
+ }
|
|
34
|
+ row.dmarc_result = row.dmarc_result_max ;
|
|
35
|
+ delete row.dmarc_result_max ;
|
|
36
|
+ delete row.dmarc_result_min ;
|
|
37
|
+ }) ;
|
|
38
|
+}
|
20
|
39
|
//##############################################################################
|
21
|
40
|
|
22
|
41
|
|
... |
... |
@@ -189,14 +208,11 @@ app.get('/reports', (req, res) => { |
189
|
208
|
// replaces the sorting column, adds arguments
|
190
|
209
|
pgClient.query(reports_query.replace("@@@@", sortStr), [perPage, ((page-1) * perPage)], (err, result) => {
|
191
|
210
|
if (err) {
|
192
|
|
- console.log("ERROR: Unable to run query") ;
|
|
211
|
+ res.status(500).send('Error fetching data');
|
193
|
212
|
} else {
|
194
|
213
|
// Converting results
|
195
|
|
- result["rows"].forEach((row, index) => {
|
196
|
|
- row["maxdate"] = convertDate(row["maxdate"]) ;
|
197
|
|
- row["mindate"] = convertDate(row["mindate"]) ;
|
198
|
|
- }) ;
|
199
|
|
- res.send(result["rows"]) ;
|
|
214
|
+ reportsConversion(result.rows) ;
|
|
215
|
+ res.send(result.rows) ;
|
200
|
216
|
}
|
201
|
217
|
}) ;
|
202
|
218
|
});
|
... |
... |
@@ -207,24 +223,18 @@ app.get('/reports/details', (req, res) => { |
207
|
223
|
// Serial required in URL
|
208
|
224
|
const { serial } = req.query ;
|
209
|
225
|
if (! serial) {
|
210
|
|
- res.send("No serial specified...") ;
|
211
|
|
- return
|
|
226
|
+ res.status(500).send("No serial specified...") ;
|
|
227
|
+ return ;
|
212
|
228
|
}
|
213
|
229
|
|
214
|
230
|
pgClient.query(details_query, [serial], (err, result) => {
|
215
|
231
|
if (err) {
|
216
|
|
- console.log("ERROR: Unable to run query") ;
|
217
|
|
- console.log(err) ;
|
|
232
|
+ res.status(500).send("No serial specified...") ;
|
218
|
233
|
} else if (result.rowCount < 1) {
|
219
|
234
|
res.send(`No report matching serial ${req.params.serial}`) ;
|
220
|
235
|
} else {
|
221
|
236
|
// Converting results
|
222
|
|
- result["rows"].forEach((row, index) => {
|
223
|
|
- row["ip"] = ip.fromLong(row["ip"]) ;
|
224
|
|
- if (row["ip6"] != null) {
|
225
|
|
- row["ip6"] = ip.fromLong(row["ip6"]) ;
|
226
|
|
- }
|
227
|
|
- }) ;
|
|
237
|
+ detailsConversion(result.rows) ;
|
228
|
238
|
res.send(result["rows"]) ;
|
229
|
239
|
}
|
230
|
240
|
}) ;
|
... |
... |
@@ -267,17 +277,12 @@ app.get('/reports/extended', async (req, res) => { |
267
|
277
|
const detailResult = await pgClient.query(details_query, [row.serial]);
|
268
|
278
|
detailResult.rows.forEach((row, index) => {
|
269
|
279
|
// Conversion for /details data
|
270
|
|
- row["ip"] = ip.fromLong(row["ip"]) ;
|
271
|
|
- if (row["ip6"] != null) {
|
272
|
|
- row["ip6"] = ip.fromLong(row["ip6"]) ;
|
273
|
|
- }
|
|
280
|
+ detailsConversion([ row ]) ;
|
274
|
281
|
}) ;
|
275
|
|
- // Conversion for /reports data
|
276
|
|
- row.details = detailResult.rows;
|
277
|
|
- row.maxdate = convertDate(row.maxdate) ;
|
278
|
|
- row.mindate = convertDate(row.mindate) ;
|
|
282
|
+ row.details = detailResult.rows ;
|
279
|
283
|
})
|
280
|
284
|
);
|
|
285
|
+ await reportsConversion(rows) ;
|
281
|
286
|
res.send(rows);
|
282
|
287
|
|
283
|
288
|
} catch (err) {
|
... |
... |
@@ -293,7 +298,7 @@ app.get('/reports/extended', async (req, res) => { |
293
|
298
|
app.get('/reports/:serial.xml', (req, res) => {
|
294
|
299
|
pgClient.query(xml_query, [req.params.serial], (err, result) => {
|
295
|
300
|
if (err) {
|
296
|
|
- console.log(err) ;
|
|
301
|
+ res.status(500).send("Error fetching data...") ;
|
297
|
302
|
} else if (result.rowCount == 0 ) {
|
298
|
303
|
// No report with that serial
|
299
|
304
|
res.send(`No xml related to serial ${req.params.serial}`) ;
|