kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
304 stars 59 forks source link

Feature Request: Port forwarding #44

Open lucasff opened 4 years ago

lucasff commented 4 years ago

Hello!

I'd like to have support for the following use case. I'm willing to pay a beer casket (maybe with Durstexpress.de)

I'd like to be able to take down all port forwarding assigned to any device with a specific port, such as 80. Then I'd like to enable one device to port forward. In this case, does the TR-069 Fritz protocol or any of it's extensions allow a single host in the network to manage port forwarding for other hosts?

I'd like to use Home Assistant and detect if a host is online to turn on port-forwarding and then if it's offline disable the port-forwarding.

rikroe commented 4 years ago

I'd love to see this as well. However, given this AVM documentation (1.14) it will not be possible via TR-069:

Port mapping entries are only allowed for hosts inside of LAN. Furthermore hosts can only add port mapping entries for themselves and not for other hosts in the LAN.

When testing it out, it also only works the machine that I'm connecting from.

What might be possible could be using the web UI API, i.e. calling http://fritz.box/data.lua with the correct parameters. However this does not fit into this library which is purely TR-069 and not HTTP and could be very vulnerable to breaking changes.

kbr commented 4 years ago

A remote http-based access is possible by using the official AVM AHA-HTTP-Interface, but that's just a wrapper for a TR-064 api-subset for home automation.

Controlling the box by the web UI is very fragile, can break on FritzOS updates and may even be model-specific. So I strongly discourage to try it this way.

bcutter commented 3 years ago

Hi, has anyone achieved this meanwhile?

I have a very important use case I want to address with this feature (automate Let's Encrypt certificate renewal progress by only enabling port forward rule for few minutes) and it would be totally fine for being able doing this only by the machine affected by the port forwarding.

Interesting: the Home Assistant fork (ha-fritzbox-tools) has implemented this already. How to do it in fritzconnection?

kbr commented 3 years ago

ha-fritzbox-tools is based on fritzconnection, using the Layer3Forwarding service for this task.

bcutter commented 3 years ago

ha-fritzbox-tools is based on fritzconnection, using the Layer3Forwarding service for this task.

Uff. For me as a non-developer it´s quite hard to estimate if it´s possible to use the same methode like the ha-fritzbox-tools in my scenario (simple script: enable port forwarding / renew certificate / disable port forwarding).

I tested fritzconnection and there are plenty of commands but obviously no "fritzports" or similar. How are chances there will in near future?

bcutter commented 2 years ago

Just a little reminder bump here. One year of silence has ended now -.-

serv-inc commented 6 months ago

Are you still interested @bcutter ? https://github.com/kbr/fritzconnection/issues/206 is very similar, and might be applied for your case as well.

serv-inc commented 6 months ago

Controlling the box by the web UI is very fragile, can break on FritzOS updates and may even be model-specific. So I strongly discourage to try it this way.

@kbr : What would you recommend if there is no official api ?

bcutter commented 6 months ago

Are you still interested @bcutter ? #206 is very similar, and might be applied for your case as well.

Interested yes. Able to use this in a Debian based shell script... not into that right now. I think I'd need a "ready to use" snippet as I'm still not a developer.

kbr commented 6 months ago

@kbr : What would you recommend if there is no official api ?

Ask for one or hack at your own risk. If AVM changes internals this attempt may fail. Feel free to use the library to get an sid for that. It is officially published by AVM how to get one.

bcutter commented 6 months ago

Well, how did the Home Assistant AVM integration folks implement this? The integration is already capable of enabling/disabling port forwarding: https://www.home-assistant.io/integrations/fritz/#port-forward

With the limitation "only by the host affected by the port forwarding". That's why I was really hoping (I still do) this will be easily implemented natively, out of the box, plug'n'play - no dirty hacks.

kbr commented 6 months ago

I don't know how it is implemented in Home-Assistant, but it is open source and inspectable.