Commit 369ac5df70f7a437d6eb10318b3d7bfa599e6072
Exists in
webadmin
Merge branch 'webadmin' of gitlab.kodesumber.com:komodo/komodo-center-evo-cp into webadmin
Showing 7 changed files Side-by-side Diff
lib/webadmin/index.js
... | ... | @@ -10,10 +10,6 @@ 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 | -}); | |
17 | 13 | |
18 | 14 | nunjucks.configure('./webadmin-views', { |
19 | 15 | autoescape: true, |
... | ... | @@ -27,7 +23,7 @@ const accessLogStream = rfs.createStream( |
27 | 23 | (time, index) => { |
28 | 24 | const ts = time ? `.${moment(time).format('YYYY-MM-DD')}` : ''; |
29 | 25 | const idx = index ? `.${index}` : ''; |
30 | - return `apiserver.access_log${ts}${idx}`; | |
26 | + return `webadmin.access_log${ts}${idx}`; | |
31 | 27 | }, |
32 | 28 | { |
33 | 29 | interval: '1d', |
... | ... | @@ -37,6 +33,11 @@ const accessLogStream = rfs.createStream( |
37 | 33 | |
38 | 34 | app.use(morgan('combined', { stream: accessLogStream })); |
39 | 35 | |
36 | +app.use((req, res, next) => { | |
37 | + res.locals.config = config; | |
38 | + next(); | |
39 | +}); | |
40 | + | |
40 | 41 | app.get('/', (req, res) => { |
41 | 42 | res.redirect('/config/modem'); |
42 | 43 | }); |
lib/webadmin/router/config.js
... | ... | @@ -16,7 +16,6 @@ async function writeConfigFile() { |
16 | 16 | |
17 | 17 | function pageMain(req, res) { |
18 | 18 | res.render('config.index.html', { |
19 | - config: JSON.stringify(config, null, 4), | |
20 | 19 | modems: orderBy(config.modems, [(v) => v.name], ['asc']), |
21 | 20 | baseUrl: req.baseUrl, |
22 | 21 | }); |
... | ... | @@ -39,7 +38,7 @@ async function pageSetOutgoing(req, res) { |
39 | 38 | |
40 | 39 | await writeConfigFile(); |
41 | 40 | |
42 | - res.redirect(`${req.baseUrl}`); | |
41 | + res.redirect(`${req.baseUrl}/modem#modem${encodeURIComponent(modemName)}`); | |
43 | 42 | } |
44 | 43 | |
45 | 44 | async function pageDelPrefix(req, res) { |
... | ... | @@ -71,7 +70,7 @@ async function pageDelPrefix(req, res) { |
71 | 70 | |
72 | 71 | await writeConfigFile(); |
73 | 72 | |
74 | - res.redirect(`${req.baseUrl}`); | |
73 | + res.redirect(`${req.baseUrl}/modem#modem${encodeURIComponent(modemName)}`); | |
75 | 74 | } |
76 | 75 | |
77 | 76 | async function modemAdd(req, res) { |
... | ... | @@ -79,9 +78,15 @@ async function modemAdd(req, res) { |
79 | 78 | name: (req.body.name || '').trim(), |
80 | 79 | imsi: (req.body.imsi || '').trim(), |
81 | 80 | outgoing: !!req.body.outgoing, |
82 | - prefix: (req.body.prefix || '').split(/[, ]+/).map((val) => val.trim().replace(/^0/, '62')).filter((row) => row), | |
81 | + prefix: (req.body.prefix || '').split(/[, ]+/) | |
82 | + .map((val) => val.trim().replace(/^0/, '62')) | |
83 | + .filter((row) => row), | |
83 | 84 | }; |
84 | - const index = config.modems.find((item) => item.name.toUpperCase() === modem.name.toUpperCase()); | |
85 | + | |
86 | + const index = config.modems.find( | |
87 | + (item) => item.name.toUpperCase() === modem.name.toUpperCase(), | |
88 | + ); | |
89 | + | |
85 | 90 | if (index >= 0) { |
86 | 91 | res.end('Modem duplikat'); |
87 | 92 | return; |
... | ... | @@ -90,12 +95,15 @@ async function modemAdd(req, res) { |
90 | 95 | config.modems.push(modem); |
91 | 96 | await writeConfigFile(); |
92 | 97 | |
93 | - res.redirect(`${req.baseUrl}`); | |
98 | + res.redirect(`${req.baseUrl}/modem`); | |
94 | 99 | } |
95 | 100 | |
96 | 101 | async function modemAddPrefix(req, res) { |
97 | 102 | const modemName = (req.body.name || '').trim(); |
98 | - const prefix = (req.body.prefix || '').split(/[, ]+/).map((val) => val.trim().replace(/^0/, '62')).filter((row) => row); | |
103 | + const prefix = (req.body.prefix || '').split(/[, ]+/) | |
104 | + .map((val) => val.trim().replace(/^0/, '62')) | |
105 | + .filter((row) => row); | |
106 | + | |
99 | 107 | const index = config.modems.findIndex( |
100 | 108 | (item) => item.name.toUpperCase() === modemName.toUpperCase(), |
101 | 109 | ); |
... | ... | @@ -112,7 +120,7 @@ async function modemAddPrefix(req, res) { |
112 | 120 | |
113 | 121 | await writeConfigFile(); |
114 | 122 | |
115 | - res.redirect(`${req.baseUrl}`); | |
123 | + res.redirect(`${req.baseUrl}/modem#modem${encodeURIComponent(modemName)}`); | |
116 | 124 | } |
117 | 125 | |
118 | 126 | async function modemUpdateImsi(req, res) { |
... | ... | @@ -131,7 +139,7 @@ async function modemUpdateImsi(req, res) { |
131 | 139 | |
132 | 140 | await writeConfigFile(); |
133 | 141 | |
134 | - res.redirect(`${req.baseUrl}`); | |
142 | + res.redirect(`${req.baseUrl}/modem#modem${encodeURIComponent(modemName)}`); | |
135 | 143 | } |
136 | 144 | |
137 | 145 | async function modemUpdateCustomIp(req, res) { |
... | ... | @@ -143,9 +151,10 @@ async function modemUpdateCustomIp(req, res) { |
143 | 151 | const index = config.modems.findIndex( |
144 | 152 | (item) => item.name.toUpperCase() === modemName.toUpperCase(), |
145 | 153 | ); |
154 | + | |
146 | 155 | config.modems[index].url = url; |
147 | 156 | config.modems[index].username = username; |
148 | - config.modems[index].password = password; | |
157 | + config.modems[index].password = password; | |
149 | 158 | |
150 | 159 | if (index < 0) { |
151 | 160 | res.end('Modem tidak ditemukan'); |
... | ... | @@ -154,7 +163,7 @@ async function modemUpdateCustomIp(req, res) { |
154 | 163 | |
155 | 164 | await writeConfigFile(); |
156 | 165 | |
157 | - res.redirect(`${req.baseUrl}`); | |
166 | + res.redirect(`${req.baseUrl}/modem#modem${encodeURIComponent(modemName)}`); | |
158 | 167 | } |
159 | 168 | |
160 | 169 | async function modemDelete(req, res) { |
package-lock.json
package.json
webadmin-views/config.include.addmodem.html
1 | -<div class="card"> | |
1 | +<div class="card" id="addmodem"> | |
2 | 2 | <div class="card-header bg-info"> |
3 | 3 | <h3>Tambah Modem</3> |
4 | 4 | </div> |
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 | placeholder="Masukkan Prefix pisahkan dengan koma" |
23 | 23 | > |
24 | 24 | </div> |
25 | - <button type="submit" class="btn btn-primary">Save</button> | |
25 | + <button type="submit" class="btn btn-primary">Simpan modem baru</button> | |
26 | 26 | </form> |
27 | 27 | </div> |
28 | 28 | </div> |
29 | 29 | \ No newline at end of file |
webadmin-views/config.index.html
... | ... | @@ -2,17 +2,22 @@ |
2 | 2 | |
3 | 3 | {% block content %} |
4 | 4 | |
5 | -<!-- | |
6 | -<code> | |
7 | -{{ config | nl2br | safe }} | |
8 | -</code> | |
9 | ---> | |
10 | 5 | |
11 | 6 | {% for modem in modems %} |
7 | + <a href="#modem{{modem.name}}" class="btn btn-sm btn-primary">{{modem.name}}</a> | |
8 | +{% endfor %} | |
9 | + | |
10 | +<a href="#addmodem" class="btn btn-sm btn-success">Tambah modem...</a> | |
11 | + | |
12 | +<br> | |
13 | + | |
14 | +{% for modem in modems %} | |
15 | +<div id="modem{{modem.name}}"> </div> | |
16 | + | |
12 | 17 | <div class="card"> |
13 | - <div class="card-header bg-info"> | |
14 | - <h3>{{ modem.name }}</3> | |
15 | - </div> | |
18 | + <h5 class="card-header"> | |
19 | + {{ modem.name }} | |
20 | + </h5> | |
16 | 21 | <div class="card-body"> |
17 | 22 | |
18 | 23 | <dl class="row"> |
... | ... | @@ -20,16 +25,20 @@ |
20 | 25 | <dd class="col-sm-9"> |
21 | 26 | {% if modem.outgoing %} |
22 | 27 | {% set newValue = 0 %} |
28 | + {% set btnClass = "btn btn-success" %} | |
29 | + {% set btnTitle = "klik disini untuk menonaktifkan outgoing" %} | |
23 | 30 | {% else %} |
24 | 31 | {% set newValue = 1 %} |
32 | + {% set btnClass = "btn btn-danger" %} | |
33 | + {% set btnTitle = "klik disini untuk mengaktifkan outgoing" %} | |
25 | 34 | {% endif %} |
26 | - <a href="{{ baseUrl }}/modem/set-outgoing/{{ modem.name | urlencode }}/{{ newValue }}" onclick="return window.confirm('Apakah anda yakin ingin mengubah status outgoing modem {{ modem.name }} menjadi {{ not modem.outgoing }}?');"> | |
35 | + <a href="{{ baseUrl }}/modem/set-outgoing/{{ modem.name | urlencode }}/{{ newValue }}" | |
36 | + class="{{ btnClass }}" title="{{ btnTitle }}" | |
37 | + onclick="return window.confirm('Apakah anda yakin ingin mengubah status outgoing modem {{ modem.name }} menjadi {{ not modem.outgoing }}?');"> | |
27 | 38 | {{ modem.outgoing }} |
28 | 39 | </a> |
29 | 40 | </dd> |
30 | - </dl> | |
31 | 41 | |
32 | - <dl class="row"> | |
33 | 42 | <dt class="col-sm-3">IMSI</dt> |
34 | 43 | <dd class="col-sm-9"> |
35 | 44 | {{ modem.imsi or '-' }} |
... | ... | @@ -37,14 +46,12 @@ |
37 | 46 | <form method="post" action="{{ baseUrl }}/modem/update-imsi" class="form-inline"> |
38 | 47 | <input type="hidden" name="name" value="{{ modem.name | urlencode }}"> |
39 | 48 | <div class="form-group"> |
40 | - <input type="text" name="imsi" class="form-control" placeholder="Update IMSI"> | |
49 | + <input type="text" name="imsi" class="form-control" placeholder="imsi baru, misal: 5100xxxxxxxxxxx"> | |
41 | 50 | </div> |
42 | - <button type="submit" class="btn btn-primary">Save</button> | |
51 | + <button type="submit" class="btn btn-primary">Simpan IMSI baru</button> | |
43 | 52 | </form> |
44 | 53 | </dd> |
45 | - </dl> | |
46 | 54 | |
47 | - <dl class="row"> | |
48 | 55 | <dt class="col-sm-3">Prefix</dt> |
49 | 56 | <dd class="col-sm-9"> |
50 | 57 | {% for prefix_item in modem.prefix %} |
... | ... | @@ -57,44 +64,41 @@ |
57 | 64 | <form method="post" action="{{ baseUrl }}/modem/add-prefix" class="form-inline"> |
58 | 65 | <input type="hidden" name="name" value="{{ modem.name | urlencode }}"> |
59 | 66 | <div class="form-group"> |
60 | - <input type="text" name="prefix" class="form-control" placeholder="Masukkan prefix baru"> | |
67 | + <input type="text" name="prefix" class="form-control" placeholder="prefix baru, misal 6281x"> | |
61 | 68 | </div> |
62 | - <button type="submit" class="btn btn-primary">Save</button> | |
69 | + <button type="submit" class="btn btn-primary">Simpan prefix baru</button> | |
63 | 70 | </form> |
64 | 71 | </dd> |
65 | - </dl> | |
66 | - <dl class="row"> | |
72 | + | |
67 | 73 | <dt class="col-sm-3">Custom Sender</dt> |
68 | 74 | <dd class="col-sm-9"> |
69 | 75 | <br> |
70 | 76 | <form method="post" action="{{ baseUrl }}/modem/update-custom-ip"> |
71 | 77 | <input type="hidden" name="name" value="{{ modem.name | urlencode }}"> |
72 | 78 | <div class="form-group"> |
73 | - <input type="text" name="url" class="form-control" placeholder="Masukkan URL" value="{{ modem.url }}"> | |
79 | + <input type="text" name="url" class="form-control" placeholder="url: misal http://127.0.0.0:59194/service/sendsms" value="{{ modem.url }}"> | |
74 | 80 | </div> |
75 | 81 | <div class="form-group"> |
76 | - <input type="text" name="username" class="form-control" placeholder="Masukkan Username" value="{{ modem.username }}"> | |
82 | + <input type="text" name="username" class="form-control" placeholder="username" value="{{ modem.username }}"> | |
77 | 83 | </div> |
78 | 84 | <div class="form-group"> |
79 | - <input type="password" name="password" class="form-control" placeholder="Masukkan Password" value="{{ modem.password }}"> | |
85 | + <input type="password" name="password" class="form-control" placeholder="password" value="{{ modem.password }}"> | |
80 | 86 | </div> |
81 | - <button type="submit" class="btn btn-primary">Save</button> | |
87 | + <button type="submit" class="btn btn-primary">Simpan custom data sender</button> | |
82 | 88 | </form> |
83 | 89 | </dd> |
84 | 90 | </dl> |
85 | - <dl class="row"> | |
86 | - <dt class="col-sm-3"> </dt> | |
87 | - <dd class="col-sm-9"> | |
88 | - <form method="post" action="{{ baseUrl }}/modem/delete"> | |
89 | - <input type="hidden" name="name" value="{{ modem.name | urlencode }}"> | |
90 | - <button type="submit" class="btn btn-block btn-danger" | |
91 | - onclick="return window.confirm('Apakah anda yakin ingin menghapus modem {{ modem.name }}?');" | |
92 | - > | |
93 | - Hapus Modem | |
94 | - </button> | |
95 | - </form> | |
96 | - </dd> | |
97 | - </dl> | |
91 | + | |
92 | + <div class="text-right"> | |
93 | + <form method="post" action="{{ baseUrl }}/modem/delete"> | |
94 | + <input type="hidden" name="name" value="{{ modem.name | urlencode }}"> | |
95 | + <button type="submit" class="btn btn-danger" | |
96 | + onclick="return window.confirm('Apakah anda yakin ingin menghapus modem {{ modem.name }}?');" | |
97 | + > | |
98 | + Hapus Modem | |
99 | + </button> | |
100 | + </form> | |
101 | + </div> | |
98 | 102 | </div> |
99 | 103 | </div> |
100 | 104 | <br> |
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>{{ main_config.name }}</title> | |
10 | + <title>{{ 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="#">{{ main_config.name }}</a> | |
47 | + <a class="navbar-brand" href="#">{{ 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> |