Skip to content

Commit

Permalink
Fixed older python compatibility
Browse files Browse the repository at this point in the history
Removed annotations that required newer python version
  • Loading branch information
a13ssandr0 committed Dec 17, 2022
1 parent 53669ac commit 9c4619b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Ufw terminal frontend based on dialog
## Installation
Tufw **NEEDS** to be installed as root, because it needs to run as root and python won't load the module if it's installed as a normal user.

Tufw requires python3.0 or newer.
```sh
sudo python3 -m pip install tufw
# OR
Expand All @@ -18,6 +17,8 @@ Obviously Tufw needs [`dialog`](https://invisible-island.net/dialog/), so instal
sudo apt install dialog
```
or whatever you use on your distribution.

>While [vermin](https://github.com/netromdk/vermin) reports minimum python version for Tufw is 3.0, it has been tested only with python 3.5.4 and 3.10. Older versions have not been tested yet.
#
## Running
As ufw, Tufw needs to be run as root.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = tufw
version = 1.1.0
version = 1.1.1
author = Alessandro Campolo
author_email = [email protected]
description = Ufw terminal frontend based on dialog
Expand Down
5 changes: 3 additions & 2 deletions src/tufw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def elevate():
def rotate(input, n=1):
return input[n:] + input[:n]

def get_tuple_with_value(list: list[tuple], index: int, value):
def get_tuple_with_value(list, index: int, value):
for t in list:
if t[index] == value:
return t
Expand Down Expand Up @@ -151,7 +151,8 @@ def delete_rule(d: Dialog, ufw: Firewall):
d.msgbox(text='No rules selected', height=6, width=30)
elif d.yesno(
title='Warning!!',
text=f"Are you sure you want to delete {len(response1[1])} rule{'' if len(response1[1])==1 else 's'}?",
text="Are you sure you want to delete {} rule{}?"\
.format(len(response1[1]), ('' if len(response1[1])==1 else 's')),
default_button='No'
) == d.OK:
d.gauge_start(text='', percent=0, title='Deleting rules...', width=60)
Expand Down
4 changes: 2 additions & 2 deletions src/tufw/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_rules(self, force_fw_on=True):

return findall(r'\[\s+\d+\]\s*(.*?(?:ALLOW|DENY|LIMIT|REJECT).*?)\s*\n', rules)

def add_rule(self, insert:str, policy:str, direction:str, iface:str, routed:str, logging:str, proto:str, from_ip:str, from_port:str, to_ip:str, to_port:str) -> tuple[bool, str, str]:
def add_rule(self, insert:str, policy:str, direction:str, iface:str, routed:str, logging:str, proto:str, from_ip:str, from_port:str, to_ip:str, to_port:str):
# ufw [route] [insert NUM] allow|deny|reject|limit [in|out on INTERFACE] [log|log-all] [proto protocol] [from ADDRESS [port PORT]] [to ADDRESS [port PORT]]
cmd_rule = [self.UFW_PATH]

Expand Down Expand Up @@ -192,7 +192,7 @@ def get_internal_ip(self):
s.connect(('10.255.255.255', 1))
return s.getsockname()[0]

def get_known_services(self, sort_by_name=False) -> list[tuple[str,str,str,str,str]]:
def get_known_services(self, sort_by_name=False):
all_serv = []
with open('/etc/services') as f:
lines = filter(lambda x: x and not x.startswith('#'), map(lambda x: x.strip(), f.readlines()))
Expand Down

0 comments on commit 9c4619b

Please sign in to comment.