mirror of
https://github.com/moul/sshportal.git
synced 2025-09-06 12:44:35 +08:00
Show 'n/a' in case of missing information to avoid crashing.
This commit is contained in:
parent
ec1e4d5c8a
commit
47a6fc9906
1 changed files with 21 additions and 3 deletions
24
shell.go
24
shell.go
|
@ -1862,9 +1862,15 @@ GLOBAL OPTIONS:
|
|||
table.SetBorder(false)
|
||||
table.SetCaption(true, fmt.Sprintf("Total: %d userkeys.", len(userKeys)))
|
||||
for _, userkey := range userKeys {
|
||||
var email string
|
||||
if userkey.User != nil {
|
||||
email = userkey.User.Email
|
||||
} else {
|
||||
email = "n/a"
|
||||
}
|
||||
table.Append([]string{
|
||||
fmt.Sprintf("%d", userkey.ID),
|
||||
userkey.User.Email,
|
||||
email,
|
||||
// FIXME: add fingerprint
|
||||
humanize.Time(userkey.UpdatedAt),
|
||||
humanize.Time(userkey.CreatedAt),
|
||||
|
@ -1961,10 +1967,22 @@ GLOBAL OPTIONS:
|
|||
duration = humanize.RelTime(session.CreatedAt, *session.StoppedAt, "", "")
|
||||
}
|
||||
duration = strings.Replace(duration, "now", "1 second", 1)
|
||||
var hostname string
|
||||
if session.Host != nil {
|
||||
hostname = session.Host.Name
|
||||
} else {
|
||||
hostname = "n/a"
|
||||
}
|
||||
var username string
|
||||
if session.User != nil {
|
||||
username = session.User.Name
|
||||
} else {
|
||||
username = "n/a"
|
||||
}
|
||||
table.Append([]string{
|
||||
fmt.Sprintf("%d", session.ID),
|
||||
session.User.Name,
|
||||
session.Host.Name,
|
||||
username,
|
||||
hostname,
|
||||
session.Status,
|
||||
humanize.Time(session.CreatedAt),
|
||||
duration,
|
||||
|
|
Loading…
Add table
Reference in a new issue