]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/CasAuthentication/extlib/CAS/PGTStorage/pgt-file.php
Tickets #2112, 2333, 1677, 2362, 2831: fix AJAX form posting on SSL page views with...
[quix0rs-gnu-social.git] / plugins / CasAuthentication / extlib / CAS / PGTStorage / pgt-file.php
1 <?php\r
2 \r
3 /**\r
4  * @file CAS/PGTStorage/pgt-file.php\r
5  * Basic class for PGT file storage\r
6  */\r
7 \r
8 /**\r
9  * @class PGTStorageFile\r
10  * The PGTStorageFile class is a class for PGT file storage. An instance of \r
11  * this class is returned by CASClient::SetPGTStorageFile().\r
12  *\r
13  * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>\r
14  *\r
15  * @ingroup internalPGTStorageFile\r
16  */\r
17 \r
18 class PGTStorageFile extends PGTStorage\r
19 {\r
20   /** \r
21    * @addtogroup internalPGTStorageFile \r
22    * @{ \r
23    */\r
24 \r
25   /**\r
26    * a string telling where PGT's should be stored on the filesystem. Written by\r
27    * PGTStorageFile::PGTStorageFile(), read by getPath().\r
28    *\r
29    * @private\r
30    */\r
31   var $_path;\r
32 \r
33   /**\r
34    * This method returns the name of the directory where PGT's should be stored \r
35    * on the filesystem.\r
36    *\r
37    * @return the name of a directory (with leading and trailing '/')\r
38    *\r
39    * @private\r
40    */\r
41   function getPath()\r
42     {\r
43       return $this->_path;\r
44     }\r
45 \r
46   /**\r
47    * a string telling the format to use to store PGT's (plain or xml). Written by\r
48    * PGTStorageFile::PGTStorageFile(), read by getFormat().\r
49    *\r
50    * @private\r
51    */\r
52   var $_format;\r
53 \r
54   /**\r
55    * This method returns the format to use when storing PGT's on the filesystem.\r
56    *\r
57    * @return a string corresponding to the format used (plain or xml).\r
58    *\r
59    * @private\r
60    */\r
61   function getFormat()\r
62     {\r
63       return $this->_format;\r
64     }\r
65 \r
66   // ########################################################################\r
67   //  DEBUGGING\r
68   // ########################################################################\r
69   \r
70   /**\r
71    * This method returns an informational string giving the type of storage\r
72    * used by the object (used for debugging purposes).\r
73    *\r
74    * @return an informational string.\r
75    * @public\r
76    */\r
77   function getStorageType()\r
78     {\r
79       return "file";\r
80     }\r
81 \r
82   /**\r
83    * This method returns an informational string giving informations on the\r
84    * parameters of the storage.(used for debugging purposes).\r
85    *\r
86    * @return an informational string.\r
87    * @public\r
88    */\r
89   function getStorageInfo()\r
90     {\r
91       return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\'';\r
92     }\r
93 \r
94   // ########################################################################\r
95   //  CONSTRUCTOR\r
96   // ########################################################################\r
97   \r
98   /**\r
99    * The class constructor, called by CASClient::SetPGTStorageFile().\r
100    *\r
101    * @param $cas_parent the CASClient instance that creates the object.\r
102    * @param $format the format used to store the PGT's (`plain' and `xml' allowed).\r
103    * @param $path the path where the PGT's should be stored\r
104    *\r
105    * @public\r
106    */\r
107   function PGTStorageFile($cas_parent,$format,$path)\r
108     {\r
109       phpCAS::traceBegin();\r
110       // call the ancestor's constructor\r
111       $this->PGTStorage($cas_parent);\r
112 \r
113       if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT;\r
114       if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH;\r
115 \r
116       // check that the path is an absolute path\r
117       if (getenv("OS")=="Windows_NT"){\r
118         \r
119          if (!preg_match('`^[a-zA-Z]:`', $path)) {\r
120                 phpCAS::error('an absolute path is needed for PGT storage to file');\r
121         }\r
122         \r
123       }\r
124       else\r
125       {\r
126       \r
127         if ( $path[0] != '/' ) {\r
128                         phpCAS::error('an absolute path is needed for PGT storage to file');\r
129         }\r
130 \r
131         // store the path (with a leading and trailing '/')      \r
132         $path = preg_replace('|[/]*$|','/',$path);\r
133         $path = preg_replace('|^[/]*|','/',$path);\r
134       }\r
135       \r
136       $this->_path = $path;\r
137       // check the format and store it\r
138       switch ($format) {\r
139       case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN:\r
140       case CAS_PGT_STORAGE_FILE_FORMAT_XML:\r
141         $this->_format = $format;\r
142         break;\r
143       default:\r
144         phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)');\r
145       }\r
146       phpCAS::traceEnd();      \r
147     }\r
148 \r
149   // ########################################################################\r
150   //  INITIALIZATION\r
151   // ########################################################################\r
152   \r
153   /**\r
154    * This method is used to initialize the storage. Halts on error.\r
155    *\r
156    * @public\r
157    */\r
158   function init()\r
159     {\r
160       phpCAS::traceBegin();\r
161       // if the storage has already been initialized, return immediatly\r
162       if ( $this->isInitialized() )\r
163         return;\r
164       // call the ancestor's method (mark as initialized)\r
165       parent::init();\r
166       phpCAS::traceEnd();      \r
167     }\r
168 \r
169   // ########################################################################\r
170   //  PGT I/O\r
171   // ########################################################################\r
172 \r
173   /**\r
174    * This method returns the filename corresponding to a PGT Iou.\r
175    *\r
176    * @param $pgt_iou the PGT iou.\r
177    *\r
178    * @return a filename\r
179    * @private\r
180    */\r
181   function getPGTIouFilename($pgt_iou)\r
182     {\r
183       phpCAS::traceBegin();\r
184       $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat();\r
185       phpCAS::traceEnd($filename);\r
186       return $filename;\r
187     }\r
188   \r
189   /**\r
190    * This method stores a PGT and its corresponding PGT Iou into a file. Echoes a\r
191    * warning on error.\r
192    *\r
193    * @param $pgt the PGT\r
194    * @param $pgt_iou the PGT iou\r
195    *\r
196    * @public\r
197    */\r
198   function write($pgt,$pgt_iou)\r
199     {\r
200       phpCAS::traceBegin();\r
201       $fname = $this->getPGTIouFilename($pgt_iou);\r
202       if ( $f=fopen($fname,"w") ) {\r
203         if ( fputs($f,$pgt) === FALSE ) {\r
204           phpCAS::error('could not write PGT to `'.$fname.'\'');\r
205         }\r
206         fclose($f);\r
207       } else {\r
208         phpCAS::error('could not open `'.$fname.'\'');\r
209       }\r
210       phpCAS::traceEnd();      \r
211     }\r
212 \r
213   /**\r
214    * This method reads a PGT corresponding to a PGT Iou and deletes the \r
215    * corresponding file.\r
216    *\r
217    * @param $pgt_iou the PGT iou\r
218    *\r
219    * @return the corresponding PGT, or FALSE on error\r
220    *\r
221    * @public\r
222    */\r
223   function read($pgt_iou)\r
224     {\r
225       phpCAS::traceBegin();\r
226       $pgt = FALSE;\r
227       $fname = $this->getPGTIouFilename($pgt_iou);\r
228       if ( !($f=fopen($fname,"r")) ) {\r
229         phpCAS::trace('could not open `'.$fname.'\'');\r
230       } else {\r
231         if ( ($pgt=fgets($f)) === FALSE ) {\r
232           phpCAS::trace('could not read PGT from `'.$fname.'\'');\r
233         } \r
234         fclose($f);\r
235       }\r
236 \r
237       // delete the PGT file\r
238       @unlink($fname);\r
239 \r
240       phpCAS::traceEnd($pgt);\r
241       return $pgt;\r
242     }\r
243   \r
244   /** @} */\r
245   \r
246 }\r
247 \r
248   \r
249 ?>