Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid argument supplied for foreach() #5

Closed
facuxt opened this issue Jul 6, 2016 · 9 comments
Closed

Invalid argument supplied for foreach() #5

facuxt opened this issue Jul 6, 2016 · 9 comments
Labels

Comments

@facuxt
Copy link

facuxt commented Jul 6, 2016

Hello, im having this issue....

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\unifi\index.php on line 452

i enabled debug mode, and this is what i get...

`Array
(
[url] => https://XXXXXXXXXX:8443/api/login
[content_type] => application/json;charset=UTF-8
[http_code] => 200
[header_size] => 332
[request_size] => 217
[filetime] => -1
[ssl_verify_result] => 18
[redirect_count] => 0
[total_time] => 0.656
[namelookup_time] => 0
[connect_time] => 0
[pretransfer_time] => 0.031
[size_upload] => 42
[size_download] => 41
[speed_download] => 62
[speed_upload] => 64
[download_content_length] => 41
[upload_content_length] => 42
[starttransfer_time] => 0.656
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => XXXXXXXXXXX
[certinfo] => Array
(
)

[primary_port] => 8443
[local_ip] => 172.16.10.166
[local_port] => 53698

)

-----RESPONSE----------------
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-FRAME-OPTIONS: SAMEORIGIN
Set-Cookie: unifises=XXXXXXXXXXXX; Path=/; Secure; HttpOnly
Set-Cookie: csrf_token=XXXXXXXXXXXXXX; Path=/; Secure
Content-Type: application/json;charset=UTF-8
Content-Length: 41
Date: Wed, 06 Jul 2016 03:25:47 GMT

{ "data" : [ ] , "meta" : { "rc" : "ok"}}
-----------------------------`

Then i have a logout and seems to be ok aswell... what is going on? im trying unifi 5.1.1 Beta at the moment..

Thank you in advance...

@malle-pietje
Copy link
Collaborator

I have not seen this error before. Which PHP and cURL versions are you using?

@Demonslay335
Copy link

I was able to reproduce this. It is due to a bit of a session confusion.

I tried connecting to UBNT 3.2.10 at first (I know the comments say 4.0.0 minimum, but I had to try before going through that hassle :P). I started getting 401s from the API, which did not register with the code as being a failed request (it looks for 400, so must be difference from old controller versions), so it tries to continue. This allowed list_sites() to fail to get any sites, returning false, and storing it in the session.

I then upgraded the controller to 4.8.20, and refreshed the page. Since the session variable $_SESSION['sites'] was already set, and equaled false, it sets $sites = $_SESSION['sites'];, which is what ends up breaking the foreach loop.

My suggestion is the change this line. on index.php:182

if (isset($_SESSION['sites']) || $_SESSION['sites'] === '') {

To:

if (isset($_SESSION['sites']) || empty($_SESSION['sites'])){

This allowed the sites from my updated controller to be pulled in correctly.

@malle-pietje
Copy link
Collaborator

malle-pietje commented Aug 16, 2016

Thanks for the feedback: seems to make sense to do it like this. I will test this change and include if all goes well.

@malle-pietje
Copy link
Collaborator

I checked the PHP docs and it turns out when using empty() there is no need to also use isset() as test.
http://php.net/manual/en/function.empty.php
Using empty() widens the scope of the test a bit to also test for "false" so it should do the trick.

@facuxt
Copy link
Author

facuxt commented Aug 17, 2016

Hello, i updated my unifi controller to 5.2.2 and suddenly it works... i put an .htpasswd simple http authorization on the app because it shows the ssh password of the aps and operator of hotspot...
@malle-pietje very nice job dude!!!! i want to collaborate with the project, would you be interested in an external app to do different stuff in unifi? i can help in angularJs frontend...

@malle-pietje
Copy link
Collaborator

There is popular demand for a reporting tool: where the API Browser tool is really a tool for developers there are quite a lot of non-technical users that want to have a tool that produces tabular reports (e.g. using DataTables) on the most relevant data collections/API endpoints. Such a tool should allow the user to select/deselect columns and a select a time range (e.g. using DataRangeSelector).

I have some idea's for this but just can't find the time to develop it.

@malle-pietje
Copy link
Collaborator

@facuxt Would be nice if you would be able to spend some time on that...:-)

@facuxt
Copy link
Author

facuxt commented Aug 17, 2016

maybe we can form some kind of project... i need that kind of reporting tool... with the api you can get historical data? for example from the unifi controller you just can get only 30 days ago... There is any documentation of the api?
i'll look forward to it... @enzogro

@malle-pietje
Copy link
Collaborator

Would be nice project to work on. The API can report on historical data as long as it's available from the controller. There is no documentation but I have made an effort in providing a start by adding comments to the functions in the class.unifi.php file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants