Hallo,
möchte per HTTPMOD auf meine KWL (Komfovent) zugreifen. Ich komme aber über die Passwortabfrage nicht hinweg. Im Eingeloggten Zustand funktioniert alles, aber ich glaube dass es am sid Data Liegt.
Leider finde ich keine Syntaxdefinition oder ein Howto wie es angegeben werden muss.
Ich habe im Debug Mode herausgefunden, dass die Anfrage "1:user" "2:password" zum Login gesendet wird. Unformetiert sieht es so aus "1=user&2=password"
Wie findet man heraus welche Daten als sidData eingegeben werden müssen um das Login zu schaffen.
Kann ich herausfinden ob das sidData überbaupt gesendet wurde (evtl hakt das ganze schon vorher?).
Danke für Hinweise!
Das session-handling von HTTPMOD ist doch in der commandref ausführlich beschrieben?
Was Fem macht ist gut beschrieben, aber nicht wie ich herausfinde was ich FHEM als Input geben muss.
Commandref:
Handling sessions and logging in
In simple cases logging in works with basic authentication. In the case HTTPMOD accepts a username and password as part of the URL in the form http://User:Password@192.168.1.18/something
However basic auth is seldom used. If you need to fill in a username and password in a HTML form and the session is then managed by a session id, here is how to configure this: when sending data to an HTTP-Device in a set, HTTPMOD will replace any $sid in the URL, Headers and Post data with the internal $hash->{sid}. To authenticate towards the device and give this internal a value, you can use an optional multi step login procedure defined by the following attributes:
sid[0-9]*URL
sid[0-9]*Data.*
sid[0-9]*Header.*
idRegex
idJSON
idXPath
idXPath-Strict
(get|set|sid)[0-9]*IdRegex
(get|set|sid)[0-9]*IdJSON
(get|set|sid)[0-9]*IdXPath
(get|set|sid)[0-9]*IdXPath-Strict
Each step can have a URL, Headers and Post Data. To extract the actual session Id, you can use regular expressions, JSON or XPath just like for the parsing of readings but with the attributes (get|set|sid)[0-9]*IdRegex, (get|set|sid)[0-9]*IdJSON, (get|set|sid)[0-9]*IdXPath or (get|set|sid)[0-9]*IdXPath-Strict.
An extracted session Id will be stored in the internal $hash->{sid}.
HTTPMOD will create a sorted list of steps (the numbers between sid and URL / Data / Header) and the loop through these steps and send the corresponding requests to the device. For each step a $sid in a Header or Post Data will be replaced with the current content of $hash->{sid}.
Using this feature, HTTPMOD can perform a forms based authentication and send user name, password or other necessary data to the device and save the session id for further requests.
If for one step not all of the URL, Data or Header Attributes are set, then HTTPMOD tries to use a sidURL, sidData.* or sidHeader.* Attribue (without the step number after sid). This way parts that are the same for all steps don't need to be defined redundantly.
To determine when this login procedure is necessary, HTTPMOD will first try to send a request without doing the login procedure. If the result contains an error that authentication is necessary, then a login is performed. To detect such an error in the HTTP response, you can again use a regular expression, JSON or XPath, this time with the attributes
reAuthRegex
reAuthJSON
reAuthXPath
reAuthXPath-Strict
[gs]et[0-9]*ReAuthRegex
[gs]et[0-9]*ReAuthJSON
[gs]et[0-9]*ReAuthXPath
[gs]et[0-9]*ReAuthXPath-Strict
reAuthJSON or reAuthXPath typically only extract one piece of data from a response. If the existance of the specified piece of data is sufficent to start a login procedure, then nothing more needs to be defined to detect this situation. If however the indicator is a status code that contains different values depending on a successful request and a failed request if a new authentication is needed, then you can combine things like reAuthJSON with reAuthRegex. In this case the regex is only matched to the data extracted by JSON (or XPath). This way you can easily extract the status code using JSON parsing and then specify the code that means "authentication needed" as a regular expression.
Example for a multi step login procedure:
attr PM reAuthRegex /html/dummy_login.htm attr PM sidURL http://192.168.70.90/cgi-bin/webgui.fcgi?sid=$sid
attr PM sidHeader1 Content-Type: application/json
attr PM sid1IdRegex wui.init\('([^']+)'
attr PM sid2Data {"set" :{"9.17401.user" :"fhem" ,"9.17401.pass" :"password" }}
attr PM sid3Data {"set" :{"35.5062.value" :"128" }}
attr PM sid4Data {"set" :{"42.8026.code" :"pincode" }}
geht schon los mit den attributen: sid[0-9]*Data.*
wird in der commandref beschrieben mit "sid[0-9]*Data.*
data part for each step to be sent as POST data to the corresponding URL "
Kein Wort über die Syntax oder ie man überhaupt an die Daten kommt die gesendet werden sollen. In Fhem muss man dieses Attribut über die commandozeile eintragen weil es über die Attributwahl immer Fehlermeldungen gibt. Es wäre also schon schön zu wissen wie das ganze eingegeben werden muss (insbesondere Nummerierung und Leerzeichen).
Im Beispiel sieht man dann attr PM sid2Data {"set" :{"9.17401.user" :"fhem" ,"9.17401.pass" :"password" }} also muss "Data anscheinend in Geschweifte Klammern (warum?) und dann kommt irgendein Inhalt aus FHEM, der mir auch nicht sagt wie der Autor an diese Daten gekommen ist (meine Frage).
Ich finde die Beschreibung in der commandref beschreibt die interne Funktion ganz gut, die Umsetzung eher mäßig, und meine Frage "Wie finde ich heraus was ich denn als "Data" eintragen soll" ist in meinen Augen gar nicht beschrieben.
Oder ich suche und lese falsch?
Und in dem Beispiel bleiben auch offene Fragen:
Example for a multi step login procedure:
attr PM reAuthRegex /html/dummy_login.htm attr PM sidURL http://192.168.70.90/cgi-bin/webgui.fcgi?sid=$sid
attr PM sidHeader1 Content-Type: application/json
attr PM sid1IdRegex wui.init\('([^']+)'
attr PM sid2Data {"set" :{"9.17401.user" :"fhem" ,"9.17401.pass" :"password" }}
attr PM sid3Data {"set" :{"35.5062.value" :"128" }}
attr PM sid4Data {"set" :{"42.8026.code" :"pincode" }}
In this case HTTPMOD detects that a login is necessary by looking for the pattern /html/dummy_login.htm in the HTTP response. If it matches, it starts a login sequence. In the above example all steps request the same URL. In step 1 only the defined header is sent in an HTTP get request. The response will contain a session id that is extraced with the regex wui.init\('([^']+)'. In the next step this session id is sent in a post request to the same URL where tha post data contains a username and password. The a third and a fourth request follow that set a value and a code. The result will be a valid and authorized session id that can be used in other requests where $sid is part of a URL, header or post data and will be replaced with the session id extracted above.
Woher weiß man dass der Header als get aufgerufen wird, aber die Session ID als POST geschickt wird? die letzen beiden sind "set", das ist für mich ersichtlich...
Zitat von: FrauMeier am 14 November 2022, 19:43:15
Was Fhem macht ist gut beschrieben, aber nicht wie ich herausfinde was ich FHEM als Input geben muss.
< snip >
Moin,
die Inhalte der zusendenden Daten ist abhängig von der WebSeite. Was dort erwartet wird kann FHEM nicht wissen.
Da hilft nur ein Trace einer funktionierenden Anmeldung, die man dann mit den entsprechenden Attributen nachbilden muss.
Auch ich habe eine KWL, für die ich eine Python Anbindung gefunden habe, jedoch bekomme ich nicht heraus, wie der Aufbau einer Session sein muss.
VG Christian
Genau, es ist abhängig von der Webseite und man muss tracen. Soweit bin ich auch schon, brauche aber hilfe beim Tracen. Hat das denn noch niemand gemacht der sich mit webseitenprogrammierung besser auskennt und ein Paar Tips geben kann?
Zitat von: FrauMeier am 15 November 2022, 12:01:43
Genau, es ist abhängig von der Webseite und man muss tracen. Soweit bin ich auch schon, brauche aber hilfe beim Tracen. Hat das denn noch niemand gemacht der sich mit webseitenprogrammierung besser auskennt und ein Paar Tips geben kann?
Für einige Anbindung gibt es da bestimmt jemanden, jedoch z.B. eine KWL an FHEM und dann noch genau die, die man auch hat, da wird es sehr schwierig.
Wie gesagt, ich habe für meine KWL ein Python Skript, dass bereits funktioniert, aber trotzdem bekomme ich es nicht in FHEM nachgebaut :-(
Bei anderen WebSeiten klappt es dann wiederum sehr gut. Leider ist jedes Gerät mit Web Interface wieder eine total neue Erfahrung.
Das HTTPMOD bietet nur den Werkzeugkasten.
Ich habe es jetzt hinbekommen und eine kleine Anleitung der generellen Vorgehensweise gemacht (Anhang).
Das Problem war der header der Anfrage den ich nicht korrekt hinbekommen hatte. Ich habe ihn letztendlich direkt aus Firefox herauskopiert und als sidHeader eingetragen.
Ich hoffe der Anhang hilft irgendwem.
Zitat von: FrauMeier am 17 November 2022, 10:44:14
Ich habe es jetzt hinbekommen und eine kleine Anleitung der generellen Vorgehensweise gemacht (Anhang).
Das Problem war der header der Anfrage den ich nicht korrekt hinbekommen hatte. Ich habe ihn letztendlich direkt aus Firefox herauskopiert und als sidHeader eingetragen.
Ich hoffe der Anhang hilft irgendwem.
Okay, danke.
Die Vorgehensweise hatte ich als Grundlage vorausgesetzt, denn man versucht ja den HTTP Request nachzubauen.
Man kann die Information aus dem Browser entnehmen und später dann noch empirisch testen, was davon wirklich gebraucht wird.
Ich nehme zuerst so ziemlich alles mit ins HTTPMOD rüber und wenn es läuft dünne ich aus, bis es nicht mehr akzeptiert wird.
Burp oder wiresharc sind auch sehr gute Tools für das tracen.