/
telnet.go
74 lines (61 loc) · 1.39 KB
/
telnet.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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package broadcom
import (
"3e8.eu/go/dsl"
"3e8.eu/go/dsl/internal/telnet"
"3e8.eu/go/dsl/models"
)
type telnetClient struct {
command string
client *telnet.Client
rawData []byte
status models.Status
bins models.Bins
}
func NewTelnetClient(config TelnetConfig) (dsl.Client, error) {
c := telnetClient{}
c.command = config.Command
var err error
user := config.User
if user == "" {
user = "root"
}
clientConfig := telnet.ClientConfig{
Prompts: []telnet.Prompts{
telnet.Prompts{
Account: "login: ",
Password: "Password: ",
Command: "# ",
},
// Billion
telnet.Prompts{
Account: "Login: ",
Password: "Password: ",
Command: "> ",
},
},
}
c.client, err = telnet.NewClient(clientConfig, config.Host, user, config.Password)
if err != nil {
return nil, err
}
return &c, nil
}
func (c *telnetClient) RawData() []byte {
return c.rawData
}
func (c *telnetClient) Status() models.Status {
return c.status
}
func (c *telnetClient) Bins() models.Bins {
return c.bins
}
func (c *telnetClient) UpdateData() (err error) {
c.status, c.bins, c.rawData, err = updateData(c.client, c.command)
return
}
func (c *telnetClient) Close() {
c.client.Close()
}