Repository navigation
Expand file tree
/
Copy pathbloomsearch.go
More file actions
230 lines (201 loc) · 5.76 KB
/
Copy pathbloomsearch.go
File metadata and controls
230 lines (201 loc) · 5.76 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
//"strconv"
//"time"
)
/* URLS:
/api/user/122434/ -- get user details (BloomSkyUser)
/api/skydevice/find_me/?name= -- search for device via name
/api/skydevice/find_me/?all=test -- returns all devices???
/api/user/122434/ -- show user details
*/
var bloomskyToken string = ""
var bloomUsername string = ""
var bloomPassword string = ""
var searchTerm string = ""
type BloomSkyDeviceData struct {
Temperature float32
seaLevelPressure_inch string
FWVersion2 string
FWVersion1 string
UV_level int
isOffline string
Dewpoint float32
TS int
Rain bool
night bool
Pressure_inch float32
seaLevelPressure string
ImageURL string
Humidity int
Dewpoint_f float32
DeviceType string
Battery_level int
Luminance int
UV_level_max int
ThirdPartyUV int
Temperature_f float32
Voltage int
UVIndex int
}
type BloomSkySearchForDeviceName struct {
Count int
Previous string
Next string
Results []BloomSkyDeviceDetails
}
type BloomSkyDeviceUser struct {
Username string
Country string
Userid int
DeviceID string
Nickname string
Id int
}
type BloomSkyDeviceDetails struct {
C_or_F bool
Distance int
AccessoryType string
BatteryNotification bool
CityName string
Following_User []BloomSkyDeviceUser
VideoList_C []string
PreviewImageList []string
DeviceName string
RainNotification bool
FullAddress string
RegisterTime int
forecast int
NumOfFollowers int
Data BloomSkyDeviceData
UTC int
LON float64
DST int
Owner string
is_newzealand string
DeviceID string
BoundedStorm string
Searchable bool
LAT float64
ALT float32
StreetName string
}
type BloomSkyUser struct {
username string
email string
cellphone_UDID string
cellphone_OS string
app_version string
cellphone_token string
cellphone_location_lon string
cellphone_location_lat string
cellphone_timezone string
cellphone_dst string
c_or_f string
registration_time string
avatar string
country string
nickname string
login_type string
id string
b_or_h string
m_or_km string
tl_notify string
followed_devices string
owned_devices string
location string
bio string
android_token_44 string
}
type BloomSkySearchData struct {
Temperature string
ImageURL string
TS string
WindSpeed string
Temperature_f string
WindDirection string
}
type BloomSkySearchDevice struct {
DeviceName string
UTC string
DST string
LON string
DeviceID string
LAT string
FullAddress string
Data BloomSkySearchData
}
func main() {
if len(os.Args) < 4 {
fmt.Printf(`bloomsearch <username> <password> <searchterm>
username - Your bloomsky username
password - Your bloomsky password
searchTerm - Bloomsky you are searching for
`)
os.Exit(2)
}
bloomUsername = os.Args[1]
bloomPassword = os.Args[2]
searchTerm = os.Args[3]
if loginAndGetToken() {
fmt.Println("Got Auth Token, searching for", searchTerm)
findDevices(searchTerm)
} else {
fmt.Println("[!] Invalid username and password")
}
}
func findDevices(searchterm string) {
url := "https://bskybackend.bloomsky.com/api/skydevice/find_me/?name=" + searchterm // this searches for a name
//url := "https://bskybackend.bloomsky.com/api/skydevice/find_me/?all=test" // this returns all devices? wtf. Needs BloomSkySearchDevice struct
fmt.Println("Making API request to", url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Println("[!] Could not make API request", err)
os.Exit(2)
}
req.Header.Set("Authorization", "Token "+bloomskyToken)
fmt.Println("Token " + bloomskyToken)
client := &http.Client{}
resp, _ := client.Do(req)
body, _ := ioutil.ReadAll(resp.Body)
var bloomSkySearchResults BloomSkySearchForDeviceName
err = json.Unmarshal(body, &bloomSkySearchResults)
if err != nil {
fmt.Println(err.Error())
}
bloomResults := bloomSkySearchResults.Results
fmt.Printf("%-40s | %-25s | %s \n", "Device Name", "Device ID", "Street Name")
fmt.Printf("%-40s | %-25s | %s \n", "-----------", "---------", "-----------")
for k, _ := range bloomResults {
fmt.Printf("%-40s | %-25s | %s \n", bloomResults[k].DeviceName, bloomResults[k].DeviceID, bloomResults[k].StreetName)
}
}
func loginAndGetToken() bool {
message := map[string]interface{}{
"username": bloomUsername,
"password": bloomPassword,
}
bytesRepresentation, err := json.Marshal(message)
if err != nil {
log.Fatalln(err)
}
resp, err := http.Post("https://bskybackend.bloomsky.com/auth/login/", "application/json", bytes.NewBuffer(bytesRepresentation))
if err != nil {
log.Fatalln(err)
}
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
tokenValue, ok := result["auth_token"]
if ok {
bloomskyToken = fmt.Sprintf("%v", tokenValue)
return true
}
return false
}