我正在尝试使用 ejabberd 设置 extauth,但是我无法使其正常工作(即使在谷歌上搜索网络修复后)。我在 ejabberd.cfg 中设置了以下内容:
{auth_method, external}.
{extauth_program, "/etc/ejabberd/extauth.class.php"}.
当我在更新配置后重新启动 ejabberd 时,我在 ejabberd.log 的末尾看到了这一点:
=ERROR REPORT==== 2010-12-26 15:38:10 ===
C(<0.4476.0>:extauth:110) : normal
=INFO REPORT==== 2010-12-26 15:38:10 ===
I(<0.4181.0>:ejabberd_app:69) : ejabberd 2.1.x is started in the node
我的 extauth 脚本只不过是从check_mysql.php.txt派生的,但到目前为止还没有任何数据库链接。这是我正在尝试使用的完整脚本:
<?php
error_reporting(1);
class imAuth {
function __construct() {
$this->log = fopen('/etc/ejabberd/extauth.log', 'a');
$this->openstd();
}
function openstd() {
$this->stdout = @fopen("php://stdout", "w");
$this->stdin = @fopen("php://stdin", "r");
}
function out($data) {
@fwrite($this->stdout, $data);
$dump = @unpack("nn", $data);
$dump = $dump["n"];
$this->logg("OUT: ". $dump);
}
function closestd() {
@fclose($this->stdin);
@fclose($this->stdout);
}
function stop() {
$this->logg("Shutting down ...");
@fclose($this->log);
$this->closestd();
exit(0);
}
function logg($data) {
fwrite($this->log, $data."\n");
}
function splitcomm() {
return explode(":", $this->data);
}
function checkuser() {
return true;
}
function checkpass() {
return true;
}
function command() {
$data = $this->splitcomm();
$this->logg("Processing command ".$data[0]);
switch($data[0]) {
case 'isuser':
$log = $data[1];
$ret = $this->checkuser();
break;
case 'auth':
$log = $data[1].":".$data[2].":".md5($data[3]);
$ret = $this->checkpass();
break;
case 'setpass':
$ret = false;
break;
default:
$this->stop();
break;
}
$ret = ($ret) ? 1 : 0;
if(strlen($data[0]) > 0 && strlen($log) > 0) {
$this->logg("Command : ".$data[0].":".$log." ==> ".$ret." ");
}
return @pack("nn", 2, $return);
}
function readstdin() {
$l = @fgets($this->stdin, 3);
$length = @unpack("n", $l);
$len = $length["1"];
if($len > 0) {
$this->logg("Reading $len bytes ... ");
$data = @fgets($this->stdin, $len+1);
$this->data = $data;
$this->logg("IN: ".$data);
}
}
function play() {
do {
$this->readstdin();
$length = strlen($this->data);
$ret = $this->command();
$this->logg("RE:".$ret);
$this->out($ret);
$this->data = null;
} while(true);
}
}
$auth = new imAuth();
$auth->play();
?>
当我的客户尝试登录聊天时,我在里面看到以下内容ejabberd.log
:
=ERROR REPORT==== 2010-12-26 15:38:31 ===
** State machine <0.4566.0> terminating
** Last event in was {xmlstreamelement,
{xmlelement,"auth",
[{"xmlns","urn:ietf:params:xml:ns:xmpp-sasl"},
{"mechanism","PLAIN"}],
[{xmlcdata,
<<"AGpheGwAbGlmZWlzbGlmZTI1QSFAKCk=">>}]}}
** When State == wait_for_feature_request
** Data == {state,{socket_state,gen_tcp,#Port<0.34718>,<0.4565.0>},
ejabberd_socket,#Ref<0.0.0.104846>,false,"103115738",
{sasl_state,"jabber","dev.jaxl.im",[],
#Fun<ejabberd_c2s.1.30334249>,
#Fun<ejabberd_c2s.2.32721014>,
#Fun<ejabberd_c2s.3.7052687>,undefined,
undefined},
c2s,c2s_shaper,false,false,false,false,
[verify_none],
false,undefined,[],"dev.jaxl.im",[],undefined,
{pres_t,0},
{pres_f,0},
{pres_a,0},
{pres_i,0},
undefined,undefined,undefined,false,
{userlist,none,[],false},
unknown,unknown,
{{127,0,0,1},33227},
"en"}
** Reason for termination =
** {badarg,[{extauth,call_port,2},
{ejabberd_auth_external,check_password_extauth,3},
{ejabberd_auth,check_password_loop,2},
{cyrsasl_plain,mech_step,2},
{cyrsasl,server_step,2},
{ejabberd_c2s,wait_for_feature_request,2},
{p1_fsm,handle_msg,10},
{proc_lib,init_p_do_apply,3}]}
我已经通过直接通过命令行运行/path/to/php /etc/ejabberd/extauth.class.php
并通过 STDIN 传递参数来测试我的脚本,它的行为符合预期。
我还尝试修改 extauth.class.php 以及 extauth.log 的权限,但没有结果。
有经验的人可以帮我解决这个问题吗?