LASME.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import subprocess
  2. import sys
  3. import importlib
  4. import base64
  5. import json
  6. def check_and_install_dependencies():
  7. """
  8. Checks if required libraries are installed. If not, installs them automatically.
  9. """
  10. dependencies = [
  11. ("requests", "requests"),
  12. ("urllib3", "urllib3"),
  13. ("questionary", "questionary"),
  14. ("rich", "rich")
  15. ]
  16. missing_packages = []
  17. for import_name, pip_name in dependencies:
  18. try:
  19. importlib.import_module(import_name)
  20. except ImportError:
  21. missing_packages.append(pip_name)
  22. if missing_packages:
  23. print(f"Missing dependencies detected: {', '.join(missing_packages)}")
  24. print("Attempting to install automatically...")
  25. try:
  26. # subprocess.check_call([sys.executable, "-m", "pip", "install"] + missing_packages)
  27. subprocess.check_call([sys.executable, "-m", "pip", "install", "--user"] + missing_packages)
  28. print("\nDependencies installed successfully.\n")
  29. except subprocess.CalledProcessError as e:
  30. print(f"\n[ERROR] Failed to install dependencies automatically: {e}")
  31. print("Please install them manually using: pip install " + " ".join(missing_packages))
  32. sys.exit(1)
  33. # Run the dependency check before importing the rest
  34. check_and_install_dependencies()
  35. # --- Imports (Safe to run now) ---
  36. import requests
  37. import urllib3
  38. import questionary
  39. from questionary import Separator
  40. from rich.console import Console
  41. from rich.panel import Panel
  42. # Disable the "InsecureRequestWarning"
  43. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  44. # Configuration
  45. URL = "https://starwars.citrite.net/las_update/api"
  46. # --- Security Configuration ---
  47. VALID_UNLOCK_KEY_B64 = "dW5sb2NrbmV0c2NhbGVy"
  48. def print_banner():
  49. """Prints a nice banner for the TUI."""
  50. console = Console()
  51. banner_text = (
  52. "[bold cyan]NS-VPX LAS Activator[/bold cyan]\n"
  53. "[dim]Build By Parv Ashwani[/dim]"
  54. )
  55. console.print(Panel(banner_text, expand=False, border_style="green"))
  56. def main():
  57. print_banner()
  58. console = Console()
  59. # 1. Collect User Input via TUI
  60. device_ip = questionary.text(
  61. "Enter Device IP / Hostname:",
  62. validate=lambda text: True if text else "Please enter a valid IP or hostname."
  63. ).ask()
  64. username = questionary.text(
  65. "Enter Username:",
  66. validate=lambda text: True if text else "Username cannot be empty."
  67. ).ask()
  68. password = questionary.password(
  69. "Enter Password:"
  70. ).ask()
  71. # Selection for request_ed (Edition)
  72. request_ed = questionary.select(
  73. "Select Request Edition (request_ed):",
  74. choices=[
  75. "Standard",
  76. "Advance",
  77. "Premium"
  78. ]
  79. ).ask()
  80. # Selection for request_pem (License Server)
  81. request_pem = questionary.select(
  82. "Select License Server (request_pem):",
  83. choices=[
  84. "CNS_V10_SERVER",
  85. "CNS_V25_SERVER",
  86. "CNS_V200_SERVER",
  87. "CNS_V1000_SERVER",
  88. "CNS_V3000_SERVER",
  89. "CNS_V5000_SERVER",
  90. "CNS_V10000_SERVER",
  91. "CNS_V25000_SERVER"
  92. ]
  93. ).ask()
  94. # 2. Security Check for High Capacity Licenses
  95. # Restricted list: Anything strictly greater than CNS_V1000_SERVER
  96. restricted_servers = [
  97. "CNS_V3000_SERVER",
  98. "CNS_V5000_SERVER",
  99. "CNS_V10000_SERVER",
  100. "CNS_V25000_SERVER"
  101. ]
  102. if request_pem in restricted_servers:
  103. console.print("\n[bold yellow]High Capacity License Selected.[/bold yellow]")
  104. console.print("[yellow]Authorization required to proceed.[/yellow]")
  105. unlock_input = questionary.password("Enter Unlock Password:").ask()
  106. # Decode the Base64 key from the code and compare
  107. try:
  108. decoded_key = base64.b64decode(VALID_UNLOCK_KEY_B64).decode("utf-8")
  109. if unlock_input != decoded_key:
  110. console.print("[bold red]Incorrect Unlock Password. Exiting.[/bold red]")
  111. sys.exit(1)
  112. except Exception:
  113. console.print("[bold red]Security check failed. Exiting.[/bold red]")
  114. sys.exit(1)
  115. console.print("[green]Unlock successful. Proceeding...[/green]")
  116. # 3. Construct the Payload
  117. payload = {
  118. "product": "NS-VPX",
  119. "deviceip": device_ip,
  120. "username": username,
  121. "password": password,
  122. "request_pem": request_pem,
  123. "request_ed": request_ed
  124. }
  125. console.print("\n[yellow]Sending request...[/yellow]")
  126. # 4. Send the Request
  127. try:
  128. response = requests.post(
  129. URL,
  130. data=payload,
  131. verify=False,
  132. timeout=30
  133. )
  134. # 5. Output the Response
  135. console.print(f"[bold green]Status Code:[/bold green] {response.status_code}")
  136. try:
  137. json_resp = response.json()
  138. console.print("[bold blue]Response Body:[/bold blue]")
  139. console.print(json.dumps(json_resp, indent=4))
  140. except ValueError:
  141. console.print("[bold blue]Response Body:[/bold blue]")
  142. console.print(response.text)
  143. except requests.exceptions.RequestException as e:
  144. console.print(f"\n[bold red]An error occurred:[/bold red] {e}")
  145. if __name__ == "__main__":
  146. try:
  147. main()
  148. except KeyboardInterrupt:
  149. print("\nExiting...")