-
Notifications
You must be signed in to change notification settings - Fork 5
/
SOLMAN1.plugin.txt
211 lines (191 loc) · 9.46 KB
/
SOLMAN1.plugin.txt
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
///////// <version>1.0.0</version>
///////// SOLMAN1 /////////////
///////// Plugin to extract Solarman data for Toon ///////////////
///////// By Oepi-Loepi ///////////////
function rightRotate(value, amount) {
return (value>>>amount) | (value<<(32 - amount));
}
function sha256(ascii) {
var mathPow = Math.pow;
var maxWord = mathPow(2, 32);
var lengthProperty = 'length'
var i, j; // Used as a counter across the whole file
var result = ''
var words = [];
var asciiBitLength = ascii[lengthProperty]*8;
//* caching results is optional - remove/add slash from front of this line to toggle
// Initial hash value: first 32 bits of the fractional parts of the square roots of the first 8 primes
// (we actually calculate the first 64, but extra values are just ignored)
var hash = sha256.h = sha256.h || [];
// Round constants: first 32 bits of the fractional parts of the cube roots of the first 64 primes
var k = sha256.k = sha256.k || [];
var primeCounter = k[lengthProperty];
/*/
var hash = [], k = [];
var primeCounter = 0;
//*/
var isComposite = {};
for (var candidate = 2; primeCounter < 64; candidate++) {
if (!isComposite[candidate]) {
for (i = 0; i < 313; i += candidate) {
isComposite[i] = candidate;
}
hash[primeCounter] = (mathPow(candidate, .5)*maxWord)|0;
k[primeCounter++] = (mathPow(candidate, 1/3)*maxWord)|0;
}
}
ascii += '\x80' // Append Ƈ' bit (plus zero padding)
while (ascii[lengthProperty]%64 - 56) ascii += '\x00' // More zero padding
for (i = 0; i < ascii[lengthProperty]; i++) {
j = ascii.charCodeAt(i);
if (j>>8) return; // ASCII check: only accept characters in range 0-255
words[i>>2] |= j << ((3 - i)%4)*8;
}
words[words[lengthProperty]] = ((asciiBitLength/maxWord)|0);
words[words[lengthProperty]] = (asciiBitLength)
// process each chunk
for (j = 0; j < words[lengthProperty];) {
var w = words.slice(j, j += 16); // The message is expanded into 64 words as part of the iteration
var oldHash = hash;
// This is now the undefinedworking hash", often labelled as variables a...g
// (we have to truncate as well, otherwise extra entries at the end accumulate
hash = hash.slice(0, 8);
for (i = 0; i < 64; i++) {
var i2 = i + j;
// Expand the message into 64 words
// Used below if
var w15 = w[i - 15], w2 = w[i - 2];
// Iterate
var a = hash[0], e = hash[4];
var temp1 = hash[7]
+ (rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25)) // S1
+ ((e&hash[5])^((~e)&hash[6])) // ch
+ k[i]
// Expand the message schedule if needed
+ (w[i] = (i < 16) ? w[i] : (
w[i - 16]
+ (rightRotate(w15, 7) ^ rightRotate(w15, 18) ^ (w15>>>3)) // s0
+ w[i - 7]
+ (rightRotate(w2, 17) ^ rightRotate(w2, 19) ^ (w2>>>10)) // s1
)|0
);
// This is only used once, so *could* be moved below, but it only saves 4 bytes and makes things unreadble
var temp2 = (rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22)) // S0
+ ((a&hash[1])^(a&hash[2])^(hash[1]&hash[2])); // maj
hash = [(temp1 + temp2)|0].concat(hash); // We don't bother trimming off the extra ones, they're harmless as long as we're truncating when we do the slice()
hash[4] = (hash[4] + temp1)|0;
}
for (i = 0; i < 8; i++) {
hash[i] = (hash[i] + oldHash[i])|0;
}
}
for (i = 0; i < 8; i++) {
for (j = 3; j + 1; j--) {
var b = (hash[i]>>(j*8))&255;
result += ((b < 16) ? 0 : '') + b.toString(16);
}
}
return result;
}
function getSolarData(passWord,userName,apiKey,siteid,urlString,totalValue){
if (debugOutput) console.log("*********SolarPanel Start getSolarData")
var newHash = sha256(passWord);
if (debugOutput) console.log("*********SolarPanel new function sha256: " + newHash)
if (debugOutput) console.log("*********SolarPanel encodeURIComponent(userName2): " + encodeURIComponent(userName2))
var data = "grant_type=password&username=" + encodeURIComponent(userName) + "&clear_text_pwd=" + encodeURIComponent(passWord) + "&password=" + encodeURIComponent(newHash) + "&identity_type=2&client_id=test"
if (debugOutput) console.log(data)
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://home.solarmanpv.com/oauth-s/oauth/token");
xhr.setRequestHeader("Host", "monitoring.csisolar.com");
xhr.setRequestHeader("Connection", "keep-alive");
xhr.setRequestHeader("sec-ch-ua", "\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\"");
xhr.setRequestHeader("Pragma", "no-cache");
xhr.setRequestHeader("sec-ch-ua-mobile", "?0");
xhr.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Accept", "application/json, text/plain, */*");
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("sec-ch-ua-platform", "\"Windows\"");
xhr.setRequestHeader("Origin", "https://home.solarmanpv.com");
xhr.setRequestHeader("Sec-Fetch-Site", "same-origin");
xhr.setRequestHeader("Sec-Fetch-Mode", "cors");
xhr.setRequestHeader("Sec-Fetch-Dest", "empty");
xhr.setRequestHeader("Referer", "https://home.solarmanpv.com/login");
xhr.setRequestHeader("Accept-Encoding", "gzip, deflate, br");
xhr.setRequestHeader("Accept-Language", "nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7");
xhr.onreadystatechange = function() { // Call a function when the state changes.
if (debugOutput) console.log(xhr.readyState)
if (xhr.readyState == XMLHttpRequest.DONE) {
if (debugOutput) console.log(xhr.status)
if (xhr.status === 200 || xhr.status === 300 || xhr.status === 302) {
try {
if (debugOutput) console.log(xhr.responseText)
var JsonString = xhr.responseText
var JsonObject= JSON.parse(JsonString)
var token = JsonObject.access_token
if (debugOutput) console.log("token : " + token)
getStep3(token)
}
catch (e){
currentPower = 0
parseReturnData(0,totalValue,todayValue,0,0,0,0, xhr.status,"error")
}
} else {
parseReturnData(currentPower,totalValue,0,0,0,0,0, xhr.status,"error")
}
}
}
xhr.send(data);
}
function getStep3(token){
if (debugOutput) console.log("*********SolarPanel Start getStep3")
var data = "{}";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open("POST", "https://home.solarmanpv.com/maintain-s/operating/station/search?order.direction=DESC&order.property=id&page=1&size=20");
xhr.setRequestHeader("Host", "monitoring.csisolar.com");
xhr.setRequestHeader("Connection", "keep-alive");
xhr.setRequestHeader("sec-ch-ua", "\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\"");
xhr.setRequestHeader("Pragma", "no-cache");
xhr.setRequestHeader("sec-ch-ua-mobile", "?0");
xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.setRequestHeader("Accept", "application/json, text/plain, */*");
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36");
xhr.setRequestHeader("sec-ch-ua-platform", "\"Windows\"");
xhr.setRequestHeader("Origin", "https://home.solarmanpv.com");
xhr.setRequestHeader("Sec-Fetch-Site", "same-origin");
xhr.setRequestHeader("Sec-Fetch-Mode", "cors");
xhr.setRequestHeader("Sec-Fetch-Dest", "empty");
https://home.solarmanpv.com/plant/infos/data
xhr.setRequestHeader("Referer", "https://home.solarmanpv.com/plant/infos/data");
xhr.setRequestHeader("Accept-Encoding", "gzip, deflate, br");
xhr.setRequestHeader("Accept-Language", "nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7");
xhr.onreadystatechange = function() { // Call a function when the state changes.
if (xhr.readyState == XMLHttpRequest.DONE) {
if (xhr.status === 200 || xhr.status === 300 || xhr.status === 302) {
try {
if (debugOutput) console.log(xhr.responseText)
var JsonString = xhr.responseText
var JsonObject= JSON.parse(JsonString)
var today2
currentPower = parseInt(JsonObject.data[0].generationPower)
if(currentPower<20)currentPower = 0
totalValue = parseInt(parseFloat(JsonObject.data[0].generationTotal)*1000)
//today2 = parseInt(JsonObject.data[0].generationValue)
//today2 = parseInt(parseFloat(JsonObject.data[0].generationCapacity)*1000)
today2 = totalValue - yesterdayTotal
parseReturnData(currentPower,totalValue,today2,0,0,0,0,xhr.status,"succes")
}
catch (e){
currentPower = 0
parseReturnData(0,totalValue,todayValue,0,0,0,0, xhr.status,"error")
}
} else {
parseReturnData(currentPower,totalValue,0,0,0,0,0, xhr.status,"error")
}
}
}
xhr.send(data);
}