Sha256: 3719883cd73041308232e2e1f73d7472652b66d8f1c295cf988756be64add427

Contents?: true

Size: 1.03 KB

Versions: 30

Compression:

Stored size: 1.03 KB

Contents

#!/usr/bin/ruby -w

$:.unshift '../../lib'
require 'shellmgr'
require 'xmpp4r'
include Jabber

if ARGV.length != 3
  puts "usage: ./shellmgr_jabber.rb jid_to_use password jid_to_authorize"
  exit(1)
end

myjid = JID.new(ARGV[0])
mypassword = ARGV[1]
authjid = JID.new(ARGV[2])

myjid = JID.new(myjid.node, myjid.domain, 'RSM')
cl = Client.new(myjid)
cl.connect
cl.auth(mypassword)
mainthread = Thread.current
sh = Shell.new { |str|
  puts "-----RECEIVING-----\n#{str}"
  cl.send(Message.new(authjid, str)) }
cl.add_message_callback do |m|
  if JID.new(m.from).strip.to_s != authjid.strip.to_s
    puts "Received message from non-authorized user #{m.from}"
  else
    if m.body == "killshell"
      cl.send(Message.new(authjid, "Exiting..."))
      mainthread.wakeup
    else
      puts "-----EXECUTING-----\n#{m.body}"
      sh.puts(m.body)
    end
  end
end
cl.send(Presence.new)
puts "Connected ! Ask #{authjid.to_s} to send commands to #{myjid.to_s}"
cl.send(Message.new(authjid, "I'm ready to receive commands from you."))
Thread.stop
cl.close
sh.kill

Version data entries

30 entries across 30 versions & 12 rubygems

Version Path
brontes3d-xmpp4r-0.4 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
bryanl-xmpp4r-0.3.2 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
edavey-xmpp4r-0.4.1 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
edavey-xmpp4r-0.4.2 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
edavey-xmpp4r-0.4 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
heipei-xmpp4r-0.3.2 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
ln-xmpp4r-0.5 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
mojodna-xmpp4r-0.4.0.2 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
mojodna-xmpp4r-0.4.0.3 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
seanohalpin-xmpp4r-0.4.1 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
xmpp4r-0.5.6 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
xmpp4r-0.5.5 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
mad-p-xmpp4r-0.6.3 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
mad-p-xmpp4r-0.6.2 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
mad-p-xmpp4r-0.6.1 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
mad-p-xmpp4r-0.6.0 data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
cerberus-0.8.0 lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
cerberus-0.7.9 lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
edavis10-cerberus-0.7.8 lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb
cerberus-0.7.8 lib/vendor/xmpp4r/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb