Geeklog-Core / geeklog

Geeklog - The Secure CMS.
https://www.geeklog.net
25 stars 19 forks source link

Upgrade or Migrate Fails Since IP Class assumes an incorrect table name #1130

Closed eSilverStrike closed 2 years ago

eSilverStrike commented 2 years ago

This issue happens when upgrading or migrating Geeklog.net.

Geeklog.net doesn't use any database table prefix (like 'gl_') so the Ip class fails as when it initializes, it assumes a table name of 'gl_ip_addresses'. It should be just 'ip_addresses'.

A PHP error has occurred:
This is being displayed as "Root Debugging" is enabled in your Geeklog configuration.
If this is a production website you must disable this option once you have resolved any issues you are investigating.

E_USER_ERROR(256) - 1146: Table 'geeklogtest.gl_ip_addresses' doesn't exist @ C:\wamp64\www\geeklogtest\system\classes\Database\DbMysqli.php line 517

C:\wamp64\www\geeklogtest\public_html\lib-common.php:8536:
array (size=3)
  'sql' => string 'INSERT INTO gl_ip_addresses (ipaddress, created_at, is_anonymized) VALUES('', 1655306360, 0)' (length=92)
  'ignore_errors' => int 0
  'result' => boolean false

This issue also relates to #1127 as you can see it is intserting a record without an actual IP Address.

The only thing I see not working is once the install, upgrade, or migrate is complete and the user is on the success page of the install the IP Address for the session is a blank for some reason. This will remain a blank until that user session logs into Geeklog. If other anonymous users visit from a different browser things work fine.

eSilverStrike commented 2 years ago

@mystralkk

In lib-common I notice in the 2 spots the IP class is initialized you do not do it when the install is running

if (!defined('GL_INSTALL_ACTIVE')) {
    \Geeklog\IP::init($_TABLES['ip_addresses'], $_CONF['ip_anonymization']);
}

When I remove the if statement and allow the IP class to be initialized even if the install is running (and I also remove the setting of the table in the IP class to "gl_ip_addresses"), everything seems to run fine with no errors. In fact this also fixes the issue with the session record pointing to an ip address that is blank.

I tested it without problems on a new install, upgrading from 2.2.1, and migrating from a 2.0.0 database.

I believe you added the IP class in 2.2.0 so it seems to run fine with a DB that existed before the class as well.

Can you think of the reason you prevented the IP class from initializing during the install? (maybe you can test the fix as well)

If not I will update lib-common and IP class.

mystralkk commented 2 years ago

Can you think of the reason you prevented the IP class from initializing during the install? (maybe you can test the fix as well)

No, I don't remember why I stopped initializing the IP class during installation.

If not I will update lib-common and IP class.

Please go ahead.

eSilverStrike commented 2 years ago

Okay it is done.