从 PHP 调用 ejabberdctl

发布于 2024-08-24 18:25:46 字数 536 浏览 5 评论 0原文

我正在开发一个 php 社交网络,该网络要求我们为所有新成员创建 XMPP 帐户。我有一个正在运行的 Ejabberd 服务器,运行 mod_admin_extra ,一切正常。

我试图从 php 文件中调用 ejabberdctl,如下所示:

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

但出现以下错误:

Failed RPC connection to the node ejabberd@localhost: nodedown

尽管相同的命令可以从命令行运行。

我还在 /etc/sudoers 中添加了以下内容:

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

那么什么给出了呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

若相惜即相离 2024-08-31 18:25:46

使用 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]');
?>

You might have better luck using phpseclib, a pure PHP SSH implementation:

<?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]');
?>
提笔书几行 2024-08-31 18:25:46

Ejabberd 有一个特殊帐户,如果我的 php exec 调用以以下开头,那么它对我来说工作得很好:

su - ejabberd -c“ejabberd 命令...”

(没有密码...嗯)

Ejabberd has a special account, and it's work fine for me if my php exec call begin with :

su - ejabberd -c "ejabberd commands..."

(with no password... hmm)

浴红衣 2024-08-31 18:25:46

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

This sometimes happens if you start ejabberd with an user and then use another user to restart, so maybe it has something to do with the user who's running the command through php?

陌生 2024-08-31 18:25:46

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

另外,您可能需要研究 mod_xmlrpc,它允许您通过 XMLRPC 接口执行任何 ejabberdctl 命令。

Avoid using sudo, copy over the ejabberd cookie to your www user and call ejabberdctl directly.

Also, you may want to look into mod_xmlrpc which will allow you to execute any ejabberdctl commands over a XMLRPC interface.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文