3

I found a code from stack follow to execute the register command in ejabberd xmpp chat server using php. (Create ejabberd user from PHP)

I also add "www-data ALL= NOPASSWD: /usr/sbin/ejabberdctl" line in "/etc/sudoers" file in ubuntu linux server 12.0

But when i execute the file i got error:

"read_passphrase: can't open /dev/tty: No such device or address Host key verification failed."

The php code i am using as follows:

`<?php
$username = 'tester';
$password = 'testerspassword';
$node = 'myserver.com';
exec('sudo /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>';
}
?>`

Please help me!

thanks

Community
  • 1
  • 1
hitender
  • 113
  • 2
  • 8

2 Answers2

0

Hi The following code is working for me..

Just change the one line on above code

exec('sudo -u ejabberd ejabberdctl register '.$username.' '.$node.' '.$password.' 2>&1',$output,$status);

Mani K
  • 183
  • 2
  • 10
  • 1
    Hi mani i use the above code on my ubnutu 14.04 LTS machine but it gives following error to me "sudo: unknown user: ejabberd" "sudo: unable to initialize policy plugin" – varun joshi Dec 16 '15 at 06:28
0

The part sudo -u ejabberd means the command shall be executed within the user, who owns your ejabberd process. Usually this should be an unprivileged user, but maybe your user is called differently or you might even use root. In latter case the command should be like:

exec('sudo -u root ejabberdctl register '.$username.' '.$node.' '.$password.' 2>&1',$output,$status);

Be aware that running services that are accessible to external networks such as internet should not run as root, because of security reasons!

Joundill
  • 6,828
  • 12
  • 36
  • 50