-
Notifications
You must be signed in to change notification settings - Fork 0
/
authcenter.go
170 lines (164 loc) · 4.46 KB
/
authcenter.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
158
159
160
161
162
163
164
165
166
167
168
169
170
package main
import (
"bufio"
"fmt"
"github.com/gin-gonic/gin"
"gopkg.in/olahol/melody.v1"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"reflect"
"strings"
)
func GetPic() string {
fileIn, fileInErr := os.Open("pic")
if fileInErr != nil {
fmt.Println("pic save err")
}
defer fileIn.Close()
finReader := bufio.NewReader(fileIn)
inputString, _ := finReader.ReadString('\n')
newString := strings.Replace(inputString, "\n", "", -1)
return newString
}
func Killip() string {
fileIn, fileInErr := os.Open("killip")
if fileInErr != nil {
fmt.Println("killhostiderror")
}
defer fileIn.Close()
finReader := bufio.NewReader(fileIn)
inputString, _ := finReader.ReadString('\n')
newString := strings.Replace(inputString, "\n", "", -1)
return newString
}
func Allkill() string {
fileIn, fileInErr := os.Open("allkill")
if fileInErr != nil {
fmt.Println("allkillerror")
}
defer fileIn.Close()
finReader := bufio.NewReader(fileIn)
inputString, _ := finReader.ReadString('\n')
newString := strings.Replace(inputString, "\n", "", -1)
return newString
}
func getContent() []string {
fileIn, fileInErr := os.Open("text")
if fileInErr != nil {
fmt.Println("get auth order error")
}
defer fileIn.Close()
finReader := bufio.NewReader(fileIn)
var fileList []string
for {
inputString, readerError := finReader.ReadString('\n')
if readerError == io.EOF {
break
}
fileList = append(fileList, strings.Replace(inputString, "\n", "", -1))
}
return fileList
}
func getIp() string {
fileIn, fileInErr := os.Open("ip")
if fileInErr != nil {
fmt.Println("get dynamic ip error")
}
defer fileIn.Close()
finReader := bufio.NewReader(fileIn)
inputString, _ := finReader.ReadString('\n')
newString := strings.Replace(inputString, "\n", "", -1)
return newString
}
func Contain(obj interface{}, target interface{}) (bool, error) {
targetValue := reflect.ValueOf(target)
switch reflect.TypeOf(target).Kind() {
case reflect.Slice, reflect.Array:
for i := 0; i < targetValue.Len(); i++ {
if targetValue.Index(i).Interface() == obj {
return true, nil
}
}
case reflect.Map:
if targetValue.MapIndex(reflect.ValueOf(obj)).IsValid() {
return true, nil
}
}
return false, fmt.Errorf("not in array")
}
func main() {
gin.DisableConsoleColor()
f, _ := os.Create("gin.log")
gin.DefaultWriter = io.MultiWriter(f)
r := gin.Default()
m := melody.New()
r.POST("/auth", func(c *gin.Context) {
list := getContent()
ip := getIp()
message := c.PostForm("name")
ext := c.PostForm("ext")
auth := c.PostForm("auth")
log.Println(auth, ext)
_, error := Contain(message, list)
if error != nil {
c.JSON(http.StatusOK, gin.H{"msg": "授权失败,联系开发者付款", "code": -1})
return
}
c.JSON(http.StatusOK, gin.H{"msg": "认证通过", "code": 0, "remote": ip})
})
r.POST("/killip", func(c *gin.Context) {
t := c.PostForm("killip")
err := ioutil.WriteFile("killip", []byte(t), 0644)
if err != nil {
fmt.Errorf("killip保存失败: %s", err)
}
c.JSON(http.StatusOK, gin.H{"msg": "杀掉IP", "code": 0, "remote": t})
})
r.POST("/allkill", func(c *gin.Context) {
t := c.PostForm("allkill")
err := ioutil.WriteFile("allkill", []byte(t), 0644)
if err != nil {
fmt.Errorf("allkill保存失败: %s", err)
}
c.JSON(http.StatusOK, gin.H{"msg": "allkill", "code": 0, "remote": t})
})
r.POST("/save", func(c *gin.Context) {
t := c.PostForm("ip")
err := ioutil.WriteFile("ip", []byte(t), 0644)
if err != nil {
fmt.Errorf("保存配置到文件出错: %s", err)
}
c.JSON(http.StatusOK, gin.H{"msg": "认证通过", "code": 0, "remote": t})
})
r.POST("/PIC", func(c *gin.Context) {
t := c.PostForm("picip")
err := ioutil.WriteFile("pic", []byte(t), 0644)
if err != nil {
fmt.Errorf("保存配置到文件出错: %s", err)
}
c.JSON(http.StatusOK, gin.H{"msg": "认证通过", "code": 0, "remote": t})
})
r.GET("/getpic", func(c *gin.Context) {
status := GetPic()
c.JSON(http.StatusOK, gin.H{"msg": "认证通过", "code": 0, "hostid": status})
})
r.GET("/Killip", func(c *gin.Context) {
status := Killip()
c.JSON(http.StatusOK, gin.H{"msg": "认证通过", "code": 0, "hostid": status})
})
r.GET("/Allkill", func(c *gin.Context) {
status := Allkill()
c.JSON(http.StatusOK, gin.H{"msg": "认证通过", "code": 0, "hostid": status})
})
r.GET("/", func(c *gin.Context) {
m.HandleRequest(c.Writer, c.Request)
})
m.HandleMessage(func(s *melody.Session, msg []byte) {
//fmt.Println(len(msg))
m.Broadcast(msg)
})
r.Run(":9000")
}