home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2003 July / CD 1 / APC0307D1.iso / workshop / jabber / files / jabuser.sh < prev   
Encoding:
Linux/UNIX/POSIX Shell Script  |  2003-04-10  |  1.6 KB  |  73 lines

  1. #! /bin/sh
  2. # Script to add users to a Jabber server
  3. #
  4. # Author: John Heller 03-Apr-2003
  5.  
  6. # Location of Jabber server config file
  7. config="/etc/jabber/jabber.xml"
  8.  
  9.  
  10. prog=`basename $0`
  11.  
  12. if [ $# != 2 ]
  13. then
  14.     echo "Usage: $prog <username> <password>"
  15.     exit 1
  16. fi
  17.  
  18. user=$1
  19. pass=$2
  20.  
  21. if [ ! -f $config ]
  22. then
  23.     echo "$config does not exist"
  24.     exit 1
  25. fi
  26.  
  27. # Source the Mandrake jabber.cfg if its present
  28. [ -f /etc/jabber/jabber.cfg ] && . /etc/jabber/jabber.cfg
  29.  
  30. if [ -z "$JABBER_SPOOL" ]
  31. then
  32.     JABBER_SPOOL=`egrep -o "<spool>.+</spool>" $config | sed -e "s/<[^>]*>//g"`
  33. fi
  34.  
  35. if [ -z "$JABBER_SPOOL" ]
  36. then
  37.     echo "Unable to determine the Jabber spool directory"
  38.     exit 1
  39. fi
  40.  
  41. if [ -z "$JABBER_HOSTNAME" ]
  42. then
  43.     JABBER_HOSTNAME=`egrep -o "<host>.+</host>" $config | sed -e "s/<[^>]*>//g"`
  44. fi
  45.  
  46. if [ -z "$JABBER_HOSTNAME" ]
  47. then
  48.     echo "Unable to determine the Jabber server hostname"
  49.     exit 1
  50. fi
  51.  
  52.  
  53. if [ -z "$user" -a -z "$pass" ]; then
  54.     echo "Invalid username or password supplied"
  55.     exit 1
  56. fi
  57.  
  58. mkdir -p $JABBER_SPOOL/$JABBER_HOSTNAME
  59.  
  60. if [ -e "$JABBER_SPOOL/$JABBER_HOSTNAME/$user.xml" ]; then
  61.     echo "User $user already exists, not creating."
  62.     exit 1
  63. fi
  64.  
  65. if cat > $JABBER_SPOOL/$JABBER_HOSTNAME/$user.xml << EOF
  66. <xdb><password xmlns='jabber:iq:auth' xdbns='jabber:iq:auth'>$pass</password><qu
  67. ery xmlns='jabber:iq:register' xdbns='jabber:iq:register'><username>$user</usern
  68. ame><password xmlns='jabber:iq:auth'>$pass</password></query></xdb>
  69. EOF
  70. then
  71.     echo "User \"$user@$JABBER_HOSTNAME\" created"
  72. fi
  73.