homedash / kankun-json

A CGI script that provides a simple web interface and RESTful JSON API for the Kankun Small K wifi switch.
http://homedash.org
MIT License
34 stars 25 forks source link

Feature/extaccess #11

Open femanzo opened 8 years ago

femanzo commented 8 years ago

I made these changes for remote access. The script works both locally and remote, of course some port forwarding settings must be made on the router. Most internet providers in my country block port 80, so I put in switches.json.exemple how they can be changed. The script automatically detects if the IP is local or remote and calls the correct urls for each action. Documentation should also be updated if you consider to include the feature.

3v1n0 commented 8 years ago

Works well, thanks.

stokito commented 3 years ago

The PR may be spitted into two parts:

Basically I don't think that it worth to use private or public IP depending on the user browser address:

  1. I may have a switch1 at home with private IP but another switch2 is external and added via public IP. But if my dashboard is on my private network so when I opened it from my browser then I simply can't turn the external switch2
  2. If my router has a public IP then it's not a big deal to call a switch via routers port. This is not a huge load. But there may be problems if internet is down and the myswitch.dyndns.org domain is not resolved. To avoid this we may add an instruction to map the myswitch.dyndns.org to router's 192.168.1.1 so even if internet is down the route is accessible. But TBH I think that users simply must have two separate dashboards: one with local IPs and another for external access (and secured by Basic Auth)

I created #19 which allows to connect to switch via hostname and port but doesn't have the logic to redirect to private IP if dashboard's hostname is also hosted on the private IP. It may solve some problems but still the solution here with attempt to directly connect via private IP is make sense. When my PR will be merged then we can simplify the PR to one commit with a new ext field.