免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4099 | 回复: 0
打印 上一主题 下一主题

python之cgi执行脚本问题 [复制链接]

论坛徽章:
1
水瓶座
日期:2014-12-25 11:15:10
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-01-05 20:24 |只看该作者 |倒序浏览
使用CGIHTTPServer 创建了一个简单的web服务
  1. [root@node02 python]# cat cgihttp.py
  2. #coding:utf-8
  3. __author__ = 'JYC103'
  4. from BaseHTTPServer import HTTPServer
  5. from CGIHTTPServer import CGIHTTPRequestHandler
  6. from SocketServer import ForkingMixIn

  7. class ForkingServer(ForkingMixIn,HTTPServer):
  8.     pass

  9. serveraddr = ('',8765)
  10. srvr = ForkingServer(serveraddr,CGIHTTPRequestHandler)
  11. srvr.serve_forever()
复制代码
访问的web页面
  1. [root@node02 python]# cat page2.html
  2. <html>
  3. <h1>Test Page 2</h1>
  4. <form name="input"action="/cgi-bin/myscript02.py"method="get">
  5. hour: <input type="text"name="firstName"><br><br>
  6. min: <input type="text"name="lastName"><br><br>
  7. sec: <input type="text"name="position"><br><br>
  8. <input type="submit"value="Submit">
  9. </form>
  10. </html>
复制代码
web页面调用的cgi中的脚本
  1. #!/usr/bin/python
  2. import cgi,os
  3. import getpass
  4. form = cgi.FieldStorage()
  5. print"Content-Type: text/html"
  6. print""
  7. print"<html>"
  8. print"<h2>CGI Script Output</h2>"
  9. print"<p>"
  10. print"The user entered data are:<br>"
  11. print"<b>First Name:</b> "+ form["firstName"].value +"<br>"
  12. print"<b>Last Name:</b> "+ form["lastName"].value +"<br>"
  13. print"<b>Position:</b> "+ form["position"].value +"<br>"
  14. hour = int(form["firstName"].value)
  15. min = int(form["lastName"].value )
  16. sec = int(form["position"].value)
  17. print "%d %d %d"  %(hour,min,sec)
  18. if   (0<=int(hour)<=23) and (0<=int(min)<=59) and (0<=int(sec)<=59):
  19.     #newtime = os.system('date -s "2015-01-06 %d:%d:%d"' %(hour,min,sec))
  20.     newtime = os.system('date -s "%d:%d:%d"' %(hour,min,sec))
  21.     print newtime
  22. else:
  23.     print "error time input"
  24. print getpass.getuser()
  25. print"</p>"
  26. print"</html>"
复制代码
问题来了

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

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


查看日志信息
  1. 192.168.164.1 - - [06/Jan/2015 14:32:05] CGI script exit status 0x100
  2. 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 -
  3. date: 无法设置日期: 不允许的操作
复制代码
不允许操作。。。

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



您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP