sarransh commited on
Commit
addcd8a
Β·
verified Β·
1 Parent(s): c353227

ADD: Secure History Dashboard with 3-Day Auto-Purge v1.3

Browse files
Files changed (2) hide show
  1. server.js +38 -0
  2. views/dashboard.ejs +18 -6
server.js CHANGED
@@ -595,6 +595,44 @@ app.get('/dashboard', (req, res) => {
595
  });
596
  });
597
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  // ─────────────────────────────────────────────────────────────────────────────
599
  const PORT = process.env.PORT || 3000;
600
  app.listen(PORT, () => {
 
595
  });
596
  });
597
 
598
+ app.get('/dashboard/view-pdf/:id', async (req, res) => {
599
+ if (!req.session.authenticated) {
600
+ return res.status(401).send("Unauthorized");
601
+ }
602
+
603
+ const { id } = req.params;
604
+ db.get("SELECT * FROM logs WHERE id = ?", [id], async (err, row) => {
605
+ if (err || !row) {
606
+ return res.status(404).send("Log entry not found");
607
+ }
608
+
609
+ try {
610
+ const data = JSON.parse(row.payload);
611
+ const type = row.type;
612
+ const includeFare = true; // Default to true for historical viewing
613
+
614
+ let pdfBuffer;
615
+ if (type === 'FLIGHT') {
616
+ await attachBarcodes(data);
617
+ pdfBuffer = await generatePdfBuffer('flight-voucher.ejs', { data, includeFare });
618
+ } else {
619
+ await attachHotelQRCode(data);
620
+ pdfBuffer = await generatePdfBuffer('voucher.ejs', { data, includeFare });
621
+ }
622
+
623
+ res.set({
624
+ 'Content-Type': 'application/pdf',
625
+ 'Content-Length': pdfBuffer.length,
626
+ 'Content-Disposition': `inline; filename="${type}-Voucher-${row.pnr}.pdf"`
627
+ });
628
+ res.send(pdfBuffer);
629
+ } catch (error) {
630
+ logger.error({ err: error, logId: id }, "Failed to re-generate PDF from history");
631
+ res.status(500).send("Error re-generating PDF: " + error.message);
632
+ }
633
+ });
634
+ });
635
+
636
  // ─────────────────────────────────────────────────────────────────────────────
637
  const PORT = process.env.PORT || 3000;
638
  app.listen(PORT, () => {
views/dashboard.ejs CHANGED
@@ -115,7 +115,13 @@
115
  <td class="px-6 py-4">
116
  <div class="text-xs font-semibold text-slate-800 uppercase"><%= log.passenger_name || 'N/A' %></div>
117
  </td>
118
- <td class="px-6 py-4 text-xs text-slate-500 font-medium">#<%= log.ag_id || '0' %></td>
 
 
 
 
 
 
119
  <td class="px-6 py-4">
120
  <% if(log.status === 200) { %>
121
  <span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-emerald-100 text-emerald-700">OK 200</span>
@@ -123,11 +129,17 @@
123
  <span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-rose-100 text-rose-700">ERR <%= log.status %></span>
124
  <% } %>
125
  </td>
126
- <td class="px-6 py-4 text-right">
127
- <button onclick='viewDetails(<%= JSON.stringify(log.payload) %>)'
128
- class="p-1.5 hover:bg-white hover:shadow-md rounded-lg text-slate-400 hover:text-blue-600 transition-all border border-transparent hover:border-slate-100 opacity-0 group-hover:opacity-100">
129
- <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/></svg>
130
- </button>
 
 
 
 
 
 
131
  </td>
132
  </tr>
133
  <% }); %>
 
115
  <td class="px-6 py-4">
116
  <div class="text-xs font-semibold text-slate-800 uppercase"><%= log.passenger_name || 'N/A' %></div>
117
  </td>
118
+ <td class="px-6 py-4 text-xs text-slate-500 font-medium whitespace-nowrap">
119
+ <% if(log.ag_id === '0' || !log.ag_id) { %>
120
+ <span class="text-slate-300 italic">System Default</span>
121
+ <% } else { %>
122
+ <span class="bg-blue-50 text-blue-600 px-2 py-0.5 rounded-md font-bold uppercase tracking-tighter">Agent #<%= log.ag_id %></span>
123
+ <% } %>
124
+ </td>
125
  <td class="px-6 py-4">
126
  <% if(log.status === 200) { %>
127
  <span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-emerald-100 text-emerald-700">OK 200</span>
 
129
  <span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-rose-100 text-rose-700">ERR <%= log.status %></span>
130
  <% } %>
131
  </td>
132
+ <td class="px-6 py-4 text-right whitespace-nowrap">
133
+ <div class="flex items-center justify-end gap-2">
134
+ <a href="/dashboard/view-pdf/<%= log.id %>" target="_blank" title="View/Download PDF"
135
+ class="p-1.5 hover:bg-white hover:shadow-md rounded-lg text-slate-400 hover:text-emerald-600 transition-all border border-transparent hover:border-slate-100 opacity-0 group-hover:opacity-100">
136
+ <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"/></svg>
137
+ </a>
138
+ <button onclick='viewDetails(<%= JSON.stringify(log.payload) %>)' title="View Raw JSON"
139
+ class="p-1.5 hover:bg-white hover:shadow-md rounded-lg text-slate-400 hover:text-blue-600 transition-all border border-transparent hover:border-slate-100 opacity-0 group-hover:opacity-100">
140
+ <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/></svg>
141
+ </button>
142
+ </div>
143
  </td>
144
  </tr>
145
  <% }); %>