Reply
Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: released

[ Edited ]

@Petasch what is your controller version and did you enter that value in the config.php file? That login screen is not what you should be seeing with $debug = true. It should be something like this:

debug.JPG

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Emerging Member
Posts: 55
Registered: ‎03-14-2013
Kudos: 5

Re: Unifi API browser tool: released

sorry problem solved. i doesn´t fill controller version, because the comment was "this value is not yet used". with controller version, it works. thank you

Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: released

sorry about that confusing message there. Thanks for reporting the issue! I have already updated the template file on github.Icon Biggrin

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: released

[ Edited ]

IMPORTANT UPDATE AVAILABLE!

@Petasch@raimis200 @ryan123

Please update your code if you have a recent version with the "About Modal"!

 

Either download and re-install a fresh version of the zip file, or run "git pull" from the directory where you installed the tool. There was a nasty bug caused by the fact that in some cases a site_id was required to be able to pull the actual controller version from the API. If no site was selected the browser would stall.

 

My apologies for the troubles this may have caused.Icon Confused

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
New Member
Posts: 20
Registered: ‎02-22-2014

Re: Unifi API browser tool: released

@slooffmaster  i was just wondering, when i requested UBNT support for API documentation they have pointed me to https://dl.ubnt.com/unifi/4.7.6/unifi_sh_api  which contains max of 6 or 7 API functions. Where as ur application had many more, like "events & alerts"  etc... where can i find a complete list of API functions ? we are working on a guest wifi portal and are exploring all the possbile ways of controlling unifi hardware.  this would help us a lot.

New Member
Posts: 20
Registered: ‎02-22-2014

Re: Unifi API browser tool: released

[ Edited ]

BTW the new update speeded up the API calls time like crazy , last week version was taking 7+sec sometimes to get 3000 event logs, where as now its <1sec, thats brilliant work. can we know what have you done for this ?

 

& a question regarding function " list_events() ", is ther a possibility of quering only last 1 hr log or log entries after a specific time? 

Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: released


s1threddy wrote:

BTW the new update speeded up the API calls time like crazy , last week version was taking 7+sec sometimes to get 3000 event logs, where as now its <1sec, thats brilliant work. can we know what have you done for this ?

 

& a question regarding function " list_events() ", is ther a possibility of quering only last 1 hr log or log entries after a specific time? 


thanks for the feedback. Glad my bit of magic worked out;-))

 

Regarding limiting the output of list_events(): I don't believe that is supported by the API itself.

 

The "bits" of the API I have added to the PHP API client, I have figured out by analyzing the communication between browser and controller when you are logged in to the controller. Fact is that the controller UI uses the same API I am using for my tool...Icon Wink

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: updates and discussion

Minor fix published to github:

- detected controller version is now displayed correctly in the About modal

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Regular Member
Posts: 347
Registered: ‎04-10-2014
Kudos: 151
Solutions: 20

Re: Unifi API browser tool: updates and discussion

I have not had any login issues with the tool but in the newest version I was not able to select my sites. It worked in prior verions so I knew it had to be something simple. As updating the sitename  in the php class showed data in the apibrowser, I figured it was in the site detection. I was able to resolve the issue by using the site code from a previous verson of the apibrowser with the current version.

 

Starting on lline 137 in index.php I replaced 

if(!isset($_SESSION['sites'])) {
    $sites = $unifidata->list_sites();
    $_SESSION['sites'] = $sites;
} else {
    $sites = $_SESSION['sites'];
}

with

 

if(!isset($_GET['sites'])) {
    $unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $siteid, $controllerversion);
    $loginresults = $unifidata->login();
    if($loginresults === 400) {
        error_log($sites);
        $alertmessage = '<div class="alert alert-danger" role="alert">HTTP response status: 400<br>This is probably caused by a Unifi controller login failure, please check your credentials in config.php</div>';
    }
    $sites = $unifidata->list_sites();
    $_SESSION['sites'] = $sites;
} else {
$sites = $_SESSION['sites'];
}

 

Thanks for developing the tool. It did help me in determining an issue I was having with the sitename versus the site ID when develping a portal for multiple sites. 

 

Tony

 

 

 

Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: updates and discussion

[ Edited ]

thesohoguy wrote:

I have not had any login issues with the tool but in the newest version I was not able to select my sites. It worked in prior verions so I knew it had to be something simple. As updating the sitename  in the php class showed data in the apibrowser, I figured it was in the site detection. I was able to resolve the issue by using the site code from a previous verson of the apibrowser with the current version.

 

Starting on lline 137 in index.php I replaced 

if(!isset($_SESSION['sites'])) {
    $sites = $unifidata->list_sites();
    $_SESSION['sites'] = $sites;
} else {
    $sites = $_SESSION['sites'];
}

with

 

if(!isset($_GET['sites'])) {
    $unifidata = new unifiapi($controlleruser, $controllerpassword, $controllerurl, $siteid, $controllerversion);
    $loginresults = $unifidata->login();
    if($loginresults === 400) {
        error_log($sites);
        $alertmessage = '<div class="alert alert-danger" role="alert">HTTP response status: 400<br>This is probably caused by a Unifi controller login failure, please check your credentials in config.php</div>';
    }
    $sites = $unifidata->list_sites();
    $_SESSION['sites'] = $sites;
} else {
$sites = $_SESSION['sites'];
}

 

Thanks for developing the tool. It did help me in determining an issue I was having with the sitename versus the site ID when develping a portal for multiple sites. 

 

Tony


 

thanks @thesohoguy / Tony, glad the tool has been useful! That's why I'm sharing it.Icon Biggrin

 

Funny thing is, I don't see this behaviour, whether on Chrome, Safari, FireFox or Edge.

Looking at your fix I believe something else is going on, probably some persistent cookie. The thing is I never use:

$_GET['sites']

which means your "if" statement will always be executed, giving you the right outcome and filling the $sites array. But on each page refresh you will be pulling the sites list from the controller, which is unnecessary.

 

It might be a better fix to somehow check/validate the contents of the 

$_SESSION['sites']

array in the "if" condition, not only using "isset".

I'll look into this to see how I can avoid cookies messing things up.....Smash

 

Thanks for the feedback!

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Regular Member
Posts: 347
Registered: ‎04-10-2014
Kudos: 151
Solutions: 20

Re: Unifi API browser tool: updates and discussion

 

 

 

Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: updates and discussion

I'm now testing a cookie expiry function which clears the session after a defined period of inactivity. If it survives until tomorrow I'll push it to github. I will let you know, maybe you can test and see if it works for you?

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Regular Member
Posts: 347
Registered: ‎04-10-2014
Kudos: 151
Solutions: 20

Re: Unifi API browser tool: updates and discussion

Sure, I"m more than willing to test. 

Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: updates and discussion

@thesohoguy I've just pushed a new version of the tool with the cookie timeout function to github. Could you have a go at it to see whether it addresses your issue?

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Regular Member
Posts: 347
Registered: ‎04-10-2014
Kudos: 151
Solutions: 20

Re: Unifi API browser tool: updates and discussion

@slooffmaster you changes fixed the issue that I was having. Great job.

 

Thanks! 

Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: updates and discussion

glad to hear that! Thanks for the feedbackIcon Lol

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: updates and discussion

Pushed a new release to github, just after the Christmas break:

  • code clean up of index.php following PSR-2 as much as possible for the pure PHP code
  • added data collections for VoIP extensions, port configurations, port forwarding rules and dynamic DNS configuration
  • code clean up of the unifiapi class (still much more work is needed)
  • fix of the create_voucher function (thanks @wozzzzz for reporting this)

Enjoy! I will be looking forward to your feedbackIcon Biggrin

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: updates and discussion

[ Edited ]

I just pushed a new version to github today with the following changes to the class.unifi.php file:

  • fixed a minor bug in error handling which was slowing down data retrieval and causing duplicate actions
  • removed the version check in the login function, it wasn't doing anything. Left the controller version in purely for backwards compatibility, you also still need to enter a value for it in the config file.

@s1threddy the performance of data retrieval with this version has improved by more than 50%Icon Lol

@wozzzzz thanks for testing the fix before I released it!

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
New Member
Posts: 20
Registered: ‎02-22-2014

Re: Unifi API browser tool: updates and discussion

@slooffmaster woah !! great job with optimization.  hiding other menu option till site is selected, genius   Hurray
 

may be u can figure out a way to specify time frame for events API too. Icon Biggrin 

Veteran Member
Posts: 4,657
Registered: ‎06-13-2015
Kudos: 1261
Solutions: 218

Re: Unifi API browser tool: updates and discussion

@s1threddy glad to hear!

I have received the request from someone else as well to implement a way to limit/expand the time frame for events selection. I need to think about that; it is quite a bit of work and also makes the program slightly more complex and more difficult to maintain.

 

Do you have a suggestion of how to implement such a feature in the GUI?

Art of WiFi
Check out our UniFi API browser tool on GitHub. The PHP API client which it uses, can be found here on GitHub.
Our UniFi Device Search tool can be found here, and our Captive Portal solutions for UniFi can be found here.
Reply