openwisp / docker-openwisp

OpenWISP in docker. For production usage we recommend using the ansible-openwisp2 role.
https://openwisp.io/docs/dev/docker/
BSD 3-Clause "New" or "Revised" License
149 stars 75 forks source link

[fix] Fix domain detection #281

Closed Bixilon closed 3 months ago

Bixilon commented 1 year ago

Should fix #273, not tested

Bixilon commented 1 year ago

I have no clue what the library is doing, but it should cut off the first part of a domain (test.abc.de -> abc.de). The library just does it with the top level domain (test.abc.de -> de, but not even then correct, check a domain with a dash test.ab-cd.de, it then just returns nothing).

It is used in a header (nginx), and if that header is not set correctly, things like chart loading fail.

Bixilon commented 1 year ago

Tested it, working fine!

Screenshot_20230324_162010

Bixilon commented 10 months ago

Any chance of getting this merged?

nemesifier commented 3 months ago

Testing with tldextract-5.1.2:

In [9]: print(tldextract.extract('openwisp.org').registered_domain)
openwisp.org

In [10]: print(tldextract.extract('api.openwisp.org').registered_domain)
openwisp.org

In [11]: print(tldextract.extract('test.api.openwisp.org').registered_domain)
openwisp.org

In [12]: print(tldextract.extract('test.abc.de').registered_domain)
abc.de

In [13]: print(tldextract.extract('abc.de').registered_domain)
abc.de

In [14]: print(tldextract.extract('test.test.abc.de').registered_domain)
abc.de

I cannot replicate the issue you are mentioning here. I will try to update this library and modify the different parts of the code to make sure they're consistent.

Bixilon commented 3 months ago

try extracting from api.open-wisp.de

nemesifier commented 3 months ago

try extracting from api.open-wisp.de

~As far as I know, dashes are not allowed in the domain.~ Yes they are allowed.

try extracting from api.open-wisp.de

In [1]: import tldextract

In [2]: ext=tldextract.extract('api.open-wisp.org')

In [3]: ext
Out[3]: ExtractResult(subdomain='api', domain='open-wisp', suffix='org', is_private=False)

In [4]: ext.registered_domain
Out[4]: 'open-wisp.org'

What's the issue? Please update your local copy of the library. PR in https://github.com/openwisp/docker-openwisp/pull/300.