Set function from API does not work

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

Re: Set function from API does not work

Post by marcolino7 » Fri Sep 18, 2015 3:39 pm

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.29.x Ubuntu 14 on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration

bbunge
Posts: 1259
Joined: Mon Mar 26, 2012 11:40 am

Re: Set function from API does not work

Post by bbunge » Fri Sep 18, 2015 4:31 pm

Yup, you will get that error. Looks like the Debian and Ubuntu API set up will be the same. Wait for it...

bbunge
Posts: 1259
Joined: Mon Mar 26, 2012 11:40 am

Re: Set function from API does not work

Post by bbunge » Fri Sep 18, 2015 5:48 pm

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: 56
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 » Fri Sep 18, 2015 9:52 pm

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.29.x Ubuntu 14 on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration

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

Re: Set function from API does not work

Post by marcolino7 » Mon Sep 21, 2015 2:15 pm

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.29.x Ubuntu 14 on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration

asker
Posts: 782
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker » Mon Sep 21, 2015 2:21 pm

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'
       ));
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

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

Re: Set function from API does not work

Post by marcolino7 » Mon Sep 21, 2015 3:30 pm

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.29.x Ubuntu 14 on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration

bbunge
Posts: 1259
Joined: Mon Mar 26, 2012 11:40 am

Re: Set function from API does not work

Post by bbunge » Mon Sep 21, 2015 3:46 pm

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: 56
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 » Mon Sep 21, 2015 4:10 pm

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

Marco
Production Zoneminder 1.29.x Ubuntu 14 on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration

bbunge
Posts: 1259
Joined: Mon Mar 26, 2012 11:40 am

Re: Set function from API does not work

Post by bbunge » Mon Sep 21, 2015 4:51 pm

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

asker
Posts: 782
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker » Mon Sep 21, 2015 6:13 pm

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?
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

bbunge
Posts: 1259
Joined: Mon Mar 26, 2012 11:40 am

Re: Set function from API does not work

Post by bbunge » Mon Sep 21, 2015 7:29 pm

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: 1259
Joined: Mon Mar 26, 2012 11:40 am

Re: Set function from API does not work

Post by bbunge » Tue Sep 22, 2015 1:07 am

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: 56
Joined: Wed Sep 16, 2015 12:20 pm

Re: Set function from API does not work

Post by marcolino7 » Tue Sep 22, 2015 8:00 am

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.29.x Ubuntu 14 on VmWare ESXi
6 Cameras FOSCAM FI8918W
OpenHab Integration

asker
Posts: 782
Joined: Sun Mar 01, 2015 12:12 pm

Re: Set function from API does not work

Post by asker » Tue Sep 22, 2015 10:43 am

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
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest