Compare commits
No commits in common. "59ecd48210d3a7cda4ac3aa9090b0092be735a09" and "32032de81da28ef2634055c9007dda8329804fdb" have entirely different histories.
59ecd48210
...
32032de81d
@ -88,28 +88,19 @@ def create_app():
|
||||
name = untaint(PAT_NAME, name)
|
||||
app.logger.info(f'Flushing table f2b-{name}'
|
||||
f' in anchor f2b-jail/{remote_user}')
|
||||
reply = {'anchor': f'f2b-jail/{remote_user}',
|
||||
'table': f'f2b-{name}',
|
||||
'operation': 'list'}
|
||||
try:
|
||||
res = pfctl_table_op('f2b-jail/{remote_user}',
|
||||
table='f2b-{name}',
|
||||
operation='show',
|
||||
verbose=True)
|
||||
except CalledProcessError as err:
|
||||
if err.stderr.find(b'pfctl: Table does not exist.') > 0:
|
||||
res = []
|
||||
reply.update({'error': f'\'{name}\' is not a known fail2ban jail'})
|
||||
else:
|
||||
raise err
|
||||
|
||||
res = pfctl_table_op('f2b-jail/{remote_user}',
|
||||
table='f2b-{name}',
|
||||
operation='show',
|
||||
verbose=True)
|
||||
result = [entry.groupdict() for entry in
|
||||
re.finditer(_PFCTL_TABLE_PAT,
|
||||
'\n'.join([x.decode('ascii') for x in res]),
|
||||
re.MULTILINE|re.VERBOSE)]
|
||||
reply.update({'result': result})
|
||||
|
||||
return jsonify(reply), 200 if len(res) else 404
|
||||
return jsonify({'anchor': f'f2b-jail/{remote_user}',
|
||||
'table': f'f2b-{name}',
|
||||
'operation': 'list',
|
||||
'result': result })
|
||||
|
||||
@app.route("/register", methods=['PUT', 'DELETE'])
|
||||
@auth.login_required
|
||||
|
@ -94,13 +94,9 @@ def test_list_nonexistent_table(client, mocker, valid_credentials):
|
||||
run_res.returncode = 255
|
||||
run_res.check_returncode = noop
|
||||
|
||||
mocker.patch('jail2ban.pfctl.run',
|
||||
return_value=run_res,
|
||||
side_effect=CalledProcessError(run_res.returncode,
|
||||
'foobar',
|
||||
output=run_res.stdout,
|
||||
stderr=run_res.stderr)
|
||||
)
|
||||
# XXX raise a CalledProcessError here...
|
||||
|
||||
mocker.patch('jail2ban.pfctl.run', return_value=run_res)
|
||||
|
||||
response = client.get("/list/nonexistent",
|
||||
headers={"Authorization":
|
||||
|
Loading…
x
Reference in New Issue
Block a user