-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
61 lines (49 loc) · 1.34 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"encoding/json"
"github.com/MatthieuLeboeuf/bitwarden-ssh-manager/backend"
"github.com/spf13/viper"
"os/exec"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
func (a *App) GetEmail() string {
return viper.GetString("vault.email")
}
func (a *App) IsLogged() bool {
return backend.GlobalData.AccessToken != ""
}
// Login return true if two-factor authentication is required
func (a *App) Login(password string, otpCode int, otpRemember bool) int {
// Get access token to backend
backend.PreLogin()
return backend.Login(password, otpCode, otpRemember)
}
func (a *App) Sync() string {
// Sync data
return backend.Sync()
}
func (a *App) LaunchTerminal(data string) {
host := &backend.FrontendHost{}
json.Unmarshal([]byte(data), &host)
var command string
if host.Password == "" {
command = "ssh " + host.Username + "@" + host.Host + " -p " + host.Port
} else {
command = "sshpass -p " + host.Password + " ssh " + host.Username + "@" + host.Host + " -p " + host.Port
}
cmd := exec.Command("gnome-terminal", "-e", command, "-t", host.Name)
_ = cmd.Run()
}