3#error_reporting(E_ALL ^ E_NOTICE);
15if (version_compare(PHP_VERSION,
'5',
'>=')) {
37define(
'PHPCAS_VERSION',
'0.4.20-1');
50define(
"CAS_VERSION_1_0",
'1.0');
54define(
"CAS_VERSION_2_0",
'2.0');
67define(
"CAS_PGT_STORAGE_FILE_DEFAULT_PATH",
'/tmp');
71define(
"CAS_PGT_STORAGE_FILE_FORMAT_PLAIN",
'plain');
75define(
"CAS_PGT_STORAGE_FILE_FORMAT_XML",
'xml');
86define(
"CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE",
'mysql');
90define(
"CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME",
'localhost');
94define(
"CAS_PGT_STORAGE_DB_DEFAULT_PORT",
'');
98define(
"CAS_PGT_STORAGE_DB_DEFAULT_DATABASE",
'phpCAS');
102define(
"CAS_PGT_STORAGE_DB_DEFAULT_TABLE",
'pgt');
116define(
"PHPCAS_SERVICE_OK",0);
121define(
"PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE",1);
126define(
"PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE",2);
131define(
"PHPCAS_SERVICE_PT_FAILURE",3);
135define(
"PHPCAS_SERVICE_NOT AVAILABLE",4);
146define(
"PHPCAS_LANG_ENGLISH",
'english');
147define(
"PHPCAS_LANG_FRENCH",
'french');
148define(
"PHPCAS_LANG_GREEK",
'greek');
217if (version_compare(PHP_VERSION,
'5',
'>='))
219 include_once(dirname(__FILE__).
'/client.php');
223 include_once(dirname(__FILE__).
'/client4.php');
274 $start_session =
true)
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\')');
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)
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\')');
349 'file' => $dbg[0][
'file'],
350 'line' => $dbg[0][
'line'],
351 'method' => __CLASS__.
'::'.__FUNCTION__);
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'].
'/';
397 $PHPCAS_DEBUG[
'unique_id'] = substr(strtoupper(md5(uniqid(
''))),0,4);
417 if ( function_exists(
'debug_backtrace') ) {
418 return debug_backtrace();
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'].
']';
524 $str .=
'<= '.str_replace(
"\n",
"",var_export(
$res,TRUE));
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\')');
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\')');
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\')');
656 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
659 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
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\')');
701 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
704 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
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);
762 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
765 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
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()');
773 if ( gettype(
$url) !=
'string' ) {
774 phpCAS::error(
'type mismatched for parameter $url (should be `string\')');
805 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
808 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
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()');
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\')');
849 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
857 'file' => $dbg[0][
'file'],
858 'line' => $dbg[0][
'line'],
859 'method' => __CLASS__.
'::'.__FUNCTION__,
876 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
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');
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');
926 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
929 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::forceAuthentication() or '.__CLASS__.
'::isAuthenticated()');
947 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
962 phpCAS::error(
'this method should not be called before '.__CLASS__.
'::client() or '.__CLASS__.
'::proxy()');
977 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::client() or'.__CLASS__.
'::proxy()');
995 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
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\')');
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\')');
1034 phpCAS::error(
'this method should only be called after '.__CLASS__.
'::proxy()');
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));
The CASClient class is a client interface that provides CAS authentication to PHP applications.
The phpCAS class is a simple container for the phpCAS library.
error($msg)
This method is used by interface methods to print an error and where the function was originally call...
setLang($lang)
This method is used to set the language used by phpCAS.
backtrace()
This method is a wrapper for debug_backtrace() that is not available in all PHP versions (>= 4....
logout($url="")
This method is used to logout from CAS.
setDebug($filename='')
Set/unset debug mode.
serviceWeb($url, &$err_code, &$output)
This method is used to access an HTTP[S] service.
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...
traceExit()
This method is used to indicate the end of the execution of the program.
setPGTStorageFile($format='', $path='')
This method is used to tell phpCAS to store the response of the CAS server to PGT requests onto the f...
getServerLoginURL()
This method returns the URL to be used to login.
retrievePT($target_service, &$err_code, &$err_msg)
Retrieve a Proxy Ticket from the CAS server.
getServiceURL()
Get the URL that is set as the CAS service parameter.
getServerLogoutURL()
This method returns the URL to be used to login.
trace($str)
This method is used to log something in debug mode.
setHTMLHeader($header)
This method sets the HTML header used for all outputs.
log($str)
Logs a string in debug mode.
traceBegin()
This method is used to indicate the start of the execution of a function in debug mode.
setFixedCallbackURL($url='')
Set the fixed URL that will be used by the CAS server to transmit the PGT.
proxy($server_version, $server_hostname, $server_port, $server_uri, $start_session=true)
phpCAS proxy initializer.
setHTMLFooter($footer)
This method sets the HTML footer used for all outputs.
checkAuthentication()
This method is called to check if the user is authenticated (use the gateway feature).
getVersion()
This method returns the phpCAS version.
forceAuthentication()
This method is called to force authentication if the user was not already authenticated.
client($server_version, $server_hostname, $server_port, $server_uri, $start_session=true)
phpCAS client initializer.
getUser()
This method returns the CAS user's login name.
traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
setFixedServiceURL($url)
Set the fixed URL that will be set as the CAS service parameter.
error($msg)
This method is used by interface methods to print an error and where the function was originally call...
backtrace()
This method is a wrapper for debug_backtrace() that is not available in all PHP versions (>= 4....
traceExit()
This method is used to indicate the end of the execution of the program.
trace($str)
This method is used to log something in debug mode.
log($str)
Logs a string in debug mode.
traceBegin()
This method is used to indicate the start of the execution of a function in debug mode.
traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
$PHPCAS_DEBUG
This global variable is used to store phpCAS debug mode.
$PHPCAS_INIT_CALL
This global variable is used to store where the initializer is called from (to print a comprehensive ...
$PHPCAS_AUTH_CHECK_CALL
This global variable is used to store where the method checking the authentication is called from (to...
$PHPCAS_CLIENT
This global variable is used by the interface class phpCAS.
isAuthenticated()
This method is called to check if the user is authenticated (previously or by tickets given in the UR...
forceAuthentication()
This method is called to force authentication if the user was not already authenticated.
getUser()
This method returns the CAS user's login name.
const PHPCAS_LANG_ENGLISH
const CAS_PGT_STORAGE_FILE_FORMAT_PLAIN
phpCAS::setPGTStorageFile()'s 2nd parameter to write plain text files
serviceMail($url, $flags, &$err_code, &$err_msg, &$pt)
This method is used to access an IMAP/POP3/NNTP service.
const PHPCAS_VERSION
phpCAS version.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']