Skip to content

Commit

Permalink
Merge branch 'main' into fix-output-sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
p0dalirius authored Jun 25, 2024
2 parents 95ae73c + 25283e9 commit 34c9e3e
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 264 deletions.
8 changes: 6 additions & 2 deletions smbclientng/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from smbclientng.core.Config import Config
from smbclientng.core.Credentials import Credentials
from smbclientng.core.InteractiveShell import InteractiveShell
from smbclientng.core.Logger import Logger
from smbclientng.core.SessionsManager import SessionsManager


Expand Down Expand Up @@ -106,7 +107,9 @@ def main():
config.not_interactive = options.not_interactive
config.startup_script = options.startup_script

sessionsManager = SessionsManager(config=config)
logger = Logger(config=config, logfile=None)

sessionsManager = SessionsManager(config=config, logger=logger)

if any([(options.auth_domain != '.'), (options.auth_username is not None), (options.auth_password is not None),(options.auth_hashes is not None)]):
credentials = Credentials(
Expand All @@ -127,7 +130,8 @@ def main():
# Start the main interactive command line
shell = InteractiveShell(
sessionsManager=sessionsManager,
config=config
config=config,
logger=logger
)
shell.run()

Expand Down
83 changes: 42 additions & 41 deletions smbclientng/core/CommandCompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,11 @@ class CommandCompleter(object):
},
}

def __init__(self, smbSession, config):
def __init__(self, smbSession, config, logger):
# Objects
self.smbSession = smbSession
self.config = config
self.logger = logger
# Pre computing for some commands
self.commands["help"]["subcommands"] = ["format"] + list(self.commands.keys())
self.commands["help"]["subcommands"].remove("help")
Expand Down Expand Up @@ -532,54 +533,54 @@ def print_help(self, command=None):
if command == "format":
self.print_help_format()
else:
print("│")
self.logger.print("│")
if self.config.no_colors:
command_str = command + "─"* (15 - len(command))
if len(self.commands[command]["description"]) == 0:
print("│ ■ %s┤ " % command_str)
self.logger.print("│ ■ %s┤ " % command_str)
elif len(self.commands[command]["description"]) == 1:
print("│ ■ %s┤ %s " % (command_str, self.commands[command]["description"][0]))
self.logger.print("│ ■ %s┤ %s " % (command_str, self.commands[command]["description"][0]))
else:
print("│ ■ %s┤ %s " % (command_str, self.commands[command]["description"][0]))
self.logger.print("│ ■ %s┤ %s " % (command_str, self.commands[command]["description"][0]))
for line in self.commands[command]["description"][1:]:
print("│ %s│ %s " % (" "*(15+2), line))
self.logger.print("│ %s│ %s " % (" "*(15+2), line))
else:
command_str = command + " \x1b[90m" + "─"* (15 - len(command)) + "\x1b[0m"
if len(self.commands[command]["description"]) == 0:
print("│ ■ %s\x1b[90m┤\x1b[0m " % command_str)
self.logger.print("│ ■ %s\x1b[90m┤\x1b[0m " % command_str)
elif len(self.commands[command]["description"]) == 1:
print("│ ■ %s\x1b[90m┤\x1b[0m %s " % (command_str, self.commands[command]["description"][0]))
self.logger.print("│ ■ %s\x1b[90m┤\x1b[0m %s " % (command_str, self.commands[command]["description"][0]))
else:
print("│ ■ %s\x1b[90m┤\x1b[0m %s " % (command_str, self.commands[command]["description"][0]))
self.logger.print("│ ■ %s\x1b[90m┤\x1b[0m %s " % (command_str, self.commands[command]["description"][0]))
for line in self.commands[command]["description"][1:]:
print("│ %s\x1b[90m│\x1b[0m %s " % (" "*(15+3), line))
print("│")
self.logger.print("│ %s\x1b[90m│\x1b[0m %s " % (" "*(15+3), line))
self.logger.print("│")
# Generic help
else:
print("│")
self.logger.print("│")
commands = sorted(self.commands.keys())
for command in commands:
if self.config.no_colors:
command_str = command + "─"* (15 - len(command))
if len(self.commands[command]["description"]) == 0:
print("│ ■ %s┤ " % command_str)
self.logger.print("│ ■ %s┤ " % command_str)
elif len(self.commands[command]["description"]) == 1:
print("│ ■ %s┤ %s " % (command_str, self.commands[command]["description"][0]))
self.logger.print("│ ■ %s┤ %s " % (command_str, self.commands[command]["description"][0]))
else:
print("│ ■ %s┤ %s " % (command_str, self.commands[command]["description"][0]))
self.logger.print("│ ■ %s┤ %s " % (command_str, self.commands[command]["description"][0]))
for line in self.commands[command]["description"][1:]:
print("│ %s│ %s " % (" "*(15+2), line))
self.logger.print("│ %s│ %s " % (" "*(15+2), line))
else:
command_str = command + " \x1b[90m" + "─"* (15 - len(command)) + "\x1b[0m"
if len(self.commands[command]["description"]) == 0:
print("│ ■ %s\x1b[90m┤\x1b[0m " % command_str)
self.logger.print("│ ■ %s\x1b[90m┤\x1b[0m " % command_str)
elif len(self.commands[command]["description"]) == 1:
print("│ ■ %s\x1b[90m┤\x1b[0m %s " % (command_str, self.commands[command]["description"][0]))
self.logger.print("│ ■ %s\x1b[90m┤\x1b[0m %s " % (command_str, self.commands[command]["description"][0]))
else:
print("│ ■ %s\x1b[90m┤\x1b[0m %s " % (command_str, self.commands[command]["description"][0]))
self.logger.print("│ ■ %s\x1b[90m┤\x1b[0m %s " % (command_str, self.commands[command]["description"][0]))
for line in self.commands[command]["description"][1:]:
print("│ %s\x1b[90m│\x1b[0m %s " % (" "*(15+3), line))
print("│")
self.logger.print("│ %s\x1b[90m│\x1b[0m %s " % (" "*(15+3), line))
self.logger.print("│")

def print_help_format(self):
"""
Expand All @@ -589,25 +590,25 @@ def print_help_format(self):
of each character in the file attribute string, such as whether a file is read-only, hidden, or a directory.
"""
if self.config.no_colors:
print("File attributes format:\n")
print("dachnrst")
print("│││││││└──> Temporary")
print("││││││└───> System")
print("│││││└────> Read-Only")
print("││││└─────> Normal")
print("│││└──────> Hidden")
print("││└───────> Compressed")
print("│└────────> Archived")
print("└─────────> Directory")
self.logger.print("File attributes format:\n")
self.logger.print("dachnrst")
self.logger.print("│││││││└──> Temporary")
self.logger.print("││││││└───> System")
self.logger.print("│││││└────> Read-Only")
self.logger.print("││││└─────> Normal")
self.logger.print("│││└──────> Hidden")
self.logger.print("││└───────> Compressed")
self.logger.print("│└────────> Archived")
self.logger.print("└─────────> Directory")
else:
print("File attributes format:\n")
print("dachnrst")
print("\x1b[90m│││││││└──>\x1b[0m Temporary")
print("\x1b[90m││││││└───>\x1b[0m System")
print("\x1b[90m│││││└────>\x1b[0m Read-Only")
print("\x1b[90m││││└─────>\x1b[0m Normal")
print("\x1b[90m│││└──────>\x1b[0m Hidden")
print("\x1b[90m││└───────>\x1b[0m Compressed")
print("\x1b[90m│└────────>\x1b[0m Archived")
print("\x1b[90m└─────────>\x1b[0m Directory")
self.logger.print("File attributes format:\n")
self.logger.print("dachnrst")
self.logger.print("\x1b[90m│││││││└──>\x1b[0m Temporary")
self.logger.print("\x1b[90m││││││└───>\x1b[0m System")
self.logger.print("\x1b[90m│││││└────>\x1b[0m Read-Only")
self.logger.print("\x1b[90m││││└─────>\x1b[0m Normal")
self.logger.print("\x1b[90m│││└──────>\x1b[0m Hidden")
self.logger.print("\x1b[90m││└───────>\x1b[0m Compressed")
self.logger.print("\x1b[90m│└────────>\x1b[0m Archived")
self.logger.print("\x1b[90m└─────────>\x1b[0m Directory")

Loading

0 comments on commit 34c9e3e

Please sign in to comment.