CurtRod / SimpleEVSE-WiFi

Brings EVSE WB/DIN into your WiFi
https://www.evse-wifi.de
78 stars 33 forks source link

Port forwarding problems? #34

Open Macrisu opened 5 years ago

Macrisu commented 5 years ago

I try to access my EVSE from the internet. I've forwarded the external port 1234 to port 80 of my EVSE. I can access the login page, but nothing is happening when I press the login button.

Do I need to do something else? To forward another port?

Macrisu commented 5 years ago

I've forwarded only the TCP port. Do I need to forward the UDP port, also?

In the console I get:

WebSocket connection to xxxx has failed. Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

hgmendes commented 4 years ago

Hi Macrisu,

Forwarding TCP 80 and UDP 80 port i can access from outside...

However would be interesting that we could define in which port SimpleEVSE Wifi is listening for that we can use a different port rather than 80 since this port could be in use for other appliances also or even for the router, and some routers couldn't be configured with other port rather than 80.

rtfmjoey commented 4 years ago

I'm using a reverse proxy and in addition to standard http protocol it's also needed to proxy the websockets protocol. The UDP protocol isn't needed and the password is not sent unencrypted over the net.

Example:

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ProxyRequests Off
        ProxyPreserveHost On
        ProxyVia On

        ProxyPass /ws ws://192.168.40.31/ws
        ProxyPassReverse /ws ws://192.168.40.31/ws

        ProxyPass / http://192.168.40.31/
        ProxyPassReverse / http://192.168.40.31/

        ServerName evse.domain.example
        ServerAdmin webmaster@domain.example

        ErrorLog "/var/log/apache2/evse.domain.example-error_log"
        CustomLog "/var/log/apache2/evse.domain.example-access_log" common

        SSLCertificateFile /etc/letsencrypt/live/evse.domain.example/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/evse.domain.example/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>
</IfModule>

Using a Let's Encrypt SSL certificate the EVSE is now accessible via https from the outside world. Just forward port 443 to the reverse proxy and you're good to go.

mkrasselt1 commented 4 years ago

Its not the port thats causing the problems, press F12 in your browser and check the console for warnings and errors. The should be some "insecure websocket not allowed outside personal networks" of some sort which is caused by the browser rejecting the (because the lack of power in the esp8266) insecure websocket connection over the internet. Of course you can disable the feature but @rtmfjoey 's solution is way better

Macrisu commented 2 years ago

I'm using a reverse proxy and in addition to standard http protocol it's also needed to proxy the websockets protocol. The UDP protocol isn't needed and the password is not sent unencrypted over the net.

I've done this and I can access the EVSE via HTTPS The problem is now, that I can not log in! After entering the password, the WIFI connection is lost for some reasons ;(

error1

No such problem via LAN

https://imgur.com/a/rmqAGhg

How do "proxy the websockets protocol" ?

I allready did this: Screenshot 2022-03-27 at 09 33 03

schenlap commented 2 years ago

I discovered a problem regarding port forwarding. The evse website always connects to websocket port 80/ 443, regardless of website port (may be different for forwarding).

function wsConnect() {
  var protocol = "ws://";
  if (window.location.protocol === "https:") {
    protocol = "wss://";
  }

  wsUri = protocol + window.location.hostname + "/ws";
  websock = new WebSocket(wsUri);

Maybe https://www.w3schools.com/jsref/prop_loc_port.asp could help to get port of current url and use this for websocket connection (to also use the forwarding).

mkrasselt1 commented 2 years ago

i think this is because insecure websocket is not allowed on https websites - do you use reverse proxy for adding https ?

Macrisu commented 2 years ago

I tried with reverse proxy https and without reverse proxy, simple port fwd.

Same problem.

I cannot use 80 and 443 ports, as there are used.

mkrasselt1 commented 2 years ago

could you use a vpn? As i wont be that confidend to expose this web-api to the public