ejabberdctl-extra - Additional Commands for ejabberdctl

WARNING

This patch is obsolete. Use mod_ctlextra instead.
Name: ejabberdctl-extra
Purpose: Adds more options for ejabberd_ctl
Author: Badlop
Type: Patch
Requirements: ejabberd 0.9.8 or 1.0.0
Download: ejabberdctl-extra.diff

Provided Commands

 - SERVER:
  load-config file              load config from file
  compile file                  recompile and reload file

 - MAINTANCE:
  delete-older-messages days    delete offline messages older than 'days'
  delete-older-users days       delete users that have not logged in the last 'days'

 - USERS:
  register user server password                 register a user
  set-password user server password             set password to user@server
  unregister user server                        unregister a user
  num-active-users vhost days                   number of users active in the last 'days'
  vcard-get user server data [data2]            get data from the vCard of the user
  vcard-set user server data [data2] content    sets data to content on the vCard

 - ROSTERS:
  add-rosteritem user1 server1 user2 server2 nick group subs
       Adds user2@server2 to user1@server1
       subs= none, from, to or both
       example: add-roster peter localhost mike server.com MiKe Employees both
       will add mike@server.com to peter@localhost roster
  pushroster file user server           push template roster in file to user@server
  pushroster-all file                   push template roster in file to all those users
  push-alltoall server group            adds all the users to all the users in Group

 - SHARED ROSTER GROUPS:
  create-group group host name description display      Create the group with options
  delete-group group host                               Delte the group
  add-usertogroup username server group host            Adds user@server to group on host
  rem-userfromgroup username server group host          Removes user@server from group on host

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Two word (or more) nick names?

I installed this module and it seems to work fine except I want to use the "add-rosteritem" function to add nicknames to all of my users. The problem is I can't see how to add nick names with more than one word in them. I can add them fine if they are one word, but the minute I try to make it two words it just assumes the last name is a group. I can change the nick to two words from within Psi just fine but I am trying to do it from the command line so I can write a script to do it for all of my users. I have tried surrounding the nick with the following and none have helped: [ ], { }, " ", ' ', < >

Any help would be appreciated!
Thanks,
Paul

Re: Two word (or more) nick names?

frielp wrote:

I have tried surrounding the nick with the following and none have helped: [ ], { }, " ", ' ', < >

I found it works for me with two different solutions:

  • doble quotes inside simple quotes, example: '"John Jack"'
  • or simple quotes inside doble quotes, example: "'John Jack'"

Re: Two word (or more) nick names?

badlop wrote:

I found it works for me with two different solutions:

  • doble quotes inside simple quotes, example: '"John Jack"'
  • or simple quotes inside doble quotes, example: "'John Jack'"

I tried what you suggested above and that didn't seem to work either. I am using ejabberd v1.1.1 on Slackware Linux 10.2 in case that makes any difference. Here is exactly what I am trying:

  • ./ejabberdctl ejabberd@server add-rosteritem first.last server.domain.com first.last server.domain.com "'John Smith'" Accounting none
  • ./ejabberdctl ejabberd@server add-rosteritem first.last server.domain.com first.last server.domain.com '"John Smith"' Accounting none

Both of those don't work.. ejabberdctl just spits out the "usage" like I'm not using it correctly. If I just use one name like below it works fine:

  • ./ejabberdctl ejabberd@server add-rosteritem first.last server.domain.com first.last server.domain.com John Accounting none

Thanks again for your help and for making this module. :)

Try this custom script

I forgot to mention that I don't use the script on tools/ejabberdctl, but by own script. When I tried with the default one, it failed as you mention.

I don't know where lies the problem exactly, but try it.

For reference, this experiment uses the default script:

$ cat ejabberdctl
#!/bin/sh

exec erl -noinput -sname ejabberdctl -s ejabberd_ctl -extra $@

$ ./ejabberdctl ejabberd2@localhost add-rosteritem badlop localhost bob localhost "'Bob Smith'" workers both
Usage: ejabberdctl node command

Available commands:
...

and nothing is done on the roster.

Using my custom script:

$ cat ejabberdctl2
#!/bin/bash

sh -c "erl -noinput -sname ejabberdctl -s ejabberd_ctl -extra $1 $2 $3 $4 $5 $6 $7 $8 $9"

$ ./ejabberdctl2 ejabberd2@localhost add-rosteritem badlop localhost bob localhost "'Bob Smith'" workers both
$

and the item is added to the roster.

If you find a clue where exactly the problem is, please tell me.

ejabberdctl script argument processing

simple test.

$ cat ./erlp
#!/usr/bin/perl
# dump arguments one per line.
print join("\n", @ARGV),"\n";

$ cat ./ejabberdctl
#!/bin/sh
# call argument dumper 'erlp'
exec ./erlp -noinput -sname ejabberdctl -s ejabberd_ctl -extra $@

$ ./ejabberdctl ejabberd2@localhost add-rosteritem badlop localhost bob localhost "'Bob Smith'" workers both
-noinput
-sname
ejabberdctl
-s
ejabberd_ctl
-extra
ejabberd2@localhost
add-rosteritem
badlop
localhost
bob
localhost
'Bob
Smith'
workers
both

problem is in argument expansion. need '"' around $@

$ cat ./ejabberdctl_fix
#!/bin/sh
# call argument dumper 'erlp'
# added '"' around $@
exec ./erlp -noinput -sname ejabberdctl -s ejabberd_ctl -extra "$@"

$ ./ejabberdctl_fix ejabberd2@localhost add-rosteritem badlop localhost bob localhost "'Bob Smith'" workers both
-noinput
-sname
ejabberdctl
-s
ejabberd_ctl
-extra
ejabberd2@localhost
add-rosteritem
badlop
localhost
bob
localhost
'Bob Smith'
workers
both

Allow spaces in nickname of contact

So I changed ejabberdctl and added " " quotes around both instances of $@.

This has worked so far, but I haven't tested all the commands, just vcard-set and add-rosteritem

When trying to use ejabberdctl2 as you wrote, I got errors trying to connect to a different server. (Running ejabberdctl to control a remote server)

ejabberdctl2/roster issues

I changed my ejabberdctl script to reflect the changes you mentioned and that works fine. Now I have created a bash script to modify all of the user's rosters so the names show as a regular name instead of the usernames. If I only run the single line as you did above it works fine, but when I run it for each user one after another the aliases keep disappearing for the previous users. So for example:

I run: ./ejabberdctl2 ejabberd2@localhost add-rosteritem badlop localhost bob localhost "'Bob Smith'" workers both

Then I would run: ./ejabberdctl2 ejabberd2@localhost add-rosteritem paul localhost badlop localhost "'badlop lastname'" workers both

But when it is run that second time it fills out the roster perfectly for the user paul, but it removes the previously added alias for paul on the badlop user's profile. So what ends up happening is the last user in my bash script has all the aliases correctly displayed.. but the first user in the bash script has none of them. Of course all the users in between have a progressively larger and larger list of correct aliases as you get towards the end of the bash script. Here is the script I'm using to do this.. but it happens whether I use the script or not.

ANY help would really be appreciated.. hope some of this makes sense to you all.

#!/bin/bash

# combined.txt is in the form: john.smith "'John Smith'" Tech
# with each user being on it's own separate line

# Cycle through the # of users as read from the file
for (( j = 1; j <= `wc -l combined.txt |awk '{print $1}'`; j++ ))
do

# grab $j line in file and assign username to variable
username=`cat -n combined.txt |grep $j -m 1 |awk '{print $2}'`

echo "Modifying roster for:" $username

for (( k = 1; k <= `wc -l combined.txt |awk '{print $1}'`; k++))
do

# assign username, full name and department to variables
nametoadd=`cat -n combined.txt |grep $k -m 1 |awk '{print $2}'`
nameinquotes=`cat -n combined.txt |grep $k -m 1 |awk '{print $3 " " $4}'`
department=`cat -n combined.txt |grep $k -m 1 |awk '{print $5}'`

./ejabberdctl2 "ejabberd@localhost add-rosteritem $username server.domain.com $nametoadd server.domain.com $nameinquotes $department none"

echo "...added:" $nametoadd
done
done

About Adds more options for ejabberd_ctl

I try to apply your steps to enable the new features that you added.
But there is many problems. When I restart ejabberd, can't load the module. in the log file I found this:
[Loading of /opt/ejabberd-1.1.1/lib/ejabberd-1.1.1/ebin/mod_ctlextra.beam failed: badfile],[beam/beam_load.c(1097): Error loading module mod_ctlextra:
use of opcode 125; this emulator supports only up to 115]
I would like to apply your module. Can you help me? can you explain farther? can you send me details steps. if you hava the compiled module, send it to me.

Re: About Adds more options for ejabberd_ctl

flower wrote:

When I restart ejabberd, can't load the module. in the log file I found this:
[Loading of /opt/ejabberd-1.1.1/lib/ejabberd-1.1.1/ebin/mod_ctlextra.beam failed: badfile],[beam/beam_load.c(1097): Error loading module mod_ctlextra:
use of opcode 125; this emulator supports only up to 115]

You probably compiled the module using Erlang R11B, but you try to use it on Erlang R10B, right? Make sure you compile the module with the same version that you later use. ejabberd is not yet tested with Erlang R11B, so you better use Erlang R10B-10.

You are using beam file for another Erlang version

Hello,

You are using beam files compiled with Erlang R11B on an older Erlang (probably R10B).
You need to recompile from source on the target system.

--
Mickaël Rémond
Process-one

Chcngelog request

Badlop,
can you include changelog in this and the rest of your contributed modules (something similar to the one from mod_logxml for example), please.

How to use diff in the FreeBSD?

I have ejabberd installed in a FreeBSD and I wanted to know as to activate this feature!

Re: How to use diff in the FreeBSD?

Apply the patch to the ejabberd source code and compile.

Apply patch on FreeBSD

Thanks.. :D
I apply the patch:

# make extract
===> Vulnerability check disabled, database not found
===> Extracting for ejabberd-0.9.8
=> MD5 Checksum OK for ejabberd-0.9.8.tar.gz.
# cp ejabberdctl-extra.diff /usr/ports/net-im/ejabberd/work/ejabberd-0.9.8/src/
# cd /usr/ports/net-im/ejabberd/work/ejabberd-0.9.8/src/
# patch < ejabberdctl-extra.diff
Hmm... Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: ejabberd_ctl.erl
|===================================================================
|--- ejabberd_ctl.erl (revisión: 444)
|+++ ejabberd_ctl.erl (copia de trabajo)
--------------------------
Patching file ejabberd_ctl.erl using Plan A...
Hunk #1 succeeded at 6 with fuzz 1.
Hunk #2 succeeded at 192.
Hunk #3 succeeded at 261.
Hunk #4 succeeded at 499.
Hunk #5 succeeded at 516.
Hunk #6 succeeded at 584.
done
#

Syndicate content