Skip to content

Commit

Permalink
Migrate Webcache out of webroot (ZoneMinder#2083)
Browse files Browse the repository at this point in the history
* migrate webcache folder out of webroot, migrate htaccess files

* rpm specfile - add missing reference to cache folder

* fix submodule mixup
  • Loading branch information
knight-of-ni authored and connortechnology committed Apr 19, 2018
1 parent e7be406 commit 3c225c9
Show file tree
Hide file tree
Showing 29 changed files with 136 additions and 46 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ set(ZM_WEBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/zoneminder/www"
"Location of the web files, default: <prefix>/${CMAKE_INSTALL_DATADIR}/zoneminder/www")
set(ZM_CGIDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}/zoneminder/cgi-bin" CACHE PATH
"Location of the cgi-bin files, default: <prefix>/${CMAKE_INSTALL_LIBEXECDIR}/zoneminder/cgi-bin")
set(ZM_CACHEDIR "/var/cache/zoneminder" CACHE PATH
"Location of the web server cache busting files, default: /var/cache/zoneminder")
set(ZM_CONTENTDIR "/var/lib/zoneminder" CACHE PATH
"Location of dynamic content (events and images), default: /var/lib/zoneminder")
set(ZM_DB_HOST "localhost" CACHE STRING
Expand Down
1 change: 1 addition & 0 deletions distros/redhat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ file(MAKE_DIRECTORY sock swap zoneminder zoneminder-upload events images temp)
install(DIRECTORY sock swap DESTINATION /var/lib/zoneminder DIRECTORY_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(DIRECTORY zoneminder DESTINATION /var/log DIRECTORY_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(DIRECTORY zoneminder DESTINATION /var/run DIRECTORY_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(DIRECTORY zoneminder DESTINATION /var/cache DIRECTORY_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(DIRECTORY zoneminder-upload DESTINATION /var/spool DIRECTORY_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(DIRECTORY events images temp DESTINATION /var/lib/zoneminder DIRECTORY_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)

Expand Down
17 changes: 17 additions & 0 deletions distros/redhat/apache/zoneminder.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(zm)(.*) https://%{SERVER_NAME}/$1$2 [R,L]

# Order matters. This alias must come first.
Alias /zm/cache "@ZM_CACHEDIR@"
<Directory "@ZM_CACHEDIR@">
SSLRequireSSL
Options -Indexes +MultiViews +FollowSymLinks
AllowOverride None
<IfModule mod_authz_core.c>
# Apache 2.4
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order deny,allow
Allow from all
</IfModule>
</Directory>

Alias /zm "@ZM_WEBDIR@"
<Directory "@ZM_WEBDIR@">
# explicitly set index.php as the only directoryindex
Expand Down
3 changes: 3 additions & 0 deletions distros/redhat/systemd/zoneminder.tmpfiles.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
D @ZM_TMPDIR@ 0755 @WEB_USER@ @WEB_GROUP@
D @ZM_SOCKDIR@ 0755 @WEB_USER@ @WEB_GROUP@
D @ZM_CACHEDIR@ 0755 @WEB_USER@ @WEB_GROUP@
D @ZM_DIR_EVENTS@ 0755 @WEB_USER@ @WEB_GROUP@
D @ZM_DIR_IMAGES@ 0755 @WEB_USER@ @WEB_GROUP@
1 change: 1 addition & 0 deletions distros/redhat/zoneminder.spec
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ rm -rf %{_docdir}/%{name}-%{version}
%dir %attr(755,%{zmuid_final},%{zmgid_final}) %{_sharedstatedir}/zoneminder/sock
%dir %attr(755,%{zmuid_final},%{zmgid_final}) %{_sharedstatedir}/zoneminder/swap
%dir %attr(755,%{zmuid_final},%{zmgid_final}) %{_sharedstatedir}/zoneminder/temp
%dir %attr(755,%{zmuid_final},%{zmgid_final}) %{_localstatedir}/cache/zoneminder
%dir %attr(755,%{zmuid_final},%{zmgid_final}) %{_localstatedir}/log/zoneminder
%dir %attr(755,%{zmuid_final},%{zmgid_final}) %{_localstatedir}/spool/zoneminder-upload
%dir %attr(755,%{zmuid_final},%{zmgid_final}) %{_localstatedir}/run/zoneminder
Expand Down
32 changes: 30 additions & 2 deletions distros/ubuntu1204/conf/apache2/zoneminder.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ ScriptAlias /zm/cgi-bin "/usr/lib/zoneminder/cgi-bin"
Require all granted
</Directory>

# Order matters. This Alias must come first
Alias /zm/cache /var/cache/zoneminder/cache
<Directory /var/cache/zoneminder/cache>
Options -Indexes +FollowSymLinks
</Directory>

Alias /zm /usr/share/zoneminder/www
<Directory /usr/share/zoneminder/www>
php_flag register_globals off
Expand All @@ -15,6 +21,28 @@ Alias /zm /usr/share/zoneminder/www
</IfModule>
</Directory>

<Directory /usr/share/zoneminder/www/api>
AllowOverride All
# For better visibility, the following directives have been migrated from the
# default .htaccess files included with the CakePHP project.
# Parameters not set here are inherited from the parent directive above.
<Directory "/usr/share/zoneminder/www/api">
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
RewriteBase /zm/api
</Directory>

<Directory "/usr/share/zoneminder/www/api/app">
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
RewriteBase /zm/api
</Directory>

<Directory "/usr/share/zoneminder/www/api/app/webroot">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteBase /zm/api
</Directory>

1 change: 1 addition & 0 deletions distros/ubuntu1204/rules
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ override_dh_auto_configure:
-DZM_SOCKDIR="/var/run/zm" \
-DZM_TMPDIR="/tmp/zm" \
-DZM_CGIDIR="/usr/lib/zoneminder/cgi-bin" \
-DZM_CACHEDIR="/var/cache/zoneminder/cache" \
-DZM_DIR_EVENTS="/var/cache/zoneminder/events" \
-DZM_DIR_IMAGES="/var/cache/zoneminder/images" \
-DZM_PATH_ZMS="/zm/cgi-bin/nph-zms" \
Expand Down
1 change: 1 addition & 0 deletions distros/ubuntu1204/zoneminder.dirs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var/lib/zm
var/cache/zoneminder/events
var/cache/zoneminder/images
var/cache/zoneminder/temp
var/cache/zoneminder/cache
usr/share/zoneminder/db
etc/zm
etc/zm/conf.d
31 changes: 29 additions & 2 deletions distros/ubuntu1604/conf/apache2/zoneminder.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ ScriptAlias /zm/cgi-bin "/usr/lib/zoneminder/cgi-bin"
Require all granted
</Directory>

# Order matters. This alias must come first.
Alias /zm/cache /var/cache/zoneminder/cache
<Directory /var/cache/zoneminder/cache>
Options -Indexes +FollowSymLinks
</Directory>

Alias /zm /usr/share/zoneminder/www
<Directory /usr/share/zoneminder/www>
Options -Indexes +FollowSymLinks
Expand All @@ -14,6 +20,27 @@ Alias /zm /usr/share/zoneminder/www
</IfModule>
</Directory>

<Directory /usr/share/zoneminder/www/api>
AllowOverride All
# For better visibility, the following directives have been migrated from the
# default .htaccess files included with the CakePHP project.
# Parameters not set here are inherited from the parent directive above.
<Directory "/usr/share/zoneminder/www/api">
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
RewriteBase /zm/api
</Directory>

<Directory "/usr/share/zoneminder/www/api/app">
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
RewriteBase /zm/api
</Directory>

<Directory "/usr/share/zoneminder/www/api/app/webroot">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteBase /zm/api
</Directory>
1 change: 1 addition & 0 deletions distros/ubuntu1604/rules
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ override_dh_auto_configure:
-DZM_SOCKDIR="/var/run/zm" \
-DZM_TMPDIR="/tmp/zm" \
-DZM_CGIDIR="/usr/lib/zoneminder/cgi-bin" \
-DZM_CACHEDIR="/var/cache/zoneminder/cache" \
-DZM_DIR_EVENTS="/var/cache/zoneminder/events" \
-DZM_DIR_IMAGES="/var/cache/zoneminder/images" \
-DZM_PATH_ZMS="/zm/cgi-bin/nph-zms"
Expand Down
2 changes: 1 addition & 1 deletion distros/ubuntu1604/zoneminder.dirs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var/lib/zm
var/cache/zoneminder/events
var/cache/zoneminder/images
var/cache/zoneminder/temp
var/cache/zoneminder/cache
usr/share/zoneminder/db
usr/share/zoneminder/www/cache
etc/zm/
etc/zm/conf.d
2 changes: 1 addition & 1 deletion distros/ubuntu1604/zoneminder.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [ "$1" = "configure" ]; then
chown www-data:root /var/log/zm
chown www-data:www-data /var/lib/zm
if [ -z "$2" ]; then
chown www-data:www-data /var/cache/zoneminder /var/cache/zoneminder/* /usr/share/zoneminder/www/cache
chown www-data:www-data /var/cache/zoneminder /var/cache/zoneminder/*
fi
if [ ! -e "/etc/apache2/mods-enabled/cgi.load" ] && [ "$(command -v a2enmod)" != "" ]; then
echo "The cgi module is not enabled in apache2. I am enabling it using a2enmod cgi."
Expand Down
2 changes: 1 addition & 1 deletion distros/ubuntu1604/zoneminder.tmpfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
d /var/run/zm 0755 www-data www-data
d /tmp/zm 0755 www-data www-data
d /var/tmp/zm 0755 www-data www-data
d /usr/share/zoneminder/www/cache 0755 www-data www-data
d /var/cache/zoneminder/cache 0755 www-data www-data
42 changes: 42 additions & 0 deletions misc/apache.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
ServerAdmin webmaster@localhost

DocumentRoot "@WEB_PREFIX@"

# Order matters. This alias must come first.
Alias /zm/cache "@ZM_CACHEDIR@"
<Directory "@ZM_CACHEDIR@">
Options -Indexes +FollowSymLinks
AllowOverride None
<IfModule mod_authz_core.c>
# Apache 2.4
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order deny,allow
Allow from all
</IfModule>
</Directory>

Alias /zm "@WEB_PREFIX@"
<Directory "@WEB_PREFIX@">
Options -Indexes +FollowSymLinks
Expand Down Expand Up @@ -38,6 +55,31 @@
</IfModule>
</Directory>

# For better visibility, the following directives have been migrated from the
# default .htaccess files included with the CakePHP project.
# Parameters not set here are inherited from the parent directive above.
<Directory "@ZM_WEBDIR@/api">
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
RewriteBase /zm/api
</Directory>

<Directory "@ZM_WEBDIR@/api/app">
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
RewriteBase /zm/api
</Directory>

<Directory "@ZM_WEBDIR@/api/app/webroot">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteBase /zm/api
</Directory>

# Use the first option to have Apache logs written to the general log
# directory, or the second to have them written to the regular Apache
# directory (you may have to change the path to that used on your system)
Expand Down
5 changes: 0 additions & 5 deletions web/.htaccess

This file was deleted.

6 changes: 0 additions & 6 deletions web/api/.htaccess

This file was deleted.

6 changes: 0 additions & 6 deletions web/api/app/.htaccess

This file was deleted.

2 changes: 1 addition & 1 deletion web/api/app/Plugin/Crud
Submodule Crud updated from 1351dd to 0bd63f
7 changes: 0 additions & 7 deletions web/api/app/webroot/.htaccess

This file was deleted.

5 changes: 0 additions & 5 deletions web/api/lib/Cake/Console/Templates/skel/.htaccess

This file was deleted.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
6 changes: 0 additions & 6 deletions web/api/lib/Cake/Console/Templates/skel/webroot/.htaccess

This file was deleted.

1 change: 1 addition & 0 deletions web/includes/config.php.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ define( 'ZM_CONFIG_SUBDIR', '@ZM_CONFIG_SUBDIR@' ); // Path to config subfolder
// Define, and override any given in config file
define( 'ZM_VERSION', '@VERSION@' ); // Version
define( 'ZM_DIR_TEMP', '@ZM_TMPDIR@' );
define( 'ZM_DIR_CACHE', '@ZM_CACHEDIR@' );
global $configvals;

$configFile = ZM_CONFIG;
Expand Down
6 changes: 3 additions & 3 deletions web/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2031,9 +2031,9 @@ function cache_bust( $file ) {
$parts = pathinfo($file);
global $css;
$dirname = preg_replace( '/\//', '_', $parts['dirname'] );
$cacheFile = 'cache/'.$dirname.'_'.$parts['filename'].'-'.$css.'-'.filemtime($file).'.'.$parts['extension'];
if ( file_exists( ZM_PATH_WEB.'/'.$cacheFile ) or symlink( ZM_PATH_WEB.'/'.$file, ZM_PATH_WEB.'/'.$cacheFile ) ) {
return $cacheFile;
$cacheFile = $dirname.'_'.$parts['filename'].'-'.$css.'-'.filemtime($file).'.'.$parts['extension'];
if ( file_exists( ZM_DIR_CACHE.'/'.$cacheFile ) or symlink( ZM_PATH_WEB.'/'.$file, ZM_DIR_CACHE.'/'.$cacheFile ) ) {
return 'cache/'.$cacheFile;
} else {
Warning("Failed linking $file to $cacheFile");
}
Expand Down

0 comments on commit 3c225c9

Please sign in to comment.