|
| 1 | +import os |
| 2 | +import tkinter as tk |
| 3 | +from tkinter import messagebox # Explicitly import messagebox |
| 4 | + |
| 5 | +# Initialize the main window |
| 6 | +root = tk.Tk() |
| 7 | +root.title("VPN API Key Request") |
| 8 | + |
| 9 | +# Instructions for obtaining the API key |
| 10 | +instructions = """ |
| 11 | +Please visit https://vpnapi.io/dashboard to create an account and obtain your API key. Once you have your API key, |
| 12 | +please enter it below and click 'Submit'. |
| 13 | +
|
| 14 | +We do apologise but for IP analysis we had to use this method, we ensure you its safe, if you are still in doubt you may use this pre-generated API key {c6048787b83f44b18d4ce50e5c8869ed} |
| 15 | +
|
| 16 | +The KEY should not include the {} given, the key has a limit of 1000 requests a day, so its recommended to use your own API key, Thank you and we apologise for this inconvenience, to skip the API function type API-NO as your key. |
| 17 | +""" |
| 18 | + |
| 19 | +# Label to display instructions |
| 20 | +instruction_label = tk.Label(root, text=instructions) |
| 21 | +instruction_label.pack(pady=20) # Use pack for simpler layout |
| 22 | + |
| 23 | +# Entry widget for the user to input the API key |
| 24 | +api_key_entry = tk.Entry(root) |
| 25 | +api_key_entry.pack(pady=10) # Use pack for simpler layout |
| 26 | + |
| 27 | +# Entry widget for the user to re-enter the API key for double-entry validation |
| 28 | +api_key_entry_confirm = tk.Entry(root) |
| 29 | +api_key_entry_confirm.pack(pady=10) # Use pack for simpler layout |
| 30 | + |
| 31 | + |
| 32 | +def submit_api_key(): |
| 33 | + api_key = api_key_entry.get().strip() # Retrieve and strip whitespace from the entered API key |
| 34 | + api_key_confirm = api_key_entry_confirm.get().strip() # Retrieve and strip whitespace from the confirmed API key |
| 35 | + |
| 36 | + # Error check for empty inputs |
| 37 | + if not api_key or not api_key_confirm: |
| 38 | + messagebox.showerror(title="Error", message="Both fields must be filled out.") |
| 39 | + return |
| 40 | + |
| 41 | + # Double-entry validation |
| 42 | + if api_key != api_key_confirm: |
| 43 | + messagebox.showwarning(title="Warning", message="The API keys do not match. Please try again.") |
| 44 | + return |
| 45 | + |
| 46 | + # Check if the API.KEY file already exists |
| 47 | + if os.path.exists('SYSTEM/API.KEY'): |
| 48 | + messagebox.showerror(title="Error", |
| 49 | + message="A API.KEY file already exists in the SYSTEM directory. Please delete it before submitting a new API key.") |
| 50 | + return |
| 51 | + |
| 52 | + # Proceed to create the API.KEY file with the submitted API key |
| 53 | + parent_dir = os.path.dirname(os.getcwd()) # Get the parent directory |
| 54 | + system_dir = os.path.join(parent_dir, "SYSTEM") # Construct the SYSTEM directory path |
| 55 | + os.makedirs(system_dir, exist_ok=True) # Ensure the SYSTEM directory exists |
| 56 | + |
| 57 | + with open(os.path.join(system_dir, 'API.KEY'), 'w') as f: |
| 58 | + f.write(api_key + "\n") # Write the API key to the file followed by a newline character |
| 59 | + |
| 60 | + messagebox.showinfo(title="Success", message="API key saved to API.KEY.") |
| 61 | + exit(1) |
| 62 | + |
| 63 | + |
| 64 | +# Submit button for the user to finalize the API key submission |
| 65 | +submit_button = tk.Button(root, text="Submit", command=submit_api_key) |
| 66 | +submit_button.pack(pady=10) # Use pack for simpler layout |
| 67 | + |
| 68 | +# Start the application |
| 69 | +root.mainloop() |
0 commit comments