我正在尝试使用ejabberd设置extauth,但是我无法让它工作(即使在Google上搜索修复后)。我在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的权限而没有结果。
有经验的人可以帮我解决这个问题吗?
答案 0 :(得分:1)
我遇到了一些问题。我从用户root测试了我的auth php脚本,然后尝试了
root@vm1096:/root~$ su ejabberd [20:55:57]
sh-3.2$ /var/lib/ejabberd/joomla-auth.php
Warning: fopen(/var/log/ejabberd/exauth.log): failed to open stream: Permission denied in /var/lib/ejabberd/joomla-auth.php on line 105
Call Stack:
0.0009 125028 1. {main}() /var/lib/ejabberd/joomla-auth.php:0
0.0009 127136 2. exAuth->__construct() /var/lib/ejabberd/joomla-auth.php:75
0.0010 127780 3. fopen() /var/lib/ejabberd/joomla-auth.php:105
是行,写日志文件。通过su ejabberd检查脚本并为脚本设置正确的访问权限:
chmod 700 /var/lib/ejabberd/joomla-auth.php
chown ejabberd:ejabberd /var/lib/ejabberd/joomla-auth.php