Can't connect to XMPP server (openfire) with HTTP binding - xmpp

I'm trying to learn XMPP protocol to make web applications using it.
So, I've installed a XMPP daemon called openfire, I configured it to support HTTP-Bind, I can connect to it using Pidgin and the default XMPP protocol.
The problem is that I can't connect to it using HTTP-Binding. In pidgin I have some options when I'm connecting to specify method whici I want to use to connect to server. If I set it to connect using HTTP-Bind it fails with this message: No session id given.
At the client side, I'd use Strophejs try to make this connection, but it doesn't work too. I have something like this:
var conn = new Strophe.Connection("http://chat.dev/http-bind");
Where http://chat.dev/http-bind is the location to the XMPP daemon. I've been forwarded this location to be set on the properly port in apache virtualhost, so the http://chat.dev/http-bind will point to the same thing as http: / / 127.0.0.1:7070.
conn.connect("test5", "test5", some_callback);
function some_callback(status)
{
if (status == Strophe.Status.CONNECTING) {
console.log('Strophe is connecting.');
} else if (status == Strophe.Status.CONNFAIL) {
console.log('Strophe failed to connect.');
} else if (status == Strophe.Status.DISCONNECTING) {
console.log('Strophe is disconnecting.');
} else if (status == Strophe.Status.DISCONNECTED) {
console.log('Strophe is disconnected.');
} else if (status == Strophe.Status.CONNECTED) {
console.log('Strophe is connected.');
// connection.disconnect();
}
}
This will return: "Strophe is connecting."
Well, I don't know the answer, I've been reading a book about XMPP and Strophe, but this book doesn't cover this aspect and the documentation which I've found also doesn't help me.
Thanks.

Try this-
var conn = new Strophe.Connection("http://chat.dev/http-bind/");
Need to put '/' in the end. Worked for me.

Related

Is it possible to know that the error is CORS in Axios?

Axios gives us the interception ability. I have created a response interceptor to get errors.
This is my code:
const errorInterceptor = error => {
if (error.code === 'ERR_NETWORK') {
throw new Error('Network is not connected')
}
// The rest of the code
}
However, if I get the CORS error, I can't find any information to know that it was a CORS error.
Why do I need this?
I want to provide meaningful messages to my users.
If network is disconnected, I want to show You are not connected to the internet. If it's CORS, I want to show API is not configured properly for CORS, please inform the administrator.
How can I know whether the error is CORS or not?
I have created an interceptor and I have tried to extract data from it.
axios.interceptors.response.use((response) => response, (error) => {
if (typeof error.response === 'undefined') {
alert('A network error occurred. '
+ 'This could be a CORS issue or a dropped internet connection. '
+ 'It is not possible for us to know.')
}
return Promise.reject(error)
})

Flutter Plugin for automatic wifi connection without prompting something from the user

The specific use case is for a wearable application (Wear OS) that I want to automatically connect to a wifi network that is specified in a config file for easy cross-site deployments without even telling that it is being done. I have tried wifi_iot and plugin_wifi_connect with some odd results. Both seemed to connect to the correct ssid, but they gave some sort of weird prompt that said something about connecting to the device and seemed to actually mess up the connection afterward.
wifi_iot implementation:
check for wifi setting
WiFiForIoTPlugin.isEnabled().then((val) {
_isEnabled = val;
});
print('isEnabled: $_isEnabled');
//check if connected to wifi
WiFiForIoTPlugin.isConnected().then((val) {
_isConnected = val;
});
print('isConnected: $_isConnected');
//enable and connect if not
if (!_isEnabled) {
//enable wifi
WiFiForIoTPlugin.setWiFiAPEnabled(true);
WiFiForIoTPlugin.setEnabled(true);
}
if (!_isConnected) {
//connect to wifi
WiFiForIoTPlugin.connect(_ssid,
password: _psk, security: NetworkSecurity.WPA);
}
plugin_wifi_connect implementation:
var _connectedTo = await PluginWifiConnect.ssid;
print("Comparing $_connectedTo to $_ssid"); //#_connectedTo returns <unidentified_ssid>#
if (_connectedTo.toString() != _ssid) { //#this always fails
try {
await PluginWifiConnect.connectToSecureNetwork(_ssid, _psk,
saveNetwork: true);
print("Connected to $_ssid");
} catch (e) {
print("Couldn't connect to $_ssid");
}
} else {
print("Already connected to $_ssid");
}
Does anyone have any experience with this? Possibly that I am not using the correct permissions for this or if I need to make something if this is even possible anymore. There seemed to be some changes for API above 29 that changed certain things about it. The plugin_wifi_connect did not have much documentation and seems like it might be based on an older package that wasn't null safe that was not really up to date with the same documentation.

asp.net core redirect to https

We have a multi-tenant asp.net core 2 application.
We need to redirect to their https the requests to non-secure url. We have to do this by code instead using the web.config or IIS, since some domains have https and some others not. We check which domain needs this redirection by checking in a database based on the host making the request.
Is it possible to do this in a middleware?
Thanks in advance.
I found a way to do what we need and I'd like to share in case someone else has the same problem.
We have solved it with URL Rewrite rules using the Microsoft.AspNetCore.Rewrite library.
In the startup.cs we add the following code
app.UseRewriter(new RewriteOptions().Add(new RedirectToSecureRule()));
Then we add the class RedirectToSecureRule
public class RedirectToSecureRule : IRule
{
public virtual void ApplyRule(RewriteContext context)
{
var currentRequest = context.HttpContext.Request;
if (currentRequest.IsHttps)
{
context.Result = RuleResult.ContinueRules;
return;
}
if (currentRequest.Host.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase))
{
context.Result = RuleResult.ContinueRules;
return;
}
if (context.HttpContext.Items["TenantSsl"] == null || !Convert.ToBoolean(context.HttpContext.Items["TenantSsl"]))
{
context.Result = RuleResult.ContinueRules;
return;
}
var httpsUrl = UriHelper.BuildAbsolute("https", new HostString(currentRequest.Host.Value), currentRequest.PathBase, currentRequest.Path, currentRequest.QueryString);
var response = context.HttpContext.Response;
response.StatusCode = 301;
response.Headers[Microsoft.Net.Http.Headers.HeaderNames.Location] = httpsUrl;
context.Result = RuleResult.EndResponse;
}
}
As you see if the request is already https we don't do anything. The same for localhost, although this condition is not necessary since we can also work with https in localhost.
Then we check if HttpContext.Items["TenantSsl"] is true. This is because our app is a multi-tenant app where we share the codes and the IIS pool but each tenant has its own database.
It could happen that one tenant has a SSL certificate and others not, that's the reason we have to add a field in our tenant's database to check that.
Before this Rule is executed, we execute the tenant selector, where we add to the HttpContext.Items a bool variable indicating is the current tenant has a SSL certificate-
Finally, if the tenant has a SSL certificate and the request is not https, we redirect to the https page.
May thanks to Ray Huang, we based this solution on one of his posts:
https://blog.discountasp.net/3-ways-to-redirect-http-to-https-and-non-www-to-www-in-asp-net-core/

Openfire in-band-registration via Bosh not working with Strophe/Strophe.register.js

I previously asked a similar question about ejabberd, however ejabberd was giving other problems, so I switched to openfire. For the sake of not making the original qestion to cluttered, I decided to create a new question, since this question pertains to openfire and is a different issue than the one I was having with ejabberd.
So, here goes the question:
I have a strophe.js xmpp client, which connects to an openfire 3.10.0 alpha server running on the Amazon cloud. I need 3.10.0 alpha over 3.9.3 because of a bfix which is included in the former, but not the latter.Anyway, since this is a strophe client, I have enabled bosh, and I can see it running at myAWSDNS.com:7070. I am able to connect to the server via my client using this bosh service and existing accounts, and send messages back and forth so it seems to be functioning ok.
I would also like to add in-band registration, for which I use strophe.register.js
This is the code I use for this:
var tempConn = new Strophe.Connection("http//myAWSDNS.com:7070/http-bind/");
tempConn.register.connect("myAWSDNS.com", function (status) {
if (status === Strophe.Status.REGISTER) {
// fill out the fields
connection.register.fields.username = "juliet";
connection.register.fields.password = "R0m30";
// calling submit will continue the registration process
connection.register.submit();
} else if (status === Strophe.Status.REGISTERED) {
console.log("registered!");
// calling login will authenticate the registered JID.
connection.authenticate();
} else if (status === Strophe.Status.CONFLICT) {
console.log("Contact already existed!");
} else if (status === Strophe.Status.NOTACCEPTABLE) {
console.log("Registration form not properly filled out.")
} else if (status === Strophe.Status.REGIFAIL) {
console.log("The Server does not support In-Band Registration")
} else if (status === Strophe.Status.CONNECTED) {
// do something after successful authentication
} else {
// Do other stuff
}
});
This seems to work fine, as it enters the first if-bracket (status === Strophe.Status.REGISTER), and tries to set connection.register.fields.username = "juliet";
However, here, when executing that line, it jumps into strophe.js line 2476:
if (this.connect_callback) {
try {
this.connect_callback(status, condition);
} catch (err) {
Strophe.error("User connection callback caused an " +
"exception: " + err);
}
}
where 2476 is the code in the catch(err) { ...... } bracket.
If I inspect err, this is what I get:
So message: connection is not defined and, obviously, the regstration doesnt work, and I am not sure why. Does anyone have any input on this?
Thanks, and best regards,
Chris
You might not like this answer... The reason for connection == undefined is because you named it tempConn.

Alternatives to NSHost in iPhone app

I'm currently using this code
NSHost *host = [NSHost hostWithAddress:hostname];
if (host == nil) {
host = [NSHost hostWithName:hostname];
if (host == nil) {
[self setMessage:#"Invalid IP address or hostname:"];
return;
}
}
to retrive my IP Address for a networking app I'm working on, however I'm aware that NSHost is a private API that will be rejected. Can anyone help me with working this code to produce the same results without using NSHost? I'm not really sure where to start.
EDIT:
Following suggestions that seem damn near perfect below I've added this code into my app in the place of the code above
Boolean result;
CFHostRef hostRef;
CFArrayRef addresses;
NSString *hostname = #"www.apple.com";
hostRef = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)hostname);
if (hostRef) {
result = CFHostStartInfoResolution(hostRef, kCFHostAddresses, NULL); // pass an error instead of NULL here to find out why it failed
if (result == TRUE) {
addresses = CFHostGetAddressing(hostRef, &result);
}
}
if (result == TRUE) {
NSLog(#"Resolved");
} else {
NSLog(#"Not resolved");
}
I've removed the 4th line (as I have this information from elsewhere already) but I get errors being based around CFHostRef being undeclared. How would I resolve that? It seems to be my only big hurdle, as other errors are only based upon the lack of being able to see hostRef after that.
EDIT: Scratch that I also get kCFHostAddresses undeclared.
You can use CFHost to achieve the same. On the top of the CFHost Reference is a cookbook recipe for making the lookup.
The following code does very, very basic synchronous resolution (as yours above would with NSHost). Note that you don't want to do this since it can render your app unresponsive because it doesn't return until it's resolved or the timeout hits.
Use asynchronous lookup instead (CFHostSetClient and CFHostScheduleWithRunLoop as described in the CFHost documentation above). Also, depending on what you're planning to do, you may want to look into using the reachability APIs. Check out the WWDC sessions on networking available on the iPhone developer website.
Boolean result;
CFHostRef hostRef;
CFArrayRef addresses;
NSString *hostname = #"www.apple.com";
hostRef = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)hostname);
if (hostRef) {
result = CFHostStartInfoResolution(hostRef, kCFHostAddresses, NULL); // pass an error instead of NULL here to find out why it failed
if (result == TRUE) {
addresses = CFHostGetAddressing(hostRef, &result);
}
}
if (result == TRUE) {
NSLog(#"Resolved");
} else {
NSLog(#"Not resolved");
}
// Don't forget to release hostRef when you're done with it
Look at this: http://blog.zachwaugh.com/post/309927273/programmatically-retrieving-ip-address-of-iphone
http://developer.apple.com/iphone/library/qa/qa2009/qa1652.html
Got a great little answer through the Developer Support system, this worked perfectly.