3 #error_reporting(E_ALL ^ E_NOTICE); 8 if (!$_SERVER[
'REQUEST_URI']) {
9 $_SERVER[
'REQUEST_URI'] = $_SERVER[
'SCRIPT_NAME'].
'?'.$_SERVER[
'QUERY_STRING'];
15 if (version_compare(PHP_VERSION,
'5',
'>=')) {
37 define(
'PHPCAS_VERSION',
'0.4.20-1');
50 define(
"CAS_VERSION_1_0",
'1.0');
54 define(
"CAS_VERSION_2_0",
'2.0');
67 define(
"CAS_PGT_STORAGE_FILE_DEFAULT_PATH",
'/tmp');
71 define(
"CAS_PGT_STORAGE_FILE_FORMAT_PLAIN",
'plain');
75 define(
"CAS_PGT_STORAGE_FILE_FORMAT_XML",
'xml');
86 define(
"CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE",
'mysql');
90 define(
"CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME",
'localhost');
94 define(
"CAS_PGT_STORAGE_DB_DEFAULT_PORT",
'');
98 define(
"CAS_PGT_STORAGE_DB_DEFAULT_DATABASE",
'phpCAS');
102 define(
"CAS_PGT_STORAGE_DB_DEFAULT_TABLE",
'pgt');
116 define(
"PHPCAS_SERVICE_OK",0);
121 define(
"PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE",1);
126 define(
"PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE",2);
131 define(
"PHPCAS_SERVICE_PT_FAILURE",3);
135 define(
"PHPCAS_SERVICE_NOT AVAILABLE",4);
146 define(
"PHPCAS_LANG_ENGLISH",
'english');
147 define(
"PHPCAS_LANG_FRENCH",
'french');
148 define(
"PHPCAS_LANG_GREEK",
'greek');
217 if (version_compare(PHP_VERSION,
'5',
'>='))
219 include_once(dirname(__FILE__).
'/client.php');
223 include_once(dirname(__FILE__).
'/client4.php');
274 $start_session =
true)
279 if ( is_object($PHPCAS_CLIENT) ) {
280 phpCAS::error($PHPCAS_INIT_CALL[
'method'].
'() has already been called (at '.$PHPCAS_INIT_CALL[
'file'].
':'.$PHPCAS_INIT_CALL[
'line'].
')');
282 if ( gettype($server_version) !=
'string' ) {
283 phpCAS::error(
'type mismatched for parameter $server_version (should be `string\')');
285 if ( gettype($server_hostname) !=
'string' ) {
286 phpCAS::error(
'type mismatched for parameter $server_hostname (should be `string\')');
288 if ( gettype($server_port) !=
'integer' ) {
289 phpCAS::error(
'type mismatched for parameter $server_port (should be `integer\')');
291 if ( gettype($server_uri) !=
'string' ) {
292 phpCAS::error(
'type mismatched for parameter $server_uri (should be `string\')');
297 $PHPCAS_INIT_CALL = array(
'done' => TRUE,
298 'file' => $dbg[0][
'file'],
299 'line' => $dbg[0][
'line'],
300 'method' => __CLASS__.
'::'.__FUNCTION__);
303 $PHPCAS_CLIENT =
new CASClient($server_version,FALSE,$server_hostname,$server_port,$server_uri,$start_session);
325 $start_session =
true)
330 if ( is_object($PHPCAS_CLIENT) ) {
331 phpCAS::error($PHPCAS_INIT_CALL[
'method'].
'() has already been called (at '.$PHPCAS_INIT_CALL[
'file'].
':'.$PHPCAS_INIT_CALL[
'line'].
')');
333 if ( gettype($server_version) !=
'string' ) {
334 phpCAS::error(
'type mismatched for parameter $server_version (should be `string\')');
336 if ( gettype($server_hostname) !=
'string' ) {
337 phpCAS::error(
'type mismatched for parameter $server_hostname (should be `string\')');
339 if ( gettype($server_port) !=
'integer' ) {
340 phpCAS::error(
'type mismatched for parameter $server_port (should be `integer\')');
342 if ( gettype($server_uri) !=
'string' ) {
343 phpCAS::error(
'type mismatched for parameter $server_uri (should be `string\')');
348 $PHPCAS_INIT_CALL = array(
'done' => TRUE,
349 'file' => $dbg[0][
'file'],
350 'line' => $dbg[0][
'line'],
351 'method' => __CLASS__.
'::'.__FUNCTION__);
354 $PHPCAS_CLIENT =
new CASClient($server_version,TRUE,$server_hostname,$server_port,$server_uri,$start_session);
378 phpCAS::error(
'type mismatched for parameter $dbg (should be FALSE or the name of the log file)');
382 if ( preg_match(
'/^Win.*/',getenv(
'OS')) ) {
383 if ( isset($_ENV[
'TMP']) ) {
384 $debugDir = $_ENV[
'TMP'].
'/';
385 }
else if ( isset($_ENV[
'TEMP']) ) {
386 $debugDir = $_ENV[
'TEMP'].
'/';
396 if ( empty($PHPCAS_DEBUG[
'unique_id']) ) {
397 $PHPCAS_DEBUG[
'unique_id'] = substr(strtoupper(md5(uniqid(
''))),0,4);
417 if ( function_exists(
'debug_backtrace') ) {
418 return debug_backtrace();
437 if ( $PHPCAS_DEBUG[
'filename'] ) {
438 for ($i=0;$i<$PHPCAS_DEBUG[
'indent'];$i++) {
441 error_log($PHPCAS_DEBUG[
'unique_id'].
' '.$indent_str.$str.
"\n",3,$PHPCAS_DEBUG[
'filename']);
460 if ( is_array($dbg) ) {
461 for ( $i=1; $i<
sizeof($dbg); $i++) {
462 if ( is_array($dbg[$i]) ) {
463 if ( $dbg[$i][
'class'] == __CLASS__ ) {
464 $function = $dbg[$i][
'function'];
465 $file = $dbg[$i][
'file'];
466 $line = $dbg[$i][
'line'];
471 echo
"<br />\n<b>phpCAS error</b>: <font color=\"FF0000\"><b>".__CLASS__.
"::".$function.
'(): '.htmlentities($msg).
"</b></font> in <b>".
$file.
"</b> on line <b>".$line.
"</b><br />\n";
483 phpCAS::log($str.
' ['.basename($dbg[1][
'file']).
':'.$dbg[1][
'line'].
']');
495 if ( !empty($dbg[2][
'class']) ) {
496 $str .= $dbg[2][
'class'].
'::';
498 $str .= $dbg[2][
'function'].
'(';
499 if ( is_array($dbg[2][
'args']) ) {
500 foreach ($dbg[2][
'args'] as $index => $arg) {
504 $str .= str_replace(
"\n",
"",var_export($arg,TRUE));
507 $str .=
') ['.basename($dbg[2][
'file']).
':'.$dbg[2][
'line'].
']';
509 $PHPCAS_DEBUG[
'indent'] ++;
521 $PHPCAS_DEBUG[
'indent'] --;
524 $str .=
'<= '.str_replace(
"\n",
"",var_export(
$res,TRUE));
536 while ( $PHPCAS_DEBUG[
'indent'] > 0 ) {
538 $PHPCAS_DEBUG[
'indent'] --;
562 if ( !is_object($PHPCAS_CLIENT) ) {
563 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
565 if ( gettype(
$lang) !=
'string' ) {
566 phpCAS::error(
'type mismatched for parameter $lang (should be `string\')');
568 $PHPCAS_CLIENT->setLang(
$lang);
607 if ( !is_object($PHPCAS_CLIENT) ) {
608 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
610 if ( gettype($header) !=
'string' ) {
611 phpCAS::error(
'type mismatched for parameter $header (should be `string\')');
613 $PHPCAS_CLIENT->setHTMLHeader($header);
624 if ( !is_object($PHPCAS_CLIENT) ) {
625 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
627 if ( gettype($footer) !=
'string' ) {
628 phpCAS::error(
'type mismatched for parameter $footer (should be `string\')');
630 $PHPCAS_CLIENT->setHTMLHeader($header);
655 if ( !is_object($PHPCAS_CLIENT) ) {
656 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
658 if ( !$PHPCAS_CLIENT->isProxy() ) {
659 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
661 if ( $PHPCAS_AUTH_CHECK_CALL[
'done'] ) {
662 phpCAS::error(
'this method should only be called before '.$PHPCAS_AUTH_CHECK_CALL[
'method'].
'() (called at '.$PHPCAS_AUTH_CHECK_CALL[
'file'].
':'.$PHPCAS_AUTH_CHECK_CALL[
'line'].
')');
664 if ( gettype($format) !=
'string' ) {
665 phpCAS::error(
'type mismatched for parameter $format (should be `string\')');
667 if ( gettype(
$path) !=
'string' ) {
668 phpCAS::error(
'type mismatched for parameter $format (should be `string\')');
670 $PHPCAS_CLIENT->setPGTStorageFile($format,
$path);
700 if ( !is_object($PHPCAS_CLIENT) ) {
701 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
703 if ( !$PHPCAS_CLIENT->isProxy() ) {
704 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
706 if ( $PHPCAS_AUTH_CHECK_CALL[
'done'] ) {
707 phpCAS::error(
'this method should only be called before '.$PHPCAS_AUTH_CHECK_CALL[
'method'].
'() (called at '.$PHPCAS_AUTH_CHECK_CALL[
'file'].
':'.$PHPCAS_AUTH_CHECK_CALL[
'line'].
')');
709 if ( gettype($user) !=
'string' ) {
710 phpCAS::error(
'type mismatched for parameter $user (should be `string\')');
712 if ( gettype($password) !=
'string' ) {
713 phpCAS::error(
'type mismatched for parameter $password (should be `string\')');
715 if ( gettype($database_type) !=
'string' ) {
716 phpCAS::error(
'type mismatched for parameter $database_type (should be `string\')');
718 if ( gettype($hostname) !=
'string' ) {
719 phpCAS::error(
'type mismatched for parameter $hostname (should be `string\')');
721 if ( gettype($port) !=
'integer' ) {
722 phpCAS::error(
'type mismatched for parameter $port (should be `integer\')');
724 if ( gettype($database) !=
'string' ) {
725 phpCAS::error(
'type mismatched for parameter $database (should be `string\')');
727 if ( gettype($table) !=
'string' ) {
728 phpCAS::error(
'type mismatched for parameter $table (should be `string\')');
730 $PHPCAS_CLIENT->setPGTStorageDB($this,$user,$password,$hostname,$port,$database,$table);
761 if ( !is_object($PHPCAS_CLIENT) ) {
762 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
764 if ( !$PHPCAS_CLIENT->isProxy() ) {
765 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
767 if ( !$PHPCAS_AUTH_CHECK_CALL[
'done'] ) {
768 phpCAS::error(
'this method should only be called after the programmer is sure the user has been authenticated (by calling '.__CLASS__.
'::checkAuthentication() or '.__CLASS__.
'::forceAuthentication()');
770 if ( !$PHPCAS_AUTH_CHECK_CALL[
'result'] ) {
771 phpCAS::error(
'authentication was checked (by '.$PHPCAS_AUTH_CHECK_CALL[
'method'].
'() at '.$PHPCAS_AUTH_CHECK_CALL[
'file'].
':'.$PHPCAS_AUTH_CHECK_CALL[
'line'].
') but the method returned FALSE');
773 if ( gettype($url) !=
'string' ) {
774 phpCAS::error(
'type mismatched for parameter $url (should be `string\')');
777 $res = $PHPCAS_CLIENT->serviceWeb($url,$err_code,$output);
804 if ( !is_object($PHPCAS_CLIENT) ) {
805 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
807 if ( !$PHPCAS_CLIENT->isProxy() ) {
808 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
810 if ( !$PHPCAS_AUTH_CHECK_CALL[
'done'] ) {
811 phpCAS::error(
'this method should only be called after the programmer is sure the user has been authenticated (by calling '.__CLASS__.
'::checkAuthentication() or '.__CLASS__.
'::forceAuthentication()');
813 if ( !$PHPCAS_AUTH_CHECK_CALL[
'result'] ) {
814 phpCAS::error(
'authentication was checked (by '.$PHPCAS_AUTH_CHECK_CALL[
'method'].
'() at '.$PHPCAS_AUTH_CHECK_CALL[
'file'].
':'.$PHPCAS_AUTH_CHECK_CALL[
'line'].
') but the method returned FALSE');
816 if ( gettype($url) !=
'string' ) {
817 phpCAS::error(
'type mismatched for parameter $url (should be `string\')');
820 if ( gettype($flags) !=
'integer' ) {
821 phpCAS::error(
'type mismatched for parameter $flags (should be `integer\')');
824 $res = $PHPCAS_CLIENT->serviceMail($url,$flags,$err_code,$err_msg,$pt);
848 if ( !is_object($PHPCAS_CLIENT) ) {
849 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
852 $auth = $PHPCAS_CLIENT->checkAuthentication();
856 $PHPCAS_AUTH_CHECK_CALL = array(
'done' => TRUE,
857 'file' => $dbg[0][
'file'],
858 'line' => $dbg[0][
'line'],
859 'method' => __CLASS__.
'::'.__FUNCTION__,
875 if ( !is_object($PHPCAS_CLIENT) ) {
876 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
879 $auth = $PHPCAS_CLIENT->forceAuthentication();
883 $PHPCAS_AUTH_CHECK_CALL = array(
'done' => TRUE,
884 'file' => $dbg[0][
'file'],
885 'line' => $dbg[0][
'line'],
886 'method' => __CLASS__.
'::'.__FUNCTION__,
890 phpCAS::trace(
'user is not authenticated, redirecting to the CAS server');
891 $PHPCAS_CLIENT->forceAuthentication();
902 function authenticate() 904 phpCAS::error('this method is deprecated. You should use
'.__CLASS__.'::forceAuthentication() instead');
912 phpCAS::error(
'this method is deprecated. You should use '.__CLASS__.
'::forceAuthentication() instead');
925 if ( !is_object($PHPCAS_CLIENT) ) {
926 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
928 if ( !$PHPCAS_AUTH_CHECK_CALL[
'done'] ) {
929 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::forceAuthentication() or '.__CLASS__.
'::isAuthenticated()');
931 if ( !$PHPCAS_AUTH_CHECK_CALL[
'result'] ) {
932 phpCAS::error(
'authentication was checked (by '.$PHPCAS_AUTH_CHECK_CALL[
'method'].
'() at '.$PHPCAS_AUTH_CHECK_CALL[
'file'].
':'.$PHPCAS_AUTH_CHECK_CALL[
'line'].
') but the method returned FALSE');
934 return $PHPCAS_CLIENT->getUser();
946 if ( !is_object($PHPCAS_CLIENT) ) {
947 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
949 return $PHPCAS_CLIENT->getServerLoginURL();
961 if ( !is_object($PHPCAS_CLIENT) ) {
962 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
964 return $PHPCAS_CLIENT->getServerLogoutURL();
976 if ( !is_object($PHPCAS_CLIENT) ) {
977 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::client() or'.__CLASS__.
'::proxy()');
979 $PHPCAS_CLIENT->logout($url);
994 if ( !is_object($PHPCAS_CLIENT) ) {
995 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
997 if ( !$PHPCAS_CLIENT->isProxy() ) {
998 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
1000 if ( gettype($url) !=
'string' ) {
1001 phpCAS::error(
'type mismatched for parameter $url (should be `string\')');
1003 $PHPCAS_CLIENT->setCallbackURL($url);
1017 if ( !is_object($PHPCAS_CLIENT) ) {
1018 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
1020 if ( gettype($url) !=
'string' ) {
1021 phpCAS::error(
'type mismatched for parameter $url (should be `string\')');
1023 $PHPCAS_CLIENT->setURL($url);
1033 if ( !is_object($PHPCAS_CLIENT) ) {
1034 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
1036 return($PHPCAS_CLIENT->getURL());
1045 if ( !is_object($PHPCAS_CLIENT) ) {
1046 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
1048 if ( gettype($target_service) !=
'string' ) {
1049 phpCAS::error(
'type mismatched for parameter $target_service(should be `string\')');
1051 return($PHPCAS_CLIENT->retrievePT($target_service,$err_code,$err_msg));
setPGTStorageFile($format='', $path='')
This method is used to tell phpCAS to store the response of the CAS server to PGT requests onto the f...
serviceWeb($url, &$err_code, &$output)
This method is used to access an HTTP[S] service.
traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
$PHPCAS_INIT_CALL
This global variable is used to store where the initializer is called from (to print a comprehensive ...
retrievePT($target_service, &$err_code, &$err_msg)
Retrieve a Proxy Ticket from the CAS server.
setDebug($filename='')
Set/unset debug mode.
The phpCAS class is a simple container for the phpCAS library.
traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
setHTMLHeader($header)
This method sets the HTML header used for all outputs.
traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
$PHPCAS_CLIENT
This global variable is used by the interface class phpCAS.
traceExit()
This method is used to indicate the end of the execution of the program.
error($msg)
This method is used by interface methods to print an error and where the function was originally call...
setFixedCallbackURL($url='')
Set the fixed URL that will be used by the CAS server to transmit the PGT.
backtrace()
This method is a wrapper for debug_backtrace() that is not available in all PHP versions (>= 4...
getServerLoginURL()
This method returns the URL to be used to login.
$PHPCAS_AUTH_CHECK_CALL
This global variable is used to store where the method checking the authentication is called from (to...
getServiceURL()
Get the URL that is set as the CAS service parameter.
proxy($server_version, $server_hostname, $server_port, $server_uri, $start_session=true)
phpCAS proxy initializer.
forceAuthentication()
This method is called to force authentication if the user was not already authenticated.
traceBegin()
This method is used to indicate the start of the execution of a function in debug mode...
getUser()
This method returns the CAS user's login name.
const PHPCAS_LANG_ENGLISH
forceAuthentication()
This method is called to force authentication if the user was not already authenticated.
logout($url="")
This method is used to logout from CAS.
error($msg)
This method is used by interface methods to print an error and where the function was originally call...
client($server_version, $server_hostname, $server_port, $server_uri, $start_session=true)
phpCAS client initializer.
backtrace()
This method is a wrapper for debug_backtrace() that is not available in all PHP versions (>= 4...
isAuthenticated()
This method is called to check if the user is authenticated (previously or by tickets given in the UR...
serviceMail($url, $flags, &$err_code, &$err_msg, &$pt)
This method is used to access an IMAP/POP3/NNTP service.
trace($str)
This method is used to log something in debug mode.
setPGTStorageDB($user, $password, $database_type='', $hostname='', $port=0, $database='', $table='')
This method is used to tell phpCAS to store the response of the CAS server to PGT requests into a dat...
getVersion()
This method returns the phpCAS version.
setLang($lang)
This method is used to set the language used by phpCAS.
getUser()
This method returns the CAS user's login name.
log($str)
Logs a string in debug mode.
setFixedServiceURL($url)
Set the fixed URL that will be set as the CAS service parameter.
const PHPCAS_VERSION
phpCAS version.
const CAS_PGT_STORAGE_FILE_FORMAT_PLAIN
phpCAS::setPGTStorageFile()'s 2nd parameter to write plain text files
checkAuthentication()
This method is called to check if the user is authenticated (use the gateway feature).
$PHPCAS_DEBUG
This global variable is used to store phpCAS debug mode.
trace($str)
This method is used to log something in debug mode.
traceExit()
This method is used to indicate the end of the execution of the program.
getServerLogoutURL()
This method returns the URL to be used to login.
The CASClient class is a client interface that provides CAS authentication to PHP applications...
log($str)
Logs a string in debug mode.
setHTMLFooter($footer)
This method sets the HTML footer used for all outputs.