forked from tomatome/grdp
/
main.go
79 lines (68 loc) · 1.29 KB
/
main.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
79
// main.go
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
"strings"
"github.com/tomatome/grdp/glog"
)
var (
server bool
)
func init() {
glog.SetLevel(glog.INFO)
logger := log.New(os.Stdout, "", 0)
glog.SetLogger(logger)
}
func main() {
flag.BoolVar(&server, "s", false, "web server")
flag.Parse()
runtime.GOMAXPROCS(runtime.NumCPU())
//web example
if server {
socketIO()
} else {
//client example
StartUI(1520, 1080)
}
}
type Screen struct {
Height int `json:"height"`
Width int `json:"width"`
}
type Info struct {
Domain string `json:"domain"`
Ip string `json:"ip"`
Port string `json:"port"`
Username string `json:"username"`
Passwd string `json:"password"`
Screen `json:"screen"`
}
func NewInfo(ip, user, passwd string) (error, *Info) {
var i Info
if ip == "" || user == "" || passwd == "" {
return fmt.Errorf("Must ip/user/passwd"), nil
}
t := strings.Split(ip, ":")
i.Ip = t[0]
i.Port = "3389"
if len(t) > 1 {
i.Port = t[1]
}
if strings.Index(user, "\\") != -1 {
t = strings.Split(user, "\\")
i.Domain = t[0]
i.Username = t[len(t)-1]
} else if strings.Index(user, "/") != -1 {
t = strings.Split(user, "/")
i.Domain = t[0]
i.Username = t[len(t)-1]
} else {
i.Username = user
}
i.Passwd = passwd
return nil, &i
}