Опытный
Профиль
Группа: Участник
Сообщений: 394
Регистрация: 30.12.2008
Репутация: нет Всего: нет
|
Пробую так Код | <?php class PublisherReprter { private $fpKey; private $Username; private $Password; private $IsDebug= true; private $CookeiFilename; private $strCookie; // public function setLogin( $Username, $Password ) { public function PublisherReprter() { $this->CookieFilename= dirname(__FILE__) . DIRECTORY_SEPARATOR . "my_cookies.txt"; session_start(); $this->strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=' . $this->CookieFilename; echo '<br>$strCookie::'.print_r( $strCookie,true).'<br>'; if ($this->IsDebug) echo 'PublisherReprter $this->CookieFilename::'.print_r($this->CookieFilename,true).'<br>';
} public function Run() { $LoginPageHTML= $this->OpenLoginPage(); //Open Login page to get value of __fp field for CSRF protection $this->Get__fpKey($LoginPageHTML); // retrieve __fp key from html from login page if ($this->IsDebug) echo 'Get__fpKey $this->fpKey::'.print_r($this->fpKey,true).'<br>';
$Res= $this->MakeLogToSite(); // make login to form using SRF protection from prior step and login parameters if ($this->IsDebug) echo '++$Res::'.print_r($Res,true).'<br>'; if ( $Res ) { $Res= $this->GetReportData(); // get report data using SRF protection from and from prior login if ($this->IsDebug) echo '++!!!@@ $Res::'.print_r($Res,true).'<br>'; } } // public function Run() {
public function setLogin( $pUsername, $pPassword ) { $this->Username= $pUsername; $this->Password= $pPassword; }
private function Get__fpKey($html) { $Pattern = '/"__fp"[\s]*value=[\s]*"([^"]*)".*?' . '$/xsi'; $Res= preg_match( $Pattern, $html, $A/*(, PREG_OFFSET_CAPTURE*/ ); if ( $Res and !empty($A[1]) ) { $this->fpKey= $A[1]; return true; } return false; } // private function Get__fpKey($html) {
private function OpenLoginPage() { $url = "http://leadserve.opt-intelligence.com/ls/reports.action"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); // set url to post to curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects // curl_setopt($ch, CURLOPT_COOKIEJAR, /* dirname(__FILE__) .*/ "my_cookies.txt"); // curl_setopt($ch, CURLOPT_COOKIEFILE, /* dirname(__FILE__) . */ "my_cookies.txt"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s //curl_setopt($ch,CURLOPT_HEADER,true); $result = curl_exec($ch); // run the whole process $curl_errno= curl_errno($ch); if ($this->IsDebug) echo '<hr><h2>OpenLoginPage</h2><hr>'; if ($this->IsDebug) echo 'LOGIN $ch::'.print_r( $ch,true ).'<br>'; if ($this->IsDebug) echo 'LOGIN curl_errno($ch)::'.print_r( curl_errno($ch),true ).'<br>'; if ($this->IsDebug) echo 'LOGIN curl_error($ch)::'.print_r( curl_error($ch),true ).'<br>'; if ($this->IsDebug) echo 'LOGIN curl_getinfo($ch)::'.print_r( curl_getinfo($ch),true ).'<br>'; if ($this->IsDebug) echo '$_COOKIE::'.print_r( $_COOKIE,true).'<br>'; if ($this->IsDebug) echo '$_SESSION::'.print_r( $_SESSION,true).'<br>'; curl_close($ch); if ($this->IsDebug) echo '<hr>LOGIN<hr>'; return $result; } // private function OpenLoginPage() {
private function GetReportData( ) { $ch = curl_init('http://leadserve.opt-intelligence.com/ls/reports.action'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_REFERER, "http://leadserve.opt-intelligence.com/ls/reports.action"); curl_setopt($ch, CURLOPT_POSTFIELDS, 'date=dr&d1=d&f2=p&f4='.urlencode('03/01/2013').'&f5=' .urlencode('03/31/2013').'&_sourcePage='.urlencode('/WEB-INF/jsp/reports/pageReports.jsp').'&__fp='.urlencode($this->fpKey) ); //curl_setopt($ch, CURLOPT_COOKIEJAR, /* dirname(__FILE__) .*/ "my_cookies.txt"); //curl_setopt($ch, CURLOPT_COOKIEFILE, /* dirname(__FILE__) .*/ "my_cookies.txt"); curl_setopt( $curl_handle, CURLOPT_COOKIE, $this->strCookie ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $content= curl_multi_getcontent($ch); curl_setopt($ch,CURLOPT_HEADER,true); $result = curl_exec($ch); $curl_errno= curl_errno($ch); if ($this->IsDebug) echo '<hr><h2>GetReportData: </h2><hr>'; if ($this->IsDebug) echo '$content::'.print_r( $content,true).'<br>'; if ($this->IsDebug) echo $result; if ($this->IsDebug) echo '<br>$result::'.print_r( $result,true).'<br>'; if ($this->IsDebug) echo '$ch::'.print_r( $ch,true ).'<br>'; if ($this->IsDebug) echo 'curl_errno($ch)::'.print_r( curl_errno($ch),true ).'<br>'; if ($this->IsDebug) echo 'curl_error($ch)::'.print_r( curl_error($ch),true ).'<br>'; if ($this->IsDebug) echo 'curl_getinfo($ch)::'.print_r( curl_getinfo($ch),true ).'<br>'; curl_close($ch); return $curl_errno == 0; } // private function GetReportData( ) {
private function MakeLogToSite() { $ch = curl_init('http://leadserve.opt-intelligence.com/ls/signin.action'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_REFERER, "http://leadserve.opt-intelligence.com/ls/signin.action"); curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.urlencode($this->Username).'&password='.urlencode($this->Password).'&_sourcePage='.urlencode('/WEB-INF/jsp/common/signin.jsp').'&__fp='.urlencode($this->fpKey) ); // curl_setopt($ch, CURLOPT_COOKIEJAR, /* dirname(__FILE__) . */ "my_cookies.txt"); // curl_setopt($ch, CURLOPT_COOKIEFILE, /* dirname(__FILE__) . */ "my_cookies.txt"); curl_setopt( $curl_handle, CURLOPT_COOKIE, $this->strCookie ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_HEADER,true); $result = curl_exec($ch); $curl_errno= curl_errno($ch); if ($this->IsDebug) echo '<hr><h2>MakeLogToSite</h2><hr>'; if ($this->IsDebug) echo $result; if ($this->IsDebug) echo '<br>$result::'.print_r( $result,true).'<br>'; if ($this->IsDebug) echo '$ch::'.print_r( $ch,true ).'<br>'; if ($this->IsDebug) echo 'curl_errno($ch)::'.print_r( curl_errno($ch),true ).'<br>'; if ($this->IsDebug) echo 'curl_error($ch)::'.print_r( curl_error($ch),true ).'<br>'; if ($this->IsDebug) echo 'curl_getinfo($ch)::'.print_r( curl_getinfo($ch),true ).'<br>'; if ($this->IsDebug) echo '$_COOKIE::'.print_r( $_COOKIE,true).'<br>'; if ($this->IsDebug) echo '$_SESSION::'.print_r( $_SESSION,true).'<br>'; curl_close($ch); return $curl_errno == 0; } // private function MakeLogToSite() {
} // class PublisherReprter {
$PublisherReprter= new PublisherReprter(); $PublisherReprter->setLogin( '[email protected]', 'password' ); $PublisherReprter->Run();
|
У меня получается такой вывод на экран Код | $strCookie:: PublisherReprter $this->CookieFilename::/mnt/diskD_Work/wwwroot/cashcrate-externals/my_cookies.txt OpenLoginPage LOGIN $ch::Resource id #2 LOGIN curl_errno($ch)::0 LOGIN curl_error($ch):: LOGIN curl_getinfo($ch)::Array ( [url] => http://leadserve.opt-intelligence.com/ls/signin.action [content_type] => text/html;charset=ISO-8859-1 [http_code] => 200 [header_size] => 968 [request_size] => 171 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 1 [total_time] => 0.781794 [namelookup_time] => 1.6E-5 [connect_time] => 1.6E-5 [pretransfer_time] => 3.5E-5 [size_upload] => 0 [size_download] => 9795 [speed_download] => 12528 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0.141601 [redirect_time] => 0.502944 [certinfo] => Array ( ) [redirect_url] => ) $_COOKIE::Array ( [PHPSESSID] => ttcjf95r6t5qu2rusn8fpfchm4 ) $_SESSION::Array ( ) LOGINGet__fpKey $this->fpKey::f+8KFTt1Wg+Rgc8eorQdhg== MakeLogToSite HTTP/1.1 200 OK Cache-control: no-cache="set-cookie" Content-Language: en-US Content-length: 9795 Content-Type: text/html;charset=ISO-8859-1 Date: Sun, 10 Mar 2013 08:16:13 GMT Set-Cookie: JSESSIONID=F04BA850A1DCB9CC39EADE70B38D665B; Path=/ls Set-Cookie: AWSELB=D171A3C314A759266FA0800BD41453A838AAFE90EC88BCF5FA39A459FDD713F494AEF2D49AE57739FF0B04EC5C1F189F5D5895521075CCDA5507BC9B3EF8BE820FBA0C5C60;PATH=/;MAX-AGE=86400 Connection: keep-alive $result::HTTP/1.1 200 OK Cache-control: no-cache="set-cookie" Content-Language: en-US Content-length: 9795 Content-Type: text/html;charset=ISO-8859-1 Date: Sun, 10 Mar 2013 08:16:13 GMT Set-Cookie: JSESSIONID=F04BA850A1DCB9CC39EADE70B38D665B; Path=/ls Set-Cookie: AWSELB=D171A3C314A759266FA0800BD41453A838AAFE90EC88BCF5FA39A459FDD713F494AEF2D49AE57739FF0B04EC5C1F189F5D5895521075CCDA5507BC9B3EF8BE820FBA0C5C60;PATH=/;MAX-AGE=86400 Connection: keep-alive $ch::Resource id #3 curl_errno($ch)::0 curl_error($ch):: curl_getinfo($ch)::Array ( [url] => http://leadserve.opt-intelligence.com/ls/signin.action [content_type] => text/html;charset=ISO-8859-1 [http_code] => 200 [header_size] => 456 [request_size] => 151 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.28221 [namelookup_time] => 2.2E-5 [connect_time] => 0.138958 [pretransfer_time] => 0.138987 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 9795 [upload_content_length] => 0 [starttransfer_time] => 0.282177 [redirect_time] => 0 [certinfo] => Array ( ) [redirect_url] => ) $_COOKIE::Array ( [PHPSESSID] => ttcjf95r6t5qu2rusn8fpfchm4 ) $_SESSION::Array ( ) ++$Res::1 GetReportData: $content:: HTTP/1.1 302 Moved Temporarily Cache-control: no-cache="set-cookie" Content-Type: text/plain; charset=UTF-8 Date: Sun, 10 Mar 2013 08:16:14 GMT Location: http://leadserve.opt-intelligence.com/ls/signin.action Set-Cookie: JSESSIONID=FC8AB7B237800F86C4021E253191E1CF; Path=/ls Set-Cookie: AWSELB=D171A3C314A759266FA0800BD41453A838AAFE90EC88BCF5FA39A459FDD713F494AEF2D49AE57739FF0B04EC5C1F189F5D5895521075CCDA5507BC9B3EF8BE820FBA0C5C60;PATH=/;MAX-AGE=86400 Connection: keep-alive $result::HTTP/1.1 302 Moved Temporarily Cache-control: no-cache="set-cookie" Content-Type: text/plain; charset=UTF-8 Date: Sun, 10 Mar 2013 08:16:14 GMT Location: http://leadserve.opt-intelligence.com/ls/signin.action Set-Cookie: JSESSIONID=FC8AB7B237800F86C4021E253191E1CF; Path=/ls Set-Cookie: AWSELB=D171A3C314A759266FA0800BD41453A838AAFE90EC88BCF5FA39A459FDD713F494AEF2D49AE57739FF0B04EC5C1F189F5D5895521075CCDA5507BC9B3EF8BE820FBA0C5C60;PATH=/;MAX-AGE=86400 Connection: keep-alive $ch::Resource id #4 curl_errno($ch)::0 curl_error($ch):: curl_getinfo($ch)::Array ( [url] => http://leadserve.opt-intelligence.com/ls/reports.action [content_type] => text/plain; charset=UTF-8 [http_code] => 302 [header_size] => 487 [request_size] => 153 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.28248 [namelookup_time] => 2.4E-5 [connect_time] => 0.139896 [pretransfer_time] => 0.139925 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => 0 [starttransfer_time] => 0.282445 [redirect_time] => 0 [certinfo] => Array ( ) [redirect_url] => http://leadserve.opt-intelligence.com/ls/signin.action ) ++!!!@@ $Res::1
|
Немного своими словами 1) Я успешно курлом открываю страницу логина ( $this->OpenLoginPage() ) с нее считываю ($this->Get__fpKey($LoginPageHTML)) значение спрятанной переменной __fp, котоая как я понимаю для CSRF защиты 2) В $this->MakeLogToSite пытаюсь симулировать отправку пост запроса логина с переменной полученной выше __fp и параметрами подключения и там странный результат так как curl_errno($ch) и curl_error($ch) ошибок не отбражают но выводят пустую строку в результате 3) Я не очень понял с кукями - видимо на шаге 2) надо его создать и передать при шаге 3) ( в GetReportData() ) Подскажите плиз как это сделать и что в этом файле должно быть ?
|