]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CasAuthentication/extlib/CAS.php
Merge branch 'master' into 0.9.x
[quix0rs-gnu-social.git] / plugins / CasAuthentication / extlib / CAS.php
1 <?php\r
2 \r
3 // commented in 0.4.22-RC2 for Sylvain Derosiaux\r
4 // error_reporting(E_ALL ^ E_NOTICE);\r
5 \r
6 //\r
7 // hack by Vangelis Haniotakis to handle the absence of $_SERVER['REQUEST_URI'] in IIS\r
8 //\r
9 if (!$_SERVER['REQUEST_URI']) {\r
10         $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'];\r
11 }\r
12 \r
13 //\r
14 // another one by Vangelis Haniotakis also to make phpCAS work with PHP5\r
15 //\r
16 if (version_compare(PHP_VERSION,'5','>=')) {\r
17         require_once(dirname(__FILE__).'/CAS/domxml-php4-php5.php');\r
18 }\r
19 \r
20 /**\r
21  * @file CAS/CAS.php\r
22  * Interface class of the phpCAS library\r
23  *\r
24  * @ingroup public\r
25  */\r
26 \r
27 // ########################################################################\r
28 //  CONSTANTS\r
29 // ########################################################################\r
30 \r
31 // ------------------------------------------------------------------------\r
32 //  CAS VERSIONS\r
33 // ------------------------------------------------------------------------\r
34 \r
35 /**\r
36  * phpCAS version. accessible for the user by phpCAS::getVersion().\r
37  */\r
38 define('PHPCAS_VERSION','1.0.1');\r
39 \r
40 // ------------------------------------------------------------------------\r
41 //  CAS VERSIONS\r
42 // ------------------------------------------------------------------------\r
43  /**\r
44   * @addtogroup public\r
45   * @{\r
46   */\r
47 \r
48 /**\r
49  * CAS version 1.0\r
50  */\r
51 define("CAS_VERSION_1_0",'1.0');\r
52 /*!\r
53  * CAS version 2.0\r
54  */\r
55 define("CAS_VERSION_2_0",'2.0');\r
56 \r
57 /** @} */\r
58  /**\r
59   * @addtogroup publicPGTStorage\r
60   * @{\r
61   */\r
62 // ------------------------------------------------------------------------\r
63 //  FILE PGT STORAGE\r
64 // ------------------------------------------------------------------------\r
65  /**\r
66   * Default path used when storing PGT's to file\r
67   */\r
68 define("CAS_PGT_STORAGE_FILE_DEFAULT_PATH",'/tmp');\r
69 /**\r
70  * phpCAS::setPGTStorageFile()'s 2nd parameter to write plain text files\r
71  */\r
72 define("CAS_PGT_STORAGE_FILE_FORMAT_PLAIN",'plain');\r
73 /**\r
74  * phpCAS::setPGTStorageFile()'s 2nd parameter to write xml files\r
75  */\r
76 define("CAS_PGT_STORAGE_FILE_FORMAT_XML",'xml');\r
77 /**\r
78  * Default format used when storing PGT's to file\r
79  */\r
80 define("CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT",CAS_PGT_STORAGE_FILE_FORMAT_PLAIN);\r
81 // ------------------------------------------------------------------------\r
82 //  DATABASE PGT STORAGE\r
83 // ------------------------------------------------------------------------\r
84  /**\r
85   * default database type when storing PGT's to database\r
86   */\r
87 define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE",'mysql');\r
88 /**\r
89  * default host when storing PGT's to database\r
90  */\r
91 define("CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME",'localhost');\r
92 /**\r
93  * default port when storing PGT's to database\r
94  */\r
95 define("CAS_PGT_STORAGE_DB_DEFAULT_PORT",'');\r
96 /**\r
97  * default database when storing PGT's to database\r
98  */\r
99 define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE",'phpCAS');\r
100 /**\r
101  * default table when storing PGT's to database\r
102  */\r
103 define("CAS_PGT_STORAGE_DB_DEFAULT_TABLE",'pgt');\r
104 \r
105 /** @} */\r
106 // ------------------------------------------------------------------------\r
107 // SERVICE ACCESS ERRORS\r
108 // ------------------------------------------------------------------------\r
109  /**\r
110   * @addtogroup publicServices\r
111   * @{\r
112   */\r
113 \r
114 /**\r
115  * phpCAS::service() error code on success\r
116  */\r
117 define("PHPCAS_SERVICE_OK",0);\r
118 /**\r
119  * phpCAS::service() error code when the PT could not retrieve because\r
120  * the CAS server did not respond.\r
121  */\r
122 define("PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE",1);\r
123 /**\r
124  * phpCAS::service() error code when the PT could not retrieve because\r
125  * the response of the CAS server was ill-formed.\r
126  */\r
127 define("PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE",2);\r
128 /**\r
129  * phpCAS::service() error code when the PT could not retrieve because\r
130  * the CAS server did not want to.\r
131  */\r
132 define("PHPCAS_SERVICE_PT_FAILURE",3);\r
133 /**\r
134  * phpCAS::service() error code when the service was not available.\r
135  */\r
136 define("PHPCAS_SERVICE_NOT AVAILABLE",4);\r
137 \r
138 /** @} */\r
139 // ------------------------------------------------------------------------\r
140 //  LANGUAGES\r
141 // ------------------------------------------------------------------------\r
142  /**\r
143   * @addtogroup publicLang\r
144   * @{\r
145   */\r
146 \r
147 define("PHPCAS_LANG_ENGLISH",    'english');\r
148 define("PHPCAS_LANG_FRENCH",     'french');\r
149 define("PHPCAS_LANG_GREEK",      'greek');\r
150 define("PHPCAS_LANG_GERMAN",     'german');\r
151 define("PHPCAS_LANG_JAPANESE",   'japanese');\r
152 define("PHPCAS_LANG_SPANISH",    'spanish');\r
153 define("PHPCAS_LANG_CATALAN",    'catalan');\r
154 \r
155 /** @} */\r
156 \r
157 /**\r
158  * @addtogroup internalLang\r
159  * @{\r
160  */\r
161 \r
162 /**\r
163  * phpCAS default language (when phpCAS::setLang() is not used)\r
164  */\r
165 define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);\r
166 \r
167 /** @} */\r
168 // ------------------------------------------------------------------------\r
169 //  DEBUG\r
170 // ------------------------------------------------------------------------\r
171  /**\r
172   * @addtogroup publicDebug\r
173   * @{\r
174   */\r
175 \r
176 /**\r
177  * The default directory for the debug file under Unix.\r
178  */\r
179 define('DEFAULT_DEBUG_DIR','/tmp/');\r
180 \r
181 /** @} */\r
182 // ------------------------------------------------------------------------\r
183 //  MISC\r
184 // ------------------------------------------------------------------------\r
185  /**\r
186   * @addtogroup internalMisc\r
187   * @{\r
188   */\r
189 \r
190 /**\r
191  * This global variable is used by the interface class phpCAS.\r
192  *\r
193  * @hideinitializer\r
194  */\r
195 $GLOBALS['PHPCAS_CLIENT']  = null;\r
196 \r
197 /**\r
198  * This global variable is used to store where the initializer is called from \r
199  * (to print a comprehensive error in case of multiple calls).\r
200  *\r
201  * @hideinitializer\r
202  */\r
203 $GLOBALS['PHPCAS_INIT_CALL'] = array('done' => FALSE,\r
204         'file' => '?',\r
205         'line' => -1,\r
206         'method' => '?');\r
207 \r
208 /**\r
209  * This global variable is used to store where the method checking\r
210  * the authentication is called from (to print comprehensive errors)\r
211  *\r
212  * @hideinitializer\r
213  */\r
214 $GLOBALS['PHPCAS_AUTH_CHECK_CALL'] = array('done' => FALSE,\r
215         'file' => '?',\r
216         'line' => -1,\r
217         'method' => '?',\r
218         'result' => FALSE);\r
219 \r
220 /**\r
221  * This global variable is used to store phpCAS debug mode.\r
222  *\r
223  * @hideinitializer\r
224  */\r
225 $GLOBALS['PHPCAS_DEBUG']  = array('filename' => FALSE,\r
226         'indent' => 0,\r
227         'unique_id' => '');\r
228 \r
229 /** @} */\r
230 \r
231 // ########################################################################\r
232 //  CLIENT CLASS\r
233 // ########################################################################\r
234 \r
235 // include client class\r
236 include_once(dirname(__FILE__).'/CAS/client.php');\r
237 \r
238 // ########################################################################\r
239 //  INTERFACE CLASS\r
240 // ########################################################################\r
241 \r
242 /**\r
243  * @class phpCAS\r
244  * The phpCAS class is a simple container for the phpCAS library. It provides CAS\r
245  * authentication for web applications written in PHP.\r
246  *\r
247  * @ingroup public\r
248  * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>\r
249  *\r
250  * \internal All its methods access the same object ($PHPCAS_CLIENT, declared \r
251  * at the end of CAS/client.php).\r
252  */\r
253 \r
254 \r
255 \r
256 class phpCAS\r
257 {\r
258         \r
259         // ########################################################################\r
260         //  INITIALIZATION\r
261         // ########################################################################\r
262         \r
263         /**\r
264          * @addtogroup publicInit\r
265          * @{\r
266          */\r
267         \r
268         /**\r
269          * phpCAS client initializer.\r
270          * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be\r
271          * called, only once, and before all other methods (except phpCAS::getVersion()\r
272          * and phpCAS::setDebug()).\r
273          *\r
274          * @param $server_version the version of the CAS server\r
275          * @param $server_hostname the hostname of the CAS server\r
276          * @param $server_port the port the CAS server is running on\r
277          * @param $server_uri the URI the CAS server is responding on\r
278          * @param $start_session Have phpCAS start PHP sessions (default true)\r
279          *\r
280          * @return a newly created CASClient object\r
281          */\r
282         function client($server_version,\r
283                                         $server_hostname,\r
284                                         $server_port,\r
285                                         $server_uri,\r
286                                         $start_session = true)\r
287                 {\r
288                 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;\r
289                 \r
290                 phpCAS::traceBegin();\r
291                 if ( is_object($PHPCAS_CLIENT) ) {\r
292                         phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')');\r
293                 }\r
294                 if ( gettype($server_version) != 'string' ) {\r
295                         phpCAS::error('type mismatched for parameter $server_version (should be `string\')');\r
296                 }\r
297                 if ( gettype($server_hostname) != 'string' ) {\r
298                         phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')');\r
299                 }\r
300                 if ( gettype($server_port) != 'integer' ) {\r
301                         phpCAS::error('type mismatched for parameter $server_port (should be `integer\')');\r
302                 }\r
303                 if ( gettype($server_uri) != 'string' ) {\r
304                         phpCAS::error('type mismatched for parameter $server_uri (should be `string\')');\r
305                 }\r
306                 \r
307                 // store where the initialzer is called from\r
308                 $dbg = phpCAS::backtrace();\r
309                 $PHPCAS_INIT_CALL = array('done' => TRUE,\r
310                         'file' => $dbg[0]['file'],\r
311                         'line' => $dbg[0]['line'],\r
312                         'method' => __CLASS__.'::'.__FUNCTION__);\r
313                 \r
314                 // initialize the global object $PHPCAS_CLIENT\r
315                 $PHPCAS_CLIENT = new CASClient($server_version,FALSE/*proxy*/,$server_hostname,$server_port,$server_uri,$start_session);\r
316                 phpCAS::traceEnd();\r
317                 }\r
318         \r
319         /**\r
320          * phpCAS proxy initializer.\r
321          * @note Only one of the phpCAS::client() and phpCAS::proxy functions should be\r
322          * called, only once, and before all other methods (except phpCAS::getVersion()\r
323          * and phpCAS::setDebug()).\r
324          *\r
325          * @param $server_version the version of the CAS server\r
326          * @param $server_hostname the hostname of the CAS server\r
327          * @param $server_port the port the CAS server is running on\r
328          * @param $server_uri the URI the CAS server is responding on\r
329          * @param $start_session Have phpCAS start PHP sessions (default true)\r
330          *\r
331          * @return a newly created CASClient object\r
332          */\r
333         function proxy($server_version,\r
334                                    $server_hostname,\r
335                                    $server_port,\r
336                                    $server_uri,\r
337                                    $start_session = true)\r
338                 {\r
339                 global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;\r
340                 \r
341                 phpCAS::traceBegin();\r
342                 if ( is_object($PHPCAS_CLIENT) ) {\r
343                         phpCAS::error($PHPCAS_INIT_CALL['method'].'() has already been called (at '.$PHPCAS_INIT_CALL['file'].':'.$PHPCAS_INIT_CALL['line'].')');\r
344                 }\r
345                 if ( gettype($server_version) != 'string' ) {\r
346                         phpCAS::error('type mismatched for parameter $server_version (should be `string\')');\r
347                 }\r
348                 if ( gettype($server_hostname) != 'string' ) {\r
349                         phpCAS::error('type mismatched for parameter $server_hostname (should be `string\')');\r
350                 }\r
351                 if ( gettype($server_port) != 'integer' ) {\r
352                         phpCAS::error('type mismatched for parameter $server_port (should be `integer\')');\r
353                 }\r
354                 if ( gettype($server_uri) != 'string' ) {\r
355                         phpCAS::error('type mismatched for parameter $server_uri (should be `string\')');\r
356                 }\r
357                 \r
358                 // store where the initialzer is called from\r
359                 $dbg = phpCAS::backtrace();\r
360                 $PHPCAS_INIT_CALL = array('done' => TRUE,\r
361                         'file' => $dbg[0]['file'],\r
362                         'line' => $dbg[0]['line'],\r
363                         'method' => __CLASS__.'::'.__FUNCTION__);\r
364                 \r
365                 // initialize the global object $PHPCAS_CLIENT\r
366                 $PHPCAS_CLIENT = new CASClient($server_version,TRUE/*proxy*/,$server_hostname,$server_port,$server_uri,$start_session);\r
367                 phpCAS::traceEnd();\r
368                 }\r
369         \r
370         /** @} */\r
371         // ########################################################################\r
372         //  DEBUGGING\r
373         // ########################################################################\r
374         \r
375         /**\r
376          * @addtogroup publicDebug\r
377          * @{\r
378          */\r
379         \r
380         /**\r
381          * Set/unset debug mode\r
382          *\r
383          * @param $filename the name of the file used for logging, or FALSE to stop debugging.\r
384          */\r
385         function setDebug($filename='')\r
386                 {\r
387                 global $PHPCAS_DEBUG;\r
388                 \r
389                 if ( $filename != FALSE && gettype($filename) != 'string' ) {\r
390                         phpCAS::error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)');\r
391                 }\r
392                 \r
393                 if ( empty($filename) ) {\r
394                         if ( preg_match('/^Win.*/',getenv('OS')) ) {\r
395                                 if ( isset($_ENV['TMP']) ) {\r
396                                         $debugDir = $_ENV['TMP'].'/';\r
397                                 } else if ( isset($_ENV['TEMP']) ) {\r
398                                         $debugDir = $_ENV['TEMP'].'/';\r
399                                 } else {\r
400                                         $debugDir = '';\r
401                                 }\r
402                         } else {\r
403                                 $debugDir = DEFAULT_DEBUG_DIR;\r
404                         }\r
405                         $filename = $debugDir . 'phpCAS.log';\r
406                 }\r
407                 \r
408                 if ( empty($PHPCAS_DEBUG['unique_id']) ) {\r
409                         $PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))),0,4);\r
410                 }\r
411                 \r
412                 $PHPCAS_DEBUG['filename'] = $filename;\r
413                 \r
414                 phpCAS::trace('START ******************');\r
415                 }\r
416         \r
417         /** @} */\r
418         /**\r
419          * @addtogroup internalDebug\r
420          * @{\r
421          */\r
422         \r
423         /**\r
424          * This method is a wrapper for debug_backtrace() that is not available \r
425          * in all PHP versions (>= 4.3.0 only)\r
426          */\r
427         function backtrace()\r
428                 {\r
429                 if ( function_exists('debug_backtrace') ) {\r
430                         return debug_backtrace();\r
431                 } else {\r
432                         // poor man's hack ... but it does work ...\r
433                         return array();\r
434                 }\r
435                 }\r
436         \r
437         /**\r
438          * Logs a string in debug mode.\r
439          *\r
440          * @param $str the string to write\r
441          *\r
442          * @private\r
443          */\r
444         function log($str)\r
445                 {\r
446                 $indent_str = ".";\r
447                 global $PHPCAS_DEBUG;\r
448                 \r
449                 if ( $PHPCAS_DEBUG['filename'] ) {\r
450                         for ($i=0;$i<$PHPCAS_DEBUG['indent'];$i++) {\r
451                                 $indent_str .= '|    ';\r
452                         }\r
453                         error_log($PHPCAS_DEBUG['unique_id'].' '.$indent_str.$str."\n",3,$PHPCAS_DEBUG['filename']);\r
454                 }\r
455                 \r
456                 }\r
457         \r
458         /**\r
459          * This method is used by interface methods to print an error and where the function\r
460          * was originally called from.\r
461          *\r
462          * @param $msg the message to print\r
463          *\r
464          * @private\r
465          */\r
466         function error($msg)\r
467                 {\r
468                 $dbg = phpCAS::backtrace();\r
469                 $function = '?';\r
470                 $file = '?';\r
471                 $line = '?';\r
472                 if ( is_array($dbg) ) {\r
473                         for ( $i=1; $i<sizeof($dbg); $i++) {\r
474                                 if ( is_array($dbg[$i]) ) {\r
475                                         if ( $dbg[$i]['class'] == __CLASS__ ) {\r
476                                                 $function = $dbg[$i]['function'];\r
477                                                 $file = $dbg[$i]['file'];\r
478                                                 $line = $dbg[$i]['line'];\r
479                                         }\r
480                                 }\r
481                         }\r
482                 }\r
483                 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";\r
484                 phpCAS::trace($msg);\r
485                 phpCAS::traceExit();\r
486                 exit();\r
487                 }\r
488         \r
489         /**\r
490          * This method is used to log something in debug mode.\r
491          */\r
492         function trace($str)\r
493                 {\r
494                 $dbg = phpCAS::backtrace();\r
495                 phpCAS::log($str.' ['.basename($dbg[1]['file']).':'.$dbg[1]['line'].']');\r
496                 }\r
497         \r
498         /**\r
499          * This method is used to indicate the start of the execution of a function in debug mode.\r
500          */\r
501         function traceBegin()\r
502                 {\r
503                 global $PHPCAS_DEBUG;\r
504                 \r
505                 $dbg = phpCAS::backtrace();\r
506                 $str = '=> ';\r
507                 if ( !empty($dbg[2]['class']) ) {\r
508                         $str .= $dbg[2]['class'].'::';\r
509                 }\r
510                 $str .= $dbg[2]['function'].'(';      \r
511                 if ( is_array($dbg[2]['args']) ) {\r
512                         foreach ($dbg[2]['args'] as $index => $arg) {\r
513                                 if ( $index != 0 ) {\r
514                                         $str .= ', ';\r
515                                 }\r
516                                 $str .= str_replace("\n","",var_export($arg,TRUE));\r
517                         }\r
518                 }\r
519                 $str .= ') ['.basename($dbg[2]['file']).':'.$dbg[2]['line'].']';\r
520                 phpCAS::log($str);\r
521                 $PHPCAS_DEBUG['indent'] ++;\r
522                 }\r
523         \r
524         /**\r
525          * This method is used to indicate the end of the execution of a function in debug mode.\r
526          *\r
527          * @param $res the result of the function\r
528          */\r
529         function traceEnd($res='')\r
530                 {\r
531                 global $PHPCAS_DEBUG;\r
532                 \r
533                 $PHPCAS_DEBUG['indent'] --;\r
534                 $dbg = phpCAS::backtrace();\r
535                 $str = '';\r
536                 $str .= '<= '.str_replace("\n","",var_export($res,TRUE));\r
537                 phpCAS::log($str);\r
538                 }\r
539         \r
540         /**\r
541          * This method is used to indicate the end of the execution of the program\r
542          */\r
543         function traceExit()\r
544                 {\r
545                 global $PHPCAS_DEBUG;\r
546                 \r
547                 phpCAS::log('exit()');\r
548                 while ( $PHPCAS_DEBUG['indent'] > 0 ) {\r
549                         phpCAS::log('-');\r
550                         $PHPCAS_DEBUG['indent'] --;\r
551                 }\r
552                 }\r
553         \r
554         /** @} */\r
555         // ########################################################################\r
556         //  INTERNATIONALIZATION\r
557         // ########################################################################\r
558         /**\r
559          * @addtogroup publicLang\r
560          * @{\r
561          */\r
562         \r
563         /**\r
564          * This method is used to set the language used by phpCAS. \r
565          * @note Can be called only once.\r
566          *\r
567          * @param $lang a string representing the language.\r
568          *\r
569          * @sa PHPCAS_LANG_FRENCH, PHPCAS_LANG_ENGLISH\r
570          */\r
571         function setLang($lang)\r
572                 {\r
573                 global $PHPCAS_CLIENT;\r
574                 if ( !is_object($PHPCAS_CLIENT) ) {\r
575                         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
576                 }\r
577                 if ( gettype($lang) != 'string' ) {\r
578                         phpCAS::error('type mismatched for parameter $lang (should be `string\')');\r
579                 }\r
580                 $PHPCAS_CLIENT->setLang($lang);\r
581                 }\r
582         \r
583         /** @} */\r
584         // ########################################################################\r
585         //  VERSION\r
586         // ########################################################################\r
587         /**\r
588          * @addtogroup public\r
589          * @{\r
590          */\r
591         \r
592         /**\r
593          * This method returns the phpCAS version.\r
594          *\r
595          * @return the phpCAS version.\r
596          */\r
597         function getVersion()\r
598                 {\r
599                 return PHPCAS_VERSION;\r
600                 }\r
601         \r
602         /** @} */\r
603         // ########################################################################\r
604         //  HTML OUTPUT\r
605         // ########################################################################\r
606         /**\r
607          * @addtogroup publicOutput\r
608          * @{\r
609          */\r
610         \r
611         /**\r
612          * This method sets the HTML header used for all outputs.\r
613          *\r
614          * @param $header the HTML header.\r
615          */\r
616         function setHTMLHeader($header)\r
617                 {\r
618                 global $PHPCAS_CLIENT;\r
619                 if ( !is_object($PHPCAS_CLIENT) ) {\r
620                         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
621                 }\r
622                 if ( gettype($header) != 'string' ) {\r
623                         phpCAS::error('type mismatched for parameter $header (should be `string\')');\r
624                 }\r
625                 $PHPCAS_CLIENT->setHTMLHeader($header);\r
626                 }\r
627         \r
628         /**\r
629          * This method sets the HTML footer used for all outputs.\r
630          *\r
631          * @param $footer the HTML footer.\r
632          */\r
633         function setHTMLFooter($footer)\r
634                 {\r
635                 global $PHPCAS_CLIENT;\r
636                 if ( !is_object($PHPCAS_CLIENT) ) {\r
637                         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
638                 }\r
639                 if ( gettype($footer) != 'string' ) {\r
640                         phpCAS::error('type mismatched for parameter $footer (should be `string\')');\r
641                 }\r
642                 $PHPCAS_CLIENT->setHTMLFooter($footer);\r
643                 }\r
644         \r
645         /** @} */\r
646         // ########################################################################\r
647         //  PGT STORAGE\r
648         // ########################################################################\r
649         /**\r
650          * @addtogroup publicPGTStorage\r
651          * @{\r
652          */\r
653         \r
654         /**\r
655          * This method is used to tell phpCAS to store the response of the\r
656          * CAS server to PGT requests onto the filesystem. \r
657          *\r
658          * @param $format the format used to store the PGT's (`plain' and `xml' allowed)\r
659          * @param $path the path where the PGT's should be stored\r
660          */\r
661         function setPGTStorageFile($format='',\r
662                 $path='')\r
663                 {\r
664                 global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL;\r
665                 \r
666                 phpCAS::traceBegin();\r
667                 if ( !is_object($PHPCAS_CLIENT) ) {\r
668                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
669                 }\r
670                 if ( !$PHPCAS_CLIENT->isProxy() ) {\r
671                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
672                 }\r
673                 if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) {\r
674                         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'].')');\r
675                 }\r
676                 if ( gettype($format) != 'string' ) {\r
677                         phpCAS::error('type mismatched for parameter $format (should be `string\')');\r
678                 }\r
679                 if ( gettype($path) != 'string' ) {\r
680                         phpCAS::error('type mismatched for parameter $format (should be `string\')');\r
681                 }\r
682                 $PHPCAS_CLIENT->setPGTStorageFile($format,$path);\r
683                 phpCAS::traceEnd();\r
684                 }\r
685         \r
686         /**\r
687          * This method is used to tell phpCAS to store the response of the\r
688          * CAS server to PGT requests into a database. \r
689          * @note The connection to the database is done only when needed. \r
690          * As a consequence, bad parameters are detected only when \r
691          * initializing PGT storage, except in debug mode.\r
692          *\r
693          * @param $user the user to access the data with\r
694          * @param $password the user's password\r
695          * @param $database_type the type of the database hosting the data\r
696          * @param $hostname the server hosting the database\r
697          * @param $port the port the server is listening on\r
698          * @param $database the name of the database\r
699          * @param $table the name of the table storing the data\r
700          */\r
701         function setPGTStorageDB($user,\r
702                                                          $password,\r
703                                                          $database_type='',\r
704                                                                  $hostname='',\r
705                                                                          $port=0,\r
706                                                                                  $database='',\r
707                                                                                          $table='')\r
708                 {\r
709                 global $PHPCAS_CLIENT,$PHPCAS_AUTH_CHECK_CALL;\r
710                 \r
711                 phpCAS::traceBegin();\r
712                 if ( !is_object($PHPCAS_CLIENT) ) {\r
713                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
714                 }\r
715                 if ( !$PHPCAS_CLIENT->isProxy() ) {\r
716                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
717                 }\r
718                 if ( $PHPCAS_AUTH_CHECK_CALL['done'] ) {\r
719                         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'].')');\r
720                 }\r
721                 if ( gettype($user) != 'string' ) {\r
722                         phpCAS::error('type mismatched for parameter $user (should be `string\')');\r
723                 }\r
724                 if ( gettype($password) != 'string' ) {\r
725                         phpCAS::error('type mismatched for parameter $password (should be `string\')');\r
726                 }\r
727                 if ( gettype($database_type) != 'string' ) {\r
728                         phpCAS::error('type mismatched for parameter $database_type (should be `string\')');\r
729                 }\r
730                 if ( gettype($hostname) != 'string' ) {\r
731                         phpCAS::error('type mismatched for parameter $hostname (should be `string\')');\r
732                 }\r
733                 if ( gettype($port) != 'integer' ) {\r
734                         phpCAS::error('type mismatched for parameter $port (should be `integer\')');\r
735                 }\r
736                 if ( gettype($database) != 'string' ) {\r
737                         phpCAS::error('type mismatched for parameter $database (should be `string\')');\r
738                 }\r
739                 if ( gettype($table) != 'string' ) {\r
740                         phpCAS::error('type mismatched for parameter $table (should be `string\')');\r
741                 }\r
742                 $PHPCAS_CLIENT->setPGTStorageDB($this,$user,$password,$hostname,$port,$database,$table);\r
743                 phpCAS::traceEnd();\r
744                 }\r
745         \r
746         /** @} */\r
747         // ########################################################################\r
748         // ACCESS TO EXTERNAL SERVICES\r
749         // ########################################################################\r
750         /**\r
751          * @addtogroup publicServices\r
752          * @{\r
753          */\r
754         \r
755         /**\r
756          * This method is used to access an HTTP[S] service.\r
757          * \r
758          * @param $url the service to access.\r
759          * @param $err_code an error code Possible values are PHPCAS_SERVICE_OK (on\r
760          * success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE,\r
761          * PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_NOT AVAILABLE.\r
762          * @param $output the output of the service (also used to give an error\r
763          * message on failure).\r
764          *\r
765          * @return TRUE on success, FALSE otherwise (in this later case, $err_code\r
766          * gives the reason why it failed and $output contains an error message).\r
767          */\r
768         function serviceWeb($url,&$err_code,&$output)\r
769                 {\r
770                 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;\r
771                 \r
772                 phpCAS::traceBegin();\r
773                 if ( !is_object($PHPCAS_CLIENT) ) {\r
774                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
775                 }\r
776                 if ( !$PHPCAS_CLIENT->isProxy() ) {\r
777                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
778                 }\r
779                 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {\r
780                         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()');\r
781                 }\r
782                 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {\r
783                         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');\r
784                 }\r
785                 if ( gettype($url) != 'string' ) {\r
786                         phpCAS::error('type mismatched for parameter $url (should be `string\')');\r
787                 }\r
788                 \r
789                 $res = $PHPCAS_CLIENT->serviceWeb($url,$err_code,$output);\r
790                 \r
791                 phpCAS::traceEnd($res);\r
792                 return $res;\r
793                 }\r
794         \r
795         /**\r
796          * This method is used to access an IMAP/POP3/NNTP service.\r
797          * \r
798          * @param $url a string giving the URL of the service, including the mailing box\r
799          * for IMAP URLs, as accepted by imap_open().\r
800          * @param $flags options given to imap_open().\r
801          * @param $err_code an error code Possible values are PHPCAS_SERVICE_OK (on\r
802          * success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE,\r
803          * PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_NOT AVAILABLE.\r
804          * @param $err_msg an error message on failure\r
805          * @param $pt the Proxy Ticket (PT) retrieved from the CAS server to access the URL\r
806          * on success, FALSE on error).\r
807          *\r
808          * @return an IMAP stream on success, FALSE otherwise (in this later case, $err_code\r
809          * gives the reason why it failed and $err_msg contains an error message).\r
810          */\r
811         function serviceMail($url,$flags,&$err_code,&$err_msg,&$pt)\r
812                 {\r
813                 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;\r
814                 \r
815                 phpCAS::traceBegin();\r
816                 if ( !is_object($PHPCAS_CLIENT) ) {\r
817                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
818                 }\r
819                 if ( !$PHPCAS_CLIENT->isProxy() ) {\r
820                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
821                 }\r
822                 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {\r
823                         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()');\r
824                 }\r
825                 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {\r
826                         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');\r
827                 }\r
828                 if ( gettype($url) != 'string' ) {\r
829                         phpCAS::error('type mismatched for parameter $url (should be `string\')');\r
830                 }\r
831                 \r
832                 if ( gettype($flags) != 'integer' ) {\r
833                         phpCAS::error('type mismatched for parameter $flags (should be `integer\')');\r
834                 }\r
835                 \r
836                 $res = $PHPCAS_CLIENT->serviceMail($url,$flags,$err_code,$err_msg,$pt);\r
837                 \r
838                 phpCAS::traceEnd($res);\r
839                 return $res;\r
840                 }\r
841         \r
842         /** @} */\r
843         // ########################################################################\r
844         //  AUTHENTICATION\r
845         // ########################################################################\r
846         /**\r
847          * @addtogroup publicAuth\r
848          * @{\r
849          */\r
850         \r
851         /**\r
852          * Set the times authentication will be cached before really accessing the CAS server in gateway mode: \r
853          * - -1: check only once, and then never again (until you pree login)\r
854          * - 0: always check\r
855          * - n: check every "n" time\r
856          *\r
857          * @param $n an integer.\r
858          */\r
859         function setCacheTimesForAuthRecheck($n)\r
860                 {\r
861                 global $PHPCAS_CLIENT;\r
862                 if ( !is_object($PHPCAS_CLIENT) ) {\r
863                         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
864                 }\r
865                 if ( gettype($n) != 'integer' ) {\r
866                         phpCAS::error('type mismatched for parameter $header (should be `string\')');\r
867                 }\r
868                 $PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);\r
869                 }\r
870         \r
871         /**\r
872          * This method is called to check if the user is authenticated (use the gateway feature).\r
873          * @return TRUE when the user is authenticated; otherwise FALSE.\r
874          */\r
875         function checkAuthentication()\r
876                 {\r
877                 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;\r
878                 \r
879                 phpCAS::traceBegin();\r
880                 if ( !is_object($PHPCAS_CLIENT) ) {\r
881                         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
882                 }\r
883                 \r
884                 $auth = $PHPCAS_CLIENT->checkAuthentication();\r
885                 \r
886                 // store where the authentication has been checked and the result\r
887                 $dbg = phpCAS::backtrace();\r
888                 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,\r
889                         'file' => $dbg[0]['file'],\r
890                         'line' => $dbg[0]['line'],\r
891                         'method' => __CLASS__.'::'.__FUNCTION__,\r
892                         'result' => $auth );\r
893                 phpCAS::traceEnd($auth);\r
894                 return $auth; \r
895                 }\r
896         \r
897         /**\r
898          * This method is called to force authentication if the user was not already \r
899          * authenticated. If the user is not authenticated, halt by redirecting to \r
900          * the CAS server.\r
901          */\r
902         function forceAuthentication()\r
903                 {\r
904                 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;\r
905                 \r
906                 phpCAS::traceBegin();\r
907                 if ( !is_object($PHPCAS_CLIENT) ) {\r
908                         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
909                 }\r
910                 \r
911                 $auth = $PHPCAS_CLIENT->forceAuthentication();\r
912                 \r
913                 // store where the authentication has been checked and the result\r
914                 $dbg = phpCAS::backtrace();\r
915                 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,\r
916                         'file' => $dbg[0]['file'],\r
917                         'line' => $dbg[0]['line'],\r
918                         'method' => __CLASS__.'::'.__FUNCTION__,\r
919                         'result' => $auth );\r
920                 \r
921                 if ( !$auth ) {\r
922                         phpCAS::trace('user is not authenticated, redirecting to the CAS server');\r
923                         $PHPCAS_CLIENT->forceAuthentication();\r
924                 } else {\r
925                         phpCAS::trace('no need to authenticate (user `'.phpCAS::getUser().'\' is already authenticated)');\r
926                 }\r
927                 \r
928                 phpCAS::traceEnd();\r
929                 return $auth; \r
930                 }\r
931         \r
932         /**\r
933          * This method is called to renew the authentication.\r
934          **/\r
935         function renewAuthentication() {\r
936                 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;\r
937                 \r
938                 phpCAS::traceBegin();\r
939                 if ( !is_object($PHPCAS_CLIENT) ) {\r
940                         phpCAS::error('this method should not be called before'.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
941                 }\r
942                 \r
943                 // store where the authentication has been checked and the result\r
944                 $dbg = phpCAS::backtrace();\r
945                 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE, 'file' => $dbg[0]['file'], 'line' => $dbg[0]['line'], 'method' => __CLASS__.'::'.__FUNCTION__, 'result' => $auth );\r
946                 \r
947                 $PHPCAS_CLIENT->renewAuthentication();\r
948                 phpCAS::traceEnd();\r
949         }\r
950 \r
951         /**\r
952          * This method has been left from version 0.4.1 for compatibility reasons.\r
953          */\r
954         function authenticate()\r
955                 {\r
956                 phpCAS::error('this method is deprecated. You should use '.__CLASS__.'::forceAuthentication() instead');\r
957                 }\r
958         \r
959         /**\r
960          * This method is called to check if the user is authenticated (previously or by\r
961          * tickets given in the URL).\r
962          *\r
963          * @return TRUE when the user is authenticated.\r
964          */\r
965         function isAuthenticated()\r
966                 {\r
967                 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;\r
968                 \r
969                 phpCAS::traceBegin();\r
970                 if ( !is_object($PHPCAS_CLIENT) ) {\r
971                         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
972                 }\r
973                 \r
974                 // call the isAuthenticated method of the global $PHPCAS_CLIENT object\r
975                 $auth = $PHPCAS_CLIENT->isAuthenticated();\r
976                 \r
977                 // store where the authentication has been checked and the result\r
978                 $dbg = phpCAS::backtrace();\r
979                 $PHPCAS_AUTH_CHECK_CALL = array('done' => TRUE,\r
980                         'file' => $dbg[0]['file'],\r
981                         'line' => $dbg[0]['line'],\r
982                         'method' => __CLASS__.'::'.__FUNCTION__,\r
983                         'result' => $auth );\r
984                 phpCAS::traceEnd($auth);\r
985                 return $auth;\r
986                 }\r
987         \r
988         /**\r
989          * Checks whether authenticated based on $_SESSION. Useful to avoid\r
990          * server calls.\r
991          * @return true if authenticated, false otherwise.\r
992          * @since 0.4.22 by Brendan Arnold\r
993          */\r
994         function isSessionAuthenticated ()\r
995                 {\r
996                 global $PHPCAS_CLIENT;\r
997                 if ( !is_object($PHPCAS_CLIENT) ) {\r
998                         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
999                 }\r
1000                 return($PHPCAS_CLIENT->isSessionAuthenticated());\r
1001                 }\r
1002         \r
1003         /**\r
1004          * This method returns the CAS user's login name.\r
1005          * @warning should not be called only after phpCAS::forceAuthentication()\r
1006          * or phpCAS::checkAuthentication().\r
1007          *\r
1008          * @return the login name of the authenticated user\r
1009          */\r
1010         function getUser()\r
1011                 {\r
1012                 global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;\r
1013                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1014                         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
1015                 }\r
1016                 if ( !$PHPCAS_AUTH_CHECK_CALL['done'] ) {\r
1017                         phpCAS::error('this method should only be called after '.__CLASS__.'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()');\r
1018                 }\r
1019                 if ( !$PHPCAS_AUTH_CHECK_CALL['result'] ) {\r
1020                         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');\r
1021                 }\r
1022                 return $PHPCAS_CLIENT->getUser();\r
1023                 }\r
1024         \r
1025     /**\r
1026      * Handle logout requests.\r
1027      */\r
1028     function handleLogoutRequests($check_client=true, $allowed_clients=false)\r
1029         {\r
1030             global $PHPCAS_CLIENT;\r
1031             if ( !is_object($PHPCAS_CLIENT) ) {\r
1032                 phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
1033             }\r
1034             return($PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));\r
1035         }\r
1036    \r
1037         /**\r
1038          * This method returns the URL to be used to login.\r
1039          * or phpCAS::isAuthenticated().\r
1040          *\r
1041          * @return the login name of the authenticated user\r
1042          */\r
1043         function getServerLoginURL()\r
1044                 {\r
1045                 global $PHPCAS_CLIENT;\r
1046                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1047                         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
1048                 }\r
1049                 return $PHPCAS_CLIENT->getServerLoginURL();\r
1050                 }\r
1051         \r
1052         /**\r
1053          * Set the login URL of the CAS server.\r
1054          * @param $url the login URL\r
1055          * @since 0.4.21 by Wyman Chan\r
1056          */\r
1057         function setServerLoginURL($url='')\r
1058                 {\r
1059                 global $PHPCAS_CLIENT;\r
1060                 phpCAS::traceBegin();\r
1061                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1062                         phpCAS::error('this method should only be called after\r
1063                                 '.__CLASS__.'::client()');\r
1064                 }\r
1065                 if ( gettype($url) != 'string' ) {\r
1066                         phpCAS::error('type mismatched for parameter $url (should be\r
1067                         `string\')');\r
1068                 }\r
1069                 $PHPCAS_CLIENT->setServerLoginURL($url);\r
1070                 phpCAS::traceEnd();\r
1071                 }\r
1072         \r
1073         /**\r
1074          * This method returns the URL to be used to login.\r
1075          * or phpCAS::isAuthenticated().\r
1076          *\r
1077          * @return the login name of the authenticated user\r
1078          */\r
1079         function getServerLogoutURL()\r
1080                 {\r
1081                 global $PHPCAS_CLIENT;\r
1082                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1083                         phpCAS::error('this method should not be called before '.__CLASS__.'::client() or '.__CLASS__.'::proxy()');\r
1084                 }\r
1085                 return $PHPCAS_CLIENT->getServerLogoutURL();\r
1086                 }\r
1087         \r
1088         /**\r
1089          * Set the logout URL of the CAS server.\r
1090          * @param $url the logout URL\r
1091          * @since 0.4.21 by Wyman Chan\r
1092          */\r
1093         function setServerLogoutURL($url='')\r
1094                 {\r
1095                 global $PHPCAS_CLIENT;\r
1096                 phpCAS::traceBegin();\r
1097                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1098                         phpCAS::error('this method should only be called after\r
1099                                 '.__CLASS__.'::client()');\r
1100                 }\r
1101                 if ( gettype($url) != 'string' ) {\r
1102                         phpCAS::error('type mismatched for parameter $url (should be\r
1103                         `string\')');\r
1104                 }\r
1105                 $PHPCAS_CLIENT->setServerLogoutURL($url);\r
1106                 phpCAS::traceEnd();\r
1107                 }\r
1108         \r
1109         /**\r
1110          * This method is used to logout from CAS.\r
1111          * @params $params an array that contains the optional url and service parameters that will be passed to the CAS server\r
1112          * @public\r
1113          */\r
1114         function logout($params = "") {\r
1115                 global $PHPCAS_CLIENT;\r
1116                 phpCAS::traceBegin();\r
1117                 if (!is_object($PHPCAS_CLIENT)) {\r
1118                         phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');\r
1119                 }\r
1120                 $parsedParams = array();\r
1121                 if ($params != "") {\r
1122                         if (is_string($params)) {\r
1123                                 phpCAS::error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');\r
1124                         }\r
1125                         if (!is_array($params)) {\r
1126                                 phpCAS::error('type mismatched for parameter $params (should be `array\')');\r
1127                         }\r
1128                         foreach ($params as $key => $value) {\r
1129                                 if ($key != "service" && $key != "url") {\r
1130                                         phpCAS::error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');\r
1131                                 }\r
1132                                 $parsedParams[$key] = $value;\r
1133                         }\r
1134                 }\r
1135                 $PHPCAS_CLIENT->logout($parsedParams);\r
1136                 // never reached\r
1137                 phpCAS::traceEnd();\r
1138         }\r
1139         \r
1140         /**\r
1141          * This method is used to logout from CAS. Halts by redirecting to the CAS server.\r
1142          * @param $service a URL that will be transmitted to the CAS server\r
1143          */\r
1144         function logoutWithRedirectService($service) {\r
1145                 global $PHPCAS_CLIENT;\r
1146                 phpCAS::traceBegin();\r
1147                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1148                         phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');\r
1149                 }\r
1150                 if (!is_string($service)) {\r
1151                         phpCAS::error('type mismatched for parameter $service (should be `string\')');\r
1152                 }\r
1153                 $PHPCAS_CLIENT->logout(array("service" => $service));\r
1154                 // never reached\r
1155                 phpCAS::traceEnd();\r
1156         }\r
1157         \r
1158         /**\r
1159          * This method is used to logout from CAS. Halts by redirecting to the CAS server.\r
1160          * @param $url a URL that will be transmitted to the CAS server\r
1161          */\r
1162         function logoutWithUrl($url) {\r
1163                 global $PHPCAS_CLIENT;\r
1164                 phpCAS::traceBegin();\r
1165                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1166                         phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');\r
1167                 }\r
1168                 if (!is_string($url)) {\r
1169                         phpCAS::error('type mismatched for parameter $url (should be `string\')');\r
1170                 }\r
1171                 $PHPCAS_CLIENT->logout(array("url" => $url));\r
1172                 // never reached\r
1173                 phpCAS::traceEnd();\r
1174         }\r
1175         \r
1176         /**\r
1177          * This method is used to logout from CAS. Halts by redirecting to the CAS server.\r
1178          * @param $service a URL that will be transmitted to the CAS server\r
1179          * @param $url a URL that will be transmitted to the CAS server\r
1180          */\r
1181         function logoutWithRedirectServiceAndUrl($service, $url) {\r
1182                 global $PHPCAS_CLIENT;\r
1183                 phpCAS::traceBegin();\r
1184                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1185                         phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');\r
1186                 }\r
1187                 if (!is_string($service)) {\r
1188                         phpCAS::error('type mismatched for parameter $service (should be `string\')');\r
1189                 }\r
1190                 if (!is_string($url)) {\r
1191                         phpCAS::error('type mismatched for parameter $url (should be `string\')');\r
1192                 }\r
1193                 $PHPCAS_CLIENT->logout(array("service" => $service, "url" => $url));\r
1194                 // never reached\r
1195                 phpCAS::traceEnd();\r
1196         }\r
1197         \r
1198         /**\r
1199          * Set the fixed URL that will be used by the CAS server to transmit the PGT.\r
1200          * When this method is not called, a phpCAS script uses its own URL for the callback.\r
1201          *\r
1202          * @param $url the URL\r
1203          */\r
1204         function setFixedCallbackURL($url='')\r
1205                 {\r
1206                 global $PHPCAS_CLIENT;\r
1207                 phpCAS::traceBegin();\r
1208                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1209                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
1210                 }\r
1211                 if ( !$PHPCAS_CLIENT->isProxy() ) {\r
1212                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
1213                 }\r
1214                 if ( gettype($url) != 'string' ) {\r
1215                         phpCAS::error('type mismatched for parameter $url (should be `string\')');\r
1216                 }\r
1217                 $PHPCAS_CLIENT->setCallbackURL($url);\r
1218                 phpCAS::traceEnd();\r
1219                 }\r
1220         \r
1221         /**\r
1222          * Set the fixed URL that will be set as the CAS service parameter. When this\r
1223          * method is not called, a phpCAS script uses its own URL.\r
1224          *\r
1225          * @param $url the URL\r
1226          */\r
1227         function setFixedServiceURL($url)\r
1228                 {\r
1229                 global $PHPCAS_CLIENT;\r
1230                 phpCAS::traceBegin();\r
1231                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1232                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
1233                 }  \r
1234                 if ( gettype($url) != 'string' ) {\r
1235                         phpCAS::error('type mismatched for parameter $url (should be `string\')');\r
1236                 }\r
1237                 $PHPCAS_CLIENT->setURL($url);\r
1238                 phpCAS::traceEnd();\r
1239                 }\r
1240         \r
1241         /**\r
1242          * Get the URL that is set as the CAS service parameter.\r
1243          */\r
1244         function getServiceURL()\r
1245                 {\r
1246                 global $PHPCAS_CLIENT;\r
1247                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1248                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
1249                 }  \r
1250                 return($PHPCAS_CLIENT->getURL());\r
1251                 }\r
1252         \r
1253         /**\r
1254          * Retrieve a Proxy Ticket from the CAS server.\r
1255          */\r
1256         function retrievePT($target_service,&$err_code,&$err_msg)\r
1257                 {\r
1258                 global $PHPCAS_CLIENT;\r
1259                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1260                         phpCAS::error('this method should only be called after '.__CLASS__.'::proxy()');\r
1261                 }  \r
1262                 if ( gettype($target_service) != 'string' ) {\r
1263                         phpCAS::error('type mismatched for parameter $target_service(should be `string\')');\r
1264                 }\r
1265                 return($PHPCAS_CLIENT->retrievePT($target_service,$err_code,$err_msg));\r
1266                 }\r
1267         \r
1268         /**\r
1269          * Set the certificate of the CAS server.\r
1270          *\r
1271          * @param $cert the PEM certificate\r
1272          */\r
1273         function setCasServerCert($cert)\r
1274                 {\r
1275                 global $PHPCAS_CLIENT;\r
1276                 phpCAS::traceBegin();\r
1277                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1278                         phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');\r
1279                 }  \r
1280                 if ( gettype($cert) != 'string' ) {\r
1281                         phpCAS::error('type mismatched for parameter $cert (should be `string\')');\r
1282                 }\r
1283                 $PHPCAS_CLIENT->setCasServerCert($cert);\r
1284                 phpCAS::traceEnd();\r
1285                 }\r
1286         \r
1287         /**\r
1288          * Set the certificate of the CAS server CA.\r
1289          *\r
1290          * @param $cert the CA certificate\r
1291          */\r
1292         function setCasServerCACert($cert)\r
1293                 {\r
1294                 global $PHPCAS_CLIENT;\r
1295                 phpCAS::traceBegin();\r
1296                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1297                         phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');\r
1298                 }  \r
1299                 if ( gettype($cert) != 'string' ) {\r
1300                         phpCAS::error('type mismatched for parameter $cert (should be `string\')');\r
1301                 }\r
1302                 $PHPCAS_CLIENT->setCasServerCACert($cert);\r
1303                 phpCAS::traceEnd();\r
1304                 }\r
1305         \r
1306         /**\r
1307          * Set no SSL validation for the CAS server.\r
1308          */\r
1309         function setNoCasServerValidation()\r
1310                 {\r
1311                 global $PHPCAS_CLIENT;\r
1312                 phpCAS::traceBegin();\r
1313                 if ( !is_object($PHPCAS_CLIENT) ) {\r
1314                         phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');\r
1315                 }  \r
1316                 $PHPCAS_CLIENT->setNoCasServerValidation();\r
1317                 phpCAS::traceEnd();\r
1318                 }\r
1319         \r
1320         /** @} */\r
1321         \r
1322   /**\r
1323    * Change CURL options.\r
1324    * CURL is used to connect through HTTPS to CAS server\r
1325    * @param $key the option key\r
1326    * @param $value the value to set\r
1327    */\r
1328    function setExtraCurlOption($key, $value)\r
1329                 {\r
1330                   global $PHPCAS_CLIENT;\r
1331                   phpCAS::traceBegin();\r
1332                   if ( !is_object($PHPCAS_CLIENT) ) {\r
1333                         phpCAS::error('this method should only be called after '.__CLASS__.'::client() or'.__CLASS__.'::proxy()');\r
1334                   }  \r
1335                   $PHPCAS_CLIENT->setExtraCurlOption($key, $value);\r
1336                   phpCAS::traceEnd();\r
1337                 }\r
1338 \r
1339 }\r
1340 \r
1341 // ########################################################################\r
1342 // DOCUMENTATION\r
1343 // ########################################################################\r
1344 \r
1345 // ########################################################################\r
1346 //  MAIN PAGE\r
1347 \r
1348 /**\r
1349  * @mainpage\r
1350  *\r
1351  * The following pages only show the source documentation.\r
1352  *\r
1353  */\r
1354 \r
1355 // ########################################################################\r
1356 //  MODULES DEFINITION\r
1357 \r
1358 /** @defgroup public User interface */\r
1359 \r
1360 /** @defgroup publicInit Initialization\r
1361  *  @ingroup public */\r
1362 \r
1363 /** @defgroup publicAuth Authentication\r
1364  *  @ingroup public */\r
1365 \r
1366 /** @defgroup publicServices Access to external services\r
1367  *  @ingroup public */\r
1368 \r
1369 /** @defgroup publicConfig Configuration\r
1370  *  @ingroup public */\r
1371 \r
1372 /** @defgroup publicLang Internationalization\r
1373  *  @ingroup publicConfig */\r
1374 \r
1375 /** @defgroup publicOutput HTML output\r
1376  *  @ingroup publicConfig */\r
1377 \r
1378 /** @defgroup publicPGTStorage PGT storage\r
1379  *  @ingroup publicConfig */\r
1380 \r
1381 /** @defgroup publicDebug Debugging\r
1382  *  @ingroup public */\r
1383 \r
1384 \r
1385 /** @defgroup internal Implementation */\r
1386 \r
1387 /** @defgroup internalAuthentication Authentication\r
1388  *  @ingroup internal */\r
1389 \r
1390 /** @defgroup internalBasic CAS Basic client features (CAS 1.0, Service Tickets)\r
1391  *  @ingroup internal */\r
1392 \r
1393 /** @defgroup internalProxy CAS Proxy features (CAS 2.0, Proxy Granting Tickets)\r
1394  *  @ingroup internal */\r
1395 \r
1396 /** @defgroup internalPGTStorage PGT storage\r
1397  *  @ingroup internalProxy */\r
1398 \r
1399 /** @defgroup internalPGTStorageDB PGT storage in a database\r
1400  *  @ingroup internalPGTStorage */\r
1401 \r
1402 /** @defgroup internalPGTStorageFile PGT storage on the filesystem\r
1403  *  @ingroup internalPGTStorage */\r
1404 \r
1405 /** @defgroup internalCallback Callback from the CAS server\r
1406  *  @ingroup internalProxy */\r
1407 \r
1408 /** @defgroup internalProxied CAS proxied client features (CAS 2.0, Proxy Tickets)\r
1409  *  @ingroup internal */\r
1410 \r
1411 /** @defgroup internalConfig Configuration\r
1412  *  @ingroup internal */\r
1413 \r
1414 /** @defgroup internalOutput HTML output\r
1415  *  @ingroup internalConfig */\r
1416 \r
1417 /** @defgroup internalLang Internationalization\r
1418  *  @ingroup internalConfig\r
1419  *\r
1420  * To add a new language:\r
1421  * - 1. define a new constant PHPCAS_LANG_XXXXXX in CAS/CAS.php\r
1422  * - 2. copy any file from CAS/languages to CAS/languages/XXXXXX.php\r
1423  * - 3. Make the translations\r
1424  */\r
1425 \r
1426 /** @defgroup internalDebug Debugging\r
1427  *  @ingroup internal */\r
1428 \r
1429 /** @defgroup internalMisc Miscellaneous\r
1430  *  @ingroup internal */\r
1431 \r
1432 // ########################################################################\r
1433 //  EXAMPLES\r
1434 \r
1435 /**\r
1436  * @example example_simple.php\r
1437  */\r
1438  /**\r
1439   * @example example_proxy.php\r
1440   */\r
1441   /**\r
1442    * @example example_proxy2.php\r
1443    */\r
1444    /**\r
1445     * @example example_lang.php\r
1446     */\r
1447     /**\r
1448      * @example example_html.php\r
1449      */\r
1450      /**\r
1451       * @example example_file.php\r
1452       */\r
1453       /**\r
1454        * @example example_db.php\r
1455        */\r
1456        /**\r
1457         * @example example_service.php\r
1458         */\r
1459         /**\r
1460          * @example example_session_proxy.php\r
1461          */\r
1462          /**\r
1463           * @example example_session_service.php\r
1464           */\r
1465           /**\r
1466            * @example example_gateway.php\r
1467            */\r
1468 \r
1469 \r
1470 \r
1471 ?>\r