Set function from API does not work

Forum for questions and support relating to the 1.28.x releases only.
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

I did a fresh Install of Ubuntu 15.04 and following guide from bbunge without any kind of error I installed Zoneminder. ZM works, but API not.
Error is the same:

Not Found
The requested URL /zm/api/host/getVersion.json was not found on this server.
Apache/2.4.10 (Ubuntu) Server at 192.168.1.224 Port 80

I'm waiting for debian guide

Thanks
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Set function from API does not work

Post by bbunge »

Yup, you will get that error. Looks like the Debian and Ubuntu API set up will be the same. Wait for it...
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Set function from API does not work

Post by bbunge »

The "Official" Configuring ZoneMinder with API is loacted at: https://github.com/pliablepixels/zmNinj ... r-with-API

This is not a detailed how to as the code is still in the works. I was able to get this to work on Ubuntu 15.04 with Zoneminder from the master PPA and Debian 8.2 with the api directory copied from the Ubuntu install. You should be able to grab the latest Zoneminder API from Github. I've tried to attach the zip file of the API directory to this...

Install cakephp

apt-get install cakephp

Enable rewrite

a2enmod rewrite

Edit apache2.conf Change "None" to "All" in two places:

<Directory /usr/share>
AllowOverride All
Require all granted
</Directory>

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Add the following to apache2.conf
<Directory /usr/local/share>
AllowOverride None
Require all granted
</Directory>

<Directory /usr/local/libexec/zoneminder/cgi-bin>
AllowOverride None
Require all granted
</Directory>

Change owner of: /usr/share/zoneminder/www sub directories and files to: www-data:www-data

You may have to edit /usr/share/zoneminder/www/api/app/Config/core.php per https://github.com/pliablepixels/zmNinj ... r-with-API

Test using: http://localhost/zm/api/host/getVersion.json

Check to see if cake is working http://localhost/zm/api/
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi bbunge,
grat job. I got ZM and API working on Ubuntu 15.04.
In next days, i move all my config to new version.

I have a question about native authentication with API.
I call API with curl command from another server. Is there a way to authenticate, or grant access only to this server's IP?

Reagrds
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi,
I ported all of my camera to new installation. I enabled ZM authentication, but seems API page still without authentication.
I have to publish on internet my ZM installation, and I need to enable authentication.

Thanks for help.

Regards

Marco
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

Did you follow this part of the guide at https://github.com/pliablepixels/zmNinj ... r-with-API

Code: Select all

Edit /usr/share/zoneminder/www/api/app/Config/core.php Around line 218 you will see this:

       Configure::write('Session', array(
                'defaults' => 'php'

       ));
change it to

  Configure::write('Session', array(
                'defaults' => 'php',
               'cookie'=>'ZMSESSID'
       ));
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
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

asker wrote:Did you follow this part of the guide at

Code: Select all

Edit /usr/share/zoneminder/www/api/app/Config/core.php Around line 218 you will see this:

       Configure::write('Session', array(
                'defaults' => 'php'

       ));
change it to

  Configure::write('Session', array(
                'defaults' => 'php',
               'cookie'=>'ZMSESSID'
       ));

Sure, i did this step.

Marco
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Set function from API does not work

Post by bbunge »

Did you copy the API files from the Ubuntu install? I seem to remember you were going to Debian. I was not able to get API to work on Debian without the newest API files.

bb
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi bbunge,
I'm on Ubuntu 15.04, for now I discarded Debian until it will be fully supported.

Marco
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Set function from API does not work

Post by bbunge »

If I understand you correctly you want to put output from your Zoneminder server on another web page? And you are concerned that there is no way, yet, to authenticate API output? If this is the case there is a way to do what you want without API.

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

Re: Set function from API does not work

Post by asker »

Marco, please do the following:

1. Please restart your ubuntu server

2. Open up a browser, log into ZM. Open up a new tab in the same browser and please paste the response you get for
(replace server) - I'd like to see the exact message

3. Open up ZM, disable authentication (uncheck OPT_AUTH) and then try the same step as 1, please let me know if it works

4. Finally, can you check your apache access.log and error.log (typically in /var/log/apache2) to see if any PHP related errors show up when you are accessing the APIs?
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: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Set function from API does not work

Post by bbunge »

Fresh install of 15.04 with ZM from PPA-Master

Below same with OPT_AUTH on or off
{
"version": "1.28.106",
"apiversion": "1.28.106.1"
}


From Apache error log after a reboot and test with http://server/zm/api/host/getVersion.json
[Mon Sep 21 15:20:50.367470 2015] [:error] [pid 1369] [client 192.166.xxx.xxx:60338] PHP Notice: Undefined index: object in /usr/share/zoneminder/www/includes/actions.php on line 739, referer: http://192.168.xxx.xxx/zm/
[Mon Sep 21 15:22:01.405526 2015] [:error] [pid 1396] [client 192.168.xxx.xxx:60361] PHP Notice: Undefined index: object in /usr/share/zoneminder/www/includes/actions.php on line 739, referer: http://192.168.xxx.xxx/zm/index.php?view=options
bbunge
Posts: 2934
Joined: Mon Mar 26, 2012 11:40 am
Location: Pennsylvania

Re: Set function from API does not work

Post by bbunge »

Did a reinstall and followed my instructions this time!

Prior to turning OPT_AUTH on I ran http://server/zm/api/host/getVersion.json which returned:
{
"version": "1.28.106",
"apiversion": "1.28.106.1"
}

With a user set and OPT_AUTH turned on and the server rebooted, http://server/zm/api/host/getVersion.json returned:
{
"success": false,
"data": {
"name": "Not Authenticated",
"message": "Not Authenticated",
"url": "\/zm\/api\/host\/getVersion.json",
"exception": {
"class": "NotFoundException",
"code": 404,
"message": "Not Authenticated",
"trace": [
"#0 [internal function]: AppController->beforeFilter(Object(CakeEvent))",
"#1 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Event\/CakeEventManager.php(244): call_user_func(Array, Object(CakeEvent))",
"#2 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Controller\/Controller.php(674): CakeEventManager->dispatch(Object(CakeEvent))",
"#3 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Routing\/Dispatcher.php(187): Controller->startupProcess()",
"#4 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Routing\/Dispatcher.php(165): Dispatcher->_invoke(Object(HostController), Object(CakeRequest))",
"#5 \/usr\/share\/zoneminder\/www\/api\/app\/webroot\/index.php(108): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))",
"#6 {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_AUTH' 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
}
],
"count": 2,
"time": 0
}
}
}
}

Uncheck OPT_AUTH and it returns:
{
"version": "1.28.106",
"apiversion": "1.28.106.1"
}

Now, how do we get a user and password passed to the API?
marcolino7
Posts: 73
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 »

Hi,
restarting ZM i got this from API:

Code: Select all

{
    "success": false,
    "data": {
        "name": "Not Authenticated",
        "message": "Not Authenticated",
        "url": "\/zm\/api\/host\/getVersion.json",
        "exception": {
            "class": "NotFoundException",
            "code": 404,
            "message": "Not Authenticated",
            "trace": [
                "#0 [internal function]: AppController->beforeFilter(Object(CakeEvent))",
                "#1 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Event\/CakeEventManager.php(244): call_user_func(Array, Object(CakeEvent))",
                "#2 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Controller\/Controller.php(674): CakeEventManager->dispatch(Object(CakeEvent))",
                "#3 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Routing\/Dispatcher.php(187): Controller->startupProcess()",
                "#4 \/usr\/share\/zoneminder\/www\/api\/lib\/Cake\/Routing\/Dispatcher.php(165): Dispatcher->_invoke(Object(HostController), Object(CakeRequest))",
                "#5 \/usr\/share\/zoneminder\/www\/api\/app\/webroot\/index.php(108): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))",
                "#6 {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_AUTH'    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": 1
                    }
                ],
                "count": 2,
                "time": 1
            }
        }
    }
}
so it seems is working fine.
Now next step :-). I call API from my Home Utomation system, using curl command. How can I authenticate?

Regards
Production Zoneminder 1.31.4 Ubuntu 16.04 LTS on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker »

There is a problem here. Your security for APIs are not working (both bbunge and marco)

Can you please do this. Please follow each step and please confirm that you have performed all the steps below in your response.

1. Enable OPT_AUTH in ZM, log out of ZM
2. Launch a terminal
3. Change directory to a place where you have write permissions (do a cd ~ ) --> this is important
4. Type in this command (replacing xxxx/yyyy/yourZMIP as needed)

Code: Select all

curl -c cookies.txt -d  "username=xxxx&password=yyyy&action=login&view=console"  http://yourZMIP/zm/index.php 
5. Make sure a file called "cookies.txt" is created.
6. see the contents of cookies.txt - it should have an entry for a cookie called ZMSESSID - if it does not, your security is not working
7. Now type this command (replace yourZMIP)

Code: Select all

curl -b cookies.txt  http://yourZMIP/zm/api/host/getVersion.json 

And please confirm what you see
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
Locked