Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to register user on ejabbered using php code

Tags:

php

ejabberd

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>';
    }
?>
like image 461
varun joshi Avatar asked Sep 02 '26 03:09

varun joshi


1 Answers

<?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
like image 148
Harshit Sethi Avatar answered Sep 03 '26 16:09

Harshit Sethi