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

stephendade / Rpanion-server / 19204169944

09 Nov 2025 05:49AM UTC coverage: 34.547% (-1.1%) from 35.678%
19204169944

Pull #342

github

web-flow
Merge 9bcb15a56 into 6694db97a
Pull Request #342: Remove react-select controls in favour of Form.Select

316 of 1186 branches covered (26.64%)

Branch coverage included in aggregate %.

20 of 61 new or added lines in 6 files covered. (32.79%)

31 existing lines in 2 files now uncovered.

993 of 2603 relevant lines covered (38.15%)

2.63 hits per line

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

9.39
/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(':')
13✔
13
        if (device.length === 3 && device[1] !== 'loopback' && device[1] !== 'bridge' && device[1] !== 'wifi-p2p' && device[1] !== 'can0' && device[1] !== 'can1') {
13✔
14
          console.log('Adding Network device ' + device[0])
4✔
15
          // if wifi, check for avail channels
16
          const freqList = []
4✔
17
          freqList.push({ value: 0, freq: 0, label: 'auto', band: 0 })
4✔
18
          if (device[1] === 'wifi') {
4!
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) {
×
NEW
26
                    freqList.push({ value: parseInt(ln[1]), freq: ln[3], label: '' + 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')) })
4!
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
          // if not ascii, return
NEW
166
          if (!/^[\x00-\x7F]*$/.test(current.ssid)) {
×
NEW
167
            return;
×
168
          }
169
        }
170

171
        if (line.startsWith("signal:")) {
×
172
          const dBm = parseFloat(line.split(" ")[1]);
×
173
          current.signal = dBm;
×
174
        }
175

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

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

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

296
function editConnectionAttached (conName, conSettings, callback) {
297
  // edit the attached interface for a connection
NEW
298
  if (conSettings.attachedIface === '&quot;&quot;' || conSettings.attachedIface === 'undefined') {
×
NEW
299
    conSettings.attachedIface = '""'
×
300
  }
301

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

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

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

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

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

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

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

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

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

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

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

571
module.exports = {
3✔
572
  getAdapters,
573
  getConnections,
574
  getConnectionDetails,
575
  activateConnection,
576
  deleteConnection,
577
  editConnection,
578
  addConnection,
579
  deactivateConnection,
580
  getWirelessStatus,
581
  setWirelessStatus,
582
  getWifiScan
583
}
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