<?php 
defined('ISDVBBS') or exit('Access Denied');
(substr($passport['colientaddresses'],-1,1)!="/")&&($passport['colientaddresses'].="/");
(false!==$dpos=strpos($passport['colientaddresses'],",")) AND ($passport['colientaddresses']=substr($passport['colientaddresses'],0,$dpos));

$phpcms_userinfo=array();
$action=$action=='logout'?'quit':'login';
if($action=='login'){
$query=$db->query("select username,userpassword as password,useremail as email,userpost,usertopic,usersign,usersex as sex
,userwealth,usercp,userep,userquesion as question,useranswer as answer,userbirthday as birthday from {$dv}user where userid={$userid}");
$phpcms_userinfo=$db->fetch_array($query);
$phpcms_userinfo['time']=time();
$phpcms_userinfo['cktime']=get_cookie('select_cookiedate');
empty($phpcms_userinfo['email']) AND ($phpcms_userinfo['email']='name@domain.com');
}

$url=makeRpcUrl($action,$passport['colientaddresses'],$comeurl,$phpcms_userinfo,$passport['passport_pkey']);
function makeRpcUrl($action,$jumpurl,$forward,$phpcms_userinfo,$passport_pkey){
	$struserinfo = '';
	$allowpassactions=array("login","quit");
	$md5pkey	= strval(md5($_SERVER['SERVER_ADDR'].$passport_pkey));
	foreach($phpcms_userinfo as $key=>$val)$struserinfo .="&$key=$val";
	($struserinfo!=='') AND ($struserinfo=substr($struserinfo,1));
	$struserinfo =StrCode($struserinfo,'ENCODE');
	if(in_array($action,$allowpassactions)){
		$verify = md5("{$action}$struserinfo$forward$passport_pkey");
		$url = $jumpurl."passport_client.php?action={$action}&userdb=".rawurlencode($struserinfo)."&forward=".rawurlencode($forward)."&verify=".rawurlencode($verify)."&time=".time();
	}else{
		$url="";
	}
	return $url;
}
function StrCode($string,$action='ENCODE')
{
	global $passport;
	$key	= substr(md5($_SERVER["HTTP_USER_AGENT"].$passport['passport_pkey']),8,18);
	$string	= $action == 'ENCODE' ? $string : base64_decode($string);
	$len	= strlen($key);
	$code	= '';
	for($i=0; $i<strlen($string); $i++)
	{
		$k		= $i % $len;
		$code  .= $string[$i] ^ $key[$k];
	}
	$code = $action == 'DECODE' ? $code : base64_encode($code);
	return $code;
}
?>