Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firewall.py complete revamp #2011

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add command firewall is-open <port> -p <protocol> for apps
  • Loading branch information
Salamandar committed Dec 20, 2024
commit 574ae0855debdace957442f9a0e2de6d83d5d444
23 changes: 20 additions & 3 deletions share/actionsmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,25 @@ firewall:
help: If not raw, list UPnP forwarded ports instead of open ports
action: store_true

### firewall_is_open()
is-open:
action_help: Returns whether the port is open or not.
api: GET /firewall/<protocol>/<port>
arguments:
port:
help: Port or range of ports to close
extra:
pattern: &pattern_port_or_range
- !!str ((^|(?!\A):)([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])){1,2}?$
- "pattern_port_or_range"
-p:
full: --protocol
help: "Protocol type (tcp/udp)"
choices:
- tcp
- udp
default: tcp

### firewall_open()
open:
action_help: Allow connections on a port
Expand All @@ -1416,9 +1435,7 @@ firewall:
port:
help: Port or range of ports to open
extra:
pattern: &pattern_port_or_range
- !!str ((^|(?!\A):)([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])){1,2}?$
- "pattern_port_or_range"
pattern: *pattern_port_or_range
-p:
full: --protocol
help: "Protocol type (tcp/udp)"
Expand Down
15 changes: 15 additions & 0 deletions src/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@ def disable(self) -> None:
self.enabled(False)


def firewall_is_open(
port: int | str,
protocol: str,
) -> bool:
"""
Returns whether the specified port is open.

Keyword arguments:
port -- Port or range of ports to open
protocol -- Protocol type to allow (tcp/udp)

"""
return port in firewall_list(raw=False, protocol=protocol, forwarded=False)


def firewall_open(
port: int | str,
protocol: str,
Expand Down