vortex-5 / ddwrt-bwmon

An Individual Bandwidth Monitor For DD-WRT
171 stars 37 forks source link

Suggestion to add more dynamic and static MAC information to mac-names.js #19

Closed monohydroxy closed 8 years ago

monohydroxy commented 8 years ago

This works for me and is very helpful. I'm adding it here as a feature request in case it will help people in general. My mac-names.js file only contained information regarding static ip's. There is more information in /tmp/dnsmasq.leases, so I added the following line to the bwmon-dnsmasq.sh file just before the DUMMY line:

cat /tmp/dnsmasq.leases | grep -v '\*' | awk '{ print "(" $2 "( : (" $4 "(," }' | tr "(" "'" >> $DYNAMIC_FILE

I had some trouble with escaping single quotes, so there may be a better way to do the single quote stuff. This captured 90% of my network, so I created a static file with the proper syntax and added the following line after the one above:

cat $SCRIPT_DIR/static-mac-names.txt >> $DYNAMIC_FILE

This one probably needs some error checking in case it doesn't exist, but in my case these two items gave me a name for every computer on my network rather than a mac address.

Thanks for the great tool!

vortex-5 commented 8 years ago

I think I would probably generate another file for the dynamic leases.

I already have one user that is overriding their static lease name with a name they have chosen in their mac-names file.

mac-names isn't just for the static leases it also retains any "personalization" the user wishes to do.

I think it is possible to incorporate your suggestion but I think instead generating 2 dynamic files would work better.

I.E. mac-names.js (user assigned) mac-names-static.js (dns masq entries) mac-names-dynamic.js (dns masq leases)

the reason I always try and make the per loop processing on the router rather minimal is to save cpu since we can just force the bwmon.js host computer do the processing instead.

In fact now that I think of it why are we generating these at all?

why can't we just ln -s the dnsmasq.conf and dnsmasq.leases file into the /tmp/www folder as js files?

that would allow read only access.

And the javascript bwmon already is able to read the raw dnsmasq.conf file for the lighttpd version.

I guess I'll work on a new version but it may be a while since an extensive change such as this would require some more testing.

Changes involved:

drop

mac-names.js being the only file it will now be used as an override file only people that have current set mac addresses in here would override whatever you set on the router. This won't break for existing users that are relying on this.

add code so on startup we do

ln -s /tmp/dnsmasq.conf /tmp/www/dnsmasq-conf.js ln -s /tmp/dnsmasq.leases /tmp/www/dnsmasq-leases.js

To save on ram the stop scripts should probably empty out the /tmp/www folders on startup only the bwmon files mind you.

we can then parse and check for new dns entries as much as we like without any adverse cost to router resources (when it comes to logging).

Note it is important that we evaluate the changes required to the lighttpd version as well since it puts the resources under a completely different directory.

vortex-5 commented 8 years ago

Oh I just checked it looks like stop.sh already has the logic to clean up after itself I only need to add the new proposed

dnsmasq-conf.js and dnsmasq-leases.js

to that list.

mac-names.js should also be substantially simpler once this update goes through since you don't have to deal with merging that file at all it's just going to be a plain static user optional override file.

Yes I'll definitely put this change in when I get time since it has the double benefit of further simplifying what the router services and offloading more of the processing onto the client machine which even if it is a phone tends to be far more capable.

the lighttpd version currently doesn't use a symlink or mac-names it internally generates it by reading the dnsmasq.conf already but I think it would be better in this case to make it also use the dnsmasq-conf / lease files since that will unify the code path and make it easier to maintain.

I wouldn't expect to see the next version out too soon most likely the version with this feature is a bit away.

vortex-5 commented 8 years ago

Sorry this may take me a bit longer I'd expect to not be able to work on this for a month so maybe work can start on this in April.

I'd expect this feature to take 2-3 days anyways including basic testing and probably a week since it's complicated enough I'd probably introduce new bugs.

So I don't want to start this until I can commit on the time.

vortex-5 commented 8 years ago

Version 1.7.0 is up it includes pulling in information from the dnsmasq.leases file you should get auto updating mac addresses even if you're on the non lighttpd version.