mattv8/yourls-ldap-plugin

Errors in plugin.php

Closed this issue · 4 comments

Hi,

I would like to use add the LDAP plugin to my YOURLS (which is working).

Once I activated the plugin (and set the variables in config.php), I try to log in with my LDAP account and there is an error 500.

I checked the nginx/error.log and this is the result:

2020/08/04 09:35:13 [error] 8230#8230: *6 FastCGI sent in stderr: "PHP message: PHP Warning: array_merge(): Argument #2 is not an array in /srv/YOURLS/user/plugins/yourls-ldap-plugin/plugin.php on line 286
PHP message: PHP Warning: count(): Parameter must be an array or an object that implements Countable in /srv/YOURLS/includes/functions-http.php on line 309
PHP message: PHP Fatal error: Uncaught Error: Call to undefined function ldap_connect() in /srv/YOURLS/user/plugins/yourls-ldap-plugin/plugin.php:114
Stack trace:
#0 /srv/YOURLS/user/plugins/yourls-ldap-plugin/plugin.php(164): ldapauth_get_ldap_connection()
#1 /srv/YOURLS/includes/functions-plugins.php(156): ldapauth_is_valid_user(false)
#2 /srv/YOURLS/includes/functions-auth.php(89): yourls_apply_filter('is_valid_user', false)
#3 /srv/YOURLS/includes/auth.php(5): yourls_is_valid_user()
#4 /srv/YOURLS/includes/functions-auth.php(14): require_once('/srv/YOURLS/inc...')
#5 /srv/YOURLS/admin/index.php(4): yourls_maybe_require_auth()
#6 {main}
thrown in /srv/YOURLS/user/plugins/yourls-ldap-plugin/plugin.php on line 114" while reading response header from upstream, client: X.X.X.X server: my_server_name, request: "POST /admin/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "my_server_name", referrer: "http://my_server_name/admin/"

In my opinion there are syntax errors in plugin.php, or I made a mistake somewhere.

k3a commented

It looks like your PHP is not compiled with LDAP support. Function ldap_connect is supported in PHP 4 - 7 but has to be explicitly enabled during compilation.

You were right.
I installed php-ldap and it's better now, but here is my error.log now:

**2020/08/05 08:32:40 [error] 1228#1228: *1 FastCGI sent in stderr: "PHP message: PHP Warning: array_merge(): Argument #2 is not an array in /srv/YOURLS/user/plugins/yourls-ldap-plugin/plugin.php on line 286

PHP message: PHP Warning: count(): Parameter must be an array or an object that implements Countable in /srv/YOURLS/includes/functions-http.php on line 309

PHP message: PHP Warning: ldap_search(): Search: Can't contact LDAP server in /srv/YOURLS/user/plugins/yourls-ldap-plugin/plugin.php on line 190" while reading response header from upstream, client: X.X.X.X, server: my_server_name, request: "POST /admin/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "my_server_name", referrer: "http://my_server_name/admin/"**

I'm interested by the first 2 errors

I've modified the proxy conf and here is the nginx error.log now:

**2020/08/05 09:17:21 [error] 2271#2271: *4 FastCGI sent in stderr: "PHP message: PHP Warning: array_merge(): Argument #2 is not an array in /srv/YOURLS/user/plugins/yourls-ldap-plugin/plugin.php on line 286

PHP message: PHP Warning: ldap_search(): Search: Can't contact LDAP server in /srv/YOURLS/user/plugins/yourls-ldap-plugin/plugin.php on line 190" while reading response header from upstream, client: X.X.X.X, server: my_server_name, request: "POST /admin/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "my_server_name", referrer: "http://my_server_name/admin/"**

k3a commented

The first PHP warning is unimportant but I fixed it in the new commit.

" ldap_search(): Search: Can't contact LDAP server" means your configured LDAP server is not reachable from the PHP.

Check your LDAP configuration, credentials and ensure LDAP can be reached from the same sever.
You can use ldapsearch utility (a part of OpenLDAP) to do test queries.