/usr/share/perl5/EBox/Squid/Model/MIME.pm is in zentyal-squid 2.3.11+quantal1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | # Copyright (C) 2009-2012 eBox Technologies S.L.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package EBox::Squid::Model::MIME;
use base 'EBox::Model::DataTable';
use strict;
use warnings;
use EBox;
use EBox::Gettext;
use EBox::Types::Boolean;
use EBox::Types::Text;
use EBox::Exceptions::Internal;
use Perl6::Junction qw(all);
use constant DEFAULT_MIME_TYPES => qw(
audio/mpeg audio/x-mpeg audio/x-pn-realaudio audio/x-wav
video/mpeg video/x-mpeg2 video/acorn-replay video/quicktime
video/x-msvideo video/msvideo application/gzip
application/x-gzip application/zip application/compress
application/x-compress application/java-vm
application/x-shockwave-flash application/x-shockwave-flash2-preview
application/futuresplash image/vnd.rn-realflash
);
sub new
{
my $class = shift;
my $self = $class->SUPER::new(@_);
bless $self, $class;
return $self;
}
sub _tableHeader
{
my @tableHeader =
(
new EBox::Types::Text(
fieldName => 'MIMEType',
printableName => __('MIME Type'),
unique => 1,
editable => 1,
optional => 0,
),
new EBox::Types::Boolean(
fieldName => 'allowed',
printableName => __('Allow'),
optional => 0,
editable => 1,
defaultValue => 1,
),
);
return \@tableHeader;
}
# Method: syncRows
#
# Overrides <EBox::Model::DataTable::syncRows>
#
sub syncRows
{
my ($self, $currentRows) = @_;
unless (@{$currentRows}) {
# if there are no rows, we have to add them
foreach my $type (DEFAULT_MIME_TYPES) {
$self->add(MIMEType => $type);
}
return 1;
} else {
return 0;
}
}
sub validateTypedRow
{
my ($self, $action, $params_r) = @_;
if (exists $params_r->{MIMEType} ) {
my $type = $params_r->{MIMEType}->value();
$self->checkMimeType($type);
}
}
# Function: bannedMimeTypes
#
# Fetch the banned MIME types
#
# Returns:
#
# Array ref - containing the MIME types
sub banned
{
my ($self) = @_;
my @banned = @{$self->findAllValue(allowed => 0)};
@banned = map { $self->row($_)->valueByName('MIMEType') } @banned;
return \@banned;
}
# A MIME type follows this syntax: type/subtype
# The current registrated types are: <http://www.iana.org/assignments/media-types/index.html>
#
my @ianaMimeTypes = ("application",
"audio",
"example",
"image",
"message",
"model",
"multipart",
"text",
"video",
"[Xx]-.*" );
my $allIanaMimeType = all @ianaMimeTypes;
sub checkMimeType
{
my ($self, $type) = @_;
my ($mainType, $subType) = split '/', $type, 2;
if (not defined $subType) {
throw EBox::Exceptions::InvalidData(
data => __('MIME Type'),
value => $type,
advice => __('A MIME Type must follow this syntax: type/subtype'),
);
}
if ($mainType ne $allIanaMimeType) {
throw EBox::Exceptions::InvalidData(
data => __('MIME Type'),
value => $type,
advice => __x(
'{type} is not a valid IANA type',
type => $mainType,
)
);
}
if (not $subType =~ m{^[\w\-\d\.+]+$} ) {
throw EBox::Exceptions::InvalidData(
data => __('MIME Type'),
value => $type,
advice => __x(
'{t} subtype has a wrong syntax',
t => $subType,
)
);
}
return 1;
}
sub _table
{
my ($self) = @_;
my $dataTable =
{
tableName => 'MIME',
modelDomain => 'Squid',
printableTableName => __('MIME types'),
defaultActions => [ 'add', 'del', 'editField', 'changeView' ],
checkAll => [ 'allowed' ],
tableDescription => $self->_tableHeader(),
class => 'dataTable',
order => 0,
rowUnique => 1,
printableRowName => __('MIME type'),
help => __("Allow/Deny the HTTP traffic of the files which the given MIME types. MIME types not listed here are allowed.\nThe filter needs a 'filter' policy to be in effect"),
messages => {
add => __('MIME type added'),
del => __('MIME type removed'),
update => __('MIME type updated'),
},
sortedBy => 'MIMEType',
};
}
# Method: viewCustomizer
#
# Overrides <EBox::Model::DataTable::viewCustomizer>
# to show breadcrumbs
sub viewCustomizer
{
my ($self) = @_;
my $custom = $self->SUPER::viewCustomizer();
$custom->setHTMLTitle([]);
return $custom;
}
1;
|