From 14151ea2f8fb33d4336afa161a0e8b8bed6e5daa Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Thu, 31 Mar 2011 23:38:47 -0400 Subject: Bug 644334 - Add hook to Bugzilla::Install::Filesystem to allow extensions to create files/directories/htaccess r/a=mkanat --- Bugzilla/Hook.pm | 91 +++++++++++++++++++++++++++++++++++++++++ Bugzilla/Install/Filesystem.pm | 10 +++++ extensions/Example/Extension.pm | 28 +++++++++++++ 3 files changed, 129 insertions(+) diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm index cf81e9c7d..996f327c3 100644 --- a/Bugzilla/Hook.pm +++ b/Bugzilla/Hook.pm @@ -720,6 +720,97 @@ time should be printed. =back +=head2 install_filesystem + +Allows for additional files and directories to be added to the +list of files and directories already managed by checksetup.pl. +You will be able to also set permissions for the files and +directories using this hook. You can also use this hook to create +appropriate .htaccess files for any directory to secure its contents. +For examples see L in L. + +Params: + +=over + +=item C + +Hash reference of files that are already present when your extension was +installed but need to have specific permissions set. Each file key +points to another hash reference containing the following settings. + +Params: + +=over + +=item C - Permissions to be set on the file. + +=back + +=item C + +Hash reference containing the name of each directory that will be created, +pointing at its default permissions. + +=item C + +Hash reference containing directories that we want to set the perms on, but not +recurse through. These are directories not created in checksetup.pl. Each directory +key's value is the permissions to be set on the directory. + +=item C + +Hash reference of directories that will have permissions set for each item inside +each of the directories, including the directory itself. Each directory key +points to another hash reference containing the following settings. + +Params: + +=over + +=item C - Permissions to be set on any files beneath the directory. + +=item C - Permissions to be set on the directory itself and any directories +beneath it. + +=back + +=item C + +Hash reference of additional files to be created. Each file key points to another +hash reference containing the following settings. + +Params: + +=over + +=item C - The permissions to be set on the file itself. + +=item C - The contents to be added to the file or leave blank for an +empty file. + +=back + +=item C + +Hash reference containing htaccess files to be created. You can set the permissions +for the htaccess as well as the contents of the file. Each file key points to another +hash reference containing the following settings. + +Params: + +=over + +=item C - Permissions to be set on the htaccess file. + +=item C - Contents of the htaccess file. It can be set manually or +use L defined in L to deny all +by default. + +=back + +=back + =head2 install_update_db This happens at the very end of all the tables being updated diff --git a/Bugzilla/Install/Filesystem.pm b/Bugzilla/Install/Filesystem.pm index 2845728bc..15106dab9 100644 --- a/Bugzilla/Install/Filesystem.pm +++ b/Bugzilla/Install/Filesystem.pm @@ -32,6 +32,7 @@ use Bugzilla::Error; use Bugzilla::Install::Localconfig; use Bugzilla::Install::Util qw(install_string); use Bugzilla::Util; +use Bugzilla::Hook; use File::Find; use File::Path; @@ -364,6 +365,15 @@ EOT }, ); + Bugzilla::Hook::process('install_filesystem', { + files => \%files, + create_dirs => \%create_dirs, + non_recurse_dirs => \%non_recurse_dirs, + recurse_dirs => \%recurse_dirs, + create_files => \%create_files, + htaccess => \%htaccess, + }); + my %all_files = (%create_files, %htaccess, %index_html, %files); my %all_dirs = (%create_dirs, %non_recurse_dirs); diff --git a/extensions/Example/Extension.pm b/extensions/Example/Extension.pm index f56416559..5b95335b8 100644 --- a/extensions/Example/Extension.pm +++ b/extensions/Example/Extension.pm @@ -31,6 +31,7 @@ use Bugzilla::User; use Bugzilla::User::Setting; use Bugzilla::Util qw(diff_arrays html_quote); use Bugzilla::Status qw(is_open_state); +use Bugzilla::Install::Filesystem; # This is extensions/Example/lib/Util.pm. I can load this here in my # Extension.pm only because I have a Config.pm. @@ -402,6 +403,33 @@ sub install_before_final_checks { # hook/global/setting-descs-settings.none.tmpl . } +sub install_filesystem { + my ($self, $args) = @_; + my $create_dirs = $args->{'create_dirs'}; + my $recurse_dirs = $args->{'recurse_dirs'}; + my $htaccess = $args->{'htaccess'}; + + # Create a new directory in datadir specifically for this extension. + # The directory will need to allow files to be created by the extension + # code as well as allow the webserver to server content from it. + # my $data_path = bz_locations->{'datadir'} . "/" . __PACKAGE__->NAME; + # $create_dirs->{$data_path} = Bugzilla::Install::Filesystem::DIR_CGI_WRITE; + + # Update the permissions of any files and directories that currently reside + # in the extension's directory. + # $recurse_dirs->{$data_path} = { + # files => Bugzilla::Install::Filesystem::CGI_READ, + # dirs => Bugzilla::Install::Filesystem::DIR_CGI_WRITE + # }; + + # Create a htaccess file that allows specific content to be served from the + # extension's directory. + # $htaccess->{"$data_path/.htaccess"} = { + # perms => Bugzilla::Install::Filesystem::WS_SERVE, + # contents => Bugzilla::Install::Filesystem::HT_DEFAULT_DENY + # }; +} + #sub install_update_db_fielddefs { # my $dbh = Bugzilla->dbh; # $dbh->bz_add_column('fielddefs', 'example_column', -- cgit v1.2.3-24-g4f1b