-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.go
78 lines (67 loc) · 1.93 KB
/
auth.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
71
72
73
74
75
76
77
78
/*
Copyright (c) 2018 Rasmus Moorats (nns)
This file is part of iopshell.
iopshell is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
iopshell is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with iopshell. If not, see <https://www.gnu.org/licenses/>.
*/
package commands
import (
"fmt"
"github.com/nnsee/iopshell/internal/cmd"
"github.com/nnsee/iopshell/internal/setting"
)
var auth = cmd.Command{
Name: "auth",
UsageText: "auth [user [pass]]",
Description: "Authenticates as [user] with [pass]. If none are specified, uses the values from settings.\n" +
"\t\tIf only the user is specified, the shell prompts for a password.",
Action: authRun,
MinArg: 1,
MaxArg: 3,
}
func authRun(param []string) {
var user, pass string
switch len(param) {
case 0:
user, _ = setting.Vars.GetS("user")
pass, _ = setting.Vars.GetS("pass")
case 1:
user = param[0]
passb, err := setting.Vars.Instance.ReadPassword("Password: ")
if err != nil {
fmt.Println("Unable to read password")
return
}
pass = string(passb)
case 2:
user = param[0]
pass = param[1]
}
// Authenticating is just another call (but key needs to be zeroed out)
request := map[string]interface{}{
"jsonrpc": "2.0",
"id": setting.Vars.Conn.ID,
"method": "call",
"params": []interface{}{
"00000000000000000000000000000000",
"session",
"login",
map[string]interface{}{
"username": user,
"password": pass,
},
},
}
setting.Vars.Conn.Send(request)
}
func init() {
auth.Register()
}