Ejemplo n.º 1
0
def refresh_screen(screen, selection, main_win=None):
    """Refreshes the GUI elements of the main screen"""
    y, x = screen.getmaxyx()
    main_x = x - (x / 4)
    main_y = len(conf.get('vaults')) + 5
    if y < main_y or x < main_x:
        problems("screen too small")

    screen.border()
    screen.bkgd(ord(' '), curses.color_pair(1))

    middle_y, middle_x = middle_yx(screen)
    if not main_win:
        main_win = curses.newwin(main_y, main_x,
                                 int(round(middle_y - (main_y/2))),
                                 int(round(middle_x - (main_x/2))))
    else:
        main_win.erase()

    main_win.bkgd(ord(' '), curses.color_pair(1))
    main_win.border()
    string_at(main_win, 1, 0, conf.get("title", "Vault Friends"),
              curses.color_pair(1), 'center')
    refresh_status(main_win, selection)
    screen.nooutrefresh()
    main_win.nooutrefresh()
    curses.doupdate()
    return main_win
Ejemplo n.º 2
0
def refresh_offline(main_win, server, selected, index):
    """Refreshes the label for a offline Vault instance"""
    y, x = main_win.getmaxyx()
    name = server['name']
    name_msg = "[%s] %s" % (index, name)
    base_x = len(name_msg) + 1
    new_msg = 'AWOL'
    line = index + 3
    col = curses.color_pair(1)
    if selected:
        col = curses.color_pair(6)

    string_at(main_win, line, 0, name_msg, col)
    string_at(main_win, line, base_x,
              new_msg, curses.color_pair(3) | curses.A_BOLD)
Ejemplo n.º 3
0
def refresh_initialized(main_win, server, index, selected):
    """Refreshes the lable for a initialized Vault instance"""
    y, x = main_win.getmaxyx()
    name = server['name']
    if server['init'] and \
       ('sealed' in server and not server['sealed']) and \
       ('ha' in server and server['ha']):
        c_state = 'S'
        if server['leader']:
            c_state = 'L'

        name = "%s [%s %s]" % (server['name'], c_state, server['cluster_name'])

    name_msg = "[%s] %s" % (index, name)
    base_x = len(name_msg) + 1
    line = index + 3
    col = curses.color_pair(1)
    if selected:
        col = curses.color_pair(6)

    string_at(main_win, line, 0, name_msg, col)
    if server['sealed']:
        s_msg = "Sealed"
        string_at(main_win, line, base_x, s_msg, curses.color_pair(3))
    else:
        s_msg = 'OK'
        s_col = 2
        if server['rekey']:
            s_msg = 'REKEY'
            s_col = 7

        string_at(main_win, line, base_x, s_msg, curses.color_pair(s_col))
Ejemplo n.º 4
0
def refresh_uninitialized(main_win, server, selected, index):
    """Refreshes the label for a uninitialized Vault instance"""
    y, x = main_win.getmaxyx()
    name = server['name']
    name_msg = "[%s] %s" % (index, name)
    base_x = len(name_msg) + 1
    new_msg = 'NEW'
    line = index + 3
    col = curses.color_pair(1)
    if selected:
        col = curses.color_pair(6)

    string_at(main_win, line, 0, name_msg, col)
    string_at(main_win, line,
              base_x, new_msg,
              curses.color_pair(7) | curses.A_BOLD)
    s_anim = ['*', 'o', '.', '^', '_', '-', '|']

    for f in range(0, 5):
        string_at(main_win,
                  line,
                  base_x + len(new_msg) + 2 + f,
                  s_anim[SystemRandom().randint(0, len(s_anim) - 1)],
                  curses.color_pair(randcolor()))
Ejemplo n.º 5
0
def refresh_controls(win, server):
    """Refresh our visible controls. This varies based on server state
    and authentication"""
    esc_msg = '[ESC] Quit'
    seal_msg = '[s]eal'
    unseal_msg = '[u]nseal'
    init_msg = '[i]nit'
    rekey_msg = '[r]ekey'
    cancel_msg = '[c]ancel'
    enter_msg = '[e]nter'
    rotate_msg = 'r[o]tate'
    regen_msg = "re[g]en"
    step_msg = 'ste[p]'

    line = win.getmaxyx()[0] - 2
    string_at(win, line, 0, esc_msg, curses.color_pair(1))
    next_x = len(esc_msg) + 2
    if 'init' in server:
        if not server['init']:
            string_at(win, line, next_x, init_msg, curses.color_pair(3))
        else:
            if server['sealed']:
                string_at(win, line, next_x, unseal_msg, curses.color_pair(1))
            else:
                if (not server['ha'] or (server['ha'] and server['leader'])) \
                   and (server['rekey'] or server['regenerating']):
                    string_at(win, line, next_x,
                              cancel_msg, curses.color_pair(7))
                    string_at(win, line,
                              next_x + len(cancel_msg) + 1,
                              enter_msg, curses.color_pair(1))
                else:
                    if server['is_root']:
                        if not server['ha'] or \
                           (server['ha'] and server['leader']):
                            string_at(win, line, next_x,
                                      seal_msg, curses.color_pair(3))
                            string_at(win, line,
                                      next_x + len(seal_msg) + 1,
                                      rekey_msg, curses.color_pair(1))
                            string_at(win, line,
                                      next_x + len(seal_msg) +
                                      len(rekey_msg) + 2,
                                      rotate_msg, curses.color_pair(1))
                            string_at(win, line,
                                      next_x + len(seal_msg) + len(rekey_msg) +
                                      len(rotate_msg) + 3,
                                      regen_msg, curses.color_pair(1))

                        if server['ha'] and server['leader']:
                            string_at(win, line,
                                      next_x + len(seal_msg) + len(rekey_msg) +
                                      len(rotate_msg) + len(regen_msg) + 4,
                                      step_msg, curses.color_pair(1))
                    else:
                        string_at(win, line, next_x,
                                  rekey_msg, curses.color_pair(1))
                        string_at(win, line,
                                  next_x + len(rekey_msg) + 2,
                                  regen_msg, curses.color_pair(1))
Ejemplo n.º 6
0
def refresh_focused(screen, server):
    """Redraw the focus/detail view of a Vault instance"""
    win_x = 30 + len(server['url'])
    win_y = 10
    middle_y, middle_x = middle_yx(screen)
    win = curses.newwin(win_y, win_x,
                        middle_y - (win_y / 2),
                        middle_x - (win_x / 2))
    win.border()
    win.bkgd(ord(' '), curses.color_pair(1))
    string_at(win, 1, 0, server['name'], curses.color_pair(1), 'center')
    string_at(win, 2, 0, server['url'], curses.color_pair(1))
    if 'init' in server:
        if server['init']:
            string_at(win, 3, 0, server['version'], curses.color_pair(1))
            if server['sealed']:
                msg_s = 'SEALED'
                string_at(win, 5, 0, msg_s,
                          curses.color_pair(3) | curses.A_BOLD)
                unseal_remaining = server['unseal_required'] \
                                   - server['unseal_progress']
                msg_details = "%s keys required" % (unseal_remaining)
                string_at(win, 5, len(msg_s) + 1,
                          msg_details, curses.color_pair(1))
            else:
                msg_s = ''
                if server['rekey']:
                    msg_s = 'REKEY'
                    string_at(win, 5, 0,
                              msg_s, curses.color_pair(7))
                    rekey_remaining = server['rekey_required'] \
                                      - server['rekey_progress']
                    string_at(win, 6, 0,
                              "%s keys required" % (rekey_remaining),
                              curses.color_pair(1))
                elif (not server['ha'] or (server['ha'] and server['leader'])) \
                     and server['regenerating']:
                    msg_s = 'REGEN'
                    string_at(win, 5, 0,
                              msg_s, curses.color_pair(7))
                    string_at(win, 6, 0,
                              "%s keys required" %
                              (server['regen_required'] - server['regen_progress']),
                              curses.color_pair(1))
                else:
                    msg_s = 'OK'
                    string_at(win, 5, 0, msg_s, curses.color_pair(2))
                    if 'key_term' in server:
                        string_at(win, 6, 0,
                                  "Key Term %s" % server['key_term'],
                                  curses.color_pair(1))

                ha_msg = "HA"
                if server['ha']:
                    string_at(win, 5, len(msg_s) + 1,
                              ha_msg, curses.color_pair(1))
                    if server['leader']:
                        string_at(win, 5,
                                  len(msg_s) + len(ha_msg) +
                                  len(server['cluster_name']) + 3,
                                  "Leader", curses.color_pair(1))
                    else:
                        string_at(win, 5,
                                  len(msg_s) + len(ha_msg) +
                                  len(server['cluster_name']) + 3,
                                  "Standby", curses.color_pair(1))
                else:
                    ha_msg = ''

                string_at(win, 5,
                          len(ha_msg) + len(msg_s) + 2,
                          server['cluster_name'], curses.color_pair(1))
        else:
            string_at(win, 5, 0, "Uninitialized Vault", curses.color_pair(1))
    else:
        string_at(win, 4, 0,
                  'OFFLINE', curses.color_pair(3) | curses.A_BOLD, 'center')

    win.hline(win_y - 3, 1, curses.ACS_HLINE, win_x - 2)
    refresh_controls(win, server)
    win.refresh()