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