/usr/share/otrs/scripts/webform.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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | #!/usr/bin/perl
# --
# webform.pl - a simple web form script to generate email with
# X-OTRS-Queue header for an OTRS system (x-headers for dispatching!).
# 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;
# to get the errors on screen
use CGI::Carp qw(fatalsToBrowser);
# Simple Common Gateway Interface Class
use CGI;
# --------------------------
# web form options
# --------------------------
my $Ident = 'ahfiw2Fw32r230dddl2foeo3r';
# sendmail location and options
my $Sendmail = '/usr/sbin/sendmail -t -i -f';
# email where the emails of the form will send to
my $OTRSEmail = 'otrs-system@example.com';
# topics and dest. queues
my %Topics = (
# topic => OTRS queue
'Info' => 'info',
'Support' => 'support',
'Bugs' => 'bugs',
'Sales' => 'sales',
'Billing' => 'billing',
'Webmaster' => 'webmaster',
);
# --------------------------
# html header
# --------------------------
sub Header {
my (%Param) = @_;
# html quote
for my $Value (qw(Title)) {
$Param{$Value} = _Ascii2Html( $Param{$Value} );
}
my $Output = <<EOF;
Content-Type: text/html
<html>
<head>
<title>$Param{Title}</title>
</head>
<body>
<h1>$Param{Title}</h1>
<hr>
EOF
return $Output;
}
# -------------------------
# html footer
# -------------------------
sub Footer {
my $Output = <<EOF;
<hr>
</body>
</html>
EOF
return $Output;
}
# -------------------------
# Thanks
# -------------------------
sub Thanks {
my (%Param) = @_;
# html quote
for my $Value (qw(From)) {
$Param{$Value} = _Ascii2Html( $Param{$Value} );
}
my $Output = <<EOF;
Thanks <b>$Param{From}</b>! Your request is forwarded to us. <br>
We will answer ASAP.<br>
EOF
return $Output;
}
# ----------------------
# error
# ----------------------
sub Error {
my (%Param) = @_;
# html quote
for my $Value (qw(Message)) {
$Param{$Value} = _Ascii2Html( $Param{$Value} );
}
my $Output = <<EOF;
<font color="red">$Param{Message}</font><br>
EOF
return $Output;
}
# ------------------------
# start the real actions
# ------------------------
my $CGI = new CGI;
my %GetParam = ();
for (qw(Action From FromEmail Subject Topic Body)) {
$GetParam{$_} = $CGI->param($_) || '';
}
# what should I do?
if ( $GetParam{Action} eq 'SendMail' ) {
SendMail(%GetParam);
}
else {
WebForm();
}
# ------------------------
# web form
# ------------------------
sub WebForm {
print Header( Title => 'Submit Request' );
print '
<form action="webform.pl" method="post">
<input type="hidden" name="Action" value="SendMail">
<table>
<tr>
<td>Topic:</td>
<td>
';
for my $Key ( sort keys %Topics ) {
my $HTMLKey = _Ascii2Html($Key);
my $HTMLValue = _Ascii2Html( $Topics{$Key} );
print $HTMLKey . '<input type="radio" name="Topic" value="' . $HTMLValue . '">';
}
print '
</td>
</tr>
<tr>
<td>From:</td>
<td><input type="text" name="From" size="45" value=""></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="FromEmail" size="45" value=""></td>
</tr>
<tr>
<td>Subject:</td>
<td><input type="text" name="Subject" size="45" value=""></td>
</tr>
<tr valign="top">
<td>Message:</td>
<td><textarea name="Body" rows="15" cols="45"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
';
print Footer();
}
# --------------------------
# send email
# --------------------------
sub SendMail {
my (%Param) = @_;
# check needed params
my $Output = '';
for (qw(From FromEmail Subject Topic Body)) {
if ( !$Param{$_} ) {
$Output .= Error( Message => "Param $_ is needed!" );
}
}
if ($Output) {
print Header( Title => 'Error!' ) . $Output . Footer();
return;
}
# simple email check
my $NonAscii = "\x80-\xff"; # Non-ASCII-Chars are not allowed
my $Nqtext = "[^\\\\$NonAscii\015\012\"]";
my $Qchar = "\\\\[^$NonAscii]";
my $Protocol = '(?:mailto:)';
my $NormUser = '[a-zA-Z0-9][a-zA-Z0-9_.-]*';
my $QuotedString = "\"(?:$Nqtext|$Qchar)+\"";
my $UserPart = "(?:$NormUser|$QuotedString)";
my $DomMainPart = '[a-zA-Z0-9][a-zA-Z0-9._-]*\\.';
my $DomSubPart = '(?:[a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*';
my $DomTldPart = '[a-zA-Z]{2,5}';
my $DomainPart = "$DomSubPart$DomMainPart$DomTldPart";
my $Regex = "$Protocol?$UserPart\@$DomainPart";
if ( $Param{FromEmail} !~ /^$Regex$/ ) {
my $Output = Header( Title => 'Error!' );
$Output .= Error( Message => "Your email '$Param{FromEmail}' is invalid!" );
$Output .= Footer();
print $Output;
return;
}
# quoting (take care to not injection any other header)
for my $Key (qw(From FromEmail Topic Subject Topic)) {
$Param{$Key} =~ s/(\n|\r)//g;
}
# build email
my @Mail = ("From: $Param{From} <$Param{FromEmail}>\n");
push @Mail, "To: $Param{Topic} <$OTRSEmail>\n";
push @Mail, "Subject: $Param{Subject}\n";
push @Mail, "X-OTRS-Ident: $Ident\n";
push @Mail, "X-OTRS-Queue: $Param{Topic}\n";
push @Mail, "X-OTRS-ArticleKey1: Sent via\n";
push @Mail, "X-OTRS-ArticleValue1: Webform\n";
push @Mail, "X-OTRS-ArticleKey2: Orig. sort\n";
push @Mail, "X-OTRS-ArticleValue2: $Param{Topic}\n";
push @Mail, "X-Mailer: OTRS WebForm\n";
push @Mail, "X-Powered-By: OTRS (http://otrs.org/)\n";
push @Mail, "\n";
push @Mail, $Param{Body};
push @Mail, "\n";
# send mail
my $FromEmail = $Param{FromEmail};
$FromEmail =~ s/"|;|'|<|>|\||\s|\r|\n|\t|`//ig;
$FromEmail = quotemeta $FromEmail;
if ( open my $Mail, '|-', "$Sendmail $FromEmail" ) { ## no critic
print $Mail @Mail;
close $Mail;
# thanks!
my $Output = Header( Title => 'Thanks!' );
$Output .= Thanks(%Param);
$Output .= Footer();
print $Output;
}
else {
# error
my $Output = Header( Title => 'Error!' );
$Output .= Error( Message => "Can't send email: $!" );
$Output .= Footer();
print $Output;
}
}
sub _Ascii2Html {
my $Text = shift;
$Text =~ s/&/&/g;
$Text =~ s/</</g;
$Text =~ s/>/>/g;
$Text =~ s/"/"/g;
return $Text;
}
|