[RCD] Roundcube Login

Alexander Fleites alex240505 at gmail.com
Thu Oct 2 22:46:43 CEST 2014


Hi I try to connect directly to the login page, but I gets an error Session Invalid or Expired

here is my code, if somebody can help me I appreciate that, Thank You.

     	    define('EOL', chr(10)); 
	    define('ROUNDCUBE_HOST', 'www.nursingclub.org'); 
            define('ROUNDCUBE_FOLDER', 'email'); 
            define('ROUNDCUBE_LOGIN', 'test at nursingclub.org'); 
            define('ROUNDCUBE_PASS', 'test at 2014'); 

	    header('Cache-Control: private, no-cache, no-store, must-revalidate, post-check=0, pre-check=0');
	    header('Pragma: no-cache');
	    
	    $header  = 'Host: ' . ROUNDCUBE_HOST . EOL;
	    $header .= 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'] . EOL;
	    $header .= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' . EOL;
	    $header .= 'Accept-Language: pt-br,en-us;q=0.7,en;q=0.3' . EOL;
	    $header .= 'Connection: close' . EOL . EOL;
	    
	    $data = $this->getConn('GET', ROUNDCUBE_HOST, '/' . ROUNDCUBE_FOLDER . '/?_task=login', $header, 80);
	    
	    //echo str_replace(EOL, '<br>', $header);
	    //var_dump($data);
	    //echo '<hr>';
	    
	    $posToken = strpos($data['content'] ,'="_token"');
	    if($posToken === false) {
	    	echo 'token not found';
	    } else if ($data['status'] === '200') {
	    	$data['content'] = $this->getToken($data['content'], $posToken + 9);
			$ddata['token'] = $data['content'];
	    	$postdata = http_build_query(
	    		array(
	    			'_token' => $data['content'],
	    			'_url' => '',
	    			'_task' => 'login',
	    			'_action' => 'login',
	    			'_timezone' => '__default__',
	    			'_user' => ROUNDCUBE_LOGIN,
	    			'_pass' => ROUNDCUBE_PASS
	    		)
	    	);
	    
	    	$header  = 'Host: ' . ROUNDCUBE_HOST . EOL;
	    	$header .= 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'] . EOL;
	    	$header .= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/'.'*;q=0.8' . EOL;
	    	$header .= 'Accept-Language: pt-br,en-us;q=0.7,en;q=0.3' . EOL;
	    	$header .= 'Referer: http://' . ROUNDCUBE_HOST . '/' . ROUNDCUBE_FOLDER . '/?_task=login' . EOL;
	    	if(count($data['cookies']) > 0) {
	    		$header .= 'Cookie: ' . implode('; ', $data['cookies']) . EOL;
	    	}
	    	$header .= 'Connection: close' . EOL;
	    	$header .= 'Content-Type: application/x-www-form-urlencoded' . EOL;
	    	$header .= 'Content-Length: ' . strlen($postdata) . EOL . EOL;
	    	$header .= $postdata;
	    
	    	$data = $this->getConn('POST', ROUNDCUBE_HOST, '/' . ROUNDCUBE_FOLDER . '/?_task=login', $header, 80);
	    
	    	//echo str_replace(EOL, '<br>', $header);
	    	//var_dump($data);
	    
	    	if($data['status'] === '0') { //0 = Not connected
	    		echo 'error_send_post(socket): ', $data['err'];
	    	} else if($data['status'] !== '302') { //If HTTP <> 302 has an issue
	    		echo 'error_send_post_http_' . $data['status'];
	    	} else {// If 302 (Moved page) login ok
	    		$j = count($data['cookies']);
	    		for($i = 0; $i < $j; $i++) {
	    			header('Set-Cookie: ' . $data['cookies'][$i] . '; path=/; httpOnly', false);
	    		}
	    		header('X-DNS-Prefetch-Control: off');
	    		header('Vary: Accept-Encoding');
	    		//$this->load->view('email/login', $ddata);
	    		header('Location: http://' . ROUNDCUBE_HOST . '/' . ROUNDCUBE_FOLDER . '/?_task=mail');
	    	}
	    }


Regards, Alex
alex240505 at gmail.com




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.roundcube.net/pipermail/dev/attachments/20141002/16599eb4/attachment.html>


More information about the dev mailing list