Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Port of Fake Webserver #15

Closed
k1llerk3ks opened this issue Apr 19, 2023 · 6 comments
Closed

Change Port of Fake Webserver #15

k1llerk3ks opened this issue Apr 19, 2023 · 6 comments

Comments

@k1llerk3ks
Copy link

Heyhey, very neat work! Everything works as intended for me. As far as i've understood, you created an extra distinct AP for the camera. I chose to connect it to my main network and block internet access through the router.

Is it possible to use a different port for the webserver? I tried to change the Port in src/v720_http.py (and src/fake_srv.py), but when i run the server with python3 src/a9_naxclow.py -s, i get an open port and a running webserver, but no Found Device.

Thanks for any help!

@vale-max
Copy link

the camera only tries to connect to port 80. If you want to use a different port you can either redirect the connection to the chosen port via TCP rules or run a reverse proxy on port 80 pointing to your desired port, e.g.to use port 9900 set nginx like this:

server {
        listen 80;
        listen [::]:80;

        server_name *.naxclow.com;
        location / {
           proxy_set_header Host $host;
           proxy_pass http://127.0.0.1:9900;
           proxy_redirect off;
        }
}

@k1llerk3ks
Copy link
Author

k1llerk3ks commented Apr 20, 2023

Thanks for your fast answer, i haven't thought about writing a nginx entry for the *.naxclow.com domain. I tried setting it up with the settings from your last message (as i already use nginx with lots of other reverse proxy settings) , changed the target port in src/v720_http.py to 9900, and tried running it. This still gives me no found device. Am i missing something?

Edit: found this in nginx log:

Apr 20 16:39:36 mydevicename nginx[763590]: 2023/04/20 16:39:36 [error] 763590#763590: *109 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.145.245, server: *.naxclow.com, request: "POST /app/api/ApiServer/getA9ConfCheck?devicesCode=<redacted>&random=<redacted>&token=<redacted> HTTP/1.1", upstream: "http://127.0.0.1:82/app/api/ApiServer/getA9ConfCheck?devicesCode=<redacted>&random=<redacted>&token=<redacted>", host: "v720.naxclow.com"

i was using port 82 instead of 9900 (of course in reverse proxy settings too), but that shouldn't change anything.
Also i removed random,token and deviceCode and replaced it with <redacted>

@vale-max
Copy link

vale-max commented Apr 20, 2023

You need to change the HTTP_PORT setting in both src/v720_http.py and src/fake_srv.py, and set the same port in the nginx proxy_pass directive, then check if you can connect to the port you chose using a browser like.
http://127.0.0.1:<your_port>/dev/list

Using port 82 needs root privileges to the user running the python3 command, that's a "low" port.
Better use an unprivileged high port ( >1024)

Your error message says it failed connecting to port 82 and you said you put the server on port 9900. Double check your configs are coherent then tell nginx to reload the configuration and restart the python3 server

@k1llerk3ks
Copy link
Author

k1llerk3ks commented Apr 20, 2023

Sorry, still doesn't work. I retried with port 9900. The nginx error from the log appeared only, after my python server process was closed, so some signal must have found its way to the process. Yet, still no "Found device" appears with this setup.

To summarize:

  1. I changed HTTP_PORT = 9900 in src/v720_http.py
  2. changed HTTP_PORT = 9900 in src/fake_srv.py
  3. added your nginx config to my nginx.
  4. Started the fakeserver with python3 src/a9_naxclow.py -s

I ran the python-script with root and without root, both with the same outcome. Port 9900 is open, according to nmap.

As soon as i use the unchanged scripts and disable my nginx process, everything works as intended and the cam shows up...

@vale-max
Copy link

Well, you need to by steps. Start everything then try to connect from same machine where the server runs to http://127.0.0.1/:<your_port>/dev/list

If this works then the server is up and running, next step, check if nginx is doing his job well.
From another computer in your network try connecting to http://whatever.naxclow.com/dev/list

If this displays the list of devices, even empty, means that nginx is ok too.

If once proving that both are ok the cam stil does not connect start the server with python3 src/a9_naxclow.py -s -v and try to understand what's wrong.
tcpdump can be of help too

For me it works, so the problem should not be in the method, just in the implementation.

@k1llerk3ks
Copy link
Author

k1llerk3ks commented Apr 26, 2023

Yes, the nginx is up and running and shows [] under devlist.
also with verbose i get the following blocks from time to time:

{"code": 200, "message": "OK", "data": {"tcpPort": 6123, "uid": "<devcode>", "isBind": "8", "domain": "v720.naxclow.com", "updateUrl": null, "host": "192.168.111.24", "currTime": "1682528136", "pwd": "deadbeef", "version": null}}
2023-04-26 18:55:41,321  [   INFO] [HTTP] POST /app/api/ApiServer/getA9ConfCheck?devicesCode=<devcode>&random=<random>&token=<token>
2023-04-26 18:55:41,321  [   INFO] [HTTP] sending: HTTP/1.1 200
Server: nginx/1.14.0 (Ubuntu)
Date: Wed, 26 Apr 2023 18:55:41 -0000
Content-Type: application/json
Connection: keep-alive
Content-Length: 232

Yet there is still no connection...

I also tried shutting down my nginx and running a clean docker nginx with only the provided server-block. Same outcome. No difference with the latest version, which included your push. Sooner or later i will check with another device and another network.

EDIT:

i made it work by using another device. First i was testing it on my main Computer, which is running Manjaro. My second device uses debian, everything worked on the first try with it.

I am still curious about the reason, why it didn't work. But as my problem is solved, i will now close the issue. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants