From d952950a6cbb882ff1e6127ecb2b8f7fb3ac4418 Mon Sep 17 00:00:00 2001 From: SovereigntyIsNotFreedom Date: Sat, 22 Mar 2025 19:24:03 +0000 Subject: [PATCH 1/5] issue #36 - env variables: added the dotenv module and fixed requirements.txt Since the .env file will be igonred you need to create a .env file in the root of the project. here are my variables TOR_HOST=socks5h://127.0.0.1 TOR_PORT=9050 WEBSOCKET_PORT=3030 --- .gitignore | 3 ++- SimpleX/main.py | 8 +++++++- requirements.txt | 2 ++ scripts/lantern.py | 12 +++++++++--- scripts/uptimechecker.py | 11 +++++++++-- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 811092d..73b66b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .git www/participants/** scripts/__pycache__/** - +.env +env/ \ No newline at end of file diff --git a/SimpleX/main.py b/SimpleX/main.py index e8caff1..60e2421 100644 --- a/SimpleX/main.py +++ b/SimpleX/main.py @@ -1,14 +1,20 @@ from websockets.sync.client import connect +from dotenv import load_dotenv + import json import random +import os +load_dotenv() +websocket_port = os.environ.get("WEBSOCKET_PORT") +print(websocket_port) def is_simplex_link_valid(simplex_link: str) -> bool: """ Connects to the group using the `simplex_link`. If the response contains error False will be returned else True. """ - with connect("ws://localhost:3030") as websocket: + with connect(f"ws://localhost:{websocket_port}") as websocket: query = f"/c incognito {simplex_link}" command = { 'corrId': f"id{random.randint(0,999999)}", diff --git a/requirements.txt b/requirements.txt index af698b3..cbf4a08 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,3 +10,5 @@ requests==2.32.3 six==1.17.0 tzdata==2025.1 urllib3==2.3.0 +python-dotenv==1.0.1 +websockets==15.0.1 diff --git a/scripts/lantern.py b/scripts/lantern.py index d36d1c0..15bc385 100644 --- a/scripts/lantern.py +++ b/scripts/lantern.py @@ -1,4 +1,5 @@ from utils import * +from dotenv import load_dotenv import os, pwd import pandas as pd @@ -8,12 +9,17 @@ import time import urllib import sys +load_dotenv() + +tor_host = os.environ.get("TOR_HOST") +tor_port = os.environ.get("TOR_PORT") + def main(): #os.system('clear') proxies = { - 'http': 'socks5h://127.0.0.1:9050', - 'https': 'socks5h://127.0.0.1:9050' + 'http': f'{tor_host}:{tor_port}', + 'https': f'{tor_host}:{tor_port}' } rootpath='/srv/darknet-lantern/' @@ -33,7 +39,7 @@ def main(): # check if the directory exists if not os.path.isdir(participantdir): #if not, create it - print("Official participan ",line.strip() , "'s directory doesnt exist, creating it") + print("Official participant ",line.strip() , "'s directory doesnt exist, creating it") os.makedirs(participantdir) diff --git a/scripts/uptimechecker.py b/scripts/uptimechecker.py index d1b929e..00d1a41 100644 --- a/scripts/uptimechecker.py +++ b/scripts/uptimechecker.py @@ -1,3 +1,5 @@ +from dotenv import load_dotenv + import os,re,pwd import csv import requests @@ -5,6 +7,11 @@ import json import pandas as pd import glob +load_dotenv() + +tor_host = os.environ.get("TOR_HOST") +tor_port = os.environ.get("TOR_PORT") + #apt install python3-pandas python3-requests python3-socks def main(): @@ -36,8 +43,8 @@ def main(): return False proxies = { - 'http': 'socks5h://127.0.0.1:9050', - 'https': 'socks5h://127.0.0.1:9050' + 'http': f'{tor_host}:{tor_port}', + 'https': f'{tor_host}:{tor_port}' } instancepath=rootpath+'www/participants/'+instance+'/' From 4dd9ed0c80860ab08302c7e9a721b006cbe16a00 Mon Sep 17 00:00:00 2001 From: SovereigntyIsNotFreedom Date: Sun, 23 Mar 2025 13:03:38 +0100 Subject: [PATCH 2/5] Update SimpleX/main.py --- SimpleX/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimpleX/main.py b/SimpleX/main.py index 60e2421..23e6708 100644 --- a/SimpleX/main.py +++ b/SimpleX/main.py @@ -8,7 +8,7 @@ import os load_dotenv() websocket_port = os.environ.get("WEBSOCKET_PORT") -print(websocket_port) + def is_simplex_link_valid(simplex_link: str) -> bool: """ From 31037597ad8a48ca8f3a871a70b58995caf8513c Mon Sep 17 00:00:00 2001 From: SovereigntyIsNotFreedom Date: Sun, 23 Mar 2025 18:28:52 +0000 Subject: [PATCH 3/5] issue #36 - env variables: now a default value is set at .env.sample if the user wants to add custom config they can create a .env file --- .env.sample | 3 +++ SimpleX/main.py | 5 ++++- scripts/lantern.py | 7 +++++-- scripts/uptimechecker.py | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..02f7692 --- /dev/null +++ b/.env.sample @@ -0,0 +1,3 @@ +TOR_HOST=socks5h://127.0.0.1 +TOR_PORT=9050 +WEBSOCKET_PORT=3030 \ No newline at end of file diff --git a/SimpleX/main.py b/SimpleX/main.py index 23e6708..6bd3d0e 100644 --- a/SimpleX/main.py +++ b/SimpleX/main.py @@ -5,7 +5,10 @@ import json import random import os -load_dotenv() +if os.path.exists('.env'): + load_dotenv(".env") +else: + load_dotenv(".env.sample") websocket_port = os.environ.get("WEBSOCKET_PORT") diff --git a/scripts/lantern.py b/scripts/lantern.py index 15bc385..3a43ea7 100644 --- a/scripts/lantern.py +++ b/scripts/lantern.py @@ -9,7 +9,10 @@ import time import urllib import sys -load_dotenv() +if os.path.exists('.env'): + load_dotenv(".env") +else: + load_dotenv(".env.sample") tor_host = os.environ.get("TOR_HOST") tor_port = os.environ.get("TOR_PORT") @@ -1196,4 +1199,4 @@ Maintenance: if __name__ == '__main__': - main() + main() \ No newline at end of file diff --git a/scripts/uptimechecker.py b/scripts/uptimechecker.py index 00d1a41..103ade6 100644 --- a/scripts/uptimechecker.py +++ b/scripts/uptimechecker.py @@ -7,7 +7,10 @@ import json import pandas as pd import glob -load_dotenv() +if os.path.exists('.env'): + load_dotenv(".env") +else: + load_dotenv(".env.sample") tor_host = os.environ.get("TOR_HOST") tor_port = os.environ.get("TOR_PORT") From acad0af3a175af462c2629faa871119f4acc3d48 Mon Sep 17 00:00:00 2001 From: SovereigntyIsNotFreedom Date: Mon, 24 Mar 2025 19:34:01 +0000 Subject: [PATCH 4/5] issue #36 - env variables: Add to there specific folder. now the script works --- SimpleX/.env.sample | 1 + .env.sample => scripts/.env.sample | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 SimpleX/.env.sample rename .env.sample => scripts/.env.sample (69%) diff --git a/SimpleX/.env.sample b/SimpleX/.env.sample new file mode 100644 index 0000000..7f15145 --- /dev/null +++ b/SimpleX/.env.sample @@ -0,0 +1 @@ +WEBSOCKET_PORT=3030 diff --git a/.env.sample b/scripts/.env.sample similarity index 69% rename from .env.sample rename to scripts/.env.sample index 02f7692..69154cf 100644 --- a/.env.sample +++ b/scripts/.env.sample @@ -1,3 +1,3 @@ TOR_HOST=socks5h://127.0.0.1 TOR_PORT=9050 -WEBSOCKET_PORT=3030 \ No newline at end of file + From 5a7d14c16a233f4c128b40b3155b8e73e3732be3 Mon Sep 17 00:00:00 2001 From: SovereigntyIsNotFreedom Date: Tue, 25 Mar 2025 09:16:08 +0000 Subject: [PATCH 5/5] issue #36 - env variables: .env works from anywhere on the system using absolute path fixed the issue --- SimpleX/main.py | 14 +++++++++----- scripts/lantern.py | 18 +++++++++++------- scripts/uptimechecker.py | 18 ++++++++++++------ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/SimpleX/main.py b/SimpleX/main.py index 6bd3d0e..5ce94d0 100644 --- a/SimpleX/main.py +++ b/SimpleX/main.py @@ -5,12 +5,16 @@ import json import random import os -if os.path.exists('.env'): - load_dotenv(".env") -else: - load_dotenv(".env.sample") +script_abs_path = os.path.dirname(os.path.abspath(__file__)) +env_path = os.path.join(script_abs_path+"/.env") +default_env_path = os.path.join(script_abs_path+"/.env.sample") -websocket_port = os.environ.get("WEBSOCKET_PORT") +if os.path.exists(env_path): + load_dotenv(dotenv_path=env_path) +else: + load_dotenv(dotenv_path=default_env_path) + +websocket_port = os.getenv("WEBSOCKET_PORT") def is_simplex_link_valid(simplex_link: str) -> bool: diff --git a/scripts/lantern.py b/scripts/lantern.py index 3a43ea7..0eb6b8f 100644 --- a/scripts/lantern.py +++ b/scripts/lantern.py @@ -9,14 +9,18 @@ import time import urllib import sys -if os.path.exists('.env'): - load_dotenv(".env") + +script_abs_path = os.path.dirname(os.path.abspath(__file__)) +env_path = os.path.join(script_abs_path+"/.env") +default_env_path = os.path.join(script_abs_path+"/.env.sample") + +if os.path.exists(env_path): + load_dotenv(dotenv_path=env_path) else: - load_dotenv(".env.sample") - -tor_host = os.environ.get("TOR_HOST") -tor_port = os.environ.get("TOR_PORT") + load_dotenv(dotenv_path=default_env_path) +tor_host = os.getenv("TOR_HOST") +tor_port = os.getenv("TOR_PORT") def main(): #os.system('clear') @@ -1199,4 +1203,4 @@ Maintenance: if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/scripts/uptimechecker.py b/scripts/uptimechecker.py index 103ade6..e3bccea 100644 --- a/scripts/uptimechecker.py +++ b/scripts/uptimechecker.py @@ -7,13 +7,19 @@ import json import pandas as pd import glob -if os.path.exists('.env'): - load_dotenv(".env") -else: - load_dotenv(".env.sample") -tor_host = os.environ.get("TOR_HOST") -tor_port = os.environ.get("TOR_PORT") + +script_abs_path = os.path.dirname(os.path.abspath(__file__)) +env_path = os.path.join(script_abs_path+"/.env") +default_env_path = os.path.join(script_abs_path+"/.env.sample") + +if os.path.exists(env_path): + load_dotenv(dotenv_path=env_path) +else: + load_dotenv(dotenv_path=default_env_path) + +tor_host = os.getenv("TOR_HOST") +tor_port = os.getenv("TOR_PORT") #apt install python3-pandas python3-requests python3-socks