forked from xiaokangwang/AndroidLibV2ray
-
Notifications
You must be signed in to change notification settings - Fork 12
/
rendercfg.go
88 lines (83 loc) · 1.83 KB
/
rendercfg.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
package libv2ray
import (
"io"
"io/ioutil"
"log"
"os"
"strings"
)
func (v *V2RayPoint) renderAll() {
v.renderesco()
v.renderptm()
v.rendervpn()
}
func (v *V2RayPoint) renderptm() {
envr0 := envToMap(v.getEnvironment())
mf0 := func(lookup string) string {
if envl0, ok := envr0[lookup]; ok {
return envl0
}
return ""
}
for _, r := range v.conf.rend {
for key2 := range r.Args {
r.Args[key2] = os.Expand(r.Args[key2], mf0)
}
mf := func(lookup string) string {
envr := envToMap(append(v.getEnvironment(), r.Args...))
if envl, ok := envr[lookup]; ok {
return envl
}
return ""
}
fs := os.Expand(r.Source, mf)
ft := os.Expand(r.Target, mf)
fds, err := os.Open(fs)
if err != nil {
log.Println(err, fs)
}
input, err := ioutil.ReadAll(fds)
if err != nil {
log.Println(err, fs, "RA")
}
inputs := string(input)
op := os.Expand(inputs, mf)
opn := strings.NewReader(op)
fdt, err := os.Create(ft)
if err != nil {
log.Println(err, ft)
}
_, err = io.Copy(fdt, opn)
if err != nil {
log.Println(err, ft, "CP")
}
}
}
func (v *V2RayPoint) renderesco() {
envr := envToMap(v.getEnvironment())
for key := range v.conf.esco {
mf := func(lookup string) string {
if envl, ok := envr[lookup]; ok {
return envl
}
return ""
}
v.conf.esco[key].Target = os.Expand(v.conf.esco[key].Target, mf)
for key2 := range v.conf.esco[key].Args {
v.conf.esco[key].Args[key2] = os.Expand(v.conf.esco[key].Args[key2], mf)
}
}
}
func (v *V2RayPoint) rendervpn() {
envr := envToMap(v.getEnvironment())
mf := func(lookup string) string {
if envl, ok := envr[lookup]; ok {
return envl
}
return ""
}
for key := range v.conf.vpnConfig.Args {
v.conf.vpnConfig.Args[key] = os.Expand(v.conf.vpnConfig.Args[key], mf)
}
v.conf.vpnConfig.Target = os.Expand(v.conf.vpnConfig.Target, mf)
}