Ejemplo n.º 1
0
def status404(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Not Found"))
Ejemplo n.º 2
0
def login(req, url=None, realm='Administrator', token=None):
    uvm_login.setup_gettext()

    options = req.get_options()

    args = util.parse_qs(req.args or '')

    error_msg = None
    if req.form.has_key('username') or req.form.has_key('password'):
        error_msg = '%s' % cgi.escape(
            _('Error: Username and Password do not match'))

    connection = req.connection
    (addr, port) = connection.local_addr
    is_local = re.match('127\.', connection.remote_ip)
    if connection.remote_ip == '::1':
        is_local = True
    if port == 80 and not get_uvm_settings_item(
            'system', 'httpAdministrationAllowed') and not is_local:
        write_error_page(req, "Permission denied")
        return

    if token != None and get_uvm_settings_item('system', 'cloudEnabled'):
        if _valid_token(req, token):
            sess = Session.Session(req, lock=0)
            sess.lock()
            sess.set_timeout(uvm_login.SESSION_TIMEOUT)
            uvm_login.save_session_user(sess, realm, "token")
            sess.save()
            sess.unlock()

            if url == None:
                return apache.OK
            else:
                url = re.sub('[^A-Za-z0-9-_/.#?=]', '', url)  # sanitize input
                if req.form.has_key('fragment') and req.form['fragment'] != '':
                    url = url + req.form['fragment']
                util.redirect(req, url)
                return

    if req.form.has_key('username') and req.form.has_key('password'):
        username = req.form['username']
        password = req.form['password']
        # debug
        # req.log_error("User:Pass = %s %s" % (username,password))

        if _valid_login(req, realm, username, password):
            sess = Session.Session(req, lock=0)
            sess.lock()
            sess.set_timeout(uvm_login.SESSION_TIMEOUT)
            uvm_login.save_session_user(sess, realm, username)
            sess.save()
            sess.unlock()

            if url == None:
                return apache.OK
            else:
                url = re.sub('[^A-Za-z0-9-_/.#?=]', '', url)  # sanitize input
                if req.form.has_key('fragment') and req.form['fragment'] != '':
                    url = url + req.form['fragment']
                util.redirect(req, url)
                return

    company_name = uvm_login.get_company_name()
    title = _("Administrator Login")
    # some i18n company_names cause exception here, so wrap to handle this
    # revert to "Administrator Login" if exception occurs
    try:
        title = cgi.escape(_("%s Administrator Login") % company_name)
    except:
        pass

    host = cgi.escape(req.hostname)

    _write_login_form(req, title, host, error_msg)
Ejemplo n.º 3
0
def status403(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Forbidden"))
Ejemplo n.º 4
0
def status411(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Length Required"))
Ejemplo n.º 5
0
def status413(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Request Entity Too Large"))
Ejemplo n.º 6
0
def status407(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Proxy Authentication Required"))
Ejemplo n.º 7
0
def status409(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Conflict"))
Ejemplo n.º 8
0
def status502(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Bad Gateway"))
Ejemplo n.º 9
0
def status503(req):
    uvm_login.setup_gettext()
    if isUvmStarting():
        _write_loading_page(req)
        return
    _write_error_page(req, _("Service Unavailable"))
Ejemplo n.º 10
0
def status500(req):
    uvm_login.setup_gettext()
    if isUvmStarting():
        _write_loading_page(req)
        return
    _write_error_page(req, _("Internal Server Error"))
Ejemplo n.º 11
0
def status501(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Not Implemented"))
Ejemplo n.º 12
0
def status417(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Expectation Failed"))
Ejemplo n.º 13
0
def status416(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Requested Range Not Satisfiable"))
Ejemplo n.º 14
0
def status415(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Unsupported Media Type"))
Ejemplo n.º 15
0
def status405(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Method Not Allowed"))
Ejemplo n.º 16
0
def status504(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Gateway Timeout"))
Ejemplo n.º 17
0
def status406(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Not Acceptable"))
Ejemplo n.º 18
0
def status505(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("HTTP Version Not Supported"))
Ejemplo n.º 19
0
def status408(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Request Timeout"))
Ejemplo n.º 20
0
def status400(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Bad Request"))
Ejemplo n.º 21
0
def status410(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Gone"))
Ejemplo n.º 22
0
def status401(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Unauthorized"))
Ejemplo n.º 23
0
def status412(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Precondition Failed"))
Ejemplo n.º 24
0
def status402(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Payment Required"))
Ejemplo n.º 25
0
def status414(req):
    uvm_login.setup_gettext()
    _write_error_page(req, _("Request-URI Too Long"))
Ejemplo n.º 26
0
def login(req, url=None, realm='Administrator', token=None):
    uvm_login.setup_gettext()

    options = req.get_options()

    args = util.parse_qs(req.args or '')

    error_msg = None
    if req.form.has_key('username') or req.form.has_key('password'):
        error_msg = '%s' % cgi.escape(_('Error: Username and Password do not match'))

    connection = req.connection
    (addr, port) = connection.local_addr
    is_local = re.match('127\.', connection.remote_ip)
    if connection.remote_ip == '::1':
        is_local = True
    if port == 80 and not get_uvm_settings_item('system','httpAdministrationAllowed') and not is_local:
        write_error_page(req, "Permission denied")
        return

    if token != None and get_uvm_settings_item('system','cloudEnabled'):
        if _valid_token(req, token):
            sess = Session.Session(req, lock=0)
            sess.lock()
            sess.set_timeout(uvm_login.SESSION_TIMEOUT)
            uvm_login.save_session_user(sess, realm, "token")
            sess.save()
            sess.unlock()

            if url == None:
                return apache.OK
            else:
                url = re.sub('[^A-Za-z0-9-_/.#?=]','',url) # sanitize input
                if req.form.has_key('fragment') and req.form['fragment'] != '':
                    url = url + req.form['fragment']
                util.redirect(req, url)
                return

    if req.form.has_key('username') and req.form.has_key('password'):
        username = req.form['username']
        password = req.form['password']
        # debug
        # req.log_error("User:Pass = %s %s" % (username,password))

        if _valid_login(req, realm, username, password):
            sess = Session.Session(req, lock=0)
            sess.lock()
            sess.set_timeout(uvm_login.SESSION_TIMEOUT)
            uvm_login.save_session_user(sess, realm, username)
            sess.save()
            sess.unlock()

            if url == None:
                return apache.OK
            else:
                url = re.sub('[^A-Za-z0-9-_/.#?=]','',url) # sanitize input
                if req.form.has_key('fragment') and req.form['fragment'] != '':
                    url = url + req.form['fragment']
                util.redirect(req, url)
                return

    company_name = uvm_login.get_company_name()
    title = _("Administrator Login")
    # some i18n company_names cause exception here, so wrap to handle this
    # revert to "Administrator Login" if exception occurs
    try:
        title = cgi.escape(_("%s Administrator Login") % company_name)
    except:
        pass

    host = cgi.escape(req.hostname)

    _write_login_form(req, title, host, error_msg)