From e729c72c6a87859cdd4bfeea2d48066ea6c036d8 Mon Sep 17 00:00:00 2001 From: Daan Selen Date: Fri, 11 Jul 2025 16:24:21 +0200 Subject: [PATCH] added support for totp --- meshbook.py | 22 +++++++++++++++----- templates/{config.conf => api.conf.template} | 0 2 files changed, 17 insertions(+), 5 deletions(-) rename templates/{config.conf => api.conf.template} (100%) diff --git a/meshbook.py b/meshbook.py index c2e734b..56c25a3 100644 --- a/meshbook.py +++ b/meshbook.py @@ -4,6 +4,7 @@ import argparse import asyncio from colorama import just_fix_windows_console +import pyotp import json import meshctrl @@ -20,11 +21,22 @@ async def init_connection(credentials: dict) -> meshctrl.Session: Use the libmeshctrl library to initiate a Secure Websocket (wss) connection to the MeshCentral instance. ''' - session = meshctrl.Session( - credentials['hostname'], - user=credentials['username'], - password=credentials['password'] - ) + if configuration["totp_secret"]: + totp = pyotp.TOTP(configuration["totp_secret"]) + otp = totp.now() + + session = meshctrl.Session( + configuration['hostname'], + user=configuration['username'], + password=configuration['password'], + token=otp + ) + else: + session = meshctrl.Session( + configuration['hostname'], + user=configuration['username'], + password=configuration['password'] + ) await session.initialized.wait() return session diff --git a/templates/config.conf b/templates/api.conf.template similarity index 100% rename from templates/config.conf rename to templates/api.conf.template