zbx-sadman / unifi_miner

UniFi Miner helps deliver data from UniFi Controller to Zabbix
66 stars 11 forks source link

Unifi Miner with UDM Pro and CloudKey Gen2 API #22

Open Yamdar opened 2 years ago

Yamdar commented 2 years ago

Hello,

The API URL have changed to access CloudKey Gen2 and UDM Pro API. More informations can be found here: https://ubntwiki.com/products/software/unifi-controller/api

The login endpoint is /api/auth/login All API endpoints need to be prefixed with /proxy/network (e.g. https://192.168.0.1/proxy/network/api/s/default/self)

I tried to modify the script but for now, no success.

Did you plan to add support for this kind of devices ?

zbx-sadman commented 2 years ago

Hello

You must try to change this lines, I guess.

Login: $globalConfig->{'login_path'} = "$globalConfig->{'unifilocation'}/api/login",

API: $globalConfig->{'api_path'} = "$globalConfig->{'unifilocation'}/api";

I have not these devices. I can't test changes w/o access to hardware.

Yamdar commented 2 years ago

That's what i did and after putting debug level 3, saw that there might have another issue: Some people are talking about it here: https://community.ui.com/questions/UDM-Pro-Unifi-API-Question/14e5fa72-4364-4958-b81f-fdded9e71a94

Hello, I had the same issue as you and after some tests I found how works the authentication...

1/ When you logged in the API add two headers that you need to interact with it, firstly "Set-Cookie: TOKEN=xxx" (this is your "cookie" token) and "X-CSRF-TOKEN: cafeca-cafeca-cafeca-cafecafe" (this is the csrf token)

2/ In all your requests add those two headers "Cookie: TOKEN=xxx" and "X-CSRF-TOKEN: cafeca-cafeca-cafeca-cafecafe", so from here there is two possible responses:

not sure that it's done with your script and not sure that i am able to modiy it yet.

zbx-sadman commented 2 years ago

You can try to add header on UA->get() method like this example, I guess:

$response = $[0]->{'ua'}->get($[2], "X-CSRF-TOKEN" => "cafeca-cafeca-cafeca-cafecafe");

Hint source:

Yamdar commented 2 years ago

Unfortunatly, didn't worked but i am sure i did something wrong.. will try to figure out a way to add support for those cloud keys.

Thank for your support.

Gael

Le mer. 4 mai 2022 à 12:07, Grigory Prigodin @.***> a écrit :

You can try add header to UA->get() method like this example:

$response = $[0]->{'ua'}->get($[2], "X-CSRF-TOKEN" => "cafeca-cafeca-cafeca-cafecafe");

Hint source:

— Reply to this email directly, view it on GitHub https://github.com/zbx-sadman/unifi_miner/issues/22#issuecomment-1117139287, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWMOZF35LXHGHBZD7DK7ZA3VIJD5BANCNFSM5UU7OJJA . You are receiving this because you authored the thread.Message ID: @.***>

zbx-sadman commented 2 years ago

Fiddler software helps to me find proper way to the Controller's data manipulation.

It's not simple work and access to real hardware is need to have effective processing.