diff --git a/bin_arc/script/ngroksenpai.py b/bin_arc/script/ngroksenpai.py index 159b408..9aa7f93 100644 --- a/bin_arc/script/ngroksenpai.py +++ b/bin_arc/script/ngroksenpai.py @@ -1,4 +1,3 @@ - import subprocess import requests import json @@ -7,7 +6,6 @@ import time LOCK_FILE = "ngroksenpai.lock" -WEBHOOK_FILE_PATH = '../config/webhook.txt' def check_lock_file(): return os.path.exists(LOCK_FILE) @@ -27,39 +25,20 @@ def check_tunnel(curl_command, target_string): return output return None -# thx chatgpt lmao -def get_discord_webhook_url(file_path): - with open(file_path, 'r') as file: - return file.read().strip() - def send_discord_webhook(webhook_url, region, url): message = f"* {region} === `{url}`" payload = {"content": message} requests.post(webhook_url, json=payload) -os.chdir('../config') -with open("conf.txt", "r") as conf_file: - conf_lines = conf_file.readlines() - -use_ngrok = False -autongrok = False - -for line in conf_lines: - if line.startswith("#"): - continue - parts = line.strip().split('=') - if len(parts) == 2: - key, value = parts[0].strip(), parts[1].strip() - if key == "use-ngrok" and value.lower() == "true": - use_ngrok = True - elif key == "autongrok" and value.lower() == "true": - autongrok = True - -if autongrok: - starter_script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'starter.sh') - subprocess.Popen(['bash', starter_script_path]) - -time.sleep(10) +def read_config(file_path): + config = {} + with open(file_path, 'r') as file: + lines = file.readlines() + for line in lines: + if '=' in line: + key, value = line.strip().split('=') + config[key.strip()] = value.strip() + return config def main(): if check_lock_file(): @@ -69,7 +48,13 @@ def main(): create_lock_file() try: - discord_webhook_url = get_discord_webhook_url(WEBHOOK_FILE_PATH) + config = read_config('../config/conf.txt') + + if config.get('autongrok') == 'True': + starter_script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'starter.sh') + subprocess.Popen(['bash', starter_script_path]) + time.sleep(15) + print("WORKING") curl_commands = [ "curl 127.0.0.1:4040/api/tunnels", @@ -81,6 +66,15 @@ def main(): target_string = "tcp://" + webhook_file_path = '../config/webhook.txt' + if os.path.exists(webhook_file_path): + with open(webhook_file_path, 'r') as webhook_file: + + discord_webhook_url = webhook_file.read().strip() # webhook func + else: + print("Error: webhook.txt not found. Please create the file with your Discord webhook URL and rerun the application.") + sys.exit(1) + region_mapping = { ".au": "Sydney", ".ap": "Singapore", diff --git a/bin_arc/ussr-ssl.py b/bin_arc/ussr-ssl.py index fb38e2c..404bde3 100644 --- a/bin_arc/ussr-ssl.py +++ b/bin_arc/ussr-ssl.py @@ -1,3 +1,5 @@ +# bin/ussr-ssl.py + import subprocess import os import requests @@ -22,7 +24,7 @@ app = Flask(__name__) -MC_FOLDER = '.mc/' +MC_FOLDER = 'bin/.mc/' DISCORD_WEBHOOK_URL_FILE = '../config/webhook.txt' def get_discord_webhook_url(): @@ -46,8 +48,7 @@ def index(): @app.route('/start') def start(): send_discord_message('``server starting...``') - - start_command = ['java', '-jar', '-Xms256M', '-Xmx5G', f'{MC_FOLDER}/fabric.jar'] + start_command = ['java', '-jar', '-Xms256M', '-Xmx5G', f'{MC_FOLDER}/server.jar'] subprocess.Popen(start_command, cwd=MC_FOLDER) time.sleep(27) diff --git a/bin_win/script/ngroksenpai.py b/bin_win/script/ngroksenpai.py index 95b6a6c..46578e6 100644 --- a/bin_win/script/ngroksenpai.py +++ b/bin_win/script/ngroksenpai.py @@ -1,4 +1,3 @@ - import subprocess import requests import json @@ -7,7 +6,6 @@ import time LOCK_FILE = "ngroksenpai.lock" -WEBHOOK_FILE_PATH = '../config/webhook.txt' def check_lock_file(): return os.path.exists(LOCK_FILE) @@ -27,40 +25,20 @@ def check_tunnel(curl_command, target_string): return output return None -# thx chatgpt lmao -def get_discord_webhook_url(file_path): - with open(file_path, 'r') as file: - return file.read().strip() - def send_discord_webhook(webhook_url, region, url): message = f"* {region} === `{url}`" payload = {"content": message} requests.post(webhook_url, json=payload) -os.chdir('../config') -with open("conf.txt", "r") as conf_file: - conf_lines = conf_file.readlines() - -use_ngrok = False -autongrok = False - -for line in conf_lines: - if line.startswith("#"): - continue - parts = line.strip().split('=') - if len(parts) == 2: - key, value = parts[0].strip(), parts[1].strip() - if key == "use-ngrok" and value.lower() == "true": - use_ngrok = True - elif key == "autongrok" and value.lower() == "true": - autongrok = True - -if autongrok: - starter_script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'starter.bat') - subprocess.Popen(['cmd', '/c', starter_script_path]) - - -time.sleep(10) +def read_config(file_path): + config = {} + with open(file_path, 'r') as file: + lines = file.readlines() + for line in lines: + if '=' in line: + key, value = line.strip().split('=') + config[key.strip()] = value.strip() + return config def main(): if check_lock_file(): @@ -70,7 +48,13 @@ def main(): create_lock_file() try: - discord_webhook_url = get_discord_webhook_url(WEBHOOK_FILE_PATH) + config = read_config('../config/conf.txt') + + if config.get('autongrok') == 'True': + starter_script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'starter.bat') + subprocess.Popen(['cmd', '/c', starter_script_path]) + time.sleep(15) + print("WORKING") curl_commands = [ "curl 127.0.0.1:4040/api/tunnels", @@ -82,6 +66,15 @@ def main(): target_string = "tcp://" + webhook_file_path = '../config/webhook.txt' + if os.path.exists(webhook_file_path): + with open(webhook_file_path, 'r') as webhook_file: + + discord_webhook_url = webhook_file.read().strip() # webhook func + else: + print("Error: webhook.txt not found. Please create the file with your Discord webhook URL and rerun the application.") + sys.exit(1) + region_mapping = { ".au": "Sydney", ".ap": "Singapore", diff --git a/bin_win/ussr-ssl.py b/bin_win/ussr-ssl.py index fb38e2c..404bde3 100644 --- a/bin_win/ussr-ssl.py +++ b/bin_win/ussr-ssl.py @@ -1,3 +1,5 @@ +# bin/ussr-ssl.py + import subprocess import os import requests @@ -22,7 +24,7 @@ app = Flask(__name__) -MC_FOLDER = '.mc/' +MC_FOLDER = 'bin/.mc/' DISCORD_WEBHOOK_URL_FILE = '../config/webhook.txt' def get_discord_webhook_url(): @@ -46,8 +48,7 @@ def index(): @app.route('/start') def start(): send_discord_message('``server starting...``') - - start_command = ['java', '-jar', '-Xms256M', '-Xmx5G', f'{MC_FOLDER}/fabric.jar'] + start_command = ['java', '-jar', '-Xms256M', '-Xmx5G', f'{MC_FOLDER}/server.jar'] subprocess.Popen(start_command, cwd=MC_FOLDER) time.sleep(27) diff --git a/scripts/launcher.py b/scripts/launcher.py index 845531d..8b0b659 100644 --- a/scripts/launcher.py +++ b/scripts/launcher.py @@ -2,6 +2,7 @@ import os import platform import webbrowser +import subprocess def clear_screen(): system = platform.system().lower() @@ -72,7 +73,10 @@ def ussr_for_arch(): else: print("Only 'y' or 'n'. Indecisive enough?") - os.system('ngrok config add-authtoken {ngrok_token}') + with open('../config/token.txt', 'r') as file: + ngrok_token = file.read().strip() + os.system(f'ngrok config add-authtoken {ngrok_token}') + os.system('chmod +x start.sh') os.system('./start.sh') os.chdir('../scripts')