Commit c4a8ece6347cbb834d9f350052b3c3b142102dd0

Authored by adi surya
1 parent c0328fc56c
Exists in master and in 1 other branch webadmin

modem management

Showing 6 changed files with 21 additions and 34 deletions Side-by-side Diff

lib/webadmin/index.js
... ... @@ -10,6 +10,10 @@ const logger = require('komodo-sdk/logger');
10 10 const routerConfig = require('./router/config');
11 11  
12 12 const app = express();
  13 +app.use((req, res, next) => {
  14 + res.locals.main_config = config;
  15 + next();
  16 +});
13 17  
14 18 nunjucks.configure('./webadmin-views', {
15 19 autoescape: true,
... ... @@ -33,6 +37,10 @@ const accessLogStream = rfs.createStream(
33 37  
34 38 app.use(morgan('combined', { stream: accessLogStream }));
35 39  
  40 +app.get('/', (req, res) => {
  41 + res.redirect('/config/modem');
  42 +});
  43 +
36 44 app.use('/config', routerConfig);
37 45  
38 46 const listenPort = (config.webadmin && config.webadmin.port) || 21923;
lib/webadmin/router/config.js
1 1 const fs = require('fs');
2 2 const express = require('express');
3   -
  3 +const { orderBy } = require('natural-orderby');
4 4 const config = require('komodo-sdk/config');
5 5  
6 6 const router = express.Router();
7 7 module.exports = router;
8 8  
9   -function composeNewModem(name, params) {
10   - return {
11   - name,
12   - outgoing: (params && params.outgoing) || false,
13   - prefix: (params && params.prefix) || [],
14   - };
15   -}
16   -
17 9 async function writeConfigFile() {
18 10 try {
19 11 await fs.promises.writeFile('config.json', JSON.stringify(config, null, 4));
... ... @@ -25,7 +17,7 @@ async function writeConfigFile() {
25 17 function pageMain(req, res) {
26 18 res.render('config.index.html', {
27 19 config: JSON.stringify(config, null, 4),
28   - modems: config.modems,
  20 + modems: orderBy(config.modems, [(v) => v.name], ['asc']),
29 21 baseUrl: req.baseUrl,
30 22 });
31 23 }
... ... @@ -87,7 +79,7 @@ async function modemAdd(req, res) {
87 79 name: (req.body.name || '').trim(),
88 80 imsi: (req.body.imsi || '').trim(),
89 81 outgoing: !!req.body.outgoing,
90   - prefix: (req.body.prefix || '').split(/[, ]+/).map((val) => val.trim()),
  82 + prefix: (req.body.prefix || '').split(/[, ]+/).map((val) => val.trim().replace(/^0/, '62')).filter((row) => row),
91 83 };
92 84 const index = config.modems.find((item) => item.name.toUpperCase() === modem.name.toUpperCase());
93 85 if (index >= 0) {
... ... @@ -103,8 +95,7 @@ async function modemAdd(req, res) {
103 95  
104 96 async function modemAddPrefix(req, res) {
105 97 const modemName = (req.body.name || '').trim();
106   - const prefix = (req.body.prefix || '').split(/[, ]+/).map((val) => val.trim());
107   - console.log(prefix);
  98 + const prefix = (req.body.prefix || '').split(/[, ]+/).map((val) => val.trim().replace(/^0/, '62')).filter((row) => row);
108 99 const index = config.modems.findIndex(
109 100 (item) => item.name.toUpperCase() === modemName.toUpperCase(),
110 101 );
... ... @@ -3153,6 +3153,11 @@
3153 3153 "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=",
3154 3154 "dev": true
3155 3155 },
  3156 + "natural-orderby": {
  3157 + "version": "2.0.3",
  3158 + "resolved": "https://registry.npmjs.org/natural-orderby/-/natural-orderby-2.0.3.tgz",
  3159 + "integrity": "sha512-p7KTHxU0CUrcOXe62Zfrb5Z13nLvPhSWR/so3kFulUQU0sgUll2Z0LwpsLN351eOOD+hRGu/F1g+6xDfPeD++Q=="
  3160 + },
3156 3161 "negotiator": {
3157 3162 "version": "0.6.2",
3158 3163 "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
... ... @@ -28,6 +28,7 @@
28 28 "locks": "^0.2.2",
29 29 "moment": "^2.24.0",
30 30 "morgan": "^1.9.1",
  31 + "natural-orderby": "^2.0.3",
31 32 "nunjucks": "^3.2.0",
32 33 "rotating-file-stream": "^2.0.0",
33 34 "uniqid": "^5.2.0"
webadmin-views/config.index.html
... ... @@ -64,7 +64,7 @@
64 64 </dd>
65 65 </dl>
66 66 <dl class="row">
67   - <dt class="col-sm-3">Custom IP</dt>
  67 + <dt class="col-sm-3">Custom Sender</dt>
68 68 <dd class="col-sm-9">
69 69 <br>
70 70 <form method="post" action="{{ baseUrl }}/modem/update-custom-ip">
webadmin-views/template.starter.html
... ... @@ -7,7 +7,7 @@
7 7 <meta name="description" content="">
8 8 <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
9 9 <meta name="generator" content="Jekyll v3.8.6">
10   - <title>Starter Template · Bootstrap</title>
  10 + <title>{{ main_config.name }}</title>
11 11  
12 12 <!-- Bootstrap core CSS -->
13 13 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
... ... @@ -44,7 +44,7 @@
44 44 </head>
45 45 <body>
46 46 <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
47   - <a class="navbar-brand" href="#">Navbar</a>
  47 + <a class="navbar-brand" href="#">{{ main_config.name }}</a>
48 48 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
49 49 <span class="navbar-toggler-icon"></span>
50 50 </button>
... ... @@ -54,25 +54,7 @@
54 54 <li class="nav-item active">
55 55 <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
56 56 </li>
57   - <li class="nav-item">
58   - <a class="nav-link" href="#">Link</a>
59   - </li>
60   - <li class="nav-item">
61   - <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
62   - </li>
63   - <li class="nav-item dropdown">
64   - <a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
65   - <div class="dropdown-menu" aria-labelledby="dropdown01">
66   - <a class="dropdown-item" href="#">Action</a>
67   - <a class="dropdown-item" href="#">Another action</a>
68   - <a class="dropdown-item" href="#">Something else here</a>
69   - </div>
70   - </li>
71 57 </ul>
72   - <form class="form-inline my-2 my-lg-0">
73   - <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
74   - <button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>
75   - </form>
76 58 </div>
77 59 </nav>
78 60