-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselfDisableTOTP.go
70 lines (54 loc) · 1.76 KB
/
selfDisableTOTP.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
62
63
64
65
66
67
68
69
70
package cmd
import (
"fmt"
"os/exec"
"github.com/inpher/sb/internal/commands"
"github.com/inpher/sb/internal/helpers"
"github.com/inpher/sb/internal/models"
"github.com/fatih/color"
)
// SelfDisableTOTP describes the selfDisableTOTP command
type SelfDisableTOTP struct{}
func init() {
commands.RegisterCommand("self totp disable", func() (c commands.Command, r models.Right, helper helpers.Helper, args map[string]commands.Argument) {
return new(SelfDisableTOTP), models.Public, helpers.Helper{
Header: "disable TOTP on the account",
Usage: "self totp disable",
Description: "disable TOTP on the account",
Aliases: []string{"selfDisableTOTP"},
}, map[string]commands.Argument{}
})
}
// Checks checks whether or not the user can execute this method
func (c *SelfDisableTOTP) Checks(ct *commands.Context) error {
// We're building on top of pam_google_authenticator, let's check the server is setup correctly
_, err := exec.LookPath("google-authenticator")
if err != nil {
return fmt.Errorf("the server is not configured for TOTP")
}
return nil
}
// Execute executes the command
func (c *SelfDisableTOTP) Execute(ct *commands.Context) (repl models.ReplicationData, cmdError error, err error) {
repl = models.ReplicationData{
"account": ct.User.User.Username,
}
err = c.Replicate(repl)
return
}
func (c *SelfDisableTOTP) PostExecute(repl models.ReplicationData) (err error) {
return
}
func (c *SelfDisableTOTP) Replicate(repl models.ReplicationData) (err error) {
user, err := models.LoadUser(repl["account"])
if err != nil {
return
}
err = user.RemoveTOTPSecret()
if err != nil {
return
}
green := color.New(color.FgGreen).SprintFunc()
fmt.Printf("%s\n", green("TOTP was successfully deactivated on your account!"))
return
}