Art-of-WiFi / UniFi-API-client

A PHP API client class to interact with Ubiquiti's UniFi Controller API
MIT License
1.09k stars 217 forks source link

Feature request: Enable/Disable Portforward rules #79

Closed Tuxos closed 3 years ago

Tuxos commented 3 years ago

Hi,

first of all, thanks a lot for your great work! I use it for my Homeautomation and it works pretty well :-)

Can you please add a function to enable/disable portforward rules? Or is there a way to do this? I tried a lot with a custom api request, but I don´t get it to work.

Thanks a lot, Dennis

malle-pietje commented 3 years ago

I'll have a look at this as soon as I have a fully functional test network available. But keep in mind, if this can't be achieved using the custom request function/method it also cannot be implemented in the PHP API Client class as a separate function.

Tuxos commented 3 years ago

Hi malle-pietje,

thanks for your very fast answer! I made it work with the custom api call. I had a bad typo :-/ Sorry for that.

It would be great if we can get a own function for this, but I can life also with the custom api call :-)

If anybody needs this too, this is how I implemented it:

        public function enable_portfwd($portfwd_id, $bool) {

            $url = $this->ReadPropertyString("url");
            $username = $this->ReadPropertyString("username");
            $password = $this->ReadPropertyString("password");
            $site = $this->ReadPropertyString("site");
            $version = $this->ReadPropertyString("version");

            $payload = [
                "enabled" => $bool,
            ];

            $urlportfwd          = '/api/s/'.$site.'/rest/portforward/'.$portfwd_id;
            $request_type = 'PUT';
            $return       = 'array';

            $unifi_connection = new UniFi_API\Client($username, $password, $url, $site, $version, false);
            $login = $unifi_connection->login();
            $results = $unifi_connection->custom_api_request($urlportfwd, $request_type, $payload, $return);

            return $results;
        }

Kind Regards, Dennis

malle-pietje commented 3 years ago

Cool, thanks for sharing!