1 package RT::Extension::AttachmentFilter;
5 require RT::Interface::Web;
6 package HTML::Mason::Commands;
12 RT-Extension-AttachmentFilter - Set forbidden attachments file names or extensions
17 Ses RT extension allows to forbid some files names or extensions from web
20 It's use may be to match an existing mail policy.
22 The filter can be defined per queue so queues that do not have outgoing emails
23 configured can have less restrictions.
25 See the configuration example under L</INSTALLATION>.
31 =item C<perl Makefile.PL>
37 May need root permissions
39 =item Edit your F</opt/rt4/etc/RT_SiteConfig.pm>
41 If you are using RT 4.2 or greater, add this line:
43 Plugin('RT::Extension::AttachmentFilter');
45 For RT 4.0, add this line:
47 Set(@Plugins, qw(RT::Extension::AttachmentFilter));
49 or add C<RT::Extension::AttachmentFilter> to your existing C<@Plugins> line.
51 Then configure the limits using the $AttachmentFilter config option. This
52 option takes the generic form of:
54 Set( $AttachmentFilter,
59 which allows to set limit per queue. '*' means for all queues that do
60 not have a specific filter.
62 'regexp' is a perl regular expression against the filename.
64 =item Clear your mason cache
66 rm -rf /opt/rt4/var/mason_data/obj
68 =item Restart your webserver
72 =head1 IMPLEMENTATION DETAILS
76 =head3 CheckAttachmentName
78 This is the main routine, it takes an attachment file name and an optional
79 queue (name, id or object) and validate it against RT $AttachmentFilter
82 Returns undef if allowed, (1, error message) else.
86 sub CheckAttachmentFilter {
93 my $filters = RT->Config->Get('AttachmentFilter');
95 return undef unless ( $filters );
96 return undef unless ( $args{'FileName'} );
98 if ( ref($filters) ne 'HASH' ) {
99 RT->Logger->crit("Configuration error, AttachmentFilter must be a HASH");
103 my $SystemQueue = RT::Queue->new( RT->SystemUser );
104 if ( $args{'Queue'} ) {
105 if ( ref($args{'Queue'}) eq 'RT::Queue' ) {
106 $SystemQueue->Load( $args{'Queue'}->id );
108 $SystemQueue->Load( $args{'Queue'} );
111 if ( $SystemQueue && $SystemQueue->id ) {
112 $filter = $filters->{$SystemQueue->Name} || $filters->{'*'};
114 RT->Logger->error( "Wrong queue passed to RT::Extension::AttachmentFilter->CheckAttachmentFilter" );
119 $filter ||= $filters->{'*'};
125 if ( $args{'FileName'} =~ m/$filter/ ) {
126 return 1, loc("File name [_1] forbidden", $args{'FileName'});
137 =item Dynamic enforcement using javascript
143 Emmanuel Lacour, E<lt>elacour@home-dn.netE<gt>
147 All bugs should be reported via email to
149 L<bug-RT-Extension-AttachmentFilter@rt.cpan.org|mailto:bug-RT-Extension-AttachmentFilter@rt.cpan.org>
153 L<rt.cpan.org|http://rt.cpan.org/Public/Dist/Display.html?Name=RT-Extension-AttachmentFilter>.
155 =head1 LICENSE AND COPYRIGHT
157 This software is Copyright (c) 2016 by Emmanuel Lacour <elacour@home-dn.net>
159 This is free software, licensed under:
161 The GNU General Public License, Version 2, June 1991