Zoneminder 1.30.4 API not working on FreeBSD

Forum for questions and support relating to the 1.30.x releases only.
n8klayko
Posts: 33
Joined: Tue Apr 17, 2018 7:54 pm

Zoneminder 1.30.4 API not working on FreeBSD

Post by n8klayko » Tue Apr 17, 2018 8:46 pm

I have installed zoneminder directly into a FreeNAS jail using the following guide and a few tweaks to get almost everything working correctly. Unfortunately one thing is not working, the APIs. To reduce overhead I really want to run zoneminder through the jail on my server rather than in a VM. I have already set it up once on a VM and was not very please with the performance/scalability versus the jail installation.

https://forums.freenas.org/index.php?th ... jail.62135


When testing the APIs, by going to "http://server/api/host/getVersion.json", I receive a 404 Not found error.

https://github.com/pliablepixels/zmNinj ... work-on-ZM


Something to note is that the directory structure of the FreeBSD jail version is different than an Ubuntu VM install. The address of my zoneminder installation does not require the "zm" at the end of the URL. Additionally, the API folder is in a different location "/jails/zm/usr/local/www/zoneminder/api". I have searched everywhere to see if I can find a solution to get the APIs working and have not found a clear cut answer. I am hoping that someone may be able to help me figure out if I am missing a dependency or something that is not allowing the APIs to work. Any help is greatly appreciated.

The closest thing to a solution that I have found is the below thread, but I am not sure what to do to resolve the issue.

viewtopic.php?t=26131

rockedge
Posts: 1147
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by rockedge » Wed Apr 18, 2018 3:21 pm

the not found error seems to indicate a URL re-write is not occurring as expected. I run ZM with a Hiawatha web server and needed to make a UrlToolkit that does the URL re-writes similar to what happens in Apache. Possibly check the paths that the re-write rule creates for the api access. You can add the pieces needed to rewrite /jails/zm/usr/local/www/zoneminder/api to a workable url.

the Hiawatha rule looks like this:

Code: Select all

UrlToolkit {
  ToolkitID = api_rule
  Match ^/zm/api Rewrite  /zm/api/app/webroot/index.php$1
}
maybe look in the /usr/share/zoneminder/www/api/.htaccess file:

Code: Select all

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^$ app/webroot/ [L]
   RewriteRule (.*) app/webroot/$1 [L]
   RewriteBase /zm/api
</IfModule>
and change the RewriteBase /zm/api to match your url /jails/zm/usr/local/www/zoneminder/api

see if that does it.

rockedge
Posts: 1147
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by rockedge » Wed Apr 18, 2018 3:41 pm

what version of PHP are you using?

n8klayko
Posts: 33
Joined: Tue Apr 17, 2018 7:54 pm

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by n8klayko » Wed Apr 18, 2018 3:59 pm

rockedge wrote:
Wed Apr 18, 2018 3:21 pm
maybe look in the /usr/share/zoneminder/www/api/.htaccess file:

Code: Select all

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^$ app/webroot/ [L]
   RewriteRule (.*) app/webroot/$1 [L]
   RewriteBase /zm/api
</IfModule>
and change the RewriteBase /zm/api to match your url /jails/zm/usr/local/www/zoneminder/api

see if that does it.
I attempted to change the .htaccess file in the api directory. I rebooted apache and zoneminder then re-tested, but to no avail.

I appear to be missing files and folders in the api directory. To my knowledge, I should have a hosts folder located in the api directory with files in it, but there is no hosts folder.

I should also mention that everything else appears to be working with the web interface, viewing monitors, viewing events, etc.


Respectfully,

n8klayko
Posts: 33
Joined: Tue Apr 17, 2018 7:54 pm

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by n8klayko » Wed Apr 18, 2018 4:01 pm

rockedge wrote:
Wed Apr 18, 2018 3:41 pm
what version of PHP are you using?
After checking the PHP version using

Code: Select all

php -i
, it shows that PHP 5.6.34 is installed in my ZM jail.

rockedge
Posts: 1147
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by rockedge » Wed Apr 18, 2018 4:16 pm

no there will be no actual "host" folder. This is a controller name in the API, this controller code has the functions like "getVersion" in it.
There is a case of missing folders that are talked about on this forum but they are cache folders that did not get installed. That could also be a problem and was fixed just by adding the missing folders but I think it is a re-write problem and the API is being found.
what happens when you use this url? http://your-zm-server/zm/api in your case http://your-zm-server/api ?
what is the error?

rockedge
Posts: 1147
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by rockedge » Wed Apr 18, 2018 4:19 pm

go to /usr/share/zoneminder/www/api/app/Config/core.php and look at line 34

Code: Select all

Configure::write('debug', 0);
and change the 0 to a 2. this will enable more error reporting and allow the url /zm/api (or equivalent to work)
then try the url http://your-zm-server/zm/api or in your case http://your-zm-server/api

rockedge
Posts: 1147
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by rockedge » Wed Apr 18, 2018 4:28 pm

example of the folder structure of the API:
Screenshot(4).png
Screenshot(4).png (21.7 KiB) Viewed 2373 times
Screenshot(1).png
Screenshot(1).png (18.21 KiB) Viewed 2374 times
Screenshot(2).png
Screenshot(2).png (11.15 KiB) Viewed 2374 times

n8klayko
Posts: 33
Joined: Tue Apr 17, 2018 7:54 pm

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by n8klayko » Wed Apr 18, 2018 4:38 pm

@rockedge, you are correct, it looks like a rewrite issue. Any thoughts?
error.PNG
error.PNG (21.63 KiB) Viewed 2372 times
Also, I really appreciate you taking the time to help me out on this! Thanks!

n8klayko
Posts: 33
Joined: Tue Apr 17, 2018 7:54 pm

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by n8klayko » Wed Apr 18, 2018 6:35 pm

I managed to fix the rewrite issue. In my system httpd.conf file, the line

Code: Select all

LoadModule rewrite_module libexec/apache2/mod_rewrite.so
was commented out. I removed the proceeding "#" as explained here:

https://book.cakephp.org/2.0/en/install ... iting.html


Additionally, I had to change my .htaccess files in the directories api and api/app to look like this:

Code: Select all

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
    RewriteBase /api
</IfModule>

I am still having a permission issue with CakePHP as you can see from the below screenshot. I am not sure what permissions I need to change. Any thoughts?
error2.PNG
error2.PNG (86.41 KiB) Viewed 2367 times

rockedge
Posts: 1147
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by rockedge » Wed Apr 18, 2018 7:56 pm

it is starting to look good. the error you are seeing I think, is from cakephp trying to write a log file in a folder someplace that does not have the permissions for www-data to write to it and so it does not exist. check that the directory the log file is writing to has the correct permissions and exists.

what does the URL /zm/api/host/getVersion.json do now?

rockedge
Posts: 1147
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by rockedge » Wed Apr 18, 2018 8:10 pm

look in /usr/share/zoneminder/www/api/app/Config/bootstrap.php around line 100
maybe one of these paths to the log directory in question,

Code: Select all

App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
	'engine' => 'File',
	'types' => array('notice', 'info', 'debug'),
	'file' => 'cake_debug',
    'path' => '/var/log/zm/'
));
CakeLog::config('error', array(
	'engine' => 'File',
	'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
	'file' => 'cake_error',
    'path' => '/var/log/zm/'
));
CakeLog::config('custom_path', array(
    'engine' => 'File',
    'path' => '/var/log/zm/'
));

n8klayko
Posts: 33
Joined: Tue Apr 17, 2018 7:54 pm

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by n8klayko » Thu Apr 19, 2018 4:26 pm

When testing the APIs, by going to http://server/api/host/getVersion.json, I am still receiving a 404 Not found error. Again, because this is directly in a FreeNAS Jail, the /zm/ is not needed for the correct path. The path to my server is http://server/ without the added /zm/ directory

Looking at the api/app/Config/bootstrap.php, the paths you mentioned look to be mostly correct. But the file is a little different than what you have:

Code: Select all

CakeLog::config('debug', array(
	'engine' => 'File',
	'types' => array('notice', 'info', 'debug'),
	'file' => 'cake_debug',
));
CakeLog::config('error', array(
	'engine' => 'File',
	'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
	'file' => 'cake_error',
));
CakeLog::config('custom_path', array(
    'engine' => 'File',
    'path' => '/var/log/zm'
));
I tried switching this to reflect yours but it seems to break everything. Switching it back corrected it, but I am still left with the mkdir permissions error from CakePHP. Looking at my Zoneminder installation it looks like the path above "/var/log/zm" is mostly correct, but I do not have a /zm/ directory inside of my "/var/log" directory.

n8klayko
Posts: 33
Joined: Tue Apr 17, 2018 7:54 pm

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by n8klayko » Mon Apr 23, 2018 2:22 pm

BUMP

n8klayko
Posts: 33
Joined: Tue Apr 17, 2018 7:54 pm

Re: Zoneminder 1.30.4 API not working on FreeBSD

Post by n8klayko » Mon Apr 23, 2018 2:24 pm

I am very close on this. The mkdir CakePHP issue is the only thing that looks to be preventing the API from working. I am not sure if this is a permission error or an error in a config file. Any guidance would be greatly appreciated.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests