-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Problem with API - /host/XXX reports 'not authenticated' but all other APIs work after authentication #1813
Comments
Folks seeing this issue, please post here: INFORMATION NEEDED (See point g - it will greatly help if someone facing this issue can let me access that system. So far, I can't debug much as I can't reproduce it) a) Your cakePHP version: thx |
i will try to remove the ZM auth and just use apache basic auth to see if it makes a difference, i remarked that the apache auth login is passed on the url inside the zmninja app... so i guess we could still have some minor security while having a working zmninja... testing this before making any code changes. BRB |
a) 2.8.0 |
Based on what @dakota and I saw earlier: To test, please don't use zmNinja. Just launch a browser, login, open a new tab and try the |
a) opt_auth removed from ZM |
okay, thanks for the confirmation. Hopefully we can figure out something about the core issue. In the meantime, you can comment out getDiskPercent completely - no one uses it (I modified my first post) |
my current hostcontroller.php does not contain the gettimezone function, should i add it ? |
its optional - it will be part of next ZM release |
hmmmm, this appears to be working fine for me. Machine 1 Machine 2 In each case, when I enter I see:
A couple times I got a 404 error message, but that turned out to be me fat fingering the wrong url. |
Yes I'm not entirely sure what is the reason why this fails for some folks. It's some server side issue - because I tried some of these portals with my browser and had the same issue. |
Just to provide another data point with a version of zoneminder matching an earlier post, I tried this from our publicly available demo server: cake 2.8.0
Note that I performed this test using both my admin login and the read-only zmuser login. Both were successful. |
a) 2.8.0
|
@dakota, @FrancoisDesfosses instead of doing an empty beforeFilter in HostController, can you try explicitly calling
|
Fatal error: Call to undefined function beforeFilter() in /usr/share/zoneminder/www/api/app/Controller/HostController.php on line 6 { "success": false, "data": { "code": 500, "name": "Call to undefined function beforeFilter()", "message": "Call to undefined function beforeFilter()", "url": "/zm/api/host/getVersion.json", "exception": { "class": "FatalErrorException", "code": 500, "message": "Call to undefined function beforeFilter()", "trace": [ "#0 /usr/share/zoneminder/www/api/lib/Cake/Error/ErrorHandler.php(213): ErrorHandler::handleFatalError(1, 'Call to undefin...', '/usr/share/zone...', 6)", "#1 [internal function]: ErrorHandler::handleError(1, 'Call to undefin...', '/usr/share/zone...', 6, Array)", "#2 /usr/share/zoneminder/www/api/lib/Cake/Core/App.php(970): call_user_func('ErrorHandler::h...', 1, 'Call to undefin...', '/usr/share/zone...', 6, Array)", "#3 /usr/share/zoneminder/www/api/lib/Cake/Core/App.php(943): App::_checkFatalError()", "#4 [internal function]: App::shutdown()", "#5 {main}" ] }, "queryLog": { "default": { "log": [ { "query": "SELECT |
that's surprising. Can you post your modified HostController.php file in a GitHub gist? |
Adding |
does that has something to do with ZM settings option, currently set to none |
The following is a total random guess based on some other cakephp weirdness I observed today. Try setting Cake's debug back to 2 in your core.php file: Apparently the debug variable controls much more than the verbosity of cake's output. |
@knnniggett, doesn't change a thing :) The only things that the debug level changes (In CakePHP 2.x) is the amount of information reported, how much detail is in error messages, and how long schema caching is (10 seconds instead of 1000 days). Source: I'm a CakePHP core developer :) I have absolutely zero idea what could possibly be causing this issue though, and why it's only on that one controller. |
@dakota Turning off debug does indeed do more than lower the verbosity of cake's output. It also stops cakephp from creating several folders under the tmp folder. Perhaps you already know, this is by design: If debug is off and the folders mentioned in that thread don't already exist, then cake will throw an error, rather than create them during runtime. I didn't mention that because this particular thread isn't about the cake tmp folders, nor do we need to discuss the "why" behind this. It is what it is. Since no one yet knows the root cause of the problem described here, I'm simply going back through our recent commits to see what was touched last. We didn't change much relating to the zoneminder API, but one recent change was to set cake debug from 2 -> 0. |
@knnniggett You'll notice that's for CakePHP 3.1, only applies for the File Log and File cache engines, and not for sessions (And can only be a problem when using CakePHP to handle sessions). In this case Zoneminder is using the default php session handler. This problem manifests itself regardless of the value of |
No, the problem manifests itself only with debug set to 0. This is very easy to duplicate so I encourage you try it yourself. These errors appear in the logs with debug set to 0:
I've seen additional errors reporting other folders such as cache/models and logs are not writeable as well. What we did is add the cake cache folders to the tmpfiles.d service to ensure all of cake's tmp folder exist and are owned by the web account user: If you have a better idea, then please let us know. |
@knnniggett That's not the problem being discussed in this issue though. This issue is about api requests to As for the tmp file issue, the options are
Ideally, the api should be upgraded to CakePHP 3 and leverage the CRUD plugin's api functionality (Which now includes JSON API support). I'll see if I can do that sometime soon if I can find myself some time! |
Thanks for the help, and I understand the time factor (or lack thereof). The original author of the zoneminder API hasn't been very active with the project. This has left us in a bit of a knowledge gap when it comes to problems requiring a strong familiarity with cakephp. And yes, this is a shameless attempt at asking for help from anyone who might read this. |
if someone who is facing this problem is able to get me SSH access to his/her instance, I'll debug it and spend time. Without access to an instance that has this problem, its near impossible for me to even try. |
I believe I am experiencing the issue if you'd like to look at it? I'm using zoneminder 1.30.4 running on Centos 6.9 installed from repository |
I have this error when I call the API
Additional to this... I have other error when I call the same endpoint and maybe the zm.conf wan't parse o load the ZM_* variables, so... I replace all the ZM_* variables in database.php and the error disapear. This last one I can't handle :( any workarround? Some additional info: OS: Debian stretch |
I mistakenly closed this issue out yesterday. @pcollaog The particular API error you are experiencing is not the same issue reported in this thread. Since we were unsuccessful yesterday in our IRC channel, you might want to try building your own zoneminder package. There are couple documented ways to do that, which are shown here: Please contact me in our IRC channel for further details. In the long run, I do hope you file a bug report against the package your are using. The package maintainer needs to get involved to fix the root cause. |
I also had this issue until yesterday. I could login to Zoneminder using it's built-in method, but calling a the version api resulted in not authorised every time. In my case I as overwrote the default php setting: output_buffering in global apache php.ini (the reason for this was for another web app - pydio - running on same server). I set this back to default 4096, and no more issues with API or zmninja iPhone app. |
AFAICT the extra whitespace in Models/Host.php was causing PHP to prematurely output to the browser and thus interfering with the sessions or HTTP headers. |
Interesting. I have the same space in my host.php Model but I don't have this issue. But if it solves the issue for those who are facing it, I'm not complaining. |
There seems to be an increasing number of people who are reporting issues that a part of the APIs are failing when authentication is enabled. Specifically, everything under the
/host/
route fails with a 401.See here for help needed to debug this issue.
Occurrence
Seems to be only on some systems. Don't have a pattern yet
Steps to reproduce
a) login to ZM (OPT_AUTH is on) using a browser, Open a new tab
b) Go to
http://server/zm/api
- shows greenc) Go to
http://server/zm/api/monitors.json,
/events.json
etc all checkout fine - they return valid JSON datad) Go to
http://server/zm/api/host/getVersion.json
and pretty much any/host/XXXX.json
function returns401 Not authenticated
I don't have a sense on what exactly is causing this - whether its an OS version problem, a Cake PHP problem, a PHP problem, a webserver config problem or something else.
Why its failing - the cause (but not root cause)
What we did figure out is the reason this happens is because the HostController.php file gets an empty Session Object, while all other Controllers get a valid session object. The API auth layer relies on the Session object to validate if you have logged in.
Why is the Session vars empty just for this one controller, I haven't a clue. I am setting up this thread so that I can invite folks who are facing this problem to report their OS/cake/PHP versions and see if we can debug something. I'll soon be tagging folks to contribute.
Temporary Workaround (has security issues, see below)
The workaround, for now is this: disable Auth checking on HostController. This will however expose the following details to any user who can access your server (as there is no auth in this controller). Note that you can keep Basic Auth enabled - it will continue to work and will honor basic auth. The problem is only with ZM Auth, for those who are affected.
a) API version
b) System load
c) Your server Time Zone (only applicable for ZM 1.30.2 and above)
d) disk percent (used/free) on a per monitor basis (this API also slows your system down significantly in addition to exposing your list of monitor names. You can comment out this function - see note below)
Note - if you are facing this problem, you can completely comment out the getDiskPercent API in HostController.php to remove open access. zmNinja does not use this API and neither does ZoneMinder - so there is no functionality loss
The workaround code is to modify HostController.php inside
api/app/controller/
and add thepublic function beforeFilter(){}
code just below theclass HostController extends AppController
line like so:The text was updated successfully, but these errors were encountered: