• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stephendade / Rpanion-server / 17876680255

20 Sep 2025 06:49AM UTC coverage: 35.979% (-0.3%) from 36.26%
17876680255

push

github

stephendade
Dev: Fix vite cross-architecture issue

322 of 1161 branches covered (27.73%)

Branch coverage included in aggregate %.

1020 of 2569 relevant lines covered (39.7%)

2.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

9.46
/server/networkManager.js
1
const { exec, execSync, execFile } = require('child_process')
3✔
2

3
function getAdapters (callback) {
4
  // Get all network adapter name, type and states
5
  exec('sudo nmcli -t -f device,type,state dev', (error, stdout, stderr) => {
3✔
6
    const netStatusList = []
3✔
7
    if (stderr) {
3!
8
      console.error(`exec error: ${error}`)
×
9
      return callback(stderr)
×
10
    } else {
11
      stdout.split('\n').forEach(function (item) {
3✔
12
        const device = item.split(':')
12✔
13
        if (device.length === 3 && device[1] !== 'loopback' && device[1] !== 'bridge' && device[1] !== 'wifi-p2p' && device[1] !== 'can0' && device[1] !== 'can1') {
12✔
14
          console.log('Adding Network device ' + device[0])
3✔
15
          // if wifi, check for avail channels
16
          const freqList = []
3✔
17
          freqList.push({ value: 0, freq: 0, text: 'auto', band: 0 })
3✔
18
          if (device[1] === 'wifi') {
3!
19
            try {
×
20
              const output = execSync('iwlist ' + device[0] + ' channel')
×
21
              const allFreqs = output.toString().split('\n')
×
22
              for (let i = 0, len = allFreqs.length; i < len; i++) {
×
23
                if (allFreqs[i].includes('Channel ') && !allFreqs[i].includes('Current')) {
×
24
                  const ln = allFreqs[i].split(' ').filter(i => i)
×
25
                  if (ln.length > 4) {
×
26
                    freqList.push({ value: parseInt(ln[1]), freq: ln[3], text: '' + ln[1] + ' (' + ln[3] + ' GHz)', band: ((parseFloat(ln[3]) < 3) ? 'bg' : 'a') })
×
27
                  }
28
                }
29
              }
30
            } catch (e) {
31
              console.error('exec error: ' + e)
×
32
              return callback(e)
×
33
            }
34
          }
35
          netStatusList.push({ value: device[0], label: device[0] + ' (' + device[1] + ')', type: device[1], state: device[2], channels: freqList, isDisabled: !!((device[2] === 'unavailable' && device[1] === 'wifi')) })
3!
36
        }
37
      })
38
    }
39
    return callback(null, netStatusList)
3✔
40
  })
41
}
42

43
function getWirelessStatus (callback) {
44
  // get the "flight mode" status of the wireless (wifi) adapters
45
  exec('sudo nmcli -t radio wifi', (error, stdout, stderr) => {
×
46
    if (stderr) {
×
47
      console.error(`exec error: ${error}`)
×
48
      return callback(stderr)
×
49
    } else {
50
      console.log('Wifi is ' + stdout)
×
51
      if (stdout === 'enabled\n') {
×
52
        return callback(null, true)
×
53
      } else {
54
        return callback(null, false)
×
55
      }
56
    }
57
  })
58
}
59

60
function setWirelessStatus (status, callback) {
61
  exec('sudo nmcli radio wifi ' + ((status === true) ? 'on' : 'off') + ' && sudo nmcli -t radio wifi', (error, stdout, stderr) => {
×
62
    if (stderr) {
×
63
      console.error(`exec error: ${error}`)
×
64
      return callback(stderr)
×
65
    } else {
66
      if (stdout === 'enabled\n') {
×
67
        return callback(null, true)
×
68
      } else {
69
        return callback(null, false)
×
70
      }
71
    }
72
  })
73
}
74

75
function activateConnection (conName, callback) {
76
  // activate the connection (by id)
77
  // assumed that conName is a valid UUID
78
  execFile('sudo', ['nmcli', 'connection', 'mod', conName, 'connection.autoconnect', 'yes'], (error, stdout, stderr) => {
×
79
    if (stderr) {
×
80
      console.error(`exec error: ${error}`)
×
81
      return callback(stderr)
×
82
    } else {
83
      execFile('sudo', ['nmcli', 'connection', 'up', conName], (error, stdout, stderr) => {
×
84
        if (stderr) {
×
85
          console.error(`exec error: ${error}`)
×
86
          return callback(stderr)
×
87
        } else {
88
          console.log('Activated network: ' + conName)
×
89
          return callback(null, 'OK')
×
90
        }
91
      })
92
    }
93
  })
94
}
95

96
function deactivateConnection (conName, callback) {
97
  // deactivate the connection (by id)
98
  // assumed that conName is a valid UUID
99
  // need to disable auto-connect too
100
  execFile('sudo', ['nmcli', 'connection', 'mod', conName, 'connection.autoconnect', 'no'], (error, stdout, stderr) => {
×
101
    if (stderr) {
×
102
      console.error(`exec error: ${error}`)
×
103
      return callback(stderr)
×
104
    } else {
105
      execFile('sudo', ['nmcli', 'connection', 'down', conName], (error, stdout, stderr) => {
×
106
        if (stderr) {
×
107
          console.error(`exec error: ${error}`)
×
108
          return callback(stderr)
×
109
        } else {
110
          console.log('Dectivated network: ' + conName)
×
111
          return callback(null, 'OK')
×
112
        }
113
      })
114
    }
115
  })
116
}
117

118
function getPrimaryWifiDevice(callback) {
119
  exec('iw dev | grep Interface | awk \'{print $2}\'', (error, stdout, stderr) => {
×
120
      if (error) {
×
121
          console.error(`exec error: ${error}`)
×
122
          return callback(error)
×
123
      }
124
      if (stderr) {
×
125
          console.error(`stderr: ${stderr}`)
×
126
          return callback(new Error(stderr))
×
127
      }
128
      const device = stdout.trim().split('\n')[0]
×
129
      callback(null, device)
×
130
  });
131
}
132

133
function getWifiScan(callback) {
134
  getPrimaryWifiDevice((error, device) => {
×
135
    if (error) {
×
136
      return callback(error)
×
137
    }
138

139
    exec(`sudo iw dev ${device} scan ap-force`, (error, stdout, stderr) => {
×
140
      if (error) {
×
141
        console.error(`exec error: ${error}`)
×
142
        return callback(error)
×
143
      }
144
      if (stderr) {
×
145
        console.error(`stderr: ${stderr}`)
×
146
        return callback(new Error(stderr))
×
147
      }
148

149
      const networks = [];
×
150
      let current = null;
×
151

152
      stdout.split("\n").forEach(line => {
×
153
        line = line.trim();
×
154

155
        if (line.startsWith("BSS ")) {
×
156
          if (current) networks.push(current);
×
157
          current = { ssid: null, signal: null, security: "Open" };
×
158
          return;
×
159
        }
160

161
        if (!current) return;
×
162

163
        if (line.startsWith("SSID:")) {
×
164
          current.ssid = line.slice(5).trim();
×
165
        }
166

167
        if (line.startsWith("signal:")) {
×
168
          const dBm = parseFloat(line.split(" ")[1]);
×
169
          current.signal = dBm;
×
170
        }
171

172
        if (line.includes("RSN:")) {
×
173
          current.security = "WPA2";
×
174
        } else if (line.includes("WPA:")) {
×
175
          current.security = "WPA";
×
176
        } else if (line.includes("WEP:")) {
×
177
          current.security = "WEP";
×
178
        }
179
      });
180
      if (current) networks.push(current);
×
181
      callback(null, networks
×
182
        .filter(net => net.ssid) // Filter out entries without SSID
×
183
        .sort((a, b) => b.signal - a.signal) // Sort by signal strength descending
×
184
      );
185
    });
186
  })
187
}
188

189
function addConnection (conNameStr, conType, conAdapter, conSettings, callback) {
190
  // add a new connection with name conNameStr and settings
191
  // conSettings
192
  // nmcli connection add type wifi ifname $IFNAME con-name $APNAME ssid $SSID
193
  // due to the multiple edits, we need to set autoconnect to "no"
194
  if (conType === 'wifi') {
×
195
    exec('sudo nmcli connection add type ' + conType + ' ifname ' + conAdapter +
×
196
             ' con-name ' + conNameStr + ' ssid \'' + conSettings.ssid.value + '\' 802-11-wireless.mode ' +
197
             conSettings.mode.value + (Object.keys(conSettings.band).length ? (' 802-11-wireless.band ' + conSettings.band.value) : '') +
×
198
             (Object.keys(conSettings.channel).length ? (' 802-11-wireless.channel ' + (conSettings.channel.value === '0' ? '\'\'' : conSettings.channel.value)) : '') +
×
199
             ' ipv4.method ' + conSettings.ipaddresstype.value + ' connection.autoconnect no ' + ' && ' +
200
             'sudo nmcli -g connection.uuid con show ' + conNameStr, (error, stdout, stderr) => {
201
      if (stderr) {
×
202
        console.error(`exec error: ${error}`)
×
203
        return callback(stderr)
×
204
      } else {
205
        // once the network is created, add in the settings
206
        const conUUID = stdout.split('\n')[stdout.split('\n').length - 2]
×
207
        console.log('Added network Wifi: ' + conNameStr + ' - ' + conAdapter + ' - ' + conUUID)
×
208
        this.editConnection(conUUID, conSettings, (err) => {
×
209
          // set autoconnect back to "yes"
210
          exec('sudo nmcli connection mod ' + conUUID + ' connection.autoconnect yes', (error, stdout, stderr) => {
×
211
            if (!err && !stderr) {
×
212
              console.log('addConnection() wifi OK')
×
213
              return callback(null, 'AddOK')
×
214
            } else {
215
              console.log('Error in editConnection() wifi addcon ', { message: err })
×
216
              console.log('Error in editConnection() wifi addcon ', { message: stderr })
×
217
              return callback(err)
×
218
            }
219
          })
220
        })
221
      }
222
    })
223
  } else {
224
    exec('sudo nmcli connection add type ' + conType + ' ifname ' + conAdapter +
×
225
             ' con-name ' + conNameStr + ' connection.autoconnect no ' + '&&' +
226
             'sudo nmcli -g connection.uuid con show ' + conNameStr, (error, stdout, stderr) => {
227
      if (stderr) {
×
228
        console.error(`exec error: ${error}`)
×
229
        return callback(stderr)
×
230
      } else {
231
        // once the network is created, add in the settings
232
        const conUUID = stdout.split('\n')[stdout.split('\n').length - 2]
×
233
        console.log('Added network Wired: ' + conNameStr + ' - ' + conAdapter + ' - ' + conUUID)
×
234
        this.editConnection(conUUID, conSettings, (err) => {
×
235
          // set autoconnect back to "yes"
236
          exec('sudo nmcli connection mod ' + conUUID + ' connection.autoconnect yes', (error, stdout, stderr) => {
×
237
            if (!err && !stderr) {
×
238
              console.log('addConnection() wired OK')
×
239
              return callback(null, 'AddOK')
×
240
            } else {
241
              console.log('Error in editConnection() wired addcon ', { message: err })
×
242
              console.log('Error in editConnection() wired addcon ', { message: stderr })
×
243
              return callback(err)
×
244
            }
245
          })
246
        })
247
      }
248
    })
249
  }
250
}
251

252
function editConnection (conName, conSettings, callback) {
253
  // edit an existing connection
254
  // assumed that conName is a valid UUID
255
  // there are 4 types of edits - AttachedInterface, IP, Wifi security, Wifi AP
256
  // small amount of callback hell here :(
257
  console.log(conSettings)
×
258
  editConnectionAttached(conName, conSettings, (errAttach) => {
×
259
    console.log('Attach')
×
260
    if (!errAttach) {
×
261
      editConnectionIP(conName, conSettings, (errIP) => {
×
262
        console.log('IP')
×
263
        if (!errIP) {
×
264
          editConnectionPSK(conName, conSettings, (errPSK) => {
×
265
            console.log('PSK')
×
266
            if (!errPSK) {
×
267
              editConnectionAPClient(conName, conSettings, (errAP) => {
×
268
                console.log('AP')
×
269
                if (!errAP) {
×
270
                  return callback(null, 'EditOK')
×
271
                } else {
272
                  return callback(errAP)
×
273
                }
274
              })
275
            } else {
276
              console.log('Error in editConnection() errPSK ', { message: errPSK })
×
277
              return callback(errPSK)
×
278
            }
279
          })
280
        } else {
281
          console.log('Error in editConnection() errIP ', { message: errIP })
×
282
          return callback(errIP)
×
283
        }
284
      })
285
    } else {
286
      console.log('Error in editConnection() errAttach ', { message: errAttach })
×
287
      return callback(errAttach)
×
288
    }
289
  })
290
}
291

292
function editConnectionAttached (conName, conSettings, callback) {
293
  // edit the attached interface for a connection
294
  if (conSettings.attachedIface.value === '&quot;&quot;' || conSettings.attachedIface.value === 'undefined') {
×
295
    conSettings.attachedIface.value = '""'
×
296
  }
297

298
  execFile('sudo', ['nmcli', 'connection', 'mod', conName, 'connection.interface-name', conSettings.attachedIface.value], (error, stdout, stderr) => {
×
299
    if (stderr) {
×
300
      console.error(`exec error: ${error}`)
×
301
      return callback(stderr)
×
302
    } else {
303
      console.log('Edited network Attachment: ' + conName + ' to ' + conSettings.attachedIface.value)
×
304
      return callback(null, 'EditAttachOK')
×
305
    }
306
  })
307
}
308

309
function editConnectionIP (conName, conSettings, callback) {
310
  // first sort out the IP Addressing (DHCP/static) for LAN and Wifi Client
311
  if (Object.keys(conSettings.ssid).length === 0 || conSettings.mode.value === 'infrastructure') {
×
312
    if (conSettings.ipaddresstype.value === 'auto') {
×
313
      execFile('sudo', ['nmcli', 'connection', 'mod', conName, 'ipv4.method', 'auto', 'ipv4.addresses', ''], (error, stdout, stderr) => {
×
314
        if (stderr) {
×
315
          console.error(`exec error: ${error}`)
×
316
          return callback(stderr)
×
317
        } else {
318
          console.log('Edited network IP Auto: ' + conName)
×
319
          return callback(null, 'EditOK')
×
320
        }
321
      })
322
    } else if (Object.keys(conSettings.ipaddress).length !== 0 && Object.keys(conSettings.subnet).length !== 0) {
×
323
      execFile('sudo', ['nmcli', 'connection', 'mod', conName, 'ipv4.addresses', conSettings.ipaddress.value + '/' +
×
324
        netmask2CIDR(conSettings.subnet.value), 'ipv4.method', conSettings.ipaddresstype.value], (error, stdout, stderr) => {
325
        if (stderr) {
×
326
          console.error(`exec error: ${error}`)
×
327
          return callback(stderr)
×
328
        } else {
329
          console.log('Edited network IP manual: ' + conName)
×
330
          return callback(null, 'EditOK')
×
331
        }
332
      })
333
    }
334
  } else {
335
    console.log('editConnectionIP() not required')
×
336
    return callback(null, 'EditNotRequired')
×
337
  }
338
}
339

340
function editConnectionPSK (conName, conSettings, callback) {
341
  // now sort out Wifi client/ap settings - password and security type
342
  if (Object.keys(conSettings.mode).length === 0) {
×
343
    return callback(null, 'EditNotRequired')
×
344
  }
345
  if (conSettings.mode.value === 'infrastructure' || conSettings.mode.value === 'ap') {
×
346
    // psk network
347
    if (conSettings.wpaType.value !== 'none' &&
×
348
            Object.keys(conSettings.ssid).length !== 0 &&
349
            Object.keys(conSettings.password).length !== 0) {
350
            execFile('sudo', ['nmcli', 'connection', 'mod', conName, '802-11-wireless-security.key-mgmt', conSettings.wpaType.value], (error, stdout, stderr) => {
×
351
        if (stderr) {
×
352
          console.error(`exec error: ${error}`)
×
353
          return callback(stderr)
×
354
        } else {
355
          execFile('sudo', ['nmcli', '-s', 'connection', 'mod', conName, '802-11-wireless-security.pairwise', 'ccmp', '802-11-wireless-security.psk', conSettings.password.value], (error, stdout, stderr) => {
×
356
            if (stderr) {
×
357
              console.error(`exec error: ${error}`)
×
358
              return callback(stderr)
×
359
            } else {
360
              console.log('Edited Wifi psk: ' + conName)
×
361
              return callback(null, 'OK')
×
362
            }
363
          })
364
        }
365
      })
366
    }
367
    else if (conSettings.wpaType.value === 'none' &&
×
368
                 Object.keys(conSettings.ssid).length !== 0) {
369
      execFile('sudo', ['nmcli', 'connection', 'mod', conName, 'remove', '802-11-wireless-security'], (error, stdout, stderr) => {
×
370
        if (stderr) {
×
371
          console.error(`exec error: ${error}`)
×
372
          return callback(stderr)
×
373
        } else {
374
          console.log('Edited Wifi no-psk: ' + conName)
×
375
          return callback(null, 'OK')
×
376
        }
377
      })
378
    }
379
  } else {
380
    console.log('editConnectionPSK() not required')
×
381
    return callback(null, 'EditNotRequired')
×
382
  }
383
}
384

385
function editConnectionAPClient (conName, conSettings, callback) {
386
  // now sort out Wifi ap or client settings - ssid, band, starting ip
387
  if (Object.keys(conSettings.mode).length === 0) {
×
388
    return callback(null, 'EditNotRequired')
×
389
  }
390
  if (conSettings.mode.value === 'ap') {
×
391
    if (Object.keys(conSettings.ssid).length !== 0 &&
×
392
            Object.keys(conSettings.band).length !== 0 &&
393
            Object.keys(conSettings.channel).length !== 0 &&
394
            Object.keys(conSettings.ipaddress).length !== 0) {
395
      const cmds = ['nmcli', 'connection', 'mod', conName, '802-11-wireless.ssid', conSettings.ssid.value,
×
396
        '802-11-wireless.band', conSettings.band.value, 'ipv4.addresses', conSettings.ipaddress.value + '/24']
397
      if (conSettings.channel.value !== '0') {
×
398
        cmds.push('802-11-wireless.channel', conSettings.channel.value)
×
399
      }
400
      if (conSettings.wpaType.value !== 'none') {
×
401
        cmds.push('802-11-wireless-security.group', 'ccmp', '802-11-wireless-security.wps-method', '1')
×
402
      }
403
      execFile('sudo', cmds, (error, stdout, stderr) => {
×
404
        if (stderr) {
×
405
          console.error(`exec error: ${error}`)
×
406
          return callback(stderr)
×
407
        } else {
408
          console.log('Edited Wifi ap ssid/band: ' + conName)
×
409
          return callback(null, 'OK')
×
410
        }
411
      })
412
    } else {
413
      console.log('Badsettings in editConnectionAPClient')
×
414
      console.log(conSettings)
×
415
      return callback(null, 'BADARGS')
×
416
    }
417
  } else {
418
    // client connection - edit ssid if required
419
    if (Object.keys(conSettings.ssid).length !== 0) {
×
420
      execFile('sudo', ['nmcli', 'connection', 'mod', conName, '802-11-wireless.ssid', conSettings.ssid.value], (error, stdout, stderr) => {
×
421
        if (stderr) {
×
422
          console.error(`exec error: ${error}`)
×
423
          return callback(stderr)
×
424
        } else {
425
          console.log('Edited Wifi client ssid: ' + conName)
×
426
          return callback(null, 'OK')
×
427
        }
428
      })
429
    } else {
430
      console.log('Badsettings in editConnectionAPClient')
×
431
      console.log(conSettings)
×
432
      return callback(null, 'BADARGS')
×
433
    }
434
  }
435
}
436

437
function deleteConnection (conName, callback) {
438
  // delete the connection (by id)
439
  // assumed that conName is a valid UUID
440
  execFile('sudo', ['nmcli', 'connection', 'delete', conName], (error, stdout, stderr) => {
×
441
    if (stderr) {
×
442
      console.error(`exec error: ${error}`)
×
443
      return callback(stderr)
×
444
    } else {
445
      console.log('Deleted network: ' + conName)
×
446
      return callback(null, 'OK')
×
447
    }
448
  })
449
}
450

451
function getConnections (callback) {
452
  let output = ''
3✔
453
  const conStatusList = []
3✔
454
  try {
3✔
455
    output = execSync('sudo nmcli -t -f NAME,UUID,TYPE,DEVICE connection show')
3✔
456
  } catch (e) {
457
    console.error('exec error: ' + e)
×
458
    return callback(e)
×
459
  }
460

461
  const allConns = output.toString().split('\n')
3✔
462
  for (let i = 0, len = allConns.length; i < len; i++) {
3✔
463
    const item = allConns[i]
3✔
464
    const connection = item.split(':')
3✔
465
    let curConn = {}
3✔
466
    let subout = ''
3✔
467
    if (connection.length == 4 || connection.length == 3) {
3!
468
      try {
×
469
        subout = execSync('sudo nmcli -s -t -f connection.interface-name connection show ' + connection[1])
×
470
        subout = subout.toString().split(':')[1].trim()
×
471
      } catch (e) {
472
        console.error('exec error: ' + e)
×
473
        // return callback("");
474
      }
475
    }
476
    if (connection[3] === '' || connection[3] === '--') {
3!
477
      curConn = { value: connection[1], label: '', labelPre: connection[0], type: connection[2], state: '', attachedIface: subout }
×
478
      conStatusList.push(curConn)
×
479
    } else if (connection.length === 4) {
3!
480
      // active connection
481
      curConn = { value: connection[1], label: '', labelPre: connection[0], type: connection[2], state: connection[3], attachedIface: subout }
×
482
      conStatusList.push(curConn)
×
483
    }
484
    // if we're at the end, return callback
485
    if (i === allConns.length - 1) {
3!
486
      console.log('getConnections() got: ' + allConns.length)
3✔
487
      return callback(null, conStatusList)
3✔
488
    }
489
  }
490
}
491

492
function getConnectionDetails (conName, callback) {
493
  execFile('sudo', ['nmcli', '-s', '-t', '-f', 'ipv4.addresses,802-11-wireless.band,ipv4.method,IP4.ADDRESS,802-11-wireless.ssid,802-11-wireless.mode,802-11-wireless-security.key-mgmt,802-11-wireless-security.psk,connection.interface-name,802-11-wireless.channel', 'connection', 'show', conName], (error, stdout, stderr) => {
×
494
    if (stderr) {
×
495
      // no connection with that name
496
      console.error(`exec error: ${error}`)
×
497
      return callback(stderr)
×
498
    } else {
499
      const ret = { DHCP: 'auto', IP: '', subnet: '', mode: '', wpaType: 'none', password: '' }
×
500
      stdout.split('\n').forEach(function (item) {
×
501
        if (item.split(':')[0] === '802-11-wireless.ssid') {
×
502
          ret.ssid = item.split(':')[1]
×
503
        } else if (item.split(':')[0] === '802-11-wireless.band') {
×
504
          if (item.split(':')[1] === '') {
×
505
            ret.band = 'bg'
×
506
          } else {
507
            ret.band = item.split(':')[1]
×
508
          }
509
        } else if (item.split(':')[0] === 'ipv4.method') {
×
510
          ret.DHCP = item.split(':')[1]
×
511
        }
512
        // DHCP IP, if using DHCP
513
        else if (item.split(':')[0] === 'IP4.ADDRESS[1]' && item.split(':').length > 1 && item.split(':')[1] !== '') {
×
514
          ret.IP = item.split(':')[1].split('/')[0]
×
515
          ret.subnet = CIDR2netmask(item.split(':')[1].split('/')[1])
×
516
        }
517
        // static IP
518
        else if (item.split(':')[0] === 'ipv4.addresses' && item.split(':').length > 1 && item.split(':')[1] !== '') {
×
519
          ret.IP = item.split(':')[1].split('/')[0]
×
520
          ret.subnet = CIDR2netmask(item.split(':')[1].split('/')[1])
×
521
        } else if (item.split(':')[0] === '802-11-wireless.mode') {
×
522
          ret.mode = item.split(':')[1]
×
523
        } else if (item.split(':')[0] === '802-11-wireless-security.key-mgmt') {
×
524
          ret.wpaType = item.split(':')[1]
×
525
        } else if (item.split(':')[0] === '802-11-wireless-security.psk') {
×
526
          ret.password = item.split(':')[1]
×
527
        } else if (item.split(':')[0] === 'connection.interface-name') {
×
528
          ret.attachedIface = item.split(':')[1]
×
529
        } else if (item.split(':')[0] === '802-11-wireless.channel') {
×
530
          ret.channel = item.split(':')[1]
×
531
        }
532
      })
533
      return callback(null, ret)
×
534
    }
535
  })
536
}
537

538
function CIDR2netmask (bitCountstr) {
539
  const mask = []
×
540
  let bitCount = parseInt(bitCountstr)
×
541
  // console.log(bitCountstr);
542
  for (let i = 0; i < 4; i++) {
×
543
    const n = Math.min(bitCount, 8)
×
544
    // console.log(bitCount);
545
    mask.push(256 - Math.pow(2, 8 - n))
×
546
    bitCount -= n
×
547
  }
548
  return mask.join('.')
×
549
}
550

551
function netmask2CIDR (mask) {
552
  let cidr = ''
×
553
  for (const m of mask.split('.')) {
×
554
    if (parseInt(m) > 255) { throw 'ERROR: Invalid Netmask' } // Check each group is 0-255
×
555
    if (parseInt(m) > 0 && parseInt(m) < 128) { throw 'ERROR: Invalid Netmask' }
×
556

557
    cidr += (m >>> 0).toString(2)
×
558
  }
559
  // Condition to check for validity of the netmask
560
  if (cidr.substring(cidr.search('0'), 32).search('1') !== -1) {
×
561
    console.log('Error in netmask2CIDR() ', { message: mask })
×
562
    throw 'ERROR: Invalid Netmask ' + mask
×
563
  }
564
  return cidr.split('1').length - 1
×
565
}
566

567
module.exports = {
3✔
568
  getAdapters,
569
  getConnections,
570
  getConnectionDetails,
571
  activateConnection,
572
  deleteConnection,
573
  editConnection,
574
  addConnection,
575
  deactivateConnection,
576
  getWirelessStatus,
577
  setWirelessStatus,
578
  getWifiScan
579
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc