Can I change WebSocket from ws to wss? (000webhost) - php

I had built a website as a dashboard (using 000webhost) to change the data in mySQL database via php which was working fine right now. After that, I have a Unity WebGL build uploaded on itch.io which was working fine as well until it need to get data from the database via php. When I was intended to get the data via accessing php files store in the 000webhost server, I got the following error show up in the web console from the accessing website.
Mixed Content: The page at 'https://.itch.io/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://:54998/'. This request has been blocked; this endpoint must be available over WSS
The link I was using to access the php files was using https instead of http. I am still new to these area, I would like to know can I change the WebSocket endpoint to wss instead of ws? Do I need a paid plan to solve this? I did saw that the Single Hosting plan did offer free SSL certificate. Please help me, I am open for any suggestion/advice, Thank You.

The Websocket Server itself need to setup the SSL Certificate. If it doesnt, you need a reverse proxy like nginx or apache to handle the SSL and forwarding to the unencrypted ws:// websocket.
Anyway, the websocket should run on default port 443/80 as well, since many firewalls are blocking non default ports for security reasons. In this case you will need the reverseproxy if you dont have a dedicated IP for the websocket server.

Use socket.io. Most of the problems are solved and there is no need to do more.
var socket = io.connect('https://www...', {secure: true});

Related

"Connection Refused" via PHP cURL from GoDaddy Hosting to internally hosted Radarr server's API (jQuery works though?!)

I'm at a complete loss as to why this is failing, so get ready for the novel describing exactly what I'm trying to accomplish and what I've tested so far.
Goal:
I'm building a webpage on my GoDaddy hosting account that I want to connect to my locally hosted Radarr server's API via PHP cURL.
I want to use PHP so I can obfuscate the IP, port, and APIKey on the client side. Plus, some of Radarr's API calls I would like to use cannot be run via query string.
Problem:
No matter what I try, I am getting nothing but the following error:
Failed to connect to <MY PUBLIC IP ADDRESS> port <PORT NUMBER>: Connection refused
(And yes, this is the publicly opened port, not the internal port on the server.)
Setup:
I installed Radarr on a FreeNAS (11.3-U5) jail hosted in my home. This is working beautifully.
I setup the FreeNAS jail with a dedicated IP address instead of allowing it to NAT internally, just to make sure it doesn't cause any issues.
I configured port forwarding on my router to allow external traffic into the Radarr server. This is working. Note: Xfinity is my ISP, but I purchased the router separately.
I have a GoDaddy hosting account where I've written a webpage to tie into Radarr's API on my local network. Currently, the webpage is also working beautifully to query data from the API, BUT it's connecting to Radarr via $.getJSON with JavaScript and jQuery.
(Before anyone says it, yes, I know GoDaddy hosting isn't the best option, but it's the one I'm using.)
Testing:
I swear I've tested EVERYTHING and I don't know why this is failing.
This IS working through the JavaScript/jQuery solution, meaning the Radarr server is up and running, the port is properly forwarded through my router, and GoDaddy's hosting isn't blocking the connection.
I CAN access the raw JSON API response in the browser simply by entering the full API URL call.
And while I'd say I am versed in PHP, I'm certainly no expert, so I even tried pulling a generic PHP cURL script from another StackOverflow post, changing the URL to mine, and running that with no luck. Note: The original script DID work to connect to another external API though.
Then I tried Postman, which worked, and I used Postman to create a PHP script, but that script failed.
All of the functional testing done on my local network was done using my publicly facing IP address. However, just to be certain, I also tried reaching the API through the browser off my network, and that worked just fine.
In a desperate attempt, I also reached out to GoDaddy support to see if they had any ideas. They went as far as creating a test PHP cURL script in the same hosting directory and had it simply pull Google's homepage. That worked just fine.
After GoDaddy was unable to help, I setup a free hosting account and free subdomain on AwardSpace, uploaded the script, and that failed too.
In digging into the Connection Refused error, someone suggested just trying to ping the IP through PHP. I attempted this, but it returned 100% packet loss. Also, I logged into my router and watched the incoming connections as I tested. Using the jQuery solution, I saw the incoming connection and it worked great. Using the PHP solution, it didn't register anything inbound.
Lastly, I have confirmed that the publicly opened port on my router is in the list of blocked port by Xfinity. However, since I can access the server externally through the browser and via the jQuery script, that can't be the issue.
There seem to be many, many, many articles online about the general Connection Refused error, but I haven't found a solution to my problem from any of them.
Does anyone have any suggestions?

AWS EC2 server refusing Ionic/Capacitor/Android connections to PHP files

I have recently begun building an Angular Ionic app which connects to PHP scripts on an AWS EC2 server. Everything works fine except for when I try to connect through Android once the app is built on my phone.
The response is a simple 404 response with no additional information. When I look at the log on Android Studio I see the following response:
E/Capacitor: Unable to open asset URL: [api address]
I have reduced both the HttpClient call on the frontend and the php file on the backend to their most simple forms and yet still nothing:
<?php
echo "Hello";
?>
I know that Capacitor was updated to 3 only a couple of months ago and am concerned that it is related to that. I am using PHP 7.
UPDATE
The issue was indeed cleartext but the issue was made more complicated by the fact that HttpClient was not catching the error and so I was simply getting back an unknown failed response.
In order to first see that it was cleartext I first had to change HttpClient for the Native HTTP plugin and check the logs whilst testing on my phone (HTTP will not work through the browser).
Only then did I notice that I hadn't changed the config file correctly.
As long as your PHP web server is not running on the Android device directly trying to connect to localhost / 127.0.0.1 won't work and you need to use another domain / IP your web server is available on and which the Android device can access. You can also check this by simply opening the URL in the browser of the Android device.
If that is not feasible for you you could also use port forwarding via adb to forward a port of your web server to a local port on the Android device.
If you use another domain / IP make sure your web server is not listening to local connections only and is not blocked by a firewall or similar.
Also if you are using an unencrypted connection (i.e. http instead of https) you might need to enable the cleartext config option in you Capacitor config.

HTTP_Request call works in browser, timeout in web app

I have a web application which gets data from itself via a REST API in JSON format. I am in the process of moving this site to a new server on a new host. I have everything moved, same database, same files. The main differences would be that PHP is running as a module on the new server instead of FastCGI and the new host has a client-configurable-firewall.
The web app makes the API call by using Pear's HTTP_Request object (GET method). When I run the web app that makes the call, it spins until it finally returns a "Connection timed out" error.
However, if I echo the URL being used by the call and then hit that directly in my browser it returns all the JSON data instantly.
I am wondering if this could be a firewall issue: port or protocol used by the guts of Pear's HTTP_Request object blocked? (There is currently a firewall policy allowing traffic on port 80 from any IP).
Or a permission issue: PHP running as a module is more sensitive to this.
Any ideas would be greatly appreciated!
As the new server is still only being tested using the IP address, the internal web application was attempting to access itself via an external IP. From the server itself, the external IP is not available. It has to be changed to point to the internal network IP for testing.
Once the domain name is moved this will become a non-issue again.

Restful php client not working on server but works fine in localhost

i need build a restful client on php. i have used pest class which is available on github. my client is working fine on localhost where the web service is hosted on a remote server. but when i uploaded the code to another server it returns timeout. I havent used any extension php (dll files). what can be the issue. please help me. thanx.
How does it execute it's web requests? (Sockets, file_get_contents, curl?) I'd imagine it's an issue of not allowing outbound requests. In that case, contact the server admin and ask them. Try using a demo curl script to see if you can contact google and pull down its index page, that will tell you if you are allowed out bound requests. I had this issue before, where my server was denied outbound requests and just had no results. I would think the server-admin would be able to help here.

PHP Websocket on Webserver

A few days ago I setup this WebSocket server from http://code.google.com/p/phpwebsocket/
It works excellent on my localhost by using Xampp. Then, I uploaded it to my webspace on Strato, but now I am not able to connect to the server.
I changed the the sockets connection to my domain but it didn`t work
Client.html:
var host = "ws://xxxxxxxx.com:12345/Websocket/server.php";
Server.php:
$master = WebSocket("xxxxxx",12345);
I already tried it with different port(80,443,12345,8080,8000....), using the IP address in server.php instead of the domain.
I also used absolute and relative paths in the client.html.
From the projects page http://code.google.com/p/phpwebsocket/ someone suggested to use 0 or 0.0.0.0 in the server.php, but that didn`t work either.
In the client.html it just shows:
WebSocket - status 0
Disconnected - status 3
My guess that the problem is that Strato is blocks me from using WebSockets.
Is it possible to run WebSockets on my webspace?
My bet is that your host is blocking incoming requests to the socket. Your not supposed to run scripts like phpwebsocket within a web service (it is a server itself). This confuses a lot of people since PHP is typically used for scripting webpages, not for coding daemons.
I say this because you mentioned running the script within Xampp, and referred to your hosting service as 'webspace'.
If this is the case you will have to upgrade to a virtual server package so that you can run your own services.
Okay, to bring this to an end.
I found a solution to use my websockets app and I´ve got an explanation why it did not work on my shared hosting solution.
I contacted Strato who told me that they don`t allow Websocket on shared hosting. The only way to get a similiar result would be to use AJAX Long Pooling.
Now I purchased to a Virtual Server and my websocket app works great now.
Thanks for your support.

Categories