OpenVPN
http-server.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
3 import os
4 
5 class ExampleHTTPRequestHandler(BaseHTTPRequestHandler):
6 
7  def do_GET(self):
8  session_key = os.path.basename(self.path)
9  file = '/tmp/openvpn_sso_' + session_key
10  print 'session file: ' + file
11  try:
12  f = open(file)
13  #send code 200 response
14  self.send_response(200)
15  #send header first
16  self.send_header('Content-type','text-html')
17  self.end_headers()
18  #send file content to client
19  user = f.read().rstrip()
20  print 'session user: ' + user
21  print 'session key: ' + session_key
22  self.wfile.write('<html><body><h1>Greetings ' + user \
23  + '. You are authorized' \
24  '</h1>' \
25  '</body></html>')
26  f.close()
27  return
28  except IOError:
29  self.send_error(404, 'authentication failed')
30 
31 def run():
32  #ip and port of servr
33  #by default http server port is 80
34  server_address = ('0.0.0.0', 8080)
35  httpd = HTTPServer(server_address, ExampleHTTPRequestHandler)
36  print('http server started')
37  httpd.serve_forever()
38  print('http server stopped')
39 
40 if __name__ == '__main__':
41  run()
http-server.run
def run()
Definition: http-server.py:31
write
@ write
Definition: interactive.c:219
http-server.ExampleHTTPRequestHandler.do_GET
def do_GET(self)
Definition: http-server.py:7
http-server.ExampleHTTPRequestHandler
Definition: http-server.py:5