Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't define wrtbwmon [user_file] #13

Closed
Dinsmoor opened this issue Oct 31, 2017 · 17 comments
Closed

Can't define wrtbwmon [user_file] #13

Dinsmoor opened this issue Oct 31, 2017 · 17 comments

Comments

@Dinsmoor
Copy link

Hello, I've tried (and failed) to add an option to define a user file to replace MACs with nicknames, as the wrtbwmon program allows for.

tried by adding this to model/cbi/wrtbwmon.lua
local macfile = s:option(Value, "macfile", translate("Nickname by MAC file"))

But that's as far as I got, I don't know much about Luci and I have no experience with Lua.

This would be super useful, because these dang Android devices don't allow you to set your own hostnames!

Cheers

@Kiougar
Copy link
Owner

Kiougar commented Dec 9, 2017

Hello and sorry for the delay.

The wrtbwmon package (which luci-wrtbwmon depends on) has a specific readme section for mapping MAC addresses.

Take a look here.

Let me know if you need extra help.

@Dinsmoor
Copy link
Author

Hi.

I have done this successfully with the wrtbwmon binary package, but not the luci-wrtbwmon package, since the luci version has no way to specify the MAC alias "UserDB".

Using the hosts, dnsmasq, or dhcp.leases doesn't work for me, because some devices on the network (smart TVs) don't advertise their hostnames with dhcp. I really need to use that "UserDB"

@NaruZosa
Copy link

The page you've linked to says it checks "/etc/hosts" for name maps. In the /etc/hosts directory there is a file named 'dhcp.cfg02411c' with the following"

"# auto-generated config file from /etc/config/dhcp
192.168.1.69 BradleyDesktop.lan
192.168.1.1 LEDE
fd2b:aacf:xxxx::1 LEDE"
due to a static IP being assigned, but it still displays my MAC on the usage page.

When a Hostname is assigned (through Network > Hostnames) the hostname is also written to /etc/config/dhcp/dhcp.cfg02411c and not read by luci-wrtbwmon.

@Kiougar
Copy link
Owner

Kiougar commented Dec 12, 2017

@BradleyDS2
Are you sure the /etc/hosts is a directory? I'm fairly certain it should be a file. Also, can you please post here the contents of the dhcp config file that is written when a hostname is assigned?

@Dinsmoor
So, if I understand correctly, you would like to have a configuration to allow you to enter the location of the file that will be used as the 4th argument to wrtbwmon publish <DB> <userDB>?

@NaruZosa
Copy link

NaruZosa commented Dec 12, 2017

@Kiougar Sorry, you are correct. It appears that /tmp/hosts is the directory I was thinking of, and the file in it contains the hostname assignments, while '/etc/hosts' doesn't contain the hostnames.

Here's the contents of 'etc/hosts':

127.0.0.1 localhost

::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


and here's the contents of /etc/config/dhcp:


config dnsmasq
	option domainneeded '1'
	option boguspriv '1'
	option localise_queries '1'
	option rebind_protection '1'
	option rebind_localhost '1'
	option local '/lan/'
	option domain 'lan'
	option expandhosts '1'
	option authoritative '1'
	option readethers '1'
	option leasefile '/tmp/dhcp.leases'
	option resolvfile '/tmp/resolv.conf.auto'
	option localservice '1'
	option nonwildcard '0'

config dhcp 'lan'
	option interface 'lan'
	option start '100'
	option limit '150'
	option leasetime '12h'
	option dhcpv6 'server'
	option ra 'server'
	list dhcp_option '6,209.222.18.222,209.222.18.218'
	option ra_management '1'

config dhcp 'wan'
	option interface 'wan'
	option ignore '1'

config odhcpd 'odhcpd'
	option maindhcp '0'
	option leasefile '/tmp/hosts/odhcpd'
	option leasetrigger '/usr/sbin/odhcpd-update'

config host
	option name 'BradleyDesktop'
	option dns '1'
	option mac '1c:1b:0d:e5:60:**'
	option ip '192.168.1.69'
	option leasetime 'infinite'

config domain


@Kiougar
Copy link
Owner

Kiougar commented Dec 12, 2017

@BradleyDS2
I see. Well, I wanted to see if these files are suitable for the wrtbwmon package to parse them as is. Unfortunately that's not the case. Browsing through the source of wrtbwmon I found out that it expects it find in these files the following syntax:

[...]
aa:bb:cc:ee:ff:00,MyDeviceName
[...]
aa:bb:cc:ee:ff:01,MyOtherDevice
[...]

In other words, even if adding the config option (that @Dinsmoor is suggesting) then the user would have to manually create such a file.

In the best case scenario, some of the config files that LuCI handles contains that structure and we can use that file as is (without extra effort from the user). We have to find these files :D

@Kiougar
Copy link
Owner

Kiougar commented Dec 12, 2017

Maybe some of them (as these are the ones suggested by wrtbwmon) have that structure?

  • /tmp/dhcp.leases
  • /tmp/dnsmasq.conf
  • /etc/dnsmasq.conf

@NaruZosa
Copy link

NaruZosa commented Dec 12, 2017

The following is the contents of /tmp/dhcp.leases:

0 1c:1b:0d:e5:60:** 192.168.1.69 BradleyDesktop 01:1c:1b:0d:e5:60:**
1513117832 94:de:80:23:6a:** 192.168.1.245 JEAN-DESKTOP 01:94:de:80:23:6a:**
1513117412 1c:1b:0d:97:b8:** 192.168.1.189 DESKTOP-5D9PGHU 01:1c:1b:0d:97:b8:**
1513118885 98:b6:e9:01:5f:** 192.168.1.246 * *
1513121179 b8:ae:6e:ce:e5:** 192.168.1.167 * 01:b8:ae:6e:ce:e5:6c
1513119267 c0:ee:fb:df:65:** 192.168.1.178 * 01:c0:ee:fb:df:65:**
1513112938 f0:03:8c:1e:2f:** 192.168.1.217 Roomba-3117440C10325600 *
1513117855 a4:77:33:bf:90:** 192.168.1.242 Google-Home *
1513118363 9c:ad:97:b0:b8:** 192.168.1.215 * 01:9c:ad:97:b0:b8**
1513113025 d8:6c:63:72:7a:** 192.168.1.165 Chromecast *
1513113023 d8:49:2f:e0:eb:** 192.168.1.205 * 01:d8:49:2f:e0:eb:**
1513113023 60:12:8b:91:ca:** 192.168.1.156 * 01:60:12:8b:91:ca:**

/tmp/dnsmasq.conf doesn't exist, /tmp/dnsmasq.d exists as an empty directory.

The following is the contents of /etc/dnsmasq.conf:

# Change the following lines if you want dnsmasq to serve SRV
# records.
# You may add multiple srv-host lines.
# The fields are <name>,<target>,<port>,<priority>,<weight>

# A SRV record sending LDAP for the example.com domain to
# ldapserver.example.com port 289
#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389

# Two SRV records for LDAP, each with different priorities
#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,1
#srv-host=_ldap._tcp.example.com,ldapserver.example.com,389,2

# A SRV record indicating that there is no LDAP server for the domain
# example.com
#srv-host=_ldap._tcp.example.com

# The following line shows how to make dnsmasq serve an arbitrary PTR
# record. This is useful for DNS-SD.
# The fields are <name>,<target>
#ptr-record=_http._tcp.dns-sd-services,"New Employee Page._http._tcp.dns-sd-services"

# Change the following lines to enable dnsmasq to serve TXT records.
# These are used for things like SPF and zeroconf.
# The fields are <name>,<text>,<text>...

#Example SPF.
#txt-record=example.com,"v=spf1 a -all"

#Example zeroconf
#txt-record=_http._tcp.example.com,name=value,paper=A4

# Provide an alias for a "local" DNS name. Note that this _only_ works
# for targets which are names from DHCP or /etc/hosts. Give host
# "bert" another name, bertrand
# The fields are <cname>,<target>
#cname=bertand,bert


/tmp/dhcp.leases looks promising.

@Kiougar
Copy link
Owner

Kiougar commented Dec 12, 2017

Yeah, /tmp/dhcp.leases does look promising but as you can see it lacks some hostnames (as @Dinsmoor already stated).

What about the /etc/config/dhcp file? If LuCI allows you to enter a custom hostname for a host when setting an infinite lease then it could work (assuming a PR is created that allows wrtbwmon to parse these files).

Otherwise, the custom file created by the user would work right out of the box (because wrtbwmon can already parse these files - using the 4th argument when calling it).

Let's wait for @Dinsmoor for feedback.

@NaruZosa
Copy link

NaruZosa commented Dec 12, 2017

The /etc/config/dhcp file would be best, if wrtbwmon could parse it, as it contains both names for assigned static IP addresses and the 'Hostnames' page, while /tmp/dhcp.leases doesn't contain hostnames defined in the 'Hostnames' page.

Loading /tmp/dhcp.leases for hostnames will probably be the best option if there isn't a PR for wrtbwmon, although assigning a static IP would certainly be a very roundabout way to set a hostname to show when checking network usage.

@Kiougar
Copy link
Owner

Kiougar commented Dec 12, 2017

So if you define a Hostname in the Hostnames page how would it look in the /etc/config/dhcp file?

Bah, it's so frustrating to not have a router atm to test these things... I'm sorry in advance for making you test these things for me :)

@NaruZosa
Copy link

NaruZosa commented Dec 12, 2017

It looks like this in the /etc/config/dhcp file:

config domain
	option name 'Test'
	option ip '192.168.1.167'

While a static ip hostname looks like this:

config host
	option name 'BradleyDesktop'
	option dns '1'
	option mac '1c:1b:0d:e5:60:f1'
	option ip '192.168.1.69'
	option leasetime 'infinite'

@Kiougar
Copy link
Owner

Kiougar commented Dec 12, 2017

Excellent, thank you!

Now all there is left is to create an issue/PR in the wrtbwmon repo to be able to parse the /etc/config/dhcp file.

@Dinsmoor
Copy link
Author

Hello, all.

I'd prefer to be able to specify a path to use my existing User DB. I have no problem using vi to make the file over ssh, since I'll generally only have to change it every once in a while.

As long as the method is documented, then it's no big deal. I just want it to work. I really like this package.

@Dinsmoor
Copy link
Author

Also,

I'm not keen on updating the /etc/config/dhcp because the method for wrtbwmon already works with a custom file, most wrtbwmon users already have their user file, and the simplicity of mac->name substitution is all I'm looking for.

@Kiougar
Copy link
Owner

Kiougar commented Dec 13, 2017

I see. Then a change in the config page is needed. Will try and fix this as soon as I can.

Thank you all for the feedback!

@camelcamro
Copy link

camelcamro commented Jan 24, 2020

specially,
i also have the /etc/config/dhcp
and as i have 4 routers, the dhcp is only creating when this is acting as dhcp, but i have multiple, so, every router is a dhcp server, depends where the clients conencting ...

so, i guess it would be needed to create a kind of serlist on startup of wrtbmon or ... the luci wrtbmon can create that on the call or on a config change ?

or on the creation of dhcp ...

there is a file: (on my router)
/tmp/etc/dnsmasq.conf.cfg01411c

which is having:
dhcp-host=20:32:33:70:D8:85,192.168.1.201,IPCam_201,24h
dhcp-host=20:32:33:70:4D:17,192.168.1.202,IPCam_202,24h
...

can these files be used ?
which change would be needed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants