-
Notifications
You must be signed in to change notification settings - Fork 8
/
generate.go
68 lines (63 loc) · 1.93 KB
/
generate.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
package utils
import (
"encoding/json"
"fmt"
"os"
C "github.com/ArchiveNetwork/wgcf-cli/constant"
)
func GenXray(resStruct C.Response) (body []byte, err error) {
in_struct := C.Xray{
Protocol: "wireguard",
Settings: struct {
SecretKey string `json:"secretKey"`
Address []string `json:"address"`
Peers []struct {
PublicKey string `json:"publicKey"`
AllowedIPs []string `json:"allowedIPs"`
Endpoint string `json:"endpoint"`
} `json:"peers"`
Reserved []int `json:"reserved"`
MTU int `json:"mtu"`
}{
SecretKey: resStruct.Config.PrivateKey,
Address: []string{resStruct.Config.Interface.Addresses.V4 + "/32", resStruct.Config.Interface.Addresses.V6 + "/128"},
Peers: []struct {
PublicKey string `json:"publicKey"`
AllowedIPs []string `json:"allowedIPs"`
Endpoint string `json:"endpoint"`
}{
{
PublicKey: "bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=",
AllowedIPs: []string{"0.0.0.0/0", "::/0"},
Endpoint: resStruct.Config.Peers[0].Endpoint.Host,
},
},
Reserved: resStruct.Config.ReservedDec,
MTU: 1280,
},
Tag: "wireguard",
}
if body, err = json.MarshalIndent(in_struct, "", " "); err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
return
}
func GenSing(resStruct C.Response) (body []byte, err error) {
in_struct := C.Sing{
Type: "wireguard",
Tag: "wireguard-out",
Server: resStruct.Config.Peers[0].Endpoint.Host,
ServerPort: 2408,
LocalAddress: []string{resStruct.Config.Interface.Addresses.V4 + "/32", resStruct.Config.Interface.Addresses.V6 + "/128"},
PrivateKey: resStruct.Config.PrivateKey,
PeerPublicKey: "bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=",
Reserved: resStruct.Config.ClientID,
MTU: 1280,
}
if body, err = json.MarshalIndent(in_struct, "", " "); err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
return
}