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

Mac Filtering Wifi #103

Closed christianguei closed 3 years ago

christianguei commented 3 years ago

Hello,

Hope you're well ? Thanks again for your developpement which helped me a lot.

I have a question, is it possible with your librairies to put MAC Addresses in the White/Black list of a Wifi ?

Cheers, Chris

christianguei commented 3 years ago

Here is the printscreen of the parameters on a Wifi Network.

I want to add/remove mac addresses with UniFi-Api-Client

Filtering
christianguei commented 3 years ago

I think i found it :

public function set_wlan_mac_filter($wlan_id, $mac_filter_policy, $mac_filter_enabled, array $macs)
    {
        if (!is_bool($mac_filter_enabled)) {
            return false;
        }

        if (!in_array($mac_filter_policy, ['allow', 'deny'])) {
            return false;
        }

        $macs    = array_map('strtolower', $macs);
        $payload = [
            'mac_filter_enabled' => (bool) $mac_filter_enabled,
            'mac_filter_policy'  => $mac_filter_policy,
            'mac_filter_list'    => $macs
        ];

        return $this->set_wlansettings_base($wlan_id, $payload);
    }

Am i right ?

malle-pietje commented 3 years ago

Glad you still like the class👍 Yes, that method/function should do what you’re looking achieve.

christianguei commented 3 years ago

I'm almost ready ;) But i can't seem to pass the MAC address, here is my payload :

    $macs = "d0:33:11:1c:72:9e";
$mac_filter_policy = "allow";
$wlan_id = "602f9d29409afc09137792a5";

$payload = [
    'mac_filter_enabled' => (bool) $mac_filter_enabled,
    'mac_filter_list' => $macs,     
    'mac_filter_policy'    => $mac_filter_policy

When i remove the mac_filter_list it works ... Do you have an idea ?

christianguei commented 3 years ago

Managed to do it ! :) Thanks !

malle-pietje commented 3 years ago

The 4th parameter must be an array, not a single MAC address/string.

malle-pietje commented 3 years ago

Beat me to it!

christianguei commented 3 years ago

Beat me to it!

Yes but again you DID the job by answering and having develop this marvelous plugin ! Thanks

malle-pietje commented 3 years ago

Thanks, not many people appreciate the amount of time it takes to maintain and support this library😉