我对 ejabberd 2.1.2 有疑问,并且external_auth 没有收到响应。我已经检查了谷歌上所有不同的帖子和这里的问题,但仍然没有找到解决方案。
在我的 /etc/ejabberd/ejabberd.cfg 我有以下条目:
{auth_method, external}.
{extauth_program, "/tmp/auth.php"}.
上面引用的 extauth_program 可以在下面找到。我可以以“ejabberd”用户身份运行 php 文件,并且文件创建/文件权限(也是日志文件)不是问题。
#!/usr/bin/php
<?
$fh = fopen("php://stdin", 'r');
$stdout = fopen('php://stdout', 'w');
$fs = fopen("/tmp/auth-log.txt." . getmypid(), 'a');
if(!$fh){
die("Cannot open STDIN\n");
}
$users = array('user1'=>'password1', 'user2'=>'password2');
do{
$lenBytes = fgets($fh, 3);
$len = unpack('n', $lenBytes);
$len = $len[1];
if($len<1) continue;
$msg = fgets($fh, $len+1);
$toks=explode(':',$msg);
fwrite($fs, $msg . "\n");
$method = array_shift($toks);
fwrite($fs, "$method\n");
$result = false;
switch($method){
case 'auth':
list($username, $server, $password) = $toks;
$password = trim($password);
fwrite($fs, "checking user: $username and password $password\n");
if($users[$username] == $password){
fwrite($fs, "password match\n");
$result = true;
}else{
$result = false;
}
break;
case 'isuser':
list($username, $server) = $toks;
if(isset($users[$username])){
$result = true;
}else{
$result = false;
}
break;
default:
$result = false;
}
$message = @pack("nn", 2, $result);
fwrite($stdout, $message);
$dump = @unpack("nn", $message);
$dump = $dump["n"];
fwrite($fs, $dump . "\n");
flush();
} while(true);
?>
当我启动 xjabberd 并尝试使用 'user1@example.com' 和密码:'password1' 连接时,它需要很长时间,最终失败。在日志文件中,我看到从上述 PHP 脚本生成的以下条目。当从客户端到服务器的连接发生时,这些几乎立即发生。
auth:user1:example.com:password1
auth
checking user: user1 and password password1
password match
2
在 /var/log/ejabberd/ejabberd.log 我有以下条目:
=INFO REPORT==== 2011-02-20 01:15:26 ===
I(<0.557.0>:ejabberd_c2s:587) : ({socket_state,tls,{tlssock,#Port<0.2820>,#Port<0.2844>},<0.556.0>}) Failed authentication for user1@example.com
=ERROR REPORT==== 2011-02-20 01:15:36 ===
E(<0.365.0>:extauth:80) : extauth call '["auth","user1@example.com",
"example.com","password1"]' didn't receive response
=INFO REPORT==== 2011-02-20 01:15:36 ===
I(<0.559.0>:ejabberd_c2s:587) : ({socket_state,tls,{tlssock,#Port<0.2846>,#Port<0.2848>},<0.558.0>}) Failed authentication for user1@example.com@example.com
=INFO REPORT==== 2011-02-20 01:15:37 ===
I(<0.553.0>:ejabberd_listener:232) : (#Port<0.2850>) Accepted connection {{10,1,1,3},55051} -> {{10,130,11,243},5222}
=ERROR REPORT==== 2011-02-20 01:15:50 ===
E(<0.365.0>:extauth:80) : extauth call '["auth","user1","example.com",
"password1"]' didn't receive response
=INFO REPORT==== 2011-02-20 01:15:50 ===
I(<0.561.0>:ejabberd_c2s:587) : ({socket_state,tls,{tlssock,#Port<0.2850>,#Port<0.2852>},<0.560.0>}) Failed authentication for user1@example.com
=INFO REPORT==== 2011-02-20 01:15:51 ===
I(<0.553.0>:ejabberd_listener:232) : (#Port<0.2854>) Accepted connection {{10,1,1,3},55052} -> {{10,130,11,243},5222}
=ERROR REPORT==== 2011-02-20 01:16:03 ===
E(<0.365.0>:extauth:80) : extauth call '["auth","user1@example.com",
"example.com","password1"]' didn't receive response
=INFO REPORT==== 2011-02-20 01:16:03 ===
I(<0.563.0>:ejabberd_c2s:587) : ({socket_state,tls,{tlssock,#Port<0.2854>,#Port<0.2856>},<0.562.0>}) Failed authentication for user1@example.com@example.com
任何解决此问题的帮助将不胜感激。提前致谢!