Request#

NAME#

Kernel::System::Web::Request - global CGI interface

DESCRIPTION#

All cgi param functions.

PUBLIC INTERFACE#

new()#

create param object. Do not use it directly, instead use:

use Kernel::System::ObjectManager;
local $Kernel::OM = Kernel::System::ObjectManager->new(
    'Kernel::System::Web::Request' => {
        WebRequest   => CGI::Fast->new(), # optional, e. g. if fast cgi is used
    }
);
my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request');

If Kernel::System::Web::Request is instantiated several times, they will share the same CGI data (this can be helpful in filters which do not have access to the ParamObject, for example.

If you need to reset the CGI data before creating a new instance, use

CGI::initialize_globals();

before calling Kernel::System::Web::Request->new();

Error()#

to get the error back

if ( $ParamObject->Error() ) {
    print STDERR $ParamObject->Error() . "\n";
}

GetParam()#

to get single request parameters. By default, trimming is performed on the data.

my $Param = $ParamObject->GetParam(
    Param => 'ID',
    Raw   => 1,       # optional, input data is not changed
);

Returns:

my $Param = '123';

GetParams()#

Get all request parameters, Strings and Arrays.

my %Params = $ParamObject->GetParams(
    Params           => [ 'TicketID', 'Queue', ]      # optional, only these parameters are fetched and returned
    Raw              => 1,                            # optional, input data is not changed
    JSONDecodeParams => ['ParamNameWithJSONData1',]   # optional, this JSON-decodes the given parameters
);

Returns:

my %Params = (
    TicketID => 1,
    Queue    => 'Raw',
    Array    => [
        1,
        2,
    ],
    'ParamNameWithJSONData1' => {
        'jsonkey' => 'jsonvalue'
    },
);

GetParamNames()#

to get names of all parameters passed to the script.

my @ParamNames = $ParamObject->GetParamNames();

Example:

Called URL: index.pl?Action=AdminSystemConfiguration;Subaction=Save;Name=Config::Option::Valid

my @ParamNames = $ParamObject->GetParamNames();

print join " :: ", @ParamNames;
# prints Action :: Subaction :: Name

Returns:

my @ParamNames = (
    'Array',
    'TicketID',
    'Queue',
);

GetArray()#

to get array request parameters. By default, trimming is performed on the data.

my @Param = $ParamObject->GetArray(
    Param => 'ID',
    Raw   => 1,     # optional, input data is not changed
);

Returns:

my @Param = (
    1,
    2,
);

GetUploadAll()#

gets file upload data.

my %File = $ParamObject->GetUploadAll(
    Param  => 'FileParam',  # the name of the request parameter containing the file data
);

Returns:

my %File = (
    Filename    => 'abc.txt',
    ContentType => 'text/plain',
    Content     => 'Some text',
);

SetCookie()#

set a cookie

$ParamObject->SetCookie(
    Key     => ID,
    Value   => 123456,
    Expires => '+3660s',
    Path    => 'otrs/',     # optional, only allow cookie for given path
    Secure  => 1,           # optional, set secure attribute to disable cookie on HTTP (HTTPS only)
    HTTPOnly => 1,          # optional, sets HttpOnly attribute of cookie to prevent access via JavaScript
    SameSite => 'None',     # optional, Strict, Lax or None; None is emitted only together with Secure
);

GetCookie()#

get a cookie

my $String = $ParamObject->GetCookie(
    Key => ID,
);

IsAJAXRequest()#

checks if the current request was sent by AJAX

my $IsAJAXRequest = $ParamObject->IsAJAXRequest();

LoadFormDraft()#

Load specified draft. This will read stored draft data and inject it into the param object for transparent use by frontend module.

my $FormDraftID = $ParamObject->LoadFormDraft(
    FormDraftID => 123,
    UserID  => 1,
);

SaveFormDraft()#

Create or replace draft using data from param object and upload cache. Specified params can be overwritten if necessary.

my $FormDraftID = $ParamObject->SaveFormDraft(
    UserID         => 1,
    ObjectType     => 'Ticket',
    ObjectID       => 123,
    OverrideParams => {               # optional, can contain strings and array references
        Subaction   => undef,
        UserID      => 1,
        CustomParam => [ 1, 2, 3, ],
        # ...
    },
);

GetLegacySessionName()#

Return the previous cookie name for a known default session name. Custom names have no previous name, so the result is empty.

my $LegacySessionName = $ParamObject->GetLegacySessionName(
    SessionName => 'ZnunyAgentInterface',    # returns OTRSAgentInterface
);

GetSessionID()#

Resolve a session ID from the request. The configured session name is tried first. When that name is a known Znuny default, the previous OTRS name is tried as well. Query/body params are read first; if SessionUseCookie is enabled, a cookie value overrides them (same priority as before).

my $SessionID = $ParamObject->GetSessionID(
    SessionName => 'ZnunyAgentInterface',
);

# List context also returns the cookie value when the session came from a cookie:
my ( $SessionID, $SessionIDCookie ) = $ParamObject->GetSessionID(
    SessionName => 'ZnunyAgentInterface',
);

ExpireLegacySessionCookie()#

Build a SetCookies entry that expires the previous cookie name for a known default session name. Does nothing when that session name has no previous name.

my $Cookie = $ParamObject->ExpireLegacySessionCookie(
    SessionName => 'ZnunyAgentInterface',
    Path        => $ConfigObject->Get('ScriptAlias'),
    Secure      => $CookieSecureAttribute,
);