syslogs.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { Syslog } from '../db/config.js';
  2. import { Alert, getLanguage, Navbar, Footer } from '../utils/system.js';
  3. export const Syslogs = async function(req, res) {
  4. req.session.host = `${req.params.host || 1}`;
  5. let logs = '';
  6. const syslogs = await Syslog.findAll({
  7. order: [
  8. ['id', 'DESC']
  9. ]
  10. });
  11. for (const log of syslogs) {
  12. let date = (log.createdAt).toDateString();
  13. let time = (log.createdAt).toLocaleTimeString();
  14. let datetime = `${time} ${date}`;
  15. // get the last 12 characters of the uniqueID
  16. let uniqueID = log.uniqueID;
  17. // if (uniqueID.length > 12) {
  18. // uniqueID = uniqueID.substring(uniqueID.length - 12);
  19. // }
  20. let message = log.message;
  21. // if (message.length > 50) {
  22. // message = message.substring(0, 50) + '...';
  23. // }
  24. logs += `<tr>
  25. <td><input class="form-check-input m-0 align-middle" name="select" type="checkbox" aria-label="Select"></td>
  26. <td class="sort-id">${log.id}</td>
  27. <td class="sort-username">${log.username}</td>
  28. <td class="sort-uniqueid">${uniqueID}</td>
  29. <td class="sort-event">${log.event}</td>
  30. <td class="sort-message">${message}</td>
  31. <td class="sort-ip">${log.ip}</td>
  32. <td class="sort-timestamp">${datetime}</td>
  33. <td class=""><a class="" href="#"><svg xmlns="http://www.w3.org/2000/svg" class="icon-tabler icon-tabler-player-play" width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 4v16l13 -8z"></path></svg></a></td>
  34. </tr>`
  35. }
  36. res.render("syslogs",{
  37. alert: '',
  38. username: req.session.username,
  39. role: req.session.role,
  40. logs: logs,
  41. navbar: await Navbar(req),
  42. footer: await Footer(req),
  43. });
  44. }
  45. export const submitSyslogs = async function(req,res){
  46. // console.log(req.body);
  47. let trigger_name = req.header('hx-trigger-name');
  48. let trigger_id = req.header('hx-trigger');
  49. console.log(`trigger_name: ${trigger_name} - trigger_id: ${trigger_id}`);
  50. res.render("syslogs",{
  51. alert: '',
  52. username: req.session.username,
  53. role: req.session.role,
  54. navbar: await Navbar(req),
  55. footer: await Footer(req),
  56. });
  57. }
  58. export const searchSyslogs = async function (req, res) {
  59. console.log(`[Search] ${req.body.search}`);
  60. res.send('ok');
  61. return;
  62. }