2016-07-12 2 views
0

は、既存の投稿からのアドバイスを見て、やった:のpythonのcgi - ヘッダーエラーから抜け出すことができない

(1)置くことによって "SyntaxError: EOF while scanning triple-quoted string literal" の世話をした

(2)たぶん"print "Content-type: text/html\n\n""と

でも悪いヘッダを世話しました。

[Tue Jul 12 14:55:59 2016] [error] [client 172.16.1.18] malformed header from script. Bad header=172.16.1.18 [has executed] d: reset.py, referer: http://172.16.1.18/cgi-bin/index.cgi?message= 

アドバイスをいただければ幸いです。

ありがとうございました。 "ダニエル・ローズマン" に

【にindex.cgiの一部】

<form name="input" action="/cgi-bin/reset.py" method="get"> 
<input type="submit" value="Reset"> 

[reset.py]

#!/usr/bin/python 
import cgi 
import cgitb; cgitb.enable() # for troubleshooting 
import os 
import subprocess 
form = cgi.FieldStorage() 
from subprocess import * 
message = form.getvalue("message", "(no message)") 
print os.environ["REMOTE_ADDR"]+ " [has executed] " + Popen('ls', shell=True, stdin=PIPE, stdout=PIPE).communicate()[0] 
print "Content-type: text/html\n\n" 
print """ 
<html> 
<h2><title>Resetting</title> 
<body> 
<h3> Resetting </h3> 
<p>Done</p> 
</body> 
</html" 
print """ 
print cgi.escape(message) 
+0

最初のprint文は何ですか? –

+0

私はこのリセットスクリプトを実行した人を表示するために "reset.py"をします。私はこれを理解するとすぐに 'ls'がスクリプトに置き換えられます。 – SndLt

+0

しかし、ヘッダーの一部として印刷しています。それはあなたの問題の一部ではありませんか? –

答えて

0

おかげヘッダ以下のコマンドを動かし。 私は、直接htmlではないバックボーンコードは以下のものではないと考えました。

import subprocess 
form = cgi.FieldStorage() 
from subprocess import * 
message = form.getvalue("message", "(no message)") 
print "Content-type: text/html\n\n" 
print os.environ["REMOTE_ADDR"]+ " [has executed] " + Popen('df -h', shell=True, stdin=PIPE, stdout=PIPE).communicate()[0] 
print """ 
関連する問題