Search code examples
pythoniispostcgissi

Server side includes (ssi) on IIS server, read POST request data fails


My Goal is that my SSI (shtml) will parse POST data parameters and return a long encrypted string which will be based on those parameters. I am using IIS as the server.

My constraints:

  1. I can't change the url - /document.shtml
  2. The shtml need to return only the base 64 string result.

What i tried:

  1. Use of "exec cgi" in the shtml, this way:

document.shtml:

<!--#exec cgi="/pythonApp/test.py?sdfsdf=sdfsdf" -->

test.py (simplified version , without the encryption logic behind):

import cgitb
cgitb.enable()
import base64,urllib,json,os,sys
import cgi

print "Content-Type: text/plain;charset=utf-8"
print

cl, _ = cgi.parse_header(os.environ['CONTENT_LENGTH'])
if (int(cl)>0):
	data = sys.stdin.read(int(cl))
	input_j = json.loads(data)

	print "AB : ",input_j["AB"] 
else:
	print "Failed to read POST request"

The problem here, is that if i send post request to .../test.py , then it works, but if i send the request to document.shtml, the content length will still be positive as described by the environment variable, but the stdin will get an error.

  1. My other idea was to read the POST data , somehow from the shtml itself and pass it to the cgi , this way:

<!--#exec cgi="/pythonApp/test.py?sdfsdf=sdfsdf" -->

The problem , is that i looked over the net and haven't found a way to do it from the shtml.

Any suggestions? am i missing something simple?


Solution

  • I haven't found away to do it using SSI directive , i did understand that the stdin is not passed to the cgi from the main script.

    So i found other solution which still answers my constrains.

    In the IIS Handler Mapping for SHTML , i configured the executable to be php.

    and in the shtml it self i wrote a php code (showing here just the sample that prints the json string):

    <?php var_dump($HTTP_RAW_POST_DATA); ?>