Commit 9b5f21d3ee90b7ac39dd786181ee5f5ec58358d3

Authored by Adhidarma Hadiwinoto
1 parent 3b4e58a992
Exists in master

pageSmsdLog pindah

Showing 4 changed files with 31 additions and 2 deletions Side-by-side Diff

lib/apiserver/routers/smstools-config.js
... ... @@ -152,6 +152,7 @@ async function pageInstallConfig(req, res) {
152 152 }
153 153  
154 154 function pageSmsdLog(req, res) {
  155 + // deprecated
155 156 const maxLines = (req.params.maxLines || 200);
156 157 childProcess.exec(`tail -n ${maxLines} /var/log/smsd/smsd.log | tac`, (err, stdout, stderr) => {
157 158 res.json({
lib/apiserver/routers/smstools.js
  1 +const childProcess = require('child_process');
1 2 const express = require('express');
  3 +const escapeQuotes = require('escape-quotes');
  4 +
2 5 const config = require('komodo-sdk/config');
  6 +
3 7 const smstoolsUtil = require('../../smstools-util');
4 8 const smstoolsStatus = require('../../smstools-status');
5 9 const smstoolsStatusParsed = require('../../smstools-status-parsed');
... ... @@ -23,6 +27,22 @@ async function pageRestart(req, res) {
23 27 res.json(await smstoolsUtil.restart());
24 28 }
25 29  
  30 +function pageSmsdLog(req, res) {
  31 + const maxLines = (Number(req.query.max) || 200);
  32 + const keyword = req.query.keyword && req.query.keyword.trim() && escapeQuotes(req.query.keyword.trim(), '\'"&|*<>[];$');
  33 + const cmd = req.query.keyword ? `tail -n ${maxLines * 50} | grep ${keyword} | tail -n ${maxLines} | tac`
  34 + : `tail -n ${maxLines} /var/log/smsd/smsd.log | tac`;
  35 +
  36 + childProcess.exec(cmd, (err, stdout, stderr) => {
  37 + res.json({
  38 + err,
  39 + stdout,
  40 + stderr,
  41 + });
  42 + });
  43 +}
  44 +
26 45 router.get('/status', pageStatus);
27 46 router.get('/status/raw', pageStatusRaw);
28 47 router.get('/restart', pageRestart);
  48 +router.get('/smsd-log', pageSmsdLog);
... ... @@ -1055,11 +1055,18 @@
1055 1055 "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
1056 1056 "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
1057 1057 },
  1058 + "escape-quotes": {
  1059 + "version": "1.0.2",
  1060 + "resolved": "https://registry.npmjs.org/escape-quotes/-/escape-quotes-1.0.2.tgz",
  1061 + "integrity": "sha1-tIltSmz4LdWzP0m3E0CMY4D2zZc=",
  1062 + "requires": {
  1063 + "escape-string-regexp": "^1.0.5"
  1064 + }
  1065 + },
1058 1066 "escape-string-regexp": {
1059 1067 "version": "1.0.5",
1060 1068 "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
1061   - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
1062   - "dev": true
  1069 + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
1063 1070 },
1064 1071 "eslint": {
1065 1072 "version": "6.7.1",
... ... @@ -30,6 +30,7 @@
30 30 },
31 31 "dependencies": {
32 32 "body-parser": "^1.19.0",
  33 + "escape-quotes": "^1.0.2",
33 34 "express": "^4.17.1",
34 35 "get-stdin": "^7.0.0",
35 36 "komodo-center-messaging-client-lib": "git+http://gitlab.kodesumber.com/komodo/komodo-center-messaging-client-lib.git",