Skip to content

Conversation

@johanfleury
Copy link

@johanfleury johanfleury commented Jan 5, 2019

This is based on the 3rdparty library rlanvin/php-ip. This library
requires installation/activation of the GMP extension.

Warning: this might break existing installation.

Requires nextcloud/3rdparty#198.

This is based on the 3rdparty library rlanvin/php-ip. This library
requires installation/activation of the GMP extension.

Signed-off-by: Johan Fleury <[email protected]>
This must be removed when 3rparty changes are merged.

Signed-off-by: Johan Fleury <[email protected]>
@kesselb
Copy link
Contributor

kesselb commented Jan 5, 2019

Thank you for your contribution 🎉

Unfortunately there is another pull request for ipv6 and trusted_proxies: #12535 😟

Caution: This library is compatible with PHP 5.2, therefore it is not namespaced.

https://github.com/rlanvin/php-ip/ not sure if this is a good choice 🤔

@johanfleury
Copy link
Author

Oh crap. I did a search before making this PR but for some reason I didn't find this one.

It's your decision either you want to close this PR or not, but in my opinion, after taking a look at #12535, is that mine is simpler and does not rely on regex to parse IP addresses.

There's still a lot of work to do to improve this PR. Tell me if I should keep working on it.

@kesselb
Copy link
Contributor

kesselb commented Jan 5, 2019

Lets ask @nextcloud/server-triage

@nickvergessen nickvergessen added the 2. developing Work in progress label Jan 9, 2019
@nickvergessen
Copy link
Member

nickvergessen commented Jan 9, 2019

Well your solution depends on a 3rdparty lib instead or regex, im not sure which is better and also the lib might use regex too.

But I think the GMP dependency is the real killer here. But there is help:

/**
* Based on http://stackoverflow.com/a/7951507
* @param string $ip
* @param string $rangeIp
* @param int $bits
* @return bool
*/
protected function matchIPv6($ip, $rangeIp, $bits) {
$ipNet = inet_pton($ip);
$binaryIp = $this->ipv6ToBits($ipNet);
$ipNetBits = substr($binaryIp, 0, $bits);
$rangeNet = inet_pton($rangeIp);
$binaryRange = $this->ipv6ToBits($rangeNet);
$rangeNetBits = substr($binaryRange, 0, $bits);
return $ipNetBits === $rangeNetBits;
}
/**
* Based on http://stackoverflow.com/a/7951507
* @param string $packedIp
* @return string
*/
protected function ipv6ToBits($packedIp) {
$unpackedIp = unpack('A16', $packedIp);
$unpackedIp = str_split($unpackedIp[1]);
$binaryIp = '';
foreach ($unpackedIp as $char) {
$binaryIp .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
}
return str_pad($binaryIp, 128, '0', STR_PAD_RIGHT);
}

We already have code that matches IPv4 and IPv6 addresses. I guess you can extract that to a new method which is then used by the workflow engine and the trusted domain code?

@ChristophWurst ChristophWurst added this to the Nextcloud 17 milestone Mar 1, 2019
@MorrisJobke MorrisJobke mentioned this pull request Jul 17, 2019
28 tasks
@MorrisJobke
Copy link
Member

We already have code that matches IPv4 and IPv6 addresses. I guess you can extract that to a new method which is then used by the workflow engine and the trusted domain code?

That makes most sense. Thus I'm closing this PR.

@MorrisJobke MorrisJobke removed this from the Nextcloud 17 milestone Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants