Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Feature/wlan security #16

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ lib/

# Ignore Jekyll site folder.
_site/

# Ignore IntelliJ files.
.idea
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fritzbox.js",
"version": "2.0.1",
"version": "2.1.0",
"author": "@lesander",
"description": "The most powerful Fritz!Box API for NodeJS.",
"homepage": "https://git.io/fritzbox",
Expand Down
2 changes: 1 addition & 1 deletion src/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fritzFormat.callsCsvToJson = (csvData) => {
// the csv to json module can parse them correctly.
let parsableCsvData = csvData
.replace('sep=;', '')
.replace('Extension;Telephone number', 'Extension;NumberSelf')
.replace('Extension;Telephone Number', 'Extension;NumberSelf')
.replace('Telephone number', 'Number')
.trim()

Expand Down
6 changes: 5 additions & 1 deletion src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ fritzRequest.request = async (path, method, options, pipe = false, formData = fa
options.sid = sessionId
}

if (typeof formUrlEncoded === 'object') {
formUrlEncoded.sid = options.sid
}

if (typeof options.removeSidFromUri === 'undefined') {
options.removeSidFromUri = false
}

// Add SID to path if one has been given to us.
if (options.sid && options.removeSidFromUri !== true && options.noAuth !== true) {
if (options.sid && options.removeSidFromUri !== true && options.noAuth !== true && !formUrlEncoded.hasOwnProperty('sid')) {
path += '&sid=' + options.sid
}

Expand Down
39 changes: 39 additions & 0 deletions src/wlan.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
/**
* @module fritzWlan
*/

let fritzWlan = {}

const fritzRequest = require('./request.js')

fritzWlan.getWlanNetwork = async (options) => {
const form = {
page: 'wSet'
}

const response = await fritzRequest.request('/data.lua', 'POST', options, false, false, form)
if (response.error) return response

return JSON.parse(response.body).data.wlanSettings
}

fritzWlan.getWlanSecurity = async (options) => {
const form = {
page: 'wKey'
}

const response = await fritzRequest.request('/data.lua', 'POST', options, false, false, form)
if (response.error) return response

return JSON.parse(response.body).data.wlan
}

fritzWlan.getWlanGuest = async (options) => {
const form = {
page: 'wGuest'
}

const response = await fritzRequest.request('/data.lua', 'POST', options, false, false, form)
if (response.error) return response

return JSON.parse(response.body).data.guestAccess
}

module.exports = fritzWlan
1 change: 1 addition & 0 deletions test/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ node --harmony-async-await test/activecalls.js # async ready
node --harmony-async-await test/markread.js # async ready
node --harmony-async-await test/tamdownload.js # async ready
node --harmony-async-await test/toggleswitch.js # async ready
node --harmony-async-await test/wlanSecurity.js # async ready

echo " ✓ Finished with tests."
30 changes: 30 additions & 0 deletions test/wlanSecurity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fritz = require('../index.js')
const options = require('../package.json').options

async function wlanSecurity () {
const network = await fritz.getWlanNetwork(options)
const security = await fritz.getWlanSecurity(options)
const guest = await fritz.getWlanGuest(options)

if (network.error) {
console.log('Error:', network.error.message)
process.exit(1)
}

if (security.error) {
console.log('Error:', security.error.message)
process.exit(1)
}

console.log(`WLAN Info:\n` +
`\tSSID: ${security.ssid}\n` +
`\tPSK: ${security.psk}\n` +
`\tHidden: ${network.hiddenSSID}`)

console.log(`Guest WLAN Info:\n` +
`\tSSID: ${guest.ssid}\n` +
`\tPSK: ${guest.psk}\n` +
`\tEnabled: ${guest.isEnabled}`)
}

wlanSecurity()