1

I am working on a php social network that requires us to create XMPP accounts for all new members. I have a working Ejabberd server running with mod_admin_extra all working fine.

I am trying to call ejabberdctl from a php file like so:

exec('sudo /home/user/ejabberd-2.1.2/bin/ejabberdctl register test server pass 2>&1');

but i get the following error :

Failed RPC connection to the node ejabberd@localhost: nodedown

Although the same command works from the command line.

I have also added the following to /etc/sudoers :

www-data ALL= NOPASSWD: /home/webuser/ejabberd-2.1.2/bin/ejabberdctl

So what gives?

4

4 回答 4

2

使用phpseclib,一个纯 PHP SSH 实现,你可能会有更好的运气:

<?php
include('Net/SSH2.php');

$ssh = new Net_SSH2('localhost', 22);
$ssh->login('username', 'password');

$ssh->read('[prompt]');
$ssh->write("su - user\n");
$ssh->read('Password:');
$ssh->write("Password\n");
echo $ssh->read('[prompt]');
?>
于 2011-04-22T21:50:13.313 回答
1

Ejabberd 有一个特殊帐户,如果我的 php exec 调用以以下开头:

su - ejabberd -c "ejabberd 命令..."

(没有密码......嗯)

于 2011-03-08T21:00:57.747 回答
0

如果您使用一个用户启动 ejabberd 然后使用另一个用户重新启动,有时会发生这种情况,所以它可能与通过 php 运行命令的用户有关?

于 2010-04-22T01:04:44.763 回答
0

避免使用 sudo,将 ejabberd cookie 复制到您的 www 用户并直接调用 ejabberdctl。

此外,您可能希望查看 mod_xmlrpc,它允许您通过 XMLRPC 接口执行任何 ejabberdctl 命令。

于 2010-08-23T10:18:26.573 回答