# Path: applications/utils.py
# def generate_session_id():
#     """
#     Returns a random, 45-character session ID.  Example:
# 
#     .. code-block:: python
# 
#         >>> generate_session_id()
#         "NzY4YzFmNDdhMTM1NDg3Y2FkZmZkMWJmYjYzNjBjM2Y5O"
#         >>>
#     """
#     import base64, uuid
#     from applications.configuration import utf8
#     session_id = base64.b64encode(
#         utf8(uuid.uuid4().hex + uuid.uuid4().hex))[:45]
#     if bytes != str: # Python 3
#         return str(session_id, 'UTF-8')
#     return session_id
# 
# def mkdir_p(path):
#     """
#     Pythonic version of "mkdir -p".  Example equivalents::
# 
#         >>> mkdir_p('/tmp/test/testing') # Does the same thing as...
#         >>> from subprocess import call
#         >>> call('mkdir -p /tmp/test/testing')
# 
#     .. note:: This doesn't actually call any external commands.
#     """
#     try:
#         os.makedirs(path)
#     except OSError as exc:
#         if exc.errno == errno.EEXIST:
#             pass
#         else:
#             logging.error(_("Could not create directory: %s") % path)
#             raise # The original exception
# 
# Path: applications/utils.py
# def getsettings(name,default=None):
#     return getattr(settings, name, default)


from django.shortcuts import render,HttpResponse,Http404
from django.views.generic import View
from django.shortcuts import render_to_response,HttpResponseRedirect,reverse,redirect
from applications.utils import generate_session_id,mkdir_p
from django.core import signing #encrypted the strings
from django.contrib.auth.views import login,logout
from applications.utils import getsettings
import os
import ast
import tornado
import io
import datetime
import hashlib
        import stat, mimetypes
            import email.utils
        import httplib
            else:
                assert self.request.method in ("HEAD","head")
                response["Content-Length"] = len(data)

    def get_error_html(self, status_code, **kwargs):
        if status_code in [404, 500, 503, 403]:
            filename = os.path.join(os.path.join(getsettings('BASE_DIR'),'templates'), '%d.html' % status_code)
            if os.path.exists(filename):
                with io.open(filename, 'r') as f:
                    data = f.read()
                return data
        return "<html><title>%(code)d: %(message)s</title>" \
                "<body class='bodyErrorPage'>%(code)d: %(message)s</body></html>" % {
            "code": status_code,
            "message": httplib.responses[status_code],
        }

class SharedTermHandler(basehttphander):
    """
    Renders shared.html which allows an anonymous user to view a shared
    terminal.
    """
    def get(self, request, share_id=None):
        hostname = os.uname()[1]
        prefs = self.request.GET.get("prefs", None)
        url_prefix = getsettings('url_prefix','/')
        gateone_js = "%sstatic/gateone.js" % url_prefix
        minified_js_abspath = os.path.join(getsettings('BASE_DIR'),'static/gateone.min.js')
        # Use the minified version if it exists
        if os.path.exists(minified_js_abspath):

# Path: applications/utils.py
# def generate_session_id():
#     """
#     Returns a random, 45-character session ID.  Example:
# 
#     .. code-block:: python
# 
#         >>> generate_session_id()
#         "NzY4YzFmNDdhMTM1NDg3Y2FkZmZkMWJmYjYzNjBjM2Y5O"
#         >>>
#     """
#     import base64, uuid
#     from applications.configuration import utf8
#     session_id = base64.b64encode(
#         utf8(uuid.uuid4().hex + uuid.uuid4().hex))[:45]
#     if bytes != str: # Python 3
#         return str(session_id, 'UTF-8')
#     return session_id
# 
# def mkdir_p(path):
#     """
#     Pythonic version of "mkdir -p".  Example equivalents::
# 
#         >>> mkdir_p('/tmp/test/testing') # Does the same thing as...
#         >>> from subprocess import call
#         >>> call('mkdir -p /tmp/test/testing')
# 
#     .. note:: This doesn't actually call any external commands.
#     """
#     try:
#         os.makedirs(path)
#     except OSError as exc:
#         if exc.errno == errno.EEXIST:
#             pass
#         else:
#             logging.error(_("Could not create directory: %s") % path)
#             raise # The original exception
# 
# Path: applications/utils.py
# def getsettings(name,default=None):
#     return getattr(settings, name, default)


# Path: applications/views.py
from django.shortcuts import render,HttpResponse,Http404
from django.views.generic import View
from django.shortcuts import render_to_response,HttpResponseRedirect,reverse,redirect
from applications.utils import generate_session_id,mkdir_p
from django.core import signing #encrypted the strings
from django.contrib.auth.views import login,logout
from applications.utils import getsettings
import os
import ast
import tornado
import io
import datetime
import hashlib
        import stat, mimetypes
            import email.utils
        import httplib

            else:
                assert self.request.method in ("HEAD","head")
                response["Content-Length"] = len(data)

    def get_error_html(self, status_code, **kwargs):
        if status_code in [404, 500, 503, 403]:
            filename = os.path.join(os.path.join(getsettings('BASE_DIR'),'templates'), '%d.html' % status_code)
            if os.path.exists(filename):
                with io.open(filename, 'r') as f:
                    data = f.read()
                return data
        return "<html><title>%(code)d: %(message)s</title>" \
                "<body class='bodyErrorPage'>%(code)d: %(message)s</body></html>" % {
            "code": status_code,
            "message": httplib.responses[status_code],
        }

class SharedTermHandler(basehttphander):
    """
    Renders shared.html which allows an anonymous user to view a shared
    terminal.
    """
    def get(self, request, share_id=None):
        hostname = os.uname()[1]
        prefs = self.request.GET.get("prefs", None)
        url_prefix = getsettings('url_prefix','/')
        gateone_js = "%sstatic/gateone.js" % url_prefix
        minified_js_abspath = os.path.join(getsettings('BASE_DIR'),'static/gateone.min.js')
        # Use the minified version if it exists
        if os.path.exists(minified_js_abspath):

            gateone_js = "%sgateone.min.js" % getsettings('STATIC_URL')