Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
767eb1d8
Commit
767eb1d8
authored
Sep 06, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style fix delete_table.py
parent
9b0c0719
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
18 deletions
+20
-18
delete_table.py
src/opnsense/scripts/filter/delete_table.py
+20
-18
No files found.
src/opnsense/scripts/filter/delete_table.py
View file @
767eb1d8
...
...
@@ -33,22 +33,24 @@ import tempfile
import
subprocess
import
os
import
sys
import
ujson
result
=
[]
if
len
(
sys
.
argv
)
>
2
:
# always validate if the item is in the pf table before trying to delete
with
tempfile
.
NamedTemporaryFile
()
as
output_stream
:
# delete an entry from a pf table
subprocess
.
call
([
'/sbin/pfctl'
,
'-t'
,
sys
.
argv
[
1
],
'-T'
,
'show'
],
stdout
=
output_stream
,
stderr
=
open
(
os
.
devnull
,
'wb'
))
output_stream
.
seek
(
0
)
if
sys
.
argv
[
2
]
.
strip
()
==
'ALL'
:
if
len
(
output_stream
.
read
()
.
strip
()
.
split
(
'
\n
'
))
>
0
:
# delete all entries from a pf table
subprocess
.
call
([
'/sbin/pfctl'
,
'-t'
,
sys
.
argv
[
1
],
'-T'
,
'flush'
],
stdout
=
output_stream
,
stderr
=
open
(
os
.
devnull
,
'wb'
))
else
:
for
line
in
output_stream
.
read
()
.
strip
()
.
split
(
'
\n
'
):
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'
))
if
__name__
==
'__main__'
:
result
=
[]
if
len
(
sys
.
argv
)
>
2
:
# always validate if the item is in the pf table before trying to delete
with
tempfile
.
NamedTemporaryFile
()
as
output_stream
:
# delete an entry from a pf table
subprocess
.
call
([
'/sbin/pfctl'
,
'-t'
,
sys
.
argv
[
1
],
'-T'
,
'show'
],
stdout
=
output_stream
,
stderr
=
open
(
os
.
devnull
,
'wb'
))
output_stream
.
seek
(
0
)
if
sys
.
argv
[
2
]
.
strip
()
==
'ALL'
:
if
len
(
output_stream
.
read
()
.
strip
()
.
split
(
'
\n
'
))
>
0
:
# delete all entries from a pf table
subprocess
.
call
([
'/sbin/pfctl'
,
'-t'
,
sys
.
argv
[
1
],
'-T'
,
'flush'
],
stdout
=
output_stream
,
stderr
=
open
(
os
.
devnull
,
'wb'
))
else
:
for
line
in
output_stream
.
read
()
.
strip
()
.
split
(
'
\n
'
):
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'
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment