-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFbxAPI.h
More file actions
282 lines (239 loc) · 8.46 KB
/
Copy pathFbxAPI.h
File metadata and controls
282 lines (239 loc) · 8.46 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*********************************************************************
RainFbx - Rainmeter Plugin for Freebox API
Copyright (C) 2016 - Christophe Lampin
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************/
#include <Windows.h>
#include "RainmeterAPI.h"
#include <WinCrypt.h>
#include <comdef.h>
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <cpprest/json.h>
#include <string>
#include <map>
#include <iostream>
#include <typeinfo>
#include <intsafe.h>
#include <pplcancellation_token.h>
using namespace std;
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
using namespace concurrency::streams; // Asynchronous streams
using namespace web::json; // JSON library
using namespace utility;
#ifndef CALG_HMAC
#define CALG_HMAC (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
#endif
#ifndef CRYPT_IPSEC_HMAC_KEY
#define CRYPT_IPSEC_HMAC_KEY 0x00000100
#endif
void RmLogW(int level, wstring message);
typedef struct _my_blob {
BLOBHEADER header;
DWORD len;
BYTE key[0];
}my_blob;
enum FbxAPIStatus
{
PENDING,
REGISTER,
UNREGISTER,
LOGOUT,
LOGIN,
UNKNOWN,
REVOKE,
TIMEOUT,
DENIED,
GRANTED,
INSUFFICIENT_RIGHTS,
AUTH_REQUIRED
};
enum FbxFormat
{
byte_s,
kbits_s,
celsius,
decibel,
rpm,
percent,
none
};
static map<wstring, map<wstring, FbxFormat>> FbxMeasures = {
{ L"net", {
{ L"bw_up", byte_s }, // upload available bandwidth (in byte/s)
{ L"bw_down", byte_s }, // download available bandwidth (in byte/
{ L"rate_up", byte_s }, // upload rate (in byte/s)
{ L"rate_down", byte_s }, // download rate (in byte/s)
{ L"vpn_rate_up", byte_s }, // vpn client upload rate (in byte/s)
{ L"vpn_rate_down", byte_s } // vpn client download rate (in byte/s)
}
},
{ L"temp", {
{ L"cpum", celsius }, // temperature cpum (in °C)
{ L"cpub", celsius }, // temperature cpub (in °C)
{ L"sw", celsius }, // temperature sw (in °C)
{ L"hdd", celsius }, // temperature hdd (in °C)
{ L"fan_speed", rpm} // fan rpm
}
},
{ L"dsl", {
{ L"rate_up", kbits_s }, // dsl available upload bandwidth (in byte/s)
{ L"rate_down", kbits_s }, // dsl available download bandwidth (in byte/s)
{ L"snr_up", decibel }, // upload signal/noise ratio (in 1/10 dB)
{ L"snr_down", decibel } // dsl download signal/noise ratio (in 1/10 dB)
}
},
{ L"net", {
{ L"rx_1", byte_s }, // receive rate on port 1 (in byte/s)
{ L"tx_1", byte_s }, // transmit on port 1 (in byte/s)
{ L"rx_2", byte_s }, // receive rate on port 2 (in byte/s)
{ L"tx_2", byte_s }, // transmit on port 2 (in byte/s)
{ L"rx_3", byte_s }, // receive rate on port 3 (in byte/s)
{ L"tx_3", byte_s }, // transmit on port 3 (in byte/s)
{ L"rx_4", byte_s }, // receive rate on port 4 (in byte/s)
{ L"tx_4", byte_s } // transmit on port 4 (in byte/s)
}
},
{ L"composite", {
{ L"busy_up", none }, // % of up bandwith occupation (net.rate_up / dsl.rate_up)
{ L"busy_down", none }, // % of down bandwith occupation (net.down_up / dsl.down_up)
{ L"status", none } // % of down bandwith occupation (net.down_up / dsl.down_up)
}
}
};
class FbxAPI {
public:
static FbxAPI& Instance();
wstring hostname;
wstring tracking_status;
FbxAPIStatus global_status;
wstring challenge;
wstring password;
wstring password_salt;
wstring app_token;
wstring track_id;
wstring logged_in;
wstring session_token;
bool fbxAPIInUse = false;
wstring rrd_error = L"";
pplx::cancellation_token_source cts;
void setHostname(LPCWSTR hostname);
pplx::task<bool> Register();
pplx::task<bool> Track();
pplx::task<bool> Login();
pplx::task<bool> Session();
bool updateMeasure(wstring database, wstring measure);
double getNumericMeasure(wstring database, wstring measure);
wstring getFormattedMeasure(wstring database, wstring measure);
void updateStatus();
static wstring format(wstring input, FbxFormat format);
wstring getStatusMsg();
bool executeNextCall(wstring db = L"", wstring field = L"");
private:
map <wstring, map<wstring, double>> numericMeasures = {
{ L"net",{
{ L"bw_up", 0 }, // upload available bandwidth (in byte/s)
{ L"bw_down", 0 }, // download available bandwidth (in byte/
{ L"rate_up", 0 }, // upload rate (in byte/s)
{ L"rate_down", 0 }, // download rate (in byte/s)
{ L"vpn_rate_up", 0 }, // vpn client upload rate (in byte/s)
{ L"vpn_rate_down", 0 } // vpn client download rate (in byte/s)
}
},
{ L"temp",{
{ L"cpum", 0 }, // temperature cpum (in °C)
{ L"cpub", 0 }, // temperature cpub (in °C)
{ L"sw", 0 }, // temperature sw (in °C)
{ L"hdd", 0 }, // temperature hdd (in °C)
{ L"fan_speed", 0 } // fan rpm
}
},
{ L"dsl",{
{ L"rate_up", 0 }, // dsl available upload bandwidth (in byte/s)
{ L"rate_down", 0 }, // dsl available download bandwidth (in byte/s)
{ L"snr_up", 0 }, // upload signal/noise ratio (in 1/10 dB)
{ L"snr_down", 0 } // dsl download signal/noise ratio (in 1/10 dB)
}
},
{ L"net",{
{ L"rx_1", 0 }, // receive rate on port 1 (in byte/s)
{ L"tx_1", 0 }, // transmit on port 1 (in byte/s)
{ L"rx_2", 0 }, // receive rate on port 2 (in byte/s)
{ L"tx_2", 0 }, // transmit on port 2 (in byte/s)
{ L"rx_3", 0 }, // receive rate on port 3 (in byte/s)
{ L"tx_3", 0 }, // transmit on port 3 (in byte/s)
{ L"rx_4", 0 }, // receive rate on port 4 (in byte/s)
{ L"tx_4", 0 } // transmit on port 4 (in byte/s)
}
},
{ L"composite",{
{ L"status", 0 }, // status
{ L"busy_up", 0 }, // % of up bandwith occupation (net.rate_up / dsl.rate_up)
{ L"busy_down", 0 } // % of down bandwith occupation (net.down_up / dsl.down_up)
}
}
};
map <wstring, map<wstring, wstring>> formattedMeasures = {
{ L"net",{
{ L"bw_up", L"" }, // upload available bandwidth (in byte/s)
{ L"bw_down", L"" }, // download available bandwidth (in byte/
{ L"rate_up", L"" }, // upload rate (in byte/s)
{ L"rate_down", L"" }, // download rate (in byte/s)
{ L"vpn_rate_up", L"" }, // vpn client upload rate (in byte/s)
{ L"vpn_rate_down", L"" } // vpn client download rate (in byte/s)
}
},
{ L"temp",{
{ L"cpum", L"" }, // temperature cpum (in °C)
{ L"cpub", L"" }, // temperature cpub (in °C)
{ L"sw", L"" }, // temperature sw (in °C)
{ L"hdd", L"" }, // temperature hdd (in °C)
{ L"fan_speed", L"" } // fan rpm
}
},
{ L"dsl",{
{ L"rate_up", L"" }, // dsl available upload bandwidth (in byte/s)
{ L"rate_down", L"" }, // dsl available download bandwidth (in byte/s)
{ L"snr_up", L"" }, // upload signal/noise ratio (in 1/10 dB)
{ L"snr_down", L"" } // dsl download signal/noise ratio (in 1/10 dB)
}
},
{ L"net",{
{ L"rx_1", L"" }, // receive rate on port 1 (in byte/s)
{ L"tx_1", L"" }, // transmit on port 1 (in byte/s)
{ L"rx_2", L"" }, // receive rate on port 2 (in byte/s)
{ L"tx_2", L"" }, // transmit on port 2 (in byte/s)
{ L"rx_3", L"" }, // receive rate on port 3 (in byte/s)
{ L"tx_3", L"" }, // transmit on port 3 (in byte/s)
{ L"rx_4", L"" }, // receive rate on port 4 (in byte/s)
{ L"tx_4", L"" } // transmit on port 4 (in byte/s)
}
},
{ L"composite",{
{ L"status", L"" }, // status
{ L"busy_up", L"" }, // % of up bandwith occupation (net.rate_up / dsl.rate_up)
{ L"busy_down", L"" } // % of down bandwith occupation (net.down_up / dsl.down_up)
}
}
};
pplx::task<json::value> handleFbxAPIResponse(http_response response);
wstring getLastRRDData(wstring value, json::value json_array);
char * HMAC(char * str, char * password, DWORD AlgId = CALG_SHA1);
pplx::task<bool> RRD(wstring database, wstring measure, FbxFormat format);
FbxAPI& operator= (const FbxAPI&) {}
FbxAPI(const FbxAPI&) {}
static FbxAPI m_instance;
FbxAPI();
~FbxAPI();
};