23
This commit is contained in:
1 parent
efd4e1dcf4
commit
3ae4e18211
4 files changed
+89
-19
No files matched your search
@@ -0,0 +1,60 @@
|
||||
"""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())
|
||||
Reference in new issue
Block a user