CGI Call to ejabberdctl

This used to work:

#!/bin/sh

export NODE=ejabberd
export HOST=localhost
export VERSION=1.1.2

# Main directories
export ROOTDIR=/opt/ejabberd-1.1.2
export BINDIR=$ROOTDIR/bin
export PROGNAME=$BINDIR/erl
export EMU=beam
export HOME=$BINDIR

export LD_LIBRARY_PATH=$ROOTDIR/lib/linux-x86/ #hard code vs. below

$BINDIR/erlexec \
-noinput \
-sname ejabberdctl@$HOST \
-s ejabberd_ctl -extra $NODE@$HOST user-resources $@

However, I'm on a new machine and on version 2.0.2.
Changing hte version numbers from 1.1.2 to 2.0.2 did not do the trick.

I used to call this from cgi (linux/apache) and it returned all active resources for the "user server".
Now under version 2.0.2, doesn't work anymore. Note: I provided a .erlang.cookie for the apache user.

I did notice that the ejabberdctl script and erl script is different across these versions --- ejabberd-ctl vs. ejabberdctl in -sname, for example.

How can I update this? It is handy for a very quick presence check.

Try ejabberdctl

I didn't check in detail your script. I think you can use the included ejabberdctl script instead of it.

I tried this:

  1. Installed ejabberd 2.0.2 using source code.
  2. Started ejabberd
  3. Then I execute:
    $ sudo ejabberdctl user-resources badlop localhost
    Home2
    $
    

Of course, in your case the ejabberdctl script may be in a different location, and may require or not to be root.

limited ejabberdctl function from cgi

1. ejabberdctl has way too many functions to make it available to any user. Therefore, intentionally limiting the call to the user-resources function as a presence check
2. The above script was called from a perl script cgi apache as the apache user.
3. Don't want to run from cgi as root.

ejabberdctl user-resources user server works in 2.0.2 as advertised, but, that's not the point or the issue.

This was just a handy way for processes (not IM stuff) to check for user/resource presence without having to log in, subscribe, etc., or interrogating the database (mnesia).

Once a user/resource was identified as present, then, and only then, would processes be applied to that user/resource.

Looked into XML-RPC methods - seem too complicated. If I could update the script to run with newer versions of the server, that would be great.

What is missing from the script?

Example system call using regular user

Ah, ok, I didn't notice the requirement of executing the script with a regular user, not root.

I tried this using ejabberd trunk SVN. In your system probably you will have different ebin path and cookie path.

$ ejabberdctl
bash: /sbin/ejabberdctl: Permiso denegado

$ erl -noinput -sname ejactl -pa /lib/ejabberd/ebin/ -s ejabberd_ctl -extra ejabberd@localhost connected-users-number
RPC failed on the node ejabberd@localhost: nodedown

And in the ejabberd log files i see:

** Connection attempt from disallowed node ejactl@atenea **

Now i provide the cookie:

$ COOKIE=`sudo cat /var/lib/ejabberd/.erlang.cookie`

$ echo $COOKIE
PVMCWDKIODNMGKFRAJMW

$ erl -setcookie $COOKIE -noinput -sname ejactl -pa /lib/ejabberd/ebin/ -s ejabberd_ctl -extra ejabberd@localhost connected-users-number
1
Syndicate content