mariusmotea / diyHue

Philips Hue emulator that is able to control multiple types of lights
Other
627 stars 107 forks source link

Bridge on loopback #470

Closed Balder86 closed 5 years ago

Balder86 commented 5 years ago

If an IP address is provided as an start parameter, the HTTP Server still binds to the loopback address 0.0.0.0 and not to the provided one. -> /opt/hue-emulator/HueEmulator3.py --ip=192.168.178.43 --debug=true

ap.add_argument("--ip", help="The IP address of the host system", nargs='?', const=None, type=str)

if args.ip:
    HostIP = args.ip
    print("Host IP given as " + HostIP)
else:
    HostIP = getIpAddress()

def run(https, server_class=ThreadingSimpleServer, handler_class=S):
    if https:
        server_address = ('', 443)
        httpd = server_class(server_address, handler_class)
        ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
        ctx.load_cert_chain(certfile="./cert.pem")
        ctx.options |= ssl.OP_NO_TLSv1
        ctx.options |= ssl.OP_NO_TLSv1_1
        ctx.options |= ssl.OP_CIPHER_SERVER_PREFERENCE
        ctx.set_ciphers('ECDHE-ECDSA-AES128-GCM-SHA256')
        ctx.set_ecdh_curve('prime256v1')
        #ctx.set_alpn_protocols(['h2', 'http/1.1'])
        httpd.socket = ctx.wrap_socket(httpd.socket, server_side=True)
        logging.info('Starting ssl httpd...')
    else:
        server_address = ('', 80)
        httpd = server_class(server_address, handler_class)
        logging.info('Starting httpd...')
    httpd.serve_forever()
    httpd.server_close()
mariusmotea commented 5 years ago

But why do we need to limit this? Rules work with internal http requests on loopback, changing this will broke rules processing and also schedules.

Balder86 commented 5 years ago

The design is sufficient for running diyhue in a docker container, running it on a host with multiple services is not possible. It will always listen on 0.0.0.0:80 and will therefore block all other services from running on :80 on every network interface.

Had also a look on the ssdp function, same matter here with the IP. Furthermore the socket seems not to work if created for a specific IP address.

To which internal requests and schedules are you referring so I can have a look?

Am Mo., 17. Dez. 2018, 22:10 hat Motea Marius notifications@github.com geschrieben:

But why do we need to limit this? Rules work with internal http requests on loopback, changing this will broke rules processing and also schedules.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mariusmotea/diyHue/issues/470#issuecomment-447999792, or mute the thread https://github.com/notifications/unsubscribe-auth/AcwOyWawmuA_F2_knRPw8NRfhzo4rfnyks5u6AgogaJpZM4ZXFwS .

mariusmotea commented 5 years ago

The function SendRequest will add http://127.0.0.1/ automatically if it don't receive an url that don't start with http.

Now i will give example of rule and almost the same is for schedules:

            "actions": [
                {
                    "address": "/groups/2/action",
                    "body": {
                        "on": false
                    },
                    "method": "PUT"
                }
            ],

while the rule engine can process these directly i choose to go easy way and really send that http request to itself as this will also trigger the sensors action.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

This issue has been automatically closed as it has not had any recent activity. Thank you for your contributions.