This file is indexed.

/usr/share/otrs/bin/otrs.ExportStatsToOPM.pl is in otrs2 3.3.5-1.

This file is owned by root:root, with mode 0o755.

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
#!/usr/bin/perl
# --
# bin/otrs.ExportStatsToOPM.pl - export all stats of a system and create a package for the package manager
# Copyright (C) 2001-2014 OTRS AG, http://otrs.com/
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU AFFERO General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# 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 Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
# or see http://www.gnu.org/licenses/agpl.txt.
# --

use strict;
use warnings;

## nofilter(TidyAll::Plugin::OTRS::Perl::Require)

use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin) . '/Kernel/cpan-lib';
use lib dirname($RealBin) . '/Custom';

use Getopt::Std;

use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Main;
use Kernel::System::DB;
use Kernel::System::Time;
use Kernel::System::Stats;
use Kernel::System::Group;
use Kernel::System::User;
use Kernel::System::Package;
use Kernel::System::CSV;

# get file version
use vars qw($Debug);

# common objects
my %CommonObject = ();
$CommonObject{UserID}       = 1;
$CommonObject{ConfigObject} = Kernel::Config->new();
$CommonObject{EncodeObject} = Kernel::System::Encode->new(%CommonObject);
$CommonObject{LogObject}    = Kernel::System::Log->new(
    LogPrefix => 'OTRS-otrs.ExportStatsToOPM.pl',
    %CommonObject,
);
$CommonObject{MainObject}    = Kernel::System::Main->new(%CommonObject);
$CommonObject{TimeObject}    = Kernel::System::Time->new(%CommonObject);
$CommonObject{DBObject}      = Kernel::System::DB->new(%CommonObject);
$CommonObject{UserObject}    = Kernel::System::User->new(%CommonObject);
$CommonObject{GroupObject}   = Kernel::System::Group->new(%CommonObject);
$CommonObject{CSVObject}     = Kernel::System::CSV->new(%CommonObject);
$CommonObject{StatsObject}   = Kernel::System::Stats->new(%CommonObject);
$CommonObject{PackageObject} = Kernel::System::Package->new(%CommonObject);

# ---------------------------------------------------------- #
# get options and params
# ---------------------------------------------------------- #

my %Opts           = ();
my $PackageName    = 'ExportStatsToOPM';
my $PackageVersion = '1.0.0';
my $DeleteStats    = 0;

getopt( 'dhvn', \%Opts );

# check needed params
if ( $Opts{'h'} ) {
    print
        "otrs.ExportStatsToOPM.pl - export all stats of a system and create a package for the package manager\n";
    print "Copyright (C) 2001-2014 OTRS AG, http://otrs.com/\n";
    print "usage: otrs.ExportStatsToOPM.pl [-n <PACKAGE_NAME>] [-v <PACKAGE_VERSION>]\n";
    print
        "       [-d 'yes' for delete existing stats if the opm will be installed] [-h for help]\n";
    exit 1;
}
if ( $Opts{'n'} ) {
    $PackageName = $Opts{'n'};
}
if ( $Opts{'v'} ) {
    $PackageVersion = $Opts{'v'};
}
if ( $Opts{'d'} && $Opts{'d'} eq 'yes' ) {
    $DeleteStats = 1;
}

# ---------------------------------------------------------- #
# check if needed directories are available
# ---------------------------------------------------------- #

my $Directory = $CommonObject{ConfigObject}->Get('Home') . "/var/";
if ( !opendir( DIR, $Directory ) ) {
    print "Can not open Directory: $Directory/";
    exit(1);
}
my $StatsFlag = 0;
my $OPMFlag   = 0;
while ( defined( my $Filename = readdir DIR ) ) {
    if ( -d "$Directory$Filename" ) {
        if ( $Filename eq 'Stats' ) {
            $StatsFlag = 1;
        }
        elsif ( $Filename eq 'OPM' ) {
            $OPMFlag = 1;
        }
    }
}
closedir(DIR);

if ( !$StatsFlag ) {
    system( "mkdir " . $Directory . "Stats" );
    print "Created Stats directory!\n";
}

if ( !$OPMFlag ) {
    system( "mkdir " . $Directory . "OPM" );
    print "Created OPM directory!\n";
}

# ---------------------------------------------------------- #
# get all configured stats and export them
# ---------------------------------------------------------- #

# get all stats of the system

my $StatsListRef  = $CommonObject{StatsObject}->GetStatsList();
my %FileListcheck = ();
my @Filelist      = ();
for my $StatID ( @{$StatsListRef} ) {

    # use Stats export function
    my $File = $CommonObject{StatsObject}->Export(
        StatID           => $StatID,
        ExportStatNumber => $DeleteStats,

        # $DeleteStats, because if one delete the statistics he want to
        # insert the new stats in the same row. For example because of the used
        # Cronjobs
    );

    # double check
    if ( $FileListcheck{ $File->{Filename} } ) {
        print "\nThe same stats title is used more than one time (Filename: $File->{Filename})!\n";
        $File->{Filename} =~ s/.xml$/I.xml/;
        print "\nTherefore the filename is renamed to '$File->{Filename}'\n";
    }

    $FileListcheck{ $File->{Filename} } = $StatID;

    # write data in filesystem
    my $FullFilename = $CommonObject{ConfigObject}->Get('Home') . "/var/Stats/" . $File->{Filename};
    push( @Filelist, $File->{Filename} );

    my $Output;
    if ( !open( $Output, ">", $FullFilename ) ) {    ## no critic
        print "\nCan't create $FullFilename!\n";
    }
    else {
        print $Output $File->{Content};
        close($Output);
        print "\n$FullFilename successful created!\n";
    }
}

# ---------------------------------------------------------- #
# build the package
# ---------------------------------------------------------- #

my %OPMS = ();
my ( $s, $m, $h, $D, $M, $Y )
    = $CommonObject{TimeObject}->SystemTime2Date(
    SystemTime => $CommonObject{TimeObject}->SystemTime(),
    );

$OPMS{Version}{Content}      = $PackageVersion;
$OPMS{Name}{Content}         = $PackageName;
$OPMS{Framework}[0]{Content} = '3.1.x';
$OPMS{Vendor}{Content}       = 'OTRS AG';
$OPMS{URL}{Content}          = 'http://otrs.org/';
$OPMS{License}{Content}      = 'GNU GENERAL PUBLIC LICENSE Version 2, June 1991';
$OPMS{ChangeLog}{Content}    = "$Y-$M-$D Created per otrs.ExportStatsToOPM.pl";
$OPMS{Description}[0]{Content}
    = 'Ein Modul um ein Paket mit allen Statistiken eines Systems zu generieren.';
$OPMS{Description}[0]{Lang}    = 'de';
$OPMS{Description}[1]{Content} = 'A module to make a package with all stats of an system.';
$OPMS{Description}[1]{Lang}    = 'en';

# build file list
my $FileListString = '';
for (@Filelist) {
    my %Hash = ();
    $Hash{Location}   = "var/Stats/" . $_;
    $Hash{Permission} = '644';
    push( @{ $OPMS{Filelist} }, \%Hash );
    $FileListString .= " $_";
}

# prepare code install settings

$OPMS{CodeInstall}{Content} = '
require Kernel::System::Stats;
require Kernel::System::Group;
require Kernel::System::User;
require Kernel::System::CSV;

$Self-&gt;{UserID} = 1;
$Self-&gt;{GroupObject} = Kernel::System::Group-&gt;new(%{$Self});
$Self-&gt;{UserObject}  = Kernel::System::User-&gt;new(%{$Self});
$Self-&gt;{StatsObject} = Kernel::System::Stats-&gt;new(%{$Self});
$Self-&gt;{CSVObject} = Kernel::System::CSV-&gt;new(%{$Self});
# delete the exitsting stats db
my $Delete = ' . $DeleteStats . ';

if ($Delete) {
    my $StatsListRef = $Self-&gt;{StatsObject}-&gt;GetStatsList();
    for my $StatID (@{$StatsListRef}) {
        $Self-&gt;{StatsObject}-&gt;StatsDelete(StatID => $StatID);
    }
}
for my $FileString (qw(' . $FileListString . ')) {
    my $File = $Self-&gt;{ConfigObject}-&gt;Get(\'Home\')."/var/Stats/$FileString";
    my $Content = \'\';
    if (open(IN, "&lt; $File")) {
        # set bin mode
        #binmode IN;
        while (&lt;IN&gt;) {
            $Content .= $_;
        }
        close (IN);
    }
    else {
        die "Can\'t open: $File: $!";
    }
    my $StatID = $Self-&gt;{StatsObject}-&gt;Import(Content  => $Content);
}

';

$OPMS{CodeReinstall}{Content} = $OPMS{CodeInstall}{Content};
$OPMS{CodeUpgrade}{Content}   = $OPMS{CodeInstall}{Content};

# save the package
my $File = $CommonObject{ConfigObject}->Get('Home')
    . "/var/OPM/$PackageName-$OPMS{Version}{Content}.opm";

my $Output;
if ( open( $Output, ">", $File ) ) {    ## no critic
    print "Writing $File\n";
    print $Output $CommonObject{PackageObject}->PackageBuild(%OPMS);
    close($Output);
    exit 1;
}
else {
    print STDERR "ERROR: Can't write $File\n";
    exit;
}

1;