Clean Install API Permission Issues

Forum for questions and support relating to the 1.29.x releases only.
elvisimprsntr
Posts: 14
Joined: Sat Feb 06, 2016 9:35 am

Clean Install API Permission Issues

Post by elvisimprsntr »

BACKGROUND

Running ZM 1.29.0

Clean install on Kubuntu 15.10 following guides here: Steps at Making sure ZM and APIs work:
  • Configured my cameras and confirmed live streams.
    Optional API check results in the following error message:

Code: Select all

Warning: mkdir(): Permission denied in /usr/share/zoneminder/www/api/lib/Cake/Cache/Engine/FileEngine.php on line 379

Warning: _cake_core_ cache was unable to write 'cake_dev_en-us' to File cache in /usr/share/zoneminder/www/api/lib/Cake/Cache/Cache.php on line 323

Warning: /usr/share/zoneminder/www/api/app/tmp/cache/persistent/ is not writable in /usr/share/zoneminder/www/api/lib/Cake/Cache/Engine/FileEngine.php on line 384

Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured.' in /usr/share/zoneminder/www/api/lib/Cake/Cache/Cache.php:181 Stack trace: #0 /usr/share/zoneminder/www/api/lib/Cake/Cache/Cache.php(151): Cache::_buildEngine('_cake_core_') #1 /usr/share/zoneminder/www/api/app/Config/core.php(376): Cache::config('_cake_core_', Array) #2 /usr/share/zoneminder/www/api/lib/Cake/Core/Configure.php(72): include('/usr/share/zone...') #3 /usr/share/zoneminder/www/api/lib/Cake/bootstrap.php(175): Configure::bootstrap(true) #4 /usr/share/zoneminder/www/api/app/webroot/index.php(94): include('/usr/share/zone...') #5 /usr/share/zoneminder/www/api/index.php(41): require('/usr/share/zone...') #6 {main} thrown in /usr/share/zoneminder/www/api/lib/Cake/Cache/Cache.php on line 181
Directory/file permissions

Code: Select all

usr/share/zoneminder/www/api/lib/Cake/Cache/Engine
-rw-r--r-- 1 root root  5804 Feb  4 12:04 XcacheEngine.php
-rw-r--r-- 1 root root  5309 Feb  4 12:04 WincacheEngine.php
-rw-r--r-- 1 root root  6147 Feb  4 12:04 RedisEngine.php
-rw-r--r-- 1 root root  8213 Feb  4 12:04 MemcacheEngine.php
-rw-r--r-- 1 root root  9651 Feb  4 12:04 MemcachedEngine.php
-rw-r--r-- 1 root root 11354 Feb  4 12:04 FileEngine.php
-rw-r--r-- 1 root root  5116 Feb  4 12:04 ApcEngine.php



/usr/share/zoneminder/www/api/lib/Cake/Cache
-rw-r--r--  1 root root 18202 Feb  4 12:04 Cache.php
-rw-r--r--  1 root root  4825 Feb  4 12:04 CacheEngine.php
drwxr-xr-x  2 root root  4096 Feb  5 21:53 Engine


/usr/share/zoneminder/www/api/lib/Cake
-rw-r--r--  1 root root  1028 Feb  4 12:04 VERSION.txt
-rw-r--r--  1 root root 14354 Feb  4 12:04 bootstrap.php
-rw-r--r--  1 root root 24209 Feb  4 12:04 basics.php
drwxr-xr-x  6 root root  4096 Feb  5 21:53 Test
drwxr-xr-x  4 root root  4096 Feb  5 21:53 Routing
drwxr-xr-x  2 root root  4096 Feb  5 21:53 Error
drwxr-xr-x  2 root root  4096 Feb  5 21:53 Utility
drwxr-xr-x  3 root root  4096 Feb  5 21:53 Cache
drwxr-xr-x  2 root root  4096 Feb  5 21:53 Configure
drwxr-xr-x  6 root root  4096 Feb  5 21:53 TestSuite
drwxr-xr-x  2 root root  4096 Feb  5 21:53 I18n
drwxr-xr-x  2 root root  4096 Feb  5 21:53 Event
drwxr-xr-x  4 root root  4096 Feb  5 21:53 Console
drwxr-xr-x  6 root root  4096 Feb  5 21:53 View
drwxr-xr-x  2 root root  4096 Feb  5 21:53 Core
drwxr-xr-x  3 root root  4096 Feb  5 21:53 Config
drwxr-xr-x  4 root root  4096 Feb  5 21:53 Network
drwxr-xr-x  5 root root  4096 Feb  5 21:53 Model
drwxr-xr-x  3 root root  4096 Feb  5 21:53 Controller
drwxr-xr-x  3 root root  4096 Feb  5 21:53 Log
QUESTIONS

Do these files need to have a different owner:group or execute permission?

Or is there something I missed or need to check?

Thanks in advance,

Elvis
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Clean Install API Permission Issues

Post by asker »

Code: Select all

sudo chown -R www-data:www-data /usr/share/zoneminder/api
I'm a little surprised why the package did not do this, since you are following the package instructions
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
elvisimprsntr
Posts: 14
Joined: Sat Feb 06, 2016 9:35 am

Re: Clean Install API Permission Issues

Post by elvisimprsntr »

asker wrote:

Code: Select all

sudo chown -R www-data:www-data /usr/share/zoneminder/api
I'm a little surprised why the package did not do this, since you are following the package instructions
Correction to command:

Code: Select all

sudo chown -R www-data:www-data /usr/share/zoneminder/www/api
The only reason I can think of is the step to add the user:group is currently listed after one installs zoneminder, thus might default to root:root because the user:group does not exist. Likely a regression test escape.

Code: Select all

adduser www-data video
Unfortunately, it did not completely solve the problem. After restarting both ZM and apache2, I opened the ZM console to make sure I was authenticated, then I tried to access the API URL check as per the instructions and got the following response:

Code: Select all

CakePHP: the rapid development php framework

Not Authenticated

Error: The requested address '/zm/api/' was not found on this server.

Stack Trace

[internal function] → AppController->beforeFilter(CakeEvent)
CORE/Cake/Event/CakeEventManager.php line 244 → call_user_func(array, CakeEvent)
CORE/Cake/Controller/Controller.php line 674 → CakeEventManager->dispatch(CakeEvent)
CORE/Cake/Routing/Dispatcher.php line 187 → Controller->startupProcess()
CORE/Cake/Routing/Dispatcher.php line 165 → Dispatcher->_invoke(PagesController, CakeRequest)
APP/webroot/index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)
ROOT/index.php line 41 → require(string)
CakePHP: the rapid development php framework
CakePHP 2.5.0-RC1

(default) 4 queries took 1 ms
Nr	Query	Error	Affected	Num. rows	Took (ms)
1	SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config` WHERE `Config`.`Name` = 'ZM_OPT_USE_API' LIMIT 1		1	1	0
2	SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config` WHERE `Config`.`Name` = 'ZM_OPT_USE_AUTH' LIMIT 1		1	1	0
3	SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config` WHERE `Config`.`Name` = 'ZM_OPT_USE_API' LIMIT 1		1	1	1
4	SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config` WHERE `Config`.`Name` = 'ZM_OPT_USE_AUTH' LIMIT 1		1	1	0
Last edited by elvisimprsntr on Sat Feb 06, 2016 1:00 pm, edited 1 time in total.
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Clean Install API Permission Issues

Post by asker »

Okay, this problem is more fundamental.Looks like you are using the most recent 1.29-stable ppa that iconnor just released right?
I haven't tried it yet so I'm going to have to try this myself, which I'll do later today.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
bbunge
Posts: 2956
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Clean Install API Permission Issues

Post by bbunge »

Thought I had seen this before...

In my upgrade instructions for Ubuntu 15.10 I have:

chown -R www-data:www-data /usr/share/zoneminder/

Will add this to the install instructions. Does no harm if it precludes issues...

bb
elvisimprsntr
Posts: 14
Joined: Sat Feb 06, 2016 9:35 am

Re: Clean Install API Permission Issues

Post by elvisimprsntr »

asker wrote:Okay, this problem is more fundamental.Looks like you are using the most recent 1.29-stable ppa that iconnor just released right?
I haven't tried it yet so I'm going to have to try this myself, which I'll do later today.
I installed ZM 1.29.0 at 21:53 PM EST last night, after installing Kubuntu 15.10 on a replacement hard drive. My old drive started reporting seek and read errors, and RW performance was down. I had been running 1.28.2 on Kubuntu 15.04. Didn't realize there was a new release last night.
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Clean Install API Permission Issues

Post by asker »

I just installed iconnors new 1.29 PPA
Please follow these instructions exactly https://github.com/pliablepixels/zmNinj ... om-Package

I had no problems getting APIs to work (and as it turns out, I did have the chown instructions as part of my instructions)
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
elvisimprsntr
Posts: 14
Joined: Sat Feb 06, 2016 9:35 am

Re: Clean Install API Permission Issues

Post by elvisimprsntr »

asker wrote:I just installed iconnors new 1.29 PPA
Please follow these instructions exactly https://github.com/pliablepixels/zmNinj ... om-Package

I had no problems getting APIs to work (and as it turns out, I did have the chown instructions as part of my instructions)

Getting different response now, but still not working. I have builtin authentication enabled. I had made sure to have successfully logged into the console before attempting to hit the CakePHP page.

Code: Select all

CakePHP: the rapid development php framework

Not Authenticated
Error: The requested address '/zm/api/' was not found on this server.

Stack Trace
[internal function] → AppController->beforeFilter(CakeEvent)
CORE/Cake/Event/CakeEventManager.php line 244 → call_user_func(array, CakeEvent)
CORE/Cake/Controller/Controller.php line 674 → CakeEventManager->dispatch(CakeEvent)
CORE/Cake/Routing/Dispatcher.php line 187 → Controller->startupProcess()
CORE/Cake/Routing/Dispatcher.php line 165 → Dispatcher->_invoke(PagesController, CakeRequest)
APP/webroot/index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)
CakePHP: the rapid development php framework
CakePHP 2.5.0-RC1

(default) 4 queries took 1 ms
Nr	Query	Error	Affected	Num. rows	Took (ms)
1	SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config` WHERE `Config`.`Name` = 'ZM_OPT_USE_API' LIMIT 1		1	1	0
2	SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config` WHERE `Config`.`Name` = 'ZM_OPT_USE_AUTH' LIMIT 1		1	1	0
3	SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config` WHERE `Config`.`Name` = 'ZM_OPT_USE_API' LIMIT 1		1	1	1
4	SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config` WHERE `Config`.`Name` = 'ZM_OPT_USE_AUTH' LIMIT 1		1	1	0

The only way i could get the CakePHP page to come up was to disable builtin authentication, and reload ZM and apache2. The instructions seem to imply this will work and suggest testing after enabling authentication.

Code: Select all


CakePHP: the rapid development php framework


Release Notes for CakePHP 2.5.0-RC1.

Read the changelog  




Your version of PHP is 5.2.8 or higher.


Your tmp directory is writable.


The FileEngine is being used for core caching. To change the config edit APP/Config/core.php


Your database configuration file is present.


CakePHP is able to connect to the database.


DebugKit is not installed. It will help you inspect and debug different aspects of your application.
You can install it from GitHub

Editing this Page

To change the content of this page, edit: APP/View/Pages/home.ctp.
 To change its layout, edit: APP/View/Layouts/default.ctp.
 You can also add some CSS styles for your pages at: APP/webroot/css.

Getting Started

New CakePHP 2.0 Docs

The 15 min Blog Tutorial

Official Plugins


• DebugKit: provides a debugging toolbar and enhanced debugging tools for CakePHP applications. 
• Localized: contains various localized validation classes and translations for specific countries 


More about CakePHP

CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Active Record, Association Data Mapping, Front Controller and MVC.

Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility.
•CakePHP ◦The Rapid Development Framework

•CakePHP Documentation  ◦Your Rapid Development Cookbook

•CakePHP API  ◦Quick API Reference

•The Bakery  ◦Everything CakePHP

•CakePHP Plugins  ◦A comprehensive list of all CakePHP plugins created by the community

•CakePHP Community Center  ◦Everything related to the CakePHP community in one place

•CakePHP Google Group  ◦Community mailing list

•irc.freenode.net #cakephp ◦Live chat about CakePHP

•CakePHP Code  ◦Find the CakePHP code on GitHub and contribute to the framework

•CakePHP Issues  ◦CakePHP Issues

•CakePHP Roadmaps  ◦CakePHP Roadmaps

•Training  ◦Join a live session and get skilled with the framework

•CakeFest  ◦Don't miss our annual CakePHP conference

•Cake Software Foundation  ◦Promoting development related to CakePHP


CakePHP: the rapid development php framework	
CakePHP 2.5.0-RC1 

(default) 2 queries took 0 ms


Nr

Query

Error

Affected

Num. rows

Took (ms)


1 SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config` WHERE `Config`.`Name` = 'ZM_OPT_USE_API' LIMIT 1  1 1 0 
2 SELECT `Config`.`Id`, `Config`.`Name`, `Config`.`Value`, `Config`.`Type`, `Config`.`DefaultValue`, `Config`.`Hint`, `Config`.`Pattern`, `Config`.`Format`, `Config`.`Prompt`, `Config`.`Help`, `Config`.`Category`, `Config`.`Readonly`, `Config`.`Requires` FROM `zm`.`Config` AS `Config` WHERE `Config`.`Name` = 'ZM_OPT_USE_AUTH' LIMIT 1  
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Clean Install API Permission Issues

Post by asker »

What do you mean by built in authentication? OPT_USE_AUTH in ZM or something else?

I have OPT_USE_AUTH enabled too. I installed on a clean Ubuntu 15 system
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
elvisimprsntr
Posts: 14
Joined: Sat Feb 06, 2016 9:35 am

Re: Clean Install API Permission Issues

Post by elvisimprsntr »

asker wrote:What do you mean by built in authentication? OPT_USE_AUTH in ZM or something else?

I have OPT_USE_AUTH enabled too. I installed on a clean Ubuntu 15 system
Yes.

OPT_USE_AUTH enabled
AUTH_TYPE builtin
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Clean Install API Permission Issues

Post by asker »

To be clear we are on the same page:

a) The API ties into ZM auth. If you have ZM auth (OPT_USE_AUTH) enabled in ZM, the APIs will require you to logging into ZM first and will work only from the same browser instance

b) If you have ZM auth disabled (which is default when you install a fresh package) just going to localhost/zm/api/host/getVersion.json should work

c) Please make sure you have "sudo a2enmod rewrite" done - its easy to miss. It's likely you have but please double check and restart apache

d) The routing is managed by 3 htaccess files which contain the following identical code:

Code: Select all

pp@ubuntu:/usr/share/zoneminder/www/api$ cat .htaccess 
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^$ app/webroot/ [L]
   RewriteRule (.*) app/webroot/$1 [L]
   RewriteBase /zm/api
</IfModule>

Code: Select all

pp@ubuntu:/usr/share/zoneminder/www/api/app$ cat .htaccess 
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
    RewriteBase /zm/api
</IfModule>

Code: Select all

pp@ubuntu:/usr/share/zoneminder/www/api/app/webroot$ cat .htaccess 
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    RewriteBase /zm/api
</IfModule>
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
elvisimprsntr
Posts: 14
Joined: Sat Feb 06, 2016 9:35 am

Re: Clean Install API Permission Issues

Post by elvisimprsntr »

asker wrote:To be clear we are on the same page:

a) The API ties into ZM auth. If you have ZM auth (OPT_USE_AUTH) enabled in ZM, the APIs will require you to logging into ZM first and will work only from the same browser instance

b) If you have ZM auth disabled (which is default when you install a fresh package) just going to localhost/zm/api/host/getVersion.json should work

c) Please make sure you have "sudo a2enmod rewrite" done - its easy to miss. It's likely you have but please double check and restart apache

d) The routing is managed by 3 htaccess files which contain the following identical code:
a. Understood and I have been making sure to log into the admin console first and open a new tab. I have tried on both Mac OS Safari and Windows 7 Explorer. Both result in same error.

b. With OPT_USE_AUTH disabled, I can hit the API version page.

Code: Select all

{
    "version": "1.29.0",
    "apiversion": "1.0"
}
c. I had previously performed that step, but checked anyway

Code: Select all

Module rewrite already enabled
d. All three .htaccess files are identical to the ones you posted.


What should I look for next?
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Clean Install API Permission Issues

Post by asker »

I'm a little stumped. Any chance I can get access to your instance? If so, please shoot me an email at pliablepixels at gmail
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Clean Install API Permission Issues

Post by asker »

What's confusing me is why you are getting a /zm/api not found error if you turn on auth. It should at worst, return a 404 Not authenticated. In your case it seems like htaccess stops working if you enable OPT_USE_AUTH which I can't seem to correlate.

Would you mind trying from a different browser? Which browser are you using now?
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
elvisimprsntr
Posts: 14
Joined: Sat Feb 06, 2016 9:35 am

Re: Clean Install API Permission Issues

Post by elvisimprsntr »

asker wrote:What's confusing me is why you are getting a /zm/api not found error if you turn on auth. It should at worst, return a 404 Not authenticated. In your case it seems like htaccess stops working if you enable OPT_USE_AUTH which I can't seem to correlate.

Would you mind trying from a different browser? Which browser are you using now?

I've tried Safari and Explorer. Sent TeamViewer Invitation
Locked