~ubuntu-branches/ubuntu/natty/otrs2/natty-updates

« back to all changes in this revision

Viewing changes to scripts/webform.pl

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2007-04-14 17:58:55 UTC
  • mto: (20.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: package-import@ubuntu.com-20070414175855-9ne0w01yu1q44ch0
Tags: upstream-2.1.7
ImportĀ upstreamĀ versionĀ 2.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
# --
3
3
# webform.pl - a simple web form script to generate email with
4
4
# X-OTRS-Queue header for an OTRS system (x-headers for dispatching!).
5
 
# Copyright (C) 2002 Martin Edenhofer <martin+code@otrs.org>
 
5
# Copyright (C) 2001-2006 OTRS GmbH, http://otrs.org/
6
6
# --
7
 
# $Id: webform.pl,v 1.3 2003/02/08 15:11:52 martin Exp $
 
7
# $Id: webform.pl,v 1.7 2006/11/02 12:21:00 tr Exp $
8
8
# --
9
9
# This program is free software; you can redistribute it and/or modify
10
10
# it under the terms of the GNU General Public License as published by
11
11
# the Free Software Foundation; either version 2 of the License, or
12
12
# (at your option) any later version.
13
 
 
13
#
14
14
# This program is distributed in the hope that it will be useful,
15
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
17
# GNU General Public License for more details.
18
 
 
18
#
19
19
# You should have received a copy of the GNU General Public License
20
20
# along with this program; if not, write to the Free Software
21
21
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
27
# Simple Common Gateway Interface Class
28
28
use CGI;
29
29
 
30
 
my $VERSION = '$Revision: 1.3 $';
 
30
my $VERSION = '$Revision: 1.7 $';
31
31
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
32
32
 
33
 
 
34
 
# --
 
33
# --------------------------
35
34
# web form options
36
 
# -- 
 
35
# --------------------------
37
36
my $Ident = 'ahfiw2Fw32r230dddl2foeo3r';
38
37
# sendmail location and options
39
38
my $Sendmail = '/usr/sbin/sendmail -t -i -f ';
50
49
    'Webmaster' => 'webmaster',
51
50
);
52
51
 
53
 
# --
 
52
# --------------------------
54
53
# html header
55
 
# --
 
54
# --------------------------
 
55
 
56
56
sub Header {
57
57
    my %Param = @_;
58
58
    (my $Output = <<EOF);
69
69
EOF
70
70
    return $Output;
71
71
}
72
 
# --
 
72
 
 
73
# -------------------------
73
74
# html footer
74
 
# --
 
75
# -------------------------
 
76
 
75
77
sub Footer {
76
78
    (my $Output = <<EOF);
77
79
<hr>
81
83
EOF
82
84
    return $Output;
83
85
}
84
 
# --
85
 
# Thanks      
86
 
# --
 
86
 
 
87
# -------------------------
 
88
# Thanks
 
89
# -------------------------
 
90
 
87
91
sub Thanks {
88
 
    my %Param = @_;    
 
92
    my %Param = @_;
89
93
    (my $Output = <<EOF);
90
94
Thanks <b>$Param{From}</b>! Your request is forwarded to us. <br>
91
95
We will answer ASAP.<br>
92
96
EOF
93
97
    return $Output;
94
98
}
95
 
# --
96
 
# error       
97
 
# --
 
99
 
 
100
# ----------------------
 
101
# error
 
102
# ----------------------
 
103
 
98
104
sub Error {
99
 
    my %Param = @_;    
 
105
    my %Param = @_;
100
106
    (my $Output = <<EOF);
101
107
<font color="red">$Param{Message}</font><br>
102
108
EOF
103
109
    return $Output;
104
110
}
105
111
 
106
 
# --
 
112
# ------------------------
107
113
# start the real actions
108
 
# --
 
114
# ------------------------
109
115
my $CGI = new CGI;
110
116
my %GetParam = ();
111
117
foreach (qw(Action From FromEmail Subject Topic Body)) {
112
118
    $GetParam{$_} = $CGI->param($_) || '';
113
119
}
114
 
# what should I do? 
 
120
# what should I do?
115
121
if ($GetParam{Action} eq 'SendMail') {
116
122
    SendMail(%GetParam);
117
123
}
119
125
    WebForm();
120
126
}
121
127
 
122
 
# --
 
128
# ------------------------
123
129
# web form
124
 
# --
 
130
# ------------------------
125
131
sub WebForm {
126
 
    print Header(Title => 'Submit Request');    
 
132
    print Header(Title => 'Submit Request');
127
133
print '
128
134
    <form action="webform.pl" method="post">
129
135
    <input type="hidden" name="Action" value="SendMail">
163
169
';
164
170
    print Footer();
165
171
}
166
 
# --
 
172
# --------------------------
167
173
# send email
168
 
# --
 
174
# --------------------------
 
175
 
169
176
sub SendMail {
170
177
    my %Param = @_;
171
178
    my $Output = '';
172
 
    # --
 
179
 
173
180
    # check needed params
174
 
    # --
175
181
    foreach (qw(From FromEmail Subject Topic Body)) {
176
182
        if (!$Param{$_}) {
177
183
            $Output .= Error(Message => "Param $_ is needed!");
183
189
        print $Output;
184
190
        return;
185
191
    }
186
 
    # --
 
192
 
187
193
    # simple email check
188
 
    # ---
189
 
    if ($Param{FromEmail} !~ /.+?\@.+?\..+?/) {
 
194
    my $NonAscii      = "\x80-\xff"; # Non-ASCII-Chars are not allowed
 
195
    my $Nqtext        = "[^\\\\$NonAscii\015\012\"]";
 
196
    my $Qchar         = "\\\\[^$NonAscii]";
 
197
    my $Protocol      = '(?:mailto:)';
 
198
    my $NormUser      = '[a-zA-Z0-9][a-zA-Z0-9_.-]*';
 
199
    my $QuotedString  = "\"(?:$Nqtext|$Qchar)+\"";
 
200
    my $UserPart     = "(?:$NormUser|$QuotedString)";
 
201
    my $DomMainPart  = '[a-zA-Z0-9][a-zA-Z0-9._-]*\\.';
 
202
    my $DomSubPart   = '(?:[a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*';
 
203
    my $DomTldPart   = '[a-zA-Z]{2,5}';
 
204
    my $DomainPart   = "$DomSubPart$DomMainPart$DomTldPart";
 
205
    my $Regex         = "$Protocol?$UserPart\@$DomainPart";
 
206
 
 
207
    if ($Param{FromEmail} !~ /^$Regex$/) {
190
208
        $Output = Header(Title => 'Error!');
191
 
        $Output .= Error(Message => "Your email '$Param{FromEmail}' is invalid!"); 
 
209
        $Output .= Error(Message => "Your email '$Param{FromEmail}' is invalid!");
192
210
        $Output .= Footer();
193
211
        print $Output;
194
212
        return;
195
213
    }
196
 
    # --
197
214
    # build email
198
 
    # --
199
215
    my @Mail = ("From: $Param{From} <$Param{FromEmail}>\n");
200
216
    push @Mail, "To: $Param{Topic} <$OTRSEmail>\n";
201
217
    push @Mail, "Subject: $Param{Subject}\n";
210
226
    push @Mail, "\n";
211
227
    push @Mail, $Param{Body};
212
228
    push @Mail, "\n";
213
 
    # --
 
229
 
214
230
    # send mail
215
 
    # --
216
231
    $Param{From} =~ s/"|;|'|<|>|\|| //ig;
217
232
    if (open(MAIL, "|$Sendmail $Param{From} ")) {
218
233
        print MAIL @Mail;
219
234
        close(MAIL);
220
 
        # --
 
235
 
221
236
        # thanks!
222
 
        # --
223
237
        $Output = Header(Title => 'Thanks!');
224
238
        $Output .= Thanks(%Param);
225
 
        $Output .= Footer(); 
 
239
        $Output .= Footer();
226
240
        print $Output;
227
 
    } 
 
241
    }
228
242
    else {
229
243
        # error
230
244
        $Output = Header(Title => 'Error!');
233
247
        print $Output;
234
248
    }
235
249
}
236
 
# --
237