Skip to content

Commit 3a65eef

Browse files
committed
Paths updated
1 parent 7da7170 commit 3a65eef

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

lss.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
from main_frame import create_main_window
3-
from json_handler import save_to_file
3+
from json_handler import save_to_file
4+
from utils import *
45
import os
56

67

@@ -15,16 +16,15 @@ def print_logo():
1516

1617

1718
def check_data_folder():
18-
data_folder = "data"
19+
data_folder = get_data_dir()
1920
if not os.path.exists(data_folder):
2021
os.mkdir(data_folder)
21-
return data_folder
2222

2323

2424
def create_default_policy():
25-
data_folder = check_data_folder()
25+
check_data_folder()
2626

27-
policies_file = data_folder + "/policies.json"
27+
policies_file = get_data_dir() + "/policies.json"
2828
if not os.path.isfile(policies_file):
2929
policy = {"Accept-all": [{"dir": "OUTPUT", "src": "any", "dst": "any", "sport":"any", "dport": "any", "proto": "any", "action": "ACCEPT"},
3030
{"dir": "INPUT", "src": "any", "dst": "any", "sport":"any", "dport": "any", "proto": "any", "action": "ACCEPT"}]}
@@ -34,7 +34,7 @@ def create_default_policy():
3434
def create_default_config():
3535
data_folder = check_data_folder()
3636

37-
conf_file = "data/config.json"
37+
conf_file = get_data_dir() + "/config.json"
3838
if not os.path.isfile(conf_file):
3939
config = {"active_policy":"Accept-all"}
4040
save_to_file(conf_file, config)

main_frame.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
from json_handler import *
55
from ui_tools import *
66
from policy_editor import *
7+
from utils import *
78
from policy import apply_current_policy, apply_blocklist
89
from iptable_tools import clear_chains, set_rule_return, save_all
910

1011
title = "Linux Security Suite"
1112

1213
def set_main_buttons(root, text, LEFT_FRAME, RIGHT_FRAME):
1314
sec_status = '''echo -e "~~~ My Configurations: ~~~\n" ;
14-
cat data/config.json ; echo -e "\n" ;
15+
cat ''' + get_data_dir() + '''/config.json ; echo -e "\n" ;
1516
systemctl status iptables.service ;
1617
echo -e "\n" ;systemctl status apparmor ;
1718
echo -e "\n~~~ Listening ports ~~~ \n";

policy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from iptable_tools import *
55
from json_handler import *
66
from ip_checks import *
7+
from utils import *
78

89
def load_policy(policy):
910
print("Creating blocklist chain if it does not exists already..")
@@ -47,8 +48,8 @@ def load_policy(policy):
4748

4849

4950
def apply_current_policy():
50-
my_policy_name = retrieve_from_file("data/config.json")["active_policy"]
51-
policy = retrieve_from_file("data/policies.json")[my_policy_name]
51+
my_policy_name = retrieve_from_file(get_data_dir() + "/config.json")["active_policy"]
52+
policy = retrieve_from_file(get_data_dir() + "/policies.json")[my_policy_name]
5253
load_policy(policy)
5354

5455

@@ -58,7 +59,7 @@ def apply_blocklist():
5859
print("Clearing previous rules if any..")
5960
clear_chains("BLOCKLIST")
6061
ip_list = []
61-
with open("data/addresses.list") as file:
62+
with open(get_data_dir() + "/addresses.list") as file:
6263
for line in file:
6364
ip_list.append(line.rstrip())
6465
for addr in ip_list:

policy_editor.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from ui_tools import *
2-
2+
from utils import *
33

44
def create_editor_buttons(root, frame1, frame2, treeview):
55
# Get data from jsons
6-
all_policies = retrieve_from_file("data/policies.json")
7-
my_config = retrieve_from_file("data/config.json")
6+
all_policies = retrieve_from_file(get_data_dir() + "/policies.json")
7+
my_config = retrieve_from_file(get_data_dir() + "/config.json")
88

99
# Change policy menu
1010
drop_down, menu_var = create_dropdown(frame1, list(all_policies))
@@ -27,14 +27,14 @@ def save_polciy():
2727
policy = []
2828
for child in treeview.get_children():
2929
policy.append(list_to_json(policy_keys,treeview.item(child)["values"]))
30-
replace_val_from_key(menu_var.get(), policy, "data/policies.json")
30+
replace_val_from_key(menu_var.get(), policy, get_data_dir() + "/policies.json")
3131
nonlocal all_policies
32-
all_policies = retrieve_from_file("data/policies.json")
32+
all_policies = retrieve_from_file(get_data_dir() + "/policies.json")
3333

3434
def mark_active():
3535
nonlocal my_config
36-
replace_val_from_key('active_policy', menu_var.get(), "data/config.json")
37-
my_config = retrieve_from_file("data/config.json")
36+
replace_val_from_key('active_policy', menu_var.get(), get_data_dir() + "/config.json")
37+
my_config = retrieve_from_file(get_data_dir() + "/config.json")
3838

3939
def update_table(tree):
4040
clear_all_tree_vals(tree)

utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import os
2+
3+
def get_data_dir():
4+
return os.path.expanduser('~') + "/.lss"
5+

0 commit comments

Comments
 (0)