31

An XMPP/Jabber echo bot written in sed

 5 years ago
source link: https://www.tuicool.com/articles/hit/Yfq6736
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

XMPP Echo Bot

Do you know that situation, you really really need an XMPP echo bot, but you don’t have access to high-level tools like Python to write one? All you have is openssl, bash, dig, stdbuf and sed? Then this tool is for you.

This is an XMPP echo bot written in (mostly) sed. Bash is used to do the pre-authentication setup (look up DNS records, establish TLS via openssl s_client ). sed processes the XML stream and handles all interaction with the server on the XMPP level. Yes, this kinda parses XML in sed.

Tested to work against Prosody 0.9.

Usage

./echoz.sh user@domain password

Supported Features

Testimonials

  • This is crazy, I haven't crashed it yet!Matthew Wild
  • I'm frightened. It's only two steps away from gaining consciousness.Georg Lukas
  • I am simultaneously appalled and in awe. wowLance
  • With Echoz.sed, we were able to reduce our XMPP Echo server costs by 90% compared to our previous TeX-based solution. — Leon
  • While simple and limited, sed is sufficiently powerful for a large number of purposes.Wikipedia
  • oh my god this actually works — Test

Implementation Details

  • We use tr to convert > to \n -- since sed is line (or NUL) based, there’s not really another way to parse XMPP XML (which generally never contains newlines) with sed.
  • TLS is handled outside of sed for similar reasons. And to keep my sanity (some people might question whether I still have any bit of sanity left).
  • Likewise, SRV lookup and composition of the authentication data is entirely handled in bash. This also means that only PLAIN SASL authentication is supported -- SCRAM requires a level of interactivity which would be extremely hard to achieve in sed (not impossible though; we would "just" have to implement base64 and sha1-hmac in sed).
  • Since XMPP is a protocol where the client speaks first, we need to hand sed some initial input to allow it to generate a "line" of output (the stream header). We do that with bash, and use that opportunity to pass some configuration to the sed program (namely JID and authentication string).

Design Considerations

  • We considered using xml2 to convert the XML stream into events; however, it turns out that 2xm[ doesn’t like stream resets. Also, using the tr approach also allows us to detect the end of elements, which is useful for various purposes.

Recommend

  • 44

    README This is jabber.el 0.8.92, an XMPP client for Emacs. XMPP (also known as 'Jabber') is an instant messaging system; see h...

  • 8
    • Github github.com 3 years ago
    • Cache

    Sed to C translator written in sed

    sed-bin: Compile a sed script This project allows to translate sed to C to be able to compile the result and generate a binary that will have the exact same behavior as the or...

  • 7

    PATCH REDO — Wormable code-execution flaw in Cisco Jabber has a severity rating of 9.9 out of 10 The company failed to adequately fix the vulnerability before, so it’s trying again....

  • 4
    • www.devdungeon.com 3 years ago
    • Cache

    How to Use XMPP/Jabber with PHP

    XMPP/Jabber is a communication protocol typically used for chat servers. Nathan Fritz wrote a PHP library for XMPP called XMPPHP. These examples demonstrate how to use the library in PHP....

  • 3

    Using AppleScript to connect to a Jabber Chat Room with Adium Monday, August 18, 2008 I have been having a lot of fun hanging out in the

  • 6
    • www.mikechambers.com 3 years ago
    • Cache

    Community test XMPP / Jabber room

    Community test XMPP / Jabber room Monday, August 18, 2008 I have set up a permanent test group chat room on the Fla...

  • 6

    Flash Platform Community Chat XMPP / Jabber Server Thursday, August 14, 2008 If you have been in the Flash community for a while, then you may remember a chat app that I worked on for Macromedia Central, named “Central Dev C...

  • 5

    Connecting to an XMPP / Jabber Server with the XIFF AS3 Library Thursday, August 14, 2008 As I mentioned earlier, I am starting to build an XMPP chat client for the

  • 4
    • arrfab.net 2 years ago
    • Cache

    a Jabber daemon on CentOS 4.x

    a Jabber daemon on CentOS 4.x I received a request from family members to be able to use Instant Messaging on a private server. I never installed a jabber daemon and if you have a look on http://www.j...

  • 0
    • www.jabber.org 1 year ago
    • Cache

    jabber.org

    Service Notices To learn about major updates related to the jabber.org IM service, please follow us on Twitter...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK