1# --
2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/
3# --
4# This software comes with ABSOLUTELY NO WARRANTY. For details, see
5# the enclosed file COPYING for license information (GPL). If you
6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
7# --
8
9package Kernel::System::Web::InterfaceInstaller;
10
11use strict;
12use warnings;
13
14use Kernel::Language qw(Translatable);
15
16our @ObjectDependencies = (
17    'Kernel::Config',
18    'Kernel::Output::HTML::Layout',
19    'Kernel::System::Log',
20    'Kernel::System::Main',
21    'Kernel::System::Web::Request',
22);
23
24=head1 NAME
25
26Kernel::System::Web::InterfaceInstaller - the installer web interface
27
28=head1 DESCRIPTION
29
30the global installer web interface
31
32=head1 PUBLIC INTERFACE
33
34=head2 new()
35
36create installer web interface object
37
38    use Kernel::System::Web::InterfaceInstaller;
39
40    my $Debug = 0;
41    my $Interface = Kernel::System::Web::InterfaceInstaller->new( Debug => $Debug );
42
43=cut
44
45sub new {
46    my ( $Type, %Param ) = @_;
47
48    # allocate new hash for object
49    my $Self = {};
50    bless( $Self, $Type );
51
52    # get debug level
53    $Self->{Debug} = $Param{Debug} || 0;
54
55    $Kernel::OM->ObjectParamAdd(
56        'Kernel::System::Log' => {
57            LogPrefix => $Kernel::OM->Get('Kernel::Config')->Get('CGILogPrefix') || 'Installer',
58        },
59        'Kernel::Output::HTML::Layout' => {
60            InstallerOnly => 1,
61        },
62        'Kernel::System::Web::Request' => {
63            WebRequest => $Param{WebRequest} || 0,
64        },
65    );
66
67    # debug info
68    if ( $Self->{Debug} ) {
69
70        $Kernel::OM->Get('Kernel::System::Log')->Log(
71            Priority => 'debug',
72            Message  => 'Global handle started...',
73        );
74    }
75
76    return $Self;
77}
78
79=head2 Run()
80
81execute the object
82
83    $Interface->Run();
84
85=cut
86
87sub Run {
88    my $Self = shift;
89
90    # get common framework params
91    my %Param;
92
93    my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request');
94
95    $Param{Action}     = $ParamObject->GetParam( Param => 'Action' )     || 'Installer';
96    $Param{Subaction}  = $ParamObject->GetParam( Param => 'Subaction' )  || '';
97    $Param{NextScreen} = $ParamObject->GetParam( Param => 'NextScreen' ) || '';
98
99    $Kernel::OM->ObjectParamAdd(
100        'Kernel::Output::HTML::Layout' => {
101            %Param,
102        },
103    );
104
105    my $LayoutObject = $Kernel::OM->Get('Kernel::Output::HTML::Layout');
106
107    # check secure mode
108    if ( $Kernel::OM->Get('Kernel::Config')->Get('SecureMode') ) {
109        print $LayoutObject->Header();
110        print $LayoutObject->Error(
111            Message => Translatable('SecureMode active!'),
112            Comment => Translatable(
113                'If you want to re-run the Installer, disable the SecureMode in the SysConfig.'
114            ),
115        );
116        print $LayoutObject->Footer();
117    }
118
119    # run modules if a version value exists
120    elsif ( $Kernel::OM->Get('Kernel::System::Main')->Require("Kernel::Modules::$Param{Action}") ) {
121
122        # proof of concept! - create $GenericObject
123        my $GenericObject = ( 'Kernel::Modules::' . $Param{Action} )->new(
124            %Param,
125            Debug => $Self->{Debug},
126        );
127
128        print $GenericObject->Run();
129    }
130
131    # else print an error screen
132    else {
133
134        # create new LayoutObject with '%Param'
135        print $LayoutObject->Header();
136        print $LayoutObject->Error(
137            Message => $LayoutObject->{LanguageObject}->Translate( 'Action "%s" not found!', $Param{Action} ),
138            Comment => Translatable('Please contact the administrator.'),
139        );
140        print $LayoutObject->Footer();
141    }
142
143    return;
144}
145
146sub DESTROY {
147    my $Self = shift;
148
149    # debug info
150    if ( $Self->{Debug} ) {
151
152        $Kernel::OM->Get('Kernel::System::Log')->Log(
153            Priority => 'debug',
154            Message  => 'Global handle stopped.',
155        );
156    }
157
158    return 1;
159}
160
1611;
162
163=head1 TERMS AND CONDITIONS
164
165This software is part of the OTRS project (L<https://otrs.org/>).
166
167This software comes with ABSOLUTELY NO WARRANTY. For details, see
168the enclosed file COPYING for license information (GPL). If you
169did not receive this file, see L<https://www.gnu.org/licenses/gpl-3.0.txt>.
170
171=cut
172