水底游 发表于 2015-01-05 20:24

python之cgi执行脚本问题

使用CGIHTTPServer 创建了一个简单的web服务# cat cgihttp.py
#coding:utf-8
__author__ = 'JYC103'
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler
from SocketServer import ForkingMixIn

class ForkingServer(ForkingMixIn,HTTPServer):
    pass

serveraddr = ('',8765)
srvr = ForkingServer(serveraddr,CGIHTTPRequestHandler)
srvr.serve_forever()访问的web页面# cat page2.html
<html>
<h1>Test Page 2</h1>
<form name="input"action="/cgi-bin/myscript02.py"method="get">
hour: <input type="text"name="firstName"><br><br>
min: <input type="text"name="lastName"><br><br>
sec: <input type="text"name="position"><br><br>
<input type="submit"value="Submit">
</form>
</html>web页面调用的cgi中的脚本#!/usr/bin/python
import cgi,os
import getpass
form = cgi.FieldStorage()
print"Content-Type: text/html"
print""
print"<html>"
print"<h2>CGI Script Output</h2>"
print"<p>"
print"The user entered data are:<br>"
print"<b>First Name:</b> "+ form["firstName"].value +"<br>"
print"<b>Last Name:</b> "+ form["lastName"].value +"<br>"
print"<b>Position:</b> "+ form["position"].value +"<br>"
hour = int(form["firstName"].value)
min = int(form["lastName"].value )
sec = int(form["position"].value)
print "%d %d %d"%(hour,min,sec)
if   (0<=int(hour)<=23) and (0<=int(min)<=59) and (0<=int(sec)<=59):
    #newtime = os.system('date -s "2015-01-06 %d:%d:%d"' %(hour,min,sec))
    newtime = os.system('date -s "%d:%d:%d"' %(hour,min,sec))
    print newtime
else:
    print "error time input"
print getpass.getuser()
print"</p>"
print"</html>"问题来了

在这个页面填入 时,分,秒后提交
页面就转入到了脚本那个文件下
里面有个 date -s的命令来执行修改系统时间

这是发现,这个‘date -s’的命令根本没有被执行到


查看日志信息192.168.164.1 - - CGI script exit status 0x100
192.168.164.1 - - "GET /cgi-bin/myscript02.py?firstName=15&lastName=11&position=32 HTTP/1.1" 200 -
date: 无法设置日期: 不允许的操作不允许操作。。。

查阅资料得知,cgi下执行的脚本的都是nobody用户
现在要怎样让 执行cgi下面的脚本当涉及到对系统层面操作时要有权限???



页: [1]
查看完整版本: python之cgi执行脚本问题