Skip to content

Instantly share code, notes, and snippets.

@envyen
Forked from pcreux/Jabber-SH
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save envyen/0b490435efad1fa0c2a7 to your computer and use it in GitHub Desktop.

Select an option

Save envyen/0b490435efad1fa0c2a7 to your computer and use it in GitHub Desktop.

Revisions

  1. @pcreux pcreux revised this gist Dec 17, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Jabber-SH
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    # Jabber-SH — SH console via XMPP/Jabber (GTalk)
    #
    # Jabber-SH allows to you to administrate a remote computer via a command line
    # Jabber-SH allows you to administrate a remote computer via a command line
    # through a Jabber client. It’s like SSH via GoogleTalk! :)
    # This is just a hack but it might be usefull sometime to run basic commands
    # on a machine that is not accessible via ssh.
  2. @pcreux pcreux created this gist Dec 17, 2009.
    60 changes: 60 additions & 0 deletions Jabber-SH
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    #!/usr/bin/env ruby

    # Jabber-SH — SH console via XMPP/Jabber (GTalk)
    #
    # Jabber-SH allows to you to administrate a remote computer via a command line
    # through a Jabber client. It’s like SSH via GoogleTalk! :)
    # This is just a hack but it might be usefull sometime to run basic commands
    # on a machine that is not accessible via ssh.
    #
    # Philippe Creux. pcreux/AT/gmail/DOT/com

    # Jabber-SH connects to Jabber using the BOT_LOGIN and BOT_PASSWORD details.
    BOT_LOGIN = "[email protected]"
    BOT_PASSWORD = "A_JABBER_SH_PASSWORD"

    # Jabber-SH answers some random epigram via 'fortune' to any message sent to him.
    # The user CLIENT_LOGIN logs into the console by sending the CLIENT_PASSPHRASE.
    CLIENT_LOGIN = "[email protected]"
    CLIENT_PASSPHRASE = "A_PASSPHRASE_TO_LOGIN"

    require 'rubygems'
    require 'xmpp4r-simple'
    require 'session'

    puts "Connecting"
    if messenger = Jabber::Simple.new(BOT_LOGIN, BOT_PASSWORD)
    puts "Connected"
    else
    puts "Ooops - Can't connect"
    end

    @sh = nil

    while true
    messenger.received_messages do |msg|
    puts "Received #{msg.body} from #{msg.from}"
    if msg && msg.from.to_s.include?(CLIENT_LOGIN)
    if msg.body == CLIENT_PASSPHRASE
    if @sh == nil
    @sh = Session::new
    message = "Now logged in!"
    else
    @sh.close && @sh = nil
    message = "Logged out..."
    end
    messenger.deliver(msg.from, message)
    else
    if @sh
    stdout, stderr = @sh.execute(msg.body) if msg.body
    messenger.deliver(msg.from, "\n" + stdout.chomp) unless stdout.empty?
    messenger.deliver(msg.from, "\n" + stderr.chomp) unless stderr.empty?
    messenger.deliver(msg.from, @sh.execute('pwd')[0].chomp + "$>")
    else
    messenger.deliver(msg.from, `fortune`)
    end
    end
    end
    end
    sleep 1
    end