Skip to content

Commit

Permalink
encoding output utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
lexndru committed Aug 31, 2018
1 parent 5dad1b4 commit e644947
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
43 changes: 15 additions & 28 deletions unlocker/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def print_page(content): stdout.write(content)
{user}@{host}:{port}
"""
""".encode("utf-8")

UPDATE_TEMPLATE = u"""
Secrets successfully updated!
{user}@{host}:{port}
"""
""".encode("utf-8")

REMOVE_TEMPLATE = u"""
Permanently removed secret {auth_type} for {host}!
Expand All @@ -54,22 +54,22 @@ def print_page(content): stdout.write(content)
{user}@{ipv4}:{port} \x1b[0;37;47m{passkey}\x1b[0m
"""
""".encode("utf-8")

LOOKUP_TEMPLATE = u"""
Secret {auth_type} for {host}
{user}@{ipv4}:{port} \x1b[0;37;47m{passkey}\x1b[0m
"""
""".encode("utf-8")

VERTICAL_LIST_TEMPLATE = u"""
{nr:>4}) {name} ({sig}{jump_server})
Hostname: {host}
IPv4: {ip}
Port: {port} ({proto})
User: {user}
"""
""".encode("utf-8")


class Display(object):
Expand Down Expand Up @@ -228,7 +228,7 @@ def show_list_view(cls, rows, column, exclude, vertical, **kwargs):
max_user_len = len(auth.get_user())
records.append({
"auth_sig": auth.signature(),
"jump_sig": jump.signature() if jump is not None else "self",
"jump_sig": jump.signature() if jump is not None else "~",
"ip4": auth.get_host_ip4(),
"port": auth.get_port(),
"user": auth.get_user(),
Expand All @@ -241,9 +241,11 @@ def show_list_view(cls, rows, column, exclude, vertical, **kwargs):
line.append("{host:^%s}" % max_host_len)
line.append("{user:^%s}" % max_user_len)
line.append("{name:^%s}" % max_name_len)
line_tpl = u" {auth_sig:^10} | {jump_sig:^10} %s " + u" | ".join(line)
content = [cls.bind_params(line_tpl).format(**headers)]
separator = {
tpl = u" {auth_sig:^10} | {jump_sig:^10} | " + u" | ".join(line)
line_tpl = tpl.encode("utf-8")
content = [line_tpl.format(**headers)]
separator = {}
counters = {
"auth_sig": 10,
"jump_sig": 10,
"ip4": 15,
Expand All @@ -253,31 +255,16 @@ def show_list_view(cls, rows, column, exclude, vertical, **kwargs):
"name": max_name_len,
"host": max_host_len
}
for k, v in separator.iteritems():
separator[k] = str(v * "=")
content.append(cls.bind_params(line_tpl).format(**separator))
for k, v in counters.iteritems():
separator[k] = unicode(v * "=")
content.append(line_tpl.format(**separator))
for record in records:
row = cls.bind_params(line_tpl, record.get("jump"))
content.append(row.format(**record))
content.append(line_tpl.format(**record))
content.append(cls.LINE_SEPARATOR)
if len(records) == 0:
content = ["Nothing to display... try \"append\" or \"update\""]
cls.show(content)

@classmethod
def bind_params(cls, line_template, subparam=False):
"""Helper function to draw a special char for servers using tunnels.
Args:
line_template (str): Template string to format.
subparam (bool): Whether to draw special char or not.
Returns:
str: Template string to be formated.
"""

return line_template % "|"

@classmethod
def show_dump(cls, passkey_dump):
"""Vulnerable passkey dump to stdout.
Expand Down
4 changes: 3 additions & 1 deletion unlocker/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ def call_read_only_list_option(self, *args, **kwargs):
continue
jump_index = indexes.get(jump.signature(), -1)
if jump_index > -1:
sorted_hosts.insert(jump_index+1, known_hosts.pop(0))
if jump_index == 0:
jump_index += 1
sorted_hosts.insert(jump_index, known_hosts.pop(0))
continue
known_hosts.insert(len(known_hosts), known_hosts.pop(0))
Log.debug("Sorted all known hosts and now preparing to print out...")
Expand Down

0 comments on commit e644947

Please sign in to comment.