alexandregz / twofactor_gauthenticator

This RoundCube plugin adds the 2-step verification(OTP) to the login proccess
MIT License
221 stars 78 forks source link

twofactor_gauthenticator broken with most recent commit #178

Closed Hydranet closed 1 year ago

Hydranet commented 1 year ago

When you try to load the Roundcube login page with the twofactor_gauthenticator plugin enabled you get an "Internal Error". When I check the php -fpm log file I see the following.

[14-Jun-2023 07:54:11 UTC] PHP Parse error: syntax error, unexpected identifier "file_put_contents" in /data/websites/roundcube/html/plugins/twofactor_gauthenticator/twofactor_gauthenticator.php on line 546

listerr commented 1 year ago

I get the same error as of today, (although has been on php8.2 fine for months.)

Is possibly related to PR https://github.com/alexandregz/twofactor_gauthenticator/pull/166

Please can you tag a release/stable version so that composer doesn't automatically upgrade to this version in dev-master and break things.

Hydranet commented 1 year ago

I get the same error as of today, (although has been on php8.2 fine for months.)

You are right it has been working with php8.2 until a few days ago, If checkout to commit 3c76f459e83f06c965e140a1f344fdcb0f4030e2 it works again.

Hydranet commented 1 year ago

If you do a "git diff" between the current HEAD 3c76f459e83f06c965e140a1f344fdcb0f4030e2 and the last working commit 085abfb14a4321b5e3b81a7053ac978a816a7be4 you see that the following lines have been changed.

class twofactor_gauthenticator extends rcube_plugin
 {
        private $_number_recovery_codes = 4;

-        // relative from RC home dir, not plugin directory
-        private $_logs_file = '/logs/log_errors_2FA.txt';
+        // relative to $config['log_dir']
+        private $_logs_file = 'log_errors_2FA.txt';

     function init() 
     {

class twofactor_gauthenticator extends rcube_plugin

         // log error into $_logs_file directory
         private function __logError() {
-                file_put_contents(realpath(".").$this->_logs_file, date("Y-m-d H:i:s")."|".$_SERVER['HTTP_X_FORWARDED_FOR']."|".$_SERVER['REMOTE_ADDR']."\n", FILE_APPEND);
+               $_log_dir = $rcmail->config->get('log_dir')
+                file_put_contents($_log_dir.'/'.$this->_logs_file, date("Y-m-d H:i:s")."|".$_SERVER['HTTP_X_FORWARDED_FOR']."|".$_SERVER['REMOTE_ADDR']."\n", FILE_APPEND);
         }

 }
gotspatel commented 1 year ago

Just a headsup This didn't work on windows with PHP 8.1 and Roundcube 1.5.2

$_log_dir = $rcmail->config->get('log_dir')

but this worked

$_log_dir = rcmail::get_instance()->config->get('log_dir');

gotspatel commented 1 year ago

By the way this gives an error when going to the settings page ANY HELP PLEASE

somewhere around line 281 in public function twofactor_gauthenticator_form() if(array_key_exists('secret', $data)){ $activateData['checked'] = "checked"; }

Error as below,

`[17-Jun-2023 09:22:48 Asia/Kolkata] PHP Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in C:\inetpub\wwwroot\roundcube\plugins\twofactor_gauthenticator\twofactor_gauthenticator.php:283 Stack trace:

0 C:\inetpub\wwwroot\roundcube\program\include\rcmail_output_html.php(1484): twofactor_gauthenticator->twofactor_gauthenticator_form()

1 [internal function]: rcmail_output_html->xml_command()

2 C:\inetpub\wwwroot\roundcube\program\include\rcmail_output_html.php(1322): preg_replace_callback()

3 C:\inetpub\wwwroot\roundcube\program\include\rcmail_output_html.php(825): rcmail_output_html->parse_xml()

4 C:\inetpub\wwwroot\roundcube\program\include\rcmail_output_html.php(654): rcmail_output_html->parse()

5 C:\inetpub\wwwroot\roundcube\plugins\twofactor_gauthenticator\twofactor_gauthenticator.php(224): rcmail_output_html->send()

6 C:\inetpub\wwwroot\roundcube\program\lib\Roundcube\rcube_plugin_api.php(570): twofactor_gauthenticator->twofactor_gauthenticator_init()

7 C:\inetpub\wwwroot\roundcube\program\include\rcmail.php(248): rcube_plugin_api->exec_action()

8 C:\inetpub\wwwroot\roundcube\index.php(288): rcmail->action_handler()

9 C:\inetpub\wwwroot\roundcube\public_html\index.php(26): include('...')

10 {main}

thrown in C:\inetpub\wwwroot\roundcube\plugins\twofactor_gauthenticator\twofactor_gauthenticator.php on line 283`