X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=SL%2FForm.pm;h=464405ca40eae528f61cf8632e7298cc4c0b73e3;hb=0a25d5a4019fabab620cae0ff7a0a713d132d2fa;hp=9253f419ddfcff32e637d4bd0789e45b87b4b56e;hpb=85f2addd9be287bfc2226e3a08c29efc0c0131d2;p=kivitendo-erp.git
diff --git a/SL/Form.pm b/SL/Form.pm
index 9253f419d..464405ca4 100644
--- a/SL/Form.pm
+++ b/SL/Form.pm
@@ -1,4 +1,4 @@
-#=====================================================================
+#====================================================================
# LX-Office ERP
# Copyright (C) 2004
# Based on SQL-Ledger Version 2.1.9
@@ -36,9 +36,30 @@
#======================================================================
package Form;
+use Data::Dumper;
+
+use Cwd;
+use HTML::Template;
+use SL::Template;
+use CGI::Ajax;
+use SL::DBUtils;
+use SL::Mailer;
+use SL::Menu;
+use SL::User;
+use SL::Common;
+use CGI;
+
+my $standard_dbh;
+
+sub DESTROY {
+ if ($standard_dbh) {
+ $standard_dbh->disconnect();
+ undef $standard_dbh;
+ }
+}
sub _input_to_hash {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(2);
my $input = $_[0];
my %in = ();
@@ -49,70 +70,86 @@ sub _input_to_hash {
$in{$name} = unescape(undef, $value);
}
- $main::lxdebug->leave_sub();
+ $main::lxdebug->leave_sub(2);
return %in;
}
sub _request_to_hash {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(2);
my ($input) = @_;
- my ($i, $loc, $key, $val);
- my (%ATTACH, $f, $header, $header_body, $len, $buf);
- my ($boundary, @list, $size, $body, $x, $blah, $name);
-
- if ($ENV{'CONTENT_TYPE'}
- && ($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data; boundary=(.+)$/)) {
- $boundary = quotemeta('--' . $1);
- @list = split(/$boundary/, $input);
-
- # For some reason there are always 2 extra, that are empty
- $size = @list - 2;
-
- for ($x = 1; $x <= $size; $x++) {
- $header_body = $list[$x];
- $header_body =~ /\r\n\r\n|\n\n/;
-
- # Here we split the header and body
- $header = $`;
- $body = $'; #'
- $body =~ s/\r\n$//;
-
- # Now we try to get the file name
- $name = $header;
- $name =~ /name=\"(.+)\"/;
- ($name, $blah) = split(/\"/, $1);
-
- # If the form name is not attach, then we need to parse this like
- # regular form data
- if ($name ne "attach") {
- $body =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
- $ATTACH{$name} = $body;
-
- # Otherwise it is an attachment and we need to finish it up
- } elsif ($name eq "attach") {
- $header =~ /filename=\"(.+)\"/;
- $ATTACH{'FILE_NAME'} = $1;
- $ATTACH{'FILE_NAME'} =~ s/\"//g;
- $ATTACH{'FILE_NAME'} =~ s/\s//g;
- $ATTACH{'FILE_CONTENT'} = $body;
-
- for ($i = $x; $list[$i]; $i++) {
- $list[$i] =~ s/^.+name=$//;
- $list[$i] =~ /\"(\w+)\"/;
- $ATTACH{$1} = $'; #'
+
+ if (!$ENV{'CONTENT_TYPE'}
+ || ($ENV{'CONTENT_TYPE'} !~ /multipart\/form-data\s*;\s*boundary\s*=\s*(.+)$/)) {
+ $main::lxdebug->leave_sub(2);
+ return _input_to_hash($input);
+ }
+
+ my ($name, $filename, $headers_done, $content_type, $boundary_found, $need_cr);
+ my %params;
+
+ my $boundary = '--' . $1;
+
+ foreach my $line (split m/\n/, $input) {
+ last if (($line eq "${boundary}--") || ($line eq "${boundary}--\r"));
+
+ if (($line eq $boundary) || ($line eq "$boundary\r")) {
+ $params{$name} =~ s|\r?\n$|| if $name;
+
+ undef $name, $filename;
+
+ $headers_done = 0;
+ $content_type = "text/plain";
+ $boundary_found = 1;
+ $need_cr = 0;
+
+ next;
+ }
+
+ next unless $boundary_found;
+
+ if (!$headers_done) {
+ $line =~ s/[\r\n]*$//;
+
+ if (!$line) {
+ $headers_done = 1;
+ next;
+ }
+
+ if ($line =~ m|^content-disposition\s*:.*?form-data\s*;|i) {
+ if ($line =~ m|filename\s*=\s*"(.*?)"|i) {
+ $filename = $1;
+ substr $line, $-[0], $+[0] - $-[0], "";
}
+
+ if ($line =~ m|name\s*=\s*"(.*?)"|i) {
+ $name = $1;
+ substr $line, $-[0], $+[0] - $-[0], "";
+ }
+
+ $params{$name} = "";
+ $params{FILENAME} = $filename if ($filename);
+
+ next;
+ }
+
+ if ($line =~ m|^content-type\s*:\s*(.*?)$|i) {
+ $content_type = $1;
}
+
+ next;
}
- $main::lxdebug->leave_sub();
- return %ATTACH;
+ next unless $name;
- } else {
- $main::lxdebug->leave_sub();
- return _input_to_hash($input);
+ $params{$name} .= "${line}\n";
}
+
+ $params{$name} =~ s|\r?\n$|| if $name;
+
+ $main::lxdebug->leave_sub(2);
+ return %params;
}
sub new {
@@ -122,6 +159,11 @@ sub new {
my $self = {};
+ if ($LXDebug::watch_form) {
+ require SL::Watchdog;
+ tie %{ $self }, 'SL::Watchdog';
+ }
+
read(STDIN, $_, $ENV{CONTENT_LENGTH});
if ($ENV{QUERY_STRING}) {
@@ -135,13 +177,10 @@ sub new {
my %parameters = _request_to_hash($_);
map({ $self->{$_} = $parameters{$_}; } keys(%parameters));
- $self->{menubar} = 1 if $self->{path} =~ /lynx/i;
-
$self->{action} = lc $self->{action};
- $self->{action} =~ s/( |-|,|#)/_/g;
+ $self->{action} =~ s/( |-|,|\#)/_/g;
- $self->{version} = "2.1.2";
- $self->{dbversion} = "2.1.2";
+ $self->{version} = "2.4.2";
$main::lxdebug->leave_sub();
@@ -161,24 +200,19 @@ sub debug {
}
sub escape {
- $main::lxdebug->enter_sub();
-
- my ($self, $str, $beenthere) = @_;
+ $main::lxdebug->enter_sub(2);
- # for Apache 2 we escape strings twice
- #if (($ENV{SERVER_SOFTWARE} =~ /Apache\/2/) && !$beenthere) {
- # $str = $self->escape($str, 1);
- #}
+ my ($self, $str) = @_;
$str =~ s/([^a-zA-Z0-9_.-])/sprintf("%%%02x", ord($1))/ge;
- $main::lxdebug->leave_sub();
+ $main::lxdebug->leave_sub(2);
return $str;
}
sub unescape {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(2);
my ($self, $str) = @_;
@@ -187,33 +221,75 @@ sub unescape {
$str =~ s/%([0-9a-fA-Z]{2})/pack("c",hex($1))/eg;
- $main::lxdebug->leave_sub();
+ $main::lxdebug->leave_sub(2);
return $str;
}
-sub error {
- $main::lxdebug->enter_sub();
+sub quote {
+ my ($self, $str) = @_;
- my ($self, $msg) = @_;
+ if ($str && !ref($str)) {
+ $str =~ s/\"/"/g;
+ }
- if ($ENV{HTTP_USER_AGENT}) {
- $msg =~ s/\n/
/g;
+ $str;
- $self->header;
+}
- print qq|
-
$msg +} - -