Neue Version von HTTPMOD mit neuen Features zum Testen

Begonnen von StefanStrobel, 05 Dezember 2015, 08:31:32

Vorheriges Thema - Nächstes Thema

StefanStrobel

Hallo,

removeBuf ist aufgrund einer Änderung in den HttpUtils sinnlos geworden. Es sollte entfernt werden.
Siehe weiter oben.

Gruß
   Stefan

josch123

#421
Zitat von: ch.eick am 08 März 2017, 16:50:42
Das Login geht schon mal und wird hier später auch noch eingefügt.

Ich wollte den Beitrag noch einmal aufgreifen. Ich versuche mich gerade ähnlich wie Christian per HTTPMOD mit dem Cloud Service meiner Vallox KWL (https://cloud.vallox.com) zu verbinden. Für das Login Verfahren muss ich den CSRF Token im Header mit schicken. Dieser wird mir als Internal "HTTPCookies" zusammen mit einigen anderen Größen im HTTPMOD Device angezeigt. Jedoch scheitere ich bisher daran per RegEx den relevanten Teil aus dem Internal zu extrahieren. Christian hat leider auch nie seine Lösung gepostet :-(.

Anbei ein Auszug aus dem List für das Device
BUSY       0
   CFGFN     
   CHANGED   
   DEF        https://cloud.vallox.com/cloudui/index.html?deviceid=C7796DA7-F3B9-4B20-B56E-5521E0F0131B 100
   HTTPCookies _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=e1HW6HFB-sYrxo-LrdgVa5LvtYHdqYquMB5c; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de

...

Attributes:
   DbLogExclude .*
   authRetries 5
   enableCookies 1
   extractAllJSON 1
   get1Name   Test
   get1URL    https://cloud.vallox.com/api/devicestate/XXXXXXXXXXXX
   getHeader1 Host: cloud.vallox.com
   getHeader2 x-csrf-token: %%csrf_token%%
   getHeader3 Accept-Encoding: gzip, deflate
   getHeader4 Accept: application/json, text/javascript, */*; q=0.01
   reAuthAlways 1
   reAuthRegex password-input
   replacement01Mode expression
   replacement01Regex %%csrf_token%%
   replacement01Value {InternalVal("valloxtest","HTTPCookies","")}
   sid1Data   username=XX&password=YY
   sid1Header1 Host: cloud.vallox.com
   sid1Header2 Accept: application/json, text/plain, */*
   sid1Header3 X-XSRF-TOKEN: %%csrf_token%%
   sid1Header4 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
   sid1URL    https://cloud.vallox.com/login
   userattr   get1Name get1URL getHeader1 getHeader2 getHeader3 getHeader4 replacement01Mode:reading,internal,text,expression,key replacement01Regex replacement01Value replacement1Mode:reading,internal,text,expression,key replacement1Regex replacement1Value sid1Data sid1Header1 sid1Header2 sid1Header3 sid1Header4 sid1URL
   verbose    5


Ich schaffe es per InternalVal("valloxtest","HTTPCookies","") den Wert des Internals abzufragen. Jedoch weiß ich bisher nicht wie ich den für mich relevanten Teil _csrfToken extrahiere. Das müsste nach meinem Verständnis per Regulärem Ausdruck (z.B. (?<=ken=)(.*)(?=; con)) gehen . Jedoch weiß ich nicht wie ich die beiden (InternalVal+RegEx) miteinander verbinde.

Beste Grüße,
Joschka

StefanStrobel

Hallo Joschka,

Leider fehlen ein paar entscheidende Informationen um Dir helfen zu können.
Wie sieht die HTTP-Kommunikation denn genau aus? Wo und in welcher Form schickt der Server die Informationen und wie müssen sie wieder zurückgeschickt werden?

Gruss
    Stefan

StefanStrobel

Anbei eine neue Version zum Testen.
Hinzugekommen ist das Attribut "enforceGoodReadingNames". Bei extractAllJSON konnten bisher ungültige Reading-Namen erzeugt werden. Wenn enforceGoodReadingNames auf 1 gesetzt ist, wird der Name durch die Funktion makeReadingName geschleust. Um keine Seiteneffekte auf bestehende Systeme zu erzeugen ist das ganze ein neues Attribut geworden. Ich würde es aber zu einem geeigneten Zeitpunkt per Default so machen (eigentlich hätte es schon immer makeReadingName verwenden sollen).

Gruss
    Stefan

JoeALLb

Hallo Stefan.
Ich habe ein Device, das ich über das Modul auslese.
Es funktioniert soweit sehr gut, doch leider benötige ich manchmal verschachtelte regex klammern, um Dinge komplett zu bekommen.
Was es mir extrem erleichtern würde wäre, wenn ich benannte Klammern als Readingnamen nutzen könnte... Damit könnte ich meine 300 Attribute auch gleich um mindestens 150 reduzieren ;-)

Hast Du dir das schon Mal überlegt? Regex-Parameter wie das Multiline funktioniert ja schon wunderbar und muss nicht mehr separat als eigenes Attribut angegeben werden....

SG Joe
FHEM-Server auf IntelAtom+Debian (8.1 Watt), KNX,
RasPi-2 Sonos-FHEM per FHEM2FHEM,RasPi-3 Versuchs-RasPi für WLAN-Tests
Gateways: DuoFern Stick, CUL866 PCA301, CUL HM, HMLan, JeeLink, LaCrosse,VCO2
Synology. Ardurino UNO für 1-Wire Tests, FB7270

josch123

Vielen Dank für die schnelle Rückmeldung.

Leider weiß ich nicht ganz wie die HTTP Kommunikation aussieht. Ich habe mich an dem Code von Christian orientiert und an dem was mir Burp ausgespuckt hat.

Ich hoffe das man aus dem Logfile diese Infos ziehen kann. Anbei ein Auszug:

2018.05.02 23:05:16 4: valloxtest: GetUpdate called (update)
2018.05.02 23:05:16 4: valloxtest: update timer modified: will call GetUpdate in 100.0 seconds at 2018-05-02 23:06:56
2018.05.02 23:05:16 4: valloxtest: Auth called with Steps: 1
2018.05.02 23:05:16 4: valloxtest: AddToQueue adds auth1, initial queue len: 0, prio
2018.05.02 23:05:16 5: valloxtest: AddToQueue prepends type auth1 to URL https://cloud.vallox.com/login, data username=XXXXXXX&password=XXXXXXX, header Host: cloud.vallox.com
Accept: application/json, text/plain, */*
X-XSRF-TOKEN: %%csrf_token%%
Content-Type: application/x-www-form-urlencoded; charset=UTF-8, retry 0
2018.05.02 23:05:16 5: valloxtest: HandleSendQueue called, qlen = 1
2018.05.02 23:05:16 5: valloxtest: Replace called for type auth1, regex %%csrf_token%%, mode expression, value {InternalVal("valloxtest","HTTPCookies","")} input: Host: cloud.vallox.com
Accept: application/json, text/plain, */*
X-XSRF-TOKEN: %%csrf_token%%
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
2018.05.02 23:05:16 4: valloxtest: Replace: match for type auth1, regex %%csrf_token%%, mode expression, value {InternalVal("valloxtest","HTTPCookies","")}, input: Host: cloud.vallox.com
Accept: application/json, text/plain, */*
X-XSRF-TOKEN: %%csrf_token%%
Content-Type: application/x-www-form-urlencoded; charset=UTF-8, result is Host: cloud.vallox.com
Accept: application/json, text/plain, */*
X-XSRF-TOKEN: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
2018.05.02 23:05:16 5: valloxtest: Replace called for type auth1, regex %%csrf_token%%, mode expression, value {InternalVal("valloxtest","HTTPCookies","")} input: username=XXXXXXX&password=XXXXXXX
2018.05.02 23:05:16 5: valloxtest: Replace called for type auth1, regex %%csrf_token%%, mode expression, value {InternalVal("valloxtest","HTTPCookies","")} input: https://cloud.vallox.com/login
2018.05.02 23:05:16 5: valloxtest: HandleSendQueue is adding Cookies: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
2018.05.02 23:05:16 4: valloxtest: HandleSendQueue sends request type auth1 to URL https://cloud.vallox.com/login,
data: username=XXXXXXX&password=XXXXXXX,
header: Host: cloud.vallox.com
Accept: application/json, text/plain, */*
X-XSRF-TOKEN: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de,
timeout 2
2018.05.02 23:05:16 5: HttpUtils url=https://cloud.vallox.com/login
2018.05.02 23:05:16 4: valloxtest: AddToQueue adds update, initial queue len: 0
2018.05.02 23:05:16 5: valloxtest: AddToQueue adds type update to URL https://cloud.vallox.com/cloudui/index.html?deviceid=XXXXXXX, no data, no headers, retry 0
2018.05.02 23:05:16 5: valloxtest: HandleSendQueue called, qlen = 1
2018.05.02 23:05:16 5: valloxtest: HandleSendQueue - still waiting for reply to last request, delay sending from queue
2018.05.02 23:05:16 5: HttpUtils request header:
POST /login HTTP/1.0
Host: cloud.vallox.com
User-Agent: fhem
Accept-Encoding: gzip,deflate
Host: cloud.vallox.com
Accept: application/json, text/plain, */*
X-XSRF-TOKEN: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Length: 65

2018.05.02 23:05:16 4: https://cloud.vallox.com/login: HTTP response code 302
2018.05.02 23:05:16 4: HttpUtils https://cloud.vallox.com/login: Redirect to https://cloud.vallox.com:443/
2018.05.02 23:05:16 5: HttpUtils url=https://cloud.vallox.com:443/
2018.05.02 23:05:16 5: HttpUtils request header:
POST / HTTP/1.0
Host: cloud.vallox.com
User-Agent: fhem
Accept-Encoding: gzip,deflate
Host: cloud.vallox.com
Accept: application/json, text/plain, */*
X-XSRF-TOKEN: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Length: 65

2018.05.02 23:05:16 4: https://cloud.vallox.com:443/: HTTP response code 302
2018.05.02 23:05:16 4: HttpUtils https://cloud.vallox.com:443/: Redirect to https://cloud.vallox.com:443/
2018.05.02 23:05:16 5: HttpUtils url=https://cloud.vallox.com:443/
2018.05.02 23:05:17 5: HttpUtils request header:
POST / HTTP/1.0
Host: cloud.vallox.com
User-Agent: fhem
Accept-Encoding: gzip,deflate
Host: cloud.vallox.com
Accept: application/json, text/plain, */*
X-XSRF-TOKEN: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Length: 65

2018.05.02 23:05:17 4: https://cloud.vallox.com:443/: HTTP response code 302
2018.05.02 23:05:17 4: HttpUtils https://cloud.vallox.com:443/: Redirect to https://cloud.vallox.com:443/
2018.05.02 23:05:17 5: HttpUtils url=https://cloud.vallox.com:443/
2018.05.02 23:05:17 5: HttpUtils request header:
POST / HTTP/1.0
Host: cloud.vallox.com
User-Agent: fhem
Accept-Encoding: gzip,deflate
Host: cloud.vallox.com
Accept: application/json, text/plain, */*
X-XSRF-TOKEN: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Length: 65

2018.05.02 23:05:17 5: valloxtest: HandleSendQueue called, qlen = 1
2018.05.02 23:05:17 5: valloxtest: HandleSendQueue - still waiting for reply to last request, delay sending from queue
2018.05.02 23:05:17 4: https://cloud.vallox.com:443/: HTTP response code 302
2018.05.02 23:05:17 4: HttpUtils https://cloud.vallox.com:443/: Redirect to https://cloud.vallox.com:443/
2018.05.02 23:05:17 5: HttpUtils url=https://cloud.vallox.com:443/
2018.05.02 23:05:17 5: HttpUtils request header:
POST / HTTP/1.0
Host: cloud.vallox.com
User-Agent: fhem
Accept-Encoding: gzip,deflate
Host: cloud.vallox.com
Accept: application/json, text/plain, */*
X-XSRF-TOKEN: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Length: 65

2018.05.02 23:05:17 4: https://cloud.vallox.com:443/: HTTP response code 302
2018.05.02 23:05:17 4: HttpUtils https://cloud.vallox.com:443/: Redirect to https://cloud.vallox.com:443/
2018.05.02 23:05:17 5: HttpUtils url=https://cloud.vallox.com:443/
2018.05.02 23:05:17 5: HttpUtils request header:
POST / HTTP/1.0
Host: cloud.vallox.com
User-Agent: fhem
Accept-Encoding: gzip,deflate
Host: cloud.vallox.com
Accept: application/json, text/plain, */*
X-XSRF-TOKEN: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Length: 65

2018.05.02 23:05:17 4: https://cloud.vallox.com:443/: HTTP response code 302
2018.05.02 23:05:17 3: valloxtest: Read callback: Error: https://cloud.vallox.com:443/: Too many redirects
2018.05.02 23:05:17 4: valloxtest: Read callback: request type was auth1 retry 0,
Header: HTTP/1.1 302 Found
Vary: X-HTTP-Method-Override, Accept, Accept-Encoding
Location: /
Content-Type: text/plain; charset=utf-8
Content-Length: 23
set-cookie: connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; Path=/; HttpOnly
Date: Wed, 02 May 2018 21:05:19 GMT
Connection: close, body empty
2018.05.02 23:05:17 5: valloxtest: looking for Cookies in HTTP/1.1 302 Found
Vary: X-HTTP-Method-Override, Accept, Accept-Encoding
Location: /
Content-Type: text/plain; charset=utf-8
Content-Length: 23
set-cookie: connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; Path=/; HttpOnly
Date: Wed, 02 May 2018 21:05:19 GMT
Connection: close
2018.05.02 23:05:17 5: valloxtest: Set-Cookie: connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; Path=/; HttpOnly
2018.05.02 23:05:17 4: valloxtest: Cookie: connect.sid Wert s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk Rest Path=/; HttpOnly
2018.05.02 23:05:17 5: valloxtest: ExtractSid called, context sid, num 1
2018.05.02 23:05:18 5: valloxtest: HandleSendQueue called, qlen = 1
2018.05.02 23:05:18 5: valloxtest: Replace called for type update, regex %%csrf_token%%, mode expression, value {InternalVal("valloxtest","HTTPCookies","")} input:
2018.05.02 23:05:18 5: valloxtest: Replace called for type update, regex %%csrf_token%%, mode expression, value {InternalVal("valloxtest","HTTPCookies","")} input:
2018.05.02 23:05:18 5: valloxtest: Replace called for type update, regex %%csrf_token%%, mode expression, value {InternalVal("valloxtest","HTTPCookies","")} input: https://cloud.vallox.com/cloudui/index.html?deviceid=XXXXXXX
2018.05.02 23:05:18 5: valloxtest: HandleSendQueue is adding Cookies: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
2018.05.02 23:05:18 4: valloxtest: HandleSendQueue sends request type update to URL https://cloud.vallox.com/cloudui/index.html?deviceid=XXXXXXX, No Data,
header: Cookie: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de,
timeout 2
2018.05.02 23:05:18 5: HttpUtils url=https://cloud.vallox.com/cloudui/index.html?deviceid=XXXXXXX
2018.05.02 23:05:18 5: HttpUtils request header:
GET /cloudui/index.html?deviceid=XXXXXXX HTTP/1.0
Host: cloud.vallox.com
User-Agent: fhem
Accept-Encoding: gzip,deflate
Cookie: _csrf=s%3AaO1YTrASIsYRNg8PzYFRaHAM.mpcO%2B6pzP%2B%2BFhkaqhtk1ocPtTCCnzogZH0EAGDlLv5Y; _csrfToken=CZpJc0Tu-I9LLFovCYfAaaT9rNic01-f2di4; connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; lang=de
Content-Length: 0
Content-Type: application/x-www-form-urlencoded

2018.05.02 23:05:18 4: https://cloud.vallox.com/cloudui/index.html?deviceid=XXXXXXX: HTTP response code 200
2018.05.02 23:05:18 5: HttpUtils https://cloud.vallox.com/cloudui/index.html?deviceid=XXXXXXX: Got data, length: 1162
2018.05.02 23:05:18 5: HttpUtils response header:
HTTP/1.1 200 OK
set-cookie: lang=de; Max-Age=604800; Path=/; Expires=Wed, 09 May 2018 21:05:19 GMT
set-cookie: _csrfToken=cU4hPa7f-7JDPHEYW_OrkykbhLwzHYWE4JGg; Path=/
set-cookie: connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; Path=/; HttpOnly
X-Frame-Options: DENY
X-Powered-By: Express
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Fri, 14 Oct 2016 09:49:32 GMT
ETag: W/"48a-157c298bbe0"
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
Content-Encoding: gzip
Date: Wed, 02 May 2018 21:05:19 GMT
Connection: close
2018.05.02 23:05:18 4: valloxtest: Read callback: request type was update retry 0,
Header: HTTP/1.1 200 OK
set-cookie: lang=de; Max-Age=604800; Path=/; Expires=Wed, 09 May 2018 21:05:19 GMT
set-cookie: _csrfToken=cU4hPa7f-7JDPHEYW_OrkykbhLwzHYWE4JGg; Path=/
set-cookie: connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; Path=/; HttpOnly
X-Frame-Options: DENY
X-Powered-By: Express
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Fri, 14 Oct 2016 09:49:32 GMT
ETag: W/"48a-157c298bbe0"
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
Content-Encoding: gzip
Date: Wed, 02 May 2018 21:05:19 GMT
Connection: close,
Body: <!doctype html><html><head><title></title><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><link rel="stylesheet" href="css/minimzd.css"><script src="lib/jquery.js"></script><script src="js/config.js"></script><script src="lib/library.js"></script><script src="js/bundle.js"></script><script>$(document).ready(function(){configurationAfterReady(),Communication.initialize(),CreateDashBoard().showDashboard({cloud:!0}),document.title=L10n.locStr("id_text_web_info_content")});</script></head><body><div data-role="page" data-theme="a" id="dashboard-dashboard-page" class="dashboard-page"></div><div data-role="page" data-theme="a" id="dashboard-info-page" class="dashboard-page"></div><div data-role="page" data-theme="a" id="dashboard-service-page" class="dashboard-page"></div><div data-role="page" data-theme="a" id="dashboard-expert-page" class="dashboard-page"></div><div data-role="page" data-theme="a" id="dashboard-settings-page" class="dashboard-page"></div><div class="dlg-stack-overlay"></div><div id="dlg-window"></div></body></html>
2018.05.02 23:05:18 3: valloxtest: error while parsing JSON data: malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "<!doctype html><html...") at (eval 182317) line 1.

2018.05.02 23:05:18 5: valloxtest: looking for Cookies in HTTP/1.1 200 OK
set-cookie: lang=de; Max-Age=604800; Path=/; Expires=Wed, 09 May 2018 21:05:19 GMT
set-cookie: _csrfToken=cU4hPa7f-7JDPHEYW_OrkykbhLwzHYWE4JGg; Path=/
set-cookie: connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; Path=/; HttpOnly
X-Frame-Options: DENY
X-Powered-By: Express
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Fri, 14 Oct 2016 09:49:32 GMT
ETag: W/"48a-157c298bbe0"
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
Content-Encoding: gzip
Date: Wed, 02 May 2018 21:05:19 GMT
Connection: close
2018.05.02 23:05:18 5: valloxtest: Set-Cookie: lang=de; Max-Age=604800; Path=/; Expires=Wed, 09 May 2018 21:05:19 GMT
2018.05.02 23:05:18 4: valloxtest: Cookie: lang Wert de Rest Max-Age=604800; Path=/; Expires=Wed, 09 May 2018 21:05:19 GMT
2018.05.02 23:05:18 5: valloxtest: Set-Cookie: _csrfToken=cU4hPa7f-7JDPHEYW_OrkykbhLwzHYWE4JGg; Path=/
2018.05.02 23:05:18 4: valloxtest: Cookie: _csrfToken Wert cU4hPa7f-7JDPHEYW_OrkykbhLwzHYWE4JGg Rest Path=/
2018.05.02 23:05:18 5: valloxtest: Set-Cookie: connect.sid=s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk; Path=/; HttpOnly
2018.05.02 23:05:18 4: valloxtest: Cookie: connect.sid Wert s%3Aaw1SEJukyVH6JVUZUw0_H3BnVN-Ml1rd.KCKqXYWyIVMQvPbcdcjuOvZjxHa9BfgDv9gh5v8REPk Rest Path=/; HttpOnly
2018.05.02 23:05:18 5: valloxtest: ExtractSid called, context reading, num
2018.05.02 23:05:18 5: valloxtest: CheckAuth is checking buffer with ReAuthRegex password-input
2018.05.02 23:05:18 4: valloxtest: CheckAuth decided no authentication required
2018.05.02 23:05:18 3: valloxtest: no parsed JSON structure available
2018.05.02 23:05:18 5: valloxtest: Read starts parsing response to update with defined readings:
2018.05.02 23:05:18 3: valloxtest: Read response to update didn't match any Reading
2018.05.02 23:05:18 5: valloxtest: HandleSendQueue called, qlen = 0


Wenn ich in der Gerätedefinition %%csrf_token%% manuell durch den Wert des csrf_token ersetze funktioniert die Kommunikation und ich bekomme die entsprechenden Readings. Ich habe es aber noch nicht geschafft den csrfToken dynamisch auszulesen und dann beim Login wieder an den Server zu schicken.

Grüße,
Joschka

StefanStrobel

Hallo Joshka,

Du musst den vom Server gesendeten Wert direkt aus der HTTP-Response lesen und in ein Reading holen. Dann kannst Du es später per Replacement aus dem Reading wieder in den nächsten Request packen.
Zum Extrahieren in ein Reading brauchst Du einen Namen, eine Regex etc.
Für die Regex würde ich nach _csrfToken= suchen und von dort bis zum Semikolon gehen. Das dazwischen soll in Dein Reading.

Gruss
    Stefan

StefanStrobel

Hallo Joe,

verschachtelte Regexes sollten problemlos funktionieren. Du kannst Sie dann über die Nummer referenzieren oder ihnen einzeln (wo benötigt) per Attribut einen Namen geben.
Über named regex groups hatte ich schon mal nachgedacht, aber keinen wirklichen Mehrwert gesehen. Man würde nur die Namen direkt in der Regex definieren und nicht per einzelnem Attribut.
Dafür wird HTTPMOD aber noch komplexer...
Oder habe ich da was übersehen?

Gruss
    Stefan

JoeALLb

Hallo Stefan,

ich finde, ehrlich gesagt, die momentane Lösung mit eigenen Namen komplexer.
Tauscht ein Wert mal die Reihenfolge, müssen oft mehrere Attribute zusammenpassend angepasst werden. Das wäre damit ales deutlich einfacher.
Wenn man den Namen direkt im Regex angeben kann und das mit einem Beispiel zeigt, glaube ich sogar dass die Anwendung einfacher für die Benutzer wird.
der Konfigurationsaufwand im Modul würde sich auch reduzieren, da ich einfach deutlich weniger Attribute benötige.
Leider kann ich nicht einschätzen, wieviel Codeänderungen das benötigt, aber da Perl ja das ja direkt unterstützt, hoffte ich schlichtweg auf einen nur kleinen
Änderungsbedarf.

sG Joe
FHEM-Server auf IntelAtom+Debian (8.1 Watt), KNX,
RasPi-2 Sonos-FHEM per FHEM2FHEM,RasPi-3 Versuchs-RasPi für WLAN-Tests
Gateways: DuoFern Stick, CUL866 PCA301, CUL HM, HMLan, JeeLink, LaCrosse,VCO2
Synology. Ardurino UNO für 1-Wire Tests, FB7270

StefanStrobel

Ok, auf der Wunschliste ist es schon eine Weile drauf.
Sobald ich Zeit finde, versuche ich es einzubauen.

Gruss
   Stefan

ch.eick

Hallo zusammen,
Leider kann ich momentan nicht helfen,  ich stecke in einer Sanierung:-)
Aber danke für Euer Valox Interesse.

Gruß
   Christian

Gesendet von meinem SM-G930F mit Tapatalk

RPI4; Docker; CUNX; Eltako FSB61NP; SamsungTV H-Serie; Sonos; Vallox; Luxtronik; 3x FB7490; Stromzähler mit DvLIR; wunderground; Plenticore 10 mit BYD; EM410; SMAEM; Modbus TCP
Contrib: https://svn.fhem.de/trac/browser/trunk/fhem/contrib/ch.eick

StefanStrobel

Hallo Joe,

probier doch mal die angehängte Version von HTTPMOD mit einer Regex, die named capture groups enthält.
Problematisch wird es allerdings mit den Attributen zum Formatieren / Aufbereiten einzelner Readings.
reading01-1Expr oder reading01-2Format etc. beziehen sich ja wieder auf die Reihenfolge der capture groups und genau das wolltest Du ja mit den named capture groups vermeiden ...

Gruss
   Stefan

JoeALLb

Hallo Stefan, wow... Bin nur leider gerade auf Dienstreise ohne Zugang zu meinem fhem. Kannst also erst ab Mittwoch testen, sorry.

SG Joe
FHEM-Server auf IntelAtom+Debian (8.1 Watt), KNX,
RasPi-2 Sonos-FHEM per FHEM2FHEM,RasPi-3 Versuchs-RasPi für WLAN-Tests
Gateways: DuoFern Stick, CUL866 PCA301, CUL HM, HMLan, JeeLink, LaCrosse,VCO2
Synology. Ardurino UNO für 1-Wire Tests, FB7270

StefanStrobel

Hier noch eine kleine Erweiterung:
Wenn z.B. reading01Regex mehrere named capture groups besitzt
und eine named capture group beispielsweise "Vorlauf" benannt ist,
dann kann man z.B. ein attribut reading01-12Name Vorlauf setzen.
Das Modul verwendet dann die andere Attribute, die mit reading01-12 beginnen für die Formatierung etc., also zum Beispiel reading01-12Format, reading01-12Map etc.

Statt der fortlaufenden Nummern von capture groups werden also die Namen der named capture groups dazu verwendet, um die passendem Attribute zu finden.
Wenn es keine passenden Attribute gibt, dann wird einfach ein Reading mit dem Namen der named capture group verwendet und keine weitere individuelle Formatierung etc. angewendet.

Gruss
    Stefan

clumsy

Hallo

Nachdem ich nun nach längerem suchen nicht die info gefunden habe die ich brauhce, frage ich mal kurz hier nach: ist es möglich bei einem set[0-9]Data eine (binär)Datei anzugeben welche dann entsprechend mit einem POST request gesendet wird (für Firmware updates von modulen)?

übrigens das eingebaute enforceGoodReadingNames funktioneirt bei mir bestens und die Werte mit Leerschlägen können jetzt auch einfach weiterverwendet werden!

Danke und Gruss