-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
209 lines (161 loc) · 6.5 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//go:generate statik -src=./public -include=*.html,*.css,*.js,*.png,*.ico,*.woff,*.woff2,*.eot,*.ttf
package main
import (
"embed"
"encoding/json"
"flag"
"fmt"
"io/fs"
"io/ioutil"
"log"
"math/rand"
"net/http"
"time"
)
var (
addr *string
p = make(map[string]*Pwnagotchi)
//go:embed public
public embed.FS
)
// Pwnagotchi ...
type Pwnagotchi struct {
Fingerprint string `json:"fingerprint"`
Initialised bool `json:"initialised"`
Name string `json:"name,omitempty"`
Mode string `json:"mode,omitempty"`
Status string `json:"status,omitempty"`
Uptime string `json:"uptime,omitempty"`
Version string `json:"version,omitempty"`
Epoch int64 `json:"epoch,omitempty"`
APsOnChannel int64 `json:"aps_on_channel,omitempty"`
APsName string `json:"aps_text,omitempty"`
APsTotal int64 `json:"apt_tot,omitempty"`
Channel int64 `json:"channel,omitempty"`
ChannelName string `json:"channel_text,omitempty"`
Face string `json:"face,omitempty"`
FriendFace string `json:"friend_face_text,omitempty"`
FriendName string `json:"friend_name_text,omitempty"`
CPU float64 `json:"cpu,omitempty"`
Memory float64 `json:"memory,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
Bluetooth string `json:"bluetooth,omitempty"`
UPS string `json:"ups,omitempty"`
// "peers": [],
PeersCount int64 `json:"num_peers,omitempty"`
PwnedLast string `json:"pwnd_last,omitempty"`
PwnedRun string `json:"pwnd_run,omitempty"`
PwnedTotal int64 `json:"pwnd_tot,omitempty"`
PwnedDeauth string `json:"pwnd_deauth,omitempty"`
TotalMessages int64 `json:"total_messages,omitempty"`
UnreadMessages int64 `json:"unread_messages,omitempty"`
Level string `json:"level,omitempty"`
Exp string `json:"exp,omitempty"`
}
func main() {
addr = flag.String("addr", ":8080", "listen address")
flag.Parse()
http.Handle("/static/css/", http.StripPrefix("/static/css/", fsHandler("css")))
http.Handle("/static/favicon/", http.StripPrefix("/static/favicon/", fsHandler("favicon")))
http.Handle("/static/font/", http.StripPrefix("/static/font/", fsHandler("font")))
http.Handle("/static/js/", http.StripPrefix("/static/js/", fsHandler("js")))
http.Handle("/", fsHandler("html"))
http.HandleFunc("/api/get", apiGet)
http.HandleFunc("/api/set", apiSet)
log.Println("start listening on", *addr)
err := http.ListenAndServe(*addr, nil)
if err != nil {
log.Fatal("ListenAndServe:", err)
}
}
func fsHandler(subPath string) http.Handler {
sub, err := fs.Sub(public, "public/"+subPath)
if err != nil {
fmt.Println("file not found", err)
}
return http.FileServer(http.FS(sub))
}
func apiGet(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.NotFound(w, r)
return
}
hash := r.URL.Query().Get("hash")
w.Header().Set("Content-Type", "application/json")
if hash == "test" {
d := &Pwnagotchi{
Fingerprint: "",
Initialised: true,
Name: randomString([]string{"pwnagotchi", "username", "test", "pet", "cat", "dog"}),
Mode: randomString([]string{"AUTO", "MANU", "AI"}),
Status: randomString([]string{"...", "ololo", "blabla", "Связываюсь с 2020", "Эй, 2020 давай дружить!", "Ждем 5c …", "Хррррр.. (29c)", "Дремлет 19с …", "Осматриваюсь вокруг (3с)", "Просто решил, что 00:12:34:56:78:0a не нужен WiFi! Кхе-кхе)"}),
Uptime: randomString([]string{"00:00:01", "12:34:56", "23:45:00"}),
Version: "1.5.3",
Epoch: randomInt64([]int64{1, 2, 3, 10, 20, 300}),
APsOnChannel: randomInt64([]int64{1, 2, 3, 10, 20, 300}),
APsName: randomString([]string{"1 (1)", "2 (5)", "10 (100)"}),
APsTotal: randomInt64([]int64{1, 2, 3, 10, 20, 300}),
Channel: randomInt64([]int64{1, 2, 3, 10, 20, 300}),
ChannelName: randomString([]string{"*", "1", "11"}),
Face: randomString([]string{"(⇀‿‿↼)", "(≖‿‿≖)", "(◕‿‿◕)", "( ⚆_⚆)", "(☉_☉ )", "( ◕‿◕)", "(◕‿◕ )", "(°▃▃°)", "(⌐■_■)", "(•‿‿•)", "(^‿‿^)", "(ᵔ◡◡ᵔ)", "(✜‿‿✜)", "(♥‿‿♥)", "(☼‿‿☼)", "(≖__≖)", "(-__-)", "(╥☁╥ )", "(ب__ب)", "(☓‿‿☓)", "(#__#)"}),
FriendFace: randomString([]string{"(⇀‿‿↼)", "(≖‿‿≖)", "(◕‿‿◕)", "( ⚆_⚆)", "(☉_☉ )", "( ◕‿◕)", "(◕‿◕ )", "(°▃▃°)", "(⌐■_■)", "(•‿‿•)", "(^‿‿^)", "(ᵔ◡◡ᵔ)", "(✜‿‿✜)", "(♥‿‿♥)", "(☼‿‿☼)", "(≖__≖)", "(-__-)", "(╥☁╥ )", "(ب__ب)", "(☓‿‿☓)", "(#__#)"}),
FriendName: randomString([]string{"username", "test", "pet"}),
CPU: 0.5,
Memory: 0.5,
Temperature: 35.5,
Bluetooth: randomString([]string{"-", "C", "NF"}),
UPS: randomString([]string{"", "0%", "1%", "10%", "11%", "100%"}),
PeersCount: randomInt64([]int64{1, 2, 3, 10, 20, 300}),
PwnedLast: randomString([]string{"pwnagotchi", "username", "test", "pet", "cat", "dog"}),
PwnedRun: "2",
PwnedTotal: randomInt64([]int64{1, 2, 3, 10, 20, 300}),
PwnedDeauth: "4",
TotalMessages: randomInt64([]int64{1, 2, 3, 10, 20, 300}),
UnreadMessages: randomInt64([]int64{1, 2, 3, 10, 20, 300}),
Level: randomString([]string{"-", "1", "11", "50", "99"}),
Exp: randomString([]string{"╷ ╷", "╷▄ ╷", "╷▄▄ ╷", "╷▄▄▄ ╷", "╷▄▄▄▄ ╷", "╷▄▄▄▄▄ ╷", "╷▄▄▄▄▄▄ ╷", "╷▄▄▄▄▄▄▄ ╷", "╷▄▄▄▄▄▄▄▄ ╷", "╷▄▄▄▄▄▄▄▄▄▄╷"}),
}
b, _ := json.Marshal(d)
_, _ = w.Write(b)
return
}
notFound := `{"initialized": false}`
if d, ok := p[hash]; ok {
b, err := json.Marshal(d)
if err != nil {
_, _ = w.Write([]byte(notFound))
return
}
_, _ = w.Write(b)
return
}
_, _ = w.Write([]byte(notFound))
}
func apiSet(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.NotFound(w, r)
return
}
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Println(err)
}
var d Pwnagotchi
if err := json.Unmarshal(body, &d); err != nil {
log.Println(err)
} else {
if d.Fingerprint != "" {
p[d.Fingerprint] = &d
}
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"success": true}`))
}
func randomInt64(list []int64) int64 {
rand.Seed(time.Now().UnixNano())
return list[rand.Intn(len(list))]
}
func randomString(list []string) string {
rand.Seed(time.Now().UnixNano())
return list[rand.Intn(len(list))]
}