New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fritznode

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fritznode - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

examples/test.js

32

examples/devices.js
/**
* This example shows currently connected devices.
* This example shows currently connected devices as table result.
*

@@ -8,15 +8,31 @@ * Try out with : node examples/devices.js

// Helper function
const fix = (val, expected, fillup=' ') => {
let ret = val;
if( ret.length>expected ) {
ret = val.substring(0, expected-3 )+'...';
} else {
while (ret.length<expected) ret += fillup;
}
return ret;
}
run = async()=>{
let con = await fritz.fritz();
let devices = await con.getDeviceList();
console.log(JSON.stringify(devices,' ',' '));
// Example how to block/unblock a device
/*for( n=0; n<devices.length; n++ ) {
console.log( fix("Name", 30) + fix("IP", 25) + fix("Type", 10) + fix("ID", 20));
console.log( fix("", 110, '-'));
for( n=0; n<devices.length; n++ ) {
let d = devices[n];
if( d.name.startsWith('MyDevice') ) {
console.log('Unblocking device : '+d.name+' with id '+d.id);
let ret = await con.changeDeviceBlockState(d.id);
if(d.active) { // Only active devices
console.log(
fix(d.name, 30)
+ fix(d.ip, 25)
+ fix(d.type, 10)
+ fix(d.id, 20)
+ (d.blocked? 'blocked' : '')
);
}
}*/
}
};
run();

@@ -103,10 +103,9 @@ /**

active : active,
ip : raw.ipv4 || raw.ipv6,
port : raw.port,
state : raw.state,
blocked : raw.state == 'globe_notallowed'
ip : (raw.ipv4 ? raw.ipv4.ip : (raw.ipv6 ? raw.ipv6.ip : null)),
ipv4 : (raw.ipv4 ? true : false),
ipv6 : (raw.ipv6 ? true : false),
blocked : raw.state.class == 'globe_notallowed',
}
}
return {
const fritzHandler = {
sid : context.sid,

@@ -131,50 +130,69 @@ getDeviceList : async ()=>{

},
getDeviceDetails : async (deviceid)=>{
log.info("Get details for device "+deviceid);
getDeviceDetails : async (deviceId)=>{
log.info("Get device details for id "+deviceId);
let data = await http.postForm(createPath('data.lua'), {
sid : context.sid,
xhrId: 'all',
dev: deviceId,
xhr: 1,
page : 'edit_device',
dev: deviceid
page : 'edit_device'
});
return {
id: data.vars.dev.UID,
mac: data.vars.dev.mac,
name: data.vars.dev.name.displayName,
blocked: data.vars.dev.netAccess.kisi.isDeviceBlocked
let dataObj = JSON.parse(data).data.vars.dev;
let resp = {
id : dataObj.UID,
mac : dataObj.mac,
name : dataObj.name.dnsName,
active : dataObj.state == 'ONLINE',
port : dataObj.devType
}
let topologyArray = dataObj.topology.path.path;
if( topologyArray && topologyArray.length>0 ){
resp.user = topologyArray[topologyArray.length-1].device.user_UIDs;
} else {
log.warn("No toplogy entries found");
}
return resp;
},
toggleDeviceBlockState : async (deviceid)=>{
log.info("Toggle block for device "+deviceid);
blockDevice : async (deviceId)=>{
log.info("Blocking device "+deviceId);
let payload = {
xhr: 1,
sid : context.sid,
blocked: true,
toBeBlocked: deviceId,
page: 'kidLis'
}
let data = await http.postForm(createPath('data.lua'), payload);
let dataObj = JSON.parse(data).data;
return dataObj.toBeBlocked === 'ok';
},
unblockDevice : async (deviceId)=>{
log.info("Unblocking device "+deviceId);
// We have to get the device details to get the device user id - the deviceid alone does not work
let deviceDetails = await fritzHandler.getDeviceDetails(deviceId);
let userId = deviceDetails.user;
log.info("Device with id "+deviceId+" has user id "+userId);
let payload = {
xhr: 1,
dev: deviceid,
block_dev: '',
page: 'edit_device',
xhr: 1,
back_to_page: 'netDev',
lang: 'de'
sid : context.sid,
blocked : false,
toBeBlocked: userId,
page: 'kidLis'
}
/*if( blocked ) { // This does not work - only toggle seems possible
payload.kisi_profile='filtprof1' // always filtprof1?
}*/
let data = await http.postForm(createPath('data.lua'), payload);
return true;
let dataObj = JSON.parse(data).data;
return dataObj.toBeBlocked === 'ok';
},
getBandwithUsage: async() => {
let data = await http.get(createPath('/internet/inetstat_monitor.lua',
{ action:'get_graphic',
xhr:1,
myXhr:1,
useajax:1
})
);
let data = await http.postForm(createPath('data.lua'), {
sid : context.sid,
page : 'netMoni'
});
let dataObj = JSON.parse(data);
let syncGroup = dataObj.data.sync_groups[0];
return {
downMax : dataObj[0].downstream,
downCurrent : dataObj[0].ds_bps_curr[0]*8,
upMax : dataObj[0].upstream,
upCurrent : dataObj[0].us_default_bps_curr[0]*8
downMax : syncGroup.downstream,
downCurrent : syncGroup.ds_bps_curr[0]*8,
upMax : syncGroup.upstream,
upCurrent : syncGroup.us_default_bps_curr[0]*8
}

@@ -188,3 +206,2 @@ },

let dataObj = JSON.parse(data).data;
log.info("Overview list : "+JSON.stringify(dataObj,2,2));
return {

@@ -215,2 +232,3 @@ powerConsumption : parseInt(dataObj.fritzos.energy),

}
return fritzHandler;
}
{
"name": "fritznode",
"version": "0.0.4",
"version": "0.0.5",
"description": "Fritz box API access",

@@ -22,3 +22,3 @@ "main": "index.js",

"dependencies": {
"simple-get": "^3.1.0",
"simple-get": "^4.0.1",
"xml2js-parser": "^1.1.1"

@@ -25,0 +25,0 @@ },

@@ -17,6 +17,19 @@ Fritz Node

- toggleDeviceBlockState
- blockDevice
Blocks or unblocks the device internet access.
Blocks the device internet access.
- unblockDevice
Unblocks the device internet access.
- getOverview
Gets overview information about your fritz.box
- GetNAS
Shows information about your fritz.box NAS
Example:

@@ -44,3 +57,5 @@ ```javascript

See the examples folder for more usage scenarios.
Environment variables supported

@@ -47,0 +62,0 @@ -------------------------------

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc