/
custom_file.go
64 lines (54 loc) · 1.2 KB
/
custom_file.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
package pkg
import (
"os"
"strconv"
"strings"
"github.com/sirupsen/logrus"
)
func ReadCustomPortFile(log *logrus.Logger) int {
if IsFile(customPort) == false {
return defPort
} else {
bytes, err := os.ReadFile(customPort)
if err != nil {
log.Errorln("ReadFile CustomPort Error", err)
log.Infoln("Use DefPort", defPort)
return defPort
}
atoi, err := strconv.Atoi(string(bytes))
if err != nil {
log.Errorln("Atoi CustomPort Error", err)
log.Infoln("Use DefPort", defPort)
return defPort
}
log.Infoln("Use CustomPort", atoi)
return atoi
}
}
func ReadCustomAuthFile(log *logrus.Logger) bool {
if IsFile(customAuth) == false {
return false
} else {
bytes, err := os.ReadFile(customAuth)
if err != nil {
log.Errorln("ReadFile CustomAuth Error", err)
return false
}
nowContent := string(bytes)
authStings := strings.Split(nowContent, "@@@@")
if len(authStings) != 3 {
log.Errorln("ReadFile CustomAuth Error", err)
return false
}
SetBaseKey(authStings[0])
SetAESKey16(authStings[1])
SetAESIv16(authStings[2])
log.Infoln("Use CustomAuth")
return true
}
}
const (
defPort = 19035
customPort = "CustomPort"
customAuth = "CustomAuth"
)