Autor Thema: [gelöst] [HTTPMOD] Login mit ASP.NET und zusätzlichen login parametern?  (Gelesen 980 mal)

Offline roman1528

  • Sr. Member
  • ****
  • Beiträge: 735
    • ueberueck.com
Okay ... Ich schließe das hier erstmal ab. Versuche derweil was anderes. Da ist dein Wissen wahrscheinlich auch wieder gefragt  ;D

Fazit: Funktioniert. Warum die Timeouts weiß ich nicht... habe ich in anderen Devices aber leider auch.. ich werde forschen.

Device:
define dr_solar_smartme HTTPMOD https://www.smart-me.com/Details/GetDetailsNew.ashx?id=<ID> 10
attr dr_solar_smartme userattr reading01Name reading01XPath-Strict reading02Name reading02XPath-Strict reading03Name reading03XPath-Strict reading04Name reading04XPath-Strict reading05Name reading05XPath-Strict reading06Name reading06XPath-Strict reading07Name reading07XPath-Strict reading08Name reading08XPath-Strict reading09Name reading09XPath-Strict reading10Name reading10XPath-Strict reading11Name reading11XPath-Strict reading12Name reading12XPath-Strict reading13Name reading13XPath-Strict reading14Name reading14XPath-Strict reading15Name reading15XPath-Strict reading16Name reading16XPath-Strict reading17Name reading17XPath-Strict reading18Name reading18XPath-Strict reading19Name reading19OExpr reading19XPath-Strict reading20Name reading20XPath-Strict replacement01Mode:reading,internal,text,expression,key replacement01Regex replacement01Value requestHeader1 requestHeader2 requestHeader3 set01Header1 set01Header2 set01Header3 set01Header4 set01IMap set01Method:GET,POST,PUT set01Name set01ParseResponse:0,1 set01URL sid01IdRegex sid01URL sid02Data sid02ParseResponse:0,1 sid02URL sidHeader01 sidHeader02 sidHeader03
attr dr_solar_smartme dontRequeueAfterAuth 1
attr dr_solar_smartme enableControlSet 1
attr dr_solar_smartme enableCookies 1
attr dr_solar_smartme event-on-change-reading .*
attr dr_solar_smartme httpVersion 1.1
attr dr_solar_smartme reAuthRegex /SignIn.aspx.*
attr dr_solar_smartme reading01Name Name
attr dr_solar_smartme reading01XPath-Strict /Folder/FolderName/text()
attr dr_solar_smartme reading02Name ID
attr dr_solar_smartme reading02XPath-Strict /Folder/ID/text()
attr dr_solar_smartme reading03Name SerialNumber
attr dr_solar_smartme reading03XPath-Strict /Folder/SerialNumber/text()
attr dr_solar_smartme reading04Name Power
attr dr_solar_smartme reading04XPath-Strict /Folder/Elements/Element[1]/Value/text()
attr dr_solar_smartme reading05Name Switch
attr dr_solar_smartme reading05XPath-Strict /Folder/Elements/Element[3]/Value/text()
attr dr_solar_smartme reading06Name Counters
attr dr_solar_smartme reading06XPath-Strict /Folder/Elements/Element[4]/Value/text()
attr dr_solar_smartme reading07Name CounterTotalT1
attr dr_solar_smartme reading08Name CounterTotalT2
attr dr_solar_smartme reading09Name CounterImportTotal
attr dr_solar_smartme reading10Name CounterImportT1
attr dr_solar_smartme reading11Name CounterImportT2
attr dr_solar_smartme reading12Name CounterExportTotal
attr dr_solar_smartme reading13Name CounterExportT1
attr dr_solar_smartme reading14Name CounterExportT2
attr dr_solar_smartme reading15Name ActiveTariff
attr dr_solar_smartme reading15XPath-Strict /Folder/Elements/Element[4]/Tariff/text()
attr dr_solar_smartme reading16Name Voltage
attr dr_solar_smartme reading16XPath-Strict /Folder/Elements/Element[5]/Value/text()
attr dr_solar_smartme reading17Name Current
attr dr_solar_smartme reading17XPath-Strict /Folder/Elements/Element[6]/Value/text()
attr dr_solar_smartme reading18Name PowerFactor
attr dr_solar_smartme reading18XPath-Strict /Folder/Elements/Element[7]/Value/text()
attr dr_solar_smartme reading19Name LastConnect
attr dr_solar_smartme reading19OExpr FmtDateTime($val)
attr dr_solar_smartme reading19XPath-Strict /Folder/Elements/Element[9]/Value/text()
attr dr_solar_smartme reading20Name Consumption
attr dr_solar_smartme reading20XPath-Strict /Folder/Elements/Element[8]/Value/text()
attr dr_solar_smartme replacement01Mode expression
attr dr_solar_smartme replacement01Regex %%LOGIN%%
attr dr_solar_smartme replacement01Value generateLogin($defs{dr_solar_smartme}{sid})
attr dr_solar_smartme requestHeader1 Referer: https://www.smart-me.com/Details/V2/All.aspx
attr dr_solar_smartme requestHeader2 User-Agent: Mozilla/5.0 (Windows NT 10.0;; Win64;; x64;; rv:78.0) Gecko/20100101 Firefox/78.0
attr dr_solar_smartme requestHeader3 Host: www.smart-me.com
attr dr_solar_smartme set01Header1 Accept: application/json
attr dr_solar_smartme set01Header2 Authorization: Basic XXXXXXXXXXXXXXXXXXXXXX
attr dr_solar_smartme set01Header3 Content-Length: 0
attr dr_solar_smartme set01Header4 User-Agent: Mozilla/5.0 (Windows NT 10.0;; Win64;; x64;; rv:78.0) Gecko/20100101 Firefox/78.0
attr dr_solar_smartme set01IMap false:off, true:on
attr dr_solar_smartme set01Method PUT
attr dr_solar_smartme set01Name switch
attr dr_solar_smartme set01ParseResponse 1
attr dr_solar_smartme set01URL https://smart-me.com:443/api/Devices/<ID>?switchState=$val&switchNumber=1
attr dr_solar_smartme showBody 1
attr dr_solar_smartme showError 1
attr dr_solar_smartme sid01IdRegex (?s)(__VIEWSTATE.*?__EVENTVALIDATION.*?)\/>
attr dr_solar_smartme sid01URL https://www.smart-me.com/SignIn.aspx?ReturnUrl=%2fDetails%2fGetDetailsNew.ashx%3fid%3d<ID>&id=<ID>
attr dr_solar_smartme sid02Data %%LOGIN%%
attr dr_solar_smartme sid02ParseResponse 1
attr dr_solar_smartme sid02URL https://www.smart-me.com/SignIn.aspx?ReturnUrl=%2fDetails%2fGetDetailsNew.ashx%3fid%3d<ID>&id=<IID>
attr dr_solar_smartme sidHeader01 Origin: https://www.smart-me.com
attr dr_solar_smartme sidHeader02 https://www.smart-me.com/SignIn.aspx?ReturnUrl=%2fDetails%2fGetDetailsNew.ashx%3fid%3d<ID&id=<ID>
attr dr_solar_smartme sidHeader03 User-Agent: Mozilla/5.0 (Windows NT 10.0;; Win64;; x64;; rv:78.0) Gecko/20100101 Firefox/78.0
attr dr_solar_smartme timeout 20
attr dr_solar_smartme verbose 5

myUtils:
sub urlencode {
    my $s = shift;
    $s =~ s/ /+/g;
    $s =~ s/([^A-Za-z0-9-\.])/sprintf("%%%02X", ord($1))/seg;
    return $s;
}

sub generateLogin {
my ($sid) = shift;
my $username = 'e@mail.com';
my $password = 'XXXXXXXXXX';
$sid =~ /__VIEWSTATE" value="(.*?)".*?__VIEWSTATEGENERATOR" value="(.*?)".*?__EVENTVALIDATION" value="(.*?)"/gs;
my $login = '__VIEWSTATE='.urlencode($1);
$login .= '&__VIEWSTATEGENERATOR='.urlencode($2);
$login .= '&__EVENTVALIDATION='.urlencode($3);
$login .= '&ctl00$ContentPlaceHolder1$Login1$UserName='.urlencode($username);
$login .= '&ctl00$ContentPlaceHolder1$Login1$Password='.urlencode($password);
$login .= '&ctl00$ContentPlaceHolder1$Login1$ctl01=Login';
return $login;
}

Vielen Dank amenomade, du hast mir sehr sehr sehr geholfen!

Grüße^^
Intel Atom 2x2,13GHz;4GB RAM;60GB SSD;8TB als NAS: FHEM 6.0,FTUI,AMAD,8" Tablet's+Fully;HUE;ESPRGBWW;HM;ESP8266;CUL433;CUL868;Duofern;ASC;MQTT;mySensors
RPi3+: FHEM 6.0;I²C;GPIO;WigandRFID;G-Tag;XiaomiBTLESens
RPi3: FHEM 6.0;DIY Relais-Board;I²C;GPIO;600W Solar;smart-me
FHEM&FTUI: www.ueberueck.com

 

decade-submarginal