Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env /usr/bin/ruby
- #
- # * ----------------------------------------------------------------------------
- # * "THE BEER-WARE LICENSE" (Revision 42):
- # * <kim@maisspace.org> wrote this file. As long as you retain this notice you
- # * can do whatever you want with this stuff. If we meet some day, and you think
- # * this stuff is worth it, you can buy me a beer in return Kim Jahn
- # * ----------------------------------------------------------------------------
- #
- require 'xmpp4r'
- require 'optparse'
- usage = 'Usage: sendxmpp.rb [options] receiver1@jabber.example.com receiver2@jabber.example.com'
- options = {}
- optparse = OptionParser.new do|opts|
- opts.banner = usage
- # not yet implemented
- # options['chatroom'] = ""
- # opts.on( '-c', '--chatroom CHATROOM', 'chatroom' ) do|chatroom|
- # options['chatroom'] = chatroom
- # end
- options['debug'] = false
- opts.on( '-d', '--debug', 'debug' ) do
- options['debug'] = true
- end
- options['file'] = ENV['HOME']+'/.sendxmpp'
- opts.on( '-f', '--file FILE', 'Use FILE for configuration instead of ~/.sendxmpp' ) do|file|
- options['file'] = file
- end
- opts.on( '-h', '--help', 'Display this screen' ) do
- puts opts
- exit
- end
- # not yet implemented
- # options['interactive'] = false
- # opts.on( '-i', '--interactive', 'interactive' ) do
- # options['interactive'] = true
- # end
- # not yet implemented
- # options['jserver'] = ""
- # opts.on( '-j', '--jserver SERVER', 'jserver' ) do|jserver|
- # options['jserver'] = jserver
- # end
- options['message'] = false
- opts.on( '-m', '--message MESSAGE', 'use MESSAGE instead of stdin' ) do|message|
- options['message'] = message
- end
- options['password'] = nil
- opts.on( '-p', '--password PASSWORD', 'use PASSWORD instead of the one in the configuration file' ) do|password|
- options['password'] = password
- end
- options["resource"] = "sendxmpp"
- opts.on( "-r", "--resource RESOURCE", "use RESOURCE instead of the on in the configuration file (default: sendxmpp)" ) do|resource|
- options["resource"] = resource
- end
- # not yet implemented
- # options['subject'] = false
- # opts.on( '-s', '--subject SUBJECT', 'subject' ) do|subject|
- # options['subject'] = subject
- # end
- # not yet implemented
- # options['tls'] = false
- # opts.on( '-t', '--tls', 'tls' ) do
- # options['tls'] = true
- # end
- options['username'] = nil
- opts.on( '-u', '--username USERNAME', 'use USERNAME instead of the one in the configuration file' ) do|username|
- options['username'] = username
- end
- # not yet implemented
- # options['verbose'] = false
- # opts.on( '-v', '--verbose', 'Output more information' ) do
- # options['verbose'] = true
- # end
- end
- optparse.parse!
- if File.exists?(options['file'])
- config = {}
- File.foreach(options['file']) do |line|
- line.strip!
- if (line[0] != ?# and line =~ /\S/ )
- i = line.index('=')
- if (i)
- config[line[0..i - 1].strip] = line[i + 1..-1].strip
- else
- config[line] = ''
- end
- end
- end
- if options['debug'] == true
- puts config
- end
- if config['username'] != nil && options['username'] == nil
- options['username'] = config['username']
- end
- if config['password'] != nil && options['password'] == nil
- options['password'] = config['password']
- end
- if config['resource'] != nil && options['resource'] == nil
- options['resource'] = config['resource']
- end
- end
- unless ARGV.length >= 1
- puts usage
- exit
- end
- if options['username'] == nil
- puts 'Dude, you need to set the username'
- exit
- end
- if options['password'] == nil
- puts 'Dude, you need to set the password in the configuration file'
- exit
- end
- if options['debug'] == true
- puts options
- end
- if options['message']
- text = options['message']
- else
- text = STDIN.gets
- end
- ARGV.each do |receiver|
- client = Jabber::Client.new(Jabber::JID.new(options['username']+"/"+options['resource']))
- client.connect
- client.auth(options['password'])
- msg = Jabber::Message.new(receiver,text)
- msg.type = :chat
- client.send(msg)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement