Commit a204c2f54d870c99f269cb43fd1dc3fcbe11843b

Authored by Adhidarma Hadiwinoto
1 parent 63be40225f
Exists in master

APISERVER del imsi from sender list

Showing 1 changed file with 72 additions and 0 deletions Side-by-side Diff

lib/apiserver/router-config-senders.js
... ... @@ -43,6 +43,14 @@ function pageIndex(req, res) {
43 43 res.json(config.senders_imsi);
44 44 }
45 45  
  46 +function delImsi(data, imsi) {
  47 + const idx = data.indexOf(imsi);
  48 + if (idx < 0) return;
  49 +
  50 + data.splice(idx, 1);
  51 + saveConfig();
  52 +}
  53 +
46 54 function addImsi(data, imsi) {
47 55 if (data.indexOf(imsi) >= 0) {
48 56 return false;
... ... @@ -100,6 +108,32 @@ function pageAddForPrefix(req, res, next) {
100 108 next();
101 109 }
102 110  
  111 +function pageDelForPrefix(req, res) {
  112 + if (!req.query.prefix) {
  113 + res.json({
  114 + status: 'NOT-OK',
  115 + message: 'Undefined prefix',
  116 + });
  117 +
  118 + return;
  119 + }
  120 +
  121 + if (!req.query.imsi) {
  122 + res.json({
  123 + status: 'NOT-OK',
  124 + message: 'Undefined IMSI',
  125 + });
  126 +
  127 + return;
  128 + }
  129 +
  130 + delImsi(config.senders_imsi.prefix_names[req.query.prefix], req.query.imsi);
  131 + res.json({
  132 + status: 'OK',
  133 + message: 'IMSI berhasil dihapus',
  134 + });
  135 +}
  136 +
103 137 /**
104 138 * Menambahkan IMSI pada list sender untuk prefix tidak dikenal
105 139 *
... ... @@ -122,6 +156,23 @@ function pageAddForUnknownPrefix(req, res, next) {
122 156 next();
123 157 }
124 158  
  159 +function pageDelForUnknownPrefix(req, res) {
  160 + if (!req.query.imsi) {
  161 + res.json({
  162 + status: 'NOT-OK',
  163 + message: 'Undefined IMSI',
  164 + });
  165 +
  166 + return;
  167 + }
  168 +
  169 + delImsi(config.senders_imsi.unknown_prefix, req.query.imsi);
  170 + res.json({
  171 + status: 'OK',
  172 + message: 'IMSI berhasil dihapus',
  173 + });
  174 +}
  175 +
125 176 /**
126 177 * Menambahkan IMSI pada list sender default
127 178 *
... ... @@ -144,9 +195,30 @@ function pageAddForDefault(req, res, next) {
144 195 next();
145 196 }
146 197  
  198 +function pageDelForDefault(req, res) {
  199 + if (!req.query.imsi) {
  200 + res.json({
  201 + status: 'NOT-OK',
  202 + message: 'Undefined IMSI',
  203 + });
  204 +
  205 + return;
  206 + }
  207 +
  208 + delImsi(config.senders_imsi.default, req.query.imsi);
  209 + res.json({
  210 + status: 'OK',
  211 + message: 'IMSI berhasil dihapus',
  212 + });
  213 +}
147 214  
148 215 router.use(initConfig);
149 216 router.get('/', initConfig, pageIndex);
  217 +
150 218 router.get('/add-for-prefix', pageAddForPrefix, addImsiResponse);
151 219 router.get('/add-for-unknown-prefix', pageAddForUnknownPrefix, addImsiResponse);
152 220 router.get('/add-for-default', pageAddForDefault, addImsiResponse)
  221 +
  222 +router.get('/del-for-prefix', pageDelForPrefix);
  223 +router.get('/del-for-unknown-prefix', pageDelForUnknownPrefix);
  224 +router.get('/del-for-default', pageDelForDefault);