Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor QOL and Bug fixes #140

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions silenttrinity/core/client/cmdloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ def get_completions(self, document, complete_event):

if self.cli_menu.teamservers.selected:
if cmd_line[0] == 'use':
for loadable in self.cli_menu.current_context.available:
if word_before_cursor in loadable:
# Apperently document.get_word_before_cursor() breaks if there's a forward slash in the command line ?
try:
yield Completion(loadable, -len(cmd_line[1]))
except IndexError:
yield Completion(loadable, -len(word_before_cursor))
if hasattr(self.cli_menu.current_context, 'available'):
for loadable in self.cli_menu.current_context.available:
if word_before_cursor in loadable:
# Apperently document.get_word_before_cursor() breaks if there's a forward slash in the command line ?
try:
yield Completion(loadable, -len(cmd_line[1]))
except IndexError:
yield Completion(loadable, -len(word_before_cursor))
return

if hasattr(self.cli_menu.current_context, 'selected') and self.cli_menu.current_context.selected:
Expand Down Expand Up @@ -184,12 +185,13 @@ async def switched_context(self, text):
if text.lower() == ctx.name:
if ctx._remote is True:
try:
response = await self.teamservers.send(
ctx=ctx.name,
cmd="get_selected"
)
if response.result:
ctx.selected = response.result
if ctx.name != "sessions":
response = await self.teamservers.send(
ctx=ctx.name,
cmd="get_selected"
)
if response.result:
ctx.selected = response.result
except AttributeError:
break

Expand All @@ -216,7 +218,9 @@ async def parse_command_line(self, text):
print_bad(f"Error parsing command: {e}")
except AttributeError as e:
print_bad(f"Unknown command '{command[0]}'")
except (DocoptExit, SystemExit):
except DocoptExit:
print_bad("Check command usage")
except SystemExit:
pass
else:
if command[0] in self._cmd_registry or self.current_context._remote is False:
Expand Down
4 changes: 2 additions & 2 deletions silenttrinity/core/teamserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import multiprocessing
from silenttrinity.core.ipcserver import IPCServer
logging.basicConfig(
format="%(asctime)s %(process)d %(threadName)s - [%(levelname)s] %(filename)s: %(funcName)s - %(message)s",
level=logging.DEBUG
format="[%(levelname)s] %(message)s",
level=logging.INFO
)

# disable all loggers from different files
Expand Down
11 changes: 10 additions & 1 deletion silenttrinity/core/teamserver/__main__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python3

"""
Usage: teamserver [-h] [--port <PORT>] [--insecure] <host> <password>
Usage: teamserver [-h] [--port <PORT>] [--insecure][--debug] <host> <password>

optional arguments:
-h, --help Show this help message and exit
-p, --port <PORT> Port to bind to [default: 5000]
--insecure Start server without TLS
--debug Enable debug logging
"""

import asyncio
Expand Down Expand Up @@ -198,4 +199,12 @@ def start(args):
if args['--insecure']:
logging.warning('SECURITY WARNING: --insecure flag passed, communication between client and server will be in cleartext!')

if args['--debug']:
logger = logging.getLogger()
logger_handler = logging.StreamHandler() # Handler for the logger
logger.addHandler(logger_handler)
logger_handler.setFormatter(logging.Formatter(
'[%(levelname)s] %(process)d %(threadName)s - %(filename)s: %(funcName)s - %(message)s'))
logging.getLogger().setLevel(logging.DEBUG)

loop.run_until_complete(server(stop, args, teamserver_digest))