Page 1 of 2

PHP7 issues with ZM API (due to bundled CakePHP 2.5-RC)

Posted: Mon Feb 15, 2016 10:38 pm
by felixita
(Original title was zmNinja error - Edited title to reflect true problem - this might start showing up for other users too - asker )

Hy, i'm using ZM 1.29 in my Arch linux. All work well, but i've a problem only with zm-ninja app. My Android App, but is the same for desktop version, fail streaming video. In zmninja app (or desktop) my credentials are verify. If i click on "system status" it show "Zoneminder is runnig" and i can see zm load. The problem appear if i make a click on Monitor or Events or Montage: a popup say to check credentials!.
I've googled for zm-ninja wiki and forum but i don't have found a solution. I've checked cgi-bin path and permission, but all seem alright. If i try to use another zm app like ZmView all work well and i can see all monitors and events.


Anyone can help me with zm-ninja? Below is a part of zm-ninja log file.

Thanks!

Code: Select all

version:1.0.7D

Feb 15, 2016 11:32:52 PM ERROR Monitor load failed {"success":false,"data":{"code":500,"name":"Cannot declare class CakeText, because the name is already in use","message":"Cannot declare class CakeText, because the name is already in use","url":"/zoneminder/api/monitors.json","exception":{"class":"FatalErrorException","code":500,"message":"Cannot declare class CakeText, because the name is already in use","trace":["#0 /srv/http/zoneminder/api/lib/Cake/Error/ErrorHandler.php(203): ErrorHandler::handleFatalError(64, 'Cannot declare ...', '/srv/http/zonem...', 25)","#1 /srv/http/zoneminder/api/lib/Cake/Core/App.php(929): ErrorHandler::handleError(64, 'Cannot declare ...', '/srv/http/zonem...', 25, Array)","#2 /srv/http/zoneminder/api/lib/Cake/Core/App.php(902): App::_checkFatalError()","#3 [internal function]: App::shutdown()","#4 {main}"]},"queryLog":{"default":{"log":[{"query":"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","params":[],"affected":1,"numRows":1,"took":0},{"query":"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","params":[],"affected":1,"numRows":1,"took":0},{"query":"SELECT `User`.`Id`, `User`.`Username`, `User`.`Password`, `User`.`Language`, `User`.`Enabled`, `User`.`Stream`, `User`.`Events`, `User`.`Control`, `User`.`Monitors`, `User`.`Groups`, `User`.`Devices`, `User`.`System`, `User`.`MaxBandwidth`, `User`.`MonitorIds` FROM `zm`.`Users` AS `User`   WHERE `User`.`Username` = 'admin'    LIMIT 1","params":[],"affected":1,"numRows":1,"took":0},{"query":"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","params":[],"affected":1,"numRows":1,"took":0},{"query":"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","params":[],"affected":1,"numRows":1,"took":0},{"query":"SELECT `User`.`Id`, `User`.`Username`, `User`.`Password`, `User`.`Language`, `User`.`Enabled`, `User`.`Stream`, `User`.`Events`, `User`.`Control`, `User`.`Monitors`, `User`.`Groups`, `User`.`Devices`, `User`.`System`, `User`.`MaxBandwidth`, `User`.`MonitorIds` FROM `zm`.`Users` AS `User`   WHERE `User`.`Username` = 'admin'    LIMIT 1","params":[],"affected":1,"numRows":1,"took":0}],"count":6,"time":0}}}}
Feb 15, 2016 11:32:52 PM INFO getMonitors:Loading all monitors
Feb 15, 2016 11:29:59 PM INFO ZM has recaptcha disabled - good
Feb 15, 2016 11:29:59 PM INFO Stream authentication construction: 
Feb 15, 2016 11:29:59 PM INFO Deferring auth key, as monitorId unknown
Feb 15, 2016 11:29:59 PM INFO zmAutologin successfully logged into Zoneminder
Feb 15, 2016 11:29:59 PM INFO Checking if reCaptcha is enabled in ZM...
Feb 15, 2016 11:29:59 PM INFO zmAutologin called

Re: zm-ninja monitor error

Posted: Mon Feb 15, 2016 10:57 pm
by asker
Hi there, please post zmNinja questions in the mobile forum (even if its the desktop port). This is only for ZM 1.29

Having said that, your post seems to indicate the problem is not with zmNinja - its with the APIs in ZM. So from that perspective, this post is fine to stay here.

Let's step back a bit and forget zmNinja:

1. Open up your ZM browser, login to the console
2. Open up another tab in the same browser and do a http://server/zm/api/monitors.json

what do you see?

Re: zm-ninja monitor error

Posted: Mon Feb 15, 2016 11:03 pm
by felixita
if can be useful, my system have CakePHP 2.5.0-RC1 and php 7.0. Also i have attached my http://zoneminderip/api page.

Re: zm-ninja monitor error

Posted: Mon Feb 15, 2016 11:05 pm
by asker
I think the problem is PHP 7. Please post the output of http://server/zm/api/monitors.json

Re: zm-ninja monitor error

Posted: Mon Feb 15, 2016 11:06 pm
by felixita
i can see this in http://192.168.88.10/zoneminder/api/monitors.json

Code: Select all

{
    "success": false,
    "data": {
        "code": 500,
        "name": "Cannot declare class CakeText, because the name is already in use",
        "message": "Cannot declare class CakeText, because the name is already in use",
        "url": "\/zoneminder\/api\/monitors.json",
        "exception": {
            "class": "FatalErrorException",
            "code": 500,
            "message": "Cannot declare class CakeText, because the name is already in use",
            "trace": [
                "#0 \/srv\/http\/zoneminder\/api\/lib\/Cake\/Error\/ErrorHandler.php(203): ErrorHandler::handleFatalError(64, 'Cannot declare ...', '\/srv\/http\/zonem...', 25)",
                "#1 \/srv\/http\/zoneminder\/api\/lib\/Cake\/Core\/App.php(929): ErrorHandler::handleError(64, 'Cannot declare ...', '\/srv\/http\/zonem...', 25, Array)",
                "#2 \/srv\/http\/zoneminder\/api\/lib\/Cake\/Core\/App.php(902): App::_checkFatalError()",
                "#3 [internal function]: App::shutdown()",
                "#4 {main}"
            ]
        },
        "queryLog": {
            "default": {
                "log": [
                    {
                        "query": "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",
                        "params": [],
                        "affected": 1,
                        "numRows": 1,
                        "took": 0
                    },
                    {
                        "query": "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",
                        "params": [],
                        "affected": 1,
                        "numRows": 1,
                        "took": 0
                    },
                    {
                        "query": "SELECT `User`.`Id`, `User`.`Username`, `User`.`Password`, `User`.`Language`, `User`.`Enabled`, `User`.`Stream`, `User`.`Events`, `User`.`Control`, `User`.`Monitors`, `User`.`Groups`, `User`.`Devices`, `User`.`System`, `User`.`MaxBandwidth`, `User`.`MonitorIds` FROM `zm`.`Users` AS `User`   WHERE `User`.`Username` = 'admin'    LIMIT 1",
                        "params": [],
                        "affected": 1,
                        "numRows": 1,
                        "took": 0
                    },
                    {
                        "query": "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",
                        "params": [],
                        "affected": 1,
                        "numRows": 1,
                        "took": 0
                    },
                    {
                        "query": "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",
                        "params": [],
                        "affected": 1,
                        "numRows": 1,
                        "took": 0
                    },
                    {
                        "query": "SELECT `User`.`Id`, `User`.`Username`, `User`.`Password`, `User`.`Language`, `User`.`Enabled`, `User`.`Stream`, `User`.`Events`, `User`.`Control`, `User`.`Monitors`, `User`.`Groups`, `User`.`Devices`, `User`.`System`, `User`.`MaxBandwidth`, `User`.`MonitorIds` FROM `zm`.`Users` AS `User`   WHERE `User`.`Username` = 'admin'    LIMIT 1",
                        "params": [],
                        "affected": 1,
                        "numRows": 1,
                        "took": 0
                    }
                ],
                "count": 6,
                "time": 0
            }
        }
    }
}

Re: zm-ninja monitor error

Posted: Mon Feb 15, 2016 11:09 pm
by asker
Okay, so this confirms your problem is the APIs, not zmNinja - the APIs seem to be incompatible with PHP7. I see this "Cannot use X because the name is already in use" to be a common PHP 7 issue (see https://github.com/osTicket/osTicket-1.8/issues/2819 for example)

I don't have a solution right now - do you have another environment to deploy ZoneMinder what uses PHP 5.x?

Re: zm-ninja monitor error

Posted: Mon Feb 15, 2016 11:18 pm
by felixita
Infact during installation i had used CakeText class instead of String in my zoneminder/api/lib/Cake/Utility/String.php (in accord with this https://github.com/cakephp/cakephp/issues/7573).

No, now i don't have other environment.

Thanks a lot, maybe an update will solve this issue.

Re: zm-ninja monitor error

Posted: Mon Feb 15, 2016 11:23 pm
by asker
I'm not sure I understand. What exactly did you change when installing the APIs and why?

Re: zm-ninja monitor error

Posted: Mon Feb 15, 2016 11:29 pm
by asker
So it looks like ZM packages Cake 2.5 while PHP7 needs 2.8. the version that is packaged with ZM lies in www/api/lib

Re: zm-ninja monitor error

Posted: Mon Feb 15, 2016 11:34 pm
by felixita
I've only substitute in zoneminder/api/lib/Cake/Utility/String.php:

Class String {....
with
Class CakeText {...

Re: zm-ninja monitor error

Posted: Mon Feb 15, 2016 11:47 pm
by asker
Okay, so I don't have a PHP7 environment, but give this a try (I don't know if it will work)

Code: Select all

cd /usr/share/zoneminder/api/lib
mv Cake Cake_old
git clone -b 2.x git://github.com/cakephp/cakephp.git
ln -s cakephp/lib/Cake/ .
Then try the API

If it doesn't work, we may have to upgrade the cakephp version using the upgrade tool

Re: PHP7 issues with ZM API (due to bundled CakePHP 2.5-RC)

Posted: Tue Feb 16, 2016 9:09 am
by felixita
i've tryed 2.8.0 but i got errors (view attachment of http://zoneminderaddress/api and http://zoneminderadress/api/monitors.json)

Re: PHP7 issues with ZM API (due to bundled CakePHP 2.5-RC)

Posted: Tue Feb 16, 2016 12:45 pm
by felixita
I've tried also with cakephp 2.7.8 installed by AUR repository but yet an error as you can see. Any ideas?

Re: PHP7 issues with ZM API (due to bundled CakePHP 2.5-RC)

Posted: Tue Feb 16, 2016 2:18 pm
by asker
Are you familiar with using cakephp upgrade tool?
http://book.cakephp.org/3.0/en/upgrade-tool.html

I don't know how to use it - just throwing it out there - I need to get a PHP7 env

Re: PHP7 issues with ZM API (due to bundled CakePHP 2.5-RC)

Posted: Tue Feb 16, 2016 8:02 pm
by felixita
Ok, i've upgrade to cakephp 3.2 but... same problem: when i go to http://zmip/api i got a page which say:
Please change the value of 'Security.salt' in ROOT/config/app.php to a salt value specific to your application. [CORE/src/Error/Debugger.php, line 791].

I don't have enough experience to solve this. Maybe It has to do with secret encoding hashed authentication?