/ Published in: PHP
just replace the XXX fields with your own numbers. Then run this PHP Script from the command line (CLI mode). It will fetch the online statements from Hypovereinsbank direct banking.
The code works by tweaking CURL settings around the HTTPS connection.
The last update (2010-02-12) is because hypo now rotates the viewstate variable on every page (before they did it only once after login).
Expand |
Embed | Plain Text
<?php global $ch; global $Betrag; $inputUsername = 'XXXXXXXXXX'; # place here the Direct banking number $inputPassword = 'XXXXXX'; # place here your pass $outputCSV = '/tmp/Umsatzliste.csv'; require_once 'func/hypo_functions.php'; $step = 0; logF("fetch start"); #define ('RND_LOW', 5); #define ('RND_HIGH', 10); $headers[] = 'Connection: Keep-Alive'; $headers[] = 'Host: my.hypovereinsbank.de'; $headers[] = 'Content-type: application/x-www-form-urlencoded'; $headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; $headers[] = 'Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; $headers[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7'; $headers[] = 'Keep-Alive: 300'; ################################################################### $Url='https://my.hypovereinsbank.de/login?view=/privatkunden/login.jsp'; $cookieFilenameLogin="/tmp/hypo_login.cookie"; $cookieFilenameAuth="/tmp/hypo_auth.cookie"; # first HTTP session : retrieve tr_sid, setcookie etc $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$Url); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFilenameLogin); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFilenameLogin); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_FAILONERROR, 1); $step++; logF($step."th $Url"); $Html = curl_exec ($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close ($ch); fWriteTo("$step.html", $Html); foreach ($linesHtml as $lineHtml) { if (strpos($lineHtml, '<a href="https://my.hypovereinsbank.de/login?view=/privatkunden/login.jsp&tr_sid=')!== false) { } # $javax = substr($lineHtml, strpos($lineHtml, 'id="javax.faces.ViewState" value="')+34, 120); } } if (!$tr_sid) { } if (!$javax) { } ################################################################### $Url .= '&tr_sid='. $tr_sid; # 'directBankingLoginForm:viewInitialized' => 'true', 'username' => $inputUsername, 'px2' => $inputPassword, 'secP' => 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'directBankingLoginForm:loginPanel:loginCommand' => 'Anmelden', 'directBankingLoginForm:_idcl' => '', 'directBankingLoginForm:_link_hidden_' => '', 'directBankingLoginForm_SUBMIT' => '1', 'javax.faces.ViewState' => ($javax), ); $postUrl = http_build_query_wrong($postFields); # second HTTP session : effective login $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$Url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFilenameAuth); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFilenameLogin); #curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_FAILONERROR, 1); #curl_setopt($ch, CURLOPT_VERBOSE, 2); curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); $step++; logF($step."th $Url"); $Html = curl_exec ($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close ($ch); fWriteTo("$step.html", $Html); ################################################################### ################################################################### $Url='https://my.hypovereinsbank.de/login?view=/privatkunden/login.jsp'; $cookieFilenameLogin="/tmp/hypo_login.cookie"; $cookieFilenameAuth="/tmp/hypo_auth.cookie"; # first HTTP session : retrieve tr_sid, setcookie etc $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$Url); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFilenameLogin); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFilenameLogin); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_FAILONERROR, 1); $step++; logF($step."th $Url"); $Html = curl_exec ($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close ($ch); fWriteTo("$step.html", $Html); foreach ($linesHtml as $lineHtml) { if (strpos($lineHtml, '<a href="https://my.hypovereinsbank.de/login?view=/privatkunden/login.jsp&tr_sid=')!== false) { } # $javax = substr($lineHtml, strpos($lineHtml, 'id="javax.faces.ViewState" value="')+34, 120); } } if (!$tr_sid) { } if (!$javax) { } ################################################################### $Url .= '&tr_sid='. $tr_sid; # 'directBankingLoginForm:viewInitialized' => 'true', 'username' => $inputUsername, 'px2' => $inputPassword, 'secP' => 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'directBankingLoginForm:loginPanel:loginCommand' => 'Anmelden', 'directBankingLoginForm:_idcl' => '', 'directBankingLoginForm:_link_hidden_' => '', 'directBankingLoginForm_SUBMIT' => '1', 'javax.faces.ViewState' => ($javax), ); $postUrl = http_build_query_urlencode($postFields); # second HTTP session : effective login $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$Url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFilenameAuth); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFilenameLogin); #curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_FAILONERROR, 1); #curl_setopt($ch, CURLOPT_VERBOSE, 2); curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); $step++; logF($step."th $Url"); $Html = curl_exec ($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close ($ch); fWriteTo("$step.html", $Html); foreach ($lines as $line) { $Var_idcl = $pieces[3]; } } if (!$Var_idcl) { print "ERROR: Cannot fetch idcl"; # exit; } logF($step ."th idcl: $Var_idcl"); $cookieStr = ''; foreach ($cookiearr as $cookieName => $cookieVal) { $cookieStr.=$cookieName.'='.$cookieVal.'; '; } ################################################################### ################################################################### # go to account $Url='https://my.hypovereinsbank.de/portal?view=/banking/accountManagement.jsp'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$Url); curl_setopt($ch, CURLOPT_COOKIE, $cookieStr); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_FAILONERROR, 1); #curl_setopt($ch, CURLOPT_VERBOSE, 2); $step++; logF($step."th $Url"); $Html = curl_exec ($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close ($ch); fWriteTo("$step.html", $Html); ################################################################### $liveStart = false; foreach ($lines as $line) { $liveStart = true; } $liveStart = false; } } } if ($lineParts2[1]) { $Betrag[1] = $lineParts2[1]; } else { } } } logF("Kontostand live ... " . $Betrag[0] ." EUR"); logF("Kontostand old ... " . $Betrag[1] ." EUR"); if (!$Betrag) { } foreach ($linesHtml as $lineHtml) { if (strpos($lineHtml, '<a href="https://my.hypovereinsbank.de/login?view=/privatkunden/login.jsp&tr_sid=')!== false) { } # $javax = substr($lineHtml, strpos($lineHtml, 'id="javax.faces.ViewState" value="')+34, 120); } } if (!$tr_sid) { } if (!$javax) { } #var_dump($Betrag); ################################################################### $Url = 'https://my.hypovereinsbank.de/portal?view=/banking/accountManagement.jsp'; 'accountManagement:dayFrom' => '1', 'accountManagement:numberOfTurnovers' => '9999', 'accountManagement:refresh' => 'Anzeigen', # 'accountManagement:buttonNavigation:j_id_id142' => 'Download Kontoums�¤tze ', 'accountManagement:_link_hidden_' => '', 'accountManagement:_idcl' => '', 'accountManagement_SUBMIT' => '1', 'javax.faces.ViewState' => ($javax), ); $postUrl = http_build_query_urlencode($postFields); # post-login steps $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$Url); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_COOKIE, $cookieStr); #curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_REFERER, 'https://my.hypovereinsbank.de/portal?view=/banking/startpage.jsp'); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_FAILONERROR, 1); #curl_setopt($ch, CURLOPT_VERBOSE, 2); $step++; logF($step."th $Url"); $Html = curl_exec ($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close ($ch); fWriteTo("$step.html", $Html); foreach ($linesHtml as $lineHtml) { if (strpos($lineHtml, '<a href="https://my.hypovereinsbank.de/login?view=/privatkunden/login.jsp&tr_sid=')!== false) { } # $javax = substr($lineHtml, strpos($lineHtml, 'id="javax.faces.ViewState" value="')+34, 120); } } if (!$tr_sid) { } if (!$javax) { } ################################################################### ################################################################### $Url = 'https://my.hypovereinsbank.de/portal?view=/banking/accountManagement.jsp'; ## 'accountManagement:monthFrom' => strftime("%B %Y"), 'accountManagement:numberOfTurnovers' => '9999', ## 'accountManagement:numberOfTurnovers' => '20', # 'accountManagement:refresh' => 'Anzeigen', 'accountManagement:_link_hidden_' => '', 'accountManagement:_idcl' => '', 'accountManagement_SUBMIT' => '1', 'javax.faces.ViewState' => ($javax), ); $postUrl = http_build_query_urlencode($postFields); # post-login steps $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$Url); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_COOKIE, $cookieStr); #curl_setopt($ch, CURLOPT_VERBOSE, TRUE); #curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); #curl_setopt($ch, CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); #curl_setopt($ch, CURLOPT_REFERER, 'https://my.hypovereinsbank.de/portal?view=/banking/startpage.jsp'); curl_setopt($ch, CURLOPT_REFERER, $Url); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); #curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_VERBOSE, 2); $step++; logF($step."th $Url"); $Html = curl_exec ($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close ($ch); fWriteTo("$step.html", $Html); ################################################################### ################################################################### ################################################################### # party over, logout $Url='https://my.hypovereinsbank.de/login?view=/privatkunden/logout.jsp'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$Url); curl_setopt($ch, CURLOPT_COOKIE, $cookieStr); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); curl_setopt($ch, CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_FAILONERROR, 1); #curl_setopt($ch, CURLOPT_VERBOSE, 2); $step++; logF($step."th $Url"); $Html = curl_exec ($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close ($ch); fWriteTo("$step.html", $Html); ################################################################### ################################################################### function http_build_query_urlencode($postFields) { $postUrl = ""; foreach ($postFields as $fName => $fValue) { # $postUrl.=($fName).'='.rawurlencode($fValue)."&"; } } function http_build_query_wrong($postFields) { $postUrl = ""; foreach ($postFields as $fName => $fValue) { # $postUrl.=($fName).'='.rawurlencode($fValue)."&"; } } function read_header($ch, $string) { global $ch; # ^overrides the function param $ch # this is okay because we need to # update the global $ch with # new cookies { #keep track of last redirect } { #get the cookie } $cookie = ""; { #execute only at end of header foreach ($cookiearr as $key=>$value) { $cookie .= "$key=$value; "; } curl_setopt($ch, CURLOPT_COOKIE, $cookie); } return $length; } ?>
Comments
Subscribe to comments
You need to login to post a comment.

tested with PHP 4.4.0 and curl 7.14.0
Does anyone know if this script still works? Can't test this because i don't have an HVB account yet.