travisghansen / hass-opnsense

OPNsense integration with Home Assistant
214 stars 29 forks source link

[FR]: Switch of pppoe connection #139

Open pickonedev opened 4 months ago

pickonedev commented 4 months ago

There is any chance to implement a switch for pppoe connection?

It would be great for keeping attackers away everytime they try someting, Like, connect/disconnect, in order for the dynamic external IP to get changed.

But something not through service netif restart because it is a very slow process… I better restart the router, it is faster. And not with ifconfig wan down/up as well, becaise it is not changing the external IP

Thank you!

Snuffy2 commented 3 weeks ago

How do you do this via the OPNsense Web page? I don't use PPPOE so I'm not sure what the options there look like.

alexdelprete commented 6 days ago

How do you do this via the OPNsense Web page? I don't use PPPOE so I'm not sure what the options there look like.

If @pickonedev means a "restart", I do reload of the PPPoE interface, that actually drops the current session and restarts a fresh one. I do it manually via the Interface Overview reload button, but I didn't check if there's an API call for that.

image

alexdelprete commented 6 days ago

I checked, and I think this is the relevant API function:

image

pickonedev commented 5 days ago

How do you do this via the OPNsense Web page? I don't use PPPOE so I'm not sure what the options there look like.

If @pickonedev means a "restart", I do reload of the PPPoE interface, that actually drops the current session and restarts a fresh one. I do it manually via the Interface Overview reload button, but I didn't check if there's an API call for that.

image

This is fast, I didn't know about this restart button from Interface Overview :-O. But, there is any commnd line which can achieve the same fast result, from putty?

Edit: Oh, now I have read your second post. Now I need to know how to use API with opnsense :-D

alexdelprete commented 5 days ago

But, there is any commnd line which can achieve the same fast result, from putty?

IDK, but you can search in OPNsense community forum. Meanwhile, did you test the reload to see if it does what you need?

Anyway, there's the API function for that, so it can be implemented in this integration as an action.

pickonedev commented 5 days ago

Yes, it does it very quick. That reload button works very good.

pickonedev commented 5 days ago

I think I found a way to use the api. It is working with this:

curl -k -u "keys" "https://192.168.0.1/api/interfaces/overview/reloadinterface/wan"

If you know any improvement to this shell command, it will be even better :-)

This is even faster than using the button

Edit: by the way, there is any shell command to achieve this reloadinterface function (to implement it in the home assistant addon)? Or I can just use curl locally, inside opnsense as a curl command? Is it right to do so?

alexdelprete commented 5 days ago

You're calling the REST API function I mentioned previously, good that it works fine. :)

Now you just need to wait for @Snuffy2 to implement it and then you can call the action in HA as with all other actions (once known as "services").

The integration doesn't use shell commands, it integrates an http client to call the REST API that OPNsense provides.

pickonedev commented 5 days ago

I have done it in the intergration as well, and it is working, like this:

image

But yes, it will be great if Snuffy2 could integrate it directly 🥇

Thank you for everything, it is WOOOOOOORKING 🥇

alexdelprete commented 5 days ago

No problem. We can close the issue.

UPDATE: I'll keep it open since @Snuffy2 might want to track it.