#!/usr/local/bin/perl use CGI ':standard'; # Scritto da Luca Cabibbo basandosi sullo script WebMonitor mail # ====================================================================== # Upload: # # Script CGI per salvare su un file del server Web # informazioni immesse in un form # # La documentazione e' inesistente # ====================================================================== # Users may want to include a: # # If this is present in the FORM input, the client will be redirected # to this HTML file as a confirmation message instead of the default. # In addition, the user can also define any of the following input names # in their form to better customize the output mailed back to them. # # # # These values will then be used in the header of the email message. # Otherwise, default values will be substituted. # ====================================================================== ######################################################################## ########## Configurable variables ###################################### $SAVEDIR = 'C:\\Home\\Apache\\'; ## Cartella dove salvare il file generato ## Also, make sure the first line of this script points ## to your PERL binary ########## Nothing else to change ###################################### ######################################################################## $ENV{'SCRIPT_NAME'} =~ m#(/.*/)(.*)$#; $SCRIPTDIR = $1; $SCRIPT = $2; #### Do standard HTTP stuff #### &cgi_receive; &cgi_decode; &cgi_header; #### Check whether to save if ($ENV{'QUERY_STRING'}) { #### User specified an option #### $tobesaved = $ENV{'QUERY_STRING'}; } else { $tobesaved = 'no'; } #### Check for require fields foreach $field (@requirefields) { &error_blank_field($field) unless ($FORM{$field}); } #### Fill in missing fields for forwarding FORM results #### ($FORM{'traccia'}) || die ("$SCRIPT: Traccia mancante!\n"); ($FORM{'cognome'}) || die ("$SCRIPT: Cognome mancante!\n"); ($FORM{'nome'}) || die ("$SCRIPT: Nome mancante!\n"); ($FORM{'matricola'}) || ($FORM{'matricola'} = "00000"); ($FORM{'estensione'}) || ($FORM{'estensione'} = "txt"); ### Calcola il nome del file $TRACCIA = $FORM{'traccia'}; $COGNOME = $FORM{'cognome'}; $NOME = $FORM{'nome'}; $ESTENSIONE = $FORM{'estensione'}; $TRACCIA =~ s/\W//g; $COGNOME =~ s/\W//g; $NOME =~ s/\W//g; $ESTENSIONE =~ s/\W//g; $SAVEFILE = $SAVEDIR . $TRACCIA . '\\' . $COGNOME . $NOME . '.' . $ESTENSIONE; ($tobesaved eq 'yes') && (&write_file); &write_stdout; #### Now, redirect if "next-url" is included if ($FORM{'next-url'}) { print "Location: $FORM{'next-url'}\n"; print "\n"; exit; } #### Prevent HTML output foreach $key (keys %FORM) { $FORM{$key} =~ s/\</g; $FORM{$key} =~ s/>/\>/g; } exit; ##################################################################### #### SUBROUTINES #################################################### sub write_file { open (FILE, "> $SAVEFILE") || die ("$SCRIPT: Impossibile aprire il file!\n"); binmode FILE; print FILE "// Nome file: $SAVEFILE\n"; print FILE "\n"; &dump_values(FORM, FILE); print FILE "\n"; close (FILE); } #### Output confirmation message #### sub write_stdout { print qq|
\n"; print "// Nome file: $SAVEFILE\n"; print "\n"; &dump_values(FORM, STDOUT); print "\n"; print "\n"; print "\n"; } sub error_blank_field { local($variable) = @_; print "\n" if ($FORM{'next-url'}); print "
\n"); foreach $field (@fields) { next if (grep(/^$field$/, @ignorefields)); if ($FORM{$field} =~ /[\cM\n]/) { $this_field = $FORM{$field}; $this_field =~ s/\r//; print $handle "/* ", "-" x 15, " $field begins here ", "-" x 15, " */\n"; print $handle $this_field; print $handle "\n/* ", "-" x 15, " $field ends here ", "-" x 15, " */\n"; } else { print $handle "// $field: $FORM{$field}\n"; } } ($handle eq "STDOUT") && (print $handle "\n"); }