Jack-Dane / odoo-wp-plugin

Odoo WordPress Plugin
GNU General Public License v3.0
8 stars 4 forks source link

Issue with write_to_file in encryption PHP #46

Open wcbdata opened 1 week ago

wcbdata commented 1 week ago

Describe the bug Uncertain as to whether this is a bug or a limitation.

When attempting to create the first new Odoo connection, $encryption_file is returned as FALSE rather than the file resource. This happens on every attempt to create a new connection. Error thrown is "Uncaught TypeError: flock(): Argument #1 ($stream) must be of type resource, bool given in /srv/htdocs/wp-content/plugins/odoo-wp-plugin/encryption.php:20" Full stack trace below.

Expected behavior A connection will be created and tested against Odoo

Platform versions:

Stack Trace:

Error Details
=============
An error of type E_ERROR was caused in line 20 of the file /srv/htdocs/wp-content/plugins/odoo-wp-plugin/encryption.php. Error message: Uncaught TypeError: flock(): Argument #1 ($stream) must be of type resource, bool given in /srv/htdocs/wp-content/plugins/odoo-wp-plugin/encryption.php:20
Stack trace:
#0 /srv/htdocs/wp-content/plugins/odoo-wp-plugin/encryption.php(20): flock(false, 6, NULL)
#1 /srv/htdocs/wp-content/plugins/odoo-wp-plugin/encryption.php(118): odoo_conn\encryption\OdooConnEncryptionFileHandler->write_to_file(':g\e\x9A\x1E\xA3\x98e\xF6\x93i\xDF\xE6\x92\xF9...')
#2 /srv/htdocs/wp-content/plugins/odoo-wp-plugin/encryption.php(83): odoo_conn\encryption\OdooConnEncryptionHandler->get_encryption_key()
#3 /srv/htdocs/wp-content/plugins/odoo-wp-plugin/admin/database_connection/odoo_connections.php(123): odoo_conn\encryption\OdooConnEncryptionHandler->encrypt('bc167276ae587bf...')
#4 /srv/htdocs/wp-content/plugins/odoo-wp-plugin/admin/database_connection/base.php(50): odoo_conn\admin\database_connection\OdooConnPostOdooConnection->parse_data(Array)
#5 /srv/htdocs/wp-content/plugins/odoo-wp-plugin/admin/pages/connections/odoo_connection.php(105): odoo_conn\admin\database_connection\OdooConnPostBaseDatabaseConnection->request(Array)
#6 /srv/htdocs/wp-content/plugins/odoo-wp-plugin/admin/pages/page_router.php(133): odoo_conn\admin\pages\connections\OdooConnOdooConnectionRouter->create_new_record()
#7 /srv/htdocs/wp-content/plugins/odoo-wp-plugin/admin/pages/page_router.php(31): odoo_conn\admin\pages\OdooConnPageRouterCreate->display_table()
#8 /srv/htdocs/wp-content/plugins/odoo-wp-plugin/admin/pages/connections/odoo_connection.php(140): odoo_conn\admin\pages\OdooConnPageRouter->request()
#9 /wordpress/core/6.6.2/wp-includes/class-wp-hook.php(324): odoo_conn\admin\pages\connections\odoo_conn_odoo_connection_page('')
#10 /wordpress/core/6.6.2/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#11 /wordpress/core/6.6.2/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#12 /wordpress/core/6.6.2/wp-admin/admin.php(259): do_action('odoo-forms_page...')
#13 {main}
  thrown
Jack-Dane commented 1 week ago

@wcbdata, thanks for bringing this to my attention, I was not aware of this.

I assume there is a limitation of where we are writing the file since fopen is returning false. https://www.php.net/manual/en/function.fopen.php#refsect1-function.fopen-returnvalues

I guess this is due to hosting on Wordpress.com (not owning the web server), I haven't been able to investigate this yet since you need a business account to upload plugins. I wasn't able to find anyone else who has had this problem.

The minimum that can be done here is to update the README.md to include this limitation.

wcbdata commented 1 week ago

Thanks, @Jack-Dane - I will see what I can find out about local file writes on the wordpress.com SaaS. If there's an option that permits this (e.g., some local usr filesystem tha WP.com provisions), would you be interested/able to work with us on this feature? We're happy to assist in testing!

Jack-Dane commented 1 week ago

@wcbdata, anytime you provide to discover a place we can create files would be greatly appreciated. I think this plugin is missing many WordPress users by not supporting the SaaS platform.

Currently, the file is created in the root WordPress directory /var/www/html (for apache), which I didn't like too much anyway. I was planning to move it to the base of the plugin directory /var/www/html/wp-content/plugins/<plugin-name>, but I don't think I found a way to do this without hard coding it.

It is also a pain because this needs to be compatible with users who are upgrading, so either the plugin needs to move the old key file to the new directory on install, or still use it in the old directory (if it exists). But now there is a bigger reason to move the file, I am more inclined to do the work needed.