I found a code from stack over flow to execute the register command in ejabberd xmpp chat server using php. (Create ejabberd user from PHP)
But when i execute the file i got error:
"sudo: unknown user: ejabberd" "sudo: unable to initialize policy plugin"
I am runing this code on my ubuntu(14.04 LTS 64-bit) machine The php code i am using as follows:
<?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>';
}
?>
<?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>';
}
?>
I am using localhost in the $node, in the $node you can use your ip address as per the ip address you have configure in your configure.cfg.
I have the following error while running the above code
no tty present and no askpass program specified ; TTY=unknown ;
so the below link is the solution for the code below
sudo in php exec()
after executing the above link process
User tester@localhost successfully registered
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With