Ability to send POST data to plugin via stdin

Version 1.53


Previously, the only way to get POST data to a plugin was through the environment. This had upper limits to it's length, as the env does have limits. This change allows DA to send the entire POST data to the plugin via stdin. To have DA do this, you'd send the GET variable: pipe_post=yes and if that is get via GET, DA will set the environment variable: POST="stdin=true" Here's a sample usage, eg: /usr/local/directadmin/plugins/hello_world/admin/stdin.html ==================== #!/usr/local/bin/php <?php $P=getenv("POST"); if ($P == "stdin=true") { echo "Got some info from stdin!!<br>"; echo "<textarea rows=10 cols=120>"; $data = ''; $stdin = fopen('php://stdin', 'r'); while (($buffer = fgets($stdin, 1024)) !== false) { $data .= $buffer; } if (!feof($stdin)) { echo "Error: unexpected fgets() failn"; } fclose($stdin); $POST = array(); parse_str($data, $POST); print_r($POST); echo "&#92;&#92;From: $data"; echo "</textarea>"; } ?> <form action=?pipe_post=yes method=POST> <input name=data1 value=apple> <input name=data2 value=orange> <input type=submit> </form> ==================== Adjust the 1024 chunk size as needed. DA's pipe send does try to force the entire upload size in the first chunk and then, and uses the write return coded size to determine how big to send the next chunk, with the updated pointer position in the data. Let us know if this is an issue for anyone and we can change it to send specific/restricted chunk sizes, like 1024 or 2048. Might not make a different as packet sizes are still the max chunk size and you should still chunk the receiving end anyway. Note, this is not a "direct" socket from the client to the plugin. DA has already parsed it (if it's multi-part) and the whole thing is stored in ram. This is not the most efficient, but just how DA does it, since the request is 100% parsed first, before any actions are done. File uploads in multi-part are piped to disk and not stored in ram, so the multi-part file upload would be the only "todo" for this feature.. if it's needed. Not tested for multi-part posts (file uploads). This method wouldn't contain the posted file anyway, as DA parses that out of the posted data and only sets the filename. If you need a file upload, try a normal post (non multi-part)... although that's not tested either.

Interested to try DirectAdmin? Get a 30-day Free Trial!