def edit_tokens(): if request.method == 'POST': try: # check if this is remove vs update POST request action = request.form.getlist('action') if action[0] == 'remove': # read in the content of a present click list_value = request.form.getlist('id') # if list is not empty - content has gone through if len(list_value) > 0: value = int(list_value[0]) # token exists since we delete from the dropdown from the db token = Tokens.get(Tokens.tokenid == value) # delete recursively - all dependencies incl. nullable token.delete_instance(recursive=True, delete_nullable=True) except socket.error: pass entries = [ dict(tid=each.tokenid, ttype=(Tokentypes.get( Tokentypes.tokentypeid == each.tokentypeid.tokentypeid) ).tokentype, ttypeid=each.tokentypeid.tokentypeid, ttoken=each.token, tdescr=each.description, tres=each.result, targs=each.args) for each in Tokens.select() ] return render_template('edit_tokens.html', entries=entries)
def show_args(): entries = [ dict(argid=arg.argid, argname=arg.argname, argnum=arg.argnumber, ttype=arg.arg_tokentype, hasrestr=arg.hasrestriction, restr=arg.restriction, tokenid=Tokens.get(Tokens.tokenid == arg.tokenid.tokenid).token) for arg in Args.select() ] return render_template('show_args.html', entries=entries)
def edit_tokens(): if request.method == 'POST': try: # check if this is remove vs update POST request action = request.form.getlist('action') if action[0] == 'remove': # read in the content of a present click list_value = request.form.getlist('id') # if list is not empty - content has gone through if len(list_value) > 0: value = int(list_value[0]) # token exists since we delete from the dropdown from the db token = Tokens.get(Tokens.tokenid == value) # delete recursively - all dependencies incl. nullable token.delete_instance(recursive=True,delete_nullable=True) except socket.error: pass entries = [dict(tid=each.tokenid, ttype=(Tokentypes.get(Tokentypes.tokentypeid==each.tokentypeid.tokentypeid)).tokentype, ttypeid=each.tokentypeid.tokentypeid, ttoken=each.token, tdescr=each.description, tres=each.result, targs=each.args) for each in Tokens.select()] return render_template('edit_tokens.html', entries=entries)
def generate(): params_list = params.split(',') if int(params_list[0]) == 0 and int(params_list[1]) == 0: db_query = [dict(rid=drule.ruleid, did=Devices.get(Devices.deviceid==drule.deviceid.deviceid).devicename, tid=Tokens.get(Tokens.tokenid==drule.tokenid.tokenid).token, rule=drule.ruleline, condition=drule.cond, config=drule.configcommand) for drule in Devicerules.select()] elif int(params_list[0]) == 0: db_query = [dict(rid=drule.ruleid, did=Devices.get(Devices.deviceid==drule.deviceid.deviceid).devicename, tid=Tokens.get(Tokens.tokenid==drule.tokenid.tokenid).token, rule=drule.ruleline, condition=drule.cond, config=drule.configcommand) for drule in Devicerules.select().where(Devicerules.tokenid==params_list[1])] elif int(params_list[1]) == 0: db_query = [dict(rid=drule.ruleid, did=Devices.get(Devices.deviceid==drule.deviceid.deviceid).devicename, tid=Tokens.get(Tokens.tokenid==drule.tokenid.tokenid).token, rule=drule.ruleline, condition=drule.cond, config=drule.configcommand) for drule in Devicerules.select().where(Devicerules.deviceid==params_list[0])] else: db_query = [dict(rid=drule.ruleid, did=Devices.get(Devices.deviceid==drule.deviceid.deviceid).devicename, tid=Tokens.get(Tokens.tokenid==drule.tokenid.tokenid).token, rule=drule.ruleline, condition=drule.cond, config=drule.configcommand) for drule in Devicerules.select().where(Devicerules.deviceid==params_list[0], Devicerules.tokenid==params_list[1])] table_start = '<table class="table table-condensed"><tr><th>Device</th><th>Token</th><th>Rule line</th><th>Condition</th><th>Configuration command</th></tr>' q = '' for each in db_query: q += '<tr>' q += '<td>' + str(each.get('did')) + '</td>' q += '<td>' + str(each.get('tid')) + '</td>' q += '<td>' + str(each.get('rule')) + '</td>' q += '<td>' + str(each.get('condition')) + '</td>' q += '<td>' + str(each.get('config')) + '</td>' q += '</tr>' table_end = '</table>' res = table_start + q + table_end yield res
def show_args(): entries = [dict(argid=arg.argid, argname=arg.argname, argnum=arg.argnumber, ttype=arg.arg_tokentype, hasrestr=arg.hasrestriction, restr=arg.restriction, tokenid=Tokens.get(Tokens.tokenid==arg.tokenid.tokenid).token) for arg in Args.select()] return render_template('show_args.html', entries=entries)
def generate(): params_list = params.split(',') if int(params_list[0]) == 0 and int(params_list[1]) == 0: db_query = [ dict(rid=drule.ruleid, did=Devices.get(Devices.deviceid == drule.deviceid.deviceid).devicename, tid=Tokens.get( Tokens.tokenid == drule.tokenid.tokenid).token, rule=drule.ruleline, condition=drule.cond, config=drule.configcommand) for drule in Devicerules.select() ] elif int(params_list[0]) == 0: db_query = [ dict(rid=drule.ruleid, did=Devices.get(Devices.deviceid == drule.deviceid.deviceid).devicename, tid=Tokens.get( Tokens.tokenid == drule.tokenid.tokenid).token, rule=drule.ruleline, condition=drule.cond, config=drule.configcommand) for drule in Devicerules.select().where( Devicerules.tokenid == params_list[1]) ] elif int(params_list[1]) == 0: db_query = [ dict(rid=drule.ruleid, did=Devices.get(Devices.deviceid == drule.deviceid.deviceid).devicename, tid=Tokens.get( Tokens.tokenid == drule.tokenid.tokenid).token, rule=drule.ruleline, condition=drule.cond, config=drule.configcommand) for drule in Devicerules.select().where( Devicerules.deviceid == params_list[0]) ] else: db_query = [ dict(rid=drule.ruleid, did=Devices.get(Devices.deviceid == drule.deviceid.deviceid).devicename, tid=Tokens.get( Tokens.tokenid == drule.tokenid.tokenid).token, rule=drule.ruleline, condition=drule.cond, config=drule.configcommand) for drule in Devicerules.select().where( Devicerules.deviceid == params_list[0], Devicerules.tokenid == params_list[1]) ] table_start = '<table class="table table-condensed"><tr><th>Device</th><th>Token</th><th>Rule line</th><th>Condition</th><th>Configuration command</th></tr>' q = '' for each in db_query: q += '<tr>' q += '<td>' + str(each.get('did')) + '</td>' q += '<td>' + str(each.get('tid')) + '</td>' q += '<td>' + str(each.get('rule')) + '</td>' q += '<td>' + str(each.get('condition')) + '</td>' q += '<td>' + str(each.get('config')) + '</td>' q += '</tr>' table_end = '</table>' res = table_start + q + table_end yield res