PirateBox-Dev / PirateBoxScripts_Webserver

PirateBox Scriptcollection for running in Webserver
GNU General Public License v3.0
206 stars 102 forks source link

Different upload-script via lighttpd-cgi #169

Open MaStr opened 7 years ago

MaStr commented 7 years ago

Use "server.stream-request-body = 2" in lighttpd configuration to enable stream transfer over the buffered upload option. This can be used to write a new uploader which directly writes into the target directory.

I'm also against using C programs in PirateBox. Yes, it should be possible to use other languages (everything that you can use for CGI + that can read environment variables and stdin should be good). Lighttpd gives two important environment variables to the CGI script: REQUEST_METHOD (should be "POST" ) and CONTENT_TYPE (should start with "multipart/form-data" and also contain the boundary). Then there's a third one: CONTENT_LENGTH - This is the length of the bytestream waiting on stdin. There might be more environment variables but these are what my c tool uses to determine it's really a file upload. Then it's code that should be simple to port in any other language:

Language: C

while(len > 0) // len == CONTENT_LENGTH
{
        size_t got = fread(buffer, 1, len < BUFSIZE ? len : BUFSIZE), stdin);
        if(len < 1)
        {
                // Error handling here
        }
        else
        {
                len -= got;
                // Do something with the buffer, i.e. find boundary, read header, pipe body to a file, ...
        }
}

by V10lator via https://forum.piratebox.cc/read.php?3,6801,20545#msg-20545

MaStr commented 6 years ago

some remarks from latest development progress:

MaStr commented 6 years ago

First set of changes is pushed into feature-branch "feat-phpupload".

Done:

Still to do: