/usr/share/otrs/bin/otrs.WebserviceConfig.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 | #!/usr/bin/perl
# --
# bin/otrs.WebserviceConfig.pl - script to read/write/list webservice config
# 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;
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::Time;
use Kernel::System::DB;
use Kernel::System::GenericInterface::Webservice;
use Kernel::System::YAML;
# get options
my %Opts;
getopt( 'hiafn', \%Opts );
if ( $Opts{h} ) {
print "otrs.WebserviceConfig.pl - read/write/list webservice config\n";
print "Copyright (C) 2001-2014 OTRS AG, http://otrs.com/\n";
print
"usage: otrs.WebserviceConfig.pl -a read -i \$ID (read config, print to STDOUT)\n";
print
" -a write -n \$name -f /path/to/yaml/file (create a new config)\n";
print
" -a write -i \$ID -f /path/to/yaml/file (update config)\n";
print
" -a list (list available config)\n";
print
" -a delete -i \$ID (delete config)\n";
exit 1;
}
# create common objects
my %CommonObject;
$CommonObject{ConfigObject} = Kernel::Config->new();
$CommonObject{EncodeObject} = Kernel::System::Encode->new(%CommonObject);
$CommonObject{LogObject} = Kernel::System::Log->new(
LogPrefix => 'OTRS-otrs.WebserviceConfig.pl',
%CommonObject,
);
$CommonObject{TimeObject} = Kernel::System::Time->new(%CommonObject);
$CommonObject{MainObject} = Kernel::System::Main->new(%CommonObject);
$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
# create needed objects
$CommonObject{WebserviceObject} = Kernel::System::GenericInterface::Webservice->new(%CommonObject);
$CommonObject{YAMLObject} = Kernel::System::YAML->new(%CommonObject);
# validate -a param
if ( !$Opts{a} ) {
print STDERR "ERROR: Need action (-a) param!\n";
exit 1;
}
if ( lc( $Opts{a} ) !~ /^(read|write|list|delete)$/ ) {
print STDERR "ERROR: Unknown action '$Opts{a}'\n";
exit 1;
}
# list webservices
if ( lc( $Opts{a} ) eq 'list' ) {
print "List Config: (ID:Name)\n";
my $List = $CommonObject{WebserviceObject}->WebserviceList();
for my $ID ( sort keys %{$List} ) {
print "$ID:$List->{$ID}\n";
}
exit 0;
}
# write webservice
if ( lc( $Opts{a} ) eq 'write' ) {
# validate file
if ( !$Opts{f} ) {
print STDERR "ERROR: Need file (-f) param!\n";
exit 1;
}
elsif ( !-f $Opts{f} ) {
print STDERR "ERROR: File (-f '$Opts{f}') is no file!\n";
exit 1;
}
# read config
my $Content = $CommonObject{MainObject}->FileRead(
Location => $Opts{f},
);
if ( !$Content ) {
print STDERR "ERROR: No content in file (-f '$Opts{f}')!\n";
exit 1;
}
my $Config = $CommonObject{YAMLObject}->Load( Data => ${$Content} );
if ( !$Config ) {
print STDERR "ERROR: Unable to read config file: $! (-f '$Opts{f}')!\n";
exit 1;
}
# webservice lookup
if ( $Opts{i} ) {
my $List = $CommonObject{WebserviceObject}->WebserviceList();
if ( !$List->{ $Opts{i} } ) {
print STDERR "ERROR: No such webservice with id (-i '$Opts{i}')!\n";
exit 1;
}
my $Webservice = $CommonObject{WebserviceObject}->WebserviceGet( ID => $Opts{i} );
if ( !$Webservice ) {
print STDERR "ERROR: No such webservice with id (-i '$Opts{i}')!\n";
exit 1;
}
# update webservice
my $Success = $CommonObject{WebserviceObject}->WebserviceUpdate(
ID => $Webservice->{ID},
Name => $Webservice->{Name},
Config => $Config,
ValidID => 1,
UserID => 1,
);
if ( !$Success ) {
print STDERR "ERROR: Unable to update webservice!\n";
exit 1;
}
print "NOTICE: Webservice updated (ID:$Webservice->{ID})!\n";
exit 0;
}
# webservice add
my $ID = $CommonObject{WebserviceObject}->WebserviceAdd(
Name => $Opts{n},
Config => $Config,
ValidID => 1,
UserID => 1,
);
if ( !$ID ) {
print STDERR "ERROR: Unable to create webservice!\n";
exit 1;
}
print "NOTICE: Webservice created (ID:$ID)!\n";
exit 0;
}
# read webservice
if ( lc( $Opts{a} ) eq 'read' ) {
# validate file
if ( !$Opts{i} ) {
print STDERR "ERROR: Need id (-i) param!\n";
exit 1;
}
# webservice lookup
my $List = $CommonObject{WebserviceObject}->WebserviceList();
if ( !$List->{ $Opts{i} } ) {
print STDERR "ERROR: No such webservice with id (-i '$Opts{i}')!\n";
exit 1;
}
# get webservice
my $Webservice = $CommonObject{WebserviceObject}->WebserviceGet( ID => $Opts{i} );
if ( !$Webservice ) {
print STDERR "ERROR: No such webservice with id (-i '$Opts{i}')!\n";
exit 1;
}
# dump config as string
my $Config = $CommonObject{YAMLObject}->Dump( Data => $Webservice->{Config} );
print "$Config\n";
exit 0;
}
# delete webservice
if ( lc( $Opts{a} ) eq 'delete' ) {
# validate file
if ( !$Opts{i} ) {
print STDERR "ERROR: Need id (-i) param!\n";
exit 1;
}
# get webservice
my $Webservice = $CommonObject{WebserviceObject}->WebserviceGet( ID => $Opts{i} );
if ( !$Webservice ) {
print STDERR "ERROR: No such webservice with id (-i '$Opts{i}')!\n";
exit 1;
}
# webservice lookup
my $Success = $CommonObject{WebserviceObject}->WebserviceDelete(
ID => $Opts{i},
UserID => 1,
);
if ( !$Success ) {
print STDERR "ERROR: No such webservice with id (-i '$Opts{i}')!\n";
exit 1;
}
print "NOTICE: Webservice deleted (ID:$Opts{i})!\n";
}
exit 0;
|