Commit 767eb1d8 authored by Ad Schellevis's avatar Ad Schellevis

style fix delete_table.py

parent 9b0c0719
...@@ -33,22 +33,24 @@ import tempfile ...@@ -33,22 +33,24 @@ import tempfile
import subprocess import subprocess
import os import os
import sys import sys
import ujson
result = [] if __name__ == '__main__':
if len(sys.argv) > 2: result = []
# always validate if the item is in the pf table before trying to delete if len(sys.argv) > 2:
with tempfile.NamedTemporaryFile() as output_stream: # always validate if the item is in the pf table before trying to delete
# delete an entry from a pf table with tempfile.NamedTemporaryFile() as output_stream:
subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'show'], stdout=output_stream, stderr=open(os.devnull, 'wb')) # delete an entry from a pf table
output_stream.seek(0) subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'show'],
if sys.argv[2].strip() == 'ALL': stdout=output_stream, stderr=open(os.devnull, 'wb'))
if len(output_stream.read().strip().split('\n')) > 0: output_stream.seek(0)
# delete all entries from a pf table if sys.argv[2].strip() == 'ALL':
subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'flush'], stdout=output_stream, stderr=open(os.devnull, 'wb')) if len(output_stream.read().strip().split('\n')) > 0:
else: # delete all entries from a pf table
for line in output_stream.read().strip().split('\n'): subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'flush'],
if line.strip() == sys.argv[2].strip(): stdout=output_stream, stderr=open(os.devnull, 'wb'))
result = [] else:
subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'delete', line.strip()], for line in output_stream.read().strip().split('\n'):
stdout=open(os.devnull, 'wb'), stderr=open(os.devnull, 'wb')) if line.strip() == sys.argv[2].strip():
result = []
subprocess.call(['/sbin/pfctl', '-t', sys.argv[1], '-T', 'delete', line.strip()],
stdout=open(os.devnull, 'wb'), stderr=open(os.devnull, 'wb'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment