Files
listik 3ae4e18211
Offline regression tests / windows (3.11) (push) Canceled after 0s
Offline regression tests / windows (3.12) (push) Canceled after 0s
Offline regression tests / windows (3.13) (push) Canceled after 0s
23
2026-10-23 21:42:13 +03:00

61 lines
2.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""SSH-only account administration for the Linux deployment."""
from __future__ import annotations
import argparse
import getpass
import os
import sys
from pathlib import Path
from user_auth import AuthError, UserStore
if os.name != "nt":
os.umask(0o077)
ROOT = Path(__file__).resolve().parent
STORE = UserStore(ROOT / "web_sim_data")
def create(username: str) -> int:
if os.name != "nt" and os.geteuid() == 0:
print("Не запускайте от root. Используйте sudo -u cryptosim.", file=sys.stderr)
return 2
password = getpass.getpass("Пароль (12–256 символов): ")
confirm = getpass.getpass("Повторите пароль: ")
if password != confirm:
print("Пароли не совпадают.", file=sys.stderr)
return 2
try:
user_id = STORE.register(username, password)
# Carry over legacy single-user data only for the first account, without deleting the source.
if STORE.mark_legacy_imported():
from web_proxy import _import_legacy_data
_import_legacy_data(STORE.data_dir(user_id))
except AuthError as exc:
print(f"Не удалось создать пользователя: {exc}", file=sys.stderr)
return 2
print(f"Создан пользователь {username}. Его личный движок запустится при первом входе на сайт.")
return 0
def main() -> int:
parser = argparse.ArgumentParser(description="Управление аккаунтами Crypto Scam (только SSH)")
commands = parser.add_subparsers(dest="command", required=True)
make = commands.add_parser("create", help="создать пользователя")
make.add_argument("username")
commands.add_parser("list", help="показать имена пользователей")
args = parser.parse_args()
if args.command == "create":
return create(args.username)
if os.name != "nt" and os.geteuid() == 0:
print("Выполните от пользователя cryptosim: sudo -u cryptosim ...", file=sys.stderr)
return 2
users = [STORE.username(user_id) for user_id in STORE.user_ids()]
print("\n".join(users) if users else "Пользователей пока нет.")
return 0
if __name__ == "__main__":
raise SystemExit(main())