PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Apache: File upload via HTTP-Formular



vanThomas
17.05.02, 09:11
Hallo zusammen!
Ich habe folgendes Problem:
Ich muss kleine Dateien (<2kb) mittels HTML Formular per Apache-Schnittstelle auf den Server bekommen. Habe bereits google, lycos etc. kontaktiert aber nichts verwertbares gefunden. Die Dateigrösse soll dabei geprüft werden und (wenn sie zu groß ist) die Datei verworfen werden.
PHP-Lösungen sind jedoch nicht möglich, daher suche ich ein Apache-Modul für Apache 1.3.22.
Kennt jemand ein solches Modul ? Wie groß ist der Aufwand?

Wäre superdankbar!!!

Gruß
vanThomas

netzmeister
17.05.02, 13:03
Hallo,

solche Teile gibt es doch zu hauf im Internet.



#!/usr/bin/perl
#
# File Upload Script Version 5.03
# Created by Jeff Carnahan jeffc@terminalp.com
# Created on: 4/8/95 Last Modified on: 06/19/97 17:30
# Scripts Archive: http://www.terminalp.com/scripts/
#
# ---------------------------------------------------------------------
#
# Copyright (C) 1996 Jeffrey D. Carnahan
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) 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.
#
# A full copy of the GNU General Public License can be retrieved from
# http://www.terminalp.com/scripts/copying.html
#
# - Jeff Carnahan <jeffc@terminalp.com
#
# ---------------------------------------------------------------------
# Program Specific Quickie Notes:
# * Make Sure The First Line Is Pointing To The Correct Location Of Perl 5.
# * Make Sure This Program is chmodded with the permissions '755'.
#
# Version: Time Stamp: History:
# __________________________________________________ __________________
#
# 1.00 04/08/96 00:00 The script was created.
# 1.10 04/23/96 00:00 Added User and Group ID to allow file
# changing by the actual user, also updated
# a security hole which allowed any user with
# the UID of 1376 to own the uploaded files.
# Also Updated the INSTALL program and README
# files.
# 3.00 05/07/96 00:00 New release with group and user id fixes, it
# updates a previously unreleased version (2.0)
# 3.10 05/10/96 00:00 Stupid Typo in script fixed, it was
# causing problems for some users.
# 4.00 08/04/96 23:16 Security hole regarding '../' paths
# fixed. Thanks to: Rus Berrett. Mime
# type error fixed. Thanks to: Bob Stewart.
# 4.01 08/07/96 11:20 Typo fixed in &NoOpen. Thanks to Marco
# Dings.
# 5.00 10/06/96 21:42 Fully rewrote script around CGI.pm library.
# As soon as I get the time, I'll write more
# features into it, but for now, this version
# is stable (to the best of my knowledge).
# 5.01 02/09/97 12:41 Fixed some typo's, and added support for
# Netscape Communicator.
# 5.02 05/07/97 15:37 Fixed a possible binary file uploading,
# added easier support for NT, and fixed
# documentation problems. Added the FAQ.
# 5.03 06/19/97 17:30 Fixed a bug which resulted in all files
# appearing to be less than one byte in
# size, thus uploads weren't saved.
# ---------------------------------------------------------------------
# Configurable Options Follow:
#

BEGIN {

$userid = 672; # --> This Number is the specific ID
# --> ID number assigned to you on your
# --> Unix System.

$groupid = 1000; # --> This Number is the specific Group
# --> ID number assigned to people with
# --> your access level on your Unix
# --> system.

#
# --> You can gain your $userid and
# --> $groupid by typing 'id' at your
# --> UNIX prompt. (GID = Group Id,
# --> UID = User Id).

$path = "/home/*user*/www/*verz*";
#
# --> The $path variable should contain the
# --> directory that this script will place
# --> uploaded files into. It should NOT have
# --> a trailing forward slash.

$url = "http://www.*domain.tld*/*verz*";
#
# --> $url should be the URL which corresponds
# --> to the $path defined above. And same
# --> as the $path variable, it SHOULD NOT
# --> have a trailing forward slash.

$overwrite = 1; # --> Set this value to '1' to allow
# --> overwriting of existing files.
# --> Set this value to '0' to dis-allow
# --> the overwriting of existing files.
# -->
# --> NOTE:
# --> Existing files WILL NOT be over-
# --> written unless they are given the
# --> permissions 'a+rw'. An error message
# --> will return to users who try to over-
# --> write files which are protected.

$success_url = "";
#
# --> This contains the URL people should be
# --> redirected to once they have completed
# --> a successful upload. If empty, a page
# --> will be generated, which includes
# --> statistics.

$Windows = 0;
#
# --> $Windows allows you to specifiy if you
# --> are using the Windows operating system
# --> or not. If you are not running this
# --> script under Microsoft Windows, set this
# --> value to zero ('0'). If you are running
# --> under Windows, set this value to one. ('1')

$exclusive_lock = 2; # --> DO NOT CHANGE THIS VALUE - It should
# --> be set to '2'

$unlock_lock = 8; # --> DO NOT CHANGE THIS VALUE - It should
# --> be set to '8'
}
#
# End of Configurable Options.
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# --> Do Not Change Anything Below This Line. <-- #
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------

$| = 1;

&GetInput;
&Process_File;
&Redirect_User;

# ---------------------------------------------------------------------

sub GetInput {
#
# --> Sub: &GetInput();
#
# --> Return:
#
# --> Summary:
# Loads CGI module, assigns $filename the filename the
# file should be saved as.
#

use CGI qw(:standard);
$CGI::OS = 'WINDOWS' if ($Windows);

$query = new CGI;

if ($query->param('save-as-filename') !~ /^[ \t]*$/) {
$filename = $query->param('save-as-filename');
} else {
$filename = $query->param('upload-file');
}

#
# END OF SUB
#
}

# ---------------------------------------------------------------------

sub Process_File {
#
# --> Sub: &Process_File();
#
# --> Return:
#
# --> Summary:
# Takes all the input, determines if the user is using
# the appropiate browser, then extracts the filename,
# and saves the file. Uploaded files are chmodded to 644,
# and given ownership to the user defined in $userid and
# $groupid.
#

&Exit_Not_A_Netscape_User if ($ENV{'HTTP_USER_AGENT'} !~ /^Mozilla\/[432]/);

if ($filename =~ /\//) {
@array = split(/\//, $filename);
$real_name = pop(@array);
} elsif ($filename =~ /\\/) {
@array = split(/\\/, $filename);
$real_name = pop(@array);
} else {
$real_name = "$filename";
}

$outfile = "$path" . "/" . "$real_name";

$filename = $query->param('upload-file');

&Exit_File_Exists if ((-e "$outfile") && (!$overwrite));
# &Exit_Size_Error if ((stat $tmpfilename)[7] < 1);

if (!open(OUTFILE, ">$outfile")) {
print "Content-type: text/plain\n\n";
print "-------------------------\n";
print "Error:\n";
print "-------------------------\n";
print "File: $outfile\n";
print "-------------------------\n";
print "There was an error opening the Output File\n";
print "for Writing.\n\n";
print "Make sure that the directory:\n";
print "$path\n";
print "has been chmodded with the permissions '777'.\n\n";
print "Also, make sure that if your attempting\n";
print "to overwrite an existing file, that the\n";
print "existing file is chmodded '666' or better.\n\n";
print "The Error message below should help you diagnose\n";
print "the problem.\n\n";
print "Error: $!\n";
exit;
}

while ($bytesread = read($filename,$buffer,1024)) {
$totalbytes += $bytesread;
binmode OUTFILE;
print OUTFILE $buffer;
}

close($filename);
close(OUTFILE);

if ((stat $outfile)[7] < 1) {
unlink $outfile;
&Exit_Size_Error;
}
chmod (0644, "$outfile") if (!$Windows);
chown ($userid, $groupid, "$outfile") if (!$Windows);

#
# END OF SUB
#
}

# ---------------------------------------------------------------------

sub Redirect_User {
#
# --> Sub: &Redirect_User();
#
# --> Return:
#
# --> Summary:
# Redirects users to the success url defined in
# $success_url the program then terminates.
#

if ($success_url) {
print "Location: $success_url\n\n\n";
exit 0;
} else {
print header;
print start_html('danke!', '#FFFFFF'),
h1(tt(b(':-)'))), br;

print "Das hat geklappt. Sie haben insgesamt $totalbytes bytes Daten auf den Server geladen\n";
# print "Diese wurden gespeichert. ber diese URL: koennen Sie die Daten abrufen ";
# print a({HREF=>"$url/$real_name"}, "$url/$real_name"), "\n";
print end_html;
exit 0;
}

#
# END OF SUB
#
}

# ---------------------------------------------------------------------

sub Exit_Not_A_Netscape_User {
#
# --> Sub: &Exit_Not_A_Netscape_User();
#
# --> Return:
#
# --> Summary:
# This user is not using a version of Netscape claiming
# to be above version 2.0...
#

print header;
print start_html('Error!', '#FFFFFF');
print h1(tt(b('Error! - Invalid Browser'))), br;
print "Sorry, but you must use Netscape 2.0+ to use this system. MSIE will not work under any circumstances.";
print " Please return to the upload page with a different browser.\n";
print end_html;
exit 0;

#
# END OF SUB
#
}

# ---------------------------------------------------------------------

sub Exit_File_Exists {
#
# --> Sub: &Exit_File_Exists();
#
# --> Return:
#
# --> Summary:
# This user is trying to upload a file with a filename
# that is already in use, and this script is set not to
# overwrite existing files.
#

print header;
print start_html('Error!', '#FFFFFF');
print h1(tt(b('Error! - Filename in Use'))), br;
print "Sorry, but this system is not allowed to overwrite existing files. The filename you have selected is";
print " already in use in the directory file-uploads are allowed. Please use the back button on your browser,";
print " rename the file, and try again.\n";
print end_html;
exit 0;

#
# END OF SUB
#
}

# ---------------------------------------------------------------------

sub Exit_Size_Error {
#
# --> Sub: &Exit_Size_Error();
#
# --> Return:
#
# --> Summary:
# This user is uploaded a file, however it's less than
# one byte in size.
#

print header;
print start_html('Error!', '#FFFFFF');
print h1(tt(b('Error! - Size Error'))), br;
print "Sorry, but it seems that the file you uploaded is less than 1 byte in size. This means that there was an";
print " error transfering the file from your computer to the server. Verify with the server administrator that";
print " you are allowed to upload files, and verify that the file you are attempting to upload exists on your system.\n";
print end_html;
exit 0;

#
# END OF SUB
#
}

# ---------------------------------------------------------------------
# EOF

vanThomas
17.05.02, 13:39
erst mal danke für die schnelle antwort, jedoch finde ich keine angaben darüber, wo man die max. obergrenze der dateigrösse angeben kann (oder aber ich bin blind). ausserdem funzenuckelt das leider nur mit netscape-browsern und nicht mit dem msie....
ich werde mal mod_put in verbindung mit apache::registry ausprobieren...
hoffentlich klappt das besser....*mir selber daumen drück*

gruß

vanThomas

red
17.05.02, 14:54
hi, probiers doch mal mit php

vanThomas
19.05.02, 09:18
php hab ich mir auch schon überlegt. das wäre eigentlich die einfachste und eleganteste alternative....
allerdings hab ich leider die gewisse vorgabe, daß das über "reine apachebordmittel" abgefrühstückt werden muss... damit scheidet php aus...
*immer noch weiter das netz durchsuch*

allen ein frohes pfingstfest!!!