我发现了一个来自stack over flow的代码,用于在ejabberd xmpp聊天服务器中使用php执行register命令。 (从PHP创建ejabberd用户)
但是当我执行文件时出现错误:
“sudo:未知用户:ejabberd” “sudo:无法初始化策略插件”
我在我的ubuntu(14.04 LTS 64位)计算机上运行此代码 我正在使用的PHP代码如下:
<?php
$username = 'tester';
$password = 'testerspassword';
$node = 'myserver.com';
exec('sudo -u ejabberd /usr/sbin/ejabberdctl register '.$username.' '.$node.' '.$password.' 2>&1',$output,$status);
if($output == 0)
{
// Success!
}
else
{
// Failure, $output has the details
echo '<pre>';
foreach($output as $o)
{
echo $o."\n";
}
echo '</pre>';
}
?>
答案 0 :(得分:1)
<?php
$username = 'tester';
$password = 'testerpassword';
$node = 'localhost';
echo exec('sudo -u ejabberd /usr/sbin/ejabberdctl register '.$username.' '.$node.' '.$password.' 2>&1',$output,$status);
die;
if($output == 0)
{
// Success!
echo "success";
}
else
{
// Failure, $output has the details
echo '<pre>';
foreach($output as $o)
{
echo $o."\n";
}
echo '</pre>';
}
?>
我在localhost
中使用$node
,在$ node中,您可以根据您在configure.cfg中配置的IP地址使用您的IP地址。
运行上面的代码时出现以下错误
no tty present and no askpass program specified ; TTY=unknown ;
所以下面的链接是下面代码的解决方案
执行上述链接过程后
User tester@localhost successfully registered