1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed User IP Check Inaccurate

Discussion in 'Resolved Bug Reports' started by Jeremy P, Dec 13, 2012.

  1. Jeremy P

    Jeremy P Well-Known Member

    When in the Admin Control Panel, viewing a user's logged IPs, you have the option to search for more users with the same IP. However, in some cases the search returns no results, even when there are multiple users with the same IP.

    Haven't been able to track this down but I can confirm that the IPs are logged for multiple in the xf_ip table, and show up in the ACP when viewing the members individually, but do not appear when running the check.
    Alien, erich37 and Rob Fritz like this.
  2. ENF

    ENF Well-Known Member

    Could you clarify 'in some cases'? Are you saying that it works in some cases and not others?

    I took a random sample of a few users that I know should have the same IP address. Also, I took another sample of those that shouldn't and it seems to be working as designed.
  3. Jeremy P

    Jeremy P Well-Known Member

    Yeah, it works sometimes, not others. Seemingly random so far. I can reproduce one recent case 100%, and I recall it happening in the past but figured it was a fluke. I can give a developer (or support staff if no one can reproduce) admin/ssh/mysql access if needed.

    Usernames purposefully edited:
    Screen Shot 2012-12-12 at 8.29.30 PM.png
    Screen Shot 2012-12-12 at 8.31.14 PM.png
    Visiting https://mysite.com/admin.php?users/ip-users&ip= yields:
    Screen Shot 2012-12-12 at 8.31.43 PM.png
    Jake Bunce likes this.
  4. Robert F Schmitz

    Robert F Schmitz Well-Known Member

    I second this. I use my ip address to search for users and get the error above.

    xenforo 1.1.2
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I don't have this problem on my forum.

    I examined the code. The second action which fails to return any records (XenForo_ControllerAdmin_User::actionIpUsers) does an INNER JOIN on xf_user and xf_user_profile. So if either record is missing then the user will be omitted, but that would also cause an error when accessing the user's profile in the Admin CP which you are obviously able to do.

    If you have this problem with addons disabled then I will need to take a look for myself. I need a URL and admin login, access to phpmyadmin, and a specific test case that I can work with.
  6. Jeremy P

    Jeremy P Well-Known Member

    Convo sent.
  7. Dan

    Dan Well-Known Member

    I have ran into this recently as well.
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Bug confirmed. Here is a fix:


    Add the red code:

    	public function getUsersByIp($ip, array $fetchOptions = array())
    		if (!$ip)
    			return array();
    		else if (is_string($ip) && strpos($ip, '.'))
    			$ip = ip2long($ip);
    			$ip = sprintf('%u', $ip);
    		$orderClause = $this->prepareUserOrderOptions($fetchOptions, 'user.username');
    		$joinOptions = $this->prepareUserFetchOptions($fetchOptions);
    		return $this->fetchAllKeyed('
    			SELECT user.*, ip.ip, MAX(ip.log_date) AS log_date
    				' . $joinOptions['selectFields'] . '
    				FROM xf_ip AS ip
    				INNER JOIN xf_user AS user ON
    					(user.user_id = ip.user_id)
    				' . $joinOptions['joinTables'] . '
    				WHERE ip.ip = ?
    				GROUP BY ip.user_id
    				' . $orderClause . '
    		', 'user_id', $ip);
    That converts it to an unsigned integer which is what is stored in the database.
    0xym0r0n, Dan, digitalpoint and 3 others like this.
  9. Mike

    Mike XenForo Developer Staff Member

    This was the only case that I could find where the sprintf() call was missing, so sorted now.
    Jeremy P, erich37, Alien and 2 others like this.

Share This Page