modified: main.py
modified: packages/vault.py
This commit is contained in:
parent
3a5972c968
commit
e905832868
48
main.py
48
main.py
@ -14,43 +14,6 @@ import signal
|
||||
import requests
|
||||
import subprocess
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import subprocess
|
||||
|
||||
# Hardcoded GitHub URL
|
||||
github_url = "https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/"
|
||||
|
||||
def githublist(command: list):
|
||||
if len(command) != 0:
|
||||
print("Usage: githublist")
|
||||
return
|
||||
|
||||
try:
|
||||
response = requests.get(github_url)
|
||||
if response.status_code == 200:
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
files = [a['href'] for a in soup.find_all('a', href=True)]
|
||||
|
||||
# Filter out directories and unwanted links
|
||||
files = [file for file in files if not file.startswith("../") and not file.endswith("/")]
|
||||
|
||||
if files:
|
||||
print("Files in the directory:")
|
||||
for file in files:
|
||||
print(file)
|
||||
else:
|
||||
print("No files found in the directory.")
|
||||
else:
|
||||
print(f"Failed to retrieve content from {github_url}.")
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {str(e)}")
|
||||
|
||||
try:
|
||||
subprocess.run(["listgithub", github_url], check=True)
|
||||
except subprocess.CalledProcessError:
|
||||
print("Failed to list files using 'listgithub'. Make sure the 'listgithub' plugin is available.")
|
||||
|
||||
|
||||
helper = '''import ast
|
||||
class color:
|
||||
@ -237,8 +200,7 @@ class packagemanager:
|
||||
install <package name> | installs package
|
||||
list | lists installed packages
|
||||
remove <package name> | uninstall packages
|
||||
available | lists available commands
|
||||
downloadable | lists all packages on the server/db""")
|
||||
available | lists available commands""")
|
||||
|
||||
elif args[1] == "install":
|
||||
self.install(args[2])
|
||||
@ -248,20 +210,14 @@ class packagemanager:
|
||||
self.uninstall(args[2:])
|
||||
elif args[1] == "available":
|
||||
self.commands("./packages")
|
||||
elif args[1] == "downloadable":
|
||||
self.listDownloadable)
|
||||
else:
|
||||
print("""Options:
|
||||
install <package name> | installs package
|
||||
list | lists installed packages
|
||||
remove <package name> | uninstall packages
|
||||
available | lists available commands
|
||||
downloadable | lists all packages on the server/db""")
|
||||
available | lists available commands""")
|
||||
return
|
||||
|
||||
def listDownloadable(self):
|
||||
githublist()
|
||||
|
||||
|
||||
|
||||
def commands(self, directory):
|
||||
|
@ -4,79 +4,101 @@ import getpass
|
||||
from cryptography.fernet import Fernet
|
||||
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
import base64
|
||||
|
||||
# Initialize the Fernet symmetric key
|
||||
# Global variables
|
||||
key = None
|
||||
cipher_suite = None
|
||||
passwords = []
|
||||
|
||||
def initialize_vault():
|
||||
global key, cipher_suite
|
||||
global key
|
||||
|
||||
print("Welcome to the Vault!")
|
||||
|
||||
while True:
|
||||
master_password = getpass.getpass("Enter your master password: ")
|
||||
master_password = getpass.getpass("Enter your master password: ")
|
||||
salt = b'some_salt_here' # Replace with a secure salt value
|
||||
|
||||
salt = b'some_salt_here' # Replace with a secure salt value
|
||||
kdf = PBKDF2HMAC(
|
||||
algorithm=hashes.SHA256(),
|
||||
iterations=100000, # Adjust the number of iterations as needed for security
|
||||
salt=salt,
|
||||
)
|
||||
kdf = PBKDF2HMAC(
|
||||
algorithm=hashes.SHA256(),
|
||||
iterations=100000, # Adjust the number of iterations as needed for security
|
||||
salt=salt,
|
||||
length=32 # Use a fixed key length (256 bits)
|
||||
)
|
||||
|
||||
key = Fernet(base64.urlsafe_b64encode(kdf.derive(master_password.encode())))
|
||||
cipher_suite = Fernet(key)
|
||||
key = base64.urlsafe_b64encode(kdf.derive(master_password.encode()))
|
||||
print("Vault initialized successfully.")
|
||||
|
||||
print("Vault initialized successfully.")
|
||||
break
|
||||
def save_vault():
|
||||
global key, passwords
|
||||
if key is None:
|
||||
print("You must log in first to access the vault.")
|
||||
return
|
||||
|
||||
# Dictionary to store encrypted passwords (service as key, encrypted password as value)
|
||||
passwords = {}
|
||||
cipher_suite = Fernet(key)
|
||||
encrypted_passwords = [cipher_suite.encrypt(password.encode()) for password in passwords]
|
||||
|
||||
with open("vault.txt", "wb") as file:
|
||||
for encrypted_password in encrypted_passwords:
|
||||
file.write(encrypted_password + b'\n')
|
||||
|
||||
def load_vault():
|
||||
global key, passwords
|
||||
if key is None:
|
||||
print("You must log in first to access the vault.")
|
||||
return
|
||||
|
||||
try:
|
||||
with open("vault.txt", "rb") as file:
|
||||
lines = file.read().splitlines()
|
||||
cipher_suite = Fernet(key)
|
||||
passwords = [cipher_suite.decrypt(line).decode() for line in lines]
|
||||
except FileNotFoundError:
|
||||
passwords = []
|
||||
|
||||
def vault_add(password):
|
||||
global key, passwords
|
||||
if key is None:
|
||||
print("You must log in first to access the vault.")
|
||||
return
|
||||
|
||||
passwords.append(password)
|
||||
print("Password added to the vault.")
|
||||
|
||||
def vault_retrieve():
|
||||
global key, passwords
|
||||
if key is None:
|
||||
print("You must log in first to access the vault.")
|
||||
return
|
||||
|
||||
for i, password in enumerate(passwords):
|
||||
print(f"Password {i + 1}: {password}")
|
||||
|
||||
def vault(command: list):
|
||||
if len(command) != 1:
|
||||
print("Usage: vault login")
|
||||
if len(command) < 1:
|
||||
print("Usage: vault [login|add|retrieve|save|load]")
|
||||
return
|
||||
|
||||
action = command[0].lower()
|
||||
|
||||
if action == "login":
|
||||
initialize_vault()
|
||||
|
||||
elif action == "add":
|
||||
if key is None:
|
||||
print("You must log in first to access the vault.")
|
||||
return
|
||||
|
||||
service = input("Enter the service or website name: ")
|
||||
password = getpass.getpass("Enter the password: ")
|
||||
|
||||
# Encrypt the password before storing it
|
||||
encrypted_password = cipher_suite.encrypt(password.encode())
|
||||
|
||||
passwords[service] = encrypted_password
|
||||
print(f"Password for {service} added and encrypted.")
|
||||
|
||||
elif action == "add" and len(command) == 2:
|
||||
password = command[1]
|
||||
vault_add(password)
|
||||
elif action == "retrieve":
|
||||
if key is None:
|
||||
print("You must log in first to access the vault.")
|
||||
return
|
||||
|
||||
service = input("Enter the service or website name: ")
|
||||
|
||||
if service in passwords:
|
||||
# Decrypt and display the password
|
||||
decrypted_password = cipher_suite.decrypt(passwords[service]).decode()
|
||||
print(f"Password for {service}: {decrypted_password}")
|
||||
else:
|
||||
print(f"No password found for {service}.")
|
||||
|
||||
vault_retrieve()
|
||||
elif action == "save":
|
||||
save_vault()
|
||||
print("Vault saved.")
|
||||
elif action == "load":
|
||||
load_vault()
|
||||
print("Vault loaded.")
|
||||
else:
|
||||
print("Invalid action. Use 'login', 'add', or 'retrieve'.")
|
||||
print("Invalid action or arguments. Usage: vault [login|add|retrieve|save|load]")
|
||||
|
||||
# Example usage:
|
||||
# vault ["login"]
|
||||
# vault ["add", "secretpassword"]
|
||||
# vault ["retrieve"]
|
||||
# vault ["save"]
|
||||
# vault ["load"]
|
||||
|
Loading…
Reference in New Issue
Block a user