<FORM ENCTYPE="multipart/form-data" METHOD="post" ACTION="https://ourdomain.com/cgi-bin/save-ascii"> <BR> Username: <INPUT type="text" name="user" value=""> <BR> Password: <INPUT type="password" name="pass" value=""> <BR> Filename: <INPUT TYPE="FILE" NAME="FILE"> <BR> <INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Submit"> </FORM>
#!/usr/bin/perl use MIME::Base64 (); # put some error checking here eventually $user = $ARGV[0]; $pass = $ARGV[1]; $file = $ARGV[2]; open(OUT,"|/usr/local/openssl/bin/openssl s_client -v -connect www:443 +") or die "Failure\n"; binmode OUT; $bound = "---------------------------2218759766176618872063491442"; # print out header stuff print OUT "POST /cgi-bin/save HTTP/1.0\n"; print OUT "Referer: https://www/upload.html\n"; print OUT "Connection: Keep-Alive\n"; print OUT "User-Agent: Amelindinator/0.1 [en] (amelinda\@mydomain.com) +\n"; print OUT "Host: www.mydomain.com:443\n"; print OUT "Content-type: multipart/form-data; boundary=$bound\n"; print OUT "Content-Length: "; # calculate content length open(FILE, "$file") or die "$!"; binmode FILE; # I'm not sure I need this. local($/) = undef; # slurp $mime = MIME::Base64::encode(<FILE>); close(FILE); $len = (length $mime) + (length $user) + (length $pass); $len += 514; # this is stuff that is constant # print rest of stuff. print OUT "$len\n\n"; print OUT "--$bound\n"; print OUT "Content-Disposition: form-data; name=\"user\"\n\n"; print OUT "$user\n"; print OUT "--$bound\n"; print OUT "Content-Disposition: form-data; name=\"pass\"\n\n"; print OUT "$pass\n"; print OUT "--$bound\n"; print OUT "Content-Disposition: form-data; name=\"FILE\"; filename=\"$ +file\"\n"; print OUT "Content-Transfer-Encoding: BASE64\n\n"; print OUT $mime; # print out the mimencoded bit here print OUT "--$bound\n"; print OUT "Content-Disposition: form-data; name=\"SUBMIT\"\n\n"; print OUT "Submit\n"; print OUT "--$bound--\n"; # close the stream, silly! close(OUT); exit;
In reply to amelinda's HTTP/MIME/file upload/not-a-cgi-but-a-client/minimal-module/perl problem by amelinda
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |