python之js/url/python互动

来源:互联网 发布:守望先锋数据app 编辑:程序博客网 时间:2024/05/01 10:28
## 前端页面
<script>function run(sCmd,arg){var baseUrl = "http://192.168.2.250:50000/";var cmd = baseUrl + sCmd + "++" + arg + "++null";document.location = cmd;}</script>


<a href='javascript:run("startMind","\\\\192.168.4.62\\home\\_ui.xmind")' class="no edit">[+]</a></span>


## 中间服务

import os,sys,platform,re,shutilimport BaseHTTPServerfrom SocketServer import ThreadingMixInimport threadingimport urllib, urllib2import time,sockettry:  from cStringIO import StringIOexcept ImportError:  from StringIO import StringIO####################################################################################################   Global Varible###################################################################################################encoding = 'utf-8'BUFSIZE = 1024####################################################################################################   Define the Simple the Http Request#   1. send the request to client.###################################################################################################class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):  #[GET]  def do_GET(self):    f = StringIO()    print "==>%s" % (self.path[1:])    sPath = self.path[1:]    cmdList = sPath.split("++")    cmdList = cmdList[0:-1]    for x in cmdList:print "list==>%s" % (x)    rCmd = ""    cmdLen = len(cmdList)    rCmd = cmdList[0]    for i in range(1,cmdLen):    rCmd = "%s %s" % (rCmd,cmdList[i])    print "OK-->%s" % (rCmd)    okCmd = '%s && echo   000000 && pwd' % (rCmd)    print okCmd    pFp = os.popen(okCmd)    ret = pFp.read()    pFp.close()    f.write("<body><script>location.href=document.referrer;</script></body>")    length = f.tell()    f.seek(0)    self.response(length)    if f:      shutil.copyfileobj(f, self.wfile)      f.close()  #[Response]  def response(self,length):      self.send_response(200)      self.send_header("Content-type", "text/html")      self.send_header("Content-Length", str(length))      self.end_headers()####################################################################################################   Define the Simple the Http Server With Multi Thread Server###################################################################################################class ThreadingServer(ThreadingMixIn, BaseHTTPServer.HTTPServer):  pass####################################################################################################   Main Control Service.###################################################################################################if __name__ == '__main__':    if len(sys.argv) < 2:        print "-----------------------------------------------"        print "Usage: miniControl.py 50000"        print "-----------------------------------------------"    else:        serveraddr = ('',int(sys.argv[1]))        #[Http Server]        print "Start Http Server(%s)" % (int(sys.argv[1]))        srvr = ThreadingServer(serveraddr, SimpleHTTPRequestHandler)        srvr.serve_forever()


## 后台支撑

①js端传递为:startMind  \\\\192.168.4.62\\home\\_ui.xmind

②后端实现:Linux/DOS下均实现一个startMind的命令,shell/python的方式,对于参数如何传递,完全由自己进行决定


0 0