ejabberd-extauth-PHP
ejabberd-extauth-PHP copied to clipboard
Can not make it work.
Hi, I am using this library but cannot make it work. When I try to authenticate I get this message from ejabberd extauth call '[<<"auth">>,<<"admin">>,<<"localhost">>,<<"123456">>]' didn't receive response.
I am using ejabberd version 17.01. Maybe it's a version issue as this script is pretty old.
here is my config:
auth_method: external
extauth_program: "/var/www/html/jabberd/index.php"
This is index.php
#!/usr/bin/php
<?php
require_once '/var/www/html/jabberd/EjabberdAuth.php';
$dbServer = 'localhost';
$dbUser = 'root';
$dbPassword = '12345';
$dbName = 'ejabberd';
$pdo = new PDO('mysql:host=' . $dbServer . ';dbname=' . $dbName, $dbUser, $dbPassword);
new EjabberdAuth($pdo, 'ejabberd-auth.log');
And this is the EjabberdAuth
class:
#!/usr/bin/php
<?php
require_once 'ejabberd_external_auth.php';
class EjabberdAuth extends EjabberdExternalAuth {
/**
* Actual authentication against the database
*/
protected function authenticate($user, $server, $password) {
$this->log('Authenticate method called .... ', LOG_INFO);
$stmt = $this->db()->prepare("SELECT * FROM `users` WHERE username = ? AND password = ? ");
$stmt->execute(array($user, $password));
if($stmt->rowCount() > 0 )
{
return true;
}
else
{
return false;
}
}
/**
* Check if a username already exists
*/
protected function exists($user, $server) {
$stmt = $this->db()->prepare("SELECT * FROM `users` WHERE username = ? ");
$stmt->execute(array($user));
if($stmt->rowCount() > 0 )
{
return true;
}
else
{
return false;
}
}
}
But nothing is logged and i am not getting any response. I made intentional errors in it to check if I get any error messages, which I get. So the script is being called. Can't figure out the issue. Thanks.
Sorry, I haven't touched this code or ejabberd since 2011 and am really not in a position to fix this. I'd happily accept a PR if you find the issue though.
Hello, I know you said you haven't touched this code for a long time but still troubling you with this issue, please excuse me for that.
Your code seems fine and working as it should. Here is the log from the script
2017-04-26 17:26:32 <26729> INFO: Starting auth service...
2017-04-26 17:26:32 <26729> INFO: Entering event loop...
2017-04-26 17:26:32 <26728> INFO: Starting auth service...
2017-04-26 17:26:32 <26728> INFO: Entering event loop...
2017-04-26 17:26:41 <26729> INFO: Parsed message... {"command":"auth","user":"admin","server":"localhost","password":"123456"}
2017-04-26 17:26:41 <26729> INFO: Sending response: 00020001
2017-04-26 17:27:41 <26729> ERROR: Pipe broken
2017-04-26 17:27:41 <26729> INFO: Exiting...
And I checked the source code for external authentication for ejabberd (source code). Although I know nothing about erlang but extauth call didn't receive response. looked like it's timeout issue. Any idea why ejabberd is not receiving the response?
Again sorry for bugging you with this. Thanks for your time.
@iamsayantan could you please help me. How you resolved the issue. I am also using the same script and having the same issue.