Reply
Veteran Member
Posts: 4,969
Registered: ‎06-13-2015
Kudos: 1345
Solutions: 234

Re: Unifi API browser tool: updates and discussion


@adminwerk wrote:

Thank you for the great work and the flowing updates!

 

As you're quite firm with the API, maybe you can help me with a slight offtopic question. Is there a way to change the SSID of the guest-wlan? As we need to change the password on a daily base, we'd like to change it as well. like guest20160118 today and guest20160119 tomorrow. If only the password is changed certain clients are unable to connect because the trying the old password.

 

Sorry if too offtopic

Thanks Chris


you're welcome! Glad this tool is turning out to be useful to some people hereIcon Wink

 

What you're looking for is possible using this function in my version of the API client:

https://github.com/malle-pietje/Unifi-API-browser/blob/master/phpapi/class.unifi.php#L872-L890

where $name = ssid and $x_passphrase is the psk. The id is the unique id of the wlan which you will find in the wlan config using my tool.

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.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
New Member
Posts: 2
Registered: ‎01-18-2016

Re: Unifi API browser tool: updates and discussion

Thank you very much. It works like a charm!

Chris

Veteran Member
Posts: 4,969
Registered: ‎06-13-2015
Kudos: 1345
Solutions: 234

Re: Unifi API browser tool: updates and discussion

Pushed a minor update to github today:

  • Improved readability of the debug output when $debug is set to true in the config file, making it readable in cli mode as well as for html output.

Enjoy!

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.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
Emerging Member
Posts: 91
Registered: ‎11-20-2015
Kudos: 3
Solutions: 6

Re: Unifi API browser tool: updates and discussion

Hello slooffmaster,

 

i personally haven't tried it yet my controller is on the aws. Can i ask a question regarding the hotspot.

 

Hotspot

  • stat vouchers
  • stat payments
  • list hotspot operators

Can i make a voucher stats like unused and used vouchers per month based on your api?

 

My appology if i don't understand correctly the API browser tool uses and its purpose.

 

Thanks,

Regular Member
Posts: 348
Registered: ‎04-10-2014
Kudos: 154
Solutions: 20

Re: Unifi API browser tool: updates and discussion

sloofmasters API tool will show you the operators and the vouchers. I highly suggest you download it and play with it to see what you can do. What you chose to do with the information is up to you. You could use the API class and a PHP script to only show what you are looking for. I've not viewed his index.php but I'm sure it will give you some starters. 

 

I've removed any potential sensitive data below but you should get the gist of what is returned. 

 

Sample Operator return

    {
        "_id": "",
        "name": "",
        "note": "",
        "site_id": "",
        "time_created": ,
        "x_password": ""
    }

 

 

Sample Voucher return with 2 Vouchers

 

 

{
        "_id": "",
        "admin_name": "admin",
        "code": "",
        "create_time": ,
        "duration": 1440,
        "for_hotspot": false,
        "note": "Test",
        "qos_overwrite": false,
        "quota": 1,
        "site_id": "",
        "used": 0
    },
    {
        "_id": "",
        "admin_name": "admin",
        "code": "2882379947",
        "create_time": 1453860598,
        "duration": 1440,
        "for_hotspot": false,
        "note": "Test",
        "qos_overwrite": false,
        "quota": 1,
        "site_id": "",
        "used": 0
    },

 

To call the API, create a custom PHP file and point to the unifiapiclass. The code below is some snippets from a page I use to get voucher information. 

 

<?php
require 'classes/unifi.config.php'; // I use a different PHP class name than sloofmaster does so you will need to change this name. 

// Send Authorization information to UniFi Server
$unifi=new unifiapi();
$unifi->login();
$authResult  = $unifi->login();
$getVouchers = $unifi->get_vouchers();

// show me the voucher info... 
echo '<pre>', print_r($getVouchers, true), '</pre>';
echo "Voucher ID is " . $item->code; echo "Quota is " . $item->qos_usage_quota . "MB"; ?>

 

 

Emerging Member
Posts: 91
Registered: ‎11-20-2015
Kudos: 3
Solutions: 6

Re: Unifi API browser tool: updates and discussion

Thank you thesohoguy for the explaination and for the simple examples.

New Member
Posts: 32
Registered: ‎08-31-2015
Kudos: 7

Re: Unifi API browser tool: updates and discussion

[ Edited ]

Just after some assistance with the API Browser.

Uploaded the files to our cpanel webhost, changed the config file, and tried to access the index.php.

Takes a very long time to load, when it does, no sites are selectable from the drop down.

 

Checked the error_log, and have two entries:

[07-Feb-2016 06:22:16 UTC] curl error: Failed to connect to stan.no-ip.org port 8443: Connection timed out
[07-Feb-2016 06:22:16 UTC] PHP Warning: Invalid argument supplied for foreach() in home/stan/public_html/stan.com/api/index.php on line 415

 

Have tried 2 different controllers(Different versions, 4.8.12, and 4.8.6), which are on different internet connections, different router types, and different base OS(Ubuntu v Windows).

 

Any idea's?

@slooffmaster

 

Veteran Member
Posts: 4,969
Registered: ‎06-13-2015
Kudos: 1345
Solutions: 234

Re: Unifi API browser tool: updates and discussion


@shaungunston wrote:

Just after some assistance with the API Browser.

Uploaded the files to our cpanel webhost, changed the config file, and tried to access the index.php.

Takes a very long time to load, when it does, no sites are selectable from the drop down.

 

Checked the error_log, and have two entries:

[07-Feb-2016 06:22:16 UTC] curl error: Failed to connect to stan.no-ip.org port 8443: Connection timed out
[07-Feb-2016 06:22:16 UTC] PHP Warning: Invalid argument supplied for foreach() in home/stan/public_html/stan.com/api/index.php on line 415

 

Have tried 2 different controllers(Different versions, 4.8.12, and 4.8.6), which are on different internet connections, different router types, and different base OS(Ubuntu v Windows).

 

Any idea's?

@slooffmaster

 


This looks like a connectivity issue between the server you installed the tool on and your controller server; somehow curl cannot connect to the IP address or port. Any firewalls in between that are preventing a connection? The PHP error is just a result of the connectivity problem.

 

To start off with, I suggest you first check IP connectivity by doing a ping from the server where the tool is installed to the controller host name which you configured in the config file.

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.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
Veteran Member
Posts: 4,969
Registered: ‎06-13-2015
Kudos: 1345
Solutions: 234

Re: Unifi API browser tool: updates and discussion

BTW: I am also unable to connect to stan.no-ip.org:8443 or stan.no-ip.org

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.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
New Member
Posts: 32
Registered: ‎08-31-2015
Kudos: 7

Re: Unifi API browser tool: updates and discussion

As a bit of a followup, with the help of @slooffmaster, we worked out the shared cpanel hosting where i had put the API Browser tool, blocks outgoing connections to 8443 (or perhaps everything besides 80, and 443).

Moved this to a local server, and works fine.

 

Thanks to sloofmaster for the assistance, and for creating such a useful tool.

 

 

Veteran Member
Posts: 4,969
Registered: ‎06-13-2015
Kudos: 1345
Solutions: 234

Re: Unifi API browser tool: updates and discussion

@shaungunston thanks for feedback! Glad to hear the tool is usefulIcon 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.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
Veteran Member
Posts: 4,969
Registered: ‎06-13-2015
Kudos: 1345
Solutions: 234

Re: Unifi API browser tool: updates and discussion

I pushed an updated version of the Unifi API Browser tool to github today with support for the metrics used in the new (cool) dashboard that has been introduced in Unifi controller version 4.9.1.alpha:

added: dashboard metrics data collection, which is supported on
controller version 4.9.1(alpha) and higher. The option shows up in the
"stats" pull down menu when a controller version of 4.9.1 or higher is
detected.

NOTE: to be able to download Unifi controller version 4.9.1.alpha you require access to the Beta forums

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.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
Member
Posts: 254
Registered: ‎07-19-2015
Kudos: 9
Solutions: 2

Re: Unifi API browser tool: updates and discussion

Works fine 

Emerging Member
Posts: 91
Registered: ‎11-20-2015
Kudos: 3
Solutions: 6

Re: Unifi API browser tool: updates and discussion

I have succefully implemented this on my local pc with the controller installed on the same pc.

 

I want to implement this on my Amazon cloud aws controller. I have some security concern.

1. will it cause an security issue?

2. I will open it to a certain port on public ip

Veteran Member
Posts: 4,969
Registered: ‎06-13-2015
Kudos: 1345
Solutions: 234

Re: Unifi API browser tool: updates and discussion

[ Edited ]

@rpm048 wrote:

I have succefully implemented this on my local pc with the controller installed on the same pc.

 

I want to implement this on my Amazon cloud aws controller. I have some security concern.

1. will it cause an security issue?

2. I will open it to a certain port on public ip


Security should indeed be a major concern when providing public access to this tool because it exposes credential/psk's etc... Therefore, when exposing this tool on a public url it is indeed good pratice to tightly control access and limit access to specific IP adresses using AWS rules in your case. On top of these controls and when using apache2, you can best also use .htaccess to limit access to specific IP adresses, maybe add a password as well.

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.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
Veteran Member
Posts: 4,969
Registered: ‎06-13-2015
Kudos: 1345
Solutions: 234

Re: Unifi API browser tool: updates and discussion

another update pushed to github today:

added: port forwarding stats
extended: output from daily.site and hourly.site stats

NOTE: currently port forward stats are not visible through the controller dashboard, using the API Browser tool you can at least have a peek at them, or else you can use the function which is now added to the PHP class.

 

Enjoy!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.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
Established Member
Posts: 927
Registered: ‎12-18-2015
Kudos: 216
Solutions: 30

Re: Unifi API browser tool: updates and discussion

Is it possible to have it work over the cloud (customer has a UC-CK Cloud Key) for times when you can't forward port 8443?

 

Let me know please and thanks.

 

-Jamie M.

Veteran Member
Posts: 4,969
Registered: ‎06-13-2015
Kudos: 1345
Solutions: 234

Re: Unifi API browser tool: updates and discussion


@toysareforboys wrote:

Is it possible to have it work over the cloud (customer has a UC-CK Cloud Key) for times when you can't forward port 8443?

 

Let me know please and thanks.

 

-Jamie M.


I haven't tried this yet, primarily because I don't have a Cloud Key (don't have an immediate requirement for it myself). 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.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
New Member
Posts: 7
Registered: ‎02-16-2016

Re: Unifi API browser tool: updates and discussion

Great tool..have installed but am interested in the following metrics:

 

1) daily count of online users per site

2) average and peak bandwith per site 

3) report for number of users connected per site at any given time

 

can see the API has those metrics but can seem to understand a bit of them .

 

Veteran Member
Posts: 4,969
Registered: ‎06-13-2015
Kudos: 1345
Solutions: 234

Re: Unifi API browser tool: updates and discussion


@jikamsila wrote:

Great tool..have installed but am interested in the following metrics:

 

1) daily count of online users per site

2) average and peak bandwith per site 

3) report for number of users connected per site at any given time

 

can see the API has those metrics but can seem to understand a bit of them .

 


Welcome to these forums. The tool itself queries data that is made available through the API. There are some stats but not all might fit your requirements.

1) daily count of online users per site -> this is available from the API: "daily site stats" in my tool

2) average and peak bandwith per site -> this is a metric you can better collect from the API (e.g. every 5 minuts) and monitor this with a monitoring tool like Cacti

3) report for number of users connected per site at any given time -> the resolution of the stats that are available through the API is limited to an hour: "hourly site stats" in my tool

 

My tool was developed primarly to show the raw data that is available through the API. For specific requirements you may need to start writing code in PHP using the PHP API client that comes with the tool.

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.
The thread on our UniFi Device Search tool can be found here, also check out our Captive Portal solutions for UniFi.
Reply