]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/_AuthInfo.php
Activated Revision substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / _AuthInfo.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /**
4  Copyright 2004 $ThePhpWikiProgrammingTeam
5
6  This file is part of PhpWiki.
7
8  PhpWiki is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  PhpWiki is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 require_once('lib/Template.php');
24 /**
25  * Used to debug auth problems and settings.
26  * This plugin is only testing purposes. 
27  * if DEBUG is false, only admin can call it, which is of no real use.
28  *
29  * Warning! This may display db and user passwords in cleartext.
30  */
31 class WikiPlugin__AuthInfo
32 extends WikiPlugin
33 {
34     function getName () {
35         return _("AuthInfo");
36     }
37
38     function getDescription () {
39         return _("Display general and user specific auth information.");
40     }
41
42     function getVersion() {
43         return preg_replace("/[Revision: $]/", '',
44                             "\$Revision$");
45     }
46
47     function getDefaultArguments() {
48         return array('userid' => '');
49     }
50
51     function run($dbi, $argstr, &$request, $basepage) {
52         $args = $this->getArgs($argstr, $request);
53         extract($args);
54         if (empty($userid) or $userid == $request->_user->UserName()) {
55             $user = $request->_user;
56             $userid = $user->UserName();
57         } else {
58             $user = WikiUser($userid);
59         }
60         if (!$user->isAdmin() and ! (DEBUG && _DEBUG_LOGIN)) {
61             $request->_notAuthorized(WIKIAUTH_ADMIN);
62             $this->disabled("! user->isAdmin");
63         }
64
65         $html = HTML(HTML::h3(fmt("General Auth Settings")));
66         $table = HTML::table(array('border' => 1,
67                                   'cellpadding' => 2,
68                                   'cellspacing' => 0));
69         $table->pushContent($this->_showhash("AUTH DEFINES", 
70                                 $this->_buildConstHash(
71                                     array("ENABLE_USER_NEW","ALLOW_ANON_USER",
72                                           "ALLOW_ANON_EDIT","ALLOW_BOGO_LOGIN",
73                                           "REQUIRE_SIGNIN_BEFORE_EDIT","ALLOW_USER_PASSWORDS",
74                                           "PASSWORD_LENGTH_MINIMUM","USE_DB_SESSION"))));
75         if ((defined('ALLOW_LDAP_LOGIN') && ALLOW_LDAP_LOGIN) or in_array("LDAP",$GLOBALS['USER_AUTH_ORDER']))
76             $table->pushContent($this->_showhash("LDAP DEFINES", 
77                                                  $this->_buildConstHash(array("LDAP_AUTH_HOST","LDAP_BASE_DN"))));
78         if ((defined('ALLOW_IMAP_LOGIN') && ALLOW_IMAP_LOGIN) or in_array("IMAP",$GLOBALS['USER_AUTH_ORDER']))
79             $table->pushContent($this->_showhash("IMAP DEFINES", array("IMAP_AUTH_HOST" => IMAP_AUTH_HOST)));
80         if (defined('AUTH_USER_FILE') or in_array("File",$GLOBALS['USER_AUTH_ORDER']))
81             $table->pushContent($this->_showhash("AUTH_USER_FILE", 
82                                     $this->_buildConstHash(array("AUTH_USER_FILE",
83                                                                  "AUTH_USER_FILE_STORABLE"))));
84         if (defined('GROUP_METHOD'))
85             $table->pushContent($this->_showhash("GROUP_METHOD", 
86                                     $this->_buildConstHash(array("GROUP_METHOD","AUTH_GROUP_FILE","GROUP_LDAP_QUERY"))));
87         $table->pushContent($this->_showhash("\$USER_AUTH_ORDER[]", $GLOBALS['USER_AUTH_ORDER']));
88         $table->pushContent($this->_showhash("USER_AUTH_POLICY", array("USER_AUTH_POLICY"=>USER_AUTH_POLICY)));
89         $DBParams = $GLOBALS['DBParams'];
90         $DBParams['dsn'] = class_exists('WikiDB_SQL') ? WikiDB_SQL::view_dsn($DBParams['dsn']) : '';
91         $table->pushContent($this->_showhash("\$DBParams[]", $DBParams));
92         $DBAuthParams = $GLOBALS['DBAuthParams'];
93         if (isset($DBAuthParams['auth_dsn']) and class_exists('WikiDB_SQL'))
94             $DBAuthParams['auth_dsn'] = WikiDB_SQL::view_dsn($DBAuthParams['auth_dsn']);
95         else
96             $DBAuthParams['auth_dsn'] = '';
97         unset($DBAuthParams['dummy']);
98         $table->pushContent($this->_showhash("\$DBAuthParams[]", $DBAuthParams));
99         $html->pushContent($table);
100         $html->pushContent(HTML(HTML::h3(fmt("Personal Auth Settings for '%s'", $userid))));
101         if (!$user) {
102             $html->pushContent(HTML::p(fmt("No userid")));
103         } else {
104             $table = HTML::table(array('border' => 1,
105                                        'cellpadding' => 2,
106                                        'cellspacing' => 0));
107             //$table->pushContent(HTML::tr(HTML::td(array('colspan' => 2))));
108             $userdata = obj2hash($user, array('_dbi','_request', 'password', 'passwd'));
109             if (isa($user, "_FilePassUser")) {
110                 foreach ($userdata['_file']->users as $u => $p) {
111                     $userdata['_file']->users[$u] = "<hidden>";
112                 }
113             }
114             $table->pushContent($this->_showhash("User: Object of ".get_class($user), $userdata));
115             if (ENABLE_USER_NEW) {
116               $group = &$request->getGroup();
117               $groups = $group->getAllGroupsIn();
118               $groupdata = obj2hash($group, array('_dbi','_request', 'password', 'passwd'));
119               unset($groupdata['request']);
120               $table->pushContent($this->_showhash("Group: Object of ".get_class($group), $groupdata));
121               $groups = $group->getAllGroupsIn();
122               $groupdata = array('getAllGroupsIn' => $groups);
123               foreach ($groups as $g) {
124                 $groupdata["getMembersOf($g)"] = $group->getMembersOf($g);
125                 $groupdata["isMember($g)"] = $group->isMember($g);
126               }
127               $table->pushContent($this->_showhash("Group Methods: ", $groupdata));
128             }
129             $html->pushContent($table);
130         }
131         return $html;
132     }
133
134     function _showhash ($heading, $hash, $depth = 0) {
135         static $seen = array();
136         static $maxdepth = 0;
137         $rows = array();
138         $maxdepth++;
139         if ($maxdepth > 35) return $heading;
140         
141         if ($heading)
142             $rows[] = HTML::tr(array('bgcolor' => '#ffcccc',
143                                      'style' => 'color:#000000'),
144                                HTML::td(array('colspan' => 2,
145                                               'style' => 'color:#000000'),
146                                         $heading));
147         if (is_object($hash))
148             $hash = obj2hash($hash);
149         if (!empty($hash)) {
150             ksort($hash);
151             foreach ($hash as $key => $val) {
152                 if (is_object($val)) {
153                     $heading = "Object of ".get_class($val);
154                     if ($depth > 3) $val = $heading;
155                     elseif ($heading == "Object of wikidb_sql") $val = $heading;
156                     elseif (substr($heading,0,13) == "Object of db_") $val = $heading;
157                     elseif (!isset($seen[$heading])) {
158                         //if (empty($seen[$heading])) $seen[$heading] = 1;
159                         $val = HTML::table(array('border' => 1,
160                                                  'cellpadding' => 2,
161                                                  'cellspacing' => 0),
162                                            $this->_showhash($heading, obj2hash($val), $depth+1));
163                     } else {
164                         $val = $heading;
165                     }
166                 } elseif (is_array($val)) {
167                     $heading = $key."[]";
168                     if ($depth > 3) $val = $heading;
169                     elseif (!isset($seen[$heading])) {
170                         //if (empty($seen[$heading])) $seen[$heading] = 1;
171                         $val = HTML::table(array('border' => 1,
172                                                  'cellpadding' => 2,
173                                                  'cellspacing' => 0),
174                                            $this->_showhash($heading, $val, $depth+1));
175                     } else {
176                         $val = $heading;
177                     }
178                 }
179                 $rows[] = HTML::tr(HTML::td(array('align' => 'right',
180                                                   'bgcolor' => '#cccccc',
181                                                   'style' => 'color:#000000'),
182                                             HTML(HTML::raw('&nbsp;'), $key,
183                                                  HTML::raw('&nbsp;'))),
184                                    HTML::td(array('bgcolor' => '#ffffff',
185                                                   'style' => 'color:#000000'),
186                                             $val ? $val : HTML::raw('&nbsp;'))
187                                    );
188                 //if (empty($seen[$key])) $seen[$key] = 1;
189             }
190         }
191         return $rows;
192     }
193     
194     function _buildConstHash($constants) {
195         $hash = array();
196         foreach ($constants as $c) {
197             $hash[$c] = defined($c) ? constant($c) : '<empty>';
198             if ($hash[$c] === false) $hash[$c] = 'false';
199             elseif ($hash[$c] === true) $hash[$c] = 'true';
200         }
201         return $hash;
202     }
203 };
204
205 // $Log: not supported by cvs2svn $
206 // Revision 1.19  2005/04/01 14:04:31  rurban
207 // use obj2hash exclude arg,
208 // fix minor security flaw: enable _AuthInfo only if Admin or DEBUG && _DEBUG_LOGIN
209 //   not on any DEBUG value
210 //
211 // Revision 1.18  2005/03/27 19:46:12  rurban
212 // security fixes (unknown why and where these get defined)
213 //
214 // Revision 1.17  2004/10/21 21:00:59  rurban
215 // fix recursion bug for old WikiUser:
216 //   limit max recursion depth (4) and overall recursions (35).
217 //
218 // Revision 1.16  2004/06/25 14:29:22  rurban
219 // WikiGroup refactoring:
220 //   global group attached to user, code for not_current user.
221 //   improved helpers for special groups (avoid double invocations)
222 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
223 // fixed a XHTML validation error on userprefs.tmpl
224 //
225 // Revision 1.15  2004/06/16 10:38:59  rurban
226 // Disallow refernces in calls if the declaration is a reference
227 // ("allow_call_time_pass_reference clean").
228 //   PhpWiki is now allow_call_time_pass_reference = Off clean,
229 //   but several external libraries may not.
230 //   In detail these libs look to be affected (not tested):
231 //   * Pear_DB odbc
232 //   * adodb oracle
233 //
234 // Revision 1.14  2004/05/18 14:49:52  rurban
235 // Simplified strings for easier translation
236 //
237 // Revision 1.13  2004/04/02 15:06:56  rurban
238 // fixed a nasty ADODB_mysql session update bug
239 // improved UserPreferences layout (tabled hints)
240 // fixed UserPreferences auth handling
241 // improved auth stability
242 // improved old cookie handling: fixed deletion of old cookies with paths
243 //
244 // Revision 1.12  2004/03/12 15:48:08  rurban
245 // fixed explodePageList: wrong sortby argument order in UnfoldSubpages
246 // simplified lib/stdlib.php:explodePageList
247 //
248 // Revision 1.11  2004/03/12 11:18:25  rurban
249 // fixed ->membership chache
250 //
251 // Revision 1.10  2004/03/10 13:54:53  rurban
252 // adodb WikiGroup fix
253 //
254 // Revision 1.9  2004/03/08 18:17:10  rurban
255 // added more WikiGroup::getMembersOf methods, esp. for special groups
256 // fixed $LDAP_SET_OPTIONS
257 // fixed _AuthInfo group methods
258 //
259 // Revision 1.8  2004/03/08 16:35:23  rurban
260 // fixed "Undefined index: auth_dsn" warning
261 //
262 // Revision 1.7  2004/02/17 12:11:36  rurban
263 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
264 //
265 // Revision 1.6  2004/02/15 15:21:24  rurban
266 // don't display the SQL dsn connection password
267 //
268 // Revision 1.5  2004/02/09 03:58:20  rurban
269 // for now default DB_SESSION to false
270 // PagePerm:
271 //   * not existing perms will now query the parent, and not
272 //     return the default perm
273 //   * added pagePermissions func which returns the object per page
274 //   * added getAccessDescription
275 // WikiUserNew:
276 //   * added global ->prepare (not yet used) with smart user/pref/member table prefixing.
277 //   * force init of authdbh in the 2 db classes
278 // main:
279 //   * fixed session handling (not triple auth request anymore)
280 //   * don't store cookie prefs with sessions
281 // stdlib: global obj2hash helper from _AuthInfo, also needed for PagePerm
282 //
283 // Revision 1.4  2004/02/07 10:41:25  rurban
284 // fixed auth from session (still double code but works)
285 // fixed GroupDB
286 // fixed DbPassUser upgrade and policy=old
287 // added GroupLdap
288 //
289 // Revision 1.3  2004/02/02 05:36:29  rurban
290 // Simplification and more options, but no passwd or admin protection yet.
291 //
292 // Revision 1.2  2004/02/01 09:14:11  rurban
293 // Started with Group_Ldap (not yet ready)
294 // added new _AuthInfo plugin to help in auth problems (warning: may display passwords)
295 // fixed some configurator vars
296 // renamed LDAP_AUTH_SEARCH to LDAP_BASE_DN
297 // changed PHPWIKI_VERSION from 1.3.8a to 1.3.8pre
298 // USE_DB_SESSION defaults to true on SQL
299 // changed GROUP_METHOD definition to string, not constants
300 // changed sample user DBAuthParams from UPDATE to REPLACE to be able to
301 //   create users. (Not to be used with external databases generally, but
302 //   with the default internal user table)
303 //
304 // fixed the IndexAsConfigProblem logic. this was flawed:
305 //   scripts which are the same virtual path defined their own lib/main call
306 //   (hmm, have to test this better, phpwiki.sf.net/demo works again)
307 //
308 // Revision 1.1  2004/02/01 01:04:34  rurban
309 // Used to debug auth problems and settings.
310 // This may display passwords in cleartext.
311 // DB Objects are not displayed anymore.
312 //
313 // Revision 1.21  2003/02/21 04:22:28  dairiki
314 // Make this work for array-valued data.  Make display of cached markup
315 // readable.  Some code cleanups.  (This still needs more work.)
316 //
317 // Revision 1.20  2003/01/18 21:19:24  carstenklapp
318 // Code cleanup:
319 // Reformatting; added copyleft, getVersion, getDescription
320 //
321
322 // (c-file-style: "gnu")
323 // Local Variables:
324 // mode: php
325 // tab-width: 8
326 // c-basic-offset: 4
327 // c-hanging-comment-ender-p: nil
328 // indent-tabs-mode: nil
329 // End:
330 ?>