예제 #1
0
 def do_POST(self):
     # 홈페이지
     if self.path != '/':
         CGIHTTPRequestHandler.do_POST(self)
         return
     # 응답 전송
     self.send_response(200)
     self.end_headers()
     try:
         # 전송받은 데이터 파싱
         data = self.rfile.read()
         data = data.decode('utf-8')
         data = urllib.parse.parse_qs(data)
         # 저장할 데이터 준비
         unix_time = int(time.time())
         device_id = data['device_id'][0]
         log_set = data['log_set'][0]
         # 데이터베이스 커밋
         self.cursor.execute('''
                 INSERT OR IGNORE INTO scan
                 (unix_time, device_id, log_set) VALUES (''' +
                             str(unix_time) + ', ' + '"' + device_id +
                             '", ' + '"' + log_set + '")')
         self.connector.commit()
         # 성공 응답 전송
         self.send_response(202)
         self.end_headers()
     except Exception as err:
         logging.error(err)
         # 실패 응답 전송
         self.send_response(400)
         self.end_headers()
예제 #2
0
    def do_POST(self):
        # set up "fake" chrooted CGI directory.
        self.cgi_directories = ["/"]
        cdir = os.path.abspath(os.curdir)
        os.chdir('cmp/')

        # fake the path to the compiler.
        self.path = self.path.split("/", 2)[2]

        # try to run the CGI program.
        CGIHTTPRequestHandler.do_POST(self)

        # restore.
        os.chdir(cdir)
        self.cgi_directories = ["/cmp/"]
예제 #3
0
 def do_GET(self):
     """Answer to a GET request."""
     path = urllib.parse.unquote(self.path, encoding='utf-8')
     print("do_GET for [%s]" % path)
     # HTML return
     if path == "/": # could be set to path="/index.html"
         self.mime_type = 'text/html'
         self.do_HEAD()
         content = """<html>
             <body><h1>Hello World</h1>
             <ul>
                 <li>Path requested : %s</li>
                 <li>Path modified : %s</li>
             </ul>
             </body>
         </html>""" % (self.path, path)
         self.wfile.write(content.encode('utf-8'))
     elif path == "/list":
         self.mime_type = 'text/html'
         self.do_HEAD()
         self.wfile.write("<html><body><ul>".encode('utf-8'))
         c = os.listdir(HTTPHandler.WWW)
         for f in c:
             r = "<li>%s</li>" % (f,)
             self.wfile.write(r.encode('utf-8'))
         self.wfile.write("</ul></body></html>".encode('utf-8'))
     else:
         self.mime_type = self.get_mime_type(path)
         if self.mime_type is None:
             self.error()
         elif self.mime_type == 'cgi_python':
             #import subprocess
             #result = subprocess.run(['python', HTTPHandler.WWW + os.sep + path], stdout=subprocess.PIPE)
             #self.wfile.write(result.stdout)
             CGIHTTPRequestHandler.cgi_directories = ['/', 'Code'] # ne marche pas
             CGIHTTPRequestHandler.do_POST(self)
         else:
             try:
                 f = open(HTTPHandler.WWW + os.sep + path, 'rb') # os.curdir = '.' can be used (ou getcwd())
                 self.do_HEAD()
                 self.wfile.write(f.read())
                 f.close()
                 return
             except IOError:
                 self.error()
예제 #4
0
 def do_POST(self):
     CGIHTTPRequestHandler.do_POST(self)
     print("do_POST, path: %s %s" % (self.path, self.client_address[0]))
     pass
예제 #5
0
 def do_POST(self):
     CGIHTTPRequestHandler.do_POST(self)