Jefferson49 / Joomla_plugin_sexypolling_reloaded

Migration of the joomla plugin "Sexy Polling" to joomla 4.x
GNU General Public License v3.0
2 stars 3 forks source link

IPV6 vs IPV4 already voted log #77

Open kvnorde opened 7 months ago

kvnorde commented 7 months ago

I think this poll script is a very nice script. However, it is now logged on IPV6. Can this also become IPV4 (optional)? IPV6 has the disadvantage that it changes every few hours (worldwide this is the case with IPV6). IPV4 doesn't have that problem. I would like to log on IPV4 (who has already voted).

Greets Kees.

Jefferson49 commented 7 months ago

Hi Kees,

very interesting question! Since I only saw IPv4 Iaddresses in my own installations, I thought that Sexy Polling uses IPv4 as a default. It is interesting to learn that alternatively, IPv6 can show up.

I just had a look at the code. The IP address is extracted by the following code:

$server = Factory::getApplication()->input->server;
$REMOTE_ADDR = null;
if($server->get('HTTP_X_FORWARDED_FOR') !== null) { list($REMOTE_ADDR) = explode(',', $server->get('HTTP_X_FORWARDED_FOR')); }
elseif($server->get('HTTP_X_REAL_IP') !== null) { $REMOTE_ADDR = $server->get('HTTP_X_REAL_IP'); }
elseif($server->get('REMOTE_ADDR') !== null) { $REMOTE_ADDR = $server->get('REMOTE_ADDR'); }
else { $REMOTE_ADDR = 'Unknown'; }
$ip = $REMOTE_ADDR;

The related values seem to be extracted from the HTTP request headers and seem to be out of control of the Joomla API. I found the following source on stackoverflow, which says that it is decided by the browser, which version of IP will be used: https://stackoverflow.com/questions/31233216/how-show-ipv4-only-with-remote-addr-in-php

kvnorde commented 7 months ago

Thanks for your quick response!

I don't think it's browser related. For example, if I look at this site: https://www.watzijnmijnips.nl/

Then I see that both versions (can) be shown. The problem with IPV6 is that the IP address changes every few hours (that's how IPV6 was invented) and there is therefore little point in logging on IPV6. IPV4 remains the same and does not change every few hours.

Is it possible to build IPV4 into the script, or at least make it optional (or, for example, give a choice whether you want to log IPV4 or IPV6)?

Thanks again for the quick response, nice script!

Jefferson49 commented 7 months ago

For example, if I look at this site: https://www.watzijnmijnips.nl/

In my case, it looks like this, e.g. only IPv4 is used: ip

My understanding is that it depends on the browser, server, proxy, etc., which version of IP is used. As a result, either IPv4, or IPv6, or both in parallel is used.

The problem with IPV6 is that the IP address changes every few hours (that's how IPV6 was invented) and there is therefore little point in logging on IPV6

Yes, I can understand this issue about IPv6 changing. How I understand your request is that you want to get the IPv4 address in case IPv4/IPv6 are used in parallel.

If there was an API in Joomla (e.g. something like ->server->getIP(string $IPversion) ), I could retrieve the IP in a certain version. However, Joomla and PHP seemingly only offer the variables shown above, e.g. the provided values from the HTTP request headers like $REMOTE_ADDR.

I am not an expert for those HTTP request header values. If you can give me a hint how I can get IPv4 out of these values if IPv4/IPv6 is used in parallel, I will try.

kvnorde commented 7 months ago

I have searched the internet for a while, but I have not yet been able to find a solution on how to specifically read an IPV4 address. I think it should be possible because in the example I sent IPV4 and IPV6 are also specified separately.

Unfortunately, my PHP knowledge does not go so far that I immediately have an answer/solution for it.

Jefferson49 commented 7 months ago

I spent some time to check this issue in more depth. In order to check the behavior I found a possibility in my network to switch between IPv4 and IPv6 and the combination of both. With debugging on the Joomla server, I tried to identify how PHP handles these situations.

The result of these examination was that PHP always offers information in IPv4 only or IPv6 only and seemingly never a mixture of IPv4/IPv6 information.

Another way to see this is to use a phpinfo file and check for the values of the PHP Variables "$_SERVER['HTTP ...".

PHP Variables

Therefore, it looks like it is not possible to solve this issue.

Jefferson49 commented 7 months ago

Some additional idea: Maybe, you can identify an option to configure your server to use IPv4?

kvnorde commented 7 months ago

My provider uses an IPV4 and an IPV6 address as standard. They cannot (or do not want to) change this. And if they want to change it, they have to do it for everyone to make it work properly :)

I think it's nice that you think so well about a solution. I still find it strange that the website https://www.watzijnmijnips.nl/ provides 2 IP addresses (1 IPV4 and 1 IPV6). WatZijnMijnIPs.nl Uw IP-adressen: IPv4 | XX.XX.XXX.XXX IPv6 | XXXX:XXXX:XXXX:X:XXXX:XXXX:XXXX:XXXX

So you would think that there should be a possibility to read IPV4 and IPV6. But I wouldn't dare say how :)