我有一个使用Flask运行https:///的网站。当我使用以下命令curl -k -X POST https:/// -d“ cmd = ls”时,它为我提供了服务器中的文件列表。但是当我多次尝试相同的命令时,它崩溃了。 / p>
我是Flask的新手。我认为我叫/opt/svcngitls/Flask/Flask/oncall.py的方式有问题。
您能不能为这起崩溃提供帮助?
这是配置: 猫/etc/httpd/conf.d/oncallproxy.conf
ServerName
#Log Setup
CustomLog /var/log/httpd/access_oncall.log combined
ErrorLog /var/log/httpd/error_oncall.log
#CustomLog /opt/svcngitls/access_oncall.log combined
#ErrorLog /opt/svcngitls/error_oncall.log
LoadModule wsgi_module /usr/lib64/python2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so
WSGIScriptAlias / /opt/svcngitls/Flask/Flask/oncallwsgi.wsgi
<Location />
Options -Indexes +FollowSymLinks
require all granted
</Location>
<Directory /opt/svcngitls/Flask/>
Options -Indexes +FollowSymLinks
require all granted
</Directory>
我的烧瓶:
cat /opt/svcngitls/Flask/Flask/oncall.py
import sys
from subprocess import Popen, PIPE, STDOUT, CalledProcessError
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def oncall():
if request.method == 'POST':
path = Popen("find /opt/svcngitls/oncall -type d -printf \":%p\"", stdout=PIPE, stderr=PIPE, shell=True, close_fds=True)
(output, err) = path.communicate()
os.environ['PATH'] += ':' + output
cmd = str(request.get_data()).split('=')[1]
process = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True, close_fds=True)
(result, stderr) = process.communicate()
if result:
return result
else:
return stderr
elif request.method == 'GET':
return "Test mehthod for POST \n"
cat /opt/svcngitls/Flask/Flask/oncallwsgi.wsgi
import sys
sys.path.insert(0,"/opt/svcngitls/Flask/")
from Flask import app as application
cat /opt/svcngitls/Flask/Flask/init.py
if name == "main":
app.run()
错误: curl -k -X POST https:/// -d“ cmd = ls”
500内部服务器错误 内部服务器错误 服务器遇到内部错误,无法完成您的请求。服务器超载或应用程序错误
我重新启动apache之后,同一命令列出服务器中的所有文件而没有问题
Apache错误日志:
[Wed Jul 03 05:35:34.947542 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] [2019-07-03 05:35:34,946] **ERROR in app: Exception on / [POST]**
[Wed Jul 03 05:35:34.947581 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] Traceback (most recent call last):
[Wed Jul 03 05:35:34.947586 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/site-packages/flask/app.py", line 2311, in wsgi_app
[Wed Jul 03 05:35:34.947589 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] response = self.full_dispatch_request()
[Wed Jul 03 05:35:34.947592 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1834, in full_dispatch_request
[Wed Jul 03 05:35:34.947595 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] rv = self.handle_user_exception(e)
[Wed Jul 03 05:35:34.947597 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1737, in handle_user_exception
[Wed Jul 03 05:35:34.947614 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] reraise(exc_type, exc_value, tb)
[Wed Jul 03 05:35:34.947616 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1832, in full_dispatch_request
[Wed Jul 03 05:35:34.947621 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] rv = self.dispatch_request()
[Wed Jul 03 05:35:34.947624 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1818, in dispatch_request
[Wed Jul 03 05:35:34.947626 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] return self.view_functions[rule.endpoint](**req.view_args)
[Wed Jul 03 05:35:34.947629 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/opt/svcngitls/Flask/Flask/oncall.py", line 15, in oncall
[Wed Jul 03 05:35:34.947631 2019] **[wsgi:error] [pid 9133] [client 172.30.88.135:48246] process = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True, close_fds=True)**
[Wed Jul 03 05:35:34.947633 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
[Wed Jul 03 05:35:34.947636 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] errread, errwrite)
[Wed Jul 03 05:35:34.947638 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
[Wed Jul 03 05:35:34.947641 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] raise child_exception
[Wed Jul 03 05:35:34.947643 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] **OSError: [Errno 7] Argument list too long**