分享

Sam Ruby: Personal Jabber Server

 ShangShujie 2011-01-18
Personal Jabber Server

2007年8月8日 12:09:26


 
 

The following started out as an exploration of erlang, but the side trip has proven interesting enough to merit its own entry.  Accordingly, here are notes regarding the installation of a personal (or “workgroup”, if you prefer) Jabber server on a home LAN.  Beware, specific user and host names are filled in, as well as a dummy password; adjust as required.

To start:

sudo apt-get install ejabberd
sudo chown rubys:rubys .erlang.cookie


The first command installs the server.  The second command is quite optional, but may be helpful later if you experiment with erlang.  The plus side of installing this way is that the installation is standard and will be kept up to date with the distribution.  The downside is that the initial install wizard that comes with ejabberd isn’t run, so three small configuration steps are required.

First, sudo vi /etc/ejabberd/ejabberd.cfg.

Now uncomment out one of the administrators, and set it to your preferred user id:

%{acl, admin, {user, "aleksey"}}.
{acl, admin, {user, "rubys"}}.


Next, the default setup will insert what this machine knows itself by into the configuration, but what you actually want is what other machines on this LAN know this machine as, so make the following change:

{hosts, ["localhost"]}.
{hosts, ["rubix"]}.


Now, write and exit that configuration file, restart the server, and add your user:

sudo /etc/init.d/ejabberd restart
sudo ejabberdctl register rubys rubix password


You can now perform administration functions from any machine on your LAN thus:

http://rubix:5280/admin/
user: rubys@rubix
password: password


Configuring GAIM/Pidgin

Adding the account couldn’t be easier.  Accounts, Add/Edit, Add:


Protocol:    Jabber

Screen name:    rubys

Server:    rubix

Resource:    Laptop

Password:    password


At this point, you can receive messages or add buddies.

Command line client

sendxmpp is a command line client (written in Perl).  Install it, and configure your default user, server, and password information:

apt-get install sendxmpp
vi ~/.sendxmpprc
rubys@rubix password
:x
chmod 0600 .sendxmpprc


You can now send messages to yourself via:

echo -n hi | sendxmpp -r echocmd rubys@rubix


Ruby library

While Jabber (the protocol) allows Jabber IDs to be used by multiple resources (/Laptop and /echocmd are examples above), I couldn’t get this to work with the “simple” Ruby and Python libraries.  No problem: since this is your server, creating new IDs are a piece of cake:

sudo ejabberdctl register george rubix password


Note: the first time you receive a message from any new Jabber ID, you will need to confirm it in your GAIM window.

Now install xmpp4r-simple:

sudo apt-get install libxmpp4r-ruby1.8 libopenssl-ruby
sudo gem install xmpp4r-simple


You can now send yourself a message from irb:

require 'rubygems'
require 'xmpp4r-simple'
jabber = Jabber::Simple.new('george@rubix','password')
jabber.deliver('rubys@rubix','hello world')
jabber.disconnect


Note: if this is a program, a sleep 1 before the disconnect is handy, otherwise the message may be lost.

Python client

Install python-xmpp:

sudo apt-get install python-xmpp python-dns


Here’s it in action:

import xmpp
jid=xmpp.protocol.JID('george@rubix')
cl=xmpp.Client(jid.getDomain(),debug=[])
cl.connect()
cl.auth(jid.getNode(),'password')
cl.send(xmpp.protocol.Message('rubys@rubix','hi there'))
cl.disconnect()


Uses

At the moment, I’m primarily using this for “best effort delivery” of notification of events for various background processes I have running.  If I’m not online, ejabberd will apparently queue up the messages.  Being able to send these messages from the command line, Python, or Ruby makes integration easy.  Of course, there are plenty of other libraries spanning most of the popular languages.  And anything available to these languages, are accessible via ssh or CGI or any other means you may have set up to tunnel into your LAN from the outside.

For example, Planet Intertwingly reflects my predilection for Atom 1.0 feeds.  At first, I periodically spot checked feeds.  Then I produced a template which produces a report every time the page is generated.  Now I’ve completely automated the check so that I’m notified if any of the feeds is ever replaced by a feed of another flavor by the following small script:

require 'rexml/document'
require 'rubygems'
require 'xmpp4r-simple'

VALIDATE = '/home/rubys/public_html/planet/validate.html'

jabber = nil

doc = REXML::Document.new(open(VALIDATE))
REXML::XPath.match(doc,'//tr[td[3] != "atom10"]').each do |tr|
  jabber = Jabber::Simple.new('planet@rubix','password') unless jabber
  message = "#{tr.elements['td[3]'].text}: #{tr.elements['td[2]/a'].text}"
  jabber.deliver 'rubys@rubix', message
end

sleep 2; jabber.disconnect if jabber


Another use that I haven’t explored yet: jabber-bots.













2007年8月8日



Sam Ruby: Personal Jabber Server


[link]...

Excerpt from del.icio.us/tag/ruby
 at
12:45:15







Personal Jabber Server with Erlang


[link] [more]...

Excerpt from reddit.com: programming - newest submissions
 at
15:46:31






Minor typo: s/Java IDs/Jabber IDs/

Good to see you using xmpp and especially ejabberd!

Posted by Stelios Sfakianakis at
17:10:45







Links for 2007-08-07 [del.icio.us]


SproutCore Because every language (even JavaScript) needs an MVC framework. Cerny.js - Introduction There might be some good ideas here. Mostly, it smells of bloat. Functional JavaScript at Oliver Steele Yet another JavaScript library that provides...

Excerpt from Crisis Averted!
 at
17:45:14






    Minor typo: s/Java IDs/Jabber IDs/


Fixed.  Thanks!

Posted by Sam Ruby at
20:32:57







Sam Ruby: Personal Jabber Server


[link]...

Excerpt from del.icio.us/tag/erlang
 at
23:45:13
2007年8月9日


apt-get install sendxmpprc -> apt-get install sendxmpp

Posted by pterk at
1:21:28






    apt-get install sendxmpprc -> apt-get install sendxmpp


Fixed.  Thanks!

Posted by Sam Ruby at
1:41:36






I have my “personal jabber server” too, using ejabberd. I use it only to run ICQ (pyicq-t), MSN (pymsn-t) and IRC (irc.py, heavily patched) transports. It is only available when my laptop is running and has ipv6 at marlow.memojo.com.

It is a bit tricky, as it can reach IPv4 through NAT, but it is only reachable using IPv6.

As client I use gajim (www.gajim.org) since I got a patch to use different languages in different chat windows in, something that I tried unsuccessfully for years with gaim/pidgin. I have contributed some patches, including polishing the xhtml-im and a ReStructured text xhtml-im generator. :)

Should we call running our own “personal” servers (Nokia’s Apache+mod_python, ejabberd in laptops) PC^2.0? As in PeerComputing2PeerComputing :-P

Posted by Santiago Gala at
2:07:28






I’ve been running my own Jabber server for the same reason you give for quite a while now but it really came in handy when the jabber.org server started having uptime issues, I was able to still receive IM’s because now the endpoint is under my control.

Posted by Mike Taylor at
2:12:39






This whole idea of using Jabber for near-realtime event notification has got my brain churning.  I just may have to get ejabberd up and running on my own server.  Did you happen to see any comparisons of ejabberd with djabberd?

Posted by Scott Johnson at
2:29:35






Is it possible with sendxmpp or xmpp4r-simple (and cron) to receive notifications of process events as soon as they happen ?

Posted by kael at
9:50:19






    Is it possible with sendxmpp or xmpp4r-simple (and cron) to receive notifications of process events as soon as they happen ?


It is possible with sendxmpp or xmpp4r-simple (and cron) to send notifications of process events as soon as they happen.  The code above that calls jabber.deliver is an example.

It is possible to receive such notifications with any client that supports Jabber.  I use GAIM.

Posted by Sam Ruby at
10:31:05






    Did you happen to see any comparisons of ejabberd with djabberd?


Nope.  Got any?

Posted by Sam Ruby at
12:40:26
2007年8月10日


    It is possible with sendxmpp or xmpp4r-simple (and cron) to send notifications of process events as soon as they happen.  The code above that calls jabber.deliver is an example.


Thanks for the explanation. Actually, I was thinking that process events would be sent only when cron was running.

BTW, when using sendxmpp, have you thought to replying to the JID ? I, for one, would like to manage my shell directly through Jabber with a kind of SSH-over-XMPP transport/component.

Posted by kael at
3:28:33






ejabberd vs. djabberd...

(I’ve not really used ejabberd in anger, so this is only a surface comparison)

ejabberd is written in Erlang. djabberd is written in Perl.

ejabberd is designed (by virtue of being written in Erlang) to scale out into a big cluster. djabberd currently has no cluster support.

ejabberd is an XMPP(-IM) server. djabberd is an XMPP server framework, though it happens to come bundled with enough add-ons to make a useful XMPP(-IM) server. (I use djabberd for my own personal Jabber server using only core components.)

djabberd is designed to run in a single thread, using non-blocking I/O for a minimal memory footprint. I couldn’t tell you what ejabberd’s comparable design goals are.

ejabberd is stable, well-tested and widely-used. djabberd is currently used on relatively few servers, has relatively little documentation, and a few XMPP-related bugs are still being found occasionally.

Posted by Martin Atkins at
15:35:45






    djabberd currently has no cluster support.


But it should be mentioned that Djabberd runs LJ’s Jabber server with plenty of users, and so far I haven’t noticed any downtime. It may not be written in Erlang, but its scalability story is clearly adequate.

Posted by Aristotle Pagaltzis at
16:54:18
2007年8月11日



Web 3.0


Sam Ruby, who is playing around with ejabberd and XHTML-IM, makes an astute observation: I do believe that Jabber will be a key part of Web 3.0. Whether the recipient will ultimately be a PC or a mobile device is yet to be seen. Ah yes, we’ve...

Excerpt from one small voice
 at
18:42:21
2007年8月16日


I’m using a local Jabber server for exactly the same reasons. Because I got into this before I started tinkering with Erlang, I’m using OpenFire. You might want to take a look at that actually, since you don’t need the scalability of Erlang for a ‘personal server’, but it has a lot more features, e.g. built in gateways to other networks, e.g. AIM/MSN. This means you can ditch your multi-protocol clients and go pure Jabber, which opens up a lot of possibilities for rolling your own client or incorporating it into something else.

Posted by Ciaran at
0:18:02






    I’m using OpenFire. You might want to take a look at that


$ apt-cache search openfire | wc -l
0


Nope.  I’ll stick with ejabberd for the moment.  I rather like having a subscription service for security patches.

Posted by Sam Ruby at
0:44:44
2007年8月18日



Links - 08.17.2007


A Comment on Static Typing Looking at all the problems caused by an even minor issue like SQL Injection it’s pretty difficult to believe that less typing will lead to more robust code. Personal Jabber Server Because everybody ends up managing their...

Excerpt from discipline and punish
 at
0:15:28
2008年1月19日


It isn’t clear to me: Is the .erlang.cookie you’re chowning in the first step the one in /var/lib/ejabberd?

Posted by Mark A. Hershberger at
0:29:26






Mark: I’m pretty sure that I was referring to $HOME.  And after installing {ejabberd on a fresh machine today, I see that the problem that I had at the time no longer exists, at least on Ubuntu Gutsy (i.e., installing ejabberd does not create a cookie that will cause you problems down the road).

Posted by Sam Ruby at
0:57:11
2008年6月15日


The following started out as an exploration of erlang, but the side trip has proven interesting enough to merit its own entry. Accordingly, here are notes regarding the installation of a personal (or “workgroup”, if you prefer) Jabber server on a...

Excerpt from Splithorizon's Blog blogs
 at
4:15:49
2008年6月24日



Personal Jabber Server with Erlang


[link] [comments]...

Excerpt from reddit.com: what's new online
 at
5:48:34
2008年11月19日



IM over a LAN


There are plenty of IM networks available but most must connect to a remote server, something which is unnecessary for a business, school or home network and lowers the network’s performance. It also makes IM impractical on networks not...

Excerpt from gHacks technology news
 at
6:42:25
2008年12月25日



Sam Ruby: Personal Jabber Server


Sam Ruby: Personal Jabber Server...

Excerpt from Andre Lewis
 at
15:45:27
2009年1月7日



links for 2009-01-06


Building a Remote Message Monitor for the iPhone (tags: ruby programming sinatra web2.0 iphone) Time Machine and netatalk (tags: linux mac backup sysadmin) Sam Ruby: Personal Jabber Server (tags: jabber sysadmin) Веб-сервисы и Ruby (tags: ruby web...

Excerpt from Bloggitation
 at
16:16:39
2009年1月8日



Sam Ruby: Personal Jabber Server


[link]...

Excerpt from zh's soup
 at
2:45:32

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多