/usr/share/perl5/EBox/CA/Model/Certificates.pm is in zentyal-ca 2.3.6+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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | # 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::CA::Model::Certificates;
# Class: EBox::CA::Model::Certificates
#
# Form to set the rollover certificates for modules
#
use base 'EBox::Model::DataTable';
use strict;
use warnings;
use EBox::Gettext;
use EBox::Global;
use EBox::Types::Text;
use EBox::Types::DomainName;
use EBox::Types::Boolean;
use EBox::CA;
# Group: Public methods
# Constructor: new
#
# Create the new Certificates model
#
# Overrides:
#
# <EBox::Model::DataTable::new>
#
# Returns:
#
# <EBox::CA::Model::Certificates> - the recently created model
#
sub new
{
my $class = shift;
my $self = $class->SUPER::new(@_);
bless ( $self, $class );
return $self;
}
# Method: precondition
#
# Check if CA has been created.
#
# Overrides:
#
# <EBox::Model::DataTable::precondition>
#
sub precondition
{
my ($self) = @_;
my $ca = EBox::Global->modInstance('ca');
return $ca->isAvailable();
}
# Method: preconditionFailMsg
#
# Returns message to be shown on precondition fail.
#
# Overrides:
#
# <EBox::Model::DataTable::preconditionFailMsg>
#
sub preconditionFailMsg
{
my ($self) = @_;
return __x('You must create a Certification Authority first. '
. 'Go to {openhref}Certification Authority{closehref} to do so',
openhref => qq{<a href='/CA/Index'>},
closehref => qq{</a>});
}
# Method: syncRows
#
# Syncronizes installed modules certificate requests with the current model.
#
# Overrides:
#
# <EBox::Model::DataTable::syncRows>
#
sub syncRows
{
my ($self, $currentRows) = @_;
my @srvs = @{EBox::CA::Certificates->srvsCerts()};
my %currentSrvs = map { $self->row($_)->valueByName('service') => 1 } @{$currentRows};
my @srvsToAdd = grep { not exists $currentSrvs{$_->{'service'}} } @srvs;
my $modified = 0;
for my $srv (@srvsToAdd) {
my $cn = exists $srv->{'defaultCN'} ? $srv->{'defaultCN'} : __('Zentyal');
my $allowCustomCN = exists $srv->{allowCustomCN} ?
$srv->{allowCustomCN} : 1;
$self->add(module => $srv->{'module'},
service => $srv->{'service'},
cn => $cn,
allowCustomCN => $allowCustomCN,
enable => 0);
$modified = 1;
}
my %srvsToAdd = map { $_->{service} => 1 } @srvs;
for my $id (@{$currentRows}) {
my $row = $self->row($id);
my $service = $row->valueByName('service');
my $module = $row->valueByName('module');
if (not exists $srvsToAdd{$service} or
not EBox::Global->modExists($module)) {
$self->removeRow($id);
$modified = 1;
}
}
return $modified;
}
# Method: disableService
#
# Disables given service in the model.
#
sub disableService
{
my ($self, $service) = @_;
my $row = $self->find(service => $service);
if ($row) {
$row->elementByName('enable')->setValue(0);
$row->store();
}
}
# Method: setServiceRO
#
# Set service as read-only.
#
sub setServiceRO
{
my ($self, $service, $ro) = @_;
my $row = $self->find(service => $service);
if ($row) {
$row->setReadOnly($ro);
$row->store();
}
}
# Method: updateCN
#
# Updates the CN in the certificate for the given service.
#
sub updateCN
{
my ($self, $service, $cn) = @_;
my $row = $self->find(service => $service);
if ($row) {
$row->elementByName('cn')->setValue($cn);
$row->store();
}
}
# Method: certUsedByService
#
# Returns if a given certificate Common Name is used by any
# of the services in the model.
#
# Returns:
#
# True if the certificate is used, false otherwise
#
sub certUsedByService
{
my ($self, $cn) = @_;
my $row = $self->find(cn => $cn);
return 1 if ($row);
return 0;
}
# Method: cnByService
#
# Returns the certificate Common Name used by a service.
#
# Returns:
#
# The Common Name if exists, undef otherwise.
#
sub cnByService
{
my ($self, $service) = @_;
my $row = $self->find(service => $service);
return $row->valueByName('cn') if ($row);
return undef;
}
# Method: isEnabledService
#
# Returns if a given service is enabled in the model.
#
# Returns:
#
# True if the service is enabled, undef otherwise
#
sub isEnabledService
{
my ($self, $service) = @_;
my $row = $self->find(service => $service);
return $row->valueByName('enable') if ($row);
return undef;
}
# Group: Private methods
# Method: _table
#
# Overrides:
#
# <EBox::Model::DataTable::_table>
#
sub _table
{
my @tableHeader =
(
new EBox::Types::Text(
fieldName => 'module',
printableName => __('Module'),
unique => 0,
editable => 0,
filter => sub {
my ($self) = @_;
my $modName = $self->value();
my $mod = EBox::Global->modInstance($modName);
# return modname if the module was uninstalled
return $modName unless defined ($mod);
return $mod->title();
},
),
new EBox::Types::Text(
fieldName => 'service',
printableName => __('Service'),
unique => 1,
editable => 0,
),
new EBox::Types::DomainName(
fieldName => 'cn',
printableName => __('Common Name'),
unique => 0,
editable => 1,
),
new EBox::Types::Boolean(
fieldName => 'enable',
printableName => __('Enable'),
editable => 1,
help => __('Generate the certificate using CA '
. 'with the common name set above'),
),
new EBox::Types::Boolean(
fieldName => 'allowCustomCN',
printableName => 'allowCustomCN',
editable => 0,
hidden => 1,
defaultValue => 1,
),
);
my $dataTable =
{
tableName => 'Certificates',
printableTableName => __('Services Certificates'),
printableRowName => __('certificate'),
defaultActions => [ 'editField', 'changeView' ],
tableDescription => \@tableHeader,
class => 'dataTable',
sortedBy => 'module',
modelDomain => 'CA',
help => __('Here you may set certificates from this CA for those '
. 'secure services managed by Zentyal'),
};
return $dataTable;
}
sub validateTypedRow
{
my ($self, $action, $params_r, $actual_r) = @_;
if ($action eq 'update') {
if (exists $params_r->{cn}) {
if (not $actual_r->{allowCustomCN}->value()) {
throw EBox::Exceptions::External(
__('This service does not allow to change the certificate common name')
);
}
}
}
}
sub updatedRowNotify
{
my ($self, $row, $oldRow, $force) = @_;
my $modName = $row->valueByName('module');
my $mod = EBox::Global->modInstance($modName);
$mod->setAsChanged();
}
1;
|