Esempio n. 1
0
def before_request():
	"""This function is run before the request is handled by Flask. It is used
	to connect to MySQL and Redis, and to tell old Internet Explorer versions
	to go away.
	"""

	# Check for MSIE version <= 10.0
	if (request.user_agent.browser == "msie" and int(round(float(request.user_agent.version))) <= 10):
		return render_template('foad.html')

	# Connect to redis
	try:
		g.redis = redis.StrictRedis(host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'], db=0)
		g.redis.get('foo') # it doesnt matter that this key doesnt exist, its just to force a test call to redis.
	except Exception as ex:
		logerr()
		return fatalerr(message='Cortex could not connect to the REDIS server')

	# Connect to database
	try:
		g.db = mysql.connect(host=app.config['MYSQL_HOST'], port=app.config['MYSQL_PORT'], user=app.config['MYSQL_USER'], passwd=app.config['MYSQL_PASS'], db=app.config['MYSQL_NAME'], charset="utf8")
	except Exception as ex:
		logerr()
		return fatalerr(message='Cortex could not connect to the MariaDB server')

	# This would ideally go in app.py, but it can't as it depends on 
	# cortex.lib.user which it can't import due to a cyclic dependency
	app.jinja_env.globals['does_user_have_permission'] = does_user_have_permission
	app.jinja_env.globals['does_user_have_system_permission'] = does_user_have_system_permission
Esempio n. 2
0
def error500(error):
	
	# Record the error in the log
	logerr()	

	# Return a standard error page		
	return stderr("Internal Error","An internal server error occured",500)
Esempio n. 3
0
def error_handler(error):
    """Handles generic exceptions within the application, displaying the
	traceback if the application is running in debug mode."""

    # Record the error in the log
    logerr()

    ## If we're handling a workflow view handler we don't need to show the fatal
    ## error screen, instead we'll use a standard error screen. the fatal error
    ## screen exists in case a flaw occurs which prevents rendering of the
    ## layout - but that can't happen with a workflow.
    if 'workflow' in g:
        if g.workflow:
            app.logger.warn("Workflow error occured")
            return stderr(
                "Workflow error",
                "An error occured in the workflow function - " +
                type(error).__name__ + ": " + str(error))

    # Get the traceback
    if app.debug:
        debug = traceback.format_exc()
    else:
        debug = "Ask your system administrator to consult the error log for this application."

    # Output a fatal error
    return fatalerr(debug=debug)
Esempio n. 4
0
def error500(error):

    # Record the error in the log
    logerr()

    # Return a standard error page
    return stderr("Internal Error", "An internal server error occured", 500)
Esempio n. 5
0
def before_request():
	"""This function is run before the request is handled by Flask. It is used
	to connect to MySQL and Redis, and to tell old Internet Explorer versions
	to go away.
	"""

	# Check for MSIE version <= 10.0
	if (request.user_agent.browser == "msie" and int(round(float(request.user_agent.version))) <= 10):
		return render_template('foad.html')

	# Connect to redis
	try:
		g.redis = redis.StrictRedis(host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'], db=0)
		g.redis.get('foo') # it doesnt matter that this key doesnt exist, its just to force a test call to redis.
	except Exception as ex:
		logerr()
		return fatalerr(message='Cortex could not connect to the REDIS server')

	# Connect to database
	try:
		g.db = mysql.connect(host=app.config['MYSQL_HOST'], port=app.config['MYSQL_PORT'], user=app.config['MYSQL_USER'], passwd=app.config['MYSQL_PASS'], db=app.config['MYSQL_NAME'], charset="utf8")
	except Exception as ex:
		logerr()
		return fatalerr(message='Cortex could not connect to the MariaDB server')

	# This would ideally go in app.py, but it can't as it depends on 
	# cortex.lib.user which it can't import due to a cyclic dependency
	app.jinja_env.globals['does_user_have_permission'] = does_user_have_permission
	app.jinja_env.globals['does_user_have_system_permission'] = does_user_have_system_permission
Esempio n. 6
0
def error_handler(error):
	"""Handles generic exceptions within the application, displaying the
	traceback if the application is running in debug mode."""

	# Record the error in the log
	logerr()

	## If we're handling a workflow view handler we don't need to show the fatal
	## error screen, instead we'll use a standard error screen. the fatal error
	## screen exists in case a flaw occurs which prevents rendering of the 
	## layout - but that can't happen with a workflow.
	if 'workflow' in g:
		if g.workflow:
			app.logger.warn("Workflow error occured")
			return stderr("Workflow error","An error occured in the workflow function - " + type(error).__name__ + ": " + str(error))

	# Get the traceback
	if app.debug:
		debug = traceback.format_exc()
	else:
		debug = "Ask your system administrator to consult the error log for this application."

	# Output a fatal error
	return fatalerr(debug=debug)