This file is indexed.

/usr/share/otrs/Kernel/Modules/AdminGenericInterfaceMappingXSLT.pm is in otrs2 6.0.5-1.

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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# --
# Copyright (C) 2001-2018 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package Kernel::Modules::AdminGenericInterfaceMappingXSLT;

use strict;
use warnings;

use Kernel::System::VariableCheck qw(:all);
use Kernel::Language qw(Translatable);

our $ObjectManagerDisabled = 1;

sub new {
    my ( $Type, %Param ) = @_;

    my $Self = {%Param};
    bless( $Self, $Type );

    # Set possible values handling strings.
    $Self->{EmptyString}   = '_RegEx_EmptyString_Dont_Use_It_String_Please';
    $Self->{DeletedString} = '_RegEx_DeletedString_Dont_Use_It_String_Please';

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;

    my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request');

    my $WebserviceID = $ParamObject->GetParam( Param => 'WebserviceID' ) || '';
    my $Operation    = $ParamObject->GetParam( Param => 'Operation' )    || '';
    my $Invoker      = $ParamObject->GetParam( Param => 'Invoker' )      || '';
    my $Direction    = $ParamObject->GetParam( Param => 'Direction' )    || '';

    my $CommunicationType = IsStringWithData($Operation) ? 'Provider'  : 'Requester';
    my $ActionType        = IsStringWithData($Operation) ? 'Operation' : 'Invoker';
    my $Action = $Operation || $Invoker;

    # Set mapping direction for display.
    my $MappingDirection = $Direction eq 'MappingOutbound'
        ? 'XSLT Mapping for Outgoing Data'
        : 'XSLT Mapping for Incoming Data';

    # Get configured Actions.
    my $ActionsConfig = $Kernel::OM->Get('Kernel::Config')->Get( 'GenericInterface::' . $ActionType . '::Module' );

    my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');

    # Make sure required libraries (XML::LibXML and XML::LibXSLT) are installed.
    LIBREQUIRED:
    for my $LibRequired (qw(XML::LibXML XML::LibXSLT)) {
        my $LibFound = $Kernel::OM->Get('Kernel::System::Main')->Require(
            $LibRequired,
        );
        next LIBREQUIRED if $LibFound;

        return $LayoutObject->ErrorScreen(
            Message => $LayoutObject->{LanguageObject}->Translate( 'Could not find required library %s', $LibRequired ),
        );
    }

    # Check for valid action backend.
    if ( !IsHashRefWithData($ActionsConfig) ) {
        return $LayoutObject->ErrorScreen(
            Message => $LayoutObject->{LanguageObject}
                ->Translate( 'Could not get registered configuration for action type %s', $ActionType ),
        );
    }

    # Check for WebserviceID.
    if ( !$WebserviceID ) {
        return $LayoutObject->ErrorScreen(
            Message => Translatable('Need WebserviceID!'),
        );
    }

    my $WebserviceObject = $Kernel::OM->Get('Kernel::System::GenericInterface::Webservice');

    # Get web service con configuration.
    my $WebserviceData = $WebserviceObject->WebserviceGet( ID => $WebserviceID );

    # Check for valid web service configuration.
    if ( !IsHashRefWithData($WebserviceData) ) {
        return $LayoutObject->ErrorScreen(
            Message =>
                $LayoutObject->{LanguageObject}->Translate( 'Could not get data for WebserviceID %s', $WebserviceID ),
        );
    }

    # Get the action type (back-end),
    my $ActionBackend = $WebserviceData->{Config}->{$CommunicationType}->{$ActionType}->{$Action}->{'Type'};

    # Check for valid action backend.
    if ( !$ActionBackend ) {
        return $LayoutObject->ErrorScreen(
            Message =>
                $LayoutObject->{LanguageObject}->Translate( 'Could not get backend for %s %s', $ActionType, $Action ),
        );
    }

    # Get the configuration dialog for the action.
    my $ActionFrontendModule = $ActionsConfig->{$ActionBackend}->{'ConfigDialog'};

    my $WebserviceName = $WebserviceData->{Name};

    # ------------------------------------------------------------ #
    # sub-action Change: load web service and show edit screen
    # ------------------------------------------------------------ #
    if ( $Self->{Subaction} eq 'Change' ) {

        # Recreate structure for edit.
        my %Mapping;
        my $MappingConfig = $WebserviceData->{Config}->{$CommunicationType}->
            {$ActionType}->{$Action}->{$Direction}->{Config};

        $Mapping{Template}              = $MappingConfig->{Template};
        $Mapping{DataInclude}           = $MappingConfig->{DataInclude};
        $Mapping{PreRegExFilter}        = $MappingConfig->{PreRegExFilter};
        $Mapping{PreRegExValueCounter}  = $MappingConfig->{PreRegExValueCounter};
        $Mapping{PostRegExFilter}       = $MappingConfig->{PostRegExFilter};
        $Mapping{PostRegExValueCounter} = $MappingConfig->{PostRegExValueCounter};

        return $Self->_ShowEdit(
            %Param,
            WebserviceID         => $WebserviceID,
            WebserviceName       => $WebserviceName,
            WebserviceData       => \%Mapping,
            Operation            => $Operation,
            Invoker              => $Invoker,
            Direction            => $Direction,
            MappingDirection     => $MappingDirection,
            CommunicationType    => $CommunicationType,
            ActionType           => $ActionType,
            Action               => $Action,
            ActionFrontendModule => $ActionFrontendModule,
            Subaction            => 'Change',
        );
    }

    # ------------------------------------------------------------ #
    # sub-action ChangeAction: write config and return to overview
    # ------------------------------------------------------------ #
    else {

        # Challenge token check for write action.
        $LayoutObject->ChallengeTokenCheck();

        # Get parameter from web browser.
        my $GetParam = $Self->_GetParams();

        # If there is an error return to edit screen.
        if ( $GetParam->{Error} ) {
            return $Self->_ShowEdit(
                %Param,
                WebserviceID         => $WebserviceID,
                WebserviceName       => $WebserviceName,
                WebserviceData       => $GetParam,
                Operation            => $Operation,
                Invoker              => $Invoker,
                Direction            => $Direction,
                MappingDirection     => $MappingDirection,
                CommunicationType    => $CommunicationType,
                ActionType           => $ActionType,
                Action               => $Action,
                ActionFrontendModule => $ActionFrontendModule,
                Subaction            => 'Change',
            );
        }

        my %NewMapping;
        $NewMapping{Template}              = $GetParam->{Template};
        $NewMapping{DataInclude}           = $GetParam->{DataInclude};
        $NewMapping{PreRegExFilter}        = $GetParam->{PreRegExFilter};
        $NewMapping{PreRegExValueCounter}  = $GetParam->{PreRegExValueCounter};
        $NewMapping{PostRegExFilter}       = $GetParam->{PostRegExFilter};
        $NewMapping{PostRegExValueCounter} = $GetParam->{PostRegExValueCounter};

        # Set new mapping.
        $WebserviceData->{Config}->{$CommunicationType}->{$ActionType}->{$Action}->{$Direction}->{Config}
            = \%NewMapping;

        # Otherwise save configuration and return to overview screen.
        my $Success = $WebserviceObject->WebserviceUpdate(
            ID      => $WebserviceID,
            Name    => $WebserviceData->{Name},
            Config  => $WebserviceData->{Config},
            ValidID => $WebserviceData->{ValidID},
            UserID  => $Self->{UserID},
        );

        # Check for successful web service update.
        if ( !$Success ) {
            return $LayoutObject->ErrorScreen(
                Message => $LayoutObject->{LanguageObject}
                    ->Translate( 'Could not update configuration data for WebserviceID %s', $WebserviceID ),
            );
        }

        # If the user would like to continue editing the invoker config, just redirect to the edit screen.
        my $RedirectURL;
        if (
            defined $ParamObject->GetParam( Param => 'ContinueAfterSave' )
            && ( $ParamObject->GetParam( Param => 'ContinueAfterSave' ) eq '1' )
            )
        {

            $RedirectURL =
                'Action='
                . $Self->{Action}
                . ';Subaction=Change;WebserviceID='
                . $WebserviceID
                . ";$ActionType="
                . $LayoutObject->LinkEncode($Action)
                . ';Direction='
                . $Direction
                . ';';
        }
        else {

            # Otherwise return to overview.
            $RedirectURL =
                'Action='
                . $ActionFrontendModule
                . ';Subaction=Change;'
                . ";$ActionType="
                . $LayoutObject->LinkEncode($Action)
                . ';WebserviceID='
                . $WebserviceID
                . ';';
        }

        return $LayoutObject->Redirect(
            OP => $RedirectURL,
        );
    }
}

sub _ShowEdit {
    my ( $Self, %Param ) = @_;

    # Set action for go back button.
    $Param{LowerCaseActionType} = lc $Param{ActionType};

    my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');

    my $Output = $LayoutObject->Header();
    $Output .= $LayoutObject->NavigationBar();

    my $MappingConfig = $Param{WebserviceData};
    my %Error;
    if ( defined $Param{WebserviceData}->{Error} ) {
        %Error = %{ $Param{WebserviceData}->{Error} };
    }

    # Add rich text editor config.
    if ( $LayoutObject->{BrowserRichText} ) {
        $LayoutObject->SetRichTextParameters(
            Data => {
                %Param,
                RichTextHeight => '600',
                RichTextWidth  => '99%',
                RichTextType   => 'CodeMirror',
            },
        );
    }

    # Render pre regex filters.
    $Self->_RegExFiltersOutput(
        %{$MappingConfig},
        Type => 'Pre',
    );

    my %DataIncludeOptionMap = (
        Requester => {
            MappingOutbound => [
                {
                    Key   => 'RequesterRequestInput',
                    Value => Translatable('Outgoing request data before processing') . ' (RequesterRequestInput)',
                },
                {
                    Key   => 'RequesterRequestPrepareOutput',
                    Value => Translatable('Outgoing request data before mapping') . ' (RequesterRequestPrepareOutput)',
                },
            ],
            MappingInbound => [
                {
                    Key   => 'RequesterRequestInput',
                    Value => Translatable('Outgoing request data before processing') . ' (RequesterRequestInput)',
                },
                {
                    Key   => 'RequesterRequestPrepareOutput',
                    Value => Translatable('Outgoing request data before mapping') . ' (RequesterRequestPrepareOutput)',
                },
                {
                    Key   => 'RequesterRequestMapOutput',
                    Value => Translatable('Outgoing request data after mapping') . ' (RequesterRequestMapOutput)',
                },
                {
                    Key   => 'RequesterResponseInput',
                    Value => Translatable('Incoming response data before mapping') . ' (RequesterResponseInput)',
                },
                {
                    Key   => 'RequesterErrorHandlingOutput',
                    Value => Translatable('Outgoing error handler data after error handling')
                        . ' (RequesterErrorHandlingOutput)',
                },
            ],
        },
        Provider => {
            MappingOutbound => [
                {
                    Key   => 'ProviderRequestInput',
                    Value => Translatable('Incoming request data before mapping') . ' (ProviderRequestInput)',
                },
                {
                    Key   => 'ProviderRequestMapOutput',
                    Value => Translatable('Incoming request data after mapping') . ' (ProviderRequestMapOutput)',
                },
                {
                    Key   => 'ProviderResponseInput',
                    Value => Translatable('Outgoing response data before mapping') . ' (ProviderResponseInput)',
                },
                {
                    Key   => 'ProviderErrorHandlingOutput',
                    Value => Translatable('Outgoing error handler data after error handling')
                        . ' (ProviderErrorHandlingOutput)',
                },
            ],
            MappingInbound => [
                {
                    Key   => 'ProviderRequestInput',
                    Value => Translatable('Incoming request data before mapping') . ' (ProviderRequestInput)',
                },
            ],
        },
    );
    $Param{DataIncludeSelect} = $LayoutObject->BuildSelection(
        Data         => $DataIncludeOptionMap{ $Param{CommunicationType} }->{ $Param{Direction} },
        Name         => 'DataInclude',
        SelectedID   => $MappingConfig->{DataInclude},
        PossibleNone => 1,
        Translation  => 1,
        Multiple     => 1,
        Class        => 'Modernize W50pc',
    );

    $LayoutObject->Block(
        Name => 'ConfigBlock',
        Data => {},
    );
    $LayoutObject->Block(
        Name => 'ConfigBlockTemplate',
        Data => {
            %Param,
            Template      => $MappingConfig->{Template},
            TemplateError => $Error{Template} || '',
        },
    );

    # Render post regex filters.
    $Self->_RegExFiltersOutput(
        %{$MappingConfig},
        Type => 'Post',
    );

    $Output .= $LayoutObject->Output(
        TemplateFile => 'AdminGenericInterfaceMappingXSLT',
        Data         => {
            %Param,
        },
    );

    $Output .= $LayoutObject->Footer();
    return $Output;
}

sub _GetParams {
    my ( $Self, %Param ) = @_;

    my $GetParam;

    my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request');

    # Get parameters from web browser.
    $GetParam->{Template} = $ParamObject->GetParam( Param => 'Template' ) || '';
    my @DataInclude = $ParamObject->GetArray( Param => 'DataInclude' );
    $GetParam->{DataInclude} = \@DataInclude;

    # Check validity.
    my $LibXML  = XML::LibXML->new();
    my $LibXSLT = XML::LibXSLT->new();
    my ( $StyleDoc, $StyleSheet );
    eval {
        $StyleDoc = XML::LibXML->load_xml(
            string   => $GetParam->{Template},
            no_cdata => 1,
        );
    };
    if ( !$StyleDoc ) {
        $GetParam->{Error}->{Template} = 'ServerError';
    }
    eval {
        my $LibXSLT = XML::LibXSLT->new();
        $StyleSheet = $LibXSLT->parse_stylesheet($StyleDoc);
    };
    if ( !$StyleSheet ) {
        $GetParam->{Error}->{Template} = 'ServerError';
    }

    # Get RegEx params.
    my %RegExFilterConfig;
    TYPE:
    for my $Type (qw(Pre Post)) {
        my $ValueCounter = $ParamObject->GetParam( Param => $Type . 'ValueCounter' ) // 0;
        next TYPE if !$ValueCounter;

        my $EmptyValueCounter = 0;
        my @RegExConfig;
        VALUEINDEX:
        for my $ValueIndex ( 1 .. $ValueCounter ) {
            my $Key = $ParamObject->GetParam( Param => $Type . 'Key' . '_' . $ValueIndex ) // '';

            # Check if key was deleted by the user and skip it.
            next VALUEINDEX if $Key eq $Self->{DeletedString};

            # Check if the original value is empty.
            if ( !IsStringWithData($Key) ) {

                # Change the empty value to a predefined string.
                $Key = $Self->{EmptyString} . $EmptyValueCounter++;
                $GetParam->{Error}->{ $Type . 'RegExFilter' }->{$Key} = 1;
            }

            push @RegExConfig, {
                Search  => $Key,
                Replace => $ParamObject->GetParam( Param => $Type . 'Value' . '_' . $ValueIndex ) // '',
            };
        }

        $GetParam->{ $Type . 'RegExFilter' }       = \@RegExConfig;
        $GetParam->{ $Type . 'RegExValueCounter' } = scalar @RegExConfig;
    }

    return $GetParam;
}

sub _RegExFiltersOutput {
    my ( $Self, %Param ) = @_;

    my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');

    my @RegExFilter;
    if ( IsArrayRefWithData( $Param{ $Param{Type} . 'RegExFilter' } ) ) {
        @RegExFilter = @{ $Param{ $Param{Type} . 'RegExFilter' } };
    }

    $LayoutObject->Block(
        Name => 'ConfigBlock',
        Data => {},
    );
    $LayoutObject->Block(
        Name => 'ConfigBlockRegExFilter',
        Data => {
            Type          => $Param{Type},
            ValueCounter  => $Param{ $Param{Type} . 'RegExValueCounter' } // 0,
            DeletedString => $Self->{DeletedString},
            Collapsed     => !@RegExFilter ? 'Collapsed' : undef,
        },
    );

    # Create the possible values template.
    $LayoutObject->Block(
        Name => 'ValueTemplate',
        Data => {
            %Param,
        },
    );

    return 1 if !@RegExFilter;

    # Output the possible entries and errors within (if any).
    my $ValueCounter = 1;
    for my $RegEx (@RegExFilter) {

        # Needed for server side validation.
        my $KeyError;
        my $KeyErrorStrg;

        # To set the correct original value.
        my $KeyClone = $RegEx->{Search};

        # Check for errors.
        if ( $Param{Error}->{ $Param{Type} . 'RegExFilter' }->{ $RegEx->{Search} } ) {

            # If the original value was empty it has been changed in _GetParams to a predefined
            #   string and need to be set to empty again.
            $KeyClone = '';

            # Set the error class.
            $KeyError     = 'ServerError';
            $KeyErrorStrg = Translatable('This field is required.');
        }

        # Create a value map row.
        $LayoutObject->Block(
            Name => 'ValueRow',
            Data => {
                Type         => $Param{Type},
                KeyError     => $KeyError,
                KeyErrorStrg => $KeyErrorStrg || Translatable('This field is required.'),
                Key          => $KeyClone,
                ValueCounter => $ValueCounter,
                Value        => $RegEx->{Replace},
            },
        );
    }
    continue {
        ++$ValueCounter;
    }

    return 1;
}

1;