Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. # Jabber-SH β€” SH console via XMPP/Jabber (GTalk)
  4. #
  5. # Jabber-SH allows you to administrate a remote computer via a command line
  6. # through a Jabber client. It’s like SSH via GoogleTalk! :)
  7. # This is just a hack but it might be usefull sometime to run basic commands
  8. # on a machine that is not accessible via ssh.
  9. #
  10. # Philippe Creux. pcreux/AT/gmail/DOT/com
  11.  
  12. # Jabber-SH connects to Jabber using the BOT_LOGIN and BOT_PASSWORD details.
  13. BOT_LOGIN = "A_JABBER_SH_ACCOUNT@gmail.com"
  14. BOT_PASSWORD = "A_JABBER_SH_PASSWORD"
  15.  
  16. # Jabber-SH answers some random epigram via 'fortune' to any message sent to him.
  17. # The user CLIENT_LOGIN logs into the console by sending the CLIENT_PASSPHRASE.
  18. CLIENT_LOGIN = "YOUR_EVERYDAY_ACCOUNT@gmail.com"
  19. CLIENT_PASSPHRASE = "A_PASSPHRASE_TO_LOGIN"
  20.  
  21. require 'rubygems'
  22. require 'xmpp4r-simple'
  23. require 'session'
  24.  
  25. puts "Connecting"
  26. if messenger = Jabber::Simple.new(BOT_LOGIN, BOT_PASSWORD)
  27. puts "Connected"
  28. else
  29. puts "Ooops - Can't connect"
  30. end
  31.  
  32. @sh = nil
  33.  
  34. while true
  35. messenger.received_messages do |msg|
  36. puts "Received #{msg.body} from #{msg.from}"
  37. if msg && msg.from.to_s.include?(CLIENT_LOGIN)
  38. if msg.body == CLIENT_PASSPHRASE
  39. if @sh == nil
  40. @sh = Session::new
  41. message = "Now logged in!"
  42. else
  43. @sh.close && @sh = nil
  44. message = "Logged out..."
  45. end
  46. messenger.deliver(msg.from, message)
  47. else
  48. if @sh
  49. stdout, stderr = @sh.execute(msg.body) if msg.body
  50. messenger.deliver(msg.from, "\n" + stdout.chomp) unless stdout.empty?
  51. messenger.deliver(msg.from, "\n" + stderr.chomp) unless stderr.empty?
  52. messenger.deliver(msg.from, @sh.execute('pwd')[0].chomp + "$>")
  53. else
  54. messenger.deliver(msg.from, `fortune`)
  55. end
  56. end
  57. end
  58. end
  59. sleep 1
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement