-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewer.go
157 lines (148 loc) · 4.1 KB
/
viewer.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/xlab/closer"
"gopkg.in/ini.v1"
)
func viewer(args ...string) {
var (
host string
)
defer closer.Close()
closer.Bind(cleanup)
ltf.Println(args)
li.Printf("\"%s\" {[:]host[::port]|[:]host[:display]|:id[:123456789]|:} [password]\n", args[0])
li.Println("On the other side may have been running - на другой стороне возможно был запущен")
switch {
case RportRFB == CportRFB:
li.Println("\t`ngrokVNC`")
case RportRFB != "":
li.Printf("\t`ngrokVNC ::%s`\n", RportRFB)
default:
li.Println("\t`ngrokVNC [::port]`")
}
if len(args) > 1 {
// host::port [password] as LAN viewer connect mode no crypt
// host[:display] [password] as LAN viewer connect mode crypt
// host as host: as host:0 as host:: as host::5900
host = abs(args[1])
if strings.HasPrefix(host, ":") {
// :host::port [password] as ngrok~proxy~IP viewer connect mode no crypt
// :host[:display] [password] as ngrok~proxy~IP viewer connect mode
// :id [password] as ngrok~proxy~ID viewer connect mode
// : [password] as ngrok viewer connect mode
proxy = host != ":" && errNgrokAPI == nil && VNC["name"] == "UltraVNC"
host = strings.TrimPrefix(host, ":")
}
}
via := []string{"LAN", "LAN"}
LAN := host != "" ||
// emulate LAN mode?
NGROK_AUTHTOKEN == ""
if LAN {
if !proxy {
if strings.Contains(host, "::") {
UseDSMPlugin = "0"
}
}
h, _, _ := hp(host, portRFB)
opts = append(opts, h)
}
if proxy || !LAN {
via = []string{"ngrok", "туннель"}
if proxy || rProxy {
if rProxy2 {
via = []string{"ngrok~proxy~ID", "туннель~прокси~ID"}
if host == "" {
opts = append(opts, "id:0")
}
} else {
via = []string{"ngrok~proxy~IP", "туннель~прокси~IP"}
if host == "" {
opts = append(opts, listen)
}
}
switch VNC["name"] {
case "UltraVNC":
opts = append(opts, "-proxy")
case "TurboVNC":
opts = append(opts, "-via")
}
}
if tcp == "" {
err = srcError(fmt.Errorf("no proxy to view - нет прокси для наблюдателя"))
} else {
opts = append(opts, tcp)
}
}
li.Printf("The VNC viewer connects to the waiting VNC server via %s - наблюдатель VNC подключается к ожидающему экрану VNC через %s\n", via[0], via[1])
if VNC["name"] == "UltraVNC" {
opts = options(opts)
}
if len(opts) < 1 {
err = srcError(fmt.Errorf("no host to view - нет адреса для наблюдателя"))
}
if err != nil {
return
}
if len(args) > 2 {
switch VNC["name"] {
case "TightVNC":
opts = append(opts, "-password="+args[2])
case "RealVNC":
default:
opts = append(opts, "-password")
opts = append(opts, args[2])
}
}
viewer := exec.Command(viewerExe, opts...)
viewer.Dir = filepath.Dir(viewer.Path)
viewer.Stdout = os.Stdout
viewer.Stderr = os.Stderr
closer.Bind(func() {
if viewer.Process != nil && viewer.ProcessState == nil {
PrintOk(cmd("Kill", viewer), viewer.Process.Kill())
}
})
processName = VNC["viewer"]
go watch(true)
li.Println(cmd("Run", viewer))
err = viewer.Run()
}
func cmd(s string, c *exec.Cmd) string {
if c == nil {
return ""
}
return fmt.Sprintf(`%s "%s" %s`, s, c.Args[0], strings.Join(c.Args[1:], " "))
}
func options(o []string) (opts []string) {
opts = o[:]
vnc := filepath.Join(VNC["path"], "options.vnc")
ini.PrettyFormat = false
iniFile, err := ini.Load(vnc)
if err == nil {
section := iniFile.Section("options")
ok := SetValue(section, "UseDSMPlugin", UseDSMPlugin)
ok = SetValue(section, "DSMPlugin", DSMPlugin) || ok
ok = SetValue(section, "RequireEncryption", UseDSMPlugin) || ok
ok = SetValue(section, "showtoolbar", "0") || ok
if ok {
err = iniFile.SaveTo(vnc)
if err != nil {
letf.Println("error write - ошибка записи", vnc)
}
}
} else {
opts = append(opts, "-noToolBar")
if UseDSMPlugin == "1" && DSMPlugin != "" {
opts = append(opts, "-DSMPlugin")
opts = append(opts, DSMPlugin)
}
letf.Println("error read - ошибка чтения", vnc)
}
return
}