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

Provider/ISP URL sometimes does not work #13045

Closed
Findus23 opened this issue Jun 7, 2018 · 7 comments
Closed

Provider/ISP URL sometimes does not work #13045

Findus23 opened this issue Jun 7, 2018 · 7 comments
Labels
Bug For errors / faults / flaws / inconsistencies etc. Help wanted Beginner friendly issues or issues where we'd highly appreciate community's help and involvement.
Milestone

Comments

@Findus23
Copy link
Member

Findus23 commented Jun 7, 2018

Another beginner friendly bug:

When I click on the ISP Rostelecom it wan't to go to http://www.rostelecom/ as it thinks the providername is an URL ending with com. As many ISPs are called telecom I guess this could happen quite often:

$extToExclude = array(
'com', 'net', 'org', 'co'
);

$e = explode('.', $hostname);
$s = sizeof($e);
// if extension not correct
if (isset($e[$s - 2]) && in_array($e[$s - 2], $extToExclude)) {
return $e[$s - 3] . "." . $e[$s - 2] . "." . $e[$s - 1];
} else {
return $e[$s - 2] . "." . $e[$s - 1];
}

PS: This code was added in def7586 11 years ago!

@Findus23 Findus23 added Help wanted Beginner friendly issues or issues where we'd highly appreciate community's help and involvement. Lower priority labels Jun 7, 2018
@sunsplat
Copy link

I would like to work on this!

@Findus23 where do you click on the ISP in the web interface?

@justju
Copy link
Contributor

justju commented Jun 22, 2018

Hi,

I don't think it's the com-ending. This seems to happen with providers, that only have no spaces.

test

@sunsplat
Copy link

I found the issue here:

function getHostnameUrl($in)
{
    if ($in == DataTable::LABEL_SUMMARY_ROW || empty($in) || strtolower($in) === 'ip') {
        return null;
    }

    // if the name looks like it can be used in a URL, use it in one, otherwise link to startpage
    if (preg_match("/^[-a-zA-Z0-9_.]+$/", $in)) {
        return "http://www." . $in . "/";
    } else {
        return "https://startpage.com/do/search?q=" . urlencode($in);
    }
}

Removing:

if (preg_match("/^[-a-zA-Z0-9_.]+$/", $in)) {
        return "http://www." . $in . "/";
    } else {

will solve the problem, but I don't know if this is good long-term solution.

I think it will take refactoring a bit to get the IP passed in and using gethostbyaddr() to get the url for the provider. This way, it should work no matter the url extension.

@Findus23 Is there a way I can test my change by adding test providers? Are providers saved to the db somewhere?

@sunsplat
Copy link

Pull Request made for change: #13110

@justju
Copy link
Contributor

justju commented Jun 28, 2018

How about changing the regex to be more specific, e.g.:
^[-a-zA-Z0-9_.]+\.[-a-zA-Z0-9_]+$

This should match if there is at least a Second-level domain followed by a dot and a Top-level domain after.

@sgiehl
Copy link
Member

sgiehl commented Jun 28, 2018

Guess the easiest way would be to use the hostname validator to check if it's a valid hostname

richardjohn added a commit to richardjohn/matomo that referenced this issue Jul 1, 2018
@mattab mattab changed the title Provider/ISP to URL conversion breaks when ISP ends with "com" Provider/ISP URL does not work when ISP ends with "com" Aug 28, 2018
@mattab mattab changed the title Provider/ISP URL does not work when ISP ends with "com" Provider/ISP URL sometimes does not work Aug 28, 2018
@mattab mattab added the Bug For errors / faults / flaws / inconsistencies etc. label Aug 28, 2018
@mattab mattab added this to the 3.6.0 milestone Aug 28, 2018
InfinityVoid pushed a commit to InfinityVoid/matomo that referenced this issue Oct 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Help wanted Beginner friendly issues or issues where we'd highly appreciate community's help and involvement.
Projects
None yet
Development

No branches or pull requests

5 participants