📜 ⬆️ ⬇️

Running Converse.js in conjunction with Bosh punjab on Apache 2.4 and a remote Openfire server or how to tie it to the jabber page from the box

I decided to write this article, because I did not find on the Russian-language Internet a description of the solution to the problems encountered during the installation and configuration of everything described in the title. Formally speaking, there is an article about punjab on Habré, but, to my regret, it didn’t help me much. The article is intended for a person who is not well versed in the tricks of administration, Pyton, etc. etc.

So, let's begin. My system is a server on Ubuntu 14.04 running Apache 2.4. He hosts the page to which there was a desire to fasten the Jabber-client. The choice of the client fell on Converse.js , since it requires a minimum number of settings and works out of the box. Jabber server - Openfire. It is located on a remote machine on the network, access to which I have only as an ordinary user. I only knew about it the IP address and port.

Any JS - Jabber (self-signed, Strophe, converse) will require you to have a BOSH server. Roughly speaking, this is an echo server that forwards messages from JS-Jabbera to the jabber server and back. Punjab was taken as BOSH.
')
With the intro part finished - let's go set.

Punjab


To work, it requires: Python 2.6> =, Twisted 11.1> = . Ubuntu has a python-twisted package in the repository. If you want to use TLS, you will need the pyopenssl package.
Our server works without encryption, because I did not install this package.
Next, either we are getting at GitHub, or downloading the archive and unzipping Punjab. We put it where we like, for example / usr / share / punjab. From this folder in the console we execute:

python setup.py install 

Further, according to the description of the authors are invited to immediately start the server. I recommend to pay your attention to the punjab.tac file.
It has this line:

  internet.TCPServer(5280, site).setServiceParent(application) 

I did not find any other settings for the port of the remote server, and since our server is running on port 5222, this one I replaced 5280 with 5222:

 internet.TCPServer(5222, site).setServiceParent(application) 

You may have the question: "Where to write the address of the jabber-server?". In the configuration of nowhere. The server address is already indicated in the client as an entry: vasyliy_pupkin@192.168.1.18, where 192.168.1.18 is the jabber server address.

Run Punjab through the console:

 twistd -y punjab.tac 

If everything went well, the console will swallow this line, and a twistd.log file will appear in the punjab folder, where you can see how our BOSH server is.

Thin point: if DNS records appear in the log, you need to add to punjab.tac immediately after the line:

 bosh = HttpbService(1) 
The following code:
 bosh.connect_srv = False 

We check the work:

.http: // server_address: port_punjab / will display a message of the form: A XEP-0124 - BOSH - component manager.
.http: // server_address: port_punjab / http-bind message of the form: XEP-0124 - BOSH

Apache 2.4


I assume that Apache is worth it. We need to enable the proxy, proxy_http modules. Enabled by simple a2enmod proxy proxy_http command.

Go to apache2.conf and append it there:

  <IfModule proxy_module> ProxyRequests Off ProxyPass /http-bind http://localhost:5222/http-bind ProxyPassReverse /http-bind http://localhost:5222/http-bind </IfModule> 

Let me remind you that I have port 5222.
Why it is needed. The browser can not send a packet to the port, only to the address. Because we replace the port address.

Converse.js


Put the files from the archive converse in the folder of the Apache website, open the index.html for editing. At the very end of the file we find the fragment of the JS-code:

  converse.initialize({ bosh_service_url: 'https://conversejs.org/http-bind/', // Please use this connection manager only for testing purposes i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported keepalive: true, message_carbons: true, play_sounds: true, roster_groups: true, show_controlbox_by_default: true, xhr_user_search: false }); 

In this code, specify the desired bosh_service_url and locales as desired.

Save, open the demo page in the browser. We indicate our credentials on it in the login form in the form: “Jabber_Id @ jabber_server” and password.

If everything went smoothly, you will see your contact list.

Source: https://habr.com/ru/post/249731/


All Articles