mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +09:00
#18541587 : remove openid_lib and replace it with janrain 1.2.3 (LGPL)
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7045 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
571766a8aa
commit
910785c86f
19 changed files with 499 additions and 3250 deletions
|
|
@ -118,6 +118,7 @@
|
||||||
FileHandler::makeDir('./files/member_extra_info/profile_image');
|
FileHandler::makeDir('./files/member_extra_info/profile_image');
|
||||||
FileHandler::makeDir('./files/member_extra_info/signature');
|
FileHandler::makeDir('./files/member_extra_info/signature');
|
||||||
|
|
||||||
|
$oDB->addIndex("member_openid_association","idx_assoc", array("server_url(255)","handle"), false);
|
||||||
return new Object();
|
return new Object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,6 +193,10 @@
|
||||||
* @brief 캐시 파일 재생성
|
* @brief 캐시 파일 재생성
|
||||||
**/
|
**/
|
||||||
function recompileCache() {
|
function recompileCache() {
|
||||||
|
set_include_path(_XE_PATH_."modules/member/php-openid-1.2.3");
|
||||||
|
require_once('Auth/OpenID/XEStore.php');
|
||||||
|
$store = new Auth_OpenID_XEStore();
|
||||||
|
$store->reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
|
|
@ -47,43 +47,34 @@
|
||||||
$config = $oModuleModel->getModuleConfig('member');
|
$config = $oModuleModel->getModuleConfig('member');
|
||||||
if($config->enable_openid != 'Y') $this->stop('msg_invalid_request');
|
if($config->enable_openid != 'Y') $this->stop('msg_invalid_request');
|
||||||
|
|
||||||
ob_start();
|
set_include_path(_XE_PATH_."modules/member/php-openid-1.2.3");
|
||||||
require('./modules/member/openid_lib/class.openid.php');
|
require_once('Auth/OpenID.php');
|
||||||
require_once('./modules/member/openid_lib/libcurlemu.inc.php');
|
require_once('Auth/OpenID/Consumer.php');
|
||||||
|
require_once('Auth/OpenID/XEStore.php');
|
||||||
|
$store = new Auth_OpenID_XEStore();
|
||||||
|
$consumer = new Auth_OpenID_Consumer($store);
|
||||||
|
|
||||||
$user_id = Context::get('user_id');
|
$user_id = Context::get('user_id');
|
||||||
if (!$user_id) $user_id = Context::get('openid');
|
if (!$user_id) $user_id = Context::get('openid');
|
||||||
|
$auth_request = $consumer->begin($user_id);
|
||||||
|
$auth_request->addExtensionArg('sreg', 'required', 'email');
|
||||||
|
$auth_request->addExtensionArg('sreg', 'optional', 'dob');
|
||||||
|
if(!$auth_request)
|
||||||
|
{
|
||||||
|
return new Object(-1, "association failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
$trust_root = 'http://'.$_SERVER["HTTP_HOST"];
|
||||||
$referer_url = Context::get('referer_url');
|
$referer_url = Context::get('referer_url');
|
||||||
if (!$referer_url) $referer_url = $_SERVER['HTTP_REFERER'];
|
if (!$referer_url) $referer_url = $_SERVER['HTTP_REFERER'];
|
||||||
if (!$referer_url)
|
if (!$referer_url)
|
||||||
$referer_url = htmlspecialchars_decode(getRequestUri(RELEASE_SSL));
|
$referer_url = htmlspecialchars_decode(getRequestUri(RELEASE_SSL));
|
||||||
|
$goto = urlencode($referer_url);
|
||||||
$openid = new SimpleOpenID();
|
$ApprovedURL = Context::getRequestUri(RELEASE_SSL) . "?module=member&act=" . $validator. "&goto=" . $goto;
|
||||||
|
$redirect_url = $auth_request->redirectURL($trust_root, $ApprovedURL);
|
||||||
$openid->SetIdentity($user_id);
|
$this->add("redirect_url", $redirect_url);
|
||||||
$openid->SetTrustRoot('http://' . $_SERVER["HTTP_HOST"]);
|
if (Context::getRequestMethod() == 'POST')
|
||||||
|
header("location:" . $redirect_url);
|
||||||
$openid->SetRequiredFields(array('email'));
|
|
||||||
$openid->SetOptionalFields(array('dob'));
|
|
||||||
|
|
||||||
if (!$openid->GetOpenIDServer()) {
|
|
||||||
$error = $openid->GetError();
|
|
||||||
$this->setError(-1);
|
|
||||||
$this->setMessage($error['description']);
|
|
||||||
|
|
||||||
if (Context::getRequestMethod() == 'POST')
|
|
||||||
header("location:" . $referer_url);
|
|
||||||
} else {
|
|
||||||
$goto = urlencode($referer_url);
|
|
||||||
$ApprovedURL = Context::getRequestUri(RELEASE_SSL) . "?module=member&act=" . $validator. "&goto=" . $goto;
|
|
||||||
$openid->SetApprovedURL($ApprovedURL);
|
|
||||||
$url = $openid->GetRedirectURL();
|
|
||||||
$this->add('redirect_url', $url);
|
|
||||||
if (Context::getRequestMethod() == 'POST')
|
|
||||||
header("location:" . $url);
|
|
||||||
}
|
|
||||||
ob_clean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLegacyUserIDsFromOpenID($openid_identity) {
|
function getLegacyUserIDsFromOpenID($openid_identity) {
|
||||||
|
|
@ -127,120 +118,109 @@
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function doOpenIDValidate($openid) {
|
|
||||||
// use the JanRain php-openid library
|
|
||||||
require_once($this->module_path.'php-openid-1.2.3/Auth/OpenID/URINorm.php');
|
|
||||||
|
|
||||||
$oModuleModel = &getModel('module');
|
|
||||||
$config = $oModuleModel->getModuleConfig('member');
|
|
||||||
if($config->enable_openid != 'Y') $this->stop('msg_invalid_request');
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
require($this->module_path.'openid_lib/class.openid.php');
|
|
||||||
require_once($this->module_path.'openid_lib/libcurlemu.inc.php');
|
|
||||||
|
|
||||||
$openid_ctx = new SimpleOpenID;
|
|
||||||
|
|
||||||
$openid_ctx->SetIdentity(Auth_OpenID_urinorm($openid));
|
|
||||||
$openid_ctx->validation_result = $openid_ctx->ValidateWithServer();
|
|
||||||
ob_clean();
|
|
||||||
|
|
||||||
return $openid_ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief openid 인증 체크
|
* @brief openid 인증 체크
|
||||||
**/
|
**/
|
||||||
function procMemberOpenIDValidate() {
|
function procMemberOpenIDValidate() {
|
||||||
$openid = $this->doOpenIDValidate($_GET['openid_identity']);
|
set_include_path(_XE_PATH_."modules/member/php-openid-1.2.3");
|
||||||
$openid_identity = $openid->GetIdentity();
|
require_once('Auth/OpenID.php');
|
||||||
$openid_validation_result = $openid->validation_result;
|
require_once('Auth/OpenID/Consumer.php');
|
||||||
|
require_once('Auth/OpenID/XEStore.php');
|
||||||
|
require_once('Auth/OpenID/URINorm.php');
|
||||||
|
|
||||||
// 인증 성공
|
$store = new Auth_OpenID_XEStore();
|
||||||
if ($openid_validation_result == true) {
|
$consumer = new Auth_OpenID_Consumer($store);
|
||||||
$oMemberModel = &getModel('member');
|
$response = $consumer->complete($_GET);
|
||||||
|
switch($response->status) {
|
||||||
// 이 오픈아이디와 연결된 (또는 연결되어 있을 가능성이 있는) 제로보드 아이디들을 받아온다.
|
case Auth_OpenID_CANCEL :
|
||||||
$login_success = false;
|
// 사용자가 인증을 취소했을 때의 처리
|
||||||
$assoc_member_info = null;
|
return $this->stop('authorization_canceled');
|
||||||
|
case Auth_OpenID_FAILURE :
|
||||||
$args->openid = $openid_identity;
|
// 무언가의 문제로 인해 인증이 실패했을 때의 처리(인증을 요구한 openid가 없다든가..)
|
||||||
$output = executeQuery('member.getMemberSrlByOpenID', $args);
|
return $this->stop('invalid_authorization');
|
||||||
|
case Auth_OpenID_SUCCESS :
|
||||||
if ($output->toBool() && !is_array($output->data)) {
|
// 인증성공!!
|
||||||
$member_srl = $output->data->member_srl;
|
break;
|
||||||
$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl);
|
default:
|
||||||
if ($member_info) {
|
|
||||||
$assoc_member_info = $member_info;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$user_id_candidates = $this->getLegacyUserIDsFromOpenID($openid_identity);
|
|
||||||
$default_user_id = $user_id_candidates[0];
|
|
||||||
|
|
||||||
if ($assoc_member_info != null) {
|
|
||||||
$user_id_candidates = array_merge(array($assoc_member_info->user_id), $user_id_candidates);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($user_id_candidates as $user_id) {
|
|
||||||
$args->user_id = $args->nick_name = $user_id;
|
|
||||||
// 기본 정보들을 받음
|
|
||||||
$args->email_address = Context::get('openid_sreg_email');
|
|
||||||
$args->user_name = Context::get('openid_sreg_fullname');
|
|
||||||
if(!$args->user_name) list($args->user_name) = explode('@', $args->email_address);
|
|
||||||
$args->birthday = str_replace('-','',Context::get('openid_sreg_dob'));
|
|
||||||
|
|
||||||
// 자체 인증 시도
|
|
||||||
$output = $this->doLogin($args->user_id);
|
|
||||||
|
|
||||||
|
|
||||||
if ($output->toBool()) {
|
|
||||||
if ($assoc_member_info == null) {
|
|
||||||
$logged_info = Context::get('logged_info');
|
|
||||||
$args->member_srl = $logged_info->member_srl;
|
|
||||||
$args->openid = $openid_identity;
|
|
||||||
executeQuery('member.addOpenIDToMember', $args);
|
|
||||||
}
|
|
||||||
$login_success = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 자체 인증 실패시 회원 가입시킴
|
|
||||||
if(!$login_success) {
|
|
||||||
$args->user_id = $args->nick_name = $default_user_id;
|
|
||||||
$args->password = md5(getmicrotime());
|
|
||||||
|
|
||||||
$output = $this->insertMember($args);
|
|
||||||
if(!$output->toBool()) return $this->stop($output->getMessage());
|
|
||||||
$output = $this->doLogin($args->user_id);
|
|
||||||
if(!$output->toBool()) return $this->stop($output->getMessage());
|
|
||||||
|
|
||||||
$logged_info = Context::get('logged_info');
|
|
||||||
$args->member_srl = $logged_info->member_srl;
|
|
||||||
$args->openid = $openid_identity;
|
|
||||||
executeQuery('member.addOpenIDToMember', $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
Context::close();
|
|
||||||
|
|
||||||
// 페이지 이동
|
|
||||||
if(Context::get('goto')) {
|
|
||||||
$goto = Context::get('goto');
|
|
||||||
header("location:" . $goto);
|
|
||||||
} else {
|
|
||||||
header("location:./");
|
|
||||||
}
|
|
||||||
|
|
||||||
exit();
|
|
||||||
|
|
||||||
// 인증 실패
|
|
||||||
} else if($openid->IsError() == true) {
|
|
||||||
$error = $openid->GetError();
|
|
||||||
return $this->stop($error['description']);
|
|
||||||
} else {
|
|
||||||
return $this->stop('invalid_authorization');
|
return $this->stop('invalid_authorization');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 인증 성공
|
||||||
|
$oMemberModel = &getModel('member');
|
||||||
|
|
||||||
|
// 이 오픈아이디와 연결된 (또는 연결되어 있을 가능성이 있는) 제로보드 아이디들을 받아온다.
|
||||||
|
$login_success = false;
|
||||||
|
$assoc_member_info = null;
|
||||||
|
$openid_identity = $response->signed_args["openid.identity"];
|
||||||
|
$args->openid = $openid_identity;
|
||||||
|
$output = executeQuery('member.getMemberSrlByOpenID', $args);
|
||||||
|
|
||||||
|
if ($output->toBool() && $output->data && !is_array($output->data)) {
|
||||||
|
$member_srl = $output->data->member_srl;
|
||||||
|
$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl);
|
||||||
|
if ($member_info) {
|
||||||
|
$assoc_member_info = $member_info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_id_candidates = $this->getLegacyUserIDsFromOpenID($openid_identity);
|
||||||
|
$default_user_id = $user_id_candidates[0];
|
||||||
|
|
||||||
|
if ($assoc_member_info != null) {
|
||||||
|
$user_id_candidates = array_merge(array($assoc_member_info->user_id), $user_id_candidates);
|
||||||
|
}
|
||||||
|
$sreg = $response->extensionResponse('sreg');
|
||||||
|
|
||||||
|
foreach($user_id_candidates as $user_id) {
|
||||||
|
$args->user_id = $args->nick_name = $user_id;
|
||||||
|
// 기본 정보들을 받음
|
||||||
|
$args->email_address = $sreg['email'];
|
||||||
|
$args->user_name = $sreg['fullname'];
|
||||||
|
if(!$args->user_name) list($args->user_name) = explode('@', $args->email_address);
|
||||||
|
$args->birthday = str_replace('-','',$sreg['dob']);
|
||||||
|
|
||||||
|
// 자체 인증 시도
|
||||||
|
$output = $this->doLogin($args->user_id);
|
||||||
|
|
||||||
|
if ($output->toBool()) {
|
||||||
|
if ($assoc_member_info == null) {
|
||||||
|
$logged_info = Context::get('logged_info');
|
||||||
|
$args->member_srl = $logged_info->member_srl;
|
||||||
|
$args->openid = $openid_identity;
|
||||||
|
executeQuery('member.addOpenIDToMember', $args);
|
||||||
|
}
|
||||||
|
$login_success = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 자체 인증 실패시 회원 가입시킴
|
||||||
|
if(!$login_success) {
|
||||||
|
$args->user_id = $args->nick_name = $default_user_id;
|
||||||
|
$args->password = md5(getmicrotime());
|
||||||
|
|
||||||
|
$output = $this->insertMember($args);
|
||||||
|
if(!$output->toBool()) return $this->stop($output->getMessage());
|
||||||
|
$output = $this->doLogin($args->user_id);
|
||||||
|
if(!$output->toBool()) return $this->stop($output->getMessage());
|
||||||
|
|
||||||
|
$logged_info = Context::get('logged_info');
|
||||||
|
$args->member_srl = $logged_info->member_srl;
|
||||||
|
$args->openid = $openid_identity;
|
||||||
|
executeQuery('member.addOpenIDToMember', $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
Context::close();
|
||||||
|
|
||||||
|
// 페이지 이동
|
||||||
|
if(Context::get('goto')) {
|
||||||
|
$goto = Context::get('goto');
|
||||||
|
header("location:" . $goto);
|
||||||
|
} else {
|
||||||
|
header("location:./");
|
||||||
|
}
|
||||||
|
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1516,7 +1496,6 @@
|
||||||
|
|
||||||
// 모델 객체 생성
|
// 모델 객체 생성
|
||||||
$oMemberModel = &getModel('member');
|
$oMemberModel = &getModel('member');
|
||||||
|
|
||||||
// 금지 아이디인지 체크
|
// 금지 아이디인지 체크
|
||||||
if($oMemberModel->isDeniedID($args->user_id)) return new Object(-1,'denied_user_id');
|
if($oMemberModel->isDeniedID($args->user_id)) return new Object(-1,'denied_user_id');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,340 +0,0 @@
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 2, June 1991
|
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
|
||||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
License is intended to guarantee your freedom to share and change free
|
|
||||||
software--to make sure the software is free for all its users. This
|
|
||||||
General Public License applies to most of the Free Software
|
|
||||||
Foundation's software and to any other program whose authors commit to
|
|
||||||
using it. (Some other Free Software Foundation software is covered by
|
|
||||||
the GNU Library General Public License instead.) You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
this service if you wish), that you receive source code or can get it
|
|
||||||
if you want it, that you can change the software or use pieces of it
|
|
||||||
in new free programs; and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
|
||||||
anyone to deny you these rights or to ask you to surrender the rights.
|
|
||||||
These restrictions translate to certain responsibilities for you if you
|
|
||||||
distribute copies of the software, or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must give the recipients all the rights that
|
|
||||||
you have. You must make sure that they, too, receive or can get the
|
|
||||||
source code. And you must show them these terms so they know their
|
|
||||||
rights.
|
|
||||||
|
|
||||||
We protect your rights with two steps: (1) copyright the software, and
|
|
||||||
(2) offer you this license which gives you legal permission to copy,
|
|
||||||
distribute and/or modify the software.
|
|
||||||
|
|
||||||
Also, for each author's protection and ours, we want to make certain
|
|
||||||
that everyone understands that there is no warranty for this free
|
|
||||||
software. If the software is modified by someone else and passed on, we
|
|
||||||
want its recipients to know that what they have is not the original, so
|
|
||||||
that any problems introduced by others will not reflect on the original
|
|
||||||
authors' reputations.
|
|
||||||
|
|
||||||
Finally, any free program is threatened constantly by software
|
|
||||||
patents. We wish to avoid the danger that redistributors of a free
|
|
||||||
program will individually obtain patent licenses, in effect making the
|
|
||||||
program proprietary. To prevent this, we have made it clear that any
|
|
||||||
patent must be licensed for everyone's free use or not licensed at all.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License applies to any program or other work which contains
|
|
||||||
a notice placed by the copyright holder saying it may be distributed
|
|
||||||
under the terms of this General Public License. The "Program", below,
|
|
||||||
refers to any such program or work, and a "work based on the Program"
|
|
||||||
means either the Program or any derivative work under copyright law:
|
|
||||||
that is to say, a work containing the Program or a portion of it,
|
|
||||||
either verbatim or with modifications and/or translated into another
|
|
||||||
language. (Hereinafter, translation is included without limitation in
|
|
||||||
the term "modification".) Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running the Program is not restricted, and the output from the Program
|
|
||||||
is covered only if its contents constitute a work based on the
|
|
||||||
Program (independent of having been made by running the Program).
|
|
||||||
Whether that is true depends on what the Program does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Program's
|
|
||||||
source code as you receive it, in any medium, provided that you
|
|
||||||
conspicuously and appropriately publish on each copy an appropriate
|
|
||||||
copyright notice and disclaimer of warranty; keep intact all the
|
|
||||||
notices that refer to this License and to the absence of any warranty;
|
|
||||||
and give any other recipients of the Program a copy of this License
|
|
||||||
along with the Program.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy, and
|
|
||||||
you may at your option offer warranty protection in exchange for a fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Program or any portion
|
|
||||||
of it, thus forming a work based on the Program, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) You must cause the modified files to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
b) You must cause any work that you distribute or publish, that in
|
|
||||||
whole or in part contains or is derived from the Program or any
|
|
||||||
part thereof, to be licensed as a whole at no charge to all third
|
|
||||||
parties under the terms of this License.
|
|
||||||
|
|
||||||
c) If the modified program normally reads commands interactively
|
|
||||||
when run, you must cause it, when started running for such
|
|
||||||
interactive use in the most ordinary way, to print or display an
|
|
||||||
announcement including an appropriate copyright notice and a
|
|
||||||
notice that there is no warranty (or else, saying that you provide
|
|
||||||
a warranty) and that users may redistribute the program under
|
|
||||||
these conditions, and telling the user how to view a copy of this
|
|
||||||
License. (Exception: if the Program itself is interactive but
|
|
||||||
does not normally print such an announcement, your work based on
|
|
||||||
the Program is not required to print an announcement.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
|
||||||
identifiable sections of that work are not derived from the Program,
|
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Program, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Program.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Program
|
|
||||||
with the Program (or with a work based on the Program) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may copy and distribute the Program (or a work based on it,
|
|
||||||
under Section 2) in object code or executable form under the terms of
|
|
||||||
Sections 1 and 2 above provided that you also do one of the following:
|
|
||||||
|
|
||||||
a) Accompany it with the complete corresponding machine-readable
|
|
||||||
source code, which must be distributed under the terms of Sections
|
|
||||||
1 and 2 above on a medium customarily used for software interchange; or,
|
|
||||||
|
|
||||||
b) Accompany it with a written offer, valid for at least three
|
|
||||||
years, to give any third party, for a charge no more than your
|
|
||||||
cost of physically performing source distribution, a complete
|
|
||||||
machine-readable copy of the corresponding source code, to be
|
|
||||||
distributed under the terms of Sections 1 and 2 above on a medium
|
|
||||||
customarily used for software interchange; or,
|
|
||||||
|
|
||||||
c) Accompany it with the information you received as to the offer
|
|
||||||
to distribute corresponding source code. (This alternative is
|
|
||||||
allowed only for noncommercial distribution and only if you
|
|
||||||
received the program in object code or executable form with such
|
|
||||||
an offer, in accord with Subsection b above.)
|
|
||||||
|
|
||||||
The source code for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For an executable work, complete source
|
|
||||||
code means all the source code for all modules it contains, plus any
|
|
||||||
associated interface definition files, plus the scripts used to
|
|
||||||
control compilation and installation of the executable. However, as a
|
|
||||||
special exception, the source code distributed need not include
|
|
||||||
anything that is normally distributed (in either source or binary
|
|
||||||
form) with the major components (compiler, kernel, and so on) of the
|
|
||||||
operating system on which the executable runs, unless that component
|
|
||||||
itself accompanies the executable.
|
|
||||||
|
|
||||||
If distribution of executable or object code is made by offering
|
|
||||||
access to copy from a designated place, then offering equivalent
|
|
||||||
access to copy the source code from the same place counts as
|
|
||||||
distribution of the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
4. You may not copy, modify, sublicense, or distribute the Program
|
|
||||||
except as expressly provided under this License. Any attempt
|
|
||||||
otherwise to copy, modify, sublicense or distribute the Program is
|
|
||||||
void, and will automatically terminate your rights under this License.
|
|
||||||
However, parties who have received copies, or rights, from you under
|
|
||||||
this License will not have their licenses terminated so long as such
|
|
||||||
parties remain in full compliance.
|
|
||||||
|
|
||||||
5. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Program or its derivative works. These actions are
|
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Program (or any work based on the
|
|
||||||
Program), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
|
||||||
the Program or works based on it.
|
|
||||||
|
|
||||||
6. Each time you redistribute the Program (or any work based on the
|
|
||||||
Program), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute or modify the Program subject to
|
|
||||||
these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties to
|
|
||||||
this License.
|
|
||||||
|
|
||||||
7. If, as a consequence of a court judgment or allegation of patent
|
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Program at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Program by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Program.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under
|
|
||||||
any particular circumstance, the balance of the section is intended to
|
|
||||||
apply and the section as a whole is intended to apply in other
|
|
||||||
circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system, which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
8. If the distribution and/or use of the Program is restricted in
|
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Program under this License
|
|
||||||
may add an explicit geographical distribution limitation excluding
|
|
||||||
those countries, so that distribution is permitted only in or among
|
|
||||||
countries not thus excluded. In such case, this License incorporates
|
|
||||||
the limitation as if written in the body of this License.
|
|
||||||
|
|
||||||
9. The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program
|
|
||||||
specifies a version number of this License which applies to it and "any
|
|
||||||
later version", you have the option of following the terms and conditions
|
|
||||||
either of that version or of any later version published by the Free
|
|
||||||
Software Foundation. If the Program does not specify a version number of
|
|
||||||
this License, you may choose any version ever published by the Free Software
|
|
||||||
Foundation.
|
|
||||||
|
|
||||||
10. If you wish to incorporate parts of the Program into other free
|
|
||||||
programs whose distribution conditions are different, write to the author
|
|
||||||
to ask for permission. For software which is copyrighted by the Free
|
|
||||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
|
||||||
make exceptions for this. Our decision will be guided by the two goals
|
|
||||||
of preserving the free status of all derivatives of our free software and
|
|
||||||
of promoting the sharing and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
|
||||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
|
||||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
|
||||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
|
||||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
|
||||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
|
||||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
|
||||||
REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
|
||||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
|
||||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
|
||||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
|
||||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
|
||||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|
||||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
convey the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program is interactive, make it output a short notice like this
|
|
||||||
when it starts in an interactive mode:
|
|
||||||
|
|
||||||
Gnomovision version 69, Copyright (C) year name of author
|
|
||||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, the commands you use may
|
|
||||||
be called something other than `show w' and `show c'; they could even be
|
|
||||||
mouse-clicks or menu items--whatever suits your program.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or your
|
|
||||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
|
||||||
necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
|
||||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1989
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
This General Public License does not permit incorporating your program into
|
|
||||||
proprietary programs. If your program is a subroutine library, you may
|
|
||||||
consider it more useful to permit linking proprietary applications with the
|
|
||||||
library. If this is what you want to do, use the GNU Library General
|
|
||||||
Public License instead of this License.
|
|
||||||
|
|
@ -1,99 +0,0 @@
|
||||||
CURL Extension Emulation Library
|
|
||||||
Version 1.0.4
|
|
||||||
Copyright 2004-2007, Steve Blinch
|
|
||||||
http://code.blitzaffe.com
|
|
||||||
============================================================================
|
|
||||||
|
|
||||||
DESCRIPTION
|
|
||||||
|
|
||||||
Provides a pure-PHP implementation of the PHP CURL extension, for use on
|
|
||||||
systems which do not already have the CURL extension installed. It emulates
|
|
||||||
all of the curl_* functions normally provided by the CURL extension itself.
|
|
||||||
|
|
||||||
This will automatically detect and use the best CURL implementation available
|
|
||||||
on your server. It will attempt the following, in order:
|
|
||||||
|
|
||||||
1) Check for the existence of the "real" CURL PHP Extension. If it is
|
|
||||||
loaded, the library will do nothing (and it will not interfere with the
|
|
||||||
"real" extension).
|
|
||||||
2) Check for the existence of the CURL console binary (usually located in
|
|
||||||
/usr/bin/curl). If found, the library will emulate the CURL PHP
|
|
||||||
extension (including all curl_* functions) and use the console binary
|
|
||||||
to execute all requests.
|
|
||||||
3) If neither the "real" CURL PHP Extension nor the CURL console binary
|
|
||||||
are available, the library will emulate the CURL PHP extension (including
|
|
||||||
all curl_* functions) using a native, pure-PHP HTTP client implementation.
|
|
||||||
This implementation is somewhat limited, but it provides support for most
|
|
||||||
of the common CURL options. HTTPS (SSL) support is available in this
|
|
||||||
mode under PHP 4.3.0 if the OpenSSL Extension is loaded.
|
|
||||||
|
|
||||||
Thus, by including this library in your project, you can rely on having some
|
|
||||||
level of CURL support regardless of the configuration of the server on which
|
|
||||||
it is being used.
|
|
||||||
|
|
||||||
|
|
||||||
HISTORY
|
|
||||||
|
|
||||||
1.0.4 (not released)
|
|
||||||
- Fixed HTTPRetriever double-inclusion bug.
|
|
||||||
|
|
||||||
|
|
||||||
USAGE
|
|
||||||
|
|
||||||
Simply copy all of the libcurlemu files into your project directory, then:
|
|
||||||
|
|
||||||
require_once("libcurlemu.inc.php");
|
|
||||||
|
|
||||||
After this, you can use all of the curl_* functions documented in the PHP
|
|
||||||
Manual.
|
|
||||||
|
|
||||||
|
|
||||||
EXAMPLE
|
|
||||||
|
|
||||||
// CURL Extension Emulation Library Example
|
|
||||||
//
|
|
||||||
// Usage should be straightforward; you simply use this script exactly as you
|
|
||||||
// would normally use the PHP CURL extension functions.
|
|
||||||
|
|
||||||
// first, include libcurlemu.inc.php
|
|
||||||
require_once('libcurlemu.inc.php');
|
|
||||||
|
|
||||||
// at this point, libcurlemu has detected the best available CURL solution
|
|
||||||
// (either the CURL extension, if available, or the CURL commandline binary,
|
|
||||||
// if available, or as a last resort, HTTPRetriever, our native-PHP HTTP
|
|
||||||
// client implementation) and has implemented the curl_* functions if
|
|
||||||
// necessary, so you can use CURL normally and safely assume that all CURL
|
|
||||||
// functions are available.
|
|
||||||
|
|
||||||
// the rest of this example code is copied straight from the PHP manual's
|
|
||||||
// reference for the curl_init() function, and will work fine with libcurlemu
|
|
||||||
|
|
||||||
// create a new CURL resource
|
|
||||||
$ch = curl_init();
|
|
||||||
|
|
||||||
// set URL and other appropriate options
|
|
||||||
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
|
|
||||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
|
||||||
|
|
||||||
// grab URL and pass it to the browser
|
|
||||||
curl_exec($ch);
|
|
||||||
|
|
||||||
// close CURL resource, and free up system resources
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
|
|
||||||
LICENSE
|
|
||||||
|
|
||||||
This script is free software; you can redistribute it and/or modify it under the
|
|
||||||
terms of the GNU General Public License as published by the Free Software
|
|
||||||
Foundation; either version 2 of the License, or (at your option) any later
|
|
||||||
version.
|
|
||||||
|
|
||||||
This script is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
||||||
details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this script; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
@ -1,314 +0,0 @@
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
FREE TO USE
|
|
||||||
Simple OpenID PHP Class
|
|
||||||
Contributed by http://www.fivestores.com/
|
|
||||||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
||||||
|
|
||||||
This Class was written to make easy for you to integrate OpenID on your website.
|
|
||||||
This is just a client, which checks for user's identity. This Class Requires CURL Module.
|
|
||||||
It should be easy to use some other HTTP Request Method, but remember, often OpenID servers
|
|
||||||
are using SSL.
|
|
||||||
We need to be able to perform SSL Verification on the background to check for valid signature.
|
|
||||||
|
|
||||||
HOW TO USE THIS CLASS:
|
|
||||||
STEP 1)
|
|
||||||
$openid = new SimpleOpenID;
|
|
||||||
:: SET IDENTITY ::
|
|
||||||
$openid->SetIdentity($_POST['openid_url']);
|
|
||||||
:: SET RETURN URL ::
|
|
||||||
$openid->SetApprovedURL('http://www.yoursite.com/return.php'); // Script which handles a response from OpenID Server
|
|
||||||
:: SET TRUST ROOT ::
|
|
||||||
$openid->SetTrustRoot('http://www.yoursite.com/');
|
|
||||||
:: FETCH SERVER URL FROM IDENTITY PAGE :: [Note: It is recomended to cache this (Session, Cookie, Database)]
|
|
||||||
$openid->GetOpenIDServer(); // Returns false if server is not found
|
|
||||||
:: REDIRECT USER TO OPEN ID SERVER FOR APPROVAL ::
|
|
||||||
|
|
||||||
:: (OPTIONAL) SET OPENID SERVER ::
|
|
||||||
$openid->SetOpenIDServer($server_url); // If you have cached previously this, you don't have to call GetOpenIDServer and set value this directly
|
|
||||||
|
|
||||||
STEP 2)
|
|
||||||
Once user gets returned we must validate signature
|
|
||||||
:: VALIDATE REQUEST ::
|
|
||||||
true|false = $openid->ValidateWithServer();
|
|
||||||
|
|
||||||
ERRORS:
|
|
||||||
array = $openid->GetError(); // Get latest Error code
|
|
||||||
|
|
||||||
FIELDS:
|
|
||||||
OpenID allowes you to retreive a profile. To set what fields you'd like to get use (accepts either string or array):
|
|
||||||
$openid->SetRequiredFields(array('email','fullname','dob','gender','postcode','country','language','timezone'));
|
|
||||||
or
|
|
||||||
$openid->SetOptionalFields('postcode');
|
|
||||||
|
|
||||||
IMPORTANT TIPS:
|
|
||||||
OPENID as is now, is not trust system. It is a great single-sign on method. If you want to
|
|
||||||
store information about OpenID in your database for later use, make sure you handle url identities
|
|
||||||
properly.
|
|
||||||
For example:
|
|
||||||
https://steve.myopenid.com/
|
|
||||||
https://steve.myopenid.com
|
|
||||||
http://steve.myopenid.com/
|
|
||||||
http://steve.myopenid.com
|
|
||||||
... are representing one single user. Some OpenIDs can be in format openidserver.com/users/user/ - keep this in mind when storing identities
|
|
||||||
|
|
||||||
To help you store an OpenID in your DB, you can use function:
|
|
||||||
$openid_db_safe = $openid->OpenID_Standarize($upenid);
|
|
||||||
This may not be comatible with current specs, but it works in current enviroment. Use this function to get openid
|
|
||||||
in one format like steve.myopenid.com (without trailing slashes and http/https).
|
|
||||||
Use output to insert Identity to database. Don't use this for validation - it may fail.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
class SimpleOpenID{
|
|
||||||
var $openid_url_identity;
|
|
||||||
var $URLs = array();
|
|
||||||
var $error = array();
|
|
||||||
var $fields = array();
|
|
||||||
|
|
||||||
function SimpleOpenID(){
|
|
||||||
if (!function_exists('curl_exec')) {
|
|
||||||
die('Error: Class SimpleOpenID requires curl extension to work');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function SetOpenIDServer($a){
|
|
||||||
$this->URLs['openid_server'] = $a;
|
|
||||||
}
|
|
||||||
function SetTrustRoot($a){
|
|
||||||
$this->URLs['trust_root'] = $a;
|
|
||||||
}
|
|
||||||
function SetCancelURL($a){
|
|
||||||
$this->URLs['cancel'] = $a;
|
|
||||||
}
|
|
||||||
function SetApprovedURL($a){
|
|
||||||
$this->URLs['approved'] = $a;
|
|
||||||
}
|
|
||||||
function SetRequiredFields($a){
|
|
||||||
if (is_array($a)){
|
|
||||||
$this->fields['required'] = $a;
|
|
||||||
}else{
|
|
||||||
$this->fields['required'][] = $a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function SetOptionalFields($a){
|
|
||||||
if (is_array($a)){
|
|
||||||
$this->fields['optional'] = $a;
|
|
||||||
}else{
|
|
||||||
$this->fields['optional'][] = $a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function SetIdentity($a){ // Set Identity URL
|
|
||||||
if(strpos($a, 'http://') === false) {
|
|
||||||
$a = 'http://'.$a;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
$u = parse_url(trim($a));
|
|
||||||
if (!isset($u['path'])){
|
|
||||||
$u['path'] = '/';
|
|
||||||
}else if(substr($u['path'],-1,1) == '/'){
|
|
||||||
$u['path'] = substr($u['path'], 0, strlen($u['path'])-1);
|
|
||||||
}
|
|
||||||
if (isset($u['query'])){ // If there is a query string, then use identity as is
|
|
||||||
$identity = $a;
|
|
||||||
}else{
|
|
||||||
$identity = $u['scheme'] . '://' . $u['host'] . $u['path'];
|
|
||||||
}*/
|
|
||||||
$this->openid_url_identity = $a;
|
|
||||||
}
|
|
||||||
function GetIdentity(){ // Get Identity
|
|
||||||
return $this->openid_url_identity;
|
|
||||||
}
|
|
||||||
function GetError(){
|
|
||||||
$e = $this->error;
|
|
||||||
return array('code'=>$e[0],'description'=>$e[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ErrorStore($code, $desc = null){
|
|
||||||
$errs['OPENID_NOSERVERSFOUND'] = 'Cannot find OpenID Server TAG on Identity page.';
|
|
||||||
if ($desc == null){
|
|
||||||
$desc = $errs[$code];
|
|
||||||
}
|
|
||||||
$this->error = array($code,$desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
function IsError(){
|
|
||||||
if (count($this->error) > 0){
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function splitResponse($response) {
|
|
||||||
$r = array();
|
|
||||||
$response = explode("\n", $response);
|
|
||||||
foreach($response as $line) {
|
|
||||||
$line = trim($line);
|
|
||||||
if ($line != "") {
|
|
||||||
list($key, $value) = explode(":", $line, 2);
|
|
||||||
$r[trim($key)] = trim($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $r;
|
|
||||||
}
|
|
||||||
|
|
||||||
function OpenID_Standarize($openid_identity){
|
|
||||||
$u = parse_url(strtolower(trim($openid_identity)));
|
|
||||||
if ($u['path'] == '/'){
|
|
||||||
$u['path'] = '';
|
|
||||||
}
|
|
||||||
if(substr($u['path'],-1,1) == '/'){
|
|
||||||
$u['path'] = substr($u['path'], 0, strlen($u['path'])-1);
|
|
||||||
}
|
|
||||||
if (isset($u['query'])){ // If there is a query string, then use identity as is
|
|
||||||
return $u['host'] . $u['path'] . '?' . $u['query'];
|
|
||||||
}else{
|
|
||||||
return $u['host'] . $u['path'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function array2url($arr){ // converts associated array to URL Query String
|
|
||||||
if (!is_array($arr)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
foreach($arr as $key => $value){
|
|
||||||
$query .= $key . "=" . $value . "&";
|
|
||||||
}
|
|
||||||
return $query;
|
|
||||||
}
|
|
||||||
function FSOCK_Request($url, $method="GET", $params = ""){
|
|
||||||
$fp = fsockopen("ssl://www.myopenid.com", 443, $errno, $errstr, 3); // Connection timeout is 3 seconds
|
|
||||||
if (!$fp) {
|
|
||||||
$this->ErrorStore('OPENID_SOCKETERROR', $errstr);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
$request = $method . " /server HTTP/1.0\r\n";
|
|
||||||
$request .= "User-Agent: Simple OpenID PHP Class (http://www.phpclasses.org/simple_openid)\r\n";
|
|
||||||
$request .= "Connection: close\r\n\r\n";
|
|
||||||
fwrite($fp, $request);
|
|
||||||
stream_set_timeout($fp, 4); // Connection response timeout is 4 seconds
|
|
||||||
$res = fread($fp, 2000);
|
|
||||||
$info = stream_get_meta_data($fp);
|
|
||||||
fclose($fp);
|
|
||||||
|
|
||||||
if ($info['timed_out']) {
|
|
||||||
$this->ErrorStore('OPENID_SOCKETTIMEOUT');
|
|
||||||
} else {
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function CURL_Request($url, $method="GET", $params = "") { // Remember, SSL MUST BE SUPPORTED
|
|
||||||
if (is_array($params)) $params = $this->array2url($params);
|
|
||||||
$curl = curl_init();
|
|
||||||
curl_setopt($curl, CURLOPT_URL,$url . ($method == "GET" && $params != "" ? "?" . $params : ""));
|
|
||||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
|
||||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
|
||||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
||||||
curl_setopt($curl, CURLOPT_HTTPGET, ($method == "GET"));
|
|
||||||
curl_setopt($curl, CURLOPT_POST, ($method == "POST"));
|
|
||||||
if ($method == "POST") curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
|
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
$response = curl_exec($curl);
|
|
||||||
|
|
||||||
if (curl_errno($curl) == 0){
|
|
||||||
$response;
|
|
||||||
}else{
|
|
||||||
$this->ErrorStore('OPENID_CURL', curl_error($curl));
|
|
||||||
}
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
function HTML2OpenIDServer($content) {
|
|
||||||
$get = array();
|
|
||||||
// Get details of their OpenID server and (optional) delegate
|
|
||||||
preg_match_all('/<link[^>]*rel="openid.server"[^>]*href="([^"]+)"[^>]*\/?>/i', $content, $matches1);
|
|
||||||
preg_match_all('/<link[^>]*href="([^"]+)"[^>]*rel="openid.server"[^>]*\/?>/i', $content, $matches2);
|
|
||||||
$servers = array_merge($matches1[1], $matches2[1]);
|
|
||||||
|
|
||||||
preg_match_all('/<link[^>]*rel="openid.delegate"[^>]*href="([^"]+)"[^>]*\/?>/i', $content, $matches1);
|
|
||||||
|
|
||||||
preg_match_all('/<link[^>]*href="([^"]+)"[^>]*rel="openid.delegate"[^>]*\/?>/i', $content, $matches2);
|
|
||||||
|
|
||||||
$delegates = array_merge($matches1[1], $matches2[1]);
|
|
||||||
|
|
||||||
$ret = array($servers, $delegates);
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetOpenIDServer(){
|
|
||||||
$response = $this->CURL_Request($this->openid_url_identity);
|
|
||||||
list($servers, $delegates) = $this->HTML2OpenIDServer($response);
|
|
||||||
if (count($servers) == 0){
|
|
||||||
$this->ErrorStore('OPENID_NOSERVERSFOUND');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($delegates[0] != ""){
|
|
||||||
$this->openid_url_identity = $delegates[0];
|
|
||||||
}
|
|
||||||
$this->SetOpenIDServer($servers[0]);
|
|
||||||
return $servers[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetRedirectURL(){
|
|
||||||
$params = array();
|
|
||||||
$params['openid.return_to'] = urlencode($this->URLs['approved']);
|
|
||||||
$params['openid.mode'] = 'checkid_setup';
|
|
||||||
$params['openid.identity'] = urlencode($this->openid_url_identity);
|
|
||||||
$params['openid.trust_root'] = urlencode($this->URLs['trust_root']);
|
|
||||||
|
|
||||||
if (count($this->fields['required']) > 0){
|
|
||||||
$params['openid.sreg.required'] = implode(',',$this->fields['required']);
|
|
||||||
}
|
|
||||||
if (count($this->fields['optional']) > 0){
|
|
||||||
$params['openid.sreg.optional'] = implode(',',$this->fields['optional']);
|
|
||||||
}
|
|
||||||
return $this->URLs['openid_server'] . "?". $this->array2url($params);
|
|
||||||
}
|
|
||||||
|
|
||||||
function Redirect(){
|
|
||||||
$redirect_to = $this->GetRedirectURL();
|
|
||||||
if (headers_sent()){ // Use JavaScript to redirect if content has been previously sent (not recommended, but safe)
|
|
||||||
echo '<script language="JavaScript" type="text/javascript">window.location=\'';
|
|
||||||
echo $redirect_to;
|
|
||||||
echo '\';</script>';
|
|
||||||
}else{ // Default Header Redirect
|
|
||||||
header('Location: ' . $redirect_to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function ValidateWithServer(){
|
|
||||||
$params = array(
|
|
||||||
'openid.assoc_handle' => urlencode($_GET['openid_assoc_handle']),
|
|
||||||
'openid.signed' => urlencode($_GET['openid_signed']),
|
|
||||||
'openid.sig' => urlencode($_GET['openid_sig'])
|
|
||||||
);
|
|
||||||
// Send only required parameters to confirm validity
|
|
||||||
$arr_signed = explode(",",str_replace('sreg.','sreg_',$_GET['openid_signed']));
|
|
||||||
for ($i=0; $i<count($arr_signed); $i++){
|
|
||||||
$s = str_replace('sreg_','sreg.', $arr_signed[$i]);
|
|
||||||
$c = $_GET['openid_' . $arr_signed[$i]];
|
|
||||||
// if ($c != ""){
|
|
||||||
$params['openid.' . $s] = urlencode($c);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
$params['openid.mode'] = "check_authentication";
|
|
||||||
// print "<pre>";
|
|
||||||
// print_r($_GET);
|
|
||||||
// print_r($params);
|
|
||||||
// print "</pre>";
|
|
||||||
$openid_server = $this->GetOpenIDServer();
|
|
||||||
if ($openid_server == false){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$response = $this->CURL_Request($openid_server,'GET',$params);
|
|
||||||
$data = $this->splitResponse($response);
|
|
||||||
if ($data['is_valid'] == "true") {
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,111 +0,0 @@
|
||||||
<?php
|
|
||||||
/* CURL Extension Emulation Library
|
|
||||||
* Version 1.0.4
|
|
||||||
* Copyright 2004-2007, Steve Blinch
|
|
||||||
* http://code.blitzaffe.com
|
|
||||||
* ============================================================================
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
*
|
|
||||||
* Provides a pure-PHP implementation of the PHP CURL extension, for use on
|
|
||||||
* systems which do not already have the CURL extension installed. It emulates
|
|
||||||
* all of the curl_* functions normally provided by the CURL extension itself.
|
|
||||||
*
|
|
||||||
* This will automatically detect and use the best CURL implementation available
|
|
||||||
* on your server. It will attempt the following, in order:
|
|
||||||
*
|
|
||||||
* 1) Check for the existence of the "real" CURL PHP Extension. If it is
|
|
||||||
* loaded, the library will do nothing (and it will not interfere with the
|
|
||||||
* "real" extension).
|
|
||||||
* 2) Check for the existence of the CURL console binary (usually located in
|
|
||||||
* /usr/bin/curl). If found, the library will emulate the CURL PHP
|
|
||||||
* extension (including all curl_* functions) and use the console binary
|
|
||||||
* to execute all requests.
|
|
||||||
* 3) If neither the "real" CURL PHP Extension nor the CURL console binary
|
|
||||||
* are available, the library will emulate the CURL PHP extension (including
|
|
||||||
* all curl_* functions) using a native, pure-PHP HTTP client implementation.
|
|
||||||
* This implementation is somewhat limited, but it provides support for most
|
|
||||||
* of the common CURL options. HTTPS (SSL) support is available in this
|
|
||||||
* mode under PHP 4.3.0 if the OpenSSL Extension is loaded.
|
|
||||||
*
|
|
||||||
* Thus, by including this library in your project, you can rely on having some
|
|
||||||
* level of CURL support regardless of the configuration of the server on which
|
|
||||||
* it is being used.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* HISTORY
|
|
||||||
*
|
|
||||||
* 1.0.4 (not released)
|
|
||||||
* - Fixed HTTPRetriever double-inclusion bug.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* USAGE
|
|
||||||
*
|
|
||||||
* Simply copy all of the libcurlemu files into your project directory, then:
|
|
||||||
*
|
|
||||||
* require_once("libcurlemu.inc.php");
|
|
||||||
*
|
|
||||||
* After this, you can use all of the curl_* functions documented in the PHP
|
|
||||||
* Manual.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* EXAMPLE
|
|
||||||
*
|
|
||||||
* // CURL Extension Emulation Library Example
|
|
||||||
* //
|
|
||||||
* // Usage should be straightforward; you simply use this script exactly as you
|
|
||||||
* // would normally use the PHP CURL extension functions.
|
|
||||||
*
|
|
||||||
* // first, include libcurlemu.inc.php
|
|
||||||
* require_once('libcurlemu.inc.php');
|
|
||||||
*
|
|
||||||
* // at this point, libcurlemu has detected the best available CURL solution
|
|
||||||
* // (either the CURL extension, if available, or the CURL commandline binary,
|
|
||||||
* // if available, or as a last resort, HTTPRetriever, our native-PHP HTTP
|
|
||||||
* // client implementation) and has implemented the curl_* functions if
|
|
||||||
* // necessary, so you can use CURL normally and safely assume that all CURL
|
|
||||||
* // functions are available.
|
|
||||||
*
|
|
||||||
* // the rest of this example code is copied straight from the PHP manual's
|
|
||||||
* // reference for the curl_init() function, and will work fine with libcurlemu
|
|
||||||
*
|
|
||||||
* // create a new CURL resource
|
|
||||||
* $ch = curl_init();
|
|
||||||
*
|
|
||||||
* // set URL and other appropriate options
|
|
||||||
* curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
|
|
||||||
* curl_setopt($ch, CURLOPT_HEADER, false);
|
|
||||||
*
|
|
||||||
* // grab URL and pass it to the browser
|
|
||||||
* curl_exec($ch);
|
|
||||||
*
|
|
||||||
* // close CURL resource, and free up system resources
|
|
||||||
* curl_close($ch);
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE
|
|
||||||
*
|
|
||||||
* This script is free software; you can redistribute it and/or modify it under the
|
|
||||||
* terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation; either version 2 of the License, or (at your option) any later
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* This script is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this script; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
if (!extension_loaded('curl') && !function_exists('curl_init')) {
|
|
||||||
define('CURLEXT_MISSING_ABORT',true);
|
|
||||||
require_once("./modules/member/openid_lib/libcurlexternal.inc.php");
|
|
||||||
|
|
||||||
if (!function_exists('curl_init')) {
|
|
||||||
if (!class_exists('HTTPRetriever')) require_once("./modules/member/openid_lib/class_HTTPRetriever.php");
|
|
||||||
require_once("./modules/member/openid_lib/libcurlnative.inc.php");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
@ -1,637 +0,0 @@
|
||||||
<?php
|
|
||||||
/* CURL Extension Emulation Library (Console Binary)
|
|
||||||
* Copyright 2004-2007, Steve Blinch
|
|
||||||
* http://code.blitzaffe.com
|
|
||||||
* ============================================================================
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
*
|
|
||||||
* Provides a pure-PHP implementation of the PHP CURL extension, for use on
|
|
||||||
* systems which do not already have the CURL extension installed. It emulates
|
|
||||||
* all of the curl_* functions normally provided by the CURL extension itself
|
|
||||||
* by wrapping the CURL console binary.
|
|
||||||
*
|
|
||||||
* This library will automatically detect whether or not the "real" CURL
|
|
||||||
* extension is installed, and if so, it will not interfere. Thus, it can be
|
|
||||||
* used to ensure that, one way or another, the CURL functions are available
|
|
||||||
* for use.
|
|
||||||
*
|
|
||||||
* This library is actually a wrapper for the CURL console application (usually
|
|
||||||
* found in /usr/bin/curl), so you must have the CURL binary installed in order
|
|
||||||
* to use this script.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* USAGE
|
|
||||||
*
|
|
||||||
* Please see the PHP documentation under the "CURL, Client URL Library
|
|
||||||
* Functions" section for information about using this library. Almost all of
|
|
||||||
* the documentation and examples in the PHP manual should work with this
|
|
||||||
* library.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE
|
|
||||||
*
|
|
||||||
* This script is free software; you can redistribute it and/or modify it under the
|
|
||||||
* terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation; either version 2 of the License, or (at your option) any later
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* This script is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this script; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
// if the real CURL PHP extension is installed, exit without doing anything
|
|
||||||
if (!extension_loaded("curl")) {
|
|
||||||
|
|
||||||
// if the CURL path was not defined by the calling script, define it
|
|
||||||
if (!defined("CURL_PATH")) define("CURL_PATH","/usr/bin/curl");
|
|
||||||
|
|
||||||
// if the CURL binary was not found, do one of the following:
|
|
||||||
// - if CURLEXT_MISSING_ABORT was defined, then exit without implementing the CURL functions
|
|
||||||
// - if CURLEXT_MISSING_IGNORE was defined, then implement the CURL functions anyway (even
|
|
||||||
// though they won't work without the CURL binary installed)
|
|
||||||
// - otherwise, raise a fatal error and halt the script
|
|
||||||
if (!is_executable(CURL_PATH)) {
|
|
||||||
|
|
||||||
if (defined("CURLEXT_MISSING_ABORT") && CURLEXT_MISSING_ABORT) {
|
|
||||||
return;
|
|
||||||
} elseif (defined("CURLEXT_MISSING_IGNORE") && CURLEXT_MISSING_IGNORE) {
|
|
||||||
// proceed and implement the CURL functions anyway, even though they won't work
|
|
||||||
} else {
|
|
||||||
trigger_error("CURL extension is not loaded, and the commandline version of CURL was not found at ".CURL_PATH,E_USER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
define("CURLEXT_VERSION","1.0.0");
|
|
||||||
|
|
||||||
define('CURLOPT_NOTHING',0);
|
|
||||||
define('CURLOPT_FILE',10001);
|
|
||||||
define('CURLOPT_URL',10002);
|
|
||||||
define('CURLOPT_PORT',3);
|
|
||||||
define('CURLOPT_PROXY',10004);
|
|
||||||
define('CURLOPT_USERPWD',10005);
|
|
||||||
define('CURLOPT_PROXYUSERPWD',10006);
|
|
||||||
define('CURLOPT_RANGE',10007);
|
|
||||||
define('CURLOPT_INFILE',10009);
|
|
||||||
define('CURLOPT_ERRORBUFFER',10010);
|
|
||||||
define('CURLOPT_WRITEFUNCTION',20011);
|
|
||||||
define('CURLOPT_READFUNCTION',20012);
|
|
||||||
define('CURLOPT_TIMEOUT',13);
|
|
||||||
define('CURLOPT_INFILESIZE',14);
|
|
||||||
define('CURLOPT_POSTFIELDS',10015);
|
|
||||||
define('CURLOPT_REFERER',10016);
|
|
||||||
define('CURLOPT_FTPPORT',10017);
|
|
||||||
define('CURLOPT_USERAGENT',10018);
|
|
||||||
define('CURLOPT_LOW_SPEED_LIMIT',19);
|
|
||||||
define('CURLOPT_LOW_SPEED_TIME',20);
|
|
||||||
define('CURLOPT_RESUME_FROM',21);
|
|
||||||
define('CURLOPT_COOKIE',10022);
|
|
||||||
define('CURLOPT_HTTPHEADER',10023);
|
|
||||||
define('CURLOPT_HTTPPOST',10024);
|
|
||||||
define('CURLOPT_SSLCERT',10025);
|
|
||||||
define('CURLOPT_SSLCERTPASSWD',10026);
|
|
||||||
define('CURLOPT_SSLKEYPASSWD',10026);
|
|
||||||
define('CURLOPT_CRLF',27);
|
|
||||||
define('CURLOPT_QUOTE',10028);
|
|
||||||
define('CURLOPT_WRITEHEADER',10029);
|
|
||||||
define('CURLOPT_COOKIEFILE',10031);
|
|
||||||
define('CURLOPT_SSLVERSION',32);
|
|
||||||
define('CURLOPT_TIMECONDITION',33);
|
|
||||||
define('CURLOPT_TIMEVALUE',34);
|
|
||||||
define('CURLOPT_HTTPREQUEST',10035);
|
|
||||||
define('CURLOPT_CUSTOMREQUEST',10036);
|
|
||||||
define('CURLOPT_STDERR',10037);
|
|
||||||
define('CURLOPT_POSTQUOTE',10039);
|
|
||||||
define('CURLOPT_WRITEINFO',10040);
|
|
||||||
define('CURLOPT_VERBOSE',41);
|
|
||||||
define('CURLOPT_HEADER',42);
|
|
||||||
define('CURLOPT_NOPROGRESS',43);
|
|
||||||
define('CURLOPT_NOBODY',44);
|
|
||||||
define('CURLOPT_FAILONERROR',45);
|
|
||||||
define('CURLOPT_UPLOAD',46);
|
|
||||||
define('CURLOPT_POST',47);
|
|
||||||
define('CURLOPT_FTPLISTONLY',48);
|
|
||||||
define('CURLOPT_FTPAPPEND',50);
|
|
||||||
define('CURLOPT_NETRC',51);
|
|
||||||
define('CURLOPT_FOLLOWLOCATION',52);
|
|
||||||
define('CURLOPT_FTPASCII',53);
|
|
||||||
define('CURLOPT_TRANSFERTEXT',53);
|
|
||||||
define('CURLOPT_PUT',54);
|
|
||||||
define('CURLOPT_MUTE',55);
|
|
||||||
define('CURLOPT_PROGRESSFUNCTION',20056);
|
|
||||||
define('CURLOPT_PROGRESSDATA',10057);
|
|
||||||
define('CURLOPT_AUTOREFERER',58);
|
|
||||||
define('CURLOPT_PROXYPORT',59);
|
|
||||||
define('CURLOPT_POSTFIELDSIZE',60);
|
|
||||||
define('CURLOPT_HTTPPROXYTUNNEL',61);
|
|
||||||
define('CURLOPT_INTERFACE',10062);
|
|
||||||
define('CURLOPT_KRB4LEVEL',10063);
|
|
||||||
define('CURLOPT_SSL_VERIFYPEER',64);
|
|
||||||
define('CURLOPT_CAINFO',10065);
|
|
||||||
define('CURLOPT_PASSWDFUNCTION',20066);
|
|
||||||
define('CURLOPT_PASSWDDATA',10067);
|
|
||||||
define('CURLOPT_MAXREDIRS',68);
|
|
||||||
define('CURLOPT_FILETIME',10069);
|
|
||||||
define('CURLOPT_TELNETOPTIONS',10070);
|
|
||||||
define('CURLOPT_MAXCONNECTS',71);
|
|
||||||
define('CURLOPT_CLOSEPOLICY',72);
|
|
||||||
define('CURLOPT_CLOSEFUNCTION',20073);
|
|
||||||
define('CURLOPT_FRESH_CONNECT',74);
|
|
||||||
define('CURLOPT_FORBID_REUSE',75);
|
|
||||||
define('CURLOPT_RANDOM_FILE',10076);
|
|
||||||
define('CURLOPT_EGDSOCKET',10077);
|
|
||||||
define('CURLOPT_CONNECTTIMEOUT',78);
|
|
||||||
define('CURLOPT_HEADERFUNCTION',20079);
|
|
||||||
define('CURLOPT_HTTPGET',80);
|
|
||||||
define('CURLOPT_SSL_VERIFYHOST',81);
|
|
||||||
define('CURLOPT_COOKIEJAR',10082);
|
|
||||||
define('CURLOPT_SSL_CIPHER_LIST',10083);
|
|
||||||
define('CURLOPT_HTTP_VERSION',84);
|
|
||||||
define('CURLOPT_FTP_USE_EPSV',85);
|
|
||||||
define('CURLOPT_SSLCERTTYPE',10086);
|
|
||||||
define('CURLOPT_SSLKEY',10087);
|
|
||||||
define('CURLOPT_SSLKEYTYPE',10088);
|
|
||||||
define('CURLOPT_SSLENGINE',10089);
|
|
||||||
define('CURLOPT_SSLENGINE_DEFAULT',90);
|
|
||||||
define('CURLOPT_DNS_USE_GLOBAL_CACHE',91);
|
|
||||||
define('CURLOPT_DNS_CACHE_TIMEOUT',92);
|
|
||||||
define('CURLOPT_PREQUOTE',10093);
|
|
||||||
|
|
||||||
define('CURLINFO_EFFECTIVE_URL',1);
|
|
||||||
define('CURLINFO_HTTP_CODE',2);
|
|
||||||
define('CURLINFO_FILETIME',14);
|
|
||||||
define('CURLINFO_TOTAL_TIME',3);
|
|
||||||
define('CURLINFO_NAMELOOKUP_TIME',4);
|
|
||||||
define('CURLINFO_CONNECT_TIME',5);
|
|
||||||
define('CURLINFO_PRETRANSFER_TIME',6);
|
|
||||||
define('CURLINFO_STARTTRANSFER_TIME',17);
|
|
||||||
define('CURLINFO_REDIRECT_TIME',19);
|
|
||||||
define('CURLINFO_REDIRECT_COUNT',20);
|
|
||||||
define('CURLINFO_SIZE_UPLOAD',7);
|
|
||||||
define('CURLINFO_SIZE_DOWNLOAD',8);
|
|
||||||
define('CURLINFO_SPEED_DOWNLOAD',9);
|
|
||||||
define('CURLINFO_SPEED_UPLOAD',10);
|
|
||||||
define('CURLINFO_HEADER_SIZE',11);
|
|
||||||
define('CURLINFO_REQUEST_SIZE',12);
|
|
||||||
define('CURLINFO_SSL_VERIFYRESULT',13);
|
|
||||||
define('CURLINFO_CONTENT_LENGTH_DOWNLOAD',15);
|
|
||||||
define('CURLINFO_CONTENT_LENGTH_UPLOAD',16);
|
|
||||||
define('CURLINFO_CONTENT_TYPE',18);
|
|
||||||
|
|
||||||
|
|
||||||
define("TIMECOND_ISUNMODSINCE",1);
|
|
||||||
define("TIMECOND_IFMODSINCE",2);
|
|
||||||
|
|
||||||
|
|
||||||
function _curlopt_name($curlopt) {
|
|
||||||
foreach (get_defined_constants() as $k=>$v) {
|
|
||||||
if ( (substr($k,0,8)=="CURLOPT_") && ($v==$curlopt)) return $k;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize a CURL emulation session
|
|
||||||
function curl_init($url=false) {
|
|
||||||
$i = $GLOBALS["_CURLEXT_OPT"]["index"]++;
|
|
||||||
$GLOBALS["_CURLEXT_OPT"][$i] = array("url"=>$url);
|
|
||||||
|
|
||||||
return $i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set an option for a CURL emulation transfer
|
|
||||||
function curl_setopt($ch,$option,$value) {
|
|
||||||
|
|
||||||
$opt = &$GLOBALS["_CURLEXT_OPT"][$ch];
|
|
||||||
if (!$opt["args"]) $opt["args"] = array();
|
|
||||||
$args = &$opt["args"];
|
|
||||||
if (!$opt["settings"]) $opt["settings"] = array();
|
|
||||||
$settings = &$opt["settings"];
|
|
||||||
|
|
||||||
switch($option) {
|
|
||||||
case CURLOPT_URL:
|
|
||||||
$opt["url"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_VERBOSE:
|
|
||||||
$opt["verbose"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_USERPWD:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["user"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_PROXYUSERPWD:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["proxy-user"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_COOKIE:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
if ( is_bool($value) || (strpos($value,"=")!==false) ) $settings["cookie"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_COOKIEFILE:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["cookie"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_COOKIEJAR:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["cookie-jar"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_CUSTOMREQUEST:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["request"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_PROXY:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["proxy"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_INTERFACE:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["interface"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_KRB4LEVEL:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["krb4"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_SSLCERT:
|
|
||||||
$pass = "";
|
|
||||||
if (is_string($settings["cert"])) {
|
|
||||||
list(,$pass) = explode(":",$settings["cert"]);
|
|
||||||
if (strlen($pass)) $pass = ":$pass";
|
|
||||||
}
|
|
||||||
$settings["cert"] = $value.$pass;
|
|
||||||
break;
|
|
||||||
case CURLOPT_SSLCERTPASSWD:
|
|
||||||
$filename = "";
|
|
||||||
if (is_string($settings["cert"])) {
|
|
||||||
list($filename,) = explode(":",$settings["cert"]);
|
|
||||||
}
|
|
||||||
$settings["cert"] = $filename.":".$value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_RANGE:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["range"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_REFERER:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["referer"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_NOBODY:
|
|
||||||
$settings["head"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_FAILONERROR:
|
|
||||||
$opt["fail_on_error"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_USERAGENT:
|
|
||||||
$settings["user-agent"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_HEADER:
|
|
||||||
$settings["include"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_RETURNTRANSFER:
|
|
||||||
$opt["return_transfer"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_TIMEOUT:
|
|
||||||
$settings["max-time"] = (int) $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_HTTPHEADER:
|
|
||||||
reset($value);
|
|
||||||
foreach ($value as $k=>$header) $args[] = "header=".$header;
|
|
||||||
break;
|
|
||||||
case CURLOPT_POST:
|
|
||||||
$settings["data"]["enabled"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_POSTFIELDS:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["data"]["value"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_SSL_VERIFYPEER:
|
|
||||||
$settings["insecure"] = ($value==0);
|
|
||||||
break;
|
|
||||||
case CURLOPT_SSL_VERIFYHOST:
|
|
||||||
// not supported by the commandline client
|
|
||||||
break;
|
|
||||||
case CURLOPT_FOLLOWLOCATION:
|
|
||||||
$settings["location"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_PUT:
|
|
||||||
$settings["upload-file"]["enabled"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_INFILE:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
|
|
||||||
if (is_resource($value)) {
|
|
||||||
|
|
||||||
// Ugh, this is a terrible hack. The CURL extension accepts a file handle, but
|
|
||||||
// the CURL binary obviously wants a filename. Since you can't derive a filename
|
|
||||||
// from a file handle, we have to make a copy of the file from the file handle,
|
|
||||||
// then pass the temporary filename to the CURL binary.
|
|
||||||
|
|
||||||
$tmpfilename = tempnam("/tmp","cif");
|
|
||||||
$fp = @fopen($tmpfilename,"w");
|
|
||||||
if (!$fp) {
|
|
||||||
trigger_error("CURL emulation library could not create a temporary file for CURLOPT_INFILE; upload aborted",E_USER_WARNING);
|
|
||||||
} else {
|
|
||||||
while (!feof($value)) {
|
|
||||||
$contents = fread($value,8192);
|
|
||||||
fwrite($fp,$contents);
|
|
||||||
}
|
|
||||||
fclose($fp);
|
|
||||||
// if a temporary file was previously created, unlink it
|
|
||||||
if ($settings["upload-file"]["value"] && file_exists($settings["upload-file"]["value"]))FileHandler::removeFile($settings["upload-file"]["value"]);
|
|
||||||
|
|
||||||
// set the new upload-file filename
|
|
||||||
$settings["upload-file"]["value"] = $tmpfilename;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
trigger_error("CURLOPT_INFILE must specify a valid file resource",E_USER_WARNING);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case CURLOPT_MUTE:
|
|
||||||
// we're already mute, no?
|
|
||||||
break;
|
|
||||||
case CURLOPT_LOW_SPEED_LIMIT:
|
|
||||||
$settings["speed-limit"] = (int) $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_LOW_SPEED_TIME:
|
|
||||||
$settings["speed-time"] = (int) $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_RESUME_FROM:
|
|
||||||
$settings["continue-at"] = (int) $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_CAINFO:
|
|
||||||
if ($value==="") $value = false;
|
|
||||||
$settings["cacert"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_SSLVERSION:
|
|
||||||
$value = (int) $value;
|
|
||||||
switch($value) {
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
unset($settings["sslv2"]);
|
|
||||||
unset($settings["sslv3"]);
|
|
||||||
$settings["sslv".$value] = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CURLOPT_TIMECONDITION:
|
|
||||||
// untested - I'm lazy :)
|
|
||||||
if (!isset($settings["time-cond"]["enabled"])) $settings["time-cond"]["enabled"] = false;
|
|
||||||
if (!$settings["time-cond"]["value"]) $settings["time-cond"]["value"] = 1;
|
|
||||||
|
|
||||||
$settings["time-cond"]["value"] = abs($settings["time-cond"]["value"]);
|
|
||||||
if ($value==TIMECOND_ISUNMODSINCE) {
|
|
||||||
$settings["time-cond"]["value"] *= -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case CURLOPT_TIMEVALUE:
|
|
||||||
// untested - I'm lazy :)
|
|
||||||
if ($settings["time-cond"]["value"]) {
|
|
||||||
$sign = $settings["time-cond"]["value"] / abs($settings["time-cond"]["value"]);
|
|
||||||
} else {
|
|
||||||
$sign = 1;
|
|
||||||
}
|
|
||||||
$settings["time-cond"]["value"] = (int) $value * $sign;
|
|
||||||
break;
|
|
||||||
case CURLOPT_FILE:
|
|
||||||
if (is_resource($value)) {
|
|
||||||
$opt["output_handle"] = $value;
|
|
||||||
} else {
|
|
||||||
trigger_error("CURLOPT_FILE must specify a valid file resource",E_USER_WARNING);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CURLOPT_WRITEHEADER:
|
|
||||||
if (is_resource($value)) {
|
|
||||||
$opt["header_handle"] = $value;
|
|
||||||
} else {
|
|
||||||
trigger_error("CURLOPT_WRITEHEADER must specify a valid file resource",E_USER_WARNING);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CURLOPT_STDERR:
|
|
||||||
// not implemented for now - not really relevant
|
|
||||||
break;
|
|
||||||
// FTP stuff not implemented
|
|
||||||
case CURLOPT_QUOTE:
|
|
||||||
case CURLOPT_POSTQUOTE:
|
|
||||||
case CURLOPT_UPLOAD:
|
|
||||||
case CURLOPT_FTPLISTONLY:
|
|
||||||
case CURLOPT_FTPAPPEND:
|
|
||||||
case CURLOPT_FTPPORT:
|
|
||||||
// Other stuff not implemented
|
|
||||||
case CURLOPT_NETRC:
|
|
||||||
default:
|
|
||||||
trigger_error("CURL emulation does not implement CURL option "._curlopt_name($option),E_USER_WARNING);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform a CURL emulation session
|
|
||||||
function curl_exec($ch) {
|
|
||||||
$opt = &$GLOBALS["_CURLEXT_OPT"][$ch];
|
|
||||||
$url = $opt["url"];
|
|
||||||
$verbose = $opt["verbose"];
|
|
||||||
|
|
||||||
// ask commandline CURL to return its statistics at the end of its output
|
|
||||||
$opt["settings"]["write-out"] = "%{http_code}|%{time_total}|%{time_namelookup}|%{time_connect}|%{time_pretransfer}|%{time_starttransfer}|%{size_download}|%{size_upload}|%{size_header}|%{size_request}|%{speed_download}|%{speed_upload}|||||||%{content_type}|%{url_effective}";
|
|
||||||
$writeout_order = array(
|
|
||||||
CURLINFO_HTTP_CODE,
|
|
||||||
CURLINFO_TOTAL_TIME,
|
|
||||||
CURLINFO_NAMELOOKUP_TIME,
|
|
||||||
CURLINFO_CONNECT_TIME,
|
|
||||||
CURLINFO_PRETRANSFER_TIME,
|
|
||||||
CURLINFO_STARTTRANSFER_TIME,
|
|
||||||
CURLINFO_SIZE_DOWNLOAD,
|
|
||||||
CURLINFO_SIZE_UPLOAD,
|
|
||||||
CURLINFO_HEADER_SIZE,
|
|
||||||
CURLINFO_REQUEST_SIZE,
|
|
||||||
CURLINFO_SPEED_DOWNLOAD,
|
|
||||||
CURLINFO_SPEED_UPLOAD,
|
|
||||||
|
|
||||||
// the following 5 items are not provided by commandline CURL, and thus are left empty
|
|
||||||
CURLINFO_FILETIME,
|
|
||||||
CURLINFO_REDIRECT_TIME,
|
|
||||||
CURLINFO_SSL_VERIFYRESULT,
|
|
||||||
CURLINFO_CONTENT_LENGTH_DOWNLOAD,
|
|
||||||
CURLINFO_CONTENT_LENGTH_UPLOAD,
|
|
||||||
CURLINFO_REDIRECT_COUNT,
|
|
||||||
|
|
||||||
CURLINFO_CONTENT_TYPE,
|
|
||||||
CURLINFO_EFFECTIVE_URL,
|
|
||||||
);
|
|
||||||
|
|
||||||
// if the CURLOPT_NOBODY option was specified (to remove the body from the output),
|
|
||||||
// but an output file handle was set, we need to tell CURL to return the body so
|
|
||||||
// that we can write it to the output handle and strip it from the output
|
|
||||||
if ($opt["settings"]["head"] && $opt["output_handle"]) {
|
|
||||||
unset($opt["settings"]["head"]);
|
|
||||||
$strip_body = true;
|
|
||||||
}
|
|
||||||
// if the CURLOPT_HEADER option was NOT specified, but a header file handle was
|
|
||||||
// specified, we again need to tell CURL to return the headers so we can write
|
|
||||||
// them, then strip them from the output
|
|
||||||
if (!isset($opt["settings"]["include"]) && isset($opt["header_handle"])) {
|
|
||||||
$opt["settings"]["include"] = true;
|
|
||||||
$strip_headers = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// build the CURL argument list
|
|
||||||
$arguments = "";
|
|
||||||
foreach ($opt["args"] as $k=>$arg) {
|
|
||||||
list($argname,$argval) = explode('=',$arg,2);
|
|
||||||
$arguments .= "--$argname ".escapeshellarg($argval)." ";
|
|
||||||
}
|
|
||||||
foreach ($opt["settings"] as $argname=>$argval) {
|
|
||||||
if (is_array($argval)) {
|
|
||||||
if (isset($argval["enabled"]) && !$argval["enabled"]) continue;
|
|
||||||
$argval = $argval["value"];
|
|
||||||
}
|
|
||||||
if ($argval===false) continue;
|
|
||||||
if (is_bool($argval)) $argval = "";
|
|
||||||
$arguments .= "--$argname ".escapeshellarg($argval)." ";
|
|
||||||
}
|
|
||||||
|
|
||||||
// build the CURL commandline and execute it
|
|
||||||
$cmd = CURL_PATH." ".$arguments." ".escapeshellarg($url);
|
|
||||||
|
|
||||||
if ($verbose) echo "libcurlemu: Executing: $cmd\n";
|
|
||||||
exec($cmd,$output,$ret);
|
|
||||||
|
|
||||||
if ($verbose) {
|
|
||||||
echo "libcurlemu: Result: ";
|
|
||||||
var_dump($output);
|
|
||||||
echo "libcurlemu: Exit code: $ret\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for errors
|
|
||||||
$opt["errno"] = $ret;
|
|
||||||
if ($ret) $opt["error"] = "CURL error #$ret";
|
|
||||||
|
|
||||||
// die if CURLOPT_FAILONERROR is set and the HTTP result code is greater than 300
|
|
||||||
if ($opt["fail_on_error"]) {
|
|
||||||
if (preg_match("/^HTTP\/1.[0-9]+ ([0-9]{3}) /",$output[0],$matches)) {
|
|
||||||
$resultcode = (int) $matches[1];
|
|
||||||
if ($resultcode>300) die;
|
|
||||||
} else {
|
|
||||||
die; // couldn't get result code!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// pull the statistics out from the output
|
|
||||||
$stats = explode('|',array_pop($output));
|
|
||||||
foreach ($writeout_order as $k=>$item) {
|
|
||||||
$opt["stats"][$item] = $stats[$k];
|
|
||||||
}
|
|
||||||
|
|
||||||
// build the response string
|
|
||||||
$output = implode("\r\n",$output);
|
|
||||||
|
|
||||||
|
|
||||||
// find the header end position if needed
|
|
||||||
if ($strip_headers || $strip_body || isset($opt["header_handle"])) {
|
|
||||||
$headerpos = strpos($output,"\r\n\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// if a file handle was provided for header output, extract the headers
|
|
||||||
// and write them to the handle
|
|
||||||
if (isset($opt["header_handle"])) {
|
|
||||||
$headers = substr($output,0,$headerpos);
|
|
||||||
fwrite($opt["header_handle"],$headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the caller did not request headers in the output, strip them
|
|
||||||
if ($strip_headers) {
|
|
||||||
$output = substr($output,$headerpos+4);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the caller did not request the response body in the output, strip it
|
|
||||||
if ($strip_body) {
|
|
||||||
if ($strip_headers) {
|
|
||||||
$body = $output;
|
|
||||||
$output = "";
|
|
||||||
} else {
|
|
||||||
$body = substr($output,$headerpos+4);
|
|
||||||
$output = substr($output,0,$headerpos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if a file handle was provided for output, write the output to it
|
|
||||||
if (isset($opt["output_handle"])) {
|
|
||||||
fwrite($opt["output_handle"],$output);
|
|
||||||
|
|
||||||
// if the caller requested that the response be returned, return it
|
|
||||||
} elseif ($opt["return_transfer"]) {
|
|
||||||
return $output;
|
|
||||||
|
|
||||||
// otherwise, just echo the output to stdout
|
|
||||||
} else {
|
|
||||||
echo $output;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function curl_close($ch) {
|
|
||||||
$opt = &$GLOBALS["_CURLEXT_OPT"][$ch];
|
|
||||||
|
|
||||||
if ($opt["settings"]) {
|
|
||||||
$settings = &$opt["settings"];
|
|
||||||
// if the user used CURLOPT_INFILE to specify a file to upload, remove the
|
|
||||||
// temporary file created for the CURL binary
|
|
||||||
if ($settings["upload-file"]["value"] && file_exists($settings["upload-file"]["value"]))FileHandler::removeFile($settings["upload-file"]["value"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($GLOBALS["_CURLEXT_OPT"][$ch]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function curl_errno($ch) {
|
|
||||||
return (int) $GLOBALS["_CURLEXT_OPT"][$ch]["errno"];
|
|
||||||
}
|
|
||||||
|
|
||||||
function curl_error($ch) {
|
|
||||||
return $GLOBALS["_CURLEXT_OPT"][$ch]["error"];
|
|
||||||
}
|
|
||||||
|
|
||||||
function curl_getinfo($ch,$opt=NULL) {
|
|
||||||
if ($opt) {
|
|
||||||
return $GLOBALS["_CURLEXT_OPT"][$ch]["stats"][$opt];
|
|
||||||
} else {
|
|
||||||
$curlinfo_tags = array(
|
|
||||||
"url"=>CURLINFO_EFFECTIVE_URL,
|
|
||||||
"content_type"=>CURLINFO_CONTENT_TYPE,
|
|
||||||
"http_code"=>CURLINFO_HTTP_CODE,
|
|
||||||
"header_size"=>CURLINFO_HEADER_SIZE,
|
|
||||||
"request_size"=>CURLINFO_REQUEST_SIZE,
|
|
||||||
"filetime"=>CURLINFO_FILETIME,
|
|
||||||
"ssl_verify_result"=>CURLINFO_SSL_VERIFYRESULT,
|
|
||||||
"redirect_count"=>CURLINFO_REDIRECT_COUNT,
|
|
||||||
"total_time"=>CURLINFO_TOTAL_TIME,
|
|
||||||
"namelookup_time"=>CURLINFO_NAMELOOKUP_TIME,
|
|
||||||
"connect_time"=>CURLINFO_CONNECT_TIME,
|
|
||||||
"pretransfer_time"=>CURLINFO_PRETRANSFER_TIME,
|
|
||||||
"size_upload"=>CURLINFO_SIZE_UPLOAD,
|
|
||||||
"size_download"=>CURLINFO_SIZE_DOWNLOAD,
|
|
||||||
"speed_download"=>CURLINFO_SPEED_DOWNLOAD,
|
|
||||||
"speed_upload"=>CURLINFO_SPEED_UPLOAD,
|
|
||||||
"download_content_length"=>CURLINFO_CONTENT_LENGTH_DOWNLOAD,
|
|
||||||
"upload_content_length"=>CURLINFO_CONTENT_LENGTH_UPLOAD,
|
|
||||||
"starttransfer_time"=>CURLINFO_STARTTRANSFER_TIME,
|
|
||||||
"redirect_time"=>CURLINFO_REDIRECT_TIME
|
|
||||||
);
|
|
||||||
$res = array();
|
|
||||||
foreach ($curlinfo_tags as $tag=>$opt) {
|
|
||||||
$res[$tag] = $GLOBALS["_CURLEXT_OPT"][$ch]["stats"][$opt];
|
|
||||||
}
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function curl_version() {
|
|
||||||
return "libcurlemu/".CURLEXT_VERSION."-ext";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
@ -1,453 +0,0 @@
|
||||||
<?php
|
|
||||||
/* CURL Extension Emulation Library (Native PHP)
|
|
||||||
* Copyright 2004-2007, Steve Blinch
|
|
||||||
* http://code.blitzaffe.com
|
|
||||||
* ============================================================================
|
|
||||||
*
|
|
||||||
* DESCRIPTION
|
|
||||||
*
|
|
||||||
* Provides a pure-PHP implementation of the PHP CURL extension, for use on
|
|
||||||
* systems which do not already have the CURL extension installed. It emulates
|
|
||||||
* all of the curl_* functions normally provided by the CURL extension itself,
|
|
||||||
* and uses an internal, native-PHP HTTP library to make requests.
|
|
||||||
*
|
|
||||||
* This library will automatically detect whether or not the "real" CURL
|
|
||||||
* extension is installed, and if so, it will not interfere. Thus, it can be
|
|
||||||
* used to ensure that, one way or another, the CURL functions are available
|
|
||||||
* for use.
|
|
||||||
*
|
|
||||||
* Note that this is only a *rough* emulation of CURL; it is not exact, and
|
|
||||||
* many of CURL's options are not implemented. For a more precise emulation of
|
|
||||||
* CURL, you may want to try our other libcurlexternal library which is based on
|
|
||||||
* the CURL console binary (and is virtually identical to the CURL extension).
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* USAGE
|
|
||||||
*
|
|
||||||
* Please see the PHP documentation under the "CURL, Client URL Library
|
|
||||||
* Functions" section for information about using this library. Almost all of
|
|
||||||
* the documentation and examples in the PHP manual should work with this
|
|
||||||
* library.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* LICENSE
|
|
||||||
*
|
|
||||||
* This script is free software; you can redistribute it and/or modify it under the
|
|
||||||
* terms of the GNU General Public License as published by the Free Software
|
|
||||||
* Foundation; either version 2 of the License, or (at your option) any later
|
|
||||||
* version.
|
|
||||||
*
|
|
||||||
* This script is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
||||||
* details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this script; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
// if the real CURL PHP extension is installed, exit without doing anything;
|
|
||||||
// if libcurlemu is installed and providing a wrapper for the CURL binary,
|
|
||||||
// exit without doing anything
|
|
||||||
if (!extension_loaded("curl") && !function_exists("curl_init")) {
|
|
||||||
|
|
||||||
|
|
||||||
// if the CURL binary was not found, do one of the following:
|
|
||||||
// - if CURLNAT_MISSING_ABORT was defined, then exit without
|
|
||||||
// implementing the CURL functions
|
|
||||||
// - otherwise, raise a fatal error and halt the script
|
|
||||||
if (!class_exists("HTTPRetriever")) {
|
|
||||||
if (is_readable("./modules/member/openid_lib/class_HTTPRetriever.php")) {
|
|
||||||
define("HTTPR_NO_REDECLARE_CURL",true);
|
|
||||||
require_once("./modules/member/openid_lib/class_HTTPRetriever.php");
|
|
||||||
} else {
|
|
||||||
if (defined("CURLNAT_MISSING_ABORT") && CURLNAT_MISSING_ABORT) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
trigger_error("CURL extension is not loaded, libcurlemu is not loaded, and the HTTPRetriever class is unavailable",E_USER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
define("CURLNAT_VERSION","1.0.0");
|
|
||||||
|
|
||||||
define('CURLOPT_NOTHING',0);
|
|
||||||
define('CURLOPT_FILE',10001);
|
|
||||||
define('CURLOPT_URL',10002);
|
|
||||||
define('CURLOPT_PORT',3);
|
|
||||||
define('CURLOPT_PROXY',10004);
|
|
||||||
define('CURLOPT_USERPWD',10005);
|
|
||||||
define('CURLOPT_PROXYUSERPWD',10006);
|
|
||||||
define('CURLOPT_RANGE',10007);
|
|
||||||
define('CURLOPT_INFILE',10009);
|
|
||||||
define('CURLOPT_ERRORBUFFER',10010);
|
|
||||||
define('CURLOPT_WRITEFUNCTION',20011);
|
|
||||||
define('CURLOPT_READFUNCTION',20012);
|
|
||||||
define('CURLOPT_TIMEOUT',13);
|
|
||||||
define('CURLOPT_INFILESIZE',14);
|
|
||||||
define('CURLOPT_POSTFIELDS',10015);
|
|
||||||
define('CURLOPT_REFERER',10016);
|
|
||||||
define('CURLOPT_FTPPORT',10017);
|
|
||||||
define('CURLOPT_USERAGENT',10018);
|
|
||||||
define('CURLOPT_LOW_SPEED_LIMIT',19);
|
|
||||||
define('CURLOPT_LOW_SPEED_TIME',20);
|
|
||||||
define('CURLOPT_RESUME_FROM',21);
|
|
||||||
define('CURLOPT_COOKIE',10022);
|
|
||||||
define('CURLOPT_HTTPHEADER',10023);
|
|
||||||
define('CURLOPT_HTTPPOST',10024);
|
|
||||||
define('CURLOPT_SSLCERT',10025);
|
|
||||||
define('CURLOPT_SSLCERTPASSWD',10026);
|
|
||||||
define('CURLOPT_SSLKEYPASSWD',10026);
|
|
||||||
define('CURLOPT_CRLF',27);
|
|
||||||
define('CURLOPT_QUOTE',10028);
|
|
||||||
define('CURLOPT_WRITEHEADER',10029);
|
|
||||||
define('CURLOPT_COOKIEFILE',10031);
|
|
||||||
define('CURLOPT_SSLVERSION',32);
|
|
||||||
define('CURLOPT_TIMECONDITION',33);
|
|
||||||
define('CURLOPT_TIMEVALUE',34);
|
|
||||||
define('CURLOPT_HTTPREQUEST',10035);
|
|
||||||
define('CURLOPT_CUSTOMREQUEST',10036);
|
|
||||||
define('CURLOPT_STDERR',10037);
|
|
||||||
define('CURLOPT_POSTQUOTE',10039);
|
|
||||||
define('CURLOPT_WRITEINFO',10040);
|
|
||||||
define('CURLOPT_VERBOSE',41);
|
|
||||||
define('CURLOPT_HEADER',42);
|
|
||||||
define('CURLOPT_NOPROGRESS',43);
|
|
||||||
define('CURLOPT_NOBODY',44);
|
|
||||||
define('CURLOPT_FAILONERROR',45);
|
|
||||||
define('CURLOPT_UPLOAD',46);
|
|
||||||
define('CURLOPT_POST',47);
|
|
||||||
define('CURLOPT_FTPLISTONLY',48);
|
|
||||||
define('CURLOPT_FTPAPPEND',50);
|
|
||||||
define('CURLOPT_NETRC',51);
|
|
||||||
define('CURLOPT_FOLLOWLOCATION',52);
|
|
||||||
define('CURLOPT_FTPASCII',53);
|
|
||||||
define('CURLOPT_TRANSFERTEXT',53);
|
|
||||||
define('CURLOPT_PUT',54);
|
|
||||||
define('CURLOPT_MUTE',55);
|
|
||||||
define('CURLOPT_PROGRESSFUNCTION',20056);
|
|
||||||
define('CURLOPT_PROGRESSDATA',10057);
|
|
||||||
define('CURLOPT_AUTOREFERER',58);
|
|
||||||
define('CURLOPT_PROXYPORT',59);
|
|
||||||
define('CURLOPT_POSTFIELDSIZE',60);
|
|
||||||
define('CURLOPT_HTTPPROXYTUNNEL',61);
|
|
||||||
define('CURLOPT_INTERFACE',10062);
|
|
||||||
define('CURLOPT_KRB4LEVEL',10063);
|
|
||||||
define('CURLOPT_SSL_VERIFYPEER',64);
|
|
||||||
define('CURLOPT_CAINFO',10065);
|
|
||||||
define('CURLOPT_PASSWDFUNCTION',20066);
|
|
||||||
define('CURLOPT_PASSWDDATA',10067);
|
|
||||||
define('CURLOPT_MAXREDIRS',68);
|
|
||||||
define('CURLOPT_FILETIME',10069);
|
|
||||||
define('CURLOPT_TELNETOPTIONS',10070);
|
|
||||||
define('CURLOPT_MAXCONNECTS',71);
|
|
||||||
define('CURLOPT_CLOSEPOLICY',72);
|
|
||||||
define('CURLOPT_CLOSEFUNCTION',20073);
|
|
||||||
define('CURLOPT_FRESH_CONNECT',74);
|
|
||||||
define('CURLOPT_FORBID_REUSE',75);
|
|
||||||
define('CURLOPT_RANDOM_FILE',10076);
|
|
||||||
define('CURLOPT_EGDSOCKET',10077);
|
|
||||||
define('CURLOPT_CONNECTTIMEOUT',78);
|
|
||||||
define('CURLOPT_HEADERFUNCTION',20079);
|
|
||||||
define('CURLOPT_HTTPGET',80);
|
|
||||||
define('CURLOPT_SSL_VERIFYHOST',81);
|
|
||||||
define('CURLOPT_COOKIEJAR',10082);
|
|
||||||
define('CURLOPT_SSL_CIPHER_LIST',10083);
|
|
||||||
define('CURLOPT_HTTP_VERSION',84);
|
|
||||||
define('CURLOPT_FTP_USE_EPSV',85);
|
|
||||||
define('CURLOPT_SSLCERTTYPE',10086);
|
|
||||||
define('CURLOPT_SSLKEY',10087);
|
|
||||||
define('CURLOPT_SSLKEYTYPE',10088);
|
|
||||||
define('CURLOPT_SSLENGINE',10089);
|
|
||||||
define('CURLOPT_SSLENGINE_DEFAULT',90);
|
|
||||||
define('CURLOPT_DNS_USE_GLOBAL_CACHE',91);
|
|
||||||
define('CURLOPT_DNS_CACHE_TIMEOUT',92);
|
|
||||||
define('CURLOPT_PREQUOTE',10093);
|
|
||||||
|
|
||||||
define('CURLINFO_EFFECTIVE_URL',1);
|
|
||||||
define('CURLINFO_HTTP_CODE',2);
|
|
||||||
define('CURLINFO_FILETIME',14);
|
|
||||||
define('CURLINFO_TOTAL_TIME',3);
|
|
||||||
define('CURLINFO_NAMELOOKUP_TIME',4);
|
|
||||||
define('CURLINFO_CONNECT_TIME',5);
|
|
||||||
define('CURLINFO_PRETRANSFER_TIME',6);
|
|
||||||
define('CURLINFO_STARTTRANSFER_TIME',17);
|
|
||||||
define('CURLINFO_REDIRECT_TIME',19);
|
|
||||||
define('CURLINFO_REDIRECT_COUNT',20);
|
|
||||||
define('CURLINFO_SIZE_UPLOAD',7);
|
|
||||||
define('CURLINFO_SIZE_DOWNLOAD',8);
|
|
||||||
define('CURLINFO_SPEED_DOWNLOAD',9);
|
|
||||||
define('CURLINFO_SPEED_UPLOAD',10);
|
|
||||||
define('CURLINFO_HEADER_SIZE',11);
|
|
||||||
define('CURLINFO_REQUEST_SIZE',12);
|
|
||||||
define('CURLINFO_SSL_VERIFYRESULT',13);
|
|
||||||
define('CURLINFO_CONTENT_LENGTH_DOWNLOAD',15);
|
|
||||||
define('CURLINFO_CONTENT_LENGTH_UPLOAD',16);
|
|
||||||
define('CURLINFO_CONTENT_TYPE',18);
|
|
||||||
|
|
||||||
|
|
||||||
define("TIMECOND_ISUNMODSINCE",1);
|
|
||||||
define("TIMECOND_IFMODSINCE",2);
|
|
||||||
|
|
||||||
|
|
||||||
function _curlopt_name($curlopt) {
|
|
||||||
foreach (get_defined_constants() as $k=>$v) {
|
|
||||||
if ( (substr($k,0,8)=="CURLOPT_") && ($v==$curlopt)) return $k;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize a CURL emulation session
|
|
||||||
function curl_init() {
|
|
||||||
$i = $GLOBALS["_CURLNAT_OPT"]["index"]++;
|
|
||||||
$GLOBALS["_CURLNAT_OPT"][$i] = array();
|
|
||||||
$GLOBALS["_CURLNAT_OPT"][$i]["http"] = &new HTTPRetriever();
|
|
||||||
$GLOBALS["_CURLNAT_OPT"][$i]["include_body"] = true;
|
|
||||||
return $i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set an option for a CURL emulation transfer
|
|
||||||
function curl_setopt($ch,$option,$value) {
|
|
||||||
|
|
||||||
$opt = &$GLOBALS["_CURLNAT_OPT"][$ch];
|
|
||||||
if (!$opt["args"]) $opt["args"] = array();
|
|
||||||
$args = &$opt["args"];
|
|
||||||
if (!$opt["settings"]) $opt["settings"] = array();
|
|
||||||
$settings = &$opt["settings"];
|
|
||||||
$http = &$opt["http"];
|
|
||||||
|
|
||||||
switch($option) {
|
|
||||||
case CURLOPT_URL:
|
|
||||||
$opt["url"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_CUSTOMREQUEST:
|
|
||||||
$opt["method"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_REFERER:
|
|
||||||
$http->headers["Referer"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_NOBODY:
|
|
||||||
$opt["include_body"] = $value==0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_FAILONERROR:
|
|
||||||
$opt["fail_on_error"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_USERAGENT:
|
|
||||||
$http->headers["User-Agent"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_HEADER:
|
|
||||||
$opt["include_headers"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_RETURNTRANSFER:
|
|
||||||
$opt["return_transfer"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_TIMEOUT:
|
|
||||||
$opt["max-time"] = (int) $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_HTTPHEADER:
|
|
||||||
reset($value);
|
|
||||||
foreach ($value as $k=>$header) {
|
|
||||||
list($headername,$headervalue) = explode(":",$header);
|
|
||||||
$http->headers[$headername] = ltrim($headervalue);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CURLOPT_POST:
|
|
||||||
$opt["post"] = $value>0;
|
|
||||||
break;
|
|
||||||
case CURLOPT_POSTFIELDS:
|
|
||||||
$opt["postdata"] = $value;
|
|
||||||
break;
|
|
||||||
case CURLOPT_MUTE:
|
|
||||||
// we're already mute, no?
|
|
||||||
break;
|
|
||||||
case CURLOPT_FILE:
|
|
||||||
if (is_resource($value)) {
|
|
||||||
$opt["output_handle"] = $value;
|
|
||||||
} else {
|
|
||||||
trigger_error("CURLOPT_FILE must specify a valid file resource",E_USER_WARNING);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CURLOPT_WRITEHEADER:
|
|
||||||
if (is_resource($value)) {
|
|
||||||
$opt["header_handle"] = $value;
|
|
||||||
} else {
|
|
||||||
trigger_error("CURLOPT_WRITEHEADER must specify a valid file resource",E_USER_WARNING);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CURLOPT_STDERR:
|
|
||||||
// not implemented for now - not really relevant
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CURLOPT_SSL_VERIFYPEER:
|
|
||||||
case CURLOPT_SSL_VERIFYHOST:
|
|
||||||
// these are automatically disabled using ssl:// anyway
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CURLOPT_USERPWD:
|
|
||||||
list($curl_user,$curl_pass) = explode(':',$value,2);
|
|
||||||
$http->auth_username = $curl_user;
|
|
||||||
$http->auth_password = $curl_pass;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Important stuff not implemented (as it's not yet supported by HTTPRetriever)
|
|
||||||
case CURLOPT_PUT:
|
|
||||||
case CURLOPT_INFILE:
|
|
||||||
case CURLOPT_FOLLOWLOCATION:
|
|
||||||
case CURLOPT_PROXYUSERPWD:
|
|
||||||
case CURLOPT_COOKIE:
|
|
||||||
case CURLOPT_COOKIEFILE:
|
|
||||||
case CURLOPT_PROXY:
|
|
||||||
case CURLOPT_RANGE:
|
|
||||||
case CURLOPT_RESUME_FROM:
|
|
||||||
|
|
||||||
// Things that cannot (reasonably) be implemented here
|
|
||||||
case CURLOPT_LOW_SPEED_LIMIT:
|
|
||||||
case CURLOPT_LOW_SPEED_TIME:
|
|
||||||
case CURLOPT_KRB4LEVEL:
|
|
||||||
case CURLOPT_SSLCERT:
|
|
||||||
case CURLOPT_SSLCERTPASSWD:
|
|
||||||
case CURLOPT_SSLVERSION:
|
|
||||||
case CURLOPT_INTERFACE:
|
|
||||||
case CURLOPT_CAINFO:
|
|
||||||
case CURLOPT_TIMECONDITION:
|
|
||||||
case CURLOPT_TIMEVALUE:
|
|
||||||
|
|
||||||
// FTP stuff not implemented
|
|
||||||
case CURLOPT_QUOTE:
|
|
||||||
case CURLOPT_POSTQUOTE:
|
|
||||||
case CURLOPT_UPLOAD:
|
|
||||||
case CURLOPT_FTPLISTONLY:
|
|
||||||
case CURLOPT_FTPAPPEND:
|
|
||||||
case CURLOPT_FTPPORT:
|
|
||||||
|
|
||||||
// Other stuff not implemented
|
|
||||||
case CURLOPT_VERBOSE:
|
|
||||||
case CURLOPT_NETRC:
|
|
||||||
default:
|
|
||||||
//trigger_error("CURL emulation does not implement CURL option "._curlopt_name($option),E_USER_WARNING);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform a CURL emulation session
|
|
||||||
function curl_exec($ch) {
|
|
||||||
$opt = &$GLOBALS["_CURLNAT_OPT"][$ch];
|
|
||||||
$url = $opt["url"];
|
|
||||||
|
|
||||||
$http = &$opt["http"];
|
|
||||||
$http->disable_curl = true; // avoid problems with recursion, since we *ARE* CURL
|
|
||||||
|
|
||||||
// set time limits if requested
|
|
||||||
if ($opt["max-time"]) {
|
|
||||||
$http->connect_timeout = $opt["max-time"];
|
|
||||||
$http->max_time = $opt["max-time"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($opt["post"]) {
|
|
||||||
$res = $http->post($url,$opt["postdata"]);
|
|
||||||
} elseif ($opt["method"]) {
|
|
||||||
$res = $http->custom($opt["method"],$url,$opt["postdata"]);
|
|
||||||
} else {
|
|
||||||
$res = $http->get($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for errors
|
|
||||||
$opt["errno"] = (!$res && $http->error) ? 1 : 0;
|
|
||||||
if ($opt["errno"]) $opt["error"] = $http->error;
|
|
||||||
|
|
||||||
// die if CURLOPT_FAILONERROR is set and the HTTP result code is greater than 300
|
|
||||||
if ($opt["fail_on_error"]) {
|
|
||||||
if ($http->result_code>300) die;
|
|
||||||
}
|
|
||||||
|
|
||||||
$opt["stats"] = $http->stats;
|
|
||||||
|
|
||||||
|
|
||||||
$headers = "";
|
|
||||||
foreach ($http->response_headers as $k=>$v) {
|
|
||||||
$headers .= "$k: $v\r\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// if a file handle was provided for header output, extract the headers
|
|
||||||
// and write them to the handle
|
|
||||||
if (isset($opt["header_handle"])) {
|
|
||||||
fwrite($opt["header_handle"],$headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = ($opt["include_headers"] ? $headers."\r\n" : "") . ($opt["include_body"] ? $http->response : "");
|
|
||||||
|
|
||||||
// if a file handle was provided for output, write the output to it
|
|
||||||
if (isset($opt["output_handle"])) {
|
|
||||||
fwrite($opt["output_handle"],$output);
|
|
||||||
|
|
||||||
// if the caller requested that the response be returned, return it
|
|
||||||
} elseif ($opt["return_transfer"]) {
|
|
||||||
return $output;
|
|
||||||
|
|
||||||
// otherwise, just echo the output to stdout
|
|
||||||
} else {
|
|
||||||
echo $output;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function curl_close($ch) {
|
|
||||||
$opt = &$GLOBALS["_CURLNAT_OPT"][$ch];
|
|
||||||
|
|
||||||
if ($opt["settings"]) {
|
|
||||||
$settings = &$opt["settings"];
|
|
||||||
// if the user used CURLOPT_INFILE to specify a file to upload, remove the
|
|
||||||
// temporary file created for the CURL binary
|
|
||||||
if ($settings["upload-file"]["value"] && file_exists($settings["upload-file"]["value"]))FileHandler::removeFile($settings["upload-file"]["value"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($GLOBALS["_CURLNAT_OPT"][$ch]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function curl_errno($ch) {
|
|
||||||
return (int) $GLOBALS["_CURLNAT_OPT"][$ch]["errno"];
|
|
||||||
}
|
|
||||||
|
|
||||||
function curl_error($ch) {
|
|
||||||
return $GLOBALS["_CURLNAT_OPT"][$ch]["error"];
|
|
||||||
}
|
|
||||||
|
|
||||||
function curl_getinfo($ch,$opt=NULL) {
|
|
||||||
if ($opt) {
|
|
||||||
$curlinfo_tags = array(
|
|
||||||
CURLINFO_EFFECTIVE_URL=>"url",
|
|
||||||
CURLINFO_CONTENT_TYPE=>"content_type",
|
|
||||||
CURLINFO_HTTP_CODE=>"http_code",
|
|
||||||
CURLINFO_HEADER_SIZE=>"header_size",
|
|
||||||
CURLINFO_REQUEST_SIZE=>"request_size",
|
|
||||||
CURLINFO_FILETIME=>"filetime",
|
|
||||||
CURLINFO_SSL_VERIFYRESULT=>"ssl_verify_result",
|
|
||||||
CURLINFO_REDIRECT_COUNT=>"redirect_count",
|
|
||||||
CURLINFO_TOTAL_TIME=>"total_time",
|
|
||||||
CURLINFO_NAMELOOKUP_TIME=>"namelookup_time",
|
|
||||||
CURLINFO_CONNECT_TIME=>"connect_time",
|
|
||||||
CURLINFO_PRETRANSFER_TIME=>"pretransfer_time",
|
|
||||||
CURLINFO_SIZE_UPLOAD=>"size_upload",
|
|
||||||
CURLINFO_SIZE_DOWNLOAD=>"size_download",
|
|
||||||
CURLINFO_SPEED_DOWNLOAD=>"speed_download",
|
|
||||||
CURLINFO_SPEED_UPLOAD=>"speed_upload",
|
|
||||||
CURLINFO_CONTENT_LENGTH_DOWNLOAD=>"download_content_length",
|
|
||||||
CURLINFO_CONTENT_LENGTH_UPLOAD=>"upload_content_length",
|
|
||||||
CURLINFO_STARTTRANSFER_TIME=>"starttransfer_time",
|
|
||||||
CURLINFO_REDIRECT_TIME=>"redirect_time"
|
|
||||||
);
|
|
||||||
|
|
||||||
$key = $curlinfo_tags[$opt];
|
|
||||||
return $GLOBALS["_CURLNAT_OPT"][$ch]["stats"][$key];
|
|
||||||
} else {
|
|
||||||
return $GLOBALS["_CURLNAT_OPT"][$ch]["stats"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function curl_version() {
|
|
||||||
return "libcurlemu/".CURLNAT_VERSION."-nat";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
131
modules/member/php-openid-1.2.3/Auth/OpenID/SessionStore.php
Normal file
131
modules/member/php-openid-1.2.3/Auth/OpenID/SessionStore.php
Normal file
|
|
@ -0,0 +1,131 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
require_once 'Auth/OpenID.php';
|
||||||
|
require_once 'Auth/OpenID/Interface.php';
|
||||||
|
require_once 'Auth/OpenID/HMACSHA1.php';
|
||||||
|
|
||||||
|
class Auth_OpenID_SessionStore extends Auth_OpenID_OpenIDStore {
|
||||||
|
|
||||||
|
|
||||||
|
function Auth_OpenID_SessionStore()
|
||||||
|
{
|
||||||
|
if(!$_SESSION["sessionStore"]) $_SESSION["sessionStore"] = array();
|
||||||
|
|
||||||
|
$this->max_nonce_age = 6 * 60 * 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
function destory()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAuthKey()
|
||||||
|
{
|
||||||
|
$auth_key = Auth_OpenID_CryptUtil::randomString($this->AUTH_KEY_LEN);
|
||||||
|
$_SESSION["sessionStore"]["authkey"] = $auth_key;
|
||||||
|
return $auth_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _readAuthKey()
|
||||||
|
{
|
||||||
|
return $_SESSION["sessionStore"]["authkey"];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAuthKey()
|
||||||
|
{
|
||||||
|
$auth_key = $this->_readAuthKey();
|
||||||
|
if ($auth_key === null) {
|
||||||
|
$auth_key = $this->createAuthKey();
|
||||||
|
|
||||||
|
if (strlen($auth_key) != $this->AUTH_KEY_LEN) {
|
||||||
|
$fmt = 'Got an invalid auth key from %s. Expected '.
|
||||||
|
'%d-byte string. Got: %s';
|
||||||
|
$msg = sprintf($fmt, $this->auth_key_name, $this->AUTH_KEY_LEN,
|
||||||
|
$auth_key);
|
||||||
|
trigger_error($msg, E_USER_WARNING);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $auth_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
function storeNonce($nonce)
|
||||||
|
{
|
||||||
|
$_SESSION["sessionStore"]["nonce"][$nonce] = time();
|
||||||
|
}
|
||||||
|
|
||||||
|
function useNonce($nonce)
|
||||||
|
{
|
||||||
|
$timestamp = $_SESSION["sessionStore"]["nonce"][$nonce];
|
||||||
|
if($timestamp)
|
||||||
|
{
|
||||||
|
$nonce_age = time() - $timestamp;
|
||||||
|
|
||||||
|
if ($nonce_age > $this->max_nonce_age) {
|
||||||
|
$present = 0;
|
||||||
|
} else {
|
||||||
|
$present = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_remove_nonce($nonce);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$present = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $present;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _remove_nonce($nonce)
|
||||||
|
{
|
||||||
|
if($_SESSION["sessionStore"]["nonce"][$nonce])
|
||||||
|
{
|
||||||
|
unset($_SESSION["sessionStore"]["nonce"][$nonce]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function storeAssociation($server_url, $association)
|
||||||
|
{
|
||||||
|
$_SESSION["sessionStore"]["association"][$server_url][$association->handle] = $association->serialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAssociation($server_url, $handle = null)
|
||||||
|
{
|
||||||
|
$assoc = null;
|
||||||
|
if ($handle != null) {
|
||||||
|
$assoc = $_SESSION["sessionStore"]["association"][$server_url][$handle];
|
||||||
|
}
|
||||||
|
else if($_SESSION["sessionStore"]["association"][$server_url]){
|
||||||
|
foreach($_SESSION["sessionStore"]["association"][$server_url] as $handle => $asso)
|
||||||
|
{
|
||||||
|
$assoc = $asso;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($assoc)
|
||||||
|
{
|
||||||
|
$assoc = Auth_OpenID_Association::deserialize('Auth_OpenID_Association', $assoc);
|
||||||
|
}
|
||||||
|
return $assoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeAssociation($server_url, $handle)
|
||||||
|
{
|
||||||
|
if($handle == null) return false;
|
||||||
|
if($_SESSION["sessionStore"]["association"][$server_url][$handle])
|
||||||
|
{
|
||||||
|
unset($_SESSION["sessionStore"]["association"][$server_url][$handle]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset()
|
||||||
|
{
|
||||||
|
unset($_SESSION["sessionStore"]);
|
||||||
|
$_SESSION["sessionStore"] = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
173
modules/member/php-openid-1.2.3/Auth/OpenID/XEStore.php
Normal file
173
modules/member/php-openid-1.2.3/Auth/OpenID/XEStore.php
Normal file
|
|
@ -0,0 +1,173 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'Auth/OpenID.php';
|
||||||
|
require_once 'Auth/OpenID/Interface.php';
|
||||||
|
require_once 'Auth/OpenID/HMACSHA1.php';
|
||||||
|
|
||||||
|
class Auth_OpenID_XEStore extends Auth_OpenID_OpenIDStore {
|
||||||
|
|
||||||
|
function Auth_OpenID_XEStore()
|
||||||
|
{
|
||||||
|
$this->max_nonce_age = 6 * 60 * 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
function destory()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAuthKey()
|
||||||
|
{
|
||||||
|
$auth_key = Auth_OpenID_CryptUtil::randomString($this->AUTH_KEY_LEN);
|
||||||
|
$oModuleModel = &getModel('module');
|
||||||
|
$memberConfig = $oModuleModel->getModuleConfig('member');
|
||||||
|
$memberConfig->openid_authkey = $auth_key;
|
||||||
|
|
||||||
|
$oModuleController = &getController('module');
|
||||||
|
$oModuleController->inesrtModuleConfig("module", $memberConfig);
|
||||||
|
return $auth_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _readAuthKey()
|
||||||
|
{
|
||||||
|
$oModuleModel = &getModel('module');
|
||||||
|
$memberConfig = $oModuleModel->getModuleConfig('member');
|
||||||
|
return $memberConfig->openid_authkey;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAuthKey()
|
||||||
|
{
|
||||||
|
$auth_key = $this->_readAuthKey();
|
||||||
|
if ($auth_key === null) {
|
||||||
|
$auth_key = $this->createAuthKey();
|
||||||
|
|
||||||
|
if (strlen($auth_key) != $this->AUTH_KEY_LEN) {
|
||||||
|
$fmt = 'Got an invalid auth key from %s. Expected '.
|
||||||
|
'%d-byte string. Got: %s';
|
||||||
|
$msg = sprintf($fmt, $this->auth_key_name, $this->AUTH_KEY_LEN,
|
||||||
|
$auth_key);
|
||||||
|
trigger_error($msg, E_USER_WARNING);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function storeNonce($nonce)
|
||||||
|
{
|
||||||
|
$args->nonce = $nonce;
|
||||||
|
$args->expires = time();
|
||||||
|
$output = executeQuery("member.insertOpenIdNonce", $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
function useNonce($nonce)
|
||||||
|
{
|
||||||
|
$args->nonce = $nonce;
|
||||||
|
$output = executeQuery("member.getOpenIdNonce", $args);
|
||||||
|
if($output->data)
|
||||||
|
{
|
||||||
|
$timestamp = $output->data->expires;
|
||||||
|
$nonce_age = time() - $timestamp;
|
||||||
|
|
||||||
|
if ($nonce_age > $this->max_nonce_age) {
|
||||||
|
$present = 0;
|
||||||
|
} else {
|
||||||
|
$present = 1;
|
||||||
|
}
|
||||||
|
$output = executeQuery("member.deleteOpenIdNonce", $args);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$present = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $present;
|
||||||
|
}
|
||||||
|
|
||||||
|
function storeAssociation($server_url, $association)
|
||||||
|
{
|
||||||
|
$args->server_url = $server_url;
|
||||||
|
$args->handle = $association->handle;
|
||||||
|
$args->secret = bin2hex($association->secret);
|
||||||
|
$args->issued = $association->issued;
|
||||||
|
$args->lifetime = $association->lifetime;
|
||||||
|
$args->assoc_type = $association->assoc_type;
|
||||||
|
executeQuery("member.insertOpenIdAssociation", $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _check_expire(&$assoc)
|
||||||
|
{
|
||||||
|
$assoc_o = new Auth_OpenID_Association($assoc->handle, $assoc->secret, $assoc->issued, $assoc->lifetime, $assoc->assoc_type);
|
||||||
|
if ($assoc_o->getExpiresIn() == 0) {
|
||||||
|
$this->removeAssociation($server_url, $assoc_o->handle);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $assoc_o;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hex2bin($h)
|
||||||
|
{
|
||||||
|
if (!is_string($h)) return null;
|
||||||
|
$r='';
|
||||||
|
for ($a=0; $a<strlen($h); $a+=2) { $r.=chr(hexdec($h{$a}.$h{($a+1)})); }
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _get_assoc($server_url, $handle)
|
||||||
|
{
|
||||||
|
$args->server_url = $server_url;
|
||||||
|
$args->handle = $handle;
|
||||||
|
$output = executeQueryArray("member.getOpenIdAssociation", $args);
|
||||||
|
if(!$output->data) return null;
|
||||||
|
|
||||||
|
if(count($output->data) == 1) {
|
||||||
|
$assoc = array_shift($output->data);
|
||||||
|
$assoc->secret = $this->hex2bin($assoc->secret);
|
||||||
|
return $this->_check_expire($assoc);
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = null;
|
||||||
|
foreach($output->data as $assoc)
|
||||||
|
{
|
||||||
|
if($res == null)
|
||||||
|
{
|
||||||
|
$res = $assoc;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$assoc->secret = $this->hex2bin($assoc->secret);
|
||||||
|
$assoc_o = $this->_check_expire($assoc);
|
||||||
|
if(!$assoc_o) continue;
|
||||||
|
|
||||||
|
if($res->issued < $assoc->issued)
|
||||||
|
{
|
||||||
|
$res = $assoc_o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAssociation($server_url, $handle = null)
|
||||||
|
{
|
||||||
|
$assoc = $this->_get_assoc($server_url, $handle);
|
||||||
|
return $assoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function removeAssociation($server_url, $handle)
|
||||||
|
{
|
||||||
|
if ($this->_get_assoc($server_url, $handle) == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$args->server_url = $server_url;
|
||||||
|
$args->handle = $handle;
|
||||||
|
$output = executeQuery("member.deleteOpenIdAssociation", $args);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset()
|
||||||
|
{
|
||||||
|
$output = executeQuery("member.deleteOpenIdNonce");
|
||||||
|
$output = executeQuery("member.deleteOpenIdAssociation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
9
modules/member/queries/deleteOpenIdAssociation.xml
Normal file
9
modules/member/queries/deleteOpenIdAssociation.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<query id="deleteOpenIdAssociation" action="delete">
|
||||||
|
<tables>
|
||||||
|
<table name="member_openid_association" />
|
||||||
|
</tables>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="server_url" var="server_url" />
|
||||||
|
<condition operation="equal" column="handle" var="handle" pipe="and" />
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
8
modules/member/queries/deleteOpenIdNonce.xml
Normal file
8
modules/member/queries/deleteOpenIdNonce.xml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<query id="deleteOpenIdNonce" action="delete">
|
||||||
|
<tables>
|
||||||
|
<table name="member_openid_nonce" />
|
||||||
|
</tables>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="nonce" var="nonce" />
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
12
modules/member/queries/getOpenIdAssociation.xml
Normal file
12
modules/member/queries/getOpenIdAssociation.xml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
<query id="getOpenIdAssociation" action="select">
|
||||||
|
<tables>
|
||||||
|
<table name="member_openid_association" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="*" />
|
||||||
|
</columns>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="server_url" var="server_url" notnull="notnull" />
|
||||||
|
<condition operation="equal" column="handle" var="handle" pipe="and" />
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
11
modules/member/queries/getOpenIdNonce.xml
Normal file
11
modules/member/queries/getOpenIdNonce.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<query id="getOpenIdNonce" action="select">
|
||||||
|
<tables>
|
||||||
|
<table name="member_openid_nonce" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="*" />
|
||||||
|
</columns>
|
||||||
|
<conditions>
|
||||||
|
<condition operation="equal" column="nonce" var="nonce" notnull="notnull" />
|
||||||
|
</conditions>
|
||||||
|
</query>
|
||||||
13
modules/member/queries/insertOpenIdAssociation.xml
Normal file
13
modules/member/queries/insertOpenIdAssociation.xml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<query id="insertOpenIdAssociation" action="insert">
|
||||||
|
<tables>
|
||||||
|
<table name="member_openid_association" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="server_url" var="server_url" notnull="notnull" />
|
||||||
|
<column name="handle" var="handle" notnull="notnull" />
|
||||||
|
<column name="secret" var="secret" notnull="notnull" />
|
||||||
|
<column name="issued" var="issued" notnull="notnull" />
|
||||||
|
<column name="lifetime" var="lifetime" notnull="notnull" />
|
||||||
|
<column name="assoc_type" var="assoc_type" notnull="notnull" />
|
||||||
|
</columns>
|
||||||
|
</query>
|
||||||
9
modules/member/queries/insertOpenIdNonce.xml
Normal file
9
modules/member/queries/insertOpenIdNonce.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<query id="insertOpenIdNonce" action="insert">
|
||||||
|
<tables>
|
||||||
|
<table name="member_openid_nonce" />
|
||||||
|
</tables>
|
||||||
|
<columns>
|
||||||
|
<column name="nonce" var="nonce" notnull="notnull" />
|
||||||
|
<column name="expires" var="expires" notnull="notnull" />
|
||||||
|
</columns>
|
||||||
|
</query>
|
||||||
8
modules/member/schemas/member_openid_association.xml
Normal file
8
modules/member/schemas/member_openid_association.xml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<table name="member_openid_association">
|
||||||
|
<column name="server_url" type="text" notnull="notnull" />
|
||||||
|
<column name="handle" type="varchar" size="255" notnull="notnull" />
|
||||||
|
<column name="secret" type="text" notnull="notnull" />
|
||||||
|
<column name="issued" type="number" size="11" />
|
||||||
|
<column name="lifetime" type="number" size="11" />
|
||||||
|
<column name="assoc_type" type="varchar" size="64" />
|
||||||
|
</table>
|
||||||
4
modules/member/schemas/member_openid_nonce.xml
Normal file
4
modules/member/schemas/member_openid_nonce.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
<table name="member_openid_nonce">
|
||||||
|
<column name="nonce" type="char" size="8" notnull="notnull" primary_key="primary_key"/>
|
||||||
|
<column name="expires" type="number" size="11" />
|
||||||
|
</table>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue