summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndreas Brachold <vdr07@deltab.de>2008-02-09 21:22:07 +0000
committerAndreas Brachold <vdr07@deltab.de>2008-02-09 21:22:07 +0000
commit995298ca98a9129f0f24b598637a486f85d4f23e (patch)
treee040c701b1c060c12fbe535fb84e6a30a94d2b8c /lib
parente194290db05bf0d1c6b6b49106c2c28197141b6e (diff)
downloadxxv-995298ca98a9129f0f24b598637a486f85d4f23e.tar.gz
xxv-995298ca98a9129f0f24b598637a486f85d4f23e.tar.bz2
* VTX: get font failed with wrong parameter
* HTTPD: deliver static html pages never as attachment
Diffstat (limited to 'lib')
-rw-r--r--lib/XXV/MODULES/HTTPD.pm72
-rw-r--r--lib/XXV/MODULES/VTX.pm8
-rw-r--r--lib/XXV/OUTPUT/Html.pm36
3 files changed, 61 insertions, 55 deletions
diff --git a/lib/XXV/MODULES/HTTPD.pm b/lib/XXV/MODULES/HTTPD.pm
index e4b9377..d32feb3 100644
--- a/lib/XXV/MODULES/HTTPD.pm
+++ b/lib/XXV/MODULES/HTTPD.pm
@@ -13,24 +13,26 @@ $| = 1;
use strict;
my $mime = {
- png => "image/png",
- gif => "image/gif",
- jpg => "image/jpeg",
- css => "text/css",
- ico => "image/x-icon",
- js => "application/x-javascript",
- m3u => "audio/x-mpegurl",
- mp3 => "audio/x-mp3",
- wav => "audio/x-wav",
- ogg => "application/x-ogg",
- rss => "application/xhtml+xml",
- avi => "video/avi",
- mp4 => "video/mp4",
- mpg => "video/x-mpeg",
- mpeg => "video/x-mpeg",
- mov => "video/quicktime",
- wmv => "video/x-ms-wmv",
- flv => "video/x-flv"
+ htm => ["text/html", '', ''],
+ html => ["text/html", '', ''],
+ png => ["image/png", 'nopack','attachment'],
+ gif => ["image/gif", 'nopack','attachment'],
+ jpg => ["image/jpeg", 'nopack','attachment'],
+ css => ["text/css", '' ,'attachment'],
+ ico => ["image/x-icon", 'nopack','attachment'],
+ js => ["application/x-javascript",'' ,'attachment'],
+ m3u => ["audio/x-mpegurl", 'nopack','attachment'],
+ mp3 => ["audio/x-mp3", 'nopack','attachment'],
+ wav => ["audio/x-wav", 'nopack','attachment'],
+ ogg => ["application/x-ogg", 'nopack','attachment'],
+ rss => ["application/xhtml+xml", '', 'attachment'],
+ avi => ["video/avi", 'nopack','attachment'],
+ mp4 => ["video/mp4", 'nopack','attachment'],
+ mpg => ["video/x-mpeg", 'nopack','attachment'],
+ mpeg => ["video/x-mpeg", 'nopack','attachment'],
+ mov => ["video/quicktime", 'nopack','attachment'],
+ wmv => ["video/x-ms-wmv", 'nopack','attachment'],
+ flv => ["video/x-flv", 'nopack','attachment']
};
# This module method must exist for XXV
@@ -271,20 +273,12 @@ sub communicator
or exists $console->{USER}->{Level})) {
$console->setCall('nothing');
- if(($data->{Request} eq '/' or $data->{Request} =~ /\.html$/) and not $data->{Query}) {
+ if($data->{Request} eq '/' and not $data->{Query}) {
# Send the first page (index.html)
- my $page = $data->{Request};
- $page =~ s/\.\.\///g;
- $page =~ s/\/\.\.//g;
- $page =~ s/\/+/\//g;
- if($page eq '/') {
- if(-r sprintf('%s/index.tmpl', $htmlRootDir)) {
- $console->index;
- } else {
- $console->datei(sprintf('%s/index.html', $htmlRootDir));
- }
+ if(-r sprintf('%s/index.tmpl', $htmlRootDir)) {
+ $console->index;
} else {
- $console->datei(sprintf('%s%s', $htmlRootDir, $page));
+ $console->datei(sprintf('%s/index.html', $htmlRootDir));
}
} elsif(my $typ = $mime->{lc((split('\.', $data->{Request}))[-1])}) {
# Send multimedia files (this must registered in $mime!)
@@ -313,7 +307,7 @@ sub communicator
$request =~ s/.*tempimages\//$tmp\//;
$console->datei($request, $typ);
} else {
- $console->datei(sprintf('%s%s', $htmlRootDir, $request), $typ);
+ $console->datei($htmlRootDir . $request, $typ);
}
} else {
$obj->handleInput($watcher, $console, $cgi);
@@ -377,7 +371,7 @@ sub parseRequest {
my $data = {};
my $line;
while (defined($line = &_readline($socket))) {
- if(!$line || $line =~ /^\r\n$/) {
+ if(!$line || $line eq "\r\n") {
last;
} elsif(!$data->{Method} && $line =~ /^(\w+) (\/[\w\.\/\-\:\%]*)([\?[\w=&\.\+\%-\:\!]*]*)[\#\d ]+HTTP\/1.\d/) {
($data->{Method}, $data->{Request}, $data->{Query}) = ($1, $2, $3 ? substr($3, 1, length($3)) : undef);
@@ -409,12 +403,13 @@ sub parseRequest {
}
$data->{Request} =~ s/%([a-f0-9][a-f0-9])/pack("C", hex($1))/ieg
- if($data->{Request});
+ if($data->{Request});
+ if($data->{Method}) {
if($data->{Method} eq 'GET'
or $data->{Method} eq 'HEAD') {
#dumper($data);
return $data;
- } elsif($data->{Method} eq 'POST') {
+ } elsif($data->{Method} eq 'POST') {
if(int($data->{ContentLength})>0) {
my $post;
my $bytes = sysread($socket,$post,$data->{ContentLength});
@@ -424,10 +419,11 @@ sub parseRequest {
}
#dumper($data);
return $data;
- } else {
- return undef;
- }
-
+ } else {
+ lg sprintf("Unsupported HTTP Method : %s",$data->{Method});
+ }
+ }
+ return undef;
}
# ------------------
sub ModulNotLoaded {
diff --git a/lib/XXV/MODULES/VTX.pm b/lib/XXV/MODULES/VTX.pm
index 15adcf6..490ad49 100644
--- a/lib/XXV/MODULES/VTX.pm
+++ b/lib/XXV/MODULES/VTX.pm
@@ -1406,14 +1406,18 @@ sub image {
my $obj = shift || return error('No object defined!');
my $watcher = shift || return error('No watcher defined!');
my $console = shift || return error('No console defined!');
- my $data = shift || return error('No file defined!');
+ my $data = shift;
- $console->err(gettext("Sorry, get image is'nt supported"))
+ return $console->err(gettext("Sorry, get image is'nt supported"))
if ($console->{TYP} ne 'HTML');
# data like black3F
$data =~ s/[^a-z0-9A-F]//g; # Remove unwantet character
+ # data lookup failed
+ return $console->status404('NULL','Wrong image parameter')
+ unless($data);
+
# Split data
my $color = $data;
$color =~ s/[^a-z]//g;
diff --git a/lib/XXV/OUTPUT/Html.pm b/lib/XXV/OUTPUT/Html.pm
index f8bd0ab..2c67976 100644
--- a/lib/XXV/OUTPUT/Html.pm
+++ b/lib/XXV/OUTPUT/Html.pm
@@ -302,8 +302,8 @@ sub parseTemplateFile {
sub out {
# ------------------
my $self = shift || return error('No object defined!');
- my $text = shift || 'no Text for Output';
- my $type = shift || 'text/html';
+ my $text = shift;
+ my $type = shift;
my %args = @_;
unless(defined $self->{header}) {
@@ -311,7 +311,7 @@ sub out {
$self->{output_header} = $self->header($type, \%args);
}
- $self->{output} .= $text,"\r\n"
+ $self->{output} .= $text
if($text);
}
@@ -602,24 +602,29 @@ sub datei {
# ------------------
my $self = shift || return error('No object defined!');
my $file = shift || return error('No file defined!');
- my $typ = shift;
+ my $mimetyp = shift;
my %args = ();
my $fst = stat($file);
unless($fst and ($fst->mode & 00400)) { # mode & S_IRUSR
- error sprintf("Couldn't stat file '%s' : %s",$file,$!);
- return $self->status404($file,$!);
+ my $error = $!;
+ error sprintf("Couldn't stat file '%s' : %s",$file,$error);
+ return $self->status404($file,$error);
}
my $size = $fst->size;
- $typ = $self->{mime}->{lc((split('\.', $file))[-1])}
- unless($typ);
- $typ = "application/octet-stream"
- unless($typ);
-
- $self->{nopack} = 1
- if($typ =~ /image\// || $typ =~ /video\//);
+ $mimetyp = $self->{mime}->{lc((split('\.', $file))[-1])}
+ unless($mimetyp);
+ my $typ;
+ if($mimetyp && $mimetyp->[0]) {
+ $typ = $mimetyp->[0];
+ $self->{nopack} = 1
+ if($mimetyp->[1] && $mimetyp->[1] eq 'nopack');
+ } else {
+ $typ = "application/octet-stream";
+ $self->{nopack} = 1;
+ }
# header only if caching
$args{'ETag'} = sprintf('%x-%x-%x',$fst->ino, $size, $fst->mtime);
@@ -628,9 +633,10 @@ sub datei {
&& $args{'ETag'} eq $self->{browser}->{'Match'});
$args{'Last-Modified'} = datum($fst->mtime,'header');
- $args{'attachment'} = basename($file);
+ $args{'attachment'} = basename($file)
+ if($mimetyp->[2] && $mimetyp->[2] eq 'attachment');
$args{'Content-Length'} = $size
- if($self->{nopack});
+ if($self->{nopack});
if($size > (32768 * 16)) { ## Only files bigger then 512k
lg sprintf("stream file : '%s' (%s)",$file,convert($size));