Создание временной лицензии
Some checks failed
CI / backend (push) Failing after 8s
CI / frontend (push) Failing after 3s

This commit is contained in:
2025-12-01 11:47:45 +00:00
parent adbf40240c
commit 667d3c205a

View File

@@ -4,11 +4,13 @@ from pathlib import Path
from ..utils.encoding import variant_base64_encode from ..utils.encoding import variant_base64_encode
from ..utils.crypto import encrypt_bytes from ..utils.crypto import encrypt_bytes
class LicenseType: class LicenseType:
Professional: int = 1 Professional: int = 1
Educational: int = 3 Educational: int = 3
Personal: int = 4 Personal: int = 4
def generate_license_file( def generate_license_file(
user_name: str, user_name: str,
version: str, version: str,
@@ -26,18 +28,21 @@ def generate_license_file(
minor_version: int = int(minor_str) minor_version: int = int(minor_str)
except Exception as e: except Exception as e:
raise ValueError(f"Неверный формат версии: {version}") from e raise ValueError(f"Неверный формат версии: {version}") from e
# Формирование строки лицензии (исправлено: убрали лишний #, интегрировали цифры в один блок)
# Формирование строки лицензии
license_str: str = ( license_str: str = (
f"{lic_type}#{user_name}|{major_version}{minor_version}" f"{lic_type}#{user_name}|{major_version}{minor_version}"
f"#{count}#{major_version}3{minor_version}6{minor_version}#0#0#0#" f"#{count}#{major_version}3{minor_version}6{minor_version}#0#0#0#"
) )
# Шифрование и кодирование # Шифрование и кодирование
encrypted: bytes = encrypt_bytes(0x0787, license_str.encode("utf-8")) encrypted: bytes = encrypt_bytes(0x0787, license_str.encode("utf-8"))
encoded: str = variant_base64_encode(encrypted).decode("ascii") encoded: str = variant_base64_encode(encrypted).decode("ascii")
# Создание временной директории и файла с фиксированным именем # Создание временной директории и файла с фиксированным именем
temp_dir = tempfile.TemporaryDirectory() temp_dir = tempfile.TemporaryDirectory()
filepath = Path(temp_dir.name) / "Custom.mxtpro" filepath = Path(temp_dir.name) / "Custom.mxtpro"
with ZipFile(filepath, "w") as zf: with ZipFile(filepath, "w") as zf:
zf.writestr("Pro.key", encoded) zf.writestr("Pro.key", encoded)
return str(filepath), temp_dir
return str(filepath), temp_dir