From 3c225c9f1c1a6ade63c1b7702d6178abacde1a21 Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Thu, 19 Apr 2018 14:01:46 -0500 Subject: [PATCH] Migrate Webcache out of webroot (#2083) * migrate webcache folder out of webroot, migrate htaccess files * rpm specfile - add missing reference to cache folder * fix submodule mixup --- CMakeLists.txt | 2 + distros/redhat/CMakeLists.txt | 1 + distros/redhat/apache/zoneminder.conf.in | 17 ++++++++ distros/redhat/systemd/zoneminder.tmpfiles.in | 3 ++ distros/redhat/zoneminder.spec | 1 + .../ubuntu1204/conf/apache2/zoneminder.conf | 32 +++++++++++++- distros/ubuntu1204/rules | 1 + distros/ubuntu1204/zoneminder.dirs | 1 + .../ubuntu1604/conf/apache2/zoneminder.conf | 31 +++++++++++++- distros/ubuntu1604/rules | 1 + distros/ubuntu1604/zoneminder.dirs | 2 +- distros/ubuntu1604/zoneminder.postinst | 2 +- distros/ubuntu1604/zoneminder.tmpfile | 2 +- misc/apache.conf.in | 42 +++++++++++++++++++ web/.htaccess | 5 --- web/api/.htaccess | 6 --- web/api/app/.htaccess | 6 --- web/api/app/Plugin/Crud | 2 +- web/api/app/webroot/.htaccess | 7 ---- .../lib/Cake/Console/Templates/skel/.htaccess | 5 --- .../Templates/skel/tmp/cache/models/empty | 0 .../Templates/skel/tmp/cache/persistent/empty | 0 .../Templates/skel/tmp/cache/views/empty | 0 .../Console/Templates/skel/tmp/logs/empty | 0 .../Console/Templates/skel/tmp/sessions/empty | 0 .../Console/Templates/skel/tmp/tests/empty | 0 .../Console/Templates/skel/webroot/.htaccess | 6 --- web/includes/config.php.in | 1 + web/includes/functions.php | 6 +-- 29 files changed, 136 insertions(+), 46 deletions(-) delete mode 100644 web/.htaccess delete mode 100644 web/api/.htaccess delete mode 100644 web/api/app/.htaccess delete mode 100644 web/api/app/webroot/.htaccess delete mode 100644 web/api/lib/Cake/Console/Templates/skel/.htaccess create mode 100644 web/api/lib/Cake/Console/Templates/skel/tmp/cache/models/empty create mode 100644 web/api/lib/Cake/Console/Templates/skel/tmp/cache/persistent/empty create mode 100644 web/api/lib/Cake/Console/Templates/skel/tmp/cache/views/empty create mode 100644 web/api/lib/Cake/Console/Templates/skel/tmp/logs/empty create mode 100644 web/api/lib/Cake/Console/Templates/skel/tmp/sessions/empty create mode 100644 web/api/lib/Cake/Console/Templates/skel/tmp/tests/empty delete mode 100644 web/api/lib/Cake/Console/Templates/skel/webroot/.htaccess diff --git a/CMakeLists.txt b/CMakeLists.txt index d6f989f01..b24bc6fa8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,6 +141,8 @@ set(ZM_WEBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/zoneminder/www" "Location of the web files, default: /${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: /${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 diff --git a/distros/redhat/CMakeLists.txt b/distros/redhat/CMakeLists.txt index 73f88f968..edc0fd080 100644 --- a/distros/redhat/CMakeLists.txt +++ b/distros/redhat/CMakeLists.txt @@ -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) diff --git a/distros/redhat/apache/zoneminder.conf.in b/distros/redhat/apache/zoneminder.conf.in index 0e546f9df..a52c1166a 100644 --- a/distros/redhat/apache/zoneminder.conf.in +++ b/distros/redhat/apache/zoneminder.conf.in @@ -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@" + + SSLRequireSSL + Options -Indexes +MultiViews +FollowSymLinks + AllowOverride None + + # Apache 2.4 + Require all granted + + + # Apache 2.2 + Order deny,allow + Allow from all + + + Alias /zm "@ZM_WEBDIR@" # explicitly set index.php as the only directoryindex diff --git a/distros/redhat/systemd/zoneminder.tmpfiles.in b/distros/redhat/systemd/zoneminder.tmpfiles.in index f3acd0af7..de155b4cc 100644 --- a/distros/redhat/systemd/zoneminder.tmpfiles.in +++ b/distros/redhat/systemd/zoneminder.tmpfiles.in @@ -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@ diff --git a/distros/redhat/zoneminder.spec b/distros/redhat/zoneminder.spec index 5d8f213b6..3d2febab9 100644 --- a/distros/redhat/zoneminder.spec +++ b/distros/redhat/zoneminder.spec @@ -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 diff --git a/distros/ubuntu1204/conf/apache2/zoneminder.conf b/distros/ubuntu1204/conf/apache2/zoneminder.conf index 0dc312769..81e9713db 100644 --- a/distros/ubuntu1204/conf/apache2/zoneminder.conf +++ b/distros/ubuntu1204/conf/apache2/zoneminder.conf @@ -6,6 +6,12 @@ ScriptAlias /zm/cgi-bin "/usr/lib/zoneminder/cgi-bin" Require all granted +# Order matters. This Alias must come first +Alias /zm/cache /var/cache/zoneminder/cache + + Options -Indexes +FollowSymLinks + + Alias /zm /usr/share/zoneminder/www php_flag register_globals off @@ -15,6 +21,28 @@ Alias /zm /usr/share/zoneminder/www - - 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. + + RewriteEngine on + RewriteRule ^$ app/webroot/ [L] + RewriteRule (.*) app/webroot/$1 [L] + RewriteBase /zm/api + + + RewriteEngine on + RewriteRule ^$ webroot/ [L] + RewriteRule (.*) webroot/$1 [L] + RewriteBase /zm/api + + + + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^ index.php [L] + RewriteBase /zm/api + + diff --git a/distros/ubuntu1204/rules b/distros/ubuntu1204/rules index 0103d1c27..aed63c110 100755 --- a/distros/ubuntu1204/rules +++ b/distros/ubuntu1204/rules @@ -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" \ diff --git a/distros/ubuntu1204/zoneminder.dirs b/distros/ubuntu1204/zoneminder.dirs index ff1ec7858..79b2c66af 100644 --- a/distros/ubuntu1204/zoneminder.dirs +++ b/distros/ubuntu1204/zoneminder.dirs @@ -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 diff --git a/distros/ubuntu1604/conf/apache2/zoneminder.conf b/distros/ubuntu1604/conf/apache2/zoneminder.conf index 59efc6248..a51b153a9 100644 --- a/distros/ubuntu1604/conf/apache2/zoneminder.conf +++ b/distros/ubuntu1604/conf/apache2/zoneminder.conf @@ -6,6 +6,12 @@ ScriptAlias /zm/cgi-bin "/usr/lib/zoneminder/cgi-bin" Require all granted +# Order matters. This alias must come first. +Alias /zm/cache /var/cache/zoneminder/cache + + Options -Indexes +FollowSymLinks + + Alias /zm /usr/share/zoneminder/www Options -Indexes +FollowSymLinks @@ -14,6 +20,27 @@ Alias /zm /usr/share/zoneminder/www - - 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. + + RewriteEngine on + RewriteRule ^$ app/webroot/ [L] + RewriteRule (.*) app/webroot/$1 [L] + RewriteBase /zm/api + + + + RewriteEngine on + RewriteRule ^$ webroot/ [L] + RewriteRule (.*) webroot/$1 [L] + RewriteBase /zm/api + + + + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^ index.php [L] + RewriteBase /zm/api diff --git a/distros/ubuntu1604/rules b/distros/ubuntu1604/rules index 97c084e42..f0808a8e1 100755 --- a/distros/ubuntu1604/rules +++ b/distros/ubuntu1604/rules @@ -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" diff --git a/distros/ubuntu1604/zoneminder.dirs b/distros/ubuntu1604/zoneminder.dirs index 08840aef4..6db3d5a95 100644 --- a/distros/ubuntu1604/zoneminder.dirs +++ b/distros/ubuntu1604/zoneminder.dirs @@ -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 diff --git a/distros/ubuntu1604/zoneminder.postinst b/distros/ubuntu1604/zoneminder.postinst index b9307bddd..17272c2df 100644 --- a/distros/ubuntu1604/zoneminder.postinst +++ b/distros/ubuntu1604/zoneminder.postinst @@ -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." diff --git a/distros/ubuntu1604/zoneminder.tmpfile b/distros/ubuntu1604/zoneminder.tmpfile index f23ca55b3..9435be2a8 100644 --- a/distros/ubuntu1604/zoneminder.tmpfile +++ b/distros/ubuntu1604/zoneminder.tmpfile @@ -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 diff --git a/misc/apache.conf.in b/misc/apache.conf.in index 1344bb9b1..cb9c08667 100644 --- a/misc/apache.conf.in +++ b/misc/apache.conf.in @@ -8,6 +8,23 @@ ServerAdmin webmaster@localhost DocumentRoot "@WEB_PREFIX@" + + # Order matters. This alias must come first. + Alias /zm/cache "@ZM_CACHEDIR@" + + Options -Indexes +FollowSymLinks + AllowOverride None + + # Apache 2.4 + Require all granted + + + # Apache 2.2 + Order deny,allow + Allow from all + + + Alias /zm "@WEB_PREFIX@" Options -Indexes +FollowSymLinks @@ -38,6 +55,31 @@ + # 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. + + RewriteEngine on + RewriteRule ^$ app/webroot/ [L] + RewriteRule (.*) app/webroot/$1 [L] + RewriteBase /zm/api + + + + RewriteEngine on + RewriteRule ^$ webroot/ [L] + RewriteRule (.*) webroot/$1 [L] + RewriteBase /zm/api + + + + RewriteEngine On + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^ index.php [L] + RewriteBase /zm/api + + # 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) diff --git a/web/.htaccess b/web/.htaccess deleted file mode 100644 index f23dbaf66..000000000 --- a/web/.htaccess +++ /dev/null @@ -1,5 +0,0 @@ - - RewriteEngine on - RewriteRule ^$ app/webroot/ [L] - RewriteRule (.*) app/webroot/$1 [L] - \ No newline at end of file diff --git a/web/api/.htaccess b/web/api/.htaccess deleted file mode 100644 index 7139a2766..000000000 --- a/web/api/.htaccess +++ /dev/null @@ -1,6 +0,0 @@ - - RewriteEngine on - RewriteRule ^$ app/webroot/ [L] - RewriteRule (.*) app/webroot/$1 [L] - RewriteBase /zm/api - diff --git a/web/api/app/.htaccess b/web/api/app/.htaccess deleted file mode 100644 index 1af74d971..000000000 --- a/web/api/app/.htaccess +++ /dev/null @@ -1,6 +0,0 @@ - - RewriteEngine on - RewriteRule ^$ webroot/ [L] - RewriteRule (.*) webroot/$1 [L] - RewriteBase /zm/api - diff --git a/web/api/app/Plugin/Crud b/web/api/app/Plugin/Crud index 1351dde6b..0bd63fb46 160000 --- a/web/api/app/Plugin/Crud +++ b/web/api/app/Plugin/Crud @@ -1 +1 @@ -Subproject commit 1351dde6b4c75b215099ae8bcf5a21d6c6e10298 +Subproject commit 0bd63fb464957080ead342db58ca9e01532cf1ef diff --git a/web/api/app/webroot/.htaccess b/web/api/app/webroot/.htaccess deleted file mode 100644 index f08afa8b2..000000000 --- a/web/api/app/webroot/.htaccess +++ /dev/null @@ -1,7 +0,0 @@ - - RewriteEngine On - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^ index.php [L] - RewriteBase /zm/api - diff --git a/web/api/lib/Cake/Console/Templates/skel/.htaccess b/web/api/lib/Cake/Console/Templates/skel/.htaccess deleted file mode 100644 index 128e7871b..000000000 --- a/web/api/lib/Cake/Console/Templates/skel/.htaccess +++ /dev/null @@ -1,5 +0,0 @@ - - RewriteEngine on - RewriteRule ^$ webroot/ [L] - RewriteRule (.*) webroot/$1 [L] - \ No newline at end of file diff --git a/web/api/lib/Cake/Console/Templates/skel/tmp/cache/models/empty b/web/api/lib/Cake/Console/Templates/skel/tmp/cache/models/empty new file mode 100644 index 000000000..e69de29bb diff --git a/web/api/lib/Cake/Console/Templates/skel/tmp/cache/persistent/empty b/web/api/lib/Cake/Console/Templates/skel/tmp/cache/persistent/empty new file mode 100644 index 000000000..e69de29bb diff --git a/web/api/lib/Cake/Console/Templates/skel/tmp/cache/views/empty b/web/api/lib/Cake/Console/Templates/skel/tmp/cache/views/empty new file mode 100644 index 000000000..e69de29bb diff --git a/web/api/lib/Cake/Console/Templates/skel/tmp/logs/empty b/web/api/lib/Cake/Console/Templates/skel/tmp/logs/empty new file mode 100644 index 000000000..e69de29bb diff --git a/web/api/lib/Cake/Console/Templates/skel/tmp/sessions/empty b/web/api/lib/Cake/Console/Templates/skel/tmp/sessions/empty new file mode 100644 index 000000000..e69de29bb diff --git a/web/api/lib/Cake/Console/Templates/skel/tmp/tests/empty b/web/api/lib/Cake/Console/Templates/skel/tmp/tests/empty new file mode 100644 index 000000000..e69de29bb diff --git a/web/api/lib/Cake/Console/Templates/skel/webroot/.htaccess b/web/api/lib/Cake/Console/Templates/skel/webroot/.htaccess deleted file mode 100644 index 1d499ba73..000000000 --- a/web/api/lib/Cake/Console/Templates/skel/webroot/.htaccess +++ /dev/null @@ -1,6 +0,0 @@ - - RewriteEngine On - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^ index.php [L] - diff --git a/web/includes/config.php.in b/web/includes/config.php.in index c9bd55dd7..c6aa93c63 100644 --- a/web/includes/config.php.in +++ b/web/includes/config.php.in @@ -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; diff --git a/web/includes/functions.php b/web/includes/functions.php index 64d6ce29b..69d655d8a 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -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"); }