Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Validate and extract ordering column. This parameter is the index of the
# column on the HTML table to order by
if 'order[0][column]' in request.form:
order_column = int(request.form['order[0][column]'])
else:
order_column = 0
# Validate and extract ordering direction. 'asc' for ascending, 'desc' for
# descending.
if 'order[0][dir]' in request.form:
if request.form['order[0][dir]'] == 'asc':
order_asc = True
elif request.form['order[0][dir]'] == 'desc':
order_asc = False
else:
app.logger.warn('Invalid \'order[0][dir]\' parameter in DataTables request')
abort(400)
else:
order_asc = False
# Handle the search parameter. This is the textbox on the DataTables
# view that the user can search by typing in
search = None
if 'search[value]' in request.form:
if request.form['search[value]'] != '':
if type(request.form['search[value]']) is not str and type(request.form['search[value]']) is not str:
search = str(request.form['search[value]'])
else:
search = request.form['search[value]']
return (draw, start, length, order_column, order_asc, search)
return False
# Check if VM recipe exists
elif entity is "vm":
cursor.execute("SELECT COUNT(`name`) AS count FROM `vm_recipes` WHERE `name`=%s AND `service_name` = %s;", (recipe_name, service_recipe_name))
result = cursor.fetchone()
if result['count'] == 1:
return True
return False
# If the entity is something else, abort
else:
app.logger.warn('There is no entity of this type')
return abort(400)
# Validate and extract ordering column. This parameter is the index of the
# column on the HTML table to order by
if 'order[0][column]' in request.form:
order_column = int(request.form['order[0][column]'])
else:
order_column = 0
# Validate and extract ordering direction. 'asc' for ascending, 'desc' for
# descending.
if 'order[0][dir]' in request.form:
if request.form['order[0][dir]'] == 'asc':
order_asc = True
elif request.form['order[0][dir]'] == 'desc':
order_asc = False
else:
app.logger.warn('Invalid \'order[0][dir]\' parameter in DataTables request')
abort(400)
else:
order_asc = False
# Handle the search parameter. This is the textbox on the DataTables
# view that the user can search by typing in
search = None
if 'search[value]' in request.form:
if request.form['search[value]'] != '':
if type(request.form['search[value]']) is not str and type(request.form['search[value]']) is not unicode:
search = str(request.form['search[value]'])
else:
search = request.form['search[value]']
return (draw, start, length, order_column, order_asc, search)
def _systems_extract_datatables():
# Validate and extract 'draw' parameter. This parameter is simply a counter
# that DataTables uses internally.
if 'draw' in request.form:
draw = int(request.form['draw'])
else:
app.logger.warn('\'draw\' parameter missing from DataTables request')
abort(400)
# Validate and extract 'start' parameter. This parameter is the index of the
# first row to return.
if 'start' in request.form:
start = int(request.form['start'])
else:
app.logger.warn('\'start\' parameter missing from DataTables request')
abort(400)
# Validate and extract 'length' parameter. This parameter is the number of
# rows that we should return
if 'length' in request.form:
length = int(request.form['length'])
if length < 0:
length = None
else:
app.logger.warn('\'length\' parameter missing from DataTables request')
abort(400)
# Validate and extract ordering column. This parameter is the index of the
# column on the HTML table to order by
if 'order[0][column]' in request.form:
order_column = int(request.form['order[0][column]'])
def _extract_datatables():
# Validate and extract 'draw' parameter. This parameter is simply a counter
# that DataTables uses internally.
if 'draw' in request.form:
draw = int(request.form['draw'])
else:
app.logger.warn('`draw` parameter missing from DataTables request')
abort(400)
# Validate and extract 'start' parameter. This parameter is the index of the
# first row to return.
if 'start' in request.form:
start = int(request.form['start'])
else:
app.logger.warn('`start` parameter missing from DataTables request')
abort(400)
# Validate and extract 'length' parameter. This parameter is the number of
# rows that we should return
if 'length' in request.form:
length = int(request.form['length'])
if length < 0:
# MySQL Max Length
elif order_column == 2:
order_by = "end"
elif order_column == 3:
order_by = "name"
elif order_column == 4:
order_by = "desc"
elif order_column == 5:
order_by = "source"
elif order_column == 6:
order_by = "username"
elif order_column == 7:
order_by = "ipaddr"
elif order_column == 8:
order_by = "status"
else:
app.logger.warn('Invalid ordering column parameter in DataTables request')
abort(400)
# Choose order direction
order_dir = "DESC"
if order_asc:
order_dir = "ASC"
# Determine the event type and add that to the query
params = ()
where_clause = ""
if event_source == 'all':
where_clause = '1=1' # This is just to make 'search' always be able to be an AND and not need an optional WHERE
elif event_source == 'user':
where_clause = "`username` != 'scheduler'"
elif event_source == 'scheduler':
where_clause = "`username` = 'scheduler'"
# Validate and extract ordering column. This parameter is the index of the
# column on the HTML table to order by
if 'order[0][column]' in request.form:
order_column = int(request.form['order[0][column]'])
else:
order_column = 0
# Validate and extract ordering direction. 'asc' for ascending, 'desc' for
# descending.
if 'order[0][dir]' in request.form:
if request.form['order[0][dir]'] == 'asc':
order_asc = True
elif request.form['order[0][dir]'] == 'desc':
order_asc = False
else:
app.logger.warn('Invalid \'order[0][dir]\' parameter in DataTables request')
abort(400)
else:
order_asc = False
# Handle the search parameter. This is the textbox on the DataTables
# view that the user can search by typing in
search = None
if 'search[value]' in request.form:
if request.form['search[value]'] != '':
if type(request.form['search[value]']) is not str and type(request.form['search[value]']) is not str:
search = str(request.form['search[value]'])
else:
search = request.form['search[value]']
return (draw, start, length, order_column, order_asc, search)
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)
def _systems_extract_datatables():
# Validate and extract 'draw' parameter. This parameter is simply a counter
# that DataTables uses internally.
if 'draw' in request.form:
draw = int(request.form['draw'])
else:
app.logger.warn('\'draw\' parameter missing from DataTables request')
abort(400)
# Validate and extract 'start' parameter. This parameter is the index of the
# first row to return.
if 'start' in request.form:
start = int(request.form['start'])
else:
app.logger.warn('\'start\' parameter missing from DataTables request')
abort(400)
# Validate and extract 'length' parameter. This parameter is the number of
# rows that we should return
if 'length' in request.form:
length = int(request.form['length'])
if length < 0:
length = None