python之cgi执行脚本问题

juanmaoking 2015-01-28 03:37:44
使用CGIHTTPServer 创建了一个简单的web服务

[root@node02 python]# 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页面

[root@node02 python]# 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>"

复制代码
问题来了
QQ截图20150105201932.png

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

这是发现,这个‘date -s’的命令根本没有被执行到
QQ截图20150105202055.png



查看日志信息

192.168.164.1 - - [06/Jan/2015 14:32:05] CGI script exit status 0x100
192.168.164.1 - - [06/Jan/2015 14:49:14] "GET /cgi-bin/myscript02.py?firstName=15&lastName=11&position=32 HTTP/1.1" 200 -
date: 无法设置日期: 不允许的操作

复制代码
不允许操作。。。

查阅资料得知,cgi下执行的脚本的都是nobody用户
现在要怎样让 执行cgi下面的脚本当涉及到对系统层面操作时要有权限???
...全文
359 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
juanmaoking 2015-03-11
  • 打赏
  • 举报
回复
已自行解决,结贴

23,118

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧