Skip to content

Commit f25c6cd

Browse files
committed
nieuwe CSI1
1 parent 4c0be94 commit f25c6cd

2 files changed

Lines changed: 257 additions & 50 deletions

File tree

CSI1.plugin(oud).txt

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
///////// <version>1.0.0</version>
2+
///////// CSI1 /////////////
3+
///////// Plugin to extract Canadian Solar data for Toon ///////////////
4+
///////// By Oepi-Loepi ///////////////
5+
6+
7+
function getSolarData(passWord,userName,apiKey,siteid,urlString,totalValue){
8+
if (debugOutput) console.log("*********SolarPanel Start getSolarData")
9+
var data = "value=" + passWord;
10+
11+
var xhr = new XMLHttpRequest();
12+
xhr.open("POST", "https://tools.keycdn.com/sha256-online-generator");
13+
xhr.setRequestHeader("Host", "tools.keycdn.com");
14+
xhr.setRequestHeader("Connection", "keep-alive");
15+
xhr.setRequestHeader("Cache-Control", "max-age=0");
16+
xhr.setRequestHeader("sec-ch-ua", "\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\"");
17+
xhr.setRequestHeader("sec-ch-ua-mobile", "?0");
18+
xhr.setRequestHeader("sec-ch-ua-platform", "\"Windows\"");
19+
xhr.setRequestHeader("Upgrade-Insecure-Requests", "1");
20+
xhr.setRequestHeader("Origin", "https://tools.keycdn.com");
21+
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
22+
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");
23+
xhr.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
24+
xhr.setRequestHeader("Sec-Fetch-Site", "same-origin");
25+
xhr.setRequestHeader("Sec-Fetch-Mode", "navigate");
26+
xhr.setRequestHeader("Sec-Fetch-User", "?1");
27+
xhr.setRequestHeader("Sec-Fetch-Dest", "document");
28+
xhr.setRequestHeader("Referer", "https://tools.keycdn.com/sha256-online-generator");
29+
xhr.setRequestHeader("Accept-Encoding", "gzip, deflate, br");
30+
xhr.setRequestHeader("Accept-Language", "nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7");
31+
32+
xhr.onreadystatechange = function() { // Call a function when the state changes.
33+
if (xhr.readyState == XMLHttpRequest.DONE) {
34+
if (xhr.status === 200 || xhr.status === 300 || xhr.status === 302) {
35+
try {
36+
if (debugOutput) console.log(xhr.responseText)
37+
var begin = xhr.responseText.indexOf("<code class=\"language-none\">") + "<code class=\"language-none\">".length
38+
var end = xhr.responseText.indexOf("<",begin)
39+
var sha256 = xhr.responseText.substring(begin, end).trim()
40+
if (debugOutput) console.log("sha2 encrypted: " +sha256)
41+
getStep2(sha256, passWord, userName)
42+
} catch (e){
43+
currentPower = 0
44+
parseReturnData(0,totalValue,todayValue,0,0,0,0, xhr.status,"error")
45+
}
46+
} else {
47+
parseReturnData(currentPower,totalValue,0,0,0,0,0, xhr.status,"error")
48+
}
49+
}
50+
}
51+
xhr.send(data);
52+
}
53+
54+
function getStep2(sha256, passWord2, userName2){
55+
if (debugOutput) console.log("*********SolarPanel Start getStep2")
56+
//userName2 = userName2.replace('@', '83@')
57+
if (debugOutput) console.log("*********SolarPanel encodeURIComponent(userName2): " + encodeURIComponent(userName2))
58+
var data = "grant_type=password&username=" + encodeURIComponent(userName2) + "&clear_text_pwd=" + encodeURIComponent(passWord2) + "&password=" + encodeURIComponent(sha256) + "&identity_type=2&client_id=test"
59+
60+
if (debugOutput) console.log(data)
61+
var xhr = new XMLHttpRequest();
62+
xhr.open("POST", "https://monitoring.csisolar.com/home/oauth-s/oauth/token");
63+
xhr.setRequestHeader("Host", "monitoring.csisolar.com");
64+
xhr.setRequestHeader("Connection", "keep-alive");
65+
xhr.setRequestHeader("sec-ch-ua", "\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\"");
66+
xhr.setRequestHeader("Pragma", "no-cache");
67+
xhr.setRequestHeader("sec-ch-ua-mobile", "?0");
68+
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");
69+
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
70+
xhr.setRequestHeader("Accept", "application/json, text/plain, */*");
71+
xhr.setRequestHeader("Cache-Control", "no-cache");
72+
xhr.setRequestHeader("sec-ch-ua-platform", "\"Windows\"");
73+
xhr.setRequestHeader("Origin", "https://monitoring.csisolar.com");
74+
xhr.setRequestHeader("Sec-Fetch-Site", "same-origin");
75+
xhr.setRequestHeader("Sec-Fetch-Mode", "cors");
76+
xhr.setRequestHeader("Sec-Fetch-Dest", "empty");
77+
xhr.setRequestHeader("Referer", "https://monitoring.csisolar.com/home/login");
78+
xhr.setRequestHeader("Accept-Encoding", "gzip, deflate, br");
79+
xhr.setRequestHeader("Accept-Language", "nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7");
80+
xhr.onreadystatechange = function() { // Call a function when the state changes.
81+
if (debugOutput) console.log(xhr.readyState)
82+
if (xhr.readyState == XMLHttpRequest.DONE) {
83+
if (debugOutput) console.log(xhr.status)
84+
if (xhr.status === 200 || xhr.status === 300 || xhr.status === 302) {
85+
try {
86+
if (debugOutput) console.log(xhr.responseText)
87+
var JsonString = xhr.responseText
88+
var JsonObject= JSON.parse(JsonString)
89+
var token = JsonObject.access_token
90+
if (debugOutput) console.log("token : " + token)
91+
getStep3(token)
92+
}
93+
catch (e){
94+
currentPower = 0
95+
parseReturnData(0,totalValue,todayValue,0,0,0,0, xhr.status,"error")
96+
}
97+
} else {
98+
parseReturnData(currentPower,totalValue,0,0,0,0,0, xhr.status,"error")
99+
}
100+
}
101+
}
102+
xhr.send(data);
103+
}
104+
105+
function getStep3(token){
106+
if (debugOutput) console.log("*********SolarPanel Start getStep3")
107+
var data = "{}";
108+
var xhr = new XMLHttpRequest();
109+
xhr.withCredentials = true;
110+
xhr.open("POST", "https://monitoring.csisolar.com/home/maintain-s/operating/station/search?order.direction=DESC&order.property=id&page=1&size=20");
111+
xhr.setRequestHeader("Host", "monitoring.csisolar.com");
112+
xhr.setRequestHeader("Connection", "keep-alive");
113+
xhr.setRequestHeader("sec-ch-ua", "\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\"");
114+
xhr.setRequestHeader("Pragma", "no-cache");
115+
xhr.setRequestHeader("sec-ch-ua-mobile", "?0");
116+
xhr.setRequestHeader("Authorization", "Bearer " + token);
117+
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
118+
xhr.setRequestHeader("Accept", "application/json, text/plain, */*");
119+
xhr.setRequestHeader("Cache-Control", "no-cache");
120+
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");
121+
xhr.setRequestHeader("sec-ch-ua-platform", "\"Windows\"");
122+
xhr.setRequestHeader("Origin", "https://monitoring.csisolar.com");
123+
xhr.setRequestHeader("Sec-Fetch-Site", "same-origin");
124+
xhr.setRequestHeader("Sec-Fetch-Mode", "cors");
125+
xhr.setRequestHeader("Sec-Fetch-Dest", "empty");
126+
xhr.setRequestHeader("Referer", "https://monitoring.csisolar.com/home/plant/infos/data");
127+
xhr.setRequestHeader("Accept-Encoding", "gzip, deflate, br");
128+
xhr.setRequestHeader("Accept-Language", "nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7");
129+
xhr.onreadystatechange = function() { // Call a function when the state changes.
130+
if (xhr.readyState == XMLHttpRequest.DONE) {
131+
if (xhr.status === 200 || xhr.status === 300 || xhr.status === 302) {
132+
try {
133+
console.log(xhr.responseText)
134+
var JsonString = xhr.responseText
135+
var JsonObject= JSON.parse(JsonString)
136+
var today2
137+
currentPower = parseInt(JsonObject.data[0].generationPower)
138+
if(currentPower<20)currentPower = 0
139+
today2 = parseInt(JsonObject.data[0].generationValue)
140+
totalValue = parseInt(JsonObject.data[0].generationTotal)
141+
parseReturnData(currentPower,totalValue,today2,0,0,0,0,xhr.status,"succes")
142+
}
143+
catch (e){
144+
currentPower = 0
145+
parseReturnData(0,totalValue,todayValue,0,0,0,0, xhr.status,"error")
146+
}
147+
} else {
148+
parseReturnData(currentPower,totalValue,0,0,0,0,0, xhr.status,"error")
149+
}
150+
}
151+
}
152+
xhr.send(data);
153+
}

CSI1.plugin.txt

Lines changed: 104 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,114 @@
1-
///////// <version>1.0.0</version>
1+
///////// <version>1.0.1</version>
22
///////// CSI1 /////////////
33
///////// Plugin to extract Canadian Solar data for Toon ///////////////
44
///////// By Oepi-Loepi ///////////////
55

66

7-
function getSolarData(passWord,userName,apiKey,siteid,urlString,totalValue){
8-
if (debugOutput) console.log("*********SolarPanel Start getSolarData")
9-
var data = "value=" + passWord;
10-
11-
var xhr = new XMLHttpRequest();
12-
xhr.open("POST", "https://tools.keycdn.com/sha256-online-generator");
13-
xhr.setRequestHeader("Host", "tools.keycdn.com");
14-
xhr.setRequestHeader("Connection", "keep-alive");
15-
xhr.setRequestHeader("Cache-Control", "max-age=0");
16-
xhr.setRequestHeader("sec-ch-ua", "\"Google Chrome\";v=\"105\", \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"105\"");
17-
xhr.setRequestHeader("sec-ch-ua-mobile", "?0");
18-
xhr.setRequestHeader("sec-ch-ua-platform", "\"Windows\"");
19-
xhr.setRequestHeader("Upgrade-Insecure-Requests", "1");
20-
xhr.setRequestHeader("Origin", "https://tools.keycdn.com");
21-
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
22-
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");
23-
xhr.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
24-
xhr.setRequestHeader("Sec-Fetch-Site", "same-origin");
25-
xhr.setRequestHeader("Sec-Fetch-Mode", "navigate");
26-
xhr.setRequestHeader("Sec-Fetch-User", "?1");
27-
xhr.setRequestHeader("Sec-Fetch-Dest", "document");
28-
xhr.setRequestHeader("Referer", "https://tools.keycdn.com/sha256-online-generator");
29-
xhr.setRequestHeader("Accept-Encoding", "gzip, deflate, br");
30-
xhr.setRequestHeader("Accept-Language", "nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7");
7+
function rightRotate(value, amount) {
8+
return (value>>>amount) | (value<<(32 - amount));
9+
}
3110

32-
xhr.onreadystatechange = function() { // Call a function when the state changes.
33-
if (xhr.readyState == XMLHttpRequest.DONE) {
34-
if (xhr.status === 200 || xhr.status === 300 || xhr.status === 302) {
35-
try {
36-
if (debugOutput) console.log(xhr.responseText)
37-
var begin = xhr.responseText.indexOf("<code class=\"language-none\">") + "<code class=\"language-none\">".length
38-
var end = xhr.responseText.indexOf("<",begin)
39-
var sha256 = xhr.responseText.substring(begin, end).trim()
40-
if (debugOutput) console.log("sha2 encrypted: " +sha256)
41-
getStep2(sha256, passWord, userName)
42-
} catch (e){
43-
currentPower = 0
44-
parseReturnData(0,totalValue,todayValue,0,0,0,0, xhr.status,"error")
45-
}
46-
} else {
47-
parseReturnData(currentPower,totalValue,0,0,0,0,0, xhr.status,"error")
48-
}
49-
}
50-
}
51-
xhr.send(data);
11+
function sha256(ascii) {
12+
13+
var mathPow = Math.pow;
14+
var maxWord = mathPow(2, 32);
15+
var lengthProperty = 'length'
16+
var i, j; // Used as a counter across the whole file
17+
var result = ''
18+
19+
var words = [];
20+
var asciiBitLength = ascii[lengthProperty]*8;
21+
22+
//* caching results is optional - remove/add slash from front of this line to toggle
23+
// Initial hash value: first 32 bits of the fractional parts of the square roots of the first 8 primes
24+
// (we actually calculate the first 64, but extra values are just ignored)
25+
var hash = sha256.h = sha256.h || [];
26+
// Round constants: first 32 bits of the fractional parts of the cube roots of the first 64 primes
27+
var k = sha256.k = sha256.k || [];
28+
var primeCounter = k[lengthProperty];
29+
/*/
30+
var hash = [], k = [];
31+
var primeCounter = 0;
32+
//*/
33+
34+
var isComposite = {};
35+
for (var candidate = 2; primeCounter < 64; candidate++) {
36+
if (!isComposite[candidate]) {
37+
for (i = 0; i < 313; i += candidate) {
38+
isComposite[i] = candidate;
39+
}
40+
hash[primeCounter] = (mathPow(candidate, .5)*maxWord)|0;
41+
k[primeCounter++] = (mathPow(candidate, 1/3)*maxWord)|0;
42+
}
43+
}
44+
45+
ascii += '\x80' // Append Ƈ' bit (plus zero padding)
46+
while (ascii[lengthProperty]%64 - 56) ascii += '\x00' // More zero padding
47+
for (i = 0; i < ascii[lengthProperty]; i++) {
48+
j = ascii.charCodeAt(i);
49+
if (j>>8) return; // ASCII check: only accept characters in range 0-255
50+
words[i>>2] |= j << ((3 - i)%4)*8;
51+
}
52+
words[words[lengthProperty]] = ((asciiBitLength/maxWord)|0);
53+
words[words[lengthProperty]] = (asciiBitLength)
54+
55+
// process each chunk
56+
for (j = 0; j < words[lengthProperty];) {
57+
var w = words.slice(j, j += 16); // The message is expanded into 64 words as part of the iteration
58+
var oldHash = hash;
59+
// This is now the undefinedworking hash", often labelled as variables a...g
60+
// (we have to truncate as well, otherwise extra entries at the end accumulate
61+
hash = hash.slice(0, 8);
62+
63+
for (i = 0; i < 64; i++) {
64+
var i2 = i + j;
65+
// Expand the message into 64 words
66+
// Used below if
67+
var w15 = w[i - 15], w2 = w[i - 2];
68+
69+
// Iterate
70+
var a = hash[0], e = hash[4];
71+
var temp1 = hash[7]
72+
+ (rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25)) // S1
73+
+ ((e&hash[5])^((~e)&hash[6])) // ch
74+
+ k[i]
75+
// Expand the message schedule if needed
76+
+ (w[i] = (i < 16) ? w[i] : (
77+
w[i - 16]
78+
+ (rightRotate(w15, 7) ^ rightRotate(w15, 18) ^ (w15>>>3)) // s0
79+
+ w[i - 7]
80+
+ (rightRotate(w2, 17) ^ rightRotate(w2, 19) ^ (w2>>>10)) // s1
81+
)|0
82+
);
83+
// This is only used once, so *could* be moved below, but it only saves 4 bytes and makes things unreadble
84+
var temp2 = (rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22)) // S0
85+
+ ((a&hash[1])^(a&hash[2])^(hash[1]&hash[2])); // maj
86+
87+
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()
88+
hash[4] = (hash[4] + temp1)|0;
89+
}
90+
91+
for (i = 0; i < 8; i++) {
92+
hash[i] = (hash[i] + oldHash[i])|0;
93+
}
94+
}
95+
96+
for (i = 0; i < 8; i++) {
97+
for (j = 3; j + 1; j--) {
98+
var b = (hash[i]>>(j*8))&255;
99+
result += ((b < 16) ? 0 : '') + b.toString(16);
100+
}
101+
}
102+
return result;
52103
}
53104

54-
function getStep2(sha256, passWord2, userName2){
55-
if (debugOutput) console.log("*********SolarPanel Start getStep2")
56-
//userName2 = userName2.replace('@', '83@')
105+
106+
function getSolarData(passWord,userName,apiKey,siteid,urlString,totalValue){
107+
if (debugOutput) console.log("*********SolarPanel Start getSolarData")
108+
var newHash = sha256(passWord);
109+
if (debugOutput) console.log("*********SolarPanel new function sha256: " + newHash)
57110
if (debugOutput) console.log("*********SolarPanel encodeURIComponent(userName2): " + encodeURIComponent(userName2))
58-
var data = "grant_type=password&username=" + encodeURIComponent(userName2) + "&clear_text_pwd=" + encodeURIComponent(passWord2) + "&password=" + encodeURIComponent(sha256) + "&identity_type=2&client_id=test"
111+
var data = "grant_type=password&username=" + encodeURIComponent(userName) + "&clear_text_pwd=" + encodeURIComponent(passWord) + "&password=" + encodeURIComponent(newHash) + "&identity_type=2&client_id=test"
59112

60113
if (debugOutput) console.log(data)
61114
var xhr = new XMLHttpRequest();
@@ -136,7 +189,8 @@ function getStep3(token){
136189
var today2
137190
currentPower = parseInt(JsonObject.data[0].generationPower)
138191
if(currentPower<20)currentPower = 0
139-
today2 = parseInt(JsonObject.data[0].generationValue)
192+
//today2 = parseInt(JsonObject.data[0].generationValue)
193+
today2 = totalValue - yesterdayTotal
140194
totalValue = parseInt(JsonObject.data[0].generationTotal)
141195
parseReturnData(currentPower,totalValue,today2,0,0,0,0,xhr.status,"succes")
142196
}

0 commit comments

Comments
 (0)