This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# 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 https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::Console::Command::Dev::Code::CPANAudit;
use strict;
use warnings;
use CPAN::Audit;
use File::Basename;
use FindBin qw($Bin);
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = ();
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Scan CPAN dependencies in Kernel/cpan-lib and in the system for known vulnerabilities.');
return;
}
sub Run {
my ( $Self, %Param ) = @_;
my $Audit = CPAN::Audit->new(
no_color => 1,
no_corelist => 0,
ascii => 0,
verbose => 0,
quiet => 0,
interactive => 0,
);
my @PathsToScan;
# We need to pass an explicit list of paths to be scanned by CPAN::Audit, otherwise it will fallback to @INC which
# includes our complete tree, with article storage, cache, temp files, etc. It can result in a downgraded
# performance if this command is run often.
# Please see bug#14666 for more information.
PATH:
for my $Path (@INC) {
next PATH if $Path && $Path eq '.'; # Current folder
next PATH if $Path && $Path eq dirname($Bin); # OTRS home folder
next PATH if $Path && $Path eq dirname($Bin) . '/Custom'; # Custom folder
push @PathsToScan, $Path;
}
# Workaround for CPAN::Audit::Installed. It does not use the passed param(s), but @ARGV instead.
local @ARGV = @PathsToScan;
return $Audit->command('installed') == 0 ? $Self->ExitCodeOk() : $Self->ExitCodeError();
}
1;

View File

@@ -0,0 +1,176 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# 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 https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::Console::Command::Dev::Code::CPANUpdate;
use strict;
use warnings;
use File::Path();
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::Main',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Update dependencies in Kernel/cpan-lib.');
$Self->AddOption(
Name => 'mode',
Description => "Update all dependencies (development), or only critical ones (stable).",
Required => 1,
HasValue => 1,
Multiple => 0,
ValueRegex => qr/^stable$/smx,
);
return;
}
sub Run {
my ( $Self, %Param ) = @_;
my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');
my $Mode = $Self->GetOption('mode');
my $CPANDir = "$Home/Kernel/cpan-lib";
if ( $Mode eq 'stable' ) {
MODULE_CONFIG:
for my $ModuleConfig ( $Self->LoadModuleConfig() ) {
next MODULE_CONFIG if !$ModuleConfig->{UpdateInStableMode};
$Self->InstallModule(
ModuleConfig => $ModuleConfig,
TargetPath => $CPANDir,
);
}
}
elsif ( $Mode eq 'development' ) {
my $CPAN2Dir = "$Home/Kernel/cpan-lib2";
# Delete Kernel/cpan-lib.
if ( -d $CPAN2Dir ) {
File::Path::remove_tree($CPAN2Dir) || die "Could not clean-up $CPAN2Dir: $!.";
}
File::Path::make_path($CPAN2Dir) || die "Could not create $CPAN2Dir: $!.";
# Install modules.
MODULE_CONFIG:
for my $ModuleConfig ( $Self->LoadModuleConfig() ) {
$Self->InstallModule(
ModuleConfig => $ModuleConfig,
TargetPath => $CPAN2Dir,
);
}
# Copy our own extension for Devel::REPL from previous cpan-lib folder.
File::Path::make_path("$CPAN2Dir/Devel/REPL/Plugin");
system("cp -r $CPANDir/Devel/REPL/Plugin/OTRS.pm $CPAN2Dir/Devel/REPL/Plugin/OTRS.pm");
# Replace cpan-lib folder.
File::Path::remove_tree($CPANDir) || die "Could not remove $CPANDir: $!.";
rename $CPAN2Dir, $CPANDir || die "Could not replace $CPANDir: $!.";
}
# Clean-up unwanted files.
File::Path::remove_tree("$CPANDir/Test/Selenium");
system("find $CPANDir -name *.pod -exec rm -f {} +");
system("find $CPANDir -name *.pl -exec rm -f {} +");
system("find $CPANDir -name *.so -exec rm -f {} +");
system("find $CPANDir -name *.exists -exec rm -f {} +");
# Fix unwanted 755 permissions.
system("find $CPANDir -type f -exec chmod 640 {} +");
my $ReadmeContent = <<EOF;
This directory contains bundled pure-perl CPAN modules that are used by the OTRS source code.
Please note that this directory is auto-generated by the command `Dev::Code::CPANUpdate`.
License information of the bundled modules can be found in the
[COPYING-Third-Party](../../COPYING-Third-Party) file.
EOF
$Kernel::OM->Get('Kernel::System::Main')->FileWrite(
Location => "$CPANDir/README.md",
Content => \$ReadmeContent,
);
return $Self->ExitCodeOk();
}
sub InstallModule {
my ( $Self, %Param ) = @_;
my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');
my $ModuleConfig = $Param{ModuleConfig};
my $TargetPath = $Param{TargetPath};
$Self->Print("Updating <yellow>$ModuleConfig->{Module}</yellow>...\n");
my $TmpDir = "$Home/var/tmp/CPANUpdate";
if ( -d $TmpDir ) {
File::Path::remove_tree($TmpDir) || die "Could not clean-up $TmpDir: $!.";
}
File::Path::make_path($TmpDir) || die "Could not create $TmpDir: $!.";
my $DownloadURL
= `wget -q -O - https://fastapi.metacpan.org/v1/download_url/$ModuleConfig->{Module} | grep download_url | cut -d '"' -f4`;
die "Error: Could not get DownloadURL." if !$DownloadURL;
chomp $DownloadURL;
system("cd $TmpDir; wget -q -O - $DownloadURL | tar -xz --strip 1");
if ( $ModuleConfig->{BuildBLib} ) {
system("cd $TmpDir; perl Makefile.PL; make; cp -r $TmpDir/blib/lib/* $TargetPath");
return 1;
}
if ( -d "$TmpDir/lib" ) {
system("cp -r $TmpDir/lib/* $TargetPath");
return 1;
}
my @ModuleParts = split( m{::}, $ModuleConfig->{Module} );
my $LastModuleLevel = pop @ModuleParts;
my $ModulePath = join '/', @ModuleParts;
if ( -f "$TmpDir/$LastModuleLevel.pm" ) {
if ( !-d "$TargetPath/$ModulePath" ) {
File::Path::make_path("$TargetPath/$ModulePath") || die "Could not create $TargetPath/$ModulePath: $!.";
}
system("cp -r $TmpDir/$LastModuleLevel.pm $TargetPath/$ModulePath");
return 1;
}
die "Download and/or file extraction of $DownloadURL failed.";
}
sub LoadModuleConfig {
return (
{
Module => 'CPAN::Audit',
UpdateInStableMode => 1,
},
{
Module => 'Mozilla::CA',
UpdateInStableMode => 1,
},
);
}
1;

View File

@@ -0,0 +1,57 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# 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 https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::Console::Command::Dev::Code::ContributorsListUpdate;
use strict;
use warnings;
use IO::File;
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::Config',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Update the list of contributors based on git commit information.');
return;
}
sub Run {
my ( $Self, %Param ) = @_;
chdir $Kernel::OM->Get('Kernel::Config')->Get('Home');
my @Lines = qx{git log --format="%aN <%aE>"};
my %Seen;
map { $Seen{$_}++ } @Lines;
my $FileHandle = IO::File->new( 'AUTHORS.md', 'w' );
$FileHandle->print("The following persons contributed to OTRS:\n\n");
AUTHOR:
for my $Author ( sort keys %Seen ) {
chomp $Author;
if ( $Author =~ m/^[^<>]+ \s <>\s?$/smx ) {
$Self->Print("<yellow>Could not find Author $Author, skipping.</yellow>\n");
next AUTHOR;
}
$FileHandle->print("* $Author\n");
}
$FileHandle->close();
return $Self->ExitCodeOk();
}
1;

View File

@@ -0,0 +1,168 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# 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 https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::Console::Command::Dev::Code::Generate::ConsoleCommand;
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
use strict;
use warnings;
use File::Path ();
use File::Basename ();
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::Main',
'Kernel::Output::HTML::Layout',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Generate a console command skeleton.');
$Self->AddOption(
Name => 'module-directory',
Description =>
"Specify the directory containing the module where the new command should be created (otherwise the OTRS home directory will be used).",
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddArgument(
Name => 'name',
Description => "Specify the name of the new command (e.g. 'Admin::Test::Command').",
Required => 1,
ValueRegex => qr/.*/smx,
);
return;
}
sub PreRun {
my ( $Self, %Param ) = @_;
my $ModuleDirectory = $Self->GetOption('module-directory');
if ( $ModuleDirectory && !-d $ModuleDirectory ) {
die "Directory $ModuleDirectory does not exist.\n";
}
return;
}
sub Run {
my ( $Self, %Param ) = @_;
my $CommandName = $Self->GetArgument('name');
my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');
my $TargetHome = $Home;
my $ModuleDirectory = $Self->GetOption('module-directory');
if ($ModuleDirectory) {
$TargetHome = $ModuleDirectory;
}
# Keep comment lines in files also in the generated output.
local $ENV{TEMPLATE_KEEP_COMMENTS} = 1;
# create perl module file
my $CommandPathPM = $CommandName . ".pm";
$CommandPathPM =~ s{::}{/}smxg;
my $SkeletonFilePM = __FILE__;
$SkeletonFilePM =~ s{ConsoleCommand\.pm$}{ConsoleCommand/ConsoleCommand.pm.skel}xms;
my $SkeletonTemplatePM = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
Location => $SkeletonFilePM,
);
if ( !$SkeletonTemplatePM || !${$SkeletonTemplatePM} ) {
$Self->PrintError("Could not read $SkeletonFilePM.");
return $Self->ExitCodeError();
}
my $SkeletonPM = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->Output(
Template => ${$SkeletonTemplatePM},
Data => {
CommandPath => $CommandPathPM,
CommandName => $CommandName,
},
);
my $TargetLocationPM = "$TargetHome/Kernel/System/Console/Command/$CommandPathPM";
my $TargetDirectoryPM = File::Basename::dirname($TargetLocationPM);
if ( !-d $TargetDirectoryPM ) {
File::Path::make_path($TargetDirectoryPM);
}
if ( -f $TargetLocationPM ) {
$Self->PrintError("$TargetLocationPM already exists.");
return $Self->ExitCodeError();
}
my $SuccessPM = $Kernel::OM->Get('Kernel::System::Main')->FileWrite(
Location => $TargetLocationPM,
Content => \$SkeletonPM,
);
if ($SuccessPM) {
$Self->Print("<green>Generated:</green> <yellow>$TargetLocationPM</yellow>\n");
}
else {
$Self->PrintError("Could not generate $TargetLocationPM.\n");
return $Self->ExitCodeError();
}
# create unit test file
my $CommandPathUT = $CommandName . ".t";
$CommandPathUT =~ s{::}{/}smxg;
my $SkeletonFileUT = __FILE__;
$SkeletonFileUT =~ s{ConsoleCommand\.pm$}{ConsoleCommand/ConsoleCommand.t.skel}xms;
my $SkeletonTemplateUT = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
Location => $SkeletonFileUT,
);
if ( !$SkeletonTemplateUT || !${$SkeletonTemplateUT} ) {
$Self->PrintError("Could not read $SkeletonFileUT.");
return $Self->ExitCodeError();
}
my $SkeletonUT = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->Output(
Template => ${$SkeletonTemplateUT},
Data => {
CommandPath => $CommandPathUT,
CommandName => $CommandName,
},
);
my $TargetLocationUT = "$TargetHome/scripts/test/Console/Command/$CommandPathUT";
my $TargetDirectoryUT = File::Basename::dirname($TargetLocationUT);
if ( !-d $TargetDirectoryUT ) {
File::Path::make_path($TargetDirectoryUT);
}
if ( -f $TargetLocationUT ) {
$Self->PrintError("$TargetLocationUT already exists.");
return $Self->ExitCodeError();
}
my $SuccessUT = $Kernel::OM->Get('Kernel::System::Main')->FileWrite(
Location => $TargetLocationUT,
Content => \$SkeletonUT,
);
if ($SuccessUT) {
$Self->Print("<green>Generated:</green> <yellow>$TargetLocationUT</yellow>\n");
return $Self->ExitCodeOk();
}
$Self->PrintError("Could not generate $TargetLocationUT.\n");
return $Self->ExitCodeError();
}
1;

View File

@@ -0,0 +1,72 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# 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 https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::Console::Command::[% Data.CommandName %];
use strict;
use warnings;
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
);
sub Configure {
my ( $Self, %Param ) = @_;
# $Self->Description('Describe this command.');
# $Self->AddOption(
# Name => 'option',
# Description => "Describe this option.",
# Required => 1,
# HasValue => 1,
# ValueRegex => qr/.*/smx,
# );
# $Self->AddArgument(
# Name => 'argument',
# Description => "Describe this argument.",
# Required => 1,
# ValueRegex => qr/.*/smx,
# );
return;
}
# sub PreRun {
# my ( $Self, %Param ) = @_;
#
# # Perform any custom validations here. Command execution can be stopped with die().
#
# # my $TargetDirectory = $Self->GetOption('target-directory');
# # if ($TargetDirectory && !-d $TargetDirectory) {
# # die "Directory $TargetDirectory does not exist.\n";
# # }
#
# return;
# }
sub Run {
my ( $Self, %Param ) = @_;
$Self->Print("<yellow>Meaningful start message...</yellow>\n");
# return $Self->ExitCodeError();
$Self->Print("<green>Done.</green>\n");
return $Self->ExitCodeOk();
}
# sub PostRun {
# my ( $Self, %Param ) = @_;
#
# # This will be called after Run() (even in case of exceptions). Perform any cleanups here.
#
# return;
# }
1;

View File

@@ -0,0 +1,26 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# 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 https://www.gnu.org/licenses/gpl-3.0.txt.
# --
## no critic (Modules::RequireExplicitPackage)
use strict;
use warnings;
use utf8;
use vars (qw($Self));
my $CommandObject = $Kernel::OM->Get('Kernel::System::Console::Command::[% Data.CommandName %]');
my ($Result, $ExitCode);
{
local *STDOUT;
open STDOUT, '>:encoding(UTF-8)', \$Result;
$ExitCode = $CommandObject->Execute();
$Kernel::OM->Get('Kernel::System::Encode')->EncodeInput(\$Result);
}
1;

View File

@@ -0,0 +1,117 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# 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 https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::Console::Command::Dev::Code::Generate::UnitTest::Backend;
## nofilter(TidyAll::Plugin::OTRS::Perl::LayoutObject)
use strict;
use warnings;
use File::Path ();
use File::Basename ();
use parent qw(Kernel::System::Console::BaseCommand);
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::Main',
'Kernel::Output::HTML::Layout',
);
sub Configure {
my ( $Self, %Param ) = @_;
$Self->Description('Generate a test skeleton.');
$Self->AddOption(
Name => 'module-directory',
Description =>
"Specify the directory containing the module where the new test should be created (otherwise the OTRS home directory will be used).",
Required => 0,
HasValue => 1,
ValueRegex => qr/.*/smx,
);
$Self->AddArgument(
Name => 'target-path',
Description => "Specify the path to the new test (e.g. MyModule/SubTest).",
Required => 1,
ValueRegex => qr/.*/smx,
);
return;
}
sub PreRun {
my ( $Self, %Param ) = @_;
my $ModuleDirectory = $Self->GetOption('module-directory');
if ( $ModuleDirectory && !-d $ModuleDirectory ) {
die "Directory $ModuleDirectory does not exist.\n";
}
return;
}
sub Run {
my ( $Self, %Param ) = @_;
my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');
my $TargetHome = $Home;
my $ModuleDirectory = $Self->GetOption('module-directory');
if ($ModuleDirectory) {
$TargetHome = $ModuleDirectory;
}
# Keep comment lines in files also in the generated output.
local $ENV{TEMPLATE_KEEP_COMMENTS} = 1;
my $TargetPath = $Self->GetArgument('target-path');
# create Test module file
my $SkeletonFile = __FILE__;
$SkeletonFile =~ s{Backend\.pm$}{Backend/Backend.t.skel}xms;
my $SkeletonTemplate = $Kernel::OM->Get('Kernel::System::Main')->FileRead(
Location => $SkeletonFile,
);
if ( !$SkeletonTemplate || !${$SkeletonTemplate} ) {
$Self->PrintError("Could not read $SkeletonFile.");
return $Self->ExitCodeError();
}
my $Skeleton = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->Output(
Template => ${$SkeletonTemplate},
);
my $TargetLocation = "$TargetHome/scripts/test/$TargetPath.t";
my $TargetDirectory = File::Basename::dirname($TargetLocation);
if ( !-d $TargetDirectory ) {
File::Path::make_path($TargetDirectory);
}
if ( -f $TargetLocation ) {
$Self->PrintError("$TargetLocation already exists.");
return $Self->ExitCodeError();
}
my $Success = $Kernel::OM->Get('Kernel::System::Main')->FileWrite(
Location => $TargetLocation,
Content => \$Skeleton,
);
if ( !$Success ) {
$Self->PrintError("Could not generate $TargetLocation.\n");
return $Self->ExitCodeError();
}
$Self->Print("<green>Generated:</green> <yellow>$TargetLocation</yellow>\n");
return $Self->ExitCodeOk();
}
1;

View File

@@ -0,0 +1,18 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# 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 https://www.gnu.org/licenses/gpl-3.0.txt.
# --
## no critic (Modules::RequireExplicitPackage)
use strict;
use warnings;
use utf8;
use vars (qw($Self));
1;