Announce
script
Download, Add a comment, Back to main page
[2004-06-02 17:46 CDT] Matthew Ife (email) Before doing this you might want to create a .tmp directory in your home directory for the user that runs this in the command prompt :)
#Matthew Ife
#Jabber ID and email:deleriux@airattack.co.uk
#Servers name and hostname is different thus server is not dns friendly for other jabber servers. Therefore its easier to get me:
#ICQ: 100860583
#!/bin/bash
#THIS SCRIPT REQUIRES NETCAT, SOME VERSIONS OF NETCAT ARE CALLED 'nc' SO YOU MIGHT WANT TO CHANGE THE NAME UNDER THE FUNCTION jabber:execute APPROPRIATELY
#My scripts are horribly nastily hacked, but hopefully this one isnt too complex.
ANNOUNCEUSERNAME=example
SERVERNAME=example.co.uk
SERVERHOST=example.co.uk #used if your server name is different from your servers actual hostname
ANNOUNCEPASSWORD=example
RESOURCE=example
#path to the netcat program
NETCATPATH=/opt/local/bin
function jabber::login()
{
#start the script writing
echo -n "<stream:stream" >~/.tmp/sendscript
echo -n " to='$SERVERNAME'">>~/.tmp/sendscript
echo -n " xmlns='jabber:client'">>~/.tmp/sendscript
echo -n " xmlns:stream='http://etherx.jabber.org/streams'>">>~/.tmp/sendscript
echo " ">>~/.tmp/sendscript
echo -n "<iq id='auth1' type='set'>">>~/.tmp/sendscript
echo -n " <query xmlns='jabber:iq:auth'>">>~/.tmp/sendscript
echo -n " <username>$ANNOUNCEUSERNAME</username>">>~/.tmp/sendscript
echo -n " <password>$ANNOUNCEPASSWORD</password>">>~/.tmp/sendscript
echo -n " <resource>$RESOURCE</resource>">>~/.tmp/sendscript
echo -n " </query>">>~/.tmp/sendscript
echo -n "</iq>">>~/.tmp/sendscript
echo "">>~/.tmp/sendscript
return
}
function jabber::announce()
{
MESSAGECOUNTER=1
while [ $MESSAGECOUNTER -le $DYNAMICCOUNTER ];do
echo -n "<message to='${USERLIST[$MESSAGECOUNTER]}'>">>~/.tmp/sendscript
echo -n " <subject>$SUBJECT</subject>">>~/.tmp/sendscript
echo -n " <body>$MESSAGE</body>">>~/.tmp/sendscript
echo -n "</message>">>~/.tmp/sendscript
let MESSAGECOUNTER=$MESSAGECOUNTER+1
done
return
}
function jabber::endmsg()
{
echo "">>~/.tmp/sendscript
echo -n "</stream:stream>" >>~/.tmp/sendscript
echo "" >>~/.tmp/sendscript
return
}
function jabber::messagecollect()
{
while [ "$1" != "" ];do
MESSAGE="$MESSAGE $1";
shift
done
return
}
function jabber::subjectcollect()
{
while [ "$1" != "" ]; do
SUBJECT="$SUBJECT $1";
shift
done
return
}
function jabber::usercollect()
{
DYNAMICCOUNTER=1
while [ "$1" != "" ]; do
USERLIST[$DYNAMICCOUNTER]=$1
let DYNAMICCOUNTER=$DYNAMICCOUNTER+1
shift
done
let DYNAMICCOUNTER=$DYNAMICCOUNTER-1
return
}
function jabber::execute()
{
$NETCATPATH/netcat --interval=1 $SERVERHOST 5222 <~/.tmp/sendscript>~/output
rm ~/output 2>/dev/null
rm ~/.tmp/sendscript
}
#make sure something wrote in
if [ "$1" == "" ]; then
echo "Must type usernames as argument to send, users must be in quotes"
echo "Subject must be in quotes."
echo "example: $0 \"exampleuser@example.co.uk exampleuser2@example.co.uk \" Subject: \"Example Subject\" Mesg: \"Example message\""
echo "If you plan on using this script in other scripts the best way to do this is open up a new bash prompt in your script, for example"
echo echo "$0 \"exampleuser@example.co.uk exampleuser2@example.co.uk \" Subject: \"Example Subject\" Mesg: \"Example message\"">somescript
bash ./somescript
rm ./somescript
exit 1
else
#collect the users
jabber::usercollect $1
fi
#collect the subject
if [ "$2" == "Subject:" ]; then
jabber::subjectcollect $3
fi
if [ "$2" == "subject:" ]; then
jabber::subjectcollect $3
fi
if [ "$2" == "SUBJECT:" ]; then
jabber::subjectcollect $3
fi
#collect the message
if [ "$4" == "Mesg:" ]; then
jabber::messagecollect $5
else
echo "No message found, (Mesg:) bailing out.."
exit 1
fi
jabber::login
jabber::announce
jabber::endmsg
jabber::execute