This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
126 lines (98 loc) · 2.85 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
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
package main
import (
"fmt"
"log"
"os"
"os/exec"
"time"
)
func main() {
fmt.Println("restarting...")
//Reinstall sing box
_, err := exec.Command("/bin/sh", "./reinstall-sing-box.sh").Output()
if err != nil {
fmt.Printf("error make-subscribe %s", err)
}
fmt.Println("read setting file...")
//Read files
serverIP := GetOutboundIP().String()
//read configuration from setting file
setting, err := ReadSettingsFile()
if err != nil {
fmt.Printf("error read settings file %v ", err)
}
//todo read setting from config
var newReality RealityJson
fmt.Println("renew configuration...")
//renew existing reality json
StringConfigZero, StringConfigAll, newReality, SliceConfigAll := RenewConfigurations(setting, serverIP, newReality)
//block bad websites
newReality = Block(newReality)
//save new Reality in file
err = WriteFile("./reality.json", newReality)
if err != nil {
log.Fatal("error during the WriteFile")
}
var AggregateSubscriptionNameLink string
//aggregate subscriptions
if len(setting.AggregateSubscriptions) > 0 {
AggregateSubscriptionNameLink = AggregateSubscriptions(setting, StringConfigAll)
}
//make subscription
subscriptionNameLink, err := DoSubscribe(setting, StringConfigAll)
if err != nil {
fmt.Printf("error %s", err)
}
//call Telegram
if len(setting.BotToken) > 4 && len(setting.ChatID) > 4 {
if setting.SendConfiguration == "first" {
err = CallTelegram(StringConfigZero, setting)
if err != nil {
fmt.Printf("error %s", err)
}
} else if setting.SendConfiguration == "all" {
for _, currentConfig := range SliceConfigAll {
err = CallTelegram(currentConfig, setting)
if err != nil {
fmt.Printf("error %s", err)
}
time.Sleep(1 * time.Second)
}
}
if setting.SendSubscriptions {
if len(setting.AggregateSubscriptions) > 0 {
err = CallTelegram("Aggregate link is: \nhttp://"+serverIP+"/"+AggregateSubscriptionNameLink, setting)
if err != nil {
fmt.Printf("error %s", err)
}
} else {
err = CallTelegram("You can also use this link to subscribe to all configuration:\nhttp://"+serverIP+"/"+subscriptionNameLink, setting)
if err != nil {
fmt.Printf("error %s", err)
}
}
}
}
//call donate endpoint
if len(setting.DonateURL) > 4 {
if len(setting.AggregateSubscriptions) > 0 {
subscriptionNameLinkFull := "http://" + serverIP + "/" + AggregateSubscriptionNameLink
CallDonate(subscriptionNameLinkFull, setting)
} else {
subscriptionNameLinkFull := "http://" + serverIP + "/" + subscriptionNameLink
CallDonate(subscriptionNameLinkFull, setting)
}
}
//send vnstat file
if setting.SendVNstat {
logByte, err := os.ReadFile("./log.txt")
if err != nil {
fmt.Printf("error %s", err)
}
stringLogByte := string(logByte)
err = CallTelegram(stringLogByte, setting)
if err != nil {
fmt.Printf("error %s", err)
}
}
}