2025-09-05 17:59:19 +03:00
|
|
|
import configparser
|
2025-09-05 23:47:51 +03:00
|
|
|
import os
|
2025-09-05 17:59:19 +03:00
|
|
|
from pathlib import Path
|
2025-09-06 01:45:47 +03:00
|
|
|
import requests
|
2025-09-06 02:18:21 +03:00
|
|
|
import argparse
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='TiropitLauncher CLI & Back-End')
|
|
|
|
|
parser.add_argument('-backend', help="Runs the app in backend mode (no UI)", action="store_true")
|
|
|
|
|
|
2025-09-05 17:59:19 +03:00
|
|
|
#declare default vars
|
2025-09-05 23:32:22 +03:00
|
|
|
class Config():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AccountKey = "NK"
|
|
|
|
|
AccountID = "NA"
|
|
|
|
|
version = 01.02
|
2025-09-05 17:59:19 +03:00
|
|
|
|
2025-09-06 00:49:46 +03:00
|
|
|
class Server():
|
2025-09-06 01:45:47 +03:00
|
|
|
host = "0.0.0.0" + ":5000"
|
2025-09-06 00:49:46 +03:00
|
|
|
isReachable = False
|
2025-09-06 01:45:47 +03:00
|
|
|
state = "Resolving IP"
|
2025-09-06 00:49:46 +03:00
|
|
|
Icon = "🌐"
|
|
|
|
|
if isReachable:
|
|
|
|
|
Icon = "🌐"
|
|
|
|
|
else:
|
|
|
|
|
Icon = "⛔"
|
|
|
|
|
|
2025-09-06 02:18:21 +03:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
2025-09-05 17:59:19 +03:00
|
|
|
|
|
|
|
|
#declare files
|
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
|
configPath = Path("Config.ini")
|
|
|
|
|
|
2025-09-06 00:49:46 +03:00
|
|
|
class Display():
|
|
|
|
|
def Clear():
|
|
|
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
|
|
2025-09-06 02:18:21 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-06 00:49:46 +03:00
|
|
|
def showIntroText():
|
|
|
|
|
print("Tiropit Launcher CLI - Release Branch")
|
|
|
|
|
print(f"[TCLI]=============[Select option]==============[{Config.version}]")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-06 02:18:21 +03:00
|
|
|
|
2025-09-05 23:47:51 +03:00
|
|
|
def WarnMissingConfig(ConfigError):
|
|
|
|
|
print(f"[⚠️ WARNING ⚠️] - Your config file is corrupt , something that has to do with {ConfigError}")
|
|
|
|
|
print("Program will exit before it crashes :)")
|
|
|
|
|
reset = input("It is recommended that you reset the app data (you will be logged out) y (reset) / n (exit)")
|
|
|
|
|
if reset == "y":
|
|
|
|
|
os.remove(configPath)
|
|
|
|
|
print("[⚠️ WARNING ⚠️] - Reset Done, Re-Open TiropitCLI")
|
|
|
|
|
exit(0)
|
|
|
|
|
|
2025-09-05 17:59:19 +03:00
|
|
|
|
2025-09-06 02:18:21 +03:00
|
|
|
|
|
|
|
|
|
2025-09-05 17:59:19 +03:00
|
|
|
def makeConfig():
|
2025-09-05 23:47:51 +03:00
|
|
|
config['DEFAULT'] = {'Version': Config.version}
|
|
|
|
|
config['ACCOUNT'] = {}
|
|
|
|
|
config['ACCOUNT']['KEY'] = "NK"
|
|
|
|
|
config['ACCOUNT']["ID"] = "NA"
|
2025-09-05 17:59:19 +03:00
|
|
|
|
|
|
|
|
with open('Config.ini', 'w') as configfile:
|
|
|
|
|
config.write(configfile)
|
|
|
|
|
|
|
|
|
|
|
2025-09-06 00:49:46 +03:00
|
|
|
|
|
|
|
|
def TiropitLogin():
|
|
|
|
|
class menuData():
|
|
|
|
|
def menuInstructions():
|
|
|
|
|
Display.Clear()
|
|
|
|
|
showIntroText()
|
|
|
|
|
print("|[About: Login Instructions] |")
|
|
|
|
|
print("|1. Enter your username & password |")
|
|
|
|
|
print("|2. Enter your pin (if you have) |")
|
|
|
|
|
print("|3. Save Login key (autologin) |")
|
|
|
|
|
print("|[e] Exit [Any] Login > |")
|
|
|
|
|
print("======================================================")
|
|
|
|
|
def menuUsername():
|
|
|
|
|
Display.Clear()
|
|
|
|
|
showIntroText()
|
|
|
|
|
print(f"|[LogIn: Login page] [{Server.Icon}]|")
|
|
|
|
|
print("| Enter your username |")
|
|
|
|
|
print("| |")
|
|
|
|
|
print("| |")
|
|
|
|
|
print("| |")
|
|
|
|
|
print("======================================================")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menuData.menuInstructions()
|
|
|
|
|
option = input(">> ")
|
|
|
|
|
match option:
|
|
|
|
|
case "e":
|
|
|
|
|
showMenu(1)
|
|
|
|
|
return 0
|
|
|
|
|
case _:
|
|
|
|
|
menuData.menuUsername()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-05 17:59:19 +03:00
|
|
|
def loadConfig():
|
2025-09-05 23:32:22 +03:00
|
|
|
try:
|
|
|
|
|
config.read(configPath)
|
|
|
|
|
Config.version = config["DEFAULT"]["Version"]
|
|
|
|
|
Config.AccountID = config["ACCOUNT"]["ID"]
|
|
|
|
|
Config.AccountID = config["ACCOUNT"]["KEY"]
|
|
|
|
|
except Exception as e:
|
2025-09-05 23:47:51 +03:00
|
|
|
WarnMissingConfig(e)
|
2025-09-05 17:59:19 +03:00
|
|
|
|
2025-09-06 02:18:21 +03:00
|
|
|
|
|
|
|
|
|
2025-09-06 01:45:47 +03:00
|
|
|
def grabServerResolver():
|
|
|
|
|
try:
|
2025-09-06 02:18:21 +03:00
|
|
|
response = requests.get("https://kevinblog.sytes.net/APIhS/test1.php")
|
2025-09-06 01:45:47 +03:00
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
data = response.json()
|
|
|
|
|
server_ip = data.get("HostIp")
|
2025-09-06 02:18:21 +03:00
|
|
|
Server.isReachable = True
|
|
|
|
|
Server.state = "Connected"
|
2025-09-06 01:45:47 +03:00
|
|
|
Server.host = server_ip
|
2025-09-06 02:18:21 +03:00
|
|
|
if args.backend: print(f"2:CONNECTED TO: {server_ip}")
|
2025-09-06 01:45:47 +03:00
|
|
|
return server_ip
|
|
|
|
|
|
|
|
|
|
except requests.exceptions.RequestException as e:
|
2025-09-06 02:18:21 +03:00
|
|
|
|
2025-09-06 01:45:47 +03:00
|
|
|
Server.isReachable = False
|
2025-09-06 02:18:21 +03:00
|
|
|
Server.state = f"Failed/Timed Out - {e}"
|
|
|
|
|
if args.backend: print(f"3:FAILED CONN TO: {e}")
|
|
|
|
|
else: print("Error resolving a host, Considering service is offline.")
|
2025-09-06 01:45:47 +03:00
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
2025-09-05 23:32:22 +03:00
|
|
|
def checkConfig():
|
|
|
|
|
if configPath.exists():
|
|
|
|
|
print("The Config file exists.")
|
|
|
|
|
loadConfig()
|
2025-09-05 17:59:19 +03:00
|
|
|
|
2025-09-05 23:32:22 +03:00
|
|
|
else:
|
|
|
|
|
print("The file Config does not exist. - Creating")
|
|
|
|
|
makeConfig()
|
2025-09-05 17:59:19 +03:00
|
|
|
|
2025-09-06 01:45:47 +03:00
|
|
|
|
|
|
|
|
def debugMenu():
|
|
|
|
|
class menuData():
|
|
|
|
|
def mainMenu():
|
|
|
|
|
Display.Clear()
|
|
|
|
|
showIntroText()
|
|
|
|
|
print(f"|[DBG] [{Server.Icon}]|")
|
|
|
|
|
print("|1. Read Server Data |")
|
|
|
|
|
print("|2. |")
|
|
|
|
|
print("|3. |")
|
|
|
|
|
print("|[e] Exit |")
|
|
|
|
|
print("======================================================")
|
|
|
|
|
|
|
|
|
|
option = input(">> ")
|
|
|
|
|
if option == "": menuData.mainMenu()
|
|
|
|
|
match option:
|
|
|
|
|
case "e":
|
|
|
|
|
showMenu(1)
|
|
|
|
|
return 0
|
|
|
|
|
case "1":
|
|
|
|
|
menuData.menuServerData()
|
|
|
|
|
case _:
|
|
|
|
|
menuData.mainMenu()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def menuServerData():
|
|
|
|
|
Display.Clear()
|
|
|
|
|
showIntroText()
|
|
|
|
|
print(f"|[DBG: Login page] [{Server.Icon}]|")
|
|
|
|
|
print(f"| IsReachable : {Server.isReachable}")
|
|
|
|
|
print(f"| Host : {Server.host}")
|
|
|
|
|
print(f"| State : {Server.state}")
|
|
|
|
|
print("[e] Exit")
|
|
|
|
|
print("======================================================")
|
|
|
|
|
|
|
|
|
|
option = input(">> ")
|
|
|
|
|
if option == "": menuData.menuServerData()
|
|
|
|
|
match option:
|
|
|
|
|
case "e":
|
|
|
|
|
showMenu(1)
|
|
|
|
|
return 0
|
|
|
|
|
case _:
|
|
|
|
|
menuData.menuServerData()
|
|
|
|
|
|
|
|
|
|
menuData.mainMenu()
|
|
|
|
|
option = input(">> ")
|
|
|
|
|
if option == "": menuData.mainMenu()
|
|
|
|
|
match option:
|
|
|
|
|
case "e":
|
|
|
|
|
showMenu(1)
|
|
|
|
|
return 0
|
|
|
|
|
case "1":
|
|
|
|
|
menuData.menuServerData()
|
|
|
|
|
case _:
|
|
|
|
|
menuData.mainMenu()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-06 00:49:46 +03:00
|
|
|
def showMenu(menuID):
|
|
|
|
|
Display.Clear()
|
|
|
|
|
showIntroText()
|
|
|
|
|
match menuID:
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
|
|
print("|[Main menu] |")
|
|
|
|
|
print("|[1] Log in to tiropit | [2] Reset Data & Config |")
|
|
|
|
|
print("|[3] Send / Get Request| [4] My Profile |")
|
2025-09-06 01:45:47 +03:00
|
|
|
print("|[5] Debug Data | |")
|
2025-09-06 00:49:46 +03:00
|
|
|
print("|[e] Exit |")
|
|
|
|
|
print("======================================================")
|
|
|
|
|
option = input(">> ")
|
|
|
|
|
if option == "": showMenu(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(option)
|
|
|
|
|
match option:
|
|
|
|
|
case "1":
|
|
|
|
|
TiropitLogin()
|
2025-09-06 01:45:47 +03:00
|
|
|
case "5":
|
|
|
|
|
debugMenu()
|
|
|
|
|
case "e":
|
|
|
|
|
print("Cya!")
|
|
|
|
|
exit();
|
2025-09-06 00:49:46 +03:00
|
|
|
case _:
|
|
|
|
|
showMenu(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pass
|
2025-09-05 17:59:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-05 23:32:22 +03:00
|
|
|
#Begin
|
2025-09-06 02:18:21 +03:00
|
|
|
if not args.backend:
|
|
|
|
|
|
|
|
|
|
grabServerResolver()
|
|
|
|
|
checkConfig()
|
|
|
|
|
showMenu(1)
|
|
|
|
|
else:
|
|
|
|
|
print("1:=== BACKEND MODE ===")
|
|
|
|
|
grabServerResolver()
|
|
|
|
|
|