Commit c0328fc56c79d064c831893606434292b4f0c3e9
1 parent
409dcdbc9a
Exists in
master
and in
1 other branch
management modem
Showing 3 changed files with 174 additions and 17 deletions Side-by-side Diff
lib/webadmin/router/config.js
... | ... | @@ -82,6 +82,118 @@ async function pageDelPrefix(req, res) { |
82 | 82 | res.redirect(`${req.baseUrl}`); |
83 | 83 | } |
84 | 84 | |
85 | -router.get('/', pageMain); | |
85 | +async function modemAdd(req, res) { | |
86 | + const modem = { | |
87 | + name: (req.body.name || '').trim(), | |
88 | + imsi: (req.body.imsi || '').trim(), | |
89 | + outgoing: !!req.body.outgoing, | |
90 | + prefix: (req.body.prefix || '').split(/[, ]+/).map((val) => val.trim()), | |
91 | + }; | |
92 | + const index = config.modems.find((item) => item.name.toUpperCase() === modem.name.toUpperCase()); | |
93 | + if (index >= 0) { | |
94 | + res.end('Modem duplikat'); | |
95 | + return; | |
96 | + } | |
97 | + | |
98 | + config.modems.push(modem); | |
99 | + await writeConfigFile(); | |
100 | + | |
101 | + res.redirect(`${req.baseUrl}`); | |
102 | +} | |
103 | + | |
104 | +async function modemAddPrefix(req, res) { | |
105 | + const modemName = (req.body.name || '').trim(); | |
106 | + const prefix = (req.body.prefix || '').split(/[, ]+/).map((val) => val.trim()); | |
107 | + console.log(prefix); | |
108 | + const index = config.modems.findIndex( | |
109 | + (item) => item.name.toUpperCase() === modemName.toUpperCase(), | |
110 | + ); | |
111 | + if (Array.isArray(config.modems[index].prefix)) { | |
112 | + config.modems[index].prefix = config.modems[index].prefix.concat(prefix); | |
113 | + } else { | |
114 | + config.modems[index].prefix = prefix; | |
115 | + } | |
116 | + | |
117 | + if (index < 0) { | |
118 | + res.end('Modem tidak ditemukan'); | |
119 | + return; | |
120 | + } | |
121 | + | |
122 | + await writeConfigFile(); | |
123 | + | |
124 | + res.redirect(`${req.baseUrl}`); | |
125 | +} | |
126 | + | |
127 | +async function modemUpdateImsi(req, res) { | |
128 | + const modemName = (req.body.name || '').trim(); | |
129 | + const imsi = (req.body.imsi || '').trim(); | |
130 | + | |
131 | + const index = config.modems.findIndex( | |
132 | + (item) => item.name.toUpperCase() === modemName.toUpperCase(), | |
133 | + ); | |
134 | + config.modems[index].imsi = imsi; | |
135 | + | |
136 | + if (index < 0) { | |
137 | + res.end('Modem tidak ditemukan'); | |
138 | + return; | |
139 | + } | |
140 | + | |
141 | + await writeConfigFile(); | |
142 | + | |
143 | + res.redirect(`${req.baseUrl}`); | |
144 | +} | |
145 | + | |
146 | +async function modemUpdateCustomIp(req, res) { | |
147 | + const modemName = (req.body.name || '').trim(); | |
148 | + const url = (req.body.url || '').trim() || null; | |
149 | + const username = (req.body.username || '').trim() || null; | |
150 | + const password = (req.body.password || '').trim() || null; | |
151 | + | |
152 | + const index = config.modems.findIndex( | |
153 | + (item) => item.name.toUpperCase() === modemName.toUpperCase(), | |
154 | + ); | |
155 | + config.modems[index].url = url; | |
156 | + config.modems[index].username = username; | |
157 | + config.modems[index].password = password; | |
158 | + | |
159 | + if (index < 0) { | |
160 | + res.end('Modem tidak ditemukan'); | |
161 | + return; | |
162 | + } | |
163 | + | |
164 | + await writeConfigFile(); | |
165 | + | |
166 | + res.redirect(`${req.baseUrl}`); | |
167 | +} | |
168 | + | |
169 | +async function modemDelete(req, res) { | |
170 | + const modemName = (req.body.name || '').trim(); | |
171 | + | |
172 | + const index = config.modems.findIndex( | |
173 | + (item) => item.name.toUpperCase() === modemName.toUpperCase(), | |
174 | + ); | |
175 | + | |
176 | + if (index < 0) { | |
177 | + res.end('Modem tidak ditemukan'); | |
178 | + return; | |
179 | + } | |
180 | + | |
181 | + config.modems.splice(index, 1); | |
182 | + | |
183 | + await writeConfigFile(); | |
184 | + | |
185 | + res.redirect(`${req.baseUrl}`); | |
186 | +} | |
187 | + | |
188 | +router.get('/', (req, res) => { | |
189 | + res.redirect(`${req.baseUrl}/modem`); // sementara redirect ke modem | |
190 | +}); | |
191 | + | |
192 | +router.get('/modem', pageMain); | |
193 | +router.post('/modem/add', express.urlencoded({ extended: true }), modemAdd); | |
194 | +router.post('/modem/add-prefix', express.urlencoded({ extended: true }), modemAddPrefix); | |
195 | +router.post('/modem/update-imsi', express.urlencoded({ extended: true }), modemUpdateImsi); | |
196 | +router.post('/modem/update-custom-ip', express.urlencoded({ extended: true }), modemUpdateCustomIp); | |
197 | +router.post('/modem/delete', express.urlencoded({ extended: true }), modemDelete); | |
86 | 198 | router.get('/modem/set-outgoing/:modemName/:newValue', pageSetOutgoing); |
87 | 199 | router.get('/modem/del-prefix/:modemName/:prefix', pageDelPrefix); |
webadmin-views/config.include.addmodem.html
... | ... | @@ -3,6 +3,26 @@ |
3 | 3 | <h3>Tambah Modem</3> |
4 | 4 | </div> |
5 | 5 | <div class="card-body"> |
6 | - | |
6 | + <form method="post" action="{{ baseUrl }}/modem/add"> | |
7 | + <div class="form-group"> | |
8 | + <label for="modem-name">Nama</label> | |
9 | + <input type="text" id="modem-name" name="name" class="form-control" placeholder="Masukkan nama" required> | |
10 | + </div> | |
11 | + <div class="form-group"> | |
12 | + <label for="modem-outgoing">Outgoing</label> | |
13 | + <input type="checkbox" id="modem-outgoing" name="outgoing"> | |
14 | + </div> | |
15 | + <div class="form-group"> | |
16 | + <label for="modem-imsi">IMSI</label> | |
17 | + <input type="text" id="modem-imsi" name="imsi" class="form-control" placeholder="Masukkan IMSI"> | |
18 | + </div> | |
19 | + <div class="form-group"> | |
20 | + <label for="modem-prefix">Prefix</label> | |
21 | + <input type="text" id="modem-prefix" name="prefix" class="form-control" | |
22 | + placeholder="Masukkan Prefix pisahkan dengan koma" | |
23 | + > | |
24 | + </div> | |
25 | + <button type="submit" class="btn btn-primary">Save</button> | |
26 | + </form> | |
7 | 27 | </div> |
8 | 28 | </div> |
9 | 29 | \ No newline at end of file |
webadmin-views/config.index.html
... | ... | @@ -34,9 +34,13 @@ |
34 | 34 | <dd class="col-sm-9"> |
35 | 35 | {{ modem.imsi or '-' }} |
36 | 36 | <br> |
37 | - [<a href="{{ baseUrl }}/modem/set-imsi/{{ modem.name | urlencode }}"> | |
38 | - edit | |
39 | - </a>] | |
37 | + <form method="post" action="{{ baseUrl }}/modem/update-imsi" class="form-inline"> | |
38 | + <input type="hidden" name="name" value="{{ modem.name | urlencode }}"> | |
39 | + <div class="form-group"> | |
40 | + <input type="text" name="imsi" class="form-control" placeholder="Update IMSI"> | |
41 | + </div> | |
42 | + <button type="submit" class="btn btn-primary">Save</button> | |
43 | + </form> | |
40 | 44 | </dd> |
41 | 45 | </dl> |
42 | 46 | |
... | ... | @@ -50,26 +54,47 @@ |
50 | 54 | </a> |
51 | 55 | <br> |
52 | 56 | {% endfor %} |
53 | - | |
54 | - [ | |
55 | - <a href="{{ baseUrl }}/modem/add-prefix/{{ modem.name | urlencode }}"> | |
56 | - tambah | |
57 | - </a> | |
58 | - ] | |
57 | + <form method="post" action="{{ baseUrl }}/modem/add-prefix" class="form-inline"> | |
58 | + <input type="hidden" name="name" value="{{ modem.name | urlencode }}"> | |
59 | + <div class="form-group"> | |
60 | + <input type="text" name="prefix" class="form-control" placeholder="Masukkan prefix baru"> | |
61 | + </div> | |
62 | + <button type="submit" class="btn btn-primary">Save</button> | |
63 | + </form> | |
59 | 64 | </dd> |
60 | 65 | </dl> |
61 | - | |
62 | 66 | <dl class="row"> |
63 | 67 | <dt class="col-sm-3">Custom IP</dt> |
64 | 68 | <dd class="col-sm-9"> |
65 | - {{ modem.ip or 'none' }} | |
66 | 69 | <br> |
67 | - [<a href="{{ baseUrl }}/modem/set-ip/{{ modem.name | urlencode }}"> | |
68 | - edit | |
69 | - </a>] | |
70 | + <form method="post" action="{{ baseUrl }}/modem/update-custom-ip"> | |
71 | + <input type="hidden" name="name" value="{{ modem.name | urlencode }}"> | |
72 | + <div class="form-group"> | |
73 | + <input type="text" name="url" class="form-control" placeholder="Masukkan URL" value="{{ modem.url }}"> | |
74 | + </div> | |
75 | + <div class="form-group"> | |
76 | + <input type="text" name="username" class="form-control" placeholder="Masukkan Username" value="{{ modem.username }}"> | |
77 | + </div> | |
78 | + <div class="form-group"> | |
79 | + <input type="password" name="password" class="form-control" placeholder="Masukkan Password" value="{{ modem.password }}"> | |
80 | + </div> | |
81 | + <button type="submit" class="btn btn-primary">Save</button> | |
82 | + </form> | |
83 | + </dd> | |
84 | + </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> | |
70 | 96 | </dd> |
71 | 97 | </dl> |
72 | - | |
73 | 98 | </div> |
74 | 99 | </div> |
75 | 100 | <br> |