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