File: InterfaceAgent.pm

package info (click to toggle)
otrs2 2.2.7-2lenny3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,444 kB
  • ctags: 5,808
  • sloc: perl: 129,825; xml: 16,139; sql: 11,400; sh: 1,198; makefile: 31; php: 16
file content (740 lines) | stat: -rw-r--r-- 27,989 bytes parent folder | download
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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
# --
# Kernel/System/Web/InterfaceAgent.pm - the agent interface file (incl. auth)
# Copyright (C) 2001-2007 OTRS GmbH, http://otrs.org/
# --
# $Id: InterfaceAgent.pm,v 1.23 2007/09/07 09:12:46 martin Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --

package Kernel::System::Web::InterfaceAgent;

use strict;

use vars qw($VERSION @INC);
$VERSION = '$Revision: 1.23 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;

# all framework needed modules
use Kernel::Config;
use Kernel::System::Log;
use Kernel::System::Main;
use Kernel::System::Encode;
use Kernel::System::Time;
use Kernel::System::Web::Request;
use Kernel::System::DB;
use Kernel::System::Auth;
use Kernel::System::AuthSession;
use Kernel::System::User;
use Kernel::System::Group;
use Kernel::Output::HTML::Layout;

=head1 NAME

Kernel::System::Web::InterfaceAgent - the agent web interface

=head1 SYNOPSIS

the global agent web interface (incl. auth, session, ...)

=head1 PUBLIC INTERFACE

=over 4

=cut

=item new()

create agent web interface object

    use Kernel::System::Web::InterfaceAgent;

    my $Debug = 0;
    my $InterfaceAgent = Kernel::System::Web::InterfaceAgent->new(Debug => $Debug);

=cut

sub new {
    my $Type = shift;
    my %Param = @_;

    # allocate new hash for object
    my $Self = {};
    bless ($Self, $Type);

    # get debug level
    $Self->{Debug} = $Param{Debug} || 0;

    # performance log
    $Self->{PerformanceLogStart} = time();

    # create common framework objects 1/3
    $Self->{ConfigObject} = Kernel::Config->new();
    $Self->{LogObject} = Kernel::System::Log->new(
        LogPrefix => $Self->{ConfigObject}->Get('CGILogPrefix'),
        %{$Self},
    );
    $Self->{MainObject} = Kernel::System::Main->new(%{$Self});
    $Self->{EncodeObject} = Kernel::System::Encode->new(%{$Self});
    $Self->{TimeObject} = Kernel::System::Time->new(%{$Self});
    $Self->{ParamObject} = Kernel::System::Web::Request->new(
        %{$Self},
        WebRequest => $Param{WebRequest} || 0,
    );

    # debug info
    if ($Self->{Debug}) {
        $Self->{LogObject}->Log(
            Priority => 'debug',
            Message => 'Global handle started...',
        );
    }
    return $Self;
}

=item Run()

execute the object

    $InterfaceAgent->Run();

=cut

sub Run {
    my $Self = shift;

    # get common framework params
    my %Param = ();
    # get session id
    $Param{SessionName} = $Self->{ConfigObject}->Get('SessionName') || 'SessionID';
    $Param{SessionID} = $Self->{ParamObject}->GetParam(Param => $Param{SessionName}) || '';
    # drop old session id (if exists)
    my $QueryString = $ENV{"QUERY_STRING"} || '';
    $QueryString =~ s/(\?|&|)$Param{SessionName}(=&|=.+?&|=.+?$)/&/g;
    # definde frame work params
    my $FramworkPrams = {
        Lang => '',
        Action => '',
        Subaction => '',
        RequestedURL => $QueryString,
    };
    foreach my $Key (keys %{$FramworkPrams}) {
        $Param{$Key} = $Self->{ParamObject}->GetParam(Param => $Key)
            || $FramworkPrams->{$Key};
    }

    # Check if the brwoser sends the SessionID cookie and set the SessionID-cookie
    # as SessionID! GET or POST SessionID have the lowest priority.
    if ($Self->{ConfigObject}->Get('SessionUseCookie')) {
        $Param{SessionIDCookie} = $Self->{ParamObject}->GetCookie(Key => $Param{SessionName});
        if ($Param{SessionIDCookie}) {
            $Param{SessionID} = $Param{SessionIDCookie};
        }
    }

    # create common framework objects 2/3
    $Self->{LayoutObject} = Kernel::Output::HTML::Layout->new(
        %{$Self},
        Lang => $Param{Lang},
    );

    # check common objects
    $Self->{DBObject} = Kernel::System::DB->new(%{$Self});
    if (!$Self->{DBObject}) {
        $Self->{LayoutObject}->FatalError(
            Comment => 'Please contact your admin'
        );
    }
    if ($Self->{ParamObject}->Error()) {
        $Self->{LayoutObject}->FatalError(
            Message => $Self->{ParamObject}->Error(),
            Comment => 'Please contact your admin'
        );
    }

    # create common framework objects 3/3
    $Self->{UserObject} = Kernel::System::User->new(%{$Self});
    $Self->{GroupObject} = Kernel::System::Group->new(%{$Self});
    $Self->{SessionObject} = Kernel::System::AuthSession->new(%{$Self});

    # application and add on application common objects
    my %CommonObject = %{$Self->{ConfigObject}->Get('Frontend::CommonObject')};
    foreach my $Key (keys %CommonObject) {
        if ($Self->{MainObject}->Require($CommonObject{$Key})) {
            $Self->{$Key} = $CommonObject{$Key}->new(%{$Self});
        }
        else {
            # print error
            $Self->{LayoutObject}->FatalError(
                Comment => 'Please contact your admin'
            );
        }
    }

    # get common application and add on application params
    my %CommonObjectParam = %{$Self->{ConfigObject}->Get('Frontend::CommonParam')};
    foreach my $Key (keys %CommonObjectParam) {
        $Param{$Key} = $Self->{ParamObject}->GetParam(Param => $Key) || $CommonObjectParam{$Key};
    }
    # security check Action Param (replace non word chars)
    $Param{Action} =~ s/\W//g;

    # check request type
    if ($Param{Action} eq "Login") {
        # get params
        my $PostUser = $Self->{ParamObject}->GetParam(Param => 'User') || '';
        my $PostPw = $Self->{ParamObject}->GetParam(Param => 'Password') || '';
        # create AuthObject
        my $AuthObject = Kernel::System::Auth->new(%{$Self});
        # check submited data
        my $User = $AuthObject->Auth(User => $PostUser, Pw => $PostPw);
        if ($User) {
            # get user data
            my %UserData = $Self->{UserObject}->GetUserData(User => $User, Valid => 1);
            # check needed data
            if (!$UserData{UserID} || !$UserData{UserLogin}) {
                if ($Self->{ConfigObject}->Get('LoginURL')) {
                    # redirect to alternate login
                    print $Self->{LayoutObject}->Redirect(
                        ExtURL => $Self->{ConfigObject}->Get('LoginURL')."?Reason=SystemError",
                    );
                }
                else {
                    # show need user data error message
                    $Self->{LayoutObject}->Print(
                        Output =>  \$Self->{LayoutObject}->Login(
                            Title => 'Panic!',
                            Message => 'Panic! No UserData!!!',
                            %Param,
                        ),
                    );
                    exit (0);
                }
            }
            # last login preferences update
            $Self->{UserObject}->SetPreferences(
                UserID => $UserData{UserID},
                Key => 'UserLastLogin',
                Value => $Self->{TimeObject}->SystemTime(),
            );
            # get groups rw
            my %GroupData = $Self->{GroupObject}->GroupMemberList(
                Result => 'HASH',
                Type => 'rw',
                UserID => $UserData{UserID},
            );
            foreach (keys %GroupData) {
                $UserData{"UserIsGroup[$GroupData{$_}]"} = 'Yes';
            }
            # get groups ro
            %GroupData = $Self->{GroupObject}->GroupMemberList(
                Result => 'HASH',
                Type => 'ro',
                UserID => $UserData{UserID},
            );
            foreach (keys %GroupData) {
                $UserData{"UserIsGroupRo[$GroupData{$_}]"} = 'Yes';
            }
            # create new session id
            my $NewSessionID = $Self->{SessionObject}->CreateSessionID(
                _UserLogin => $PostUser,
                _UserPw => $PostPw,
                %UserData,
                UserLastRequest => $Self->{TimeObject}->SystemTime(),
                UserType => 'User',
            );
            # set time zone offset if TimeZoneFeature is active
            if ($Self->{ConfigObject}->Get('TimeZoneUser') &&
                $Self->{ConfigObject}->Get('TimeZoneUserBrowserAutoOffset') &&
                    $Self->{LayoutObject}->{BrowserJavaScriptSupport}) {
                my $TimeOffset = $Self->{ParamObject}->GetParam(Param => 'TimeOffset') || '';
                if ($TimeOffset > 0) {
                    $TimeOffset = '-'.($TimeOffset/60);
                }
                else {
                    $TimeOffset = ($TimeOffset/60);
                    $TimeOffset =~ s/-/+/;
                }
                $Self->{UserObject}->SetPreferences(
                    UserID => $UserData{UserID},
                    Key => 'UserTimeZone',
                    Value => $TimeOffset,
                );
                $Self->{SessionObject}->UpdateSessionID(
                    SessionID => $NewSessionID,
                    Key => 'UserTimeZone',
                    Value => $TimeOffset,
                );
            }
            # create a new LayoutObject with SessionIDCookie
            my $Expires = '+'.$Self->{ConfigObject}->Get('SessionMaxTime').'s';
            if (!$Self->{ConfigObject}->Get('SessionUseCookieAfterBrowserClose')) {
                $Expires = '';
            }
            my $LayoutObject = Kernel::Output::HTML::Layout->new(
                SetCookies => {
                    SessionIDCookie => $Self->{ParamObject}->SetCookie(
                        Key => $Param{SessionName},
                        Value => $NewSessionID,
                        Expires => $Expires,
                    ),
                },
                SessionID => $NewSessionID,
                SessionName => $Param{SessionName},
                %{$Self},
            );
            # redirect with new session id and old params
            # prepare old redirect URL -- do not redirect to Login or Logout (loop)!
            if ($Param{RequestedURL} =~ /Action=(Logout|Login)/) {
                $Param{RequestedURL} = '';
            }
            # redirect with new session id
            print $LayoutObject->Redirect(OP => "$Param{RequestedURL}");
        }
        # login is valid
        else {
            if ($Self->{ConfigObject}->Get('LoginURL')) {
                # redirect to alternate login
                $Param{RequestedURL} = $Self->{LayoutObject}->LinkEncode($Param{RequestedURL});
                print $Self->{LayoutObject}->Redirect(
                    ExtURL => $Self->{ConfigObject}->Get('LoginURL').
                        "?Reason=LoginFailed&RequestedURL=$Param{RequestedURL}",
                );
            }
            else {
                # show normal login
                $Self->{LayoutObject}->Print(
                    Output =>  \$Self->{LayoutObject}->Login(
                        Title => 'Login',
                        Message => $Self->{LogObject}->GetLogEntry(
                            Type => 'Info',
                            What => 'Message',
                            ) || 'Login failed! Your username or password was entered incorrectly.',
                        User => $User,
                        %Param,
                    ),
                );
            }
        }
    }
    # Logout
    elsif ($Param{Action} eq "Logout") {
        if ($Self->{SessionObject}->CheckSessionID(SessionID => $Param{SessionID})) {
            # get session data
            my %UserData = $Self->{SessionObject}->GetSessionIDData(
                SessionID => $Param{SessionID},
            );
            # create new LayoutObject with new '%Param' and '%UserData'
            $Self->{LayoutObject} = Kernel::Output::HTML::Layout->new(
                SetCookies => {
                    SessionIDCookie => $Self->{ParamObject}->SetCookie(
                        Key => $Param{SessionName},
                        Value => '',
                    ),
                },
                %{$Self},
                %Param,
                %UserData,
            );
            # remove session id
            if ($Self->{SessionObject}->RemoveSessionID(SessionID => $Param{SessionID})) {
                if ($Self->{ConfigObject}->Get('LogoutURL')) {
                    # redirect to alternate login
                    print $Self->{LayoutObject}->Redirect(
                        ExtURL => $Self->{ConfigObject}->Get('LogoutURL')."?Reason=Logout",
                    );
                }
                else {
                    # show logout screen
                    $Self->{LayoutObject}->Print(
                        Output =>  \$Self->{LayoutObject}->Login(
                            Title => 'Logout',
                            Message => 'Logout successful. Thank you for using OTRS!',
                            %Param,
                        ),
                    );
                }
            }
            else {
                $Self->{LayoutObject}->FatalError(
                    Message => 'Can`t remove SessionID',
                    Comment => 'Please contact your admin'
                );
            }
        }
        else {
            if ($Self->{ConfigObject}->Get('LoginURL')) {
                # redirect to alternate login
                $Param{RequestedURL} = $Self->{LayoutObject}->LinkEncode($Param{RequestedURL});
                print $Self->{LayoutObject}->Redirect(
                    ExtURL => $Self->{ConfigObject}->Get('LoginURL').
                        "?Reason=InvalidSessionID&RequestedURL=$Param{RequestedURL}",
                );
            }
            else {
                # show login screen
                $Self->{LayoutObject}->Print(
                    Output =>  \$Self->{LayoutObject}->Login(
                        Title => 'Logout',
                        Message => 'Invalid SessionID!',
                        %Param,
                    ),
                );
            }
        }
    }
    # user lost password
    elsif ($Param{Action} eq "LostPassword") {
        # check feature
        if (! $Self->{ConfigObject}->Get('LostPassword')) {
            # show normal login
            $Self->{LayoutObject}->Print(
                Output =>  \$Self->{LayoutObject}->Login(
                    Title => 'Login',
                    Message => 'Feature not active!',
                ),
            );
            exit 0;
        }
        # get params
        my $User = $Self->{ParamObject}->GetParam(Param => 'User') || '';
        # get user data
        my %UserData = $Self->{UserObject}->GetUserData(User => $User, Valid => 1);
        if (! $UserData{UserID}) {
            # show normal login
            $Self->{LayoutObject}->Print(
                Output =>  \$Self->{LayoutObject}->Login(
                    Title => 'Login',
                    Message => 'There is no account with that login name.',
                    %Param,
                ),
            );
            exit 0;
        }
        else {
            # get new password
            $UserData{NewPW} = $Self->{UserObject}->GenerateRandomPassword();
            # update new password
            $Self->{UserObject}->SetPassword(UserLogin => $User, PW => $UserData{NewPW});
            # send notify email
            my $EmailObject = Kernel::System::Email->new(%{$Self});
            my $Body = $Self->{ConfigObject}->Get('NotificationBodyLostPassword')
                || "New Password is: <OTRS_NEWPW>";
            my $Subject = $Self->{ConfigObject}->Get('NotificationSubjectLostPassword')
                || 'New Password!';
            foreach (keys %UserData) {
                $Body =~ s/<OTRS_$_>/$UserData{$_}/gi;
            }
            if ($EmailObject->Send(
                To => $UserData{UserEmail},
                Subject => $Subject,
                Charset => 'iso-8859-15',
                Type => 'text/plain',
                Body => $Body)
            ) {
                $Self->{LayoutObject}->Print(
                    Output =>  \$Self->{LayoutObject}->Login(
                        Title => 'Login',
                        Message => "Sent new password to: ".$UserData{"UserEmail"},
                        User => $User,
                        %Param,
                    ),
                );
                exit 0;
            }
            else {
                $Self->{LayoutObject}->FatalError(
                    Comment => 'Please contact your admin'
                );
            }
        }
    }
    # show login site
    elsif (!$Param{SessionID}) {
        # create AuthObject
        my $AuthObject = Kernel::System::Auth->new(%{$Self});
        if ($AuthObject->GetOption(What => 'PreAuth')) {
            # automatic login
            $Param{RequestedURL} = $Self->{LayoutObject}->LinkEncode($Param{RequestedURL});
            print $Self->{LayoutObject}->Redirect(
                OP => "Action=Login&RequestedURL=$Param{RequestedURL}",
            );
        }
        elsif ($Self->{ConfigObject}->Get('LoginURL')) {
            # redirect to alternate login
            $Param{RequestedURL} = $Self->{LayoutObject}->LinkEncode($Param{RequestedURL});
            print $Self->{LayoutObject}->Redirect(
                ExtURL => $Self->{ConfigObject}->Get('LoginURL').
                    "?RequestedURL=$Param{RequestedURL}",
            );
        }
        else {
            # login screen
            $Self->{LayoutObject}->Print(
                Output =>  \$Self->{LayoutObject}->Login(
                    Title => 'Login',
                    %Param,
                ),
            );
        }
    }
    # run modules if exists a version value
    elsif ($Self->{MainObject}->Require("Kernel::Modules::$Param{Action}")) {
        # check session id
        if ( !$Self->{SessionObject}->CheckSessionID(SessionID => $Param{SessionID}) ) {
            # create new LayoutObject with new '%Param'
            $Self->{LayoutObject} = Kernel::Output::HTML::Layout->new(
                SetCookies => {
                    SessionIDCookie => $Self->{ParamObject}->SetCookie(
                        Key => $Param{SessionName},
                        Value => '',
                    ),
                },
                %{$Self},
                %Param,
            );
            # create AuthObject
            my $AuthObject = Kernel::System::Auth->new(%{$Self});
            if ($AuthObject->GetOption(What => 'PreAuth')) {
                # automatic re-login
                $Param{RequestedURL} = $Self->{LayoutObject}->LinkEncode($Param{RequestedURL});
                print $Self->{LayoutObject}->Redirect(
                    OP => "?Action=Login&RequestedURL=$Param{RequestedURL}",
                );
            }
            elsif ($Self->{ConfigObject}->Get('LoginURL')) {
                # redirect to alternate login
                $Param{RequestedURL} = $Self->{LayoutObject}->LinkEncode($Param{RequestedURL});
                print $Self->{LayoutObject}->Redirect(
                    ExtURL => $Self->{ConfigObject}->Get('LoginURL').
                        "?Reason=InvalidSessionID&RequestedURL=$Param{RequestedURL}",
                );
            }
            else {
                # show login
                $Self->{LayoutObject}->Print(
                    Output =>  \$Self->{LayoutObject}->Login(
                        Title => 'Login',
                        Message => $Self->{SessionObject}->CheckSessionIDMessage(),
                        %Param,
                    ),
                );
            }
        }
        # run module
        else {
            # get session data
            my %UserData = $Self->{SessionObject}->GetSessionIDData(
                SessionID => $Param{SessionID},
            );
            # check needed data
            if (!$UserData{UserID} || !$UserData{UserLogin} || $UserData{UserType} ne 'User') {
                if ($Self->{ConfigObject}->Get('LoginURL')) {
                    # redirect to alternate login
                    print $Self->{LayoutObject}->Redirect(
                        ExtURL => $Self->{ConfigObject}->Get('LoginURL')."?Reason=SystemError",
                    );
                }
                else {
                    # show login screen
                    $Self->{LayoutObject}->Print(
                        Output =>  \$Self->{LayoutObject}->Login(
                            Title => 'Panic!',
                            Message => 'Panic! Invalid Session!!!',
                            %Param,
                        ),
                    );
                    exit (0);
                }
            }
            # check module registry
            my $ModuleReg = $Self->{ConfigObject}->Get('Frontend::Module')->{$Param{Action}};
            if (!$ModuleReg) {
                $Self->{LogObject}->Log(
                    Priority => 'error',
                    Message => "Module Kernel::Modules::$Param{Action} not registered in Kernel/Config.pm!",
                );
                $Self->{LayoutObject}->FatalError(
                    Comment => 'Please contact your admin'
                );
            }
            # module permisson check
            if (!$ModuleReg->{GroupRo} && !$ModuleReg->{Group}) {
                $Param{AccessRo} = 1;
                $Param{AccessRw} = 1;
            }
            else {
                foreach my $Permission (qw(GroupRo Group)) {
                    my $AccessOk = 0;
                    my $Group = $ModuleReg->{$Permission};
                    my $Key = "UserIs$Permission";
                    if (ref($Group) eq 'ARRAY') {
                        foreach (@{$Group}) {
                            if ($_ && $UserData{$Key."[$_]"} && $UserData{$Key."[$_]"} eq 'Yes') {
                                $AccessOk = 1;
                            }
                        }
                    }
                    else {
                        if ($Group && $UserData{$Key."[$Group]"} && $UserData{$Key."[$Group]"} eq 'Yes') {
                            $AccessOk = 1;
                        }
                    }
                    if ($Permission eq 'Group' && $AccessOk) {
                        $Param{AccessRo} = 1;
                        $Param{AccessRw} = 1;
                    }
                    elsif ($Permission eq 'GroupRo' && $AccessOk) {
                        $Param{AccessRo} = 1;
                    }
                }
            }
            if (!$Param{AccessRo} && !$Param{AccessRw} || !$Param{AccessRo} && $Param{AccessRw}) {
                print $Self->{LayoutObject}->NoPermission(
                    Message => "No Permission to use this frontend module!",
                );
                exit (0);
            }
            # create new LayoutObject with new '%Param' and '%UserData'
            $Self->{LayoutObject} = Kernel::Output::HTML::Layout->new(
                %{$Self},
                %Param,
                %UserData,
                ModuleReg => $ModuleReg,
            );
            # updated last request time
            $Self->{SessionObject}->UpdateSessionID(
                SessionID => $Param{SessionID},
                Key => 'UserLastRequest',
                Value => $Self->{TimeObject}->SystemTime(),
            );
            # pre application module
            my $PreModule = $Self->{ConfigObject}->Get('PreApplicationModule');
            if ($PreModule) {
                my %PreModuleList = ();
                if (ref($PreModule) eq 'HASH') {
                    %PreModuleList = %{$PreModule};
                }
                else {
                    $PreModuleList{Init} = $PreModule;
                }
                foreach my $PreModuleKey (sort keys %PreModuleList) {
                    my $PreModule = $PreModuleList{$PreModuleKey};
                    if ($PreModule && $Self->{MainObject}->Require($PreModule)) {
                        # debug info
                        if ($Self->{Debug}) {
                            $Self->{LogObject}->Log(
                                Priority => 'debug',
                                Message => "PreApplication module $PreModule is used.",
                            );
                        }
                        # use module
                        my $PreModuleObject = $PreModule->new(
                            %{$Self},
                            %Param,
                            %UserData,
                            ModuleReg => $ModuleReg,
                        );
                        my $Output = $PreModuleObject->PreRun();
                        if ($Output) {
                            $Self->{LayoutObject}->Print(Output => \$Output);
                            exit (0);
                        }
                    }
                }
            }
            # debug info
            if ($Self->{Debug}) {
                $Self->{LogObject}->Log(
                    Priority => 'debug',
                    Message => 'Kernel::Modules::' . $Param{Action} .'->new',
                );
            }
            # prove of concept! - create $GenericObject
            my $GenericObject = ('Kernel::Modules::'.$Param{Action})->new(
                %{$Self},
                %Param,
                %UserData,
                ModuleReg => $ModuleReg,
            );
            # debug info
            if ($Self->{Debug}) {
                $Self->{LogObject}->Log(
                    Priority => 'debug',
                    Message => ''. 'Kernel::Modules::' . $Param{Action} .'->run',
                );
            }
            # ->Run $Action with $GenericObject
            $Self->{LayoutObject}->Print(Output => \$GenericObject->Run());
            # log request time
            if ($Self->{ConfigObject}->Get('PerformanceLog')) {
                if ((!$QueryString && $Param{Action}) || ($QueryString !~ /Action=/)) {
                    $QueryString = "Action=".$Param{Action};
                }
                my $File = $Self->{ConfigObject}->Get('PerformanceLog::File');
                if (open(OUT, ">> $File")) {
                    print OUT time()."::Agent::".(time()-$Self->{PerformanceLogStart})."::$UserData{UserLogin}::$QueryString\n";
                    close (OUT);
                    $Self->{LogObject}->Log(
                        Priority => 'notice',
                        Message => "Response::Agent: ".(time()-$Self->{PerformanceLogStart})."s taken (URL:$QueryString:$UserData{UserLogin})",
                    );
                }
                else {
                    $Self->{LogObject}->Log(
                        Priority => 'error',
                        Message => "Can't write $File: $!",
                    );
                }
            }
        }
    }
    # else print an error screen
    else {
        # create new LayoutObject with '%Param'
        my %Data = $Self->{SessionObject}->GetSessionIDData(
            SessionID => $Param{SessionID},
        );
        $Self->{LayoutObject} = Kernel::Output::HTML::Layout->new(
            %{$Self},
            %Param,
            %Data,
        );
        # print error
        $Self->{LayoutObject}->FatalError(
            Comment => 'Please contact your admin'
        );
    }
    # debug info
    if ($Self->{Debug}) {
        $Self->{LogObject}->Log(
            Priority => 'debug',
            Message => 'Global handle stopped.',
        );
    }
    # db disconnect && undef %Param
    $Self->{DBObject}->Disconnect();
    undef %Param;
}

1;

=back

=head1 TERMS AND CONDITIONS

This software is part of the OTRS project (http://otrs.org/).

This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (GPL). If you
did not receive this file, see http://www.gnu.org/licenses/gpl.txt.

=cut

=head1 VERSION

$Revision: 1.23 $ $Date: 2007/09/07 09:12:46 $

=cut