facebook chat using strophe, punjab - javascript

using the answer of my previous question and another post I tried to implement facebook-chat from a browser. Here is what I did:
on an ubuntu virtual machine, I have python 2.6.5, python-twisted-conch 1:10.0.0-2, python-twisted-names 10.0.0-1, python-twisted-web 10.0.0-1 and python-twisted-words 10.0.0-2 already installed. I did not install jabberd2 server, I assumed facebook server is the Jabber/XMPP server in my case. Also I did not install pyopenssl.
downloaded and untared punjab from here
run it using the following command
user#ubunto: sudo twistd punjab
sometimes it tells that the process is already running under PID xxx but most times the reply was
Removing stale pidfile /home/user/twistd.pid
Does this mean that punjab is running?
In the punjab.tac file, according to this post I change the root.putChild line to
root.putChild('bosh', b)
On the other hand, I have an apache server running on the host computer (windows xp) to host my webpage that uses Strophe. In the apache config file httpd.conf, I proxy the BOSH requests to punjab at port 5280 using:
<IfModule proxy_http_module>
ProxyRequests Off
ProxyPass /bosh http://ubunto_ipAddress:5280/bosh
ProxyPassReverse /bosh http://ubunto_ipAddress:5280/bosh
</IfModule>
Note that the host and the virtual machine are bridged, so both get their IP address from the router and each one can ping the other. I also didn't install a jabber/xmpp server, or
For testing, I use the basic example of strophe as my webpage basic.html and basic.js with JID: FB_username#chat.facebook.com & password: FB_password.
I get the following:
Strophe is connecting.
SENT: <body rid='1709425072' xmlns='http://jabber.org/protocol/httpbind' to='chat.facebook.com' xml:lang='en' wait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>
Strophe is disconnecting.
Is there anything wrong or missing? Please help since I am not finding real documentation other than some posts concerning this issue. Thanks
Sabah

I'm not certain this is what you're trying to do, but if you're trying to have a webpage independently connect to Facebook Chat via JS, it's not going to work due to Cross Site Scripting protections. You can only use Strophe to connect to the same server that issued the webpage Strophe is working on. You'll have to connect back to your server first and use that as an inbetween; or use iframes to embed facebook chat in your webpage.
(For the record, I know nothing about Python, but it looks like your problem is with the JS :) )

Related

WebSocket connection timed out in EC2 website

I have a problem that seems to me to be impossible to solve, well, I have a website on EC2, I bought my own domain, I added HTTPS using Let's encrypt, and on this website there is a chat, and I am using the PHP Ratchet library to create a connection with websockets, and the problem is that my server doesn't start in the browser, well, I've tried to make my server start with several ports, 3000, 8080, 8181, 8443, 4433, and none of these work, at least when I use the command php chat-server.php to start the PHP server, I don't get any errors, it works, however, when entering the browser, it doesn't display a message in the PHP script console saying that there is a new connection, and the browser console ( chrome) reports a timed out error, that is, it looks like you are not connecting to the server, I really don't know what to do anymore, I don't know if this is because of the HTTPS I'm using, I don't know if should I edit something in the apache configuration, I need the someone help me, please
In fact, I already edited the security group in EC2, I already enabled these ports that I said I tried to use, I restarted the Apache server too and I still get the same error
PHP CODE - chat-server.php :
<?php
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Local\Socket\Chat;
require dirname(__DIR__) . '/vendor/autoload.php';
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Chat()
)
),
4433
);
$server->run();
JS CODE:
var conn = new WebSocket("wss://example.net:4433/chat.php");
ERROR:
failed: Error in connection establishment:
net::ERR_CONNECTION_TIMED_OU

JS webstomp BAD CONNECT Access refused for user 'guest'

I have problem with connection to RabbitMQ server (version: 3.8.2, erlang version: 22.2.8) by JS (on browser) webstomp. I'm using stomp.js.
I'm using example from here: https://github.com/rabbitmq/rabbitmq-web-stomp-examples/blob/master/priv/echo.html
I've done everything like is described here: https://www.rabbitmq.com/web-stomp.html
I've set permissions to my user using this: sudo rabbitmqctl set_permissions -p / user ".*" ".*" ".*"
I've set tags to my user using this: sudo rabbitmqctl set_user_tags user management
I've already checked these solutions:
Failing to connect RabbitMQ through a EasyNetQ, getting access refused for user guest and
RabbitMQ - access to vhost 'XXX' refused for user 'guest',
and others that I found in google.
My configuration for rabbitmq_web_stomp:
{rabbitmq_web_stomp,
[
{tcp_config, [{port, 15674}
]
},
{use_http_auth, true},
{ssl_config, [{port, 15673},
{backlog, 1024},
{cacertfile,"path/to/cert"},
{certfile,"path/to/cert"},
{keyfile,"path/to/cert"},
{password, "pass"}
]
}
]
},
I always get the same response from server:
Opening Web Socket...
Web Socket Opened...
>>> CONNECT login:user passcode:pass host:/ accept-version:1.1,1.0 heart-beat:10000,10000
<<< ERROR message:Bad CONNECT content-type:text/plain version:1.0,1.1,1.2 content-length:32 Access refused for user 'guest'
Whoops! Lost connection to ws://ip.addres/ws
I have access (for this user) to the server by .NET Core client in C# and by Management Plugin
Thanks for help!
I found the solution.
I don't exactly sure why it works but it was enough to remove the {use_http_auth, true} from configuration. After that there was no problem with connection from JS from browser.

Open sessionURL for Autobahn websocket in browser

I have a Pyramid web application on which I would like to embed an iFrame displaying an instance of ParaViewWeb's visualizer so users can display VTU files remotely.
I have successfully done so while running the application on my own workstation by calling a subprocess from Python that executes ParaViewWeb's Quick Start method and returns the URL to JavaScript for iFrame generation.
http://www.paraview.org/ParaView3/Doc/Nightly/www/js-doc/index.html#!/guide/quick_start
However, in order to accommodate multiple users, ParaViewWeb's documentation indicates that
the server must provide a single entry point to establish a connection, as well as a mechanism to start a new visualization session on demand
for which it suggests using Apache as the front-end application and a python launcher to start the process for each session.
Conveniently, I have a "freshly installed Ubuntu Desktop 14.04 LTS" so I used the following guide to configure both the launcher and Apache:
http://www.paraview.org/ParaView3/Doc/Nightly/www/js-doc/index.html#!/guide/ubuntu_14_04
Ok so I'm pretty sure I am missing something major here, but once the launcher is started with /data/pvw/bin/start.sh... how do I then submit the request with information regarding what app to use (visualizer) and what data directory to load???
Update
I am able to launch a session such that a sessionURL with a unique ID is returned by first running
/data/pvw/bin$ ./start.sh
and then entering the following commands in the python interpreter
>>> import requests
>>> import json
>>> data = {"sessionManagerURL": "http://localhost:8080/paraview", "application": "visualizer"}
>>> data = json.dumps(data)
>>> r = requests.post("http://localhost:8080/paraview",data=data)
>>> r.json()['sessionURL']
u'ws://localhost/proxy?sessionId=e2970d68-42c8-11e5-a755-3c970e8061f9'
So now I have a websocket which should contain an instance of ParaViewWeb that I would like to access from the browser... typing the sessionURL as is into the browser does nothing and replacing 'ws' with 'http' opens a page with the following text:
AutobahnPython 0.6.0
I am not Web server, but a WebSocket endpoint. You can talk to me using the WebSocket protocol.
For more information, please visit my homepage.
I am new to both apache and websockets so I am reading up on the protocol on the homepage, but if someone has a quick answer about how to utilize this websocket to display ParaViewWeb to the user I would be very appreciative!!
Note: Command line argument -dr is unknown so omit it from all of the command line arguments given in the guide's launcher.json
Thanks in advance!

API calls are not working in cordova application

I made an application using apache cordova. my server is written in node.js running locally and port 3005. So I want to make API call from cordova I am using backbone in client side.
I written the following code to make API call
makingAPICallForStatus:function(){
var userSessionModel = Backbone.Model.extend({ //Creaating a model for checking user session status
url:"http://localhost:3005/api/user/status/",
});
var userSessionModelObj=new userSessionModel();
this.makeApiCall(userSessionModelObj,"",'GET',function(model,response,options){console.log(response);});
},
makeApiCall:function(modelObj,dataObject,requestType,successCallback){
modelObj.fetch({data:dataObject,
type:requestType,
success:successCallback,
error:function(){console.log("error")}
});
}
If you observe, I mention URL path is :"http://localhost:3005/api/user/status/". This way it's not working. it's showing This request has no response data available
Now I tried with production domain like
URL path is :"http://xxx.xxxx.com/api/user/status/"
This way it's working fine.
Why localhost was not working, I invoke same url directly in my browser working fine. but it's not working in cordova.
Note : I didn't modify anything in www/config.xml file.
What's the problem how can I fix this.
Thanks.
localhost is an alias of 127.0.0.1 even if you are running on an emulator on the same machine, local host is not real. You have to always make calls to an ipaddress or domain name from a device (even virtual devices). This is because on the device localhost is referring to the device not the machine that it may be running from.

PhoneGap app's XMLHttpRequest POST data lost

I'm porting an ajaxed, mobile-optimized website to PhoneGap, but have been unsuccessful in getting any POST to the server. From what I've read, xhreq POSTS are supposed to be possible in PhoneGap.
The specifics: I'm targeting the Android platform using the latest Cordova 3.3.1-0.1.2, the latest Android SDK, and a Galaxy S3 updated by Verizon to Android 4.3. Connectivity is over wifi to my local server. In every attempt, the POST arrives at the server as a GET, with no post data (verified using tcpdump to inspect packets). The mobile-optimized web site works fine in the browser on the same phone, also over wifi.
I've isolated the fail case by creating a brand new Phonegap project, nothing more than:
$ cordova create Hello
$ cd Hello
$ cordova platform add android
Then in index.js, at the end of the onDeviceReady handler, adding a snippet I first tested in a simple browser page (domain substituted here):
// TEST POST CAPABILITY
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState==4 && (req.status==200 || req.status==0)) {
console.log("POST Response: " + req.responseText);
}
};
var t = new Date().getTime(); // Just to foil any caching
req.open("POST", "http://mydomain.com/services/rpc?t=" + t, true); // async
req.setRequestHeader('Content-type','application/text; charset=utf-8');
var postContent = JSON.stringify({id:t, method:"misc.log", params:[{log:"POST Test"}]});
req.send(postContent);
And then run on the phone with:
$ cordova run android
It fails like the fuller app, arriving at the server as a GET with no post data. I verified a couple of configuration item defaults to make sure they were as required:
In config.xml:
<access origin="*" />
In AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
Any ideas as to what might be going wrong, or other things to look in to?
Thanks.
Your content type should be set to
"application/json".
JSON.stringify() creates JSON content.
Next, can you tell us how your server process is determining the request type. Can you post the relevant code?
I would start by adjusting the content type value. See if that makes a difference.
Hope that helps.
The problem was an ip forwarding one, just not the one I'd originally suspected (forwarding to & from port 80 to my local server on port 8080, which I've used for years as a convenience to allow not having to add :8080 into the browser url all the time).
It was this:
In the MX records for "mydomain.com", I had www.mydomain.com pointing to my server's IP address, but the root mydomain.com (the host address I was using in the url to XMLHttpRequest), redirecting to www.mydomain.com.
This worked in a normal browser session, as if you type in mydomain.com, it just goes to www.mydomain.com, then runs from there - and it would use all relative paths in the xhreq's.
In PhoneGap, however, which requires the full path be specified, the POSTs were not making it through the redirect. It was also causing sluggish image loading behavior and some bizarre communication hangups after many loads - I just hadn't realized the problem had the same root cause (rather I was getting worried about WebView performance).
The great news is that POST is working fine now, and the WebView appears to be plenty speedy for my needs.
To summarize the solution: make sure that the subdomain (or lack thereof) in fully qualified urls passed to XMLHttpRequest (as required in PhoneGap) are mapped to an ip address (A record), and not redirected, in the MX records for your domain.

Categories

Resources