This file is indexed.

/usr/share/perl5/EBox/OpenVPN/Model/ClientConfiguration.pm is in zentyal-openvpn 2.3.10+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
# Copyright (C) 2008-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

# Class: EBox::OpenVPN::Model::ClientConfiguration
#

package EBox::OpenVPN::Model::ClientConfiguration;
use base 'EBox::Model::DataForm';

use strict;
use warnings;

use Error qw(:try);

use EBox::Global;
use EBox::Gettext;
use EBox::Validate qw(:all);
use EBox::Exceptions::External;
use EBox::Exceptions::DataExists;

use EBox::Types::Select;
use EBox::Types::Host;
use EBox::Types::Password;
use EBox::Types::File;
use EBox::Types::Port;
use EBox::Types::HostIP;

use EBox::OpenVPN::Types::PortAndProtocol;
use EBox::OpenVPN::Client::ValidateCertificate;

sub new
{
    my $class = shift;
    my %parms = @_;

    my $self = $class->SUPER::new(@_);
    bless($self, $class);

    return $self;
}

sub _table
{
    # allowDownload option is disabled until the bug with allowDownload +
    # DataForm is fixed (syntoms: undef $type->row())
    my @tableHead = (
         new EBox::Types::Host(
                               fieldName => 'server',
                               printableName => __('Server'),
                               editable => 1,
                              ),
         new EBox::OpenVPN::Types::PortAndProtocol(
                                                    fieldName => 'serverPortAndProtocol',
                                                    printableName => __('Server port'),
                                                    editable => 1,
                                                  ),
         new EBox::Types::File(
                               fieldName => 'caCertificate',
                               printableName => __("CA's certificate"),
                               editable => 1,
                               dynamicPath => \&_privateFilePath,
                               showFileWhenEditing => 1,
#                               allowDownload => 1,
                               user          => 'root',
                               allowUnsafeChars => 1,
                              ),
         new EBox::Types::File(
                               fieldName => 'certificate',
                               printableName => __("Client's certificate"),
                               editable => 1,
                               dynamicPath => \&_privateFilePath,
                               showFileWhenEditing => 1,
#                               allowDownload => 1,
                               user          => 'root',
                               allowUnsafeChars => 1,
                              ),
         new EBox::Types::File(
                               fieldName => 'certificateKey',
                               printableName => __("Client's private key"),
                               editable => 1,
                               dynamicPath => \&_privateFilePath,
                               showFileWhenEditing => 1,
#                               allowDownload => 1,
                               user          => 'root',
                               allowUnsafeChars => 1,
                              ),
         new EBox::Types::Boolean(
                 fieldName =>  'tunInterface',
                 printableName => __('TUN interface'),
                 editable => 1,
                 defaultValue => 0,
                 ),
        new EBox::Types::Password(
                                  fieldName => 'ripPasswd',
                                  printableName => __('Server tunnel password'),
                                  minLength => 6,
                                  editable => 1,
                                 ),
          new EBox::Types::Port(
                                  fieldName => 'lport',
                                  printableName => __('Bind port for client'),
                                  minLength => 6,
                                  editable => 1,
                                  optional => 1,
                                  hidden => 1,
                                 ),
         new EBox::Types::HostIP(
                 fieldName  => 'localAddr',
                 printableName => __('Bind address for client'),
                 optional => 1,
                 editable => 1,
                 hidden => 1,
                 ),
         new EBox::Types::Text(
                 fieldName  => 'routeUpCmd',
                 printableName => __('Command to execute after routes are set'),
                 optional => 1,
                 editable => 1,
                 hidden => 1,
                 ),
        );

    my $dataTable =
        {
            'tableName'               => __PACKAGE__->nameFromClass(),
            'printableTableName' => __('Client configuration'),
            'automaticRemove' => 1,
            'defaultController' => '/OpenVPN/Controller/ClientConfiguration',
            'defaultActions' => ['add', 'del', 'editField',  'changeView' ],
            'tableDescription' => \@tableHead,
            'class' => 'dataTable',
            'printableRowName' => __('client'),
            'modelDomain' => 'OpenVPN',
        };

    return $dataTable;
}



sub name
{
    __PACKAGE__->nameFromClass(),
}

sub configured
{
    my ($self) = @_;

    my $row = $self->row();

    $row->valueByName('server') or return 0;
    my $serverService = $row->elementByName('serverPortAndProtocol');
    $serverService->port()      or return 0;
    $serverService->protocol()  or return 0;

    $row->elementByName('caCertificate')->exist()  or return 0;
    $row->elementByName('certificate')->exist()    or return 0;
    $row->elementByName('certificateKey')->exist() or return 0;

    $row->valueByName('ripPasswd')                 or return 0;

    return 1;
}

sub validateTypedRow
{
    my ($self, $action, $params_r, $actual_r) = @_;


    if (exists $params_r->{server}) {
        EBox::OpenVPN::Client->checkServer($params_r->{server}->value());
    }

    $self->_validateNoCertParams($action, $params_r, $actual_r);
    $self->_validateCerts($action, $params_r, $actual_r);
}


sub _validateNoCertParams
{
    my ($self, $action, $params_r, $actual_r) = @_;
    my @mandatoryParams = qw(server serverPortAndProtocol ripPasswd);
    foreach my $param (@mandatoryParams) {
        my $paramChanged = exists $params_r->{$param};
        if ( $paramChanged and $params_r->{$param}->printableValue()) {
            next;
        }
        elsif ((not $paramChanged) and (exists $actual_r->{$param}) ) {
            if ($actual_r->{$param}->printableValue()) {
                next;
            }
        }

        my $printableName = $actual_r->{$param}->printableName();
        throw EBox::Exceptions::MissingArgument($printableName);
    }

}

sub _validateCerts
{
    my ($self, $action, $params_r, $actual_r) = @_;

    my %path;

    my $path;
    my $noChanges = 1;

    my @fieldNames = qw(caCertificate certificate certificateKey);
    foreach my $fieldName (@fieldNames) {
        my $certPath;
        if ( exists $params_r->{$fieldName} ) {
            $noChanges = 0;
            $certPath =  $params_r->{$fieldName}->tmpPath();
        } else {
                my $file =  $actual_r->{$fieldName};
                if (not $file->exist()) {
                    throw EBox::Exceptions::External(
                        __x(
                            'No file supplied or already set for {f}',
                            f => $file->printableName
                           )
                       );
                }
                $certPath = $file->path();
            }
        $path{$fieldName} = $certPath;
    }


    return if ($noChanges);

    EBox::OpenVPN::Client::ValidateCertificate::check(
            $path{caCertificate},
            $path{certificate},
            $path{certificateKey}
            );
}


sub _privateFilePath
{
    my ($file) = @_;

    return unless (defined($file));
    return unless (defined($file->model()));

    my $row     = $file->model()->row();
    return unless defined $row;

    my $clientName = __PACKAGE__->_clientName($row);
    $clientName or
        return;

    my $dir      = EBox::OpenVPN::Client->privateDirForName($clientName);
    my $fileName = $file->fieldName();

    return "$dir/$fileName";
}

sub updatedRowNotify
{
    my ($self, $row, $oldRow, $force) = @_;

    # The interface type resides in the ServerModels so we must set it in the
    # parentRow
    my $toSet = $row->valueByName('tunInterface') ? 'tun' : 'tap';
    my $parentRow = $self->parentRow();
    my $ifaceType = $parentRow->elementByName('interfaceType');
    if ($ifaceType->value() ne $toSet) {
        $ifaceType->setValue($toSet);
        $parentRow->store();
    }
}

# Method: pageTitle
#
#   Overrides <EBox::Model::DataTable::pageTitle>
#   to show the name of the domain
sub pageTitle
{
    my ($self) = @_;

    return $self->parentRow()->printableValueByName('name');
}

sub _clientName
{
    my ($package, $row) = @_;

    my $parent  = $row->parentRow();

    $parent or
        return undef;

    return $parent->elementByName('name')->value();
}

1;