59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
import argparse
|
|
import json
|
|
import os
|
|
from datetime import datetime
|
|
|
|
from cryptography.fernet import Fernet
|
|
|
|
|
|
LEGACY_LICENSE_KEY = b"vS-C5Z_R1ST-Gf_K8_L9_Xo2-M1A3B5C7D9E1F2G3H4="
|
|
|
|
|
|
def load_master_key() -> bytes:
|
|
env_key = os.getenv("VFM_LICENSE_MASTER_KEY")
|
|
if env_key:
|
|
return env_key.encode("utf-8")
|
|
return LEGACY_LICENSE_KEY
|
|
|
|
|
|
def parse_args():
|
|
parser = argparse.ArgumentParser(description="Gerador de licenca do V-Fire Monitor")
|
|
parser.add_argument("--hwid", help="Hardware ID do cliente")
|
|
parser.add_argument("--cliente", help="Nome do cliente")
|
|
parser.add_argument("--expira", help="Data de expiracao no formato AAAA-MM-DD")
|
|
return parser.parse_args()
|
|
|
|
|
|
def ask_if_missing(value: str, prompt: str) -> str:
|
|
return value if value else input(prompt).strip()
|
|
|
|
|
|
def validate_expiration(date_text: str) -> str:
|
|
datetime.strptime(date_text, "%Y-%m-%d")
|
|
return date_text
|
|
|
|
|
|
def gerar_serial(hardware_id: str, cliente: str, data_expiracao: str) -> str:
|
|
fernet = Fernet(load_master_key())
|
|
payload = {"h": hardware_id.strip(), "c": cliente.strip(), "e": validate_expiration(data_expiracao)}
|
|
return fernet.encrypt(json.dumps(payload, ensure_ascii=False).encode("utf-8")).decode("utf-8")
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
|
|
hardware_id = ask_if_missing(args.hwid, "Hardware ID do cliente: ")
|
|
cliente = ask_if_missing(args.cliente, "Nome do cliente: ")
|
|
expiracao = ask_if_missing(args.expira, "Validade (AAAA-MM-DD): ")
|
|
|
|
if not hardware_id:
|
|
raise SystemExit("Hardware ID obrigatorio.")
|
|
if not cliente:
|
|
raise SystemExit("Nome do cliente obrigatorio.")
|
|
|
|
print(gerar_serial(hardware_id, cliente, expiracao))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|